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.
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import { evaluate } from './interpreter'
|
|
import type { Env } from './env'
|
|
import { tokenize } from './lexer'
|
|
import { Parser } from './parser'
|
|
import { runApp } from './runtime';
|
|
import { builtins } from './builtins';
|
|
|
|
import stdlibCode from './stdlib.cg?raw';
|
|
import designTokensCode from './design-tokens.cg?raw';
|
|
import uiComponentsCode from './ui-components.cg?raw';
|
|
|
|
import textInputCode from './textinput-test.cg?raw';
|
|
import testCode from './test.cg?raw';
|
|
import counterApp from './counter.cg?raw';
|
|
|
|
const canvas = document.createElement('canvas') as HTMLCanvasElement;
|
|
document.body.appendChild(canvas);
|
|
|
|
const cgCode = stdlibCode + '\n' + designTokensCode + '\n' + uiComponentsCode + '\n' + textInputCode;
|
|
|
|
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", 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);
|