|
@@ -14,7 +14,7 @@ import { ProcessorErrorFactory } from '../error/processorErrorFactory';
|
|
|
**/
|
|
|
|
|
|
export function createSubstringFun () {
|
|
|
- const substringFun = (sto, _) => {
|
|
|
+ const substringFun = async (sto, _) => {
|
|
|
const str = sto.applyStore("str");
|
|
|
const start = sto.applyStore("start");
|
|
|
const end = sto.applyStore("end");
|
|
@@ -22,7 +22,7 @@ export function createSubstringFun () {
|
|
|
const temp = new StoreValue(Types.STRING, result);
|
|
|
sto.insertStore("$", temp);
|
|
|
sto.mode = Modes.RETURN;
|
|
|
- return Promise.resolve(sto);
|
|
|
+ return sto;
|
|
|
};
|
|
|
|
|
|
const block = new Commands.CommandBlock([], [new Commands.SysCall(substringFun)]);
|
|
@@ -35,12 +35,12 @@ export function createSubstringFun () {
|
|
|
}
|
|
|
|
|
|
export function createLengthFun () {
|
|
|
- const lengthFun = (sto, _) => {
|
|
|
+ const lengthFun = async (sto, _) => {
|
|
|
const str = sto.applyStore("str");
|
|
|
const temp = new StoreValue(Types.INTEGER, toInt(str.value.length));
|
|
|
sto.insertStore("$", temp);
|
|
|
sto.mode = Modes.RETURN;
|
|
|
- return Promise.resolve(sto);
|
|
|
+ return sto;
|
|
|
}
|
|
|
const block = new Commands.CommandBlock([], [new Commands.SysCall(lengthFun)]);
|
|
|
const func = new Commands.Function('$length', Types.INTEGER,
|
|
@@ -50,12 +50,12 @@ export function createLengthFun () {
|
|
|
}
|
|
|
|
|
|
export function createUppercaseFun () {
|
|
|
- const uppercaseFun = (sto, _) => {
|
|
|
+ const uppercaseFun = async (sto, _) => {
|
|
|
const str = sto.applyStore("str");
|
|
|
const temp = new StoreValue(Types.STRING, str.get().toUpperCase());
|
|
|
sto.insertStore("$", temp);
|
|
|
sto.mode = Modes.RETURN;
|
|
|
- return Promise.resolve(sto);
|
|
|
+ return sto;
|
|
|
}
|
|
|
const block = new Commands.CommandBlock([], [new Commands.SysCall(uppercaseFun)]);
|
|
|
const func = new Commands.Function('$uppercase', Types.STRING,
|
|
@@ -65,12 +65,12 @@ export function createUppercaseFun () {
|
|
|
}
|
|
|
|
|
|
export function createLowercaseFun () {
|
|
|
- const lowercaseFun = (sto, _) => {
|
|
|
+ const lowercaseFun = async (sto, _) => {
|
|
|
const str = sto.applyStore("str");
|
|
|
const temp = new StoreValue(Types.STRING, str.get().toLowerCase());
|
|
|
sto.insertStore("$", temp);
|
|
|
sto.mode = Modes.RETURN;
|
|
|
- return Promise.resolve(sto);
|
|
|
+ return sto;
|
|
|
}
|
|
|
const block = new Commands.CommandBlock([], [new Commands.SysCall(lowercaseFun)]);
|
|
|
const func = new Commands.Function('$lowercase', Types.STRING,
|
|
@@ -80,16 +80,17 @@ export function createLowercaseFun () {
|
|
|
}
|
|
|
|
|
|
export function createrCharAtFun () {
|
|
|
- const charAtFun = function (sto, _) {
|
|
|
+ const charAtFun = async function (sto, _) {
|
|
|
const str = sto.applyStore("str");
|
|
|
const idx = sto.applyStore("index");
|
|
|
if (idx.get().toNumber() < 0 || idx.get().toNumber() >= str.get().length) {
|
|
|
- return Promise.reject(ProcessorErrorFactory.invalid_string_index(idx.get().toNumber(), str.get(), this.function_call_stack.pop()));
|
|
|
+ throw ProcessorErrorFactory.invalid_string_index(idx.get().toNumber(), str.get(),
|
|
|
+ this.function_call_stack.pop());
|
|
|
}
|
|
|
const temp = new StoreValue(Types.STRING, str.get().charAt(idx.get().toNumber()));
|
|
|
sto.insertStore("$", temp);
|
|
|
sto.mode = Modes.RETURN;
|
|
|
- return Promise.resolve(sto);
|
|
|
+ return sto;
|
|
|
}
|
|
|
const block = new Commands.CommandBlock([], [new Commands.SysCall(charAtFun)]);
|
|
|
const func = new Commands.Function('$charAt', Types.STRING,
|