|
|
|
@ -65,7 +65,7 @@ export function evaluate(ast: AST, env: Env): Value {
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
kind: 'constructor',
|
|
|
|
kind: 'constructor',
|
|
|
|
name: ast.name,
|
|
|
|
name: ast.name,
|
|
|
|
args: [] // TODO: constructors args
|
|
|
|
args: []
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
case 'let': {
|
|
|
|
case 'let': {
|
|
|
|
@ -105,6 +105,16 @@ export function evaluate(ast: AST, env: Env): Value {
|
|
|
|
|
|
|
|
|
|
|
|
const func = evaluate(ast.func, env);
|
|
|
|
const func = evaluate(ast.func, env);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Constructor application
|
|
|
|
|
|
|
|
if (func.kind === 'constructor') {
|
|
|
|
|
|
|
|
const argValues = ast.args.map(arg => evaluate(arg, env));
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
kind: 'constructor',
|
|
|
|
|
|
|
|
name: func.name,
|
|
|
|
|
|
|
|
args: [...func.args, ...argValues]
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (func.kind !== 'closure')
|
|
|
|
if (func.kind !== 'closure')
|
|
|
|
throw new Error('Not a function');
|
|
|
|
throw new Error('Not a function');
|
|
|
|
|
|
|
|
|
|
|
|
|