|
|
|
@ -12,13 +12,6 @@ import osCode from './os.cg?raw';
|
|
|
|
const canvas = document.createElement('canvas') as HTMLCanvasElement;
|
|
|
|
const canvas = document.createElement('canvas') as HTMLCanvasElement;
|
|
|
|
document.body.appendChild(canvas);
|
|
|
|
document.body.appendChild(canvas);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
const clearButton = document.getElementById('clear-storage');
|
|
|
|
|
|
|
|
if (clearButton) {
|
|
|
|
|
|
|
|
clearButton.onclick = () => clearStore();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const cgCode = stdlibCode + '\n' +
|
|
|
|
const cgCode = stdlibCode + '\n' +
|
|
|
|
designTokensCode + '\n' +
|
|
|
|
designTokensCode + '\n' +
|
|
|
|
uiComponentsCode + '\n' +
|
|
|
|
uiComponentsCode + '\n' +
|
|
|
|
@ -29,61 +22,12 @@ try {
|
|
|
|
const parser = new Parser(tokens, cgCode);
|
|
|
|
const parser = new Parser(tokens, cgCode);
|
|
|
|
const defs = parser.parse();
|
|
|
|
const defs = parser.parse();
|
|
|
|
const os = compileAndRun(defs);
|
|
|
|
const os = compileAndRun(defs);
|
|
|
|
console.log("Compiled os:", os);
|
|
|
|
|
|
|
|
runAppCompiled(
|
|
|
|
runAppCompiled(
|
|
|
|
{ init: os.init, update: os.update, view: os.view },
|
|
|
|
{ init: os.init, update: os.update, view: os.view },
|
|
|
|
canvas,
|
|
|
|
canvas,
|
|
|
|
_rt
|
|
|
|
_rt
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
const env: Env = new Map(Object.entries(builtins));
|
|
|
|
|
|
|
|
const store = createStore();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const persisted = loadStore();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (const def of definitions) {
|
|
|
|
|
|
|
|
// const body = persisted?.[def.name]?.body ?? def.body;
|
|
|
|
|
|
|
|
const body = def.body;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const deps = startTracking(def.name);
|
|
|
|
|
|
|
|
const value = evaluate(body, env, cgCode);
|
|
|
|
|
|
|
|
stopTracking();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
env.set(def.name, value);
|
|
|
|
|
|
|
|
store.set(def.name, { value, body, dependencies: deps });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Load persisted store entries
|
|
|
|
|
|
|
|
if (persisted) {
|
|
|
|
|
|
|
|
for (const [name, data] of Object.entries(persisted)) {
|
|
|
|
|
|
|
|
if (!store.has(name) && data.source === 'runtime') {
|
|
|
|
|
|
|
|
const deps = startTracking(name);
|
|
|
|
|
|
|
|
const value = evaluate(data.body, env, "");
|
|
|
|
|
|
|
|
stopTracking();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
env.set(name, value);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
store.set(name, { value, body: data.body, dependencies: deps });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const dependents = buildDependents(store);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const appRecord = env.get('os');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!appRecord || appRecord.kind !== 'record')
|
|
|
|
|
|
|
|
throw new Error('Expected record');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const init = appRecord.fields.init;
|
|
|
|
|
|
|
|
const update = appRecord.fields.update;
|
|
|
|
|
|
|
|
const view = appRecord.fields.view;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
runApp({ init, update, view }, canvas, cgCode, env, store, dependents);
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch(error) {
|
|
|
|
} catch(error) {
|
|
|
|
console.error(error);
|
|
|
|
console.error(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|