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