Execute SNUSP/Tcl: Difference between revisions

m
Fixed syntax highlighting.
m (Fixed syntax highlighting.)
 
(5 intermediate revisions by 2 users not shown)
Line 1:
{{implementation|SNUSP}}{{collection|RCSNUSP}}[[Categoryimplementation of task:Tcl:RCSNUSP| ]]
ThisThese isare an[[Tcl]] interpreterinterpreters for [[SNUSP]]., and they Appearsappear to work with correct SNUSP programs.
 
Historically, the Bloated interpreter was evolved from the Modular interpreter, which in turn was evolved from the Core interpreter.
 
The most interesting feature of the '''Core''' interpreter is that it models the data store as an unbounded half-line (implemented in a [[Tcl]] list), dynamically extending it “on the right” to have as many cells as necessary. Also, when a failure occurs (going outside the program space, going before the start of the data store) then a multi-level “break” exception is thrown to make the main loop exit.
 
The '''Modular''' interpreter adds a basic stack; it is not very much more interesting than the Core interpreter but was immediately evolved from it in order to be able to read the majority of SNUSP programs that exist out there (this is the most common dialect).
 
The interpreter for '''Bloated''' interpreterSNUSP is considerably more complex, but most of this complexity is limited to the outer parts of the main loop (plus the change in addressing model for the data store, which becomes an unbounded quarter plane). The principal interesting feature is the use of a dictionary to hold the thread-specific values, together with the use of <tt>dict with</tt> to break these variables temporarily out into global variables for processing. The definition of the READ operation also had to change to become non-blocking so that non-availability of a character would not block other threads. In theory, this could have been done with native OS threads, but then the fairness constraints described in the SNUSP language definition would not have been respected. Thread termination is performed by simply deleting the thread's data from the dictionary of threads.
<br clear=all>
===Core [[SNUSP]]===
<langsyntaxhighlight lang="tcl">package require Tcl 8.5
 
# Basic I/O to read the program data and get ready for execution
Line 89:
Move
}
if {$last != 10} {puts ""}</langsyntaxhighlight>
 
===Modular [[SNUSP]]===
<langsyntaxhighlight lang="tcl">package require Tcl 8.5
 
# Basic I/O to read the program data and get ready for execution
Line 190:
Move
}
if {$last != 10} {puts ""}</langsyntaxhighlight>
 
===Bloated [[SNUSP]]===
<langsyntaxhighlight lang="tcl">package require Tcl 8.5
# Basic I/O to read the program data and get ready for execution
Line 327:
}
}
if {$last != 10} {puts ""}</langsyntaxhighlight>
===Test Code===
====Samples of Bloated SNUSP====
This prints out a random number of random length:
<pre><nowiki>$!/+++++++++%++++++++++++++++++++++++++++++++++++++++++++++++.!/-\
9,476

edits