mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-06-10 06:54:04 +09:00
basic: function plotter update
This commit is contained in:
@@ -2617,8 +2617,8 @@ bF._troNOP = function(lnum, stmtnum) { return new SyntaxTreeReturnObj("null", un
|
|||||||
bF._executeSyntaxTree = function(lnum, stmtnum, syntaxTree, recDepth) {
|
bF._executeSyntaxTree = function(lnum, stmtnum, syntaxTree, recDepth) {
|
||||||
if (lnum === undefined || stmtnum === undefined) throw Error(`Line or statement number is undefined: (${lnum},${stmtnum})`);
|
if (lnum === undefined || stmtnum === undefined) throw Error(`Line or statement number is undefined: (${lnum},${stmtnum})`);
|
||||||
|
|
||||||
let _debugExec = true;
|
let _debugExec = false;
|
||||||
let _debugPrintCurrentLine = true;
|
let _debugPrintCurrentLine = false;
|
||||||
let recWedge = ">".repeat(recDepth) + " ";
|
let recWedge = ">".repeat(recDepth) + " ";
|
||||||
|
|
||||||
if (_debugExec || _debugPrintCurrentLine) serial.println(recWedge+"@@ EXECUTE @@");
|
if (_debugExec || _debugPrintCurrentLine) serial.println(recWedge+"@@ EXECUTE @@");
|
||||||
@@ -2870,7 +2870,7 @@ bF._executeAndGet = function(lnum, stmtnum, syntaxTree) {
|
|||||||
try {
|
try {
|
||||||
var execResult = bF._executeSyntaxTree(lnum, stmtnum, syntaxTree, 0);
|
var execResult = bF._executeSyntaxTree(lnum, stmtnum, syntaxTree, 0);
|
||||||
|
|
||||||
if (bF.parserDoDebugPrint) serial.println(`Line ${lnum} TRO: ${Object.entries(execResult)}`);
|
if (DBGON) serial.println(`Line ${lnum} TRO: ${Object.entries(execResult)}`);
|
||||||
|
|
||||||
return execResult.troNextLine;
|
return execResult.troNextLine;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,18 @@
|
|||||||
1 GOTO 1000
|
1 ZEROLINE=10
|
||||||
|
2 AMP=20
|
||||||
|
3 GOTO 1000
|
||||||
100 LABEL SINCQ:REM gets Sinc(Q)
|
100 LABEL SINCQ:REM gets Sinc(Q)
|
||||||
110 Q=SIN(I)/I
|
110 Q=IF I==0 THEN 1.0 ELSE SIN(I)/I
|
||||||
120 RETURN
|
120 RETURN
|
||||||
200 LABEL TOSPC
|
200 LABEL PLOTLINE:REM Converts 0-1 value into screen line
|
||||||
201 REM Converts 0-1 value into screen line
|
201 REM input is Q, results are stored to SQ
|
||||||
202 REM input is Q, results are stored to SQ
|
210 SQ=CHR(0)
|
||||||
210 SQ="I":REM currently empty string literals can't be used because of bug
|
220 FOR X=1 TO ZEROLINE+AMP
|
||||||
220 FOR X=1 TO 10 MAX 10+Q*20
|
230 SQ=SQ+(IF X==ROUND(ZEROLINE+Q*AMP) THEN "@" ELSE IF X==10 THEN "|" ELSE CHR(250))
|
||||||
230 SQ=SQ+(IF X==FIX(10+Q*20) THEN "@" ELSE IF X==10 THEN ":" ELSE " ")
|
|
||||||
240 NEXT
|
240 NEXT
|
||||||
250 RETURN
|
250 RETURN
|
||||||
1000 FOR I=1 TO 20
|
1000 FOR I=0 TO 20
|
||||||
1010 GOSUB SINCQ
|
1010 GOSUB SINCQ
|
||||||
1020 GOSUB TOSPC
|
1020 GOSUB PLOTLINE
|
||||||
1030 PRINT(SQ)
|
1030 PRINT(SQ)
|
||||||
1040 NEXT
|
1040 NEXT
|
||||||
|
|||||||
17
assets/sinc2.bas
Normal file
17
assets/sinc2.bas
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
1 ZEROLINE=10
|
||||||
|
2 AMP=20
|
||||||
|
10 DEFUN SINC(P)=IF P==0 THEN 1.0 ELSE SIN(P)/P
|
||||||
|
20 DEFUN TOCHAR(P,X)=IF (X==ROUND(ZEROLINE+P*AMP)) THEN "@" ELSE IF (X==ZEROLINE) THEN "|" ELSE CHR(250)
|
||||||
|
30 DEFUN SCONCAT(ACC,S)=ACC+S
|
||||||
|
40 DEFUN PLOTLINE(X)=FOLD(SCONCAT,CHR(0),MAP(TOCHAR<~X,1 TO ZEROLINE+AMP))
|
||||||
|
|
||||||
|
100 FOR I=0 TO 20
|
||||||
|
110 PRINT PLOTLINE(SINC(I))
|
||||||
|
120 NEXT
|
||||||
|
999 END
|
||||||
|
|
||||||
|
1000 REM Known bugs
|
||||||
|
1010 DEFUN PLOTLINE(F,X)=FOLD(SCONCAT,CHR(0),MAP(TOCHAR<~F(X),1 TO ZEROLINE+AMP))
|
||||||
|
1011 REM calling user-defined function within DEFUN is not working
|
||||||
|
|
||||||
|
1020 REM empty string literal "" is translated to number zero (another JS blunder)
|
||||||
Reference in New Issue
Block a user