mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-06-12 23:54:04 +09:00
basic: DATA statement impl
This commit is contained in:
4
assets/disk0/home/basic/data1.bas
Normal file
4
assets/disk0/home/basic/data1.bas
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
1 DATA 7,9,8,2,6,3,1,4,5
|
||||||
|
10 FOR K=1 TO 13
|
||||||
|
20 READ L:PRINT L;" ";
|
||||||
|
30 NEXT:PRINT
|
||||||
6
assets/disk0/home/basic/data2.bas
Normal file
6
assets/disk0/home/basic/data2.bas
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
1 DATA "THE","QUICK","BROWN","FOX","JUMPS","OVER","A","LAZY","DOG"
|
||||||
|
10 FOR K=1 TO 9
|
||||||
|
20 PRINT DGET();" ";
|
||||||
|
30 NEXT:PRINT
|
||||||
|
40 RESTORE
|
||||||
|
50 GOTO 10
|
||||||
@@ -51,6 +51,7 @@ let cmdbuf = []; // index: line number
|
|||||||
let gotoLabels = {};
|
let gotoLabels = {};
|
||||||
let cmdbufMemFootPrint = 0;
|
let cmdbufMemFootPrint = 0;
|
||||||
let prompt = "Ok";
|
let prompt = "Ok";
|
||||||
|
let prescan = false;
|
||||||
|
|
||||||
/* if string can be FOR REAL cast to number */
|
/* if string can be FOR REAL cast to number */
|
||||||
function isNumable(s) {
|
function isNumable(s) {
|
||||||
@@ -1164,7 +1165,11 @@ if no arg text were given (e.g. "10 NEXT"), args will have zero length
|
|||||||
INDEX_BASE = lh|0;
|
INDEX_BASE = lh|0;
|
||||||
});
|
});
|
||||||
}},
|
}},
|
||||||
"DATA" : {f:function() { /*DATA must do nothing when encountered; they must be pre-processed*/ }},
|
"DATA" : {f:function(lnum, stmtnum, args) {
|
||||||
|
if (prescan) {
|
||||||
|
args.forEach(it => DATA_CONSTS.push(resolve(it)));
|
||||||
|
}
|
||||||
|
}},
|
||||||
/* Syopsis: MAP function, functor
|
/* Syopsis: MAP function, functor
|
||||||
*/
|
*/
|
||||||
"MAP" : {f:function(lnum, stmtnum, args) {
|
"MAP" : {f:function(lnum, stmtnum, args) {
|
||||||
@@ -1215,10 +1220,11 @@ if no arg text were given (e.g. "10 NEXT"), args will have zero length
|
|||||||
return args[args.length - 1];
|
return args[args.length - 1];
|
||||||
}},
|
}},
|
||||||
"LABEL" : {f:function(lnum, stmtnum, args) {
|
"LABEL" : {f:function(lnum, stmtnum, args) {
|
||||||
let labelname = args[0].troValue;
|
if (prescan) {
|
||||||
|
let labelname = args[0].troValue;
|
||||||
if (labelname === undefined) throw lang.syntaxfehler(lnum, "empty LABEL");
|
if (labelname === undefined) throw lang.syntaxfehler(lnum, "empty LABEL");
|
||||||
gotoLabels[labelname] = lnum;
|
gotoLabels[labelname] = lnum;
|
||||||
|
}
|
||||||
}},
|
}},
|
||||||
"ON" : {f:function(lnum, stmtnum, args) {
|
"ON" : {f:function(lnum, stmtnum, args) {
|
||||||
//args: functionName (string), testvalue (SyntaxTreeReturnObj), arg0 (SyntaxTreeReturnObj), arg1 (SyntaxTreeReturnObj), ...
|
//args: functionName (string), testvalue (SyntaxTreeReturnObj), arg0 (SyntaxTreeReturnObj), arg1 (SyntaxTreeReturnObj), ...
|
||||||
@@ -2978,6 +2984,9 @@ bF.new = function(args) { // NEW function
|
|||||||
if (args) cmdbuf = [];
|
if (args) cmdbuf = [];
|
||||||
bStatus.vars = initBvars();
|
bStatus.vars = initBvars();
|
||||||
gotoLabels = {};
|
gotoLabels = {};
|
||||||
|
DATA_CONSTS = [];
|
||||||
|
DATA_CURSOR = 0;
|
||||||
|
INDEX_BASE = 0;
|
||||||
};
|
};
|
||||||
bF.renum = function(args) { // RENUM function
|
bF.renum = function(args) { // RENUM function
|
||||||
var newcmdbuf = [];
|
var newcmdbuf = [];
|
||||||
@@ -3023,8 +3032,9 @@ bF.prescanStmts = ["DATA","LABEL"];
|
|||||||
bF.run = function(args) { // RUN function
|
bF.run = function(args) { // RUN function
|
||||||
bF.new(false);
|
bF.new(false);
|
||||||
|
|
||||||
// pre-build the trees
|
|
||||||
let programTrees = [];
|
let programTrees = [];
|
||||||
|
// pre-build the trees
|
||||||
|
prescan = true;
|
||||||
cmdbuf.forEach((linestr, linenum) => {
|
cmdbuf.forEach((linestr, linenum) => {
|
||||||
let trees = bF._interpretLine(linenum, linestr.trim());
|
let trees = bF._interpretLine(linenum, linestr.trim());
|
||||||
programTrees[linenum] = trees
|
programTrees[linenum] = trees
|
||||||
@@ -3037,6 +3047,11 @@ bF.run = function(args) { // RUN function
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
prescan = false;
|
||||||
|
|
||||||
|
if (!PROD && DBGON) {
|
||||||
|
serial.println("[BASIC] final DATA: "+DATA_CONSTS);
|
||||||
|
}
|
||||||
|
|
||||||
// actually execute the program
|
// actually execute the program
|
||||||
let lnum = 1;
|
let lnum = 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user