38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import { compileAndRun } from './compiler'
|
|
import { tokenize } from './lexer'
|
|
import { Parser } from './parser'
|
|
import { runAppCompiled } from './runtime-compiled'
|
|
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)
|
|
.sort()
|
|
.map(key => modules[key])
|
|
.join('\n');
|
|
|
|
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 { definitions: defs, typeDefinitions: typeDefs, classDefinitions: classDefs, instanceDeclarations: instances } = parser.parse();
|
|
loadDefinitions();
|
|
|
|
// TODO remove once we're booting from store, files are backup
|
|
if (!store.paletteHistory) store.paletteHistory = [];
|
|
|
|
compileAndRun(defs, typeDefs, classDefs, instances);
|
|
saveDefinitions();
|
|
|
|
runAppCompiled(canvas, store);
|
|
} catch(error) {
|
|
console.error(error);
|
|
}
|