You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
901 B
TypeScript

import { compileAndRun } from './compiler'
import { tokenize } from './lexer'
import { Parser } from './parser'
import { runAppCompiled } from './runtime-compiled'
import { _rt, loadDefinitions, saveDefinitions } from './runtime-js'
const modules = import.meta.glob('./cg/*.cg', { query: 'raw', import: 'default', eager: true });
const cgCode = Object.keys(modules)
.sort()
.map(key => modules[key])
.join('\n');
const canvas = document.createElement('canvas') as HTMLCanvasElement;
document.body.appendChild(canvas);
try {
const tokens = tokenize(cgCode);
const parser = new Parser(tokens, cgCode);
const defs = parser.parse();
loadDefinitions();
const os = compileAndRun(defs);
saveDefinitions();
runAppCompiled(
{ init: os.init, update: os.update, view: os.view },
canvas,
_rt
);
} catch(error) {
console.error(error);
}