Fixing too much. also, the OS is actually spawning and managing windows

This commit is contained in:
Dustin Swan 2026-02-12 16:13:00 -07:00
parent 62f6e202b0
commit db4abfa450
No known key found for this signature in database
GPG key ID: 30D46587E2100467
5 changed files with 168 additions and 130 deletions

View file

@ -2,7 +2,7 @@ import { compileAndRun } from './compiler'
import { tokenize } from './lexer'
import { Parser } from './parser'
import { runAppCompiled } from './runtime-compiled'
import { _rt, loadDefinitions, saveDefinitions } from './runtime-js'
import { _rt, store, loadDefinitions, saveDefinitions } from './runtime-js'
const modules = import.meta.glob('./cg/*.cg', { query: 'raw', import: 'default', eager: true });
const cgCode = Object.keys(modules)
@ -13,20 +13,22 @@ const cgCode = Object.keys(modules)
const canvas = document.createElement('canvas') as HTMLCanvasElement;
document.body.appendChild(canvas);
// Populate store with natives
for (const [name, value] of Object.entries(_rt)) {
store[name] = value;
}
store.viewport = { width: window.innerWidth, height: window.innerHeight };
try {
const tokens = tokenize(cgCode);
const parser = new Parser(tokens, cgCode);
const defs = parser.parse();
loadDefinitions();
const os = compileAndRun(defs);
compileAndRun(defs);
saveDefinitions();
runAppCompiled(
{ init: os.init, update: os.update, view: os.view },
canvas,
_rt
);
runAppCompiled(canvas, store);
} catch(error) {
console.error(error);
}