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.

32 lines
842 B
TypeScript

import { evaluate } from './interpreter'
import type { Env } from './env'
import { tokenize } from './lexer'
import { Parser } from './parser'
import cgCode from './counter.cg?raw';
import { runApp } from './runtime';
import { builtins } from './builtins';
const canvas = document.createElement('canvas');
canvas.width = 800;
canvas.height = 600;
document.body.appendChild(canvas);
const tokens = tokenize(cgCode);
const parser = new Parser(tokens);
const ast = parser.parse();
console.log(ast);
const env: Env = new Map(Object.entries(builtins));
const appRecord = evaluate(ast, env);
console.log(appRecord);
if (appRecord.kind !== 'record')
throw new Error('Expected record');
const init = appRecord.fields.init;
const update = appRecord.fields.update;
const view = appRecord.fields.view;
runApp({ init, update, view }, canvas);