From 1af45748dec764502c790371e17287b638ac708a Mon Sep 17 00:00:00 2001 From: minjaesong Date: Thu, 3 Dec 2020 12:50:30 +0900 Subject: [PATCH] basic:for is mutable, test with formut.bas --- assets/basic.js | 7 +++++-- assets/formut.bas | 13 +++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 assets/formut.bas diff --git a/assets/basic.js b/assets/basic.js index 94ac4db..f273696 100644 --- a/assets/basic.js +++ b/assets/basic.js @@ -323,8 +323,11 @@ let ForGen = function(s,e,t) { // 0 + 1 <= 0 -> false } + // mutableVar: the actual number stored into the FOR-Variable, because BASIC's FOR-Var is mutable af // returns undefined if there is no next() - this.getNext = function() { + this.getNext = function(mutated) { + //if (mutated === undefined) throw "InternalError: parametre is missing"; + if (mutated !== undefined) this.current = mutated; this.current += this.step; return this.hasNext() ? this.current : undefined; } @@ -731,7 +734,7 @@ if no arg text were given (e.g. "10 NEXT"), args will have zero length var forVar = bStatus.vars["for var "+forVarname].bvLiteral; if (forVar instanceof ForGen) - bStatus.vars[forVarname].bvLiteral = forVar.getNext(); + bStatus.vars[forVarname].bvLiteral = forVar.getNext(bStatus.vars[forVarname].bvLiteral); else bStatus.vars[forVarname].bvLiteral = forVar.shift(); diff --git a/assets/formut.bas b/assets/formut.bas new file mode 100644 index 0000000..34b0786 --- /dev/null +++ b/assets/formut.bas @@ -0,0 +1,13 @@ +1 k=0 +2 goto 100 +20 k=1 +30 a=10 +40 return +100 for a=5 to 1 step -1 +110 print a +120 if a==3 and k==0 then gosub 20 +130 next +140 print "==" +150 print a +1000 rem expected output according to gw-basic: +1001 rem 5 4 3 9 8 7 6 5 4 3 2 1 == 0