diff --git a/tools/amalgamate-python.retro b/tools/amalgamate-python.retro new file mode 100644 index 0000000..b2abfd2 --- /dev/null +++ b/tools/amalgamate-python.retro @@ -0,0 +1,31 @@ +# Amalgamate + +The standard RETRO system is built using the Nga VM[1] and an +image file. The Python implementation consists of several files, +but it's nice to have a single file copy for easier deployment. +This tool combines the pieces into a single source file. + +Output will be written to stdout. + +## Code + +Extract and generate the single file source. + +~~~ +{{ + :include-file + ASCII:SPACE s:tokenize #1 a:fetch + 'vm/nga-python/ s:prepend '.py s:append here swap file:slurp here s:put ; + + :source:line + dup 'from_ s:begins-with? + [ include-file ] [ s:put nl ] choose ; + +---reveal--- + + :amalgamate + 'vm/nga-python/retro.py [ source:line ] file:for-each-line ; +}} + +amalgamate +~~~ diff --git a/vm/nga-python/retro.py b/vm/nga-python/retro.py index e6f1964..a404b93 100644 --- a/vm/nga-python/retro.py +++ b/vm/nga-python/retro.py @@ -25,7 +25,6 @@ # ------------------------------------------------------------- import os, sys, math, time, struct, random, datetime -from struct import pack, unpack from ClockDevice import Clock from RNGDevice import RNG @@ -241,24 +240,24 @@ class Retro: def i_add(self): t = self.stack.pop() v = self.stack.pop() - self.stack.push(unpack("=l", pack("=L", (t + v) & 0xFFFFFFFF))[0]) + self.stack.push(struct.unpack("=l", struct.pack("=L", (t + v) & 0xFFFFFFFF))[0]) def i_subtract(self): t = self.stack.pop() v = self.stack.pop() - self.stack.push(unpack("=l", pack("=L", (v - t) & 0xFFFFFFFF))[0]) + self.stack.push(stuct.unpack("=l", struct.pack("=L", (v - t) & 0xFFFFFFFF))[0]) def i_multiply(self): t = self.stack.pop() v = self.stack.pop() - self.stack.push(unpack("=l", pack("=L", (v * t) & 0xFFFFFFFF))[0]) + self.stack.push(struct.unpack("=l", struct.pack("=L", (v * t) & 0xFFFFFFFF))[0]) def i_divmod(self): t = self.stack.pop() v = self.stack.pop() b, a = self.div_mod(v, t) - self.stack.push(unpack("=l", pack("=L", a & 0xFFFFFFFF))[0]) - self.stack.push(unpack("=l", pack("=L", b & 0xFFFFFFFF))[0]) + self.stack.push(struct.unpack("=l", struct.pack("=L", a & 0xFFFFFFFF))[0]) + self.stack.push(struct.unpack("=l", struct.pack("=L", b & 0xFFFFFFFF))[0]) def i_and(self): t = self.stack.pop()