Execute SNUSP/F Sharp: Difference between revisions

m
Fixed syntax highlighting.
m (A little more work)
m (Fixed syntax highlighting.)
 
(2 intermediate revisions by 2 users not shown)
Line 1:
{{implementation|SNUSP}}{{collection|RCSNUSP}}[[Category:F Sharp]]
This is the [[F Sharp|F#]] implementation of the "modular" version. Perhaps I'll get around to bloated later. Allows infinite size data space to the left and right of the original data pointer. I originally mistook the meaning of '<code>,</code>' and had the user input an arbitrary number which I would place on the tape, but after looking at the sample multiplication program, realized that I was supposed to input the ascii value of the single key entered. Still, it seems like a good command to allow for reading an arbitrary value so I arbitrarily allocated '<code>~</code>' as the command for that purpose.
 
Bloated version below this modular version. Somehow this page has been set up so I can't seem to change the original comments to note this fact. Probably I'm just too dumb to know now.
<br clear=all>
===Modular SNUSP===
<langsyntaxhighlight lang="fsharp">open System
open System.Collections.Generic
 
Line 130:
while ip.Valid() do
interpretCmd() |> ignore
(!input).[!ptr]</langsyntaxhighlight>
===Bloated SNUSP===
Okay, I did the bloated version and made a few other changes. Using <code>*</code> rather than <code>~</code> for inputting a number because it's easy for <code>~</code> to get lost in the visual sea of characters that makes up the typical program. Also made separate classes for the engine and the IP. I allow for infinite data space in both directions and threads not waiting for input run while other threads are blocked on input. I tried this on all the programs I could find. There don't appear to be any which really utilize the 2D data space, but I tested it with some simple test programs and it seems okay.
<langsyntaxhighlight lang="fsharp">// Bloated RCSNUSP
open System
open System.Collections.Generic
Line 375:
let snusp = new SNUSP(pgm) // Create an engine
snusp.Execute() // and run the program with it
snusp.ReturnValue() // Return the return value</syntaxhighlight>
</lang>
 
===Example Inputs===
<langsyntaxhighlight lang="fsharp">let p1 = @"
read two characters ,>,==\ * /=================== ATOI ----------\
convert to integers /=/@</@=/ * // /===== ITOA ++++++++++\ /----------/
Line 419 ⟶ 418:
\!\/\/\/
")
printfn "value = %d" (RCSNUSP @"6=@@@+@+++++#")</syntaxhighlight>
</lang>
9,483

edits