ivprogProcessor.js 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107
  1. import { Store } from './store/store';
  2. import { Modes } from './modes';
  3. import { Context } from './context';
  4. import { Types } from './../typeSystem/types';
  5. import { Operators } from './../ast/operators';
  6. import { LanguageDefinedFunction } from './definedFunctions';
  7. import { resultTypeAfterInfixOp, resultTypeAfterUnaryOp } from './compatibilityTable';
  8. import * as Commands from './../ast/commands/';
  9. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  10. import { Command } from './../ast/commands/command'
  11. import * as Expressions from './../ast/expressions/';
  12. import * as Utils from './../util/utils';
  13. import { ArrayType } from './../typeSystem/array_type';
  14. import { convertToString, toInt } from '../typeSystem/parsers';
  15. import { Config } from '../util/config';
  16. import { ProcessorErrorFactory } from './error/processorErrorFactory';
  17. import { RuntimeError } from './error/runtimeError';
  18. import { Location } from '../memory/location';
  19. import { StoreValue } from './store/value/store_value';
  20. import { StoreValueRef } from './store/value/store_value_ref';
  21. import { ArrayStoreValue } from './store/value/array_store_value';
  22. import { ArrayStoreValueRef } from './store/value/array_store_value_ref';
  23. import { StoreValueAddress } from './store/value/store_value_address';
  24. import { LocalizedStrings } from '../services/localizedStringsService';
  25. export class IVProgProcessor {
  26. static get MAIN_INTERNAL_ID () {
  27. return "$main";
  28. }
  29. constructor (ast) {
  30. this.ast = ast;
  31. this.globalStore = new Store("$global");
  32. this.stores = [this.globalStore];
  33. this.context = [Context.BASE];
  34. this.input = null;
  35. this.forceKill = false;
  36. this.output = null;
  37. this.mode = Modes.RUN;
  38. /**
  39. * Stores the sourceInfo of every function call, command or expression
  40. */
  41. this.function_call_stack = [];
  42. this.instruction_count = 0;
  43. this.function_call_count = 0;
  44. }
  45. registerInput (input) {
  46. if(this.input !== null)
  47. this.input = null;
  48. this.input = input;
  49. }
  50. registerOutput (output) {
  51. if(this.output !== null)
  52. this.output = null;
  53. this.output = output;
  54. }
  55. checkContext(context) {
  56. return this.context[this.context.length - 1] === context;
  57. }
  58. ignoreSwitchCases (store) {
  59. if (store.mode === Modes.RETURN) {
  60. return true;
  61. } else if (store.mode === Modes.BREAK) {
  62. return true;
  63. } else {
  64. return false;
  65. }
  66. }
  67. prepareState () {
  68. if(this.stores !== null) {
  69. for (let i = 0; i < this.stores.length; i++) {
  70. delete this.stores[i];
  71. }
  72. this.stores = null;
  73. }
  74. if(this.globalStore !== null)
  75. this.globalStore = null;
  76. this.globalStore = new Store("$global");
  77. this.stores = [this.globalStore];
  78. this.context = [Context.BASE];
  79. this.instruction_count = 0;
  80. this.mode = Modes.RUN;
  81. }
  82. async interpretAST () {
  83. this.prepareState();
  84. Location.clear();
  85. await this.initGlobal();
  86. const mainFunc = this.findMainFunction();
  87. if (mainFunc === null) {
  88. throw ProcessorErrorFactory.main_missing();
  89. }
  90. return this.runFunction(mainFunc, [], this.globalStore);
  91. }
  92. async initGlobal () {
  93. if(!this.checkContext(Context.BASE)) {
  94. return ProcessorErrorFactory.invalid_global_var();
  95. }
  96. return this.executeCommands(this.globalStore, this.ast.global);
  97. }
  98. findMainFunction () {
  99. return this.ast.functions.find(v => v.isMain);
  100. }
  101. findFunction (name) {
  102. if(name.match(/^\$.+$/)) {
  103. if(name === IVProgProcessor.MAIN_INTERNAL_ID) {
  104. return this.findMainFunction();
  105. }
  106. const fun = LanguageDefinedFunction.getFunction(name);
  107. if(!fun) {
  108. throw ProcessorErrorFactory.not_implemented(name);
  109. }
  110. return fun;
  111. } else {
  112. const val = this.ast.functions.find( v => v.name === name);
  113. if (!val) {
  114. throw ProcessorErrorFactory.function_missing(name);
  115. }
  116. return val;
  117. }
  118. }
  119. async runFunction (func, actualParameters, store) {
  120. const funcName = func.isMain ? IVProgProcessor.MAIN_INTERNAL_ID : func.name;
  121. const funcStore = new Store(funcName);
  122. funcStore.extendStore(this.globalStore);
  123. await this.associateParameters(func.formalParameters, actualParameters, store, funcStore);
  124. this.context.push(Context.FUNCTION);
  125. this.stores.push(funcStore);
  126. const stoWithVars = await this.executeCommands(funcStore, func.variablesDeclarations);
  127. const finalSto = this.executeCommands(stoWithVars, func.commands);
  128. this.stores.pop();
  129. this.context.pop();
  130. return finalSto;
  131. }
  132. async associateParameters (formal_params, effective_params, caller_store, callee_store) {
  133. const funcName = callee_store.name === IVProgProcessor.MAIN_INTERNAL_ID ?
  134. LanguageDefinedFunction.getMainFunctionName() : callee_store.name;
  135. if (formal_params.length != effective_params.length) {
  136. throw ProcessorErrorFactory.invalid_parameters_size(funcName, formal_params.length, effective_params.length);
  137. }
  138. for (let i = 0; i < effective_params.length; i += 1) {
  139. const actualParam = effective_params[i];
  140. const actualValue = await this.evaluateExpression(caller_store, actualParam);
  141. const exp = effective_params[i];
  142. let shouldTypeCast = false;
  143. const formalParameter = formal_params[i];
  144. if(!formalParameter.type.isCompatible(actualValue.type)) {
  145. if (Config.enable_type_casting && !formalParameter.byRef
  146. && Store.canImplicitTypeCast(formalParameter.type, actualValue.type)) {
  147. shouldTypeCast = true;
  148. } else {
  149. throw ProcessorErrorFactory.invalid_parameter_type(funcName, exp.toString());
  150. }
  151. }
  152. if(formalParameter.byRef && !actualValue.inStore()) {
  153. throw ProcessorErrorFactory.invalid_ref(funcName, exp.toString());
  154. }
  155. if(formalParameter.byRef) {
  156. const realObj = caller_store.getStoreObject(actualValue.id);
  157. let ref = null;
  158. if(actualValue instanceof ArrayStoreValue) {
  159. // it's a vector or matrix...
  160. const values = actualValue.get();
  161. const array_type = actualValue.type;
  162. const addresses = values.map( v => realObj.getLocAddressOf(v.line, v.column));
  163. const columns = actualValue.isVector() ? 0 : actualValue.columns;
  164. ref = new ArrayStoreValueRef(array_type, values, addresses, actualValue.lines, columns, realObj.id);
  165. } else {
  166. if(actualValue instanceof StoreValueAddress) {
  167. const line = actualValue.line;
  168. const column = actualValue.column;
  169. ref = new StoreValueRef(actualValue.type, actualValue.get(),
  170. realObj.getLocAddressOf(line, column), realObj.id);
  171. ref.setReferenceDimension(realObj.type.dimensions);
  172. } else {
  173. ref = new StoreValueRef(actualValue.type, actualValue.get(), realObj.locAddress, realObj.id);
  174. }
  175. }
  176. callee_store.insertStore(formalParameter.id, ref);
  177. } else {
  178. let realValue = actualValue;
  179. if (shouldTypeCast) {
  180. realValue = Store.doImplicitCasting(formalParameter.type, realValue);
  181. }
  182. callee_store.insertStore(formalParameter.id, realValue);
  183. }
  184. }
  185. return callee_store;
  186. }
  187. /**
  188. *
  189. * @param {Store} store
  190. * @param {Command[]} cmds
  191. */
  192. async executeCommands (store, cmds) {
  193. // helper to partially apply a function, in this case executeCommand
  194. let sto = store;
  195. for (let i = 0; i < cmds.length; i += 1) {
  196. sto = await this.executeCommand(sto, cmds[i]);
  197. }
  198. return sto;
  199. }
  200. /**
  201. *
  202. * @param {Store} store
  203. * @param {Command} cmd
  204. */
  205. async executeCommand (store, cmd) {
  206. this.instruction_count += 1;
  207. if(this.instruction_count % Config.suspend_threshold == 0) {
  208. //every Config.suspend_threshold instruction should briefly delay its execution in order to allow the browser to process other things
  209. await Utils.sleep(5)
  210. }
  211. // Checks if it must interrupt the execution for some reason
  212. if(this.instruction_count >= Config.max_instruction_count) {
  213. throw ProcessorErrorFactory.exceed_max_instructions();
  214. } else if(this.forceKill) {
  215. throw "FORCED_KILL!";
  216. } else if (store.mode === Modes.PAUSE) {
  217. return this.executeCommand(store, cmd);
  218. } else if(store.mode === Modes.RETURN) {
  219. return store;
  220. } else if (this.checkContext(Context.BREAKABLE) && store.mode === Modes.BREAK) {
  221. return store;
  222. } else if (this.mode === Modes.ABORT) {
  223. throw LocalizedStrings.getMessage('aborted_execution');
  224. }
  225. if (cmd instanceof Commands.Declaration) {
  226. return this.executeDeclaration(store, cmd);
  227. } else if (cmd instanceof Commands.ArrayIndexAssign) {
  228. return this.executeArrayIndexAssign(store, cmd);
  229. } else if (cmd instanceof Commands.Assign) {
  230. return this.executeAssign(store, cmd);
  231. } else if (cmd instanceof Commands.Break) {
  232. return this.executeBreak(store, cmd);
  233. } else if (cmd instanceof Commands.Return) {
  234. return this.executeReturn(store, cmd);
  235. } else if (cmd instanceof Commands.IfThenElse) {
  236. return this.executeIfThenElse(store, cmd);
  237. } else if (cmd instanceof Commands.RepeatUntil) {
  238. return this.executeRepeatUntil(store, cmd);
  239. } else if (cmd instanceof Commands.While) {
  240. return this.executeWhile(store, cmd);
  241. } else if (cmd instanceof Commands.For) {
  242. return this.executeFor(store, cmd);
  243. } else if (cmd instanceof Commands.Switch) {
  244. return this.executeSwitch(store, cmd);
  245. } else if (cmd instanceof Expressions.FunctionCall) {
  246. return this.executeFunctionCall(store, cmd);
  247. } else if (cmd instanceof Commands.SysCall) {
  248. return this.executeSysCall(store, cmd);
  249. } else {
  250. throw ProcessorErrorFactory.unknown_command(cmd.sourceInfo);
  251. }
  252. }
  253. executeSysCall (store, cmd) {
  254. const func = cmd.langFunc.bind(this);
  255. return func(store, cmd);
  256. }
  257. async executeFunctionCall (store, cmd) {
  258. let func = null;
  259. if(cmd.isMainCall) {
  260. func = this.findMainFunction();
  261. } else {
  262. func = this.findFunction(cmd.id);
  263. }
  264. this.function_call_stack.push(cmd.sourceInfo);
  265. const sto = await this.runFunction(func, cmd.actualParameters, store);
  266. sto.destroy();
  267. if(!Types.VOID.isCompatible(func.returnType) && sto.mode !== Modes.RETURN) {
  268. const funcName = func.name === IVProgProcessor.MAIN_INTERNAL_ID ?
  269. LanguageDefinedFunction.getMainFunctionName() : func.name;
  270. throw ProcessorErrorFactory.function_no_return(funcName);
  271. } else {
  272. this.function_call_stack.pop();
  273. return store;
  274. }
  275. }
  276. executeSwitch (store, cmd) {
  277. this.context.push(Context.BREAKABLE);
  278. const caseSequence = cmd.cases.reduce( (prev,next) => {
  279. return prev.then( tuple => {
  280. if(this.ignoreSwitchCases(tuple[1])) {
  281. return Promise.resolve(tuple);
  282. } else if(tuple[0] || next.isDefault) {
  283. return this.executeCommands(tuple[1], next.commands)
  284. .then(nSto => Promise.resolve([true, nSto]));
  285. } else {
  286. const equalityInfixApp = new Expressions.InfixApp(Operators.EQ, cmd.expression, next.expression);
  287. equalityInfixApp.sourceInfo = next.sourceInfo;
  288. return this.evaluateExpression(tuple[1],equalityInfixApp).then(stoObj => stoObj.get())
  289. .then(isEqual => {
  290. if (isEqual) {
  291. return this.executeCommands(tuple[1], next.commands)
  292. .then(nSto => Promise.resolve([true, nSto]));
  293. } else {
  294. return Promise.resolve(tuple);
  295. }
  296. });
  297. }
  298. });
  299. }, Promise.resolve([false, store]));
  300. return caseSequence.then(tuple => {
  301. this.context.pop();
  302. const newStore = tuple[1];
  303. if (newStore.mode === Modes.BREAK) {
  304. newStore.mode = Modes.RUN;
  305. }
  306. return newStore;
  307. });
  308. }
  309. /**
  310. *
  311. * @param {Store} store
  312. * @param {Commands.For} cmd
  313. */
  314. executeFor (store, cmd) {
  315. //BEGIN for -> while rewrite
  316. const initCmd = new Commands.Assign(cmd.for_id.id, cmd.for_from);
  317. initCmd.sourceInfo = cmd.sourceInfo;
  318. const expression_tuple = []; //(for conditional, is for increasing)
  319. if(cmd.for_pass == null) {
  320. expression_tuple.push(Promise.resolve(null));
  321. expression_tuple.push(this.evaluateExpression(store, new Expressions.InfixApp(Operators.GE, cmd.for_to, cmd.for_from)));
  322. } else {
  323. expression_tuple.push(this.evaluateExpression(store, new Expressions.InfixApp(Operators.GE, cmd.for_pass, new Expressions.IntLiteral(toInt(0)))));
  324. expression_tuple.push(Promise.resolve(null));
  325. }
  326. return Promise.all(expression_tuple).then (results => {
  327. // console.log(results);
  328. let is_forward = true;
  329. let is_end_gt_init = undefined;
  330. let condition = null;
  331. let pass_value = cmd.for_pass;
  332. if (results[0] == null) {
  333. // pass is null, we need to deduce a value for it
  334. is_end_gt_init = results[1].value;
  335. } else {
  336. is_forward = results[0].value
  337. }
  338. if(is_end_gt_init == null) {
  339. // console.log("pass is not null and is forward? ", is_forward);
  340. if(is_forward) {
  341. condition = new Expressions.InfixApp(Operators.LE, cmd.for_id, cmd.for_to);
  342. } else {
  343. condition = new Expressions.InfixApp(Operators.GE, cmd.for_id, cmd.for_to);
  344. }
  345. // console.log("Cond", condition);
  346. } else if(is_end_gt_init) {
  347. pass_value = new Expressions.IntLiteral(toInt(1));
  348. condition = new Expressions.InfixApp(Operators.LE, cmd.for_id, cmd.for_to);
  349. } else {
  350. pass_value = new Expressions.IntLiteral(toInt(-1));
  351. condition = new Expressions.InfixApp(Operators.GE, cmd.for_id, cmd.for_to);
  352. }
  353. condition.sourceInfo = cmd.sourceInfo;
  354. const increment = new Commands.Assign(cmd.for_id.id,
  355. new Expressions.InfixApp(Operators.ADD, cmd.for_id, pass_value));
  356. increment.sourceInfo = cmd.sourceInfo;
  357. const whileBlock = new Commands.CommandBlock([],
  358. cmd.commands.concat(increment));
  359. const forAsWhile = new Commands.While(condition, whileBlock);
  360. forAsWhile.sourceInfo = cmd.sourceInfo;
  361. //END for -> while rewrite
  362. const newCmdList = [initCmd,forAsWhile];
  363. return this.executeCommands(store, newCmdList);
  364. }).catch(error => Promise.reject(error));
  365. }
  366. executeRepeatUntil (store, cmd) {
  367. try {
  368. this.context.push(Context.BREAKABLE);
  369. const $newStore = this.executeCommands(store, cmd.commands);
  370. return $newStore.then(sto => {
  371. if(sto.mode === Modes.BREAK) {
  372. this.context.pop();
  373. sto.mode = Modes.RUN;
  374. return sto;
  375. }
  376. const $value = this.evaluateExpression(sto, cmd.expression);
  377. return $value.then(vl => {
  378. if (!vl.type.isCompatible(Types.BOOLEAN)) {
  379. return Promise.reject(ProcessorErrorFactory.loop_condition_type_full(cmd.sourceInfo));
  380. }
  381. if (!vl.get()) {
  382. this.context.pop();
  383. return this.executeCommand(sto, cmd);
  384. } else {
  385. this.context.pop();
  386. return sto;
  387. }
  388. })
  389. })
  390. } catch (error) {
  391. return Promise.reject(error);
  392. }
  393. }
  394. executeWhile (store, cmd) {
  395. try {
  396. this.context.push(Context.BREAKABLE);
  397. const $value = this.evaluateExpression(store, cmd.expression);
  398. return $value.then(vl => {
  399. if(vl.type.isCompatible(Types.BOOLEAN)) {
  400. if(vl.get()) {
  401. const $newStore = this.executeCommands(store, cmd.commands);
  402. return $newStore.then(sto => {
  403. this.context.pop();
  404. if (sto.mode === Modes.BREAK) {
  405. sto.mode = Modes.RUN;
  406. return sto;
  407. }
  408. return this.executeCommand(sto, cmd);
  409. });
  410. } else {
  411. this.context.pop();
  412. return store;
  413. }
  414. } else {
  415. return Promise.reject(ProcessorErrorFactory.loop_condition_type_full(cmd.expression.toString(), cmd.sourceInfo));
  416. }
  417. })
  418. } catch (error) {
  419. return Promise.reject(error);
  420. }
  421. }
  422. executeIfThenElse (store, cmd) {
  423. try {
  424. const $value = this.evaluateExpression(store, cmd.condition);
  425. return $value.then(vl => {
  426. if(vl.type.isCompatible(Types.BOOLEAN)) {
  427. if(vl.get()) {
  428. return this.executeCommands(store, cmd.ifTrue.commands);
  429. } else if( cmd.ifFalse !== null){
  430. if(cmd.ifFalse instanceof Commands.IfThenElse) {
  431. return this.executeCommand(store, cmd.ifFalse);
  432. } else {
  433. return this.executeCommands(store, cmd.ifFalse.commands);
  434. }
  435. } else {
  436. return Promise.resolve(store);
  437. }
  438. } else {
  439. return Promise.reject(ProcessorErrorFactory.if_condition_type_full(cmd.condition.toString(), cmd.sourceInfo));
  440. }
  441. });
  442. } catch (error) {
  443. return Promise.reject(error);
  444. }
  445. }
  446. executeReturn (store, cmd) {
  447. try {
  448. const funcName = store.name === IVProgProcessor.MAIN_INTERNAL_ID ?
  449. LanguageDefinedFunction.getMainFunctionName() : store.name;
  450. // console.log(funcName, store.name === IVProgProcessor.MAIN_INTERNAL_ID);
  451. const func = this.findFunction(store.name);
  452. const funcType = func.returnType;
  453. const $value = this.evaluateExpression(store, cmd.expression);
  454. return $value.then(value => {
  455. let real_value = value;
  456. if(value === null && funcType.isCompatible(Types.VOID)) {
  457. store.mode = Modes.RETURN;
  458. return Promise.resolve(store);
  459. }
  460. if (value === null || !funcType.isCompatible(value.type)) {
  461. if(!Config.enable_type_casting || !Store.canImplicitTypeCast(funcType, value.type)) {
  462. const stringInfo = funcType.stringInfo();
  463. const info = stringInfo[0];
  464. return Promise.reject(ProcessorErrorFactory.invalid_return_type_full(funcName, info.type, info.dim, cmd.sourceInfo));
  465. }
  466. real_value = Store.doImplicitCasting(funcType, value);
  467. } else {
  468. store.insertStore('$', real_value);
  469. store.mode = Modes.RETURN;
  470. return Promise.resolve(store);
  471. }
  472. });
  473. } catch (error) {
  474. return Promise.reject(error);
  475. }
  476. }
  477. executeBreak (store, cmd) {
  478. if(this.checkContext(Context.BREAKABLE)) {
  479. store.mode = Modes.BREAK;
  480. return Promise.resolve(store);
  481. } else {
  482. return Promise.reject(ProcessorErrorFactory.unexpected_break_command_full(cmd.sourceInfo));
  483. }
  484. }
  485. executeAssign (store, cmd) {
  486. try {
  487. const inStore = store.applyStore(cmd.id);
  488. if(inStore.isConst) {
  489. return Promise.reject(ProcessorErrorFactory.invalid_const_assignment_full(cmd.id, cmd.sourceInfo))
  490. }
  491. const $value = this.evaluateExpression(store, cmd.expression);
  492. return $value.then( vl => {
  493. let realValue = vl;
  494. if(!inStore.type.isCompatible(realValue.type)) {
  495. if(Config.enable_type_casting && Store.canImplicitTypeCast(inStore.type, vl.type)) {
  496. realValue = Store.doImplicitCasting(inStore.type, realValue);
  497. } else {
  498. const stringInfo = inStore.type.stringInfo()
  499. const info = stringInfo[0]
  500. const exp_type_string_info = vl.type.stringInfo();
  501. const exp_type_info = exp_type_string_info[0];
  502. const exp = cmd.expression.toString();
  503. return Promise.reject(ProcessorErrorFactory.incompatible_types_full(info.type, info.dim, exp_type_info.type, exp_type_info.dim, exp, cmd.sourceInfo));
  504. }
  505. }
  506. if(inStore instanceof ArrayStoreValue) {
  507. const columns = realValue.columns == null ? 0 : realValue.columns;
  508. if(inStore.lines !== realValue.lines || inStore.columns !== columns){
  509. const exp = cmd.expression.toString();
  510. if(inStore.isVector()) {
  511. return Promise.reject(ProcessorErrorFactory.invalid_vector_assignment_full(cmd.id, inStore.lines, exp, realValue.lines, cmd.sourceInfo));
  512. } else {
  513. return Promise.reject(ProcessorErrorFactory.invalid_matrix_assignment_full(cmd.id, inStore.lines, inStore.columns, exp, realValue.lines, realValue.columns, cmd.sourceInfo));
  514. }
  515. }
  516. }
  517. store.updateStore(cmd.id, realValue)
  518. return store;
  519. });
  520. } catch (error) {
  521. return Promise.reject(error);
  522. }
  523. }
  524. executeArrayIndexAssign (store, cmd) {
  525. const mustBeArray = store.applyStore(cmd.id);
  526. let used_dims = 0;
  527. if(mustBeArray.isConst) {
  528. return Promise.reject(ProcessorErrorFactory.invalid_const_assignment_full(cmd.id, cmd.sourceInfo))
  529. }
  530. if(!(mustBeArray.type instanceof ArrayType)) {
  531. return Promise.reject(ProcessorErrorFactory.invalid_array_access_full(cmd.id, cmd.sourceInfo));
  532. }
  533. const line$ = this.evaluateExpression(store, cmd.line);
  534. const column$ = this.evaluateExpression(store, cmd.column);
  535. const value$ = this.evaluateExpression(store, cmd.expression);
  536. return Promise.all([line$, column$, value$]).then(([line_sv, column_sv, value]) => {
  537. if(!Types.INTEGER.isCompatible(line_sv.type)) {
  538. return Promise.reject(ProcessorErrorFactory.array_dimension_not_int_full(cmd.sourceInfo));
  539. }
  540. const line = line_sv.get().toNumber();
  541. used_dims += 1;
  542. let column = undefined;
  543. if (column_sv != null) {
  544. if(!Types.INTEGER.isCompatible(column_sv.type)) {
  545. return Promise.reject(ProcessorErrorFactory.array_dimension_not_int_full(cmd.sourceInfo));
  546. }
  547. column = column_sv.get().toNumber();
  548. used_dims += 1;
  549. }
  550. let actualValue = value;
  551. if (line >= mustBeArray.lines) {
  552. if(mustBeArray.isVector) {
  553. return Promise.reject(ProcessorErrorFactory.vector_line_outbounds_full(cmd.id, line, mustBeArray.lines, cmd.sourceInfo));
  554. } else {
  555. return Promise.reject(ProcessorErrorFactory.matrix_line_outbounds_full(cmd.id, line, mustBeArray.lines, cmd.sourceInfo));
  556. }
  557. } else if (line < 0) {
  558. return Promise.reject(ProcessorErrorFactory.array_dimension_not_positive_full(cmd.sourceInfo))
  559. }
  560. if (column != null && mustBeArray.columns === 0 ){
  561. return Promise.reject(ProcessorErrorFactory.vector_not_matrix_full(cmd.id, cmd.sourceInfo));
  562. }
  563. if(column != null ) {
  564. if (column >= mustBeArray.columns) {
  565. return Promise.reject(ProcessorErrorFactory.matrix_column_outbounds_full(cmd.id, column,mustBeArray.columns, cmd.sourceInfo));
  566. } else if (column < 0) {
  567. return Promise.reject(ProcessorErrorFactory.array_dimension_not_positive_full(cmd.sourceInfo))
  568. }
  569. }
  570. if (!mustBeArray.type.canAccept(value.type, used_dims)) {
  571. if(!Config.enable_type_casting || !Store.canImplicitTypeCast(mustBeArray.type.innerType, value.type)) {
  572. const type = mustBeArray.type.innerType;
  573. const stringInfo = type.stringInfo();
  574. const info = stringInfo[0];
  575. const exp_type_string_info = value.type.stringInfo();
  576. const exp_type_info = exp_type_string_info[0];
  577. const exp = cmd.expression.toString();
  578. return Promise.reject(ProcessorErrorFactory.incompatible_types_full(info.type, info.dim, exp_type_info.type, exp_type_info.dim, exp, cmd.sourceInfo));
  579. }
  580. actualValue = Store.doImplicitCasting(mustBeArray.type.innerType, value);
  581. }
  582. const current_value = mustBeArray.getAt(line, column);
  583. if(current_value instanceof ArrayStoreValue) {
  584. if(current_value.lines !== actualValue.lines || current_value.columns !== actualValue.columns){
  585. const exp = cmd.expression.toString();
  586. return Promise.reject(ProcessorErrorFactory.invalid_matrix_index_assign_full(cmd.id, line, current_value.lines, exp, actualValue.lines, cmd.sourceInfo))
  587. }
  588. }
  589. // mustBeArray.setAt(actualValue, line, column);
  590. // store.updateStore(cmd.id, mustBeArray);
  591. return store.updateStoreArray(cmd.id, actualValue, line, column);
  592. });
  593. }
  594. /**
  595. *
  596. * @param {Store} store
  597. * @param {Commands.Declaration} cmd
  598. */
  599. executeDeclaration (store, cmd) {
  600. try {
  601. let $value = Promise.resolve(null);
  602. if(cmd instanceof Commands.ArrayDeclaration) {
  603. return this.executeArrayDeclaration(store, cmd);
  604. } else {
  605. if(cmd.initial !== null) {
  606. $value = this.evaluateExpression(store, cmd.initial);
  607. }
  608. return $value.then(vl => {
  609. let realValue = vl;
  610. let temp = null;
  611. if (vl !== null) {
  612. if(!vl.type.isCompatible(cmd.type)) {
  613. if(Config.enable_type_casting && Store.canImplicitTypeCast(cmd.type, vl.type)) {
  614. realValue = Store.doImplicitCasting(cmd.type, realValue);
  615. } else {
  616. const stringInfo = vl.type.stringInfo();
  617. const info = stringInfo[0];
  618. const exp_type_string_info = vl.type.stringInfo();
  619. const exp_type_info = exp_type_string_info[0];
  620. const exp = cmd.expression.toString();
  621. return Promise.reject(ProcessorErrorFactory.incompatible_types_full(info.type, info.dim, exp_type_info.type, exp_type_info.dim, exp, cmd.sourceInfo));
  622. }
  623. }
  624. temp = new StoreValue(cmd.type, realValue.get(), null, cmd.isConst);
  625. } else {
  626. temp = new StoreValue(cmd.type, null, null, cmd.isConst);
  627. }
  628. store.insertStore(cmd.id, temp);
  629. return store;
  630. });
  631. }
  632. } catch (e) {
  633. return Promise.reject(e);
  634. }
  635. }
  636. /**
  637. *
  638. * @param {Store} store
  639. * @param {Commands.ArrayDeclaration} cmd
  640. */
  641. executeArrayDeclaration (store, cmd) {
  642. const $lines = this.evaluateExpression(store, cmd.lines);
  643. const $columns = cmd.columns === null ? null: this.evaluateExpression(store, cmd.columns);
  644. return Promise.all([$lines, $columns]).then(([line_sv, column_sv]) => {
  645. if(!Types.INTEGER.isCompatible(line_sv.type)) {
  646. return Promise.reject(ProcessorErrorFactory.array_dimension_not_int_full(cmd.sourceInfo));
  647. }
  648. const line = line_sv.get().toNumber();
  649. if(line < 0) {
  650. return Promise.reject(ProcessorErrorFactory.array_dimension_not_positive_full(cmd.sourceInfo));
  651. }
  652. let column = null
  653. if (column_sv !== null) {
  654. if(!Types.INTEGER.isCompatible(column_sv.type)) {
  655. return Promise.reject(ProcessorErrorFactory.array_dimension_not_int_full(cmd.sourceInfo));
  656. }
  657. column = column_sv.get().toNumber();
  658. if(column < 0) {
  659. return Promise.reject(ProcessorErrorFactory.array_dimension_not_positive_full(cmd.sourceInfo));
  660. }
  661. }
  662. let $value = Promise.resolve(null);
  663. if(cmd.initial !== null) {
  664. // array can only be initialized by a literal....
  665. $value = this.evaluateArrayLiteral(store, cmd.initial, cmd.type, line, column);
  666. }
  667. return $value.then(vector_list => {
  668. let temp = null;
  669. if (vector_list !== null) {
  670. temp = new ArrayStoreValue(cmd.type, vector_list, line, column, null, cmd.isConst);
  671. } else {
  672. temp = new ArrayStoreValue(cmd.type, [], line, column, null, cmd.isConst);
  673. }
  674. store.insertStore(cmd.id, temp);
  675. return store;
  676. })
  677. });
  678. }
  679. async evaluateExpression (store, exp) {
  680. this.instruction_count += 1;
  681. if(this.instruction_count % Config.suspend_threshold == 0) {
  682. //every Config.suspend_threshold instruction should briefly delay its execution in order to allow the browser to process other things
  683. await Utils.sleep(5);
  684. }
  685. if (this.mode === Modes.ABORT) {
  686. throw LocalizedStrings.getMessage('aborted_execution');
  687. }
  688. if(this.instruction_count >= Config.max_instruction_count) {
  689. throw new Error("Número de instruções excedeu o limite definido. Verifique se seu código não possui laços infinitos ou muitas chamadas de funções recursivas.");
  690. }
  691. if (exp instanceof Expressions.UnaryApp) {
  692. return this.evaluateUnaryApp(store, exp);
  693. } else if (exp instanceof Expressions.InfixApp) {
  694. return this.evaluateInfixApp(store, exp);
  695. } else if (exp instanceof Expressions.ArrayAccess) {
  696. return this.evaluateArrayAccess(store, exp);
  697. } else if (exp instanceof Expressions.VariableLiteral) {
  698. return this.evaluateVariableLiteral(store, exp);
  699. } else if (exp instanceof Expressions.IntLiteral) {
  700. return this.evaluateLiteral(store, exp);
  701. } else if (exp instanceof Expressions.RealLiteral) {
  702. return this.evaluateLiteral(store, exp);
  703. } else if (exp instanceof Expressions.BoolLiteral) {
  704. return this.evaluateLiteral(store, exp);
  705. } else if (exp instanceof Expressions.StringLiteral) {
  706. return this.evaluateLiteral(store, exp);
  707. } else if (exp instanceof Expressions.ArrayLiteral) {
  708. throw new Error("Internal Error: The system should not eval an array literal.");
  709. } else if (exp instanceof Expressions.FunctionCall) {
  710. return this.evaluateFunctionCall(store, exp);
  711. }
  712. return null;
  713. }
  714. async evaluateFunctionCall (store, exp) {
  715. if(exp.isMainCall) {
  716. throw ProcessorErrorFactory.void_in_expression_full(LanguageDefinedFunction.getMainFunctionName(), exp.sourceInfo);
  717. }
  718. const func = this.findFunction(exp.id);
  719. if(Types.VOID.isCompatible(func.returnType)) {
  720. throw ProcessorErrorFactory.void_in_expression_full(exp.id, exp.sourceInfo);
  721. }
  722. if(this.function_call_stack.length >= Config.max_call_stack) {
  723. throw ProcessorErrorFactory.exceeded_recursive_calls(exp.sourceInfo);
  724. }
  725. this.function_call_stack.push(exp.sourceInfo);
  726. const sto = await this.runFunction(func, exp.actualParameters, store);
  727. if(sto.mode !== Modes.RETURN) {
  728. throw new Error("!!!Internal error: the function that was called did not have a return command or did not set the store mode properly -> "+exp.id);
  729. }
  730. const val = sto.applyStore('$');
  731. sto.destroy();
  732. this.function_call_stack.pop();
  733. return val;
  734. }
  735. /**
  736. *
  737. * @param {Store} store
  738. * @param {Expressions.ArrayLiteral} exp
  739. * @param {ArrayType} type
  740. */
  741. evaluateArrayLiteral (store, exp, type, lines, columns) {
  742. if(!exp.isVector) {
  743. if(columns == null) {
  744. return Promise.reject(new Error("This should never happen: Vector cannot be initialized by a matrix"));
  745. }
  746. const $matrix = this.evaluateMatrix(store, exp, type, lines, columns);
  747. return Promise.all($matrix).then(vectorList => {
  748. const values = vectorList.reduce((prev, next) => prev.concat(next), []);
  749. return Promise.resolve(values);
  750. });
  751. } else {
  752. if(columns != null) {
  753. return Promise.reject(new Error("This should never happen: Matrix cannot be initialized by a vector"));
  754. }
  755. return this.evaluateVector(store, exp, type, lines).then(list => {
  756. return Promise.resolve(list);
  757. });
  758. }
  759. }
  760. /**
  761. * Evalautes a list of literals and expression composing the vector
  762. * @param {Store} store
  763. * @param {Expressions.ArrayLiteral} exps
  764. * @param {ArrayType} type
  765. * @param {number} n_elements
  766. * @returns {Promise<StoreValue[]>} store object list
  767. */
  768. evaluateVector (store, exps, type, n_elements) {
  769. const values = exps.value;
  770. if(n_elements !== values.length) {
  771. return Promise.reject(ProcessorErrorFactory.invalid_number_elements_vector(n_elements, exps.toString(), values.length, exps.sourceInfo));
  772. }
  773. const actual_values = Promise.all(values.map( exp => this.evaluateExpression(store, exp)));
  774. return actual_values.then( values => {
  775. return values.map((v, index) => {
  776. if(!type.canAccept(v.type, 1)) {
  777. if (!Config.enable_type_casting || !Store.canImplicitTypeCast(type.innerType, v.type)) {
  778. // const stringInfo = v.type.stringInfo();
  779. // const info = stringInfo[0];
  780. const exp_str = values[index].toString();
  781. // TODO - fix error message
  782. return Promise.reject(ProcessorErrorFactory.invalid_array_literal_type_full(exp_str, values[index].sourceInfo));
  783. }
  784. const new_value = Store.doImplicitCasting(type.innerType, v);
  785. return new_value;
  786. }
  787. return v;
  788. });
  789. });
  790. }
  791. /**
  792. * Evaluates a list of array literals composing the matrix
  793. * @param {Store} store
  794. * @param {Expressions.ArrayLiteral} exps
  795. * @param {ArrayType} type
  796. * @returns {Promise<StoreValue[]>[]}
  797. */
  798. evaluateMatrix (store, exps, type, lines, columns) {
  799. const values = exps.value;
  800. if(values.length !== lines) {
  801. return Promise.reject(ProcessorErrorFactory.invalid_number_lines_matrix(lines,exps.toString(),values.length, exps.sourceInfo));
  802. }
  803. return values.map( vector => {
  804. const vec_type = new ArrayType(type.innerType, 1);
  805. return this.evaluateVector(store, vector, vec_type, columns);
  806. });
  807. }
  808. evaluateLiteral (_, exp) {
  809. return Promise.resolve(new StoreValue(exp.type, exp.value));
  810. }
  811. evaluateVariableLiteral (store, exp) {
  812. try {
  813. const val = store.applyStore(exp.id);
  814. return Promise.resolve(val);
  815. } catch (error) {
  816. return Promise.reject(error);
  817. }
  818. }
  819. evaluateArrayAccess (store, exp) {
  820. const mustBeArray = store.getStoreObject(exp.id);
  821. if (!(mustBeArray.type instanceof ArrayType)) {
  822. return Promise.reject(ProcessorErrorFactory.invalid_array_access_full(exp.id, exp.sourceInfo));
  823. }
  824. const $line = this.evaluateExpression(store, exp.line);
  825. const $column = this.evaluateExpression(store, exp.column);
  826. return Promise.all([$line, $column]).then(([line_sv, column_sv]) => {
  827. if(!Types.INTEGER.isCompatible(line_sv.type)) {
  828. return Promise.reject(ProcessorErrorFactory.array_dimension_not_int_full(exp.sourceInfo));
  829. }
  830. const line = line_sv.get().toNumber();
  831. let column = null;
  832. if(column_sv !== null) {
  833. if(!Types.INTEGER.isCompatible(column_sv.type)) {
  834. return Promise.reject(ProcessorErrorFactory.array_dimension_not_int_full(exp.sourceInfo));
  835. }
  836. column = column_sv.get().toNumber();
  837. }
  838. if (line >= mustBeArray.lines) {
  839. if(mustBeArray.isVector) {
  840. return Promise.reject(ProcessorErrorFactory.vector_line_outbounds_full(exp.id, line, mustBeArray.lines, exp.sourceInfo));
  841. } else {
  842. return Promise.reject(ProcessorErrorFactory.matrix_line_outbounds_full(exp.id, line, mustBeArray.lines, exp.sourceInfo));
  843. }
  844. } else if (line < 0) {
  845. return Promise.reject(ProcessorErrorFactory.array_dimension_not_positive_full(exp.sourceInfo));
  846. }
  847. if (column !== null && mustBeArray.columns === 0 ){
  848. return Promise.reject(ProcessorErrorFactory.vector_not_matrix_full(exp.id, exp.sourceInfo));
  849. }
  850. if(column !== null ) {
  851. if (column >= mustBeArray.columns) {
  852. return Promise.reject(ProcessorErrorFactory.matrix_column_outbounds_full(exp.id, column,mustBeArray.columns, exp.sourceInfo));
  853. } else if (column < 0) {
  854. return Promise.reject(ProcessorErrorFactory.array_dimension_not_positive_full(exp.sourceInfo));
  855. }
  856. }
  857. const result = mustBeArray.getAt(line, column);
  858. const type = mustBeArray.type.innerType;
  859. if(Array.isArray(result)) {
  860. const values = result.map((v, c) => {
  861. return new StoreValueAddress(type, v, line, c, mustBeArray.id, mustBeArray.readOnly);
  862. });
  863. return Promise.resolve(new ArrayStoreValue(new ArrayType(type, 1),
  864. values, mustBeArray.columns, null, mustBeArray.id, mustBeArray.readOnly))
  865. } else {
  866. return Promise.resolve(new StoreValueAddress(type, result, line, column, mustBeArray.id, mustBeArray.readOnly));
  867. }
  868. });
  869. }
  870. evaluateUnaryApp (store, unaryApp) {
  871. const $left = this.evaluateExpression(store, unaryApp.left);
  872. return $left.then( left => {
  873. const resultType = resultTypeAfterUnaryOp(unaryApp.op, left.type);
  874. if (Types.UNDEFINED.isCompatible(resultType)) {
  875. const stringInfo = left.type.stringInfo();
  876. const info = stringInfo[0];
  877. return Promise.reject(ProcessorErrorFactory.invalid_unary_op_full(unaryApp.op, info.type, info.dim, unaryApp.sourceInfo));
  878. }
  879. switch (unaryApp.op.ord) {
  880. case Operators.ADD.ord:
  881. return new StoreValue(resultType, left.get());
  882. case Operators.SUB.ord:
  883. return new StoreValue(resultType, left.get().negated());
  884. case Operators.NOT.ord:
  885. return new StoreValue(resultType, !left.get());
  886. default:
  887. return Promise.reject(new RuntimeError('!!!Critical Invalid UnaryApp '+ unaryApp.op));
  888. }
  889. });
  890. }
  891. evaluateInfixApp (store, infixApp) {
  892. const $left = this.evaluateExpression(store, infixApp.left);
  893. const $right = this.evaluateExpression(store, infixApp.right);
  894. return Promise.all([$left, $right]).then(values => {
  895. let shouldImplicitCast = false;
  896. const left = values[0];
  897. const right = values[1];
  898. let resultType = resultTypeAfterInfixOp(infixApp.op, left.type, right.type);
  899. if (Types.UNDEFINED.isCompatible(resultType)) {
  900. if (Config.enable_type_casting && Store.canImplicitTypeCast(left.type, right.type)) {
  901. shouldImplicitCast = true;
  902. } else {
  903. const stringInfoLeft = left.type.stringInfo();
  904. const infoLeft = stringInfoLeft[0];
  905. const stringInfoRight = right.type.stringInfo();
  906. const infoRight = stringInfoRight[0];
  907. return Promise.reject(ProcessorErrorFactory.invalid_infix_op_full(infixApp.op, infoLeft.type, infoLeft.dim,
  908. infoRight.type,infoRight.dim,infixApp.sourceInfo));
  909. }
  910. }
  911. let result = null;
  912. switch (infixApp.op.ord) {
  913. case Operators.ADD.ord: {
  914. if(Types.STRING.isCompatible(left.type)) {
  915. const rightStr = convertToString(right.get(), right.type);
  916. return new StoreValue(resultType, (left.get() + rightStr));
  917. } else if (Types.STRING.isCompatible(right.type)) {
  918. const leftStr = convertToString(left.get(), left.type);
  919. return new StoreValue(resultType, (leftStr + right.get()));
  920. } else {
  921. return new StoreValue(resultType, (left.get().plus(right.get())));
  922. }
  923. }
  924. case Operators.SUB.ord:
  925. return new StoreValue(resultType, (left.get().minus(right.get())));
  926. case Operators.MULT.ord: {
  927. result = left.get().times(right.get());
  928. return new StoreValue(resultType, result);
  929. }
  930. case Operators.DIV.ord: {
  931. if(right.get() == 0) {
  932. return Promise.reject(ProcessorErrorFactory.divsion_by_zero_full(infixApp.toString(), infixApp.sourceInfo));
  933. }
  934. if (Types.INTEGER.isCompatible(resultType))
  935. result = left.get().divToInt(right.get());
  936. else
  937. result = left.get().div(right.get());
  938. return new StoreValue(resultType, (result));
  939. }
  940. case Operators.MOD.ord: {
  941. let leftValue = left.get();
  942. let rightValue = right.get();
  943. if(shouldImplicitCast) {
  944. resultType = Types.INTEGER;
  945. leftValue = leftValue.trunc();
  946. rightValue = rightValue.trunc();
  947. }
  948. result = leftValue.modulo(rightValue);
  949. return new StoreValue(resultType, (result));
  950. }
  951. case Operators.GT.ord: {
  952. let leftValue = left.get();
  953. let rightValue = right.get();
  954. if (Types.STRING.isCompatible(left.type)) {
  955. result = leftValue.length > rightValue.length;
  956. } else {
  957. if (shouldImplicitCast) {
  958. resultType = Types.BOOLEAN;
  959. leftValue = leftValue.trunc();
  960. rightValue = rightValue.trunc();
  961. }
  962. result = leftValue.gt(rightValue);
  963. }
  964. return new StoreValue(resultType, result);
  965. }
  966. case Operators.GE.ord: {
  967. let leftValue = left.get();
  968. let rightValue = right.get();
  969. if (Types.STRING.isCompatible(left.type)) {
  970. result = leftValue.length >= rightValue.length;
  971. } else {
  972. if (shouldImplicitCast) {
  973. resultType = Types.BOOLEAN;
  974. leftValue = leftValue.trunc();
  975. rightValue = rightValue.trunc();
  976. }
  977. result = leftValue.gte(rightValue);
  978. }
  979. return new StoreValue(resultType, result);
  980. }
  981. case Operators.LT.ord: {
  982. let leftValue = left.get();
  983. let rightValue = right.get();
  984. if (Types.STRING.isCompatible(left.type)) {
  985. result = leftValue.length < rightValue.length;
  986. } else {
  987. if (shouldImplicitCast) {
  988. resultType = Types.BOOLEAN;
  989. leftValue = leftValue.trunc();
  990. rightValue = rightValue.trunc();
  991. }
  992. result = leftValue.lt(rightValue);
  993. }
  994. return new StoreValue(resultType, (result));
  995. }
  996. case Operators.LE.ord: {
  997. let leftValue = left.get();
  998. let rightValue = right.get();
  999. if (Types.STRING.isCompatible(left.type)) {
  1000. result = leftValue.length <= rightValue.length;
  1001. } else {
  1002. if (shouldImplicitCast) {
  1003. resultType = Types.BOOLEAN;
  1004. leftValue = leftValue.trunc();
  1005. rightValue = rightValue.trunc();
  1006. }
  1007. result = leftValue.lte(rightValue);
  1008. }
  1009. return new StoreValue(resultType, result);
  1010. }
  1011. case Operators.EQ.ord: {
  1012. let leftValue = left.get();
  1013. let rightValue = right.get();
  1014. if (Types.INTEGER.isCompatible(left.type) || Types.REAL.isCompatible(left.type)) {
  1015. if (shouldImplicitCast) {
  1016. resultType = Types.BOOLEAN;
  1017. leftValue = leftValue.trunc();
  1018. rightValue = rightValue.trunc();
  1019. }
  1020. result = leftValue.eq(rightValue);
  1021. } else {
  1022. result = leftValue === rightValue;
  1023. }
  1024. return new StoreValue(resultType, result);
  1025. }
  1026. case Operators.NEQ.ord: {
  1027. let leftValue = left.get();
  1028. let rightValue = right.get();
  1029. if (Types.INTEGER.isCompatible(left.type) || Types.REAL.isCompatible(left.type)) {
  1030. if (shouldImplicitCast) {
  1031. resultType = Types.BOOLEAN;
  1032. leftValue = leftValue.trunc();
  1033. rightValue = rightValue.trunc();
  1034. }
  1035. result = !leftValue.eq(rightValue);
  1036. } else {
  1037. result = leftValue !== rightValue;
  1038. }
  1039. return new StoreValue(resultType, result);
  1040. }
  1041. case Operators.AND.ord:
  1042. return new StoreValue(resultType, (left.get() && right.get()));
  1043. case Operators.OR.ord:
  1044. return new StoreValue(resultType, (left.get() || right.get()));
  1045. default:
  1046. return Promise.reject(new RuntimeError('!!!Critical Invalid InfixApp '+ infixApp.op));
  1047. }
  1048. });
  1049. }
  1050. }