ivprogProcessor.js 40 KB

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