calcium-lang
Version:
Calcium language interpreter
37 lines • 1.21 kB
JavaScript
import { default as Sym } from "../symbol";
import { evaluate } from "../util";
import { builtinFunctionOrMethod, None } from "../factory";
/**
* use a unary operator and calculate
*/
export default class Call {
constructor(funcRef, args) {
this.funcRef = funcRef;
this.args = args;
this.returnedValue = undefined;
this.willGetReturnedValue = false;
}
[Sym.evaluate](env) {
if (this.returnedValue === undefined) {
if (this.willGetReturnedValue) {
this.returnedValue = env.returnedValue;
env.returnedValue = None;
return this.returnedValue;
}
const func = evaluate(this.funcRef, env);
if (Reflect.get(func, Sym.class) === builtinFunctionOrMethod) {
this.willGetReturnedValue = false;
}
else {
this.willGetReturnedValue = true;
}
// FunctionCalled could be thrown
const result = Reflect.get(func, Sym.call)(this.args, env);
return result;
}
else {
return this.returnedValue;
}
}
}
//# sourceMappingURL=call.js.map