|
|
|
@ -25,14 +25,20 @@ const cgCode = stdlibCode + '\n' +
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const tokens = tokenize(cgCode);
|
|
|
|
const tokens = tokenize(cgCode);
|
|
|
|
const parser = new Parser(tokens, cgCode);
|
|
|
|
const parser = new Parser(tokens, cgCode);
|
|
|
|
const ast = parser.parse();
|
|
|
|
const definitions = parser.parse();
|
|
|
|
// console.log(ast);
|
|
|
|
// console.log(ast);
|
|
|
|
|
|
|
|
|
|
|
|
const env: Env = new Map(Object.entries(builtins));
|
|
|
|
const env: Env = new Map(Object.entries(builtins));
|
|
|
|
const appRecord = evaluate(ast, env, cgCode);
|
|
|
|
|
|
|
|
// console.log("appRecord", appRecord);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (appRecord.kind !== 'record')
|
|
|
|
for (const def of definitions) {
|
|
|
|
|
|
|
|
const value = evaluate(def.body, env, cgCode);
|
|
|
|
|
|
|
|
env.set(def.name, value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const appRecord = env.get('os');
|
|
|
|
|
|
|
|
console.log("appRecord", appRecord);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!appRecord || appRecord.kind !== 'record')
|
|
|
|
throw new Error('Expected record');
|
|
|
|
throw new Error('Expected record');
|
|
|
|
|
|
|
|
|
|
|
|
const init = appRecord.fields.init;
|
|
|
|
const init = appRecord.fields.init;
|
|
|
|
|