From cdaa2a718d3b886af6f91599e488962a9c27453c Mon Sep 17 00:00:00 2001 From: minjaesong Date: Sun, 27 Dec 2020 16:32:10 +0900 Subject: [PATCH] basic: DATA statement impl --- assets/disk0/home/basic/data1.bas | 4 ++++ assets/disk0/home/basic/data2.bas | 6 ++++++ assets/disk0/tbas/basic.js | 27 +++++++++++++++++++++------ 3 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 assets/disk0/home/basic/data1.bas create mode 100644 assets/disk0/home/basic/data2.bas diff --git a/assets/disk0/home/basic/data1.bas b/assets/disk0/home/basic/data1.bas new file mode 100644 index 0000000..3bbf1b0 --- /dev/null +++ b/assets/disk0/home/basic/data1.bas @@ -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 diff --git a/assets/disk0/home/basic/data2.bas b/assets/disk0/home/basic/data2.bas new file mode 100644 index 0000000..02d005b --- /dev/null +++ b/assets/disk0/home/basic/data2.bas @@ -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 diff --git a/assets/disk0/tbas/basic.js b/assets/disk0/tbas/basic.js index 6a78e2d..908551e 100644 --- a/assets/disk0/tbas/basic.js +++ b/assets/disk0/tbas/basic.js @@ -51,6 +51,7 @@ let cmdbuf = []; // index: line number let gotoLabels = {}; let cmdbufMemFootPrint = 0; let prompt = "Ok"; +let prescan = false; /* if string can be FOR REAL cast to number */ 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; }); }}, -"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 */ "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]; }}, "LABEL" : {f:function(lnum, stmtnum, args) { - let labelname = args[0].troValue; - - if (labelname === undefined) throw lang.syntaxfehler(lnum, "empty LABEL"); - gotoLabels[labelname] = lnum; + if (prescan) { + let labelname = args[0].troValue; + if (labelname === undefined) throw lang.syntaxfehler(lnum, "empty LABEL"); + gotoLabels[labelname] = lnum; + } }}, "ON" : {f:function(lnum, stmtnum, args) { //args: functionName (string), testvalue (SyntaxTreeReturnObj), arg0 (SyntaxTreeReturnObj), arg1 (SyntaxTreeReturnObj), ... @@ -2978,6 +2984,9 @@ bF.new = function(args) { // NEW function if (args) cmdbuf = []; bStatus.vars = initBvars(); gotoLabels = {}; + DATA_CONSTS = []; + DATA_CURSOR = 0; + INDEX_BASE = 0; }; bF.renum = function(args) { // RENUM function var newcmdbuf = []; @@ -3023,8 +3032,9 @@ bF.prescanStmts = ["DATA","LABEL"]; bF.run = function(args) { // RUN function bF.new(false); - // pre-build the trees let programTrees = []; + // pre-build the trees + prescan = true; cmdbuf.forEach((linestr, linenum) => { let trees = bF._interpretLine(linenum, linestr.trim()); 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 let lnum = 1;