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.
35 lines
1001 B
TypeScript
35 lines
1001 B
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 defs = parser.parse();
|
|
loadDefinitions();
|
|
compileAndRun(defs);
|
|
saveDefinitions();
|
|
|
|
runAppCompiled(canvas, store);
|
|
} catch(error) {
|
|
console.error(error);
|
|
}
|