MCPcopy Create free account
hub / github.com/aiscript-dev/aiscript / __evalSync

Method __evalSync

src/interpreter/index.ts:1011–1541  ·  view source on GitHub ↗
(node: Ast.Node, scope: Scope, callStack: readonly CallInfo[])

Source from the content-addressed store, hash-verified

1009
1010 @autobind
1011 private __evalSync(node: Ast.Node, scope: Scope, callStack: readonly CallInfo[]): Value | Control {
1012 if (this.stop) return NULL;
1013
1014 this.stepCount++;
1015 if (this.opts.maxStep && this.stepCount > this.opts.maxStep) {
1016 throw new AiScriptRuntimeError('max step exceeded');
1017 }
1018
1019 switch (node.type) {
1020 case 'call': {
1021 const callee = this._evalSync(node.target, scope, callStack);
1022 if (isControl(callee)) {
1023 return callee;
1024 }
1025 assertFunction(callee);
1026 const args = [];
1027 for (const expr of node.args) {
1028 const arg = this._evalSync(expr, scope, callStack);
1029 if (isControl(arg)) {
1030 return arg;
1031 }
1032 args.push(arg);
1033 }
1034 return this._fnSync(callee, args, callStack, node.loc.start);
1035 }
1036
1037 case 'if': {
1038 const cond = this._evalSync(node.cond, scope, callStack);
1039 if (isControl(cond)) {
1040 return cond;
1041 }
1042 assertBoolean(cond);
1043 if (cond.value) {
1044 return unWrapLabeledBreak(this._evalClauseSync(node.then, scope, callStack), node.label);
1045 }
1046 for (const elseif of node.elseif) {
1047 const cond = this._evalSync(elseif.cond, scope, callStack);
1048 if (isControl(cond)) {
1049 return cond;
1050 }
1051 assertBoolean(cond);
1052 if (cond.value) {
1053 return unWrapLabeledBreak(this._evalClauseSync(elseif.then, scope, callStack), node.label);
1054 }
1055 }
1056 if (node.else) {
1057 return unWrapLabeledBreak(this._evalClauseSync(node.else, scope, callStack), node.label);
1058 }
1059 return NULL;
1060 }
1061
1062 case 'match': {
1063 const about = this._evalSync(node.about, scope, callStack);
1064 if (isControl(about)) {
1065 return about;
1066 }
1067 for (const qa of node.qs) {
1068 const q = this._evalSync(qa.q, scope, callStack);

Callers 1

_evalSyncMethod · 0.95

Calls 15

_evalSyncMethod · 0.95
_fnSyncMethod · 0.95
_evalClauseSyncMethod · 0.95
_runSyncMethod · 0.95
defineMethod · 0.95
evalAndSetAttrSyncMethod · 0.95
getReferenceSyncMethod · 0.95
logMethod · 0.95
isControlFunction · 0.85
assertFunctionFunction · 0.85
assertBooleanFunction · 0.85

Tested by

no test coverage detected