compiling. interpreting was too slow

This commit is contained in:
Dustin Swan 2026-02-08 20:02:06 -07:00
parent 6edf592637
commit 2cd5a609bb
No known key found for this signature in database
GPG key ID: 30D46587E2100467
8 changed files with 650 additions and 21 deletions

View file

@ -1,26 +1,23 @@
import type { Env } from './env'
import { evaluate } from './interpreter'
import { compileAndRun } from './compiler'
import { tokenize } from './lexer'
import { Parser } from './parser'
import { runApp } from './runtime';
import { builtins } from './builtins';
import { CGError } from './error';
import { createStore, startTracking, stopTracking, buildDependents } from './store';
import { loadStore, clearStore } from './persistence';
import { runAppCompiled } from './runtime-compiled'
import { _rt } from './runtime-js'
import stdlibCode from './stdlib.cg?raw';
import designTokensCode from './design-tokens.cg?raw';
import uiComponentsCode from './ui-components.cg?raw';
import osCode from './os.cg?raw';
const canvas = document.createElement('canvas') as HTMLCanvasElement;
document.body.appendChild(canvas);
/*
const clearButton = document.getElementById('clear-storage');
if (clearButton) {
clearButton.onclick = () => clearStore();
}
*/
const cgCode = stdlibCode + '\n' +
designTokensCode + '\n' +
@ -30,8 +27,16 @@ const cgCode = stdlibCode + '\n' +
try {
const tokens = tokenize(cgCode);
const parser = new Parser(tokens, cgCode);
const definitions = parser.parse();
const defs = parser.parse();
const os = compileAndRun(defs);
console.log("Compiled os:", os);
runAppCompiled(
{ init: os.init, update: os.update, view: os.view },
canvas,
_rt
);
/*
const env: Env = new Map(Object.entries(builtins));
const store = createStore();
@ -76,10 +81,9 @@ try {
const view = appRecord.fields.view;
runApp({ init, update, view }, canvas, cgCode, env, store, dependents);
*/
} catch(error) {
if (error instanceof CGError) {
console.error(error.format());
} else {
throw error;
}
console.error(error);
}