|
@@ -6,11 +6,11 @@ import { ProcessorErrorFactory } from "./../error/processorErrorFactory";
|
|
|
import { StoreValue } from '../store/value/store_value';
|
|
|
|
|
|
export function createOutputFun () {
|
|
|
- const writeFunction = function (store, _) {
|
|
|
+ const writeFunction = async function (store, _) {
|
|
|
const val = store.applyStore('p1');
|
|
|
this.output.sendOutput(convertToString(val.get(), val.type));
|
|
|
store.mode = Modes.RETURN;
|
|
|
- return Promise.resolve(store);
|
|
|
+ return store;
|
|
|
}
|
|
|
const block = new Commands.CommandBlock([], [new Commands.SysCall(writeFunction)]);
|
|
|
const func = new Commands.Function('$write', Types.VOID,
|
|
@@ -20,51 +20,47 @@ export function createOutputFun () {
|
|
|
}
|
|
|
|
|
|
export function createInputFun () {
|
|
|
- const readFunction = function (store, _) {
|
|
|
- const request = new Promise((resolve, _) => {
|
|
|
- this.input.requestInput(resolve);
|
|
|
- });
|
|
|
- return request.then(text => {
|
|
|
- const typeToConvert = store.applyStore('p1').type;
|
|
|
- let type = null
|
|
|
- let result = null;
|
|
|
- try {
|
|
|
- if (typeToConvert.isCompatible(Types.INTEGER)) {
|
|
|
- result = toInt(text.trim()).trunc();
|
|
|
- type = Types.INTEGER;
|
|
|
- } else if (typeToConvert.isCompatible(Types.REAL)) {
|
|
|
- result = toReal(text.trim())
|
|
|
- type = Types.REAL;
|
|
|
- } else if (typeToConvert.isCompatible(Types.BOOLEAN)) {
|
|
|
- result = toBool(text.trim())
|
|
|
- type = Types.BOOLEAN;
|
|
|
- } else if (typeToConvert.isCompatible(Types.STRING)) {
|
|
|
- result = toString(text)
|
|
|
- type = Types.STRING;
|
|
|
- } else {
|
|
|
- return Promise.reject(new Error("!!!!Critical error: Unknown type in readFunction!!!!"));
|
|
|
- }
|
|
|
- } catch (_) {
|
|
|
- if(this.mode == Modes.ABORT) {
|
|
|
- store.mode = Modes.RETURN;
|
|
|
- return Promise.resolve(store);
|
|
|
- }
|
|
|
- const stringInfo = typeToConvert.stringInfo()[0]
|
|
|
- const realObject = store.getStoreObject("p1");
|
|
|
- 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, this.function_call_stack.pop());
|
|
|
- return Promise.reject(error);
|
|
|
- }
|
|
|
- const error = ProcessorErrorFactory.invalid_read_type(text, stringInfo.type, stringInfo.dim, realObject.getRefObj(), this.function_call_stack.pop());
|
|
|
- return Promise.reject(error);
|
|
|
+ const readFunction = async function (store, _) {
|
|
|
+ const text = await this.input.requestInput();
|
|
|
+ const typeToConvert = store.applyStore('p1').type;
|
|
|
+ let type = null
|
|
|
+ let result = null;
|
|
|
+ try {
|
|
|
+ if (typeToConvert.isCompatible(Types.INTEGER)) {
|
|
|
+ result = toInt(text.trim()).trunc();
|
|
|
+ type = Types.INTEGER;
|
|
|
+ } else if (typeToConvert.isCompatible(Types.REAL)) {
|
|
|
+ result = toReal(text.trim())
|
|
|
+ type = Types.REAL;
|
|
|
+ } else if (typeToConvert.isCompatible(Types.BOOLEAN)) {
|
|
|
+ result = toBool(text.trim())
|
|
|
+ type = Types.BOOLEAN;
|
|
|
+ } else if (typeToConvert.isCompatible(Types.STRING)) {
|
|
|
+ result = toString(text)
|
|
|
+ type = Types.STRING;
|
|
|
+ } else {
|
|
|
+ throw new Error("!!!!Critical error: Unknown type in readFunction!!!!");
|
|
|
}
|
|
|
- const stoValue = new StoreValue(type, result);
|
|
|
- store.updateStore('p1', stoValue);
|
|
|
- store.mode = Modes.RETURN;
|
|
|
- return Promise.resolve(store);
|
|
|
- });
|
|
|
+ } catch (_) {
|
|
|
+ if(this.mode == Modes.ABORT) {
|
|
|
+ store.mode = Modes.RETURN;
|
|
|
+ return store;
|
|
|
+ }
|
|
|
+ const stringInfo = typeToConvert.stringInfo()[0]
|
|
|
+ const realObject = store.getStoreObject("p1");
|
|
|
+ if (realObject.getReferenceDimension() > 0) {
|
|
|
+ const arrayInfo = realObject.type.stringInfo()[0];
|
|
|
+ const dim = realObject.getReferenceDimension();
|
|
|
+ throw ProcessorErrorFactory.invalid_read_type_array(text, stringInfo.type, stringInfo.dim,
|
|
|
+ realObject.getRefObj(), arrayInfo.type, dim, this.function_call_stack.pop());
|
|
|
+ }
|
|
|
+ throw ProcessorErrorFactory.invalid_read_type(text, stringInfo.type, stringInfo.dim,
|
|
|
+ realObject.getRefObj(), this.function_call_stack.pop());
|
|
|
+ }
|
|
|
+ const stoValue = new StoreValue(type, result);
|
|
|
+ store.updateStore('p1', stoValue);
|
|
|
+ store.mode = Modes.RETURN;
|
|
|
+ return store;
|
|
|
}
|
|
|
const block = new Commands.CommandBlock([], [new Commands.SysCall(readFunction)]);
|
|
|
const func = new Commands.Function('$read', Types.VOID,
|