Browse Source

Rework ivprog language internal functions to conform with the new return rules

Lucas de Souza 4 years ago
parent
commit
6c94612745

+ 4 - 0
js/ast/commands/arrayDeclaration.js

@@ -7,4 +7,8 @@ export class ArrayDeclaration extends Declaration {
     this.lines = lines;
     this.columns = columns;
   }
+
+  get isVector () {
+    return this.columns == null;
+  }
 }

+ 2 - 0
js/processor/ivprogProcessor.js

@@ -18,6 +18,7 @@ import { StoreValueRef } from './store/value/store_value_ref';
 import { ArrayStoreValue } from './store/value/array_store_value';
 import { ArrayStoreValueRef } from './store/value/array_store_value_ref';
 import { StoreValueAddress } from './store/value/store_value_address';
+import { StoreObjectArray } from './store/storeObjectArray';
 
 export class IVProgProcessor {
 
@@ -196,6 +197,7 @@ export class IVProgProcessor {
               const column = sto_value.column;
               ref = new StoreValueRef(sto_value.type, sto_value.get(),
                 realObj.getLocAddressOf(line, column), realObj.id);
+              ref.setReferenceDimension(realObj.type.dimensions);
             } else {
               ref = new StoreValueRef(sto_value.type, sto_value.get(), realObj.locAddress, realObj.id);
             }

+ 10 - 7
js/processor/lib/arrays.js

@@ -1,9 +1,9 @@
-import { StoreObject } from '../store/storeObject';
 import * as Commands from './../../ast/commands';
 import { Types } from './../../typeSystem/types';
 import { toInt } from "./../../typeSystem/parsers";
 import { ArrayType } from '../../typeSystem/array_type';
 import { Modes } from '../modes';
+import { StoreValue } from '../store/value/store_value';
 
 /**
  * num_elements
@@ -14,9 +14,10 @@ import { Modes } from '../modes';
 export function createNumElementsFun () {
   const numElementsFun = (sto, _) => {
     const vector  = sto.applyStore("vector");
-    const temp = new StoreObject(Types.INTEGER, toInt(vector.lines));
+    const temp = new StoreValue(Types.INTEGER, toInt(vector.lines));
     sto.mode = Modes.RETURN;
-    return Promise.resolve(sto.updateStore("$", temp));
+    sto.insertStore("$", temp);
+    return Promise.resolve(sto);
   }
 
   const block = new Commands.CommandBlock([],  [new Commands.SysCall(numElementsFun)]);
@@ -29,9 +30,10 @@ export function createNumElementsFun () {
 export function createMatrixLinesFun () {
   const matrixLinesFun = (sto, _) => {
     const matrix  = sto.applyStore("matrix");
-    const temp = new StoreObject(Types.INTEGER, toInt(matrix.lines));
+    const temp = new StoreValue(Types.INTEGER, toInt(matrix.lines));
     sto.mode = Modes.RETURN;
-    return Promise.resolve(sto.updateStore("$", temp));
+    sto.insertStore("$", temp);
+    return Promise.resolve(sto);
   }
 
   const block = new Commands.CommandBlock([],  [new Commands.SysCall(matrixLinesFun)]);
@@ -44,9 +46,10 @@ export function createMatrixLinesFun () {
 export function createMatrixColumnsFun () {
   const matrixColumnsFun = (sto, _) => {
     const matrix  = sto.applyStore("matrix");
-    const temp = new StoreObject(Types.INTEGER, toInt(matrix.columns));
+    const temp = new StoreValue(Types.INTEGER, toInt(matrix.columns));
     sto.mode = Modes.RETURN;
-    return Promise.resolve(sto.updateStore("$", temp));
+    sto.insertStore("$", temp);
+    return Promise.resolve(sto);
   }
 
   const block = new Commands.CommandBlock([],  [new Commands.SysCall(matrixColumnsFun)]);

+ 6 - 5
js/processor/lib/io.js

@@ -3,13 +3,12 @@ import { Modes } from '../modes';
 import {toInt, toString, toBool, toReal, convertToString} from './../../typeSystem/parsers';
 import { Types } from './../../typeSystem/types';
 import { ProcessorErrorFactory } from "./../error/processorErrorFactory";
-import { StoreObjectArrayAddressRef } from '../store/storeObjectArrayAddressRef';
 import { StoreValue } from '../store/value/store_value';
 
 export function createOutputFun () {
   const writeFunction = function (store, _) {
     const val = store.applyStore('p1');
-    this.output.sendOutput(convertToString(val.value, val.type));
+    this.output.sendOutput(convertToString(val.get(), val.type));
     store.mode = Modes.RETURN;
     return Promise.resolve(store);
   }
@@ -48,9 +47,11 @@ export function createInputFun () {
       } catch (_) {
         const stringInfo = typeToConvert.stringInfo()[0]
         const realObject = store.getStoreObject("p1");
-        if (realObject instanceof StoreObjectArrayAddressRef) {
-          const arrayInfo = realObject.address.getArrayObject().type.stringInfo()[0];
-          const error = ProcessorErrorFactory.invalid_read_type_array(text, stringInfo.type, stringInfo.dim, realObject.address.refID, arrayInfo.type, arrayInfo.dim);
+        console.log(realObject);
+        if (realObject.getReferenceDimension() > 0) {
+          const arrayInfo = realObject.type.stringInfo()[0];
+          const dim = realObject.getReferenceDimension();
+          const error = ProcessorErrorFactory.invalid_read_type_array(text, stringInfo.type, stringInfo.dim, realObject.getRefObj(), arrayInfo.type, dim);
           return Promise.reject(error);
         }
         const error = ProcessorErrorFactory.invalid_read_type(text, stringInfo.type, stringInfo.dim, realObject.getRefObj());

+ 53 - 32
js/processor/lib/lang.js

@@ -1,4 +1,3 @@
-import { StoreObject } from '../store/storeObject';
 import * as Commands from './../../ast/commands';
 import { Types } from './../../typeSystem/types';
 import { toReal, convertToString } from "./../../typeSystem/parsers";
@@ -7,6 +6,7 @@ import { RealLiteral, IntLiteral, BoolLiteral } from '../../ast/expressions';
 import { Modes } from '../modes';
 import { MultiType } from '../../typeSystem/multiType';
 import { ProcessorErrorFactory } from '../error/processorErrorFactory';
+import { StoreValue } from '../store/value/store_value';
 
 /**
  * 
@@ -22,17 +22,20 @@ import { ProcessorErrorFactory } from '../error/processorErrorFactory';
 export function createIsRealFun () {
   const isRealFun = (sto, _) => {
     const str = sto.applyStore("str");
-    const parser = IVProgParser.createParser(str.value);
+    const parser = IVProgParser.createParser(str.get());
     let result = false;
     try {
       const val = parser.parseTerm();
       if (val instanceof RealLiteral) {
         result = true;
       }
-    } catch (error) { }
-    const temp = new StoreObject(Types.BOOLEAN, result);
+    } catch (error) {
+      // ignore
+     }
+    const temp = new StoreValue(Types.BOOLEAN, result);
+    sto.insertStore("$", temp);
     sto.mode = Modes.RETURN;
-    return Promise.resolve(sto.updateStore("$", temp));
+    return Promise.resolve(sto);
   }
 
   const block = new Commands.CommandBlock([],  [new Commands.SysCall(isRealFun)]);
@@ -45,17 +48,20 @@ export function createIsRealFun () {
 export function createIsIntFun () {
   const isIntFun = (sto, _) => {
     const str = sto.applyStore("str");
-    const parser = IVProgParser.createParser(str.value);
+    const parser = IVProgParser.createParser(str.get());
     let result = false;
     try {
       const val = parser.parseTerm();
       if (val instanceof IntLiteral) {
         result = true;
       }
-    } catch (error) { }
-    const temp = new StoreObject(Types.BOOLEAN, result);
+    } catch { 
+      // ignore
+    }
+    const temp = new StoreValue(Types.BOOLEAN, result);
+    sto.insertStore("$", temp);
     sto.mode = Modes.RETURN;
-    return Promise.resolve(sto.updateStore("$", temp));
+    return Promise.resolve(sto);
   }
 
   const block = new Commands.CommandBlock([],  [new Commands.SysCall(isIntFun)]);
@@ -68,17 +74,20 @@ export function createIsIntFun () {
 export function createIsBoolFun () {
   const isBoolFun = (sto, _) => {
     const str = sto.applyStore("str");
-    const parser = IVProgParser.createParser(str.value);
+    const parser = IVProgParser.createParser(str.get());
     let result = false;
     try {
       const val = parser.parseTerm();
       if (val instanceof BoolLiteral) {
         result = true;
       }
-    } catch (error) { }
-    const temp = new StoreObject(Types.BOOLEAN, result);
+    } catch (error) { 
+      // ignore
+    }
+    const temp = new StoreValue(Types.BOOLEAN, result);
+    sto.insertStore("$", temp);
     sto.mode = Modes.RETURN;
-    return Promise.resolve(sto.updateStore("$", temp));
+    return Promise.resolve(sto);
   }
 
   const block = new Commands.CommandBlock([],  [new Commands.SysCall(isBoolFun)]);
@@ -91,24 +100,28 @@ export function createIsBoolFun () {
 export function createCastRealFun () {
   const castRealFun = (sto, _) => {
     const val = sto.applyStore("val");
-    let value = val.value;
+    let value = val.get();
     switch (val.type.ord) {
       case Types.INTEGER.ord: {
         value = value.toNumber();
-        const temp = new StoreObject(Types.REAL, toReal(value));
+        const temp = new StoreValue(Types.REAL, toReal(value));
+        sto.insertStore("$", temp);
         sto.mode = Modes.RETURN;
-        return Promise.resolve(sto.updateStore("$", temp));
+        return Promise.resolve(sto);
       }
       case Types.STRING.ord: {
         const parser = IVProgParser.createParser(value);
         try {
           const result = parser.parseTerm();
           if (result instanceof RealLiteral) {
-            const temp = new StoreObject(Types.REAL, result.value);
+            const temp = new StoreValue(Types.REAL, result.value);
+            sto.insertStore("$", temp);
             sto.mode = Modes.RETURN;
-            return Promise.resolve(sto.updateStore("$", temp));
+            return Promise.resolve(sto);
           }
-        } catch (error) { }
+        } catch (error) {
+          // ignore
+         }
       }
     }
     const typeStringInfoArray = Types.REAL.stringInfo();
@@ -126,24 +139,28 @@ export function createCastRealFun () {
 export function createCastIntFun () {
   const castIntFun = (sto, _) => {
     const val = sto.applyStore("val");
-    let value = val.value;
+    let value = val.get();
     switch (val.type.ord) {
       case Types.REAL.ord: {
         value = value.toNumber();
-        const temp = new StoreObject(Types.INTEGER, Math.floor(value));
+        const temp = new StoreValue(Types.INTEGER, Math.floor(value));
+        sto.insertStore("$", temp);
         sto.mode = Modes.RETURN;
-        return Promise.resolve(sto.updateStore("$", temp));
+        return Promise.resolve(sto);
       }
       case Types.STRING.ord: {
         const parser = IVProgParser.createParser(value);
         try {
           const result = parser.parseTerm();
           if (result instanceof IntLiteral) {
-            const temp = new StoreObject(Types.INTEGER, result.value);
+            const temp = new StoreValue(Types.INTEGER, result.value);
+            sto.insertStore("$", temp);
             sto.mode = Modes.RETURN;
-            return Promise.resolve(sto.updateStore("$", temp));
+            return Promise.resolve(sto);
           }
-        } catch (error) { }
+        } catch (error) { 
+          // ignore
+        }
       }
     }
     const typeStringInfoArray = Types.INTEGER.stringInfo();
@@ -161,16 +178,19 @@ export function createCastIntFun () {
 export function createCastBoolFun () {
   const castBoolFun = (sto, _) => {
     const str = sto.applyStore("str");
-    let value = str.value; 
+    const value = str.get(); 
     const parser = IVProgParser.createParser(value);
     try {
       const val = parser.parseTerm();
       if (val instanceof BoolLiteral) {
-        const temp = new StoreObject(Types.BOOLEAN, val.value);
+        const temp = new StoreValue(Types.BOOLEAN, val.value);
+        sto.insertStore("$", temp);
         sto.mode = Modes.RETURN;
-        return Promise.resolve(sto.updateStore("$", temp));
+        return Promise.resolve(sto);
       }
-    } catch (error) { }
+    } catch (error) { 
+      // ignore
+    }
     const typeStringInfoArray = Types.BOOLEAN.stringInfo();
     const typeInfo = typeStringInfoArray[0];
     return Promise.reject(ProcessorErrorFactory.invalid_type_conversion(value, typeInfo.type, typeInfo.dim));
@@ -186,10 +206,11 @@ export function createCastBoolFun () {
 export function createCastStringFun () {
   const castStringFun = function (store, _) {
     const val = store.applyStore('str');
-    let result = convertToString(val, val.type);
-    const temp = new StoreObject(Types.STRING, result);
+    const result = convertToString(val.get(), val.type);
+    const temp = new StoreValue(Types.STRING, result);
+    store.insertStore("$", temp);
     store.mode = Modes.RETURN;
-    return Promise.resolve(store.updateStore("$", temp));
+    return Promise.resolve(store);
   }
   const block = new Commands.CommandBlock([], [new Commands.SysCall(castStringFun)]);
   const func = new Commands.Function('$castString', Types.STRING,

+ 52 - 61
js/processor/lib/math.js

@@ -1,4 +1,3 @@
-import { StoreObject } from '../store/storeObject';
 import * as Commands from './../../ast/commands';
 import { Types } from './../../typeSystem/types';
 import { toReal } from "./../../typeSystem/parsers";
@@ -6,7 +5,7 @@ import { Decimal } from 'decimal.js';
 import { MultiType } from '../../typeSystem/multiType';
 import { ArrayType } from '../../typeSystem/array_type';
 import { Modes } from '../modes';
-import { Config } from '../../util/config';
+import { StoreValue } from '../store/value/store_value';
 
 /**
  * sin
@@ -29,7 +28,7 @@ function convertToRadians (degrees) {
 export function createSinFun () {
    const sinFun = (sto, _) => {
      const x = sto.applyStore('x');
-     const angle = x.value.mod(360);
+     const angle = x.get().mod(360);
      let result = null;
      if(angle.eq(90)) {
        result = new Decimal(1);
@@ -40,12 +39,10 @@ export function createSinFun () {
      } else {
        result = Decimal.sin(convertToRadians(angle));
      }
-    //  if(result.dp() > Config.decimalPlaces) {
-    //   result = new Decimal(result.toFixed(Config.decimalPlaces));
-    // }
-     const temp = new StoreObject(Types.REAL, result);
+     const temp = new StoreValue(Types.REAL, result);
+     sto.insertStore("$", temp);
      sto.mode = Modes.RETURN;
-     return Promise.resolve(sto.updateStore('$', temp));
+     return Promise.resolve(sto);
    };
 
   const block = new Commands.CommandBlock([],  [new Commands.SysCall(sinFun)]);
@@ -58,7 +55,7 @@ export function createSinFun () {
 export function createCosFun () {
   const cosFun = (sto, _) => {
     const x = sto.applyStore('x');
-    const angle = x.value.mod(360);
+    const angle = x.get().mod(360);
     let result = null;
     if(angle.eq(90)) {
       result = new Decimal(0);
@@ -68,12 +65,10 @@ export function createCosFun () {
       result = new Decimal(0)
     }
     result = Decimal.cos(convertToRadians(angle));
-    // if(result.dp() > Config.decimalPlaces) {
-    //   result = new Decimal(result.toFixed(Config.decimalPlaces));
-    // }
-    const temp = new StoreObject(Types.REAL, result);
+    const temp = new StoreValue(Types.REAL, result);
+    sto.insertStore("$", temp);
     sto.mode = Modes.RETURN;
-    return Promise.resolve(sto.updateStore('$', temp));
+    return Promise.resolve(sto);
   };
 
  const block = new Commands.CommandBlock([],  [new Commands.SysCall(cosFun)]);
@@ -86,17 +81,16 @@ export function createCosFun () {
 export function createTanFun () {
   const tanFun = (sto, _) => {
     const x = sto.applyStore('x');
-    const angle = x.value.mod(360);
+    const angle = x.get().mod(360);
     if(angle.eq(90) || angle.eq(270)) {
-      return Promise.reject("Tangent of "+x.value.toNumber()+"° is undefined.");
+      // TODO better error message
+      return Promise.reject("Tangent of "+x.get().toNumber()+"° is undefined.");
     }
-    let result = Decimal.tan(convertToRadians(angle));
-    // if(result.dp() > Config.decimalPlaces) {
-    //   result = new Decimal(result.toFixed(Config.decimalPlaces));
-    // }
-    const temp = new StoreObject(Types.REAL, result);
+    const result = Decimal.tan(convertToRadians(angle));
+    const temp = new StoreValue(Types.REAL, result);
+    sto.insertStore("$", temp);
     sto.mode = Modes.RETURN;
-    return Promise.resolve(sto.updateStore('$', temp));
+    return Promise.resolve(sto);
   };
 
  const block = new Commands.CommandBlock([],  [new Commands.SysCall(tanFun)]);
@@ -109,13 +103,11 @@ export function createTanFun () {
 export function createSqrtFun () {
   const sqrtFun = (sto, _) => {
     const x = sto.applyStore('x');
-    let result = x.value.sqrt();
-    // if(result.dp() > Config.decimalPlaces) {
-    //   result = new Decimal(result.toFixed(Config.decimalPlaces));
-    // }
-    const temp = new StoreObject(Types.REAL, result);
+    const result = x.get().sqrt();
+    const temp = new StoreValue(Types.REAL, result);
+    sto.insertStore("$", temp);
     sto.mode = Modes.RETURN;
-    return Promise.resolve(sto.updateStore('$', temp));
+    return Promise.resolve(sto);
   };
 
  const block = new Commands.CommandBlock([],  [new Commands.SysCall(sqrtFun)]);
@@ -129,13 +121,11 @@ export function createPowFun () {
   const powFun = (sto, _) => {
     const x = sto.applyStore('x');
     const y = sto.applyStore('y');
-    let result = x.value.pow(y.value);
-    // if(result.dp() > Config.decimalPlaces) {
-    //   result = new Decimal(result.toFixed(Config.decimalPlaces));
-    // }
-    const temp = new StoreObject(Types.REAL, result);
+    const result = x.get().pow(y.get());
+    const temp = new StoreValue(Types.REAL, result);
+    sto.insertStore("$", temp);
     sto.mode = Modes.RETURN;
-    return Promise.resolve(sto.updateStore('$', temp));
+    return Promise.resolve(sto);
   };
 
  const block = new Commands.CommandBlock([],  [new Commands.SysCall(powFun)]);
@@ -149,16 +139,15 @@ export function createPowFun () {
 export function createLogFun () {
   const logFun = (sto, _) => {
     const x = sto.applyStore('x');
-    if (x.value.isNegative()) {
+    if (x.get().isNegative()) {
+      // TODO better error message
       return Promise.reject(new Error("the value passed to log function cannot be negative"));
     }
-    let result = Decimal.log10(x.value);
-    // if(result.dp() > Config.decimalPlaces) {
-    //   result = new Decimal(result.toFixed(Config.decimalPlaces));
-    // }
-    const temp = new StoreObject(Types.REAL, result);
+    const result = Decimal.log10(x.get());
+    const temp = new StoreValue(Types.REAL, result);
+    sto.insertStore("$", temp);
     sto.mode = Modes.RETURN;
-    return Promise.resolve(sto.updateStore('$', temp));
+    return Promise.resolve(sto);
   };
 
  const block = new Commands.CommandBlock([],  [new Commands.SysCall(logFun)]);
@@ -171,9 +160,9 @@ export function createLogFun () {
 export function createAbsFun () {
   const absFun = (sto, _) => {
     const x = sto.applyStore('x');
-    const result = x.value.abs();
-    const temp = new StoreObject(x.type, result);
-    sto.updateStore('$', temp)
+    const result = x.get().abs();
+    const temp = new StoreValue(x.type, result);
+    sto.insertStore("$", temp);
     sto.mode = Modes.RETURN;
     return Promise.resolve(sto);
   };
@@ -188,10 +177,11 @@ export function createAbsFun () {
 export function createNegateFun () {
   const negateFun = (sto, _) => {
     const x = sto.applyStore('x');
-    const result = x.value.negated();
-    const temp = new StoreObject(x.type, result);
+    const result = x.get().negated();
+    const temp = new StoreValue(x.type, result);
+    sto.insertStore("$", temp);
     sto.mode = Modes.RETURN;
-    return Promise.resolve(sto.updateStore('$', temp));
+    return Promise.resolve(sto);
   };
 
  const block = new Commands.CommandBlock([],  [new Commands.SysCall(negateFun)]);
@@ -204,13 +194,11 @@ export function createNegateFun () {
 export function createInvertFun () {
   const invertFun = (sto, _) => {
     const x = sto.applyStore('x');
-    let result = toReal(1).dividedBy(x.value);
-    // if(result.dp() > Config.decimalPlaces) {
-    //   result = new Decimal(result.toFixed(Config.decimalPlaces));
-    // }
-    const temp = new StoreObject(Types.REAL, result);
+    const result = toReal(1).dividedBy(x.get());
+    const temp = new StoreValue(Types.REAL, result);
+    sto.insertStore("$", temp);
     sto.mode = Modes.RETURN;
-    return Promise.resolve(sto.updateStore('$', temp));
+    return Promise.resolve(sto);
   };
 
  const block = new Commands.CommandBlock([],  [new Commands.SysCall(invertFun)]);
@@ -223,11 +211,12 @@ export function createInvertFun () {
 export function createMaxFun () {
   const maxFun = (sto, _) => {
     const x = sto.applyStore('x');
-    const numbers = x.value.map(stoObj => stoObj.value);
+    const numbers = x.get().map(sto_addrs => sto_addrs.get());
     const result = Decimal.max(...numbers);
-    const temp = new StoreObject(x.type.innerType, result);
+    const temp = new StoreValue(x.type.innerType, result);
+    sto.insertStore("$", temp);
     sto.mode = Modes.RETURN;
-    return Promise.resolve(sto.updateStore('$', temp));
+    return Promise.resolve(sto);
   };
  const paramType = new ArrayType(new MultiType([Types.INTEGER, Types.REAL]), 1);
  const block = new Commands.CommandBlock([],  [new Commands.SysCall(maxFun)]);
@@ -240,11 +229,12 @@ export function createMaxFun () {
 export function createMinFun () {
   const minFun = (sto, _) => {
     const x = sto.applyStore('x');
-    const numbers = x.value.map(stoObj => stoObj.value);
+    const numbers = x.get().map(sto_addrs => sto_addrs.get());
     const result = Decimal.min(...numbers);
-    const temp = new StoreObject(x.type.innerType, result);
+    const temp = new StoreValue(x.type.innerType, result);
+    sto.insertStore("$", temp);
     sto.mode = Modes.RETURN;
-    return Promise.resolve(sto.updateStore('$', temp));
+    return Promise.resolve(sto);
   };
  const paramType = new ArrayType(new MultiType([Types.INTEGER, Types.REAL]), 1);
  const block = new Commands.CommandBlock([],  [new Commands.SysCall(minFun)]);
@@ -257,9 +247,10 @@ export function createMinFun () {
 export function createRandFun () {
   const randFun = (sto, _) => {
     const val = Math.random();
-    const result = new StoreObject(Types.REAL, new Decimal(val));
+    const temp = new StoreValue(Types.REAL, new Decimal(val));
+    sto.insertStore("$", temp);
     sto.mode = Modes.RETURN;
-    return Promise.resolve(sto.updateStore("$", result));
+    return Promise.resolve(sto);
   };
   const block = new Commands.CommandBlock([],  [new Commands.SysCall(randFun)]);
   const func = new Commands.Function('$rand', Types.REAL, [], block);

+ 19 - 13
js/processor/lib/strings.js

@@ -1,8 +1,8 @@
-import { StoreObject } from '../store/storeObject';
 import * as Commands from './../../ast/commands';
 import { Types } from './../../typeSystem/types';
 import { toInt } from "./../../typeSystem/parsers";
 import { Modes } from '../modes';
+import { StoreValue } from '../store/value/store_value';
 
 /*
 *  substring
@@ -17,10 +17,11 @@ export function createSubstringFun () {
     const str = sto.applyStore("str");
     const start = sto.applyStore("start");
     const end = sto.applyStore("end");
-    const result = str.value.substring(start.value, end.value);
-    const temp = new StoreObject(Types.STRING, result);
+    const result = str.get().substring(start.get(), end.get());
+    const temp = new StoreValue(Types.STRING, result);
+    sto.insertStore("$", temp);
     sto.mode = Modes.RETURN;
-    return Promise.resolve(sto.updateStore("$", temp));
+    return Promise.resolve(sto);
   };
 
   const block = new Commands.CommandBlock([],  [new Commands.SysCall(substringFun)]);
@@ -35,9 +36,10 @@ export function createSubstringFun () {
 export function createLengthFun () {
   const lengthFun = (sto, _) => {
     const str = sto.applyStore("str");
-    const temp = new StoreObject(Types.INTEGER, toInt(str.value.length));
+    const temp = new StoreValue(Types.INTEGER, toInt(str.value.length));
+    sto.insertStore("$", temp);
     sto.mode = Modes.RETURN;
-    return Promise.resolve(sto.updateStore("$", temp));
+    return Promise.resolve(sto);
   }
   const block = new Commands.CommandBlock([],  [new Commands.SysCall(lengthFun)]);
   const func = new Commands.Function('$length', Types.INTEGER,
@@ -49,9 +51,10 @@ export function createLengthFun () {
 export function createUppercaseFun () {
   const uppercaseFun = (sto, _) => {
     const str = sto.applyStore("str");
-    const temp = new StoreObject(Types.STRING, str.value.toUpperCase());
+    const temp = new StoreValue(Types.STRING, str.get().toUpperCase());
+    sto.insertStore("$", temp);
     sto.mode = Modes.RETURN;
-    return Promise.resolve(sto.updateStore("$", temp));
+    return Promise.resolve(sto);
   }
   const block = new Commands.CommandBlock([],  [new Commands.SysCall(uppercaseFun)]);
   const func = new Commands.Function('$uppercase', Types.STRING,
@@ -63,9 +66,10 @@ export function createUppercaseFun () {
 export function createLowercaseFun () {
   const lowercaseFun = (sto, _) => {
     const str = sto.applyStore("str");
-    const temp = new StoreObject(Types.STRING, str.value.toLowerCase());
+    const temp = new StoreValue(Types.STRING, str.get().toLowerCase());
+    sto.insertStore("$", temp);
     sto.mode = Modes.RETURN;
-    return Promise.resolve(sto.updateStore("$", temp));
+    return Promise.resolve(sto);
   }
   const block = new Commands.CommandBlock([],  [new Commands.SysCall(lowercaseFun)]);
   const func = new Commands.Function('$lowercase', Types.STRING,
@@ -78,12 +82,14 @@ export function createrCharAtFun () {
   const charAtFun = (sto, _) => {
     const str = sto.applyStore("str");
     const idx = sto.applyStore("index");
-    if (idx.value.toNumber() < 0 || idx.value.toNumber() >= str.value.length) {
+    if (idx.get().toNumber() < 0 || idx.get().toNumber() >= str.get().length) {
+      // TODO better error message
       return Promise.reject(new Error("invalid string position"));
     }
-    const temp = new StoreObject(Types.STRING, str.value.charAt(idx.value.toNumber()));
+    const temp = new StoreValue(Types.STRING, str.get().charAt(idx.get().toNumber()));
+    sto.insertStore("$", temp);
     sto.mode = Modes.RETURN;
-    return Promise.resolve(sto.updateStore("$", temp));
+    return Promise.resolve(sto);
   }
   const block = new Commands.CommandBlock([],  [new Commands.SysCall(charAtFun)]);
   const func = new Commands.Function('$charAt', Types.STRING,

+ 2 - 0
js/processor/semantic/semanticAnalyser.js

@@ -273,6 +273,7 @@ export class SemanticAnalyser {
   evaluateArrayLiteral (arrayDeclaration) {
     const type =  arrayDeclaration.type;
     const literal = arrayDeclaration.initial;
+    console.log(arrayDeclaration);
     if(arrayDeclaration.isVector) {
       this.evaluateVectorLiteralType(literal, type);
     } else {
@@ -557,6 +558,7 @@ export class SemanticAnalyser {
   }
 
   evaluateVectorLiteralType (literal, type) {
+    console.log(literal);
     for(let i = 0; i < literal.value.length; i+=1) {
       const exp = literal.value[i];
       const expType = this.evaluateExpressionType(exp);

+ 1 - 1
js/processor/store/store.ts

@@ -206,7 +206,7 @@ export class Store {
     if(stoValue instanceof StoreValueRef) {
       newObj = new StoreObjectRef(stoValue);
     } else if (stoValue instanceof ArrayStoreValueRef) {
-      newObj = new StoreObjectArrayRef(stoValue,0,0,false);
+      newObj = new StoreObjectArrayRef(stoValue, stoValue.lines, stoValue.columns);
     } else if (stoValue instanceof ArrayStoreValue) {
       const columns = stoValue.isVector() ? 0 : stoValue.columns!;
       const addresses: number[] = [];

+ 0 - 101
js/processor/store/storeObjectArrayAddress.js

@@ -1,101 +0,0 @@
-import { StoreObject } from './storeObject';
-import { StoreObjectArray } from './storeObjectArray';
-import { ArrayType } from '../../typeSystem/array_type';
-import { ProcessorErrorFactory } from '../error/processorErrorFactory';
-
-export class StoreObjectArrayAddress extends StoreObject {
-
-  constructor (refID, line, column, store) {
-    super(null, null, false);
-    this.refID = refID;
-    this.store = store;
-    this.line = line;
-    this.column = column;
-  }
-
-  get isRef () {
-    return false;
-  }
-
-  get inStore () {
-    return true;
-  }
-
-  get refValue () {
-    const refLine = this.store.applyStore(this.refID).value[this.line];
-    if(!refLine) {
-      if(this.getArrayObject().isVector) {
-        throw ProcessorErrorFactory.vector_line_outbounds(this.refID, this.line, this.getArrayObject().lines);
-      } else {
-        throw ProcessorErrorFactory.matrix_line_outbounds(this.refID, this.line, this.getArrayObject().lines);
-      }
-    }
-    if (this.column !== null) {
-      const refColumn = refLine.value[this.column];
-      if(!refColumn) {
-        if(this.getArrayObject().isVector) {
-          throw ProcessorErrorFactory.vector_not_matrix(this.refID);
-        } else {
-          throw ProcessorErrorFactory.matrix_column_outbounds(this.refID, this.column, this.getArrayObject().columns);
-        }
-      }
-      return refColumn;
-    }
-    return refLine;
-  }
-
-  get value () {
-    return this.refValue.value;
-  }
-
-  get type () {
-    return this.refValue.type;
-  }
-
-  get lines () {
-    if(!(this.type instanceof ArrayType)) {
-      return null;
-    }
-    return this.refValue.value.length;
-  }
-
-  get columns () {
-    switch (this.type.dimensions) {
-      case 2:
-        return this.refValue.value[0].value.length;
-      default:
-        return null;
-    }
-  }
-
-  getArrayObject () {
-    return this.store.applyStore(this.refID);
-  }
-
-  updateArrayObject (stoObj) {
-    const anArray =  this.getArrayObject();
-    const newArray = Object.assign(new StoreObjectArray(null,null,null), anArray);
-    if(!stoObj.type.isCompatible(this.type)) {
-      throw new Error(`Invalid operation: cannot assign the value given to ${this.refID}`);
-    } else if (this.type instanceof ArrayType && this.type.canAccept(stoObj.type)) {
-      throw new Error(`Invalid operation: cannot assign the value given to ${this.refID}`);
-    }
-    if (this.column !== null) {
-     newArray.value[this.line].value[this.column] = stoObj;
-     return newArray;
-    } else {
-     newArray.value[this.line] = stoObj;
-     return newArray;
-    }
-  }
-
-  isCompatible (another) {
-    if(this.type.isCompatible(another.type)) {
-      if(another.type instanceof ArrayType) {
-        return this.lines === another.lines && this.columns === another.columns;
-      } else {
-        this.refValue.isCompatible(another);
-      }
-    }
-  }
-}

+ 0 - 43
js/processor/store/storeObjectArrayAddressRef.js

@@ -1,43 +0,0 @@
-import { StoreObject } from './storeObject';
-import Decimal from 'decimal.js';
-
-export class StoreObjectArrayAddressRef extends StoreObject {
-
-  constructor (address) {
-    super(null, null, false);
-    this.address = address;
-  }
-
-  get isRef () {
-    return true;
-  }
-
-  get type () {
-    return this.address.type;
-  }
-
-  get value () {
-    return this.address.value;
-  }
-
-  get number () {
-    if (this.value instanceof Decimal) {
-      return this.value.toNumber();
-    } else {
-      return null;
-    }
-  }
-
-  getRefObj () {
-    return this.address.refValue;
-  }
-
-  updateRef (stoObj) {
-    const newArray = this.address.updateArrayObject(stoObj);
-    this.address.store.updateStore(this.address.refID, newArray);
-  }
-
-  isCompatible (another) {
-    return this.address.isCompatible(another);
-  }
-}

+ 6 - 0
js/processor/store/storeObjectRef.ts

@@ -4,6 +4,7 @@ import { StoreValueRef } from './value/store_value_ref';
 export class StoreObjectRef extends StoreObject {
 
   private refObj: String;
+  private reference_dimension: number;
 
   /**
    * 
@@ -12,6 +13,7 @@ export class StoreObjectRef extends StoreObject {
   constructor (stoValue: StoreValueRef) {
     super(stoValue.type, stoValue.getRefAddress(), false);
     this.refObj = stoValue.id!;
+    this.reference_dimension = stoValue.getReferenceDimension();
   }
 
   get isRef () {
@@ -22,6 +24,10 @@ export class StoreObjectRef extends StoreObject {
     return this.refObj;
   }
 
+  getReferenceDimension (): number {
+    return this.reference_dimension;
+  }
+
   destroy () {
     return false;
   }

+ 2 - 4
js/processor/store/store_object_array_ref.ts

@@ -1,14 +1,12 @@
 import { StoreObjectArray } from "./storeObjectArray";
 import { ArrayStoreValueRef } from "./value/array_store_value_ref";
-import { Location } from "../../memory/location";
-import { IStoreValue } from "./value/istore_value";
 
 export class StoreObjectArrayRef extends StoreObjectArray {
 
   private refObj: String;
 
-  constructor(stoValue: ArrayStoreValueRef, lines:number, columns:number, source_matrix:boolean) {
-    super(stoValue.type, lines, columns,stoValue.getAddresses(), false);
+  constructor(stoValue: ArrayStoreValueRef, lines:number, columns:number) {
+    super(stoValue.type, lines, columns, stoValue.getAddresses(), false);
     this.refObj = stoValue.id;
   }
 

+ 9 - 0
js/processor/store/value/store_value_ref.ts

@@ -4,6 +4,7 @@ import { Type } from "../../../typeSystem/type";
 export class StoreValueRef implements IStoreValue {
 
   public isConst = false;
+  private reference_dimesion = 0;
 
   constructor(public type: Type, public value: any, private loc_address: number, public id:String) {
 
@@ -20,4 +21,12 @@ export class StoreValueRef implements IStoreValue {
   inStore () {
     return this.id != null;
   }
+
+  getReferenceDimension (): number {
+    return this.reference_dimesion;
+  }
+
+  setReferenceDimension (dimension: number):void {
+    this.reference_dimesion = dimension;
+  }
 }