diff --git a/roms/stnp_flowcon5/auto_flowcon5.stnp b/roms/stnp_flowcon5/auto_flowcon5.stnp new file mode 100644 index 0000000..a512de4 --- /dev/null +++ b/roms/stnp_flowcon5/auto_flowcon5.stnp @@ -0,0 +1,23 @@ +#unconditional begin block test. + +#only really useful with conditional `top` statements, and code formatting. + +#unconditional `begin` statements, and their `end` statements only use +# 'zerosize', so no additional memory is used. + +#IMPORTANT: do note, that when `end` statements are paired with looped blocks, +# a `goto` is used to facilitate the loop, so the above blurb depends +# on context!! + +var kb=0 + +begin + prline press A to ask again, any other key to exit. + keyprompt + set kb + if kb,:A top + if kb,:a top + +end + +stop \ No newline at end of file diff --git a/roms/stnp_flowcon5/auto_flowcon5.trom b/roms/stnp_flowcon5/auto_flowcon5.trom new file mode 100644 index 0000000..14892e7 --- /dev/null +++ b/roms/stnp_flowcon5/auto_flowcon5.trom @@ -0,0 +1,66 @@ +-9459,1 +-9457,5 +0,0 +0,-94 +0,-121 +-9460,-106 +-9460,-104 +-9460,-117 +-9460,-103 +-9460,-103 +-9460,-95 +-9460,-94 +-9460,-95 +-9460,-102 +-9460,-107 +-9460,-95 +-9460,-121 +-9460,-103 +-9460,-111 +-9460,-95 +-9460,-121 +-9460,-115 +-9460,-121 +-9460,-113 +-9460,-108 +-9460,-30 +-9460,-95 +-9460,-121 +-9460,-108 +-9460,-97 +-9460,-95 +-9460,-107 +-9460,-102 +-9460,-114 +-9460,-117 +-9460,-104 +-9460,-95 +-9460,-111 +-9460,-117 +-9460,-97 +-9460,-95 +-9460,-102 +-9460,-107 +-9460,-95 +-9460,-117 +-9460,-98 +-9460,-113 +-9460,-102 +-9460,-29 +-9460,1 +-9840,0 +-9492,4 +-9490,4 +-9599,-9789 +-9496,-9839 +-9500,-9839 +-9499,-9838 +-9599,-9782 +-9600,-9781 +-9600,-9836 +-9500,-9839 +-9499,-9837 +-9599,-9777 +-9600,-9776 +-9600,-9836 +-9000,0 diff --git a/roms/stnp_flowcon5/x_auto_flowcon5__stnp.tasm b/roms/stnp_flowcon5/x_auto_flowcon5__stnp.tasm new file mode 100644 index 0000000..84c9d45 --- /dev/null +++ b/roms/stnp_flowcon5/x_auto_flowcon5__stnp.tasm @@ -0,0 +1,85 @@ +#SSTNPL COMPILER v0.4.0 +#header +head-rname=auto_flowcon5 +head-nspin=stdnsp +fopset1;>io.ttywr +fopset2;>io.packart +#stnp source file: (autogenerated from) "roms/stnp_flowcon5/auto_flowcon5.stnp +null;0;kb +null;:A;:A +null;:a;:a +#unconditional begin +zerosize;;flow--con-x-1--start +#prline +fopwri1;:p +fopwri1;:r +fopwri1;:e +fopwri1;:s +fopwri1;:s +fopwri1;:\s +fopwri1;:A +fopwri1;:\s +fopwri1;:t +fopwri1;:o +fopwri1;:\s +fopwri1;:a +fopwri1;:s +fopwri1;:k +fopwri1;:\s +fopwri1;:a +fopwri1;:g +fopwri1;:a +fopwri1;:i +fopwri1;:n +fopwri1;:\m +fopwri1;:\s +fopwri1;:a +fopwri1;:n +fopwri1;:y +fopwri1;:\s +fopwri1;:o +fopwri1;:t +fopwri1;:h +fopwri1;:e +fopwri1;:r +fopwri1;:\s +fopwri1;:k +fopwri1;:e +fopwri1;:y +fopwri1;:\s +fopwri1;:t +fopwri1;:o +fopwri1;:\s +fopwri1;:e +fopwri1;:x +fopwri1;:i +fopwri1;:t +fopwri1;:. +fopwri1;:\n +#keprompt: prompt for single keypress, continue only when keypress is received. +setreg2;0 +iowrite1;>io.ttyrd +ioread1;>io.ttyrd;keyprompt--loop-7-0 +gotoif;>keyprompt--loop-7-0 +#set(1) (used after 2-op math, asm code, or get) +datawrite1;>kb +#conditional flow control to-top-of-block (top) +dataread1;>kb +dataread2;>:A +gotoif;>goto--branch-9-0 +goto;>goto--jumper-9-0 +goto;>flow--con-x-1--start;goto--branch-9-0 + +zerosize;;goto--jumper-9-0 +#conditional flow control to-top-of-block (top) +dataread1;>kb +dataread2;>:a +gotoif;>goto--branch-10-0 +goto;>goto--jumper-10-0 +goto;>flow--con-x-1--start;goto--branch-10-0 + +zerosize;;goto--jumper-10-0 +zerosize;;flow--con-x-1 +#stop (shutdown vm) +stop +#END OF FILE diff --git a/textdocs/SSTNPL/command_overview.txt b/textdocs/SSTNPL/command_overview.txt index e963e23..6046f1b 100644 --- a/textdocs/SSTNPL/command_overview.txt +++ b/textdocs/SSTNPL/command_overview.txt @@ -213,9 +213,28 @@ Command documentation: has been met, loop exits as normal. - in conditional blocks, run conditional block from its start again unconditionally. + - in non-looped blocks, do the same as with conditional blocks. end : used in conjunction with conditional code blocks (made via the conditional operation 'begin') +--begin blocks: + + Begin blocks are mostly identical to conditional blocks, and are provided to allow use + of 'top' outside of conditional blocks and loops, or within specific scopes, + which can be more readable than using gotos in some cases. + + --Example (from roms/stnp_flowcon5): + + var kb=0 + begin + prline press A to ask again, any other key to exit. + keyprompt + set kb + if kb,:A top + if kb,:a top + + end + stop --for loops: NOTE: like conditional 'begin' statements, an 'end' statement is REQUIRED. @@ -279,7 +298,7 @@ Command documentation: top : - in looped blocks, run next loop iteration, or if loop end condition has been met, loop exits as normal. - - in conditional blocks, run conditional block from its start again + - in conditional blocks/non-looped blocks, run conditional block from its start again (bypasses conditional check that begun the block.) goto : ordinary goto. gsub : store next block (line) of code as return address. (same as normal gsub command) diff --git a/vmsystem/stnplib.py b/vmsystem/stnplib.py index 5a7c6d1..733dc08 100755 --- a/vmsystem/stnplib.py +++ b/vmsystem/stnplib.py @@ -143,6 +143,22 @@ def p3(self, args, keyword, lineno, nvars, valid_nvars, labels, tables, destobj) return +class in_fcon_begin: + def __init__(self): + self.keywords=["begin"] + def p0(self, args, keyword, lineno): + return 0, None + def p1(self, args, keyword, lineno): + return [] + def p2(self, args, keyword, lineno, nvars, valid_nvars, labels, tables): + fsyntax_begin(lineno, keyword) + + return 0, None + def p3(self, args, keyword, lineno, nvars, valid_nvars, labels, tables, destobj): + blockname=fcon_begin(loop=False) + destobj.write('''#unconditional begin +zerosize;;''' + fcon_loopback() + "\n") + return class in_fcon_end: def __init__(self): self.keywords=["end"] @@ -2373,6 +2389,7 @@ def __init__(self, srcobj, destpath, sourcepath, bpname): in_fcon_break(), in_fcon_end(), in_fcon_loop(), + in_fcon_begin(), in_fcon_top(), in_for(), in_condgoto(["if"], "gotoif", condmode=0),#conditionals