Skip to content

Commit

Permalink
Add unconditional begin statement to SSTNPL, and a basic test rom for…
Browse files Browse the repository at this point in the history
… it.
  • Loading branch information
ThomasTheSpaceFox committed Mar 17, 2021
1 parent 96f160e commit 52b9b7b
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 1 deletion.
23 changes: 23 additions & 0 deletions roms/stnp_flowcon5/auto_flowcon5.stnp
Original file line number Diff line number Diff line change
@@ -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
66 changes: 66 additions & 0 deletions roms/stnp_flowcon5/auto_flowcon5.trom

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

85 changes: 85 additions & 0 deletions roms/stnp_flowcon5/x_auto_flowcon5__stnp.tasm

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 20 additions & 1 deletion textdocs/SSTNPL/command_overview.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions vmsystem/stnplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 52b9b7b

Please sign in to comment.