فهرست منبع

Implement refference parameters for type array and its position addresses

Revert the modification that stored line, columns and values address list into a Location. These values are now stored inside the StoreObject
Lucas de Souza 5 سال پیش
والد
کامیت
92366d4a89

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

@@ -74,7 +74,6 @@ export class Store {
           return new StoreValueAddress(array_type.innerType, v, l, c++, array.id, array.readOnly);  
         }
       });
-      console.log("applyStore", values);
       result = new ArrayStoreValue(array_type, values, array.lines, array.columns, val.id, val.readOnly);
     } else {
       result = new StoreValue(val.type, val.value, val.id, val.readOnly);
@@ -104,7 +103,6 @@ export class Store {
         if(oldObj.isCompatible(array_value)) {
           if(oldObj.isVector) {
             array_value.get().forEach((val, index) => {
-              console.log(val);
               oldObj.setAt(val, index, undefined);
             });
           } else {
@@ -211,9 +209,6 @@ export class Store {
       newObj = new StoreObjectArrayRef(stoValue,0,0,false);
     } else if (stoValue instanceof ArrayStoreValue) {
       const columns = stoValue.isVector() ? 0 : stoValue.columns!;
-      const line_address = Location.allocate(stoValue.lines);
-      const column_address = Location.allocate(columns);
-      const values_address = Location.allocate([]);
       const addresses: number[] = [];
       const all_values = stoValue.get();
       if(all_values.length > 0) {
@@ -228,8 +223,7 @@ export class Store {
           addresses.push(Location.allocate(null));
         }
       }
-      Location.updateAddress(values_address, addresses);
-      newObj = new StoreObjectArray(stoValue.type as ArrayType, line_address, column_address, values_address, stoValue.isConst);
+      newObj = new StoreObjectArray(stoValue.type as ArrayType, stoValue.lines, columns, addresses, stoValue.isConst);
     } else {
       const loc_address = Location.allocate(stoValue.get());
       newObj = new StoreObject(stoValue.type, loc_address, stoValue.isConst);

+ 4 - 14
js/processor/store/storeObjectArray.ts

@@ -7,25 +7,15 @@ import { StoreValue } from './value/store_value';
 
 export class StoreObjectArray extends StoreObject {
 
-  constructor (type: ArrayType, private _lines:number, private _columns:number, loc_address: number, readOnly = false) {
-    super(type, loc_address, readOnly);
+  constructor (type: ArrayType, private _lines:number, private _columns:number, private loc_addresses: number[], readOnly = false) {
+    super(type, -1, readOnly);
   }
 
   get lines () {
-    const num = Location.find(this._lines)!.value;
-    return num;
-  }
-
-  getLineAddress () {
     return this._lines;
   }
 
   get columns () {
-    const num = Location.find(this._columns)!.value;
-    return num;
-  }
-
-  getColumnAddress () {
     return this._columns;
   }
 
@@ -74,11 +64,11 @@ export class StoreObjectArray extends StoreObject {
    * Returns the address that contains a list of all addresses of the values present in the array
    */
   get locAddress (): number {
-    return super.locAddress;
+    throw new Error("!!!Internal Error: Cannot invoke locAddress on StoreObjectArray");
   }
 
   protected get addresses (): number[] {
-    return Location.find(this.locAddress)!.value;
+    return this.loc_addresses;
   }
 
   getAt (line: number, column?: number): any {

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

@@ -6,18 +6,10 @@ import { IStoreValue } from "./value/istore_value";
 export class StoreObjectArrayRef extends StoreObjectArray {
 
   private refObj: String;
-  private indexes: number[];
-  private line_address: number;
-  private column_address?: number;
-  private source_matrix: boolean;
 
-  constructor(stoValue: ArrayStoreValueRef, line_address:number, column_address:number, source_matrix:boolean) {
-    super(stoValue.type, line_address, column_address, stoValue.getRefAddress(), false);
+  constructor(stoValue: ArrayStoreValueRef, lines:number, columns:number, source_matrix:boolean) {
+    super(stoValue.type, lines, columns,stoValue.getAddresses(), false);
     this.refObj = stoValue.id;
-    this.indexes = stoValue.getIndexes();
-    this.line_address = stoValue.line_address;
-    this.column_address = stoValue.column_address;
-    this.source_matrix = source_matrix;
   }
 
   get isRef () {
@@ -28,20 +20,6 @@ export class StoreObjectArrayRef extends StoreObjectArray {
     return this.refObj;
   }
 
-  updateValues (values: IStoreValue[]) {
-    if(this.indexes.length !== values.length) {
-      throw new Error("!!!Internal Error: updating ref array with a different number of values in relation to addresses");
-    }
-    const addresses = Location.find(this.locAddress)!.value as number[];
-    this.indexes.forEach(i => {
-      Location.updateAddress(addresses[i], values[i].get());
-    })
-  }
-
-  sourceIsMatrix () {
-    return this.source_matrix;
-  }
-
   destroy () {
     return false;
   }

+ 4 - 14
js/processor/store/value/array_store_value_ref.ts

@@ -7,25 +7,15 @@ export class ArrayStoreValueRef implements IStoreValue {
   public isConst = false;
 
   constructor(public type: ArrayType, private values: StoreValueAddress[],
-    public lines: number, public columns:number, public id:String,
-    public line_address: number, public column_address?: number) { }
+    private addresses: number[], public lines: number, public columns:number,
+    public id:String) { }
 
   get () {
     return this.values;
   }
 
-  getIndexes (): number[] {
-    return this.values.map(val => {
-      if(this.type.dimensions == 1) {
-        return val.line;
-      } else {
-        return val.line * this.lines + this.columns;
-      }
-    })
-  }
-
-  getRefAddress () : number {
-    return 0//this.values_address;
+  getAddresses (): number[] {
+    return this.addresses;
   }
 
   inStore () {