|
@@ -90,7 +90,7 @@ export class IVProgProcessor {
|
|
|
return this.initGlobal().then( _ => {
|
|
|
const mainFunc = this.findMainFunction();
|
|
|
if(mainFunc === null) {
|
|
|
- throw ProcessorErrorFactory.main_missing();
|
|
|
+ return Promise.reject(ProcessorErrorFactory.main_missing())
|
|
|
}
|
|
|
return this.runFunction(mainFunc, [], this.globalStore);
|
|
|
});
|
|
@@ -98,7 +98,7 @@ export class IVProgProcessor {
|
|
|
|
|
|
initGlobal () {
|
|
|
if(!this.checkContext(Context.BASE)) {
|
|
|
- throw ProcessorErrorFactory.invalid_global_var();
|
|
|
+ return Promise.reject(ProcessorErrorFactory.invalid_global_var())
|
|
|
}
|
|
|
return this.executeCommands(this.globalStore, this.ast.global);
|
|
|
}
|
|
@@ -145,7 +145,7 @@ export class IVProgProcessor {
|
|
|
LanguageDefinedFunction.getMainFunctionName() : callee_store.name;
|
|
|
|
|
|
if (formal_params.length != effective_params.length) {
|
|
|
- throw ProcessorErrorFactory.invalid_parameters_size(funcName, formal_params.length, effective_params.length);
|
|
|
+ return Promise.reject(ProcessorErrorFactory.invalid_parameters_size(funcName, formal_params.length, effective_params.length))
|
|
|
}
|
|
|
const promises$ = effective_params.map(actual_param => this.evaluateExpression(caller_store, actual_param));
|
|
|
return Promise.all(promises$).then(values => {
|
|
@@ -161,12 +161,12 @@ export class IVProgProcessor {
|
|
|
&& Store.canImplicitTypeCast(formalParameter.type, sto_value.type)) {
|
|
|
shouldTypeCast = true;
|
|
|
} else {
|
|
|
- throw ProcessorErrorFactory.invalid_parameter_type(funcName, exp.toString());
|
|
|
+ return Promise.reject(ProcessorErrorFactory.invalid_parameter_type(funcName, exp.toString()))
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if(formalParameter.byRef && !sto_value.inStore()) {
|
|
|
- throw ProcessorErrorFactory.invalid_ref(funcName, exp.toString());
|
|
|
+ return Promise.reject(ProcessorErrorFactory.invalid_ref(funcName, exp.toString()))
|
|
|
}
|
|
|
|
|
|
if(formalParameter.byRef) {
|
|
@@ -247,7 +247,7 @@ export class IVProgProcessor {
|
|
|
} else if (cmd instanceof Commands.SysCall) {
|
|
|
return this.executeSysCall(store, cmd);
|
|
|
} else {
|
|
|
- throw ProcessorErrorFactory.unknown_command(cmd.sourceInfo);
|
|
|
+ return Promise.reject(ProcessorErrorFactory.unknown_command(cmd.sourceInfo))
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -479,7 +479,7 @@ export class IVProgProcessor {
|
|
|
try {
|
|
|
const inStore = store.applyStore(cmd.id);
|
|
|
if(inStore.isConst) {
|
|
|
- throw ProcessorErrorFactory.invalid_const_assignment_full(cmd.id, cmd.sourceInfo);
|
|
|
+ return Promise.reject(ProcessorErrorFactory.invalid_const_assignment_full(cmd.id, cmd.sourceInfo))
|
|
|
}
|
|
|
const $value = this.evaluateExpression(store, cmd.expression);
|
|
|
return $value.then( vl => {
|
|
@@ -490,7 +490,10 @@ export class IVProgProcessor {
|
|
|
} else {
|
|
|
const stringInfo = inStore.type.stringInfo()
|
|
|
const info = stringInfo[0]
|
|
|
- return Promise.reject(ProcessorErrorFactory.incompatible_types_full(info.type, info.dim, cmd.sourceInfo));
|
|
|
+ const exp_type_string_info = vl.type.stringInfo();
|
|
|
+ const exp_type_info = exp_type_string_info[0];
|
|
|
+ const exp = cmd.expression.toString();
|
|
|
+ return Promise.reject(ProcessorErrorFactory.incompatible_types_full(info.type, info.dim, exp_type_info.type, exp_type_info.dim, exp, cmd.sourceInfo));
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -518,7 +521,7 @@ export class IVProgProcessor {
|
|
|
const mustBeArray = store.applyStore(cmd.id);
|
|
|
let used_dims = 0;
|
|
|
if(mustBeArray.isConst) {
|
|
|
- throw ProcessorErrorFactory.invalid_const_assignment_full(cmd.id, cmd.sourceInfo);
|
|
|
+ return Promise.reject(ProcessorErrorFactory.invalid_const_assignment_full(cmd.id, cmd.sourceInfo))
|
|
|
}
|
|
|
if(!(mustBeArray.type instanceof ArrayType)) {
|
|
|
return Promise.reject(ProcessorErrorFactory.invalid_array_access_full(cmd.id, cmd.sourceInfo));
|
|
@@ -548,7 +551,7 @@ export class IVProgProcessor {
|
|
|
return Promise.reject(ProcessorErrorFactory.matrix_line_outbounds_full(cmd.id, line, mustBeArray.lines, cmd.sourceInfo));
|
|
|
}
|
|
|
} else if (line < 0) {
|
|
|
- throw ProcessorErrorFactory.array_dimension_not_positive_full(cmd.sourceInfo);
|
|
|
+ return Promise.reject(ProcessorErrorFactory.array_dimension_not_positive_full(cmd.sourceInfo))
|
|
|
}
|
|
|
if (column != null && mustBeArray.columns === 0 ){
|
|
|
return Promise.reject(ProcessorErrorFactory.vector_not_matrix_full(cmd.id, cmd.sourceInfo));
|
|
@@ -557,7 +560,7 @@ export class IVProgProcessor {
|
|
|
if (column >= mustBeArray.columns) {
|
|
|
return Promise.reject(ProcessorErrorFactory.matrix_column_outbounds_full(cmd.id, column,mustBeArray.columns, cmd.sourceInfo));
|
|
|
} else if (column < 0) {
|
|
|
- throw ProcessorErrorFactory.array_dimension_not_positive_full(cmd.sourceInfo);
|
|
|
+ return Promise.reject(ProcessorErrorFactory.array_dimension_not_positive_full(cmd.sourceInfo))
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -566,8 +569,10 @@ export class IVProgProcessor {
|
|
|
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));
|
|
|
+ const exp_type_string_info = value.type.stringInfo();
|
|
|
+ const exp_type_info = exp_type_string_info[0];
|
|
|
+ const exp = cmd.expression.toString();
|
|
|
+ return Promise.reject(ProcessorErrorFactory.incompatible_types_full(info.type, info.dim, exp_type_info.type, exp_type_info.dim, exp, cmd.sourceInfo));
|
|
|
}
|
|
|
actualValue = Store.doImplicitCasting(mustBeArray.type.innerType, value);
|
|
|
}
|
|
@@ -575,14 +580,14 @@ export class IVProgProcessor {
|
|
|
const current_value = mustBeArray.getAt(line, column);
|
|
|
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");
|
|
|
+ const exp = cmd.expression.toString();
|
|
|
+ return Promise.reject(ProcessorErrorFactory.invalid_matrix_index_assign_full(cmd.id, line, current_value.lines, exp, actualValue.lines, cmd.sourceInfo))
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// mustBeArray.setAt(actualValue, line, column);
|
|
|
// store.updateStore(cmd.id, mustBeArray);
|
|
|
- return store.updateStoreArray(cmd.id,actualValue, line, column);
|
|
|
+ return store.updateStoreArray(cmd.id, actualValue, line, column);
|
|
|
});
|
|
|
}
|
|
|
|
|
@@ -610,7 +615,10 @@ export class IVProgProcessor {
|
|
|
} else {
|
|
|
const stringInfo = vl.type.stringInfo();
|
|
|
const info = stringInfo[0];
|
|
|
- return Promise.reject(ProcessorErrorFactory.incompatible_types_full(info.type, info.dim, cmd.sourceInfo));
|
|
|
+ const exp_type_string_info = vl.type.stringInfo();
|
|
|
+ const exp_type_info = exp_type_string_info[0];
|
|
|
+ const exp = cmd.expression.toString();
|
|
|
+ return Promise.reject(ProcessorErrorFactory.incompatible_types_full(info.type, info.dim, exp_type_info.type, exp_type_info.dim, exp, cmd.sourceInfo));
|
|
|
}
|
|
|
}
|
|
|
temp = new StoreValue(cmd.type, realValue.get(), null, cmd.isConst);
|
|
@@ -640,7 +648,7 @@ export class IVProgProcessor {
|
|
|
}
|
|
|
const line = line_sv.get().toNumber();
|
|
|
if(line < 0) {
|
|
|
- throw ProcessorErrorFactory.array_dimension_not_positive_full(cmd.sourceInfo);
|
|
|
+ return Promise.reject(ProcessorErrorFactory.array_dimension_not_positive_full(cmd.sourceInfo));
|
|
|
}
|
|
|
let column = null
|
|
|
if (column_sv !== null) {
|
|
@@ -649,7 +657,7 @@ export class IVProgProcessor {
|
|
|
}
|
|
|
column = column_sv.get().toNumber();
|
|
|
if(column < 0) {
|
|
|
- throw ProcessorErrorFactory.array_dimension_not_positive_full(cmd.sourceInfo);
|
|
|
+ return Promise.reject(ProcessorErrorFactory.array_dimension_not_positive_full(cmd.sourceInfo));
|
|
|
}
|
|
|
}
|
|
|
let $value = Promise.resolve(null);
|
|
@@ -706,7 +714,7 @@ export class IVProgProcessor {
|
|
|
const $newStore = this.runFunction(func, exp.actualParameters, store);
|
|
|
return $newStore.then( sto => {
|
|
|
if(sto.mode !== Modes.RETURN) {
|
|
|
- return Promise.reject(new Error("The function that was called did not have a return command: "+exp.id));
|
|
|
+ return Promise.reject(new Error("!!!Internal error: the function that was called did not have a return command or did not set the store mode properly -> "+exp.id));
|
|
|
}
|
|
|
const val = sto.applyStore('$');
|
|
|
sto.destroy();
|
|
@@ -723,7 +731,7 @@ export class IVProgProcessor {
|
|
|
evaluateArrayLiteral (store, exp, type, lines, columns) {
|
|
|
if(!exp.isVector) {
|
|
|
if(columns == null) {
|
|
|
- throw new Error("Vector cannot be initialized by a matrix");
|
|
|
+ return Promise.reject(new Error("This should never happen: Vector cannot be initialized by a matrix"));
|
|
|
}
|
|
|
const $matrix = this.evaluateMatrix(store, exp, type, lines, columns);
|
|
|
return Promise.all($matrix).then(vectorList => {
|
|
@@ -732,7 +740,7 @@ export class IVProgProcessor {
|
|
|
});
|
|
|
} else {
|
|
|
if(columns != null) {
|
|
|
- throw new Error("Matrix cannot be initialized by a vector");
|
|
|
+ return Promise.reject(new Error("This should never happen: Matrix cannot be initialized by a vector"));
|
|
|
}
|
|
|
return this.evaluateVector(store, exp, type, lines).then(list => {
|
|
|
return Promise.resolve(list);
|
|
@@ -751,8 +759,7 @@ export class IVProgProcessor {
|
|
|
evaluateVector (store, exps, type, n_elements) {
|
|
|
const values = exps.value;
|
|
|
if(n_elements !== values.length) {
|
|
|
- // TODO better error message
|
|
|
- throw new Error("invalid number of elements to array literal...");
|
|
|
+ return Promise.reject(ProcessorErrorFactory.invalid_number_elements_vector(n_elements, exps.toString(), values.length, exps.sourceInfo));
|
|
|
}
|
|
|
const actual_values = Promise.all(values.map( exp => this.evaluateExpression(store, exp)));
|
|
|
return actual_values.then( values => {
|
|
@@ -763,7 +770,7 @@ export class IVProgProcessor {
|
|
|
// const info = stringInfo[0];
|
|
|
const exp_str = values[index].toString();
|
|
|
// TODO - fix error message
|
|
|
- throw ProcessorErrorFactory.invalid_array_literal_type_full(exp_str, values[index].sourceInfo);
|
|
|
+ return Promise.reject(ProcessorErrorFactory.invalid_array_literal_type_full(exp_str, values[index].sourceInfo));
|
|
|
}
|
|
|
const new_value = Store.doImplicitCasting(type.innerType, v);
|
|
|
return new_value;
|
|
@@ -783,8 +790,7 @@ export class IVProgProcessor {
|
|
|
evaluateMatrix (store, exps, type, lines, columns) {
|
|
|
const values = exps.value;
|
|
|
if(values.length !== lines) {
|
|
|
- // TODO better error message
|
|
|
- throw new Error("Invalid number of lines to matrix literal...");
|
|
|
+ return Promise.reject(ProcessorErrorFactory.invalid_number_lines_matrix(lines,exps.toString(),values.length, exps.sourceInfo));
|
|
|
}
|
|
|
return values.map( vector => {
|
|
|
const vec_type = new ArrayType(type.innerType, 1);
|
|
@@ -832,7 +838,7 @@ export class IVProgProcessor {
|
|
|
return Promise.reject(ProcessorErrorFactory.matrix_line_outbounds_full(exp.id, line, mustBeArray.lines, exp.sourceInfo));
|
|
|
}
|
|
|
} else if (line < 0) {
|
|
|
- throw ProcessorErrorFactory.array_dimension_not_positive_full(exp.sourceInfo);
|
|
|
+ return Promise.reject(ProcessorErrorFactory.array_dimension_not_positive_full(exp.sourceInfo));
|
|
|
}
|
|
|
if (column !== null && mustBeArray.columns === 0 ){
|
|
|
return Promise.reject(ProcessorErrorFactory.vector_not_matrix_full(exp.id, exp.sourceInfo));
|
|
@@ -841,7 +847,7 @@ export class IVProgProcessor {
|
|
|
if (column >= mustBeArray.columns) {
|
|
|
return Promise.reject(ProcessorErrorFactory.matrix_column_outbounds_full(exp.id, column,mustBeArray.columns, exp.sourceInfo));
|
|
|
} else if (column < 0) {
|
|
|
- throw ProcessorErrorFactory.array_dimension_not_positive_full(exp.sourceInfo);
|
|
|
+ return Promise.reject(ProcessorErrorFactory.array_dimension_not_positive_full(exp.sourceInfo));
|
|
|
}
|
|
|
}
|
|
|
const result = mustBeArray.getAt(line, column);
|