Language now supports top level definitions. no more last-expression-is-a-value thing, it's also a def. Host knows to run the special os def
This commit is contained in:
parent
9b8916eb72
commit
31ef279f16
4 changed files with 36 additions and 8 deletions
14
src/main.ts
14
src/main.ts
|
|
@ -25,14 +25,20 @@ const cgCode = stdlibCode + '\n' +
|
|||
try {
|
||||
const tokens = tokenize(cgCode);
|
||||
const parser = new Parser(tokens, cgCode);
|
||||
const ast = parser.parse();
|
||||
const definitions = parser.parse();
|
||||
// console.log(ast);
|
||||
|
||||
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');
|
||||
|
||||
const init = appRecord.fields.init;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue