mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-06-10 23:04:04 +09:00
basic:optional index at 1, LEFT, MID, RIGHT funs
This commit is contained in:
@@ -15,6 +15,8 @@ Test Programs:
|
|||||||
20 GOTO 10
|
20 GOTO 10
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
let INDEX_BASE = 0;
|
||||||
|
|
||||||
if (system.maxmem() < 8192) {
|
if (system.maxmem() < 8192) {
|
||||||
println("Out of memory. BASIC requires 8K or more User RAM");
|
println("Out of memory. BASIC requires 8K or more User RAM");
|
||||||
throw new Error("Out of memory");
|
throw new Error("Out of memory");
|
||||||
@@ -325,12 +327,12 @@ bStatus.getArrayIndexFun = function(lnum, arrayName, array) {
|
|||||||
return varArgNum(lnum, args, (dims) => {
|
return varArgNum(lnum, args, (dims) => {
|
||||||
let indexingstr = "";
|
let indexingstr = "";
|
||||||
dims.forEach((d) => {
|
dims.forEach((d) => {
|
||||||
indexingstr = `[${d}]${indexingstr}`;
|
indexingstr = `[${d-INDEX_BASE}]${indexingstr}`;
|
||||||
})
|
})
|
||||||
let indexedValue = eval(`array${indexingstr}`);
|
let indexedValue = eval(`array${indexingstr}`);
|
||||||
let index = dims[0];
|
let index = dims[0];
|
||||||
let parentArr = eval(`array${indexingstr.substring(0, indexingstr.length - 2 - (""+index).length)}`);
|
let parentArr = eval(`array${indexingstr.substring(0, indexingstr.length - 2 - (""+index).length)}`);
|
||||||
return {arrValue: indexedValue, arrObj: parentArr, arrIndex: index, arrName: arrayName}
|
return {arrValue: indexedValue, arrObj: parentArr, arrIndex: index-INDEX_BASE, arrName: arrayName}
|
||||||
});
|
});
|
||||||
|
|
||||||
//return {arrValue: indexedValue, arrObj: array, arrIndex: rsvArg0, arrName: arrayName}; //array[rsvArg0];
|
//return {arrValue: indexedValue, arrObj: array, arrIndex: rsvArg0, arrName: arrayName}; //array[rsvArg0];
|
||||||
@@ -344,7 +346,6 @@ bStatus.builtin = {
|
|||||||
if no args were given (e.g. "10 NEXT()"), args[0] will be: {troType: null, troValue: , troNextLine: 11}
|
if no args were given (e.g. "10 NEXT()"), args[0] will be: {troType: null, troValue: , troNextLine: 11}
|
||||||
if no arg text were given (e.g. "10 NEXT"), args will have zero length
|
if no arg text were given (e.g. "10 NEXT"), args will have zero length
|
||||||
*/
|
*/
|
||||||
"REM" : function(lnum, args) {},
|
|
||||||
"=" : function(lnum, args) {
|
"=" : function(lnum, args) {
|
||||||
if (args.length != 2) throw lang.syntaxfehler(lnum, args.length+lang.aG);
|
if (args.length != 2) throw lang.syntaxfehler(lnum, args.length+lang.aG);
|
||||||
var troValue = args[0].troValue;
|
var troValue = args[0].troValue;
|
||||||
@@ -728,6 +729,21 @@ if no arg text were given (e.g. "10 NEXT"), args will have zero length
|
|||||||
"SPC" : function(lnum, args) {
|
"SPC" : function(lnum, args) {
|
||||||
return oneArgNum(lnum, args, (lh) => " ".repeat(lh));
|
return oneArgNum(lnum, args, (lh) => " ".repeat(lh));
|
||||||
},
|
},
|
||||||
|
"LEFT$" : function(lnum, args) {
|
||||||
|
return twoArg(lnum, args, (str, len) => str.substring(0, len));
|
||||||
|
},
|
||||||
|
"MID$" : function(lnum, args) {
|
||||||
|
return threeArg(lnum, args, (str, start, len) => str.substring(start-INDEX_BASE, start-INDEX_BASE+len));
|
||||||
|
},
|
||||||
|
"RIGHT$" : function(lnum, args) {
|
||||||
|
return twoArg(lnum, args, (str, len) => str.substring(str.length - len, str.length));
|
||||||
|
},
|
||||||
|
"OPTIONBASE" : function(lnum, args) {
|
||||||
|
return oneArgNum(lnum, args, (lh) => {
|
||||||
|
if (lh != 0 && lh != 1) throw lang.syntaxfehler(line);
|
||||||
|
INDEX_BASE = lh|0;
|
||||||
|
});
|
||||||
|
},
|
||||||
};
|
};
|
||||||
Object.freeze(bStatus.builtin);
|
Object.freeze(bStatus.builtin);
|
||||||
let bF = {};
|
let bF = {};
|
||||||
@@ -1566,8 +1582,6 @@ bF._executeSyntaxTree = function(lnum, syntaxTree, recDepth) {
|
|||||||
if (syntaxTree.astLeaves.length > 1) throw "WTF";
|
if (syntaxTree.astLeaves.length > 1) throw "WTF";
|
||||||
return bF._executeSyntaxTree(lnum, syntaxTree.astLeaves[0], recDepth);
|
return bF._executeSyntaxTree(lnum, syntaxTree.astLeaves[0], recDepth);
|
||||||
}
|
}
|
||||||
else if (recDepth == 0 && syntaxTree.astValue.toUpperCase() == "REM")
|
|
||||||
return bF._troNOP(lnum);
|
|
||||||
else if (syntaxTree.astType == "function" || syntaxTree.astType == "op") {
|
else if (syntaxTree.astType == "function" || syntaxTree.astType == "op") {
|
||||||
if (_debugExec) serial.println(recWedge+"function|operator");
|
if (_debugExec) serial.println(recWedge+"function|operator");
|
||||||
if (_debugExec) serial.println(recWedge+syntaxTree.toString());
|
if (_debugExec) serial.println(recWedge+syntaxTree.toString());
|
||||||
@@ -1658,6 +1672,11 @@ bF._executeSyntaxTree = function(lnum, syntaxTree, recDepth) {
|
|||||||
bF._interpretLine = function(lnum, cmd) {
|
bF._interpretLine = function(lnum, cmd) {
|
||||||
var _debugprintHighestLevel = true;
|
var _debugprintHighestLevel = true;
|
||||||
|
|
||||||
|
if (cmd.toUpperCase().startsWith("REM")) {
|
||||||
|
if (_debugprintHighestLevel) serial.println(lnum+" "+cmd);
|
||||||
|
return lnum+1;
|
||||||
|
}
|
||||||
|
|
||||||
// TOKENISE
|
// TOKENISE
|
||||||
var tokenisedObject = bF._tokenise(lnum, cmd);
|
var tokenisedObject = bF._tokenise(lnum, cmd);
|
||||||
var tokens = tokenisedObject.tokens;
|
var tokens = tokenisedObject.tokens;
|
||||||
@@ -1751,7 +1770,7 @@ bF.run = function(args) { // RUN function
|
|||||||
do {
|
do {
|
||||||
if (cmdbuf[linenumber] !== undefined) {
|
if (cmdbuf[linenumber] !== undefined) {
|
||||||
oldnum = linenumber;
|
oldnum = linenumber;
|
||||||
linenumber = bF._interpretLine(linenumber, cmdbuf[linenumber]);
|
linenumber = bF._interpretLine(linenumber, cmdbuf[linenumber].trim());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
linenumber += 1;
|
linenumber += 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user