Commit 2864caa6 authored by Romain Casati's avatar Romain Casati
Browse files

API: allow kernel specific options at build.

parent b0fdde5c
......@@ -7,10 +7,10 @@ declare global {
}
}
const loader = new KernelLoader(
window.basthonRoot ?? "./",
window.basthonKernel ?? "python3"
);
const loader = new KernelLoader({
"rootPath": window.basthonRoot ?? "./",
"language": window.basthonKernel ?? "python3"
});
(async () => {
loader.showLoader("Chargement de Basthon...", true);
......
......@@ -11,8 +11,7 @@ declare global {
}
export interface GUIOptions {
kernelRootPath: string,
language: string,
kernelOptions: any,
uiName?: string,
noCheckpointsInit?: boolean,
}
......@@ -36,14 +35,14 @@ export class GUIBase {
private _console_error: (message: string) => void = console.error;
public constructor(options: GUIOptions) {
this._language = options.language;
this._loader = new KernelLoader(options.kernelRootPath, options.language);
this._language = options?.kernelOptions?.language;
this._loader = new KernelLoader(options.kernelOptions);
// loading Basthon (errors are fatal)
this._loader.showLoader("Chargement de Basthon...", false, false);
/* per language checkpoints */
if (!options.noCheckpointsInit)
this._checkpoints = new CheckpointsManager<string>(
`${options.uiName}.${options.language}`, this._maxCheckpoints);
`${options.uiName}.${this._language}`, this._maxCheckpoints);
/* globale states (not language specific) */
this._stateStorage = new Storage(`${options.uiName}.states`);
}
......
......@@ -33,9 +33,9 @@ export class KernelBase {
private readonly _loaded = new PromiseDelegate<void>();
public _execution_count: number = 0;
constructor(rootPath: string) {
constructor(options: any) {
// root path where kernel is installed
this._rootPath = rootPath;
this._rootPath = options.rootPath;
}
/**
......
......@@ -8,8 +8,8 @@ export class KernelJavaScript extends KernelBase {
window: undefined,
};;
constructor(rootPath: string) {
super(rootPath);
constructor(options: any) {
super(options);
this._execution_count = 0;
}
......
......@@ -27,9 +27,9 @@ export class KernelLoader {
private _loaderTextElem?: HTMLDivElement;
private _loaderTextError?: HTMLDivElement;
constructor(rootPath: string,
language: string,
constructor(options: any,
loaderId?: string) {
const language: string = options.language;
if (loaderId != null) this._loaderId = loaderId;
if (document.readyState === 'loading') {
......@@ -49,25 +49,25 @@ export class KernelLoader {
case "python3":
case "python3.10":
const { KernelPython3 } = await import("@basthon/kernel-python3");
this._kernel = new KernelPython3(rootPath);
this._kernel = new KernelPython3(options);
break;
case "python3-old":
case "python3.8":
const { KernelPython3Old } = await import("@basthon/kernel-python3-old");
this._kernel = new KernelPython3Old(rootPath);
this._kernel = new KernelPython3Old(options);
break;
case "js":
case "javascript":
const { KernelJavaScript } = await import("@basthon/kernel-javascript");
this._kernel = new KernelJavaScript(rootPath);
this._kernel = new KernelJavaScript(options);
break;
case "sql":
const { KernelSQL } = await import("@basthon/kernel-sql");
this._kernel = new KernelSQL(rootPath);
this._kernel = new KernelSQL(options);
break;
case "ocaml":
const { KernelOCaml } = await import("@basthon/kernel-ocaml");
this._kernel = new KernelOCaml(rootPath);
this._kernel = new KernelOCaml(options);
break;
default:
window.console.error(`Kernel '${language}' not supported.`);
......
......@@ -17,8 +17,8 @@ export class KernelOCaml extends KernelBase {
private __eval_data__?: any = {};
private _initInnerCode: string;
constructor(rootPath: string) {
super(rootPath);
constructor(options: any) {
super(options);
this._initInnerCode = `\
open Js_of_ocaml
module Basthon = struct
......
......@@ -21,7 +21,7 @@ export class KernelPython3Old extends KernelBase {
private __kernel__: any = null;
public pythonVersion: string = "";
constructor(rootPath: string) { super(rootPath); }
constructor(options: any) { super(options); }
/**
* Get the URL of Basthon modules dir.
......
......@@ -22,7 +22,7 @@ export class KernelPython3 extends KernelBase {
private __kernel__: any = null;
public pythonVersion: string = "";
constructor(rootPath: string) { super(rootPath); }
constructor(options: any) { super(options); }
/**
* Get the URL of Basthon modules dir.
......
......@@ -13,8 +13,8 @@ export class KernelSQL extends KernelBase {
private db: any;
private _dots: { [key: string]: { [key: string]: string | (() => unknown) } };
public constructor(rootPath: string) {
super(rootPath);
public constructor(options: any) {
super(options);
this._execution_count = 0;
// initial db file (used to restart SQLite)
this._dbInit = undefined;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment