|
@@ -468,7 +468,7 @@ export class IVProgProcessor {
|
|
const info = stringInfo[0];
|
|
const info = stringInfo[0];
|
|
return Promise.reject(ProcessorErrorFactory.invalid_return_type_full(funcName, info.type, info.dim, cmd.sourceInfo));
|
|
return Promise.reject(ProcessorErrorFactory.invalid_return_type_full(funcName, info.type, info.dim, cmd.sourceInfo));
|
|
} else {
|
|
} else {
|
|
- const realValue = this.parseStoreObjectValue(vl);
|
|
|
|
|
|
+ const realValue = vl;
|
|
store.updateStore('$', realValue);
|
|
store.updateStore('$', realValue);
|
|
store.mode = Modes.RETURN;
|
|
store.mode = Modes.RETURN;
|
|
return Promise.resolve(store);
|
|
return Promise.resolve(store);
|
|
@@ -491,9 +491,12 @@ export class IVProgProcessor {
|
|
executeAssign (store, cmd) {
|
|
executeAssign (store, cmd) {
|
|
try {
|
|
try {
|
|
const inStore = store.applyStore(cmd.id);
|
|
const inStore = store.applyStore(cmd.id);
|
|
|
|
+ if(inStore.isConst) {
|
|
|
|
+ throw ProcessorErrorFactory.invalid_const_assignment_full(cmd.id, cmd.sourceInfo);
|
|
|
|
+ }
|
|
const $value = this.evaluateExpression(store, cmd.expression);
|
|
const $value = this.evaluateExpression(store, cmd.expression);
|
|
return $value.then( vl => {
|
|
return $value.then( vl => {
|
|
- let realValue = this.parseStoreObjectValue(vl);
|
|
|
|
|
|
+ let realValue = vl;
|
|
if(!inStore.type.isCompatible(realValue.type)) {
|
|
if(!inStore.type.isCompatible(realValue.type)) {
|
|
if(Config.enable_type_casting && Store.canImplicitTypeCast(inStore.type, vl.type)) {
|
|
if(Config.enable_type_casting && Store.canImplicitTypeCast(inStore.type, vl.type)) {
|
|
realValue = Store.doImplicitCasting(inStore.type, realValue);
|
|
realValue = Store.doImplicitCasting(inStore.type, realValue);
|
|
@@ -503,6 +506,14 @@ export class IVProgProcessor {
|
|
return Promise.reject(ProcessorErrorFactory.incompatible_types_full(info.type, info.dim, cmd.sourceInfo));
|
|
return Promise.reject(ProcessorErrorFactory.incompatible_types_full(info.type, info.dim, cmd.sourceInfo));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if(inStore instanceof ArrayStoreValue) {
|
|
|
|
+ const columns = realValue.columns == null ? 0 : realValue.columns;
|
|
|
|
+ if(inStore.lines !== realValue.lines || inStore.columns !== columns){
|
|
|
|
+ // TODO better error message
|
|
|
|
+ throw new Error("exp exceeds the number of elements of the vector");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
store.updateStore(cmd.id, realValue)
|
|
store.updateStore(cmd.id, realValue)
|
|
return store;
|
|
return store;
|
|
@@ -514,27 +525,30 @@ export class IVProgProcessor {
|
|
|
|
|
|
executeArrayIndexAssign (store, cmd) {
|
|
executeArrayIndexAssign (store, cmd) {
|
|
const mustBeArray = store.applyStore(cmd.id);
|
|
const mustBeArray = store.applyStore(cmd.id);
|
|
|
|
+ let used_dims = 0;
|
|
|
|
+ if(mustBeArray.isConst) {
|
|
|
|
+ throw ProcessorErrorFactory.invalid_const_assignment_full(cmd.id, cmd.sourceInfo);
|
|
|
|
+ }
|
|
if(!(mustBeArray.type instanceof ArrayType)) {
|
|
if(!(mustBeArray.type instanceof ArrayType)) {
|
|
return Promise.reject(ProcessorErrorFactory.invalid_array_access_full(cmd.id, cmd.sourceInfo));
|
|
return Promise.reject(ProcessorErrorFactory.invalid_array_access_full(cmd.id, cmd.sourceInfo));
|
|
}
|
|
}
|
|
const line$ = this.evaluateExpression(store, cmd.line);
|
|
const line$ = this.evaluateExpression(store, cmd.line);
|
|
const column$ = this.evaluateExpression(store, cmd.column);
|
|
const column$ = this.evaluateExpression(store, cmd.column);
|
|
const value$ = this.evaluateExpression(store, cmd.expression);
|
|
const value$ = this.evaluateExpression(store, cmd.expression);
|
|
- return Promise.all([line$, column$, value$]).then(results => {
|
|
|
|
- const lineSO = results[0];
|
|
|
|
- if(!Types.INTEGER.isCompatible(lineSO.type)) {
|
|
|
|
|
|
+ return Promise.all([line$, column$, value$]).then(([line_sv, column_sv, value]) => {
|
|
|
|
+ if(!Types.INTEGER.isCompatible(line_sv.type)) {
|
|
return Promise.reject(ProcessorErrorFactory.array_dimension_not_int_full(cmd.sourceInfo));
|
|
return Promise.reject(ProcessorErrorFactory.array_dimension_not_int_full(cmd.sourceInfo));
|
|
}
|
|
}
|
|
- const line = lineSO.get();
|
|
|
|
- const columnSO = results[1];
|
|
|
|
- let column = null
|
|
|
|
- if (columnSO !== null) {
|
|
|
|
- if(!Types.INTEGER.isCompatible(columnSO.type)) {
|
|
|
|
|
|
+ const line = line_sv.get().toNumber();
|
|
|
|
+ used_dims += 1;
|
|
|
|
+ let column = undefined;
|
|
|
|
+ if (column_sv != null) {
|
|
|
|
+ if(!Types.INTEGER.isCompatible(column_sv.type)) {
|
|
return Promise.reject(ProcessorErrorFactory.array_dimension_not_int_full(cmd.sourceInfo));
|
|
return Promise.reject(ProcessorErrorFactory.array_dimension_not_int_full(cmd.sourceInfo));
|
|
}
|
|
}
|
|
- column = columnSO.get();
|
|
|
|
|
|
+ column = column_sv.get().toNumber();
|
|
|
|
+ used_dims += 1;
|
|
}
|
|
}
|
|
- const value = this.parseStoreObjectValue(results[2]);
|
|
|
|
let actualValue = value;
|
|
let actualValue = value;
|
|
if (line >= mustBeArray.lines) {
|
|
if (line >= mustBeArray.lines) {
|
|
if(mustBeArray.isVector) {
|
|
if(mustBeArray.isVector) {
|
|
@@ -545,10 +559,10 @@ export class IVProgProcessor {
|
|
} else if (line < 0) {
|
|
} else if (line < 0) {
|
|
throw ProcessorErrorFactory.array_dimension_not_positive_full(cmd.sourceInfo);
|
|
throw ProcessorErrorFactory.array_dimension_not_positive_full(cmd.sourceInfo);
|
|
}
|
|
}
|
|
- if (column !== null && mustBeArray.columns === null ){
|
|
|
|
|
|
+ if (column != null && mustBeArray.columns === 0 ){
|
|
return Promise.reject(ProcessorErrorFactory.vector_not_matrix_full(cmd.id, cmd.sourceInfo));
|
|
return Promise.reject(ProcessorErrorFactory.vector_not_matrix_full(cmd.id, cmd.sourceInfo));
|
|
}
|
|
}
|
|
- if(column !== null ) {
|
|
|
|
|
|
+ if(column != null ) {
|
|
if (column >= mustBeArray.columns) {
|
|
if (column >= mustBeArray.columns) {
|
|
return Promise.reject(ProcessorErrorFactory.matrix_column_outbounds_full(cmd.id, column,mustBeArray.columns, cmd.sourceInfo));
|
|
return Promise.reject(ProcessorErrorFactory.matrix_column_outbounds_full(cmd.id, column,mustBeArray.columns, cmd.sourceInfo));
|
|
} else if (column < 0) {
|
|
} else if (column < 0) {
|
|
@@ -556,35 +570,29 @@ export class IVProgProcessor {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- const newArray = Object.assign(new StoreObjectArray(null,null,null), mustBeArray);
|
|
|
|
- if (column !== null) {
|
|
|
|
- if (!newArray.type.canAccept(value.type)) {
|
|
|
|
- if(!Config.enable_type_casting || !Store.canImplicitTypeCast(mustBeArray.type.innerType, value.type)) {
|
|
|
|
- const type = mustBeArray.type.innerType;
|
|
|
|
- const stringInfo = type.stringInfo();
|
|
|
|
- const info = stringInfo[0];
|
|
|
|
- // const exp = cmd.expression.toString();
|
|
|
|
- return Promise.reject(ProcessorErrorFactory.incompatible_types_full(info.type, info.dim, cmd.sourceInfo));
|
|
|
|
- }
|
|
|
|
- actualValue = Store.doImplicitCasting(mustBeArray.type.innerType, value);
|
|
|
|
|
|
+ if (!mustBeArray.type.canAccept(value.type, used_dims)) {
|
|
|
|
+ if(!Config.enable_type_casting || !Store.canImplicitTypeCast(mustBeArray.type.innerType, value.type)) {
|
|
|
|
+ const type = mustBeArray.type.innerType;
|
|
|
|
+ const stringInfo = type.stringInfo();
|
|
|
|
+ const info = stringInfo[0];
|
|
|
|
+ // const exp = cmd.expression.toString();
|
|
|
|
+ return Promise.reject(ProcessorErrorFactory.incompatible_types_full(info.type, info.dim, cmd.sourceInfo));
|
|
}
|
|
}
|
|
- newArray.value[line].value[column] = actualValue;
|
|
|
|
- store.updateStore(cmd.id, newArray);
|
|
|
|
- } else {
|
|
|
|
- if(!newArray.type.canAccept(value.type)) {
|
|
|
|
- if(!Config.enable_type_casting || !Store.canImplicitTypeCast(mustBeArray.type.innerType, value.type)) {
|
|
|
|
- const type = mustBeArray.type;
|
|
|
|
- const stringInfo = type.stringInfo();
|
|
|
|
- const info = stringInfo[0];
|
|
|
|
- const exp = cmd.expression.toString();
|
|
|
|
- return Promise.reject(ProcessorErrorFactory.incompatible_types_array_full(exp,info.type, info.dim-1, cmd.sourceInfo));
|
|
|
|
- }
|
|
|
|
- actualValue = Store.doImplicitCasting(mustBeArray.type.innerType, value);
|
|
|
|
|
|
+ actualValue = Store.doImplicitCasting(mustBeArray.type.innerType, value);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const current_value = mustBeArray.getAt(line, column);
|
|
|
|
+ console.log(current_value);
|
|
|
|
+ if(current_value instanceof ArrayStoreValue) {
|
|
|
|
+ if(current_value.lines !== actualValue.lines || current_value.columns !== actualValue.columns){
|
|
|
|
+ // TODO better error message
|
|
|
|
+ throw new Error("exp exceeds the number of elements of the vector");
|
|
}
|
|
}
|
|
- newArray.value[line] = actualValue;
|
|
|
|
- store.updateStore(cmd.id, newArray);
|
|
|
|
}
|
|
}
|
|
- return store;
|
|
|
|
|
|
+
|
|
|
|
+ // mustBeArray.setAt(actualValue, line, column);
|
|
|
|
+ // store.updateStore(cmd.id, mustBeArray);
|
|
|
|
+ return store.updateStoreArray(cmd.id,actualValue, line, column);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
@@ -762,7 +770,7 @@ export class IVProgProcessor {
|
|
const actual_values = Promise.all(values.map( exp => this.evaluateExpression(store, exp)));
|
|
const actual_values = Promise.all(values.map( exp => this.evaluateExpression(store, exp)));
|
|
return actual_values.then( values => {
|
|
return actual_values.then( values => {
|
|
return values.map((v, index) => {
|
|
return values.map((v, index) => {
|
|
- if(!type.canAccept(v.type)) {
|
|
|
|
|
|
+ if(!type.canAccept(v.type, 1)) {
|
|
if (!Config.enable_type_casting || !Store.canImplicitTypeCast(type.innerType, v.type)) {
|
|
if (!Config.enable_type_casting || !Store.canImplicitTypeCast(type.innerType, v.type)) {
|
|
// const stringInfo = v.type.stringInfo();
|
|
// const stringInfo = v.type.stringInfo();
|
|
// const info = stringInfo[0];
|
|
// const info = stringInfo[0];
|
|
@@ -804,11 +812,6 @@ export class IVProgProcessor {
|
|
try {
|
|
try {
|
|
const val = store.applyStore(exp.id);
|
|
const val = store.applyStore(exp.id);
|
|
return Promise.resolve(val);
|
|
return Promise.resolve(val);
|
|
- // if (val instanceof StoreObjectArray) {
|
|
|
|
- // return Promise.resolve(Object.assign(new StoreObjectArray(null,null,null,null), val));
|
|
|
|
- // } else {
|
|
|
|
- // return Promise.resolve(val);
|
|
|
|
- // }
|
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
return Promise.reject(error);
|
|
return Promise.reject(error);
|
|
}
|
|
}
|
|
@@ -856,20 +859,14 @@ export class IVProgProcessor {
|
|
const result = mustBeArray.getAt(line, column);
|
|
const result = mustBeArray.getAt(line, column);
|
|
const type = mustBeArray.type.innerType;
|
|
const type = mustBeArray.type.innerType;
|
|
if(Array.isArray(result)) {
|
|
if(Array.isArray(result)) {
|
|
- let l = 0;
|
|
|
|
- const values = result.map(v => {
|
|
|
|
- if(!Array.isArray(v)) {
|
|
|
|
- return new StoreValueAddress(type.innerType, v, l++, undefined, mustBeArray.id, mustBeArray.readOnly);
|
|
|
|
- } else {
|
|
|
|
- throw new Error("Indexing 3D structure....");
|
|
|
|
- }
|
|
|
|
|
|
+ const values = result.map((v, c) => {
|
|
|
|
+ return new StoreValueAddress(type, v, line, c, mustBeArray.id, mustBeArray.readOnly);
|
|
});
|
|
});
|
|
return Promise.resolve(new ArrayStoreValue(new ArrayType(type, 1),
|
|
return Promise.resolve(new ArrayStoreValue(new ArrayType(type, 1),
|
|
values, mustBeArray.columns, null, mustBeArray.id, mustBeArray.readOnly))
|
|
values, mustBeArray.columns, null, mustBeArray.id, mustBeArray.readOnly))
|
|
} else {
|
|
} else {
|
|
return Promise.resolve(new StoreValueAddress(type, result, line, column, mustBeArray.id, mustBeArray.readOnly));
|
|
return Promise.resolve(new StoreValueAddress(type, result, line, column, mustBeArray.id, mustBeArray.readOnly));
|
|
}
|
|
}
|
|
- //return Promise.resolve(mustBeArray.getAt(line, column));
|
|
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
@@ -932,9 +929,6 @@ export class IVProgProcessor {
|
|
return new StoreValue(resultType, (left.get().minus(right.get())));
|
|
return new StoreValue(resultType, (left.get().minus(right.get())));
|
|
case Operators.MULT.ord: {
|
|
case Operators.MULT.ord: {
|
|
result = left.get().times(right.get());
|
|
result = left.get().times(right.get());
|
|
- // if(result.dp() > Config.decimalPlaces) {
|
|
|
|
- // result = new Decimal(result.toFixed(Config.decimalPlaces));
|
|
|
|
- // }
|
|
|
|
return new StoreValue(resultType, result);
|
|
return new StoreValue(resultType, result);
|
|
}
|
|
}
|
|
case Operators.DIV.ord: {
|
|
case Operators.DIV.ord: {
|
|
@@ -942,9 +936,6 @@ export class IVProgProcessor {
|
|
result = left.get().divToInt(right.get());
|
|
result = left.get().divToInt(right.get());
|
|
else
|
|
else
|
|
result = left.get().div(right.get());
|
|
result = left.get().div(right.get());
|
|
- // if(result.dp() > Config.decimalPlaces) {
|
|
|
|
- // result = new Decimal(result.toFixed(Config.decimalPlaces));
|
|
|
|
- // }
|
|
|
|
return new StoreValue(resultType, (result));
|
|
return new StoreValue(resultType, (result));
|
|
}
|
|
}
|
|
case Operators.MOD.ord: {
|
|
case Operators.MOD.ord: {
|
|
@@ -956,9 +947,6 @@ export class IVProgProcessor {
|
|
rightValue = rightValue.trunc();
|
|
rightValue = rightValue.trunc();
|
|
}
|
|
}
|
|
result = leftValue.modulo(rightValue);
|
|
result = leftValue.modulo(rightValue);
|
|
- // if(result.dp() > Config.decimalPlaces) {
|
|
|
|
- // result = new Decimal(result.toFixed(Config.decimalPlaces));
|
|
|
|
- // }
|
|
|
|
return new StoreValue(resultType, (result));
|
|
return new StoreValue(resultType, (result));
|
|
}
|
|
}
|
|
case Operators.GT.ord: {
|
|
case Operators.GT.ord: {
|
|
@@ -1061,24 +1049,4 @@ export class IVProgProcessor {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
- parseStoreObjectValue (vl) {
|
|
|
|
- let realValue = vl;
|
|
|
|
- if(vl instanceof StoreObjectArrayAddress) {
|
|
|
|
- if(vl.type instanceof ArrayType) {
|
|
|
|
- switch(vl.type.dimensions) {
|
|
|
|
- case 1: {
|
|
|
|
- realValue = new StoreObjectArray(vl.type, vl.get().length, null, vl.get());
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- default: {
|
|
|
|
- throw new RuntimeError("Three dimensional array address...");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- realValue = new StoreValue(vl.type, vl.get());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return realValue;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
}
|
|
}
|