mirror of
https://git.sr.ht/~crc_/retroforth
synced 2024-11-16 19:48:56 +01:00
toolchain: add amalagamate tool for the Python implementation
FossilOrigin-Name: 2d0d2155c6aa3695d72dc2c594dd26200c7660839b4d66449d52696a91e6ce6d
This commit is contained in:
parent
d185b6e423
commit
cf5df015e7
2 changed files with 36 additions and 6 deletions
31
tools/amalgamate-python.retro
Normal file
31
tools/amalgamate-python.retro
Normal file
|
@ -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
|
||||||
|
~~~
|
|
@ -25,7 +25,6 @@
|
||||||
# -------------------------------------------------------------
|
# -------------------------------------------------------------
|
||||||
|
|
||||||
import os, sys, math, time, struct, random, datetime
|
import os, sys, math, time, struct, random, datetime
|
||||||
from struct import pack, unpack
|
|
||||||
|
|
||||||
from ClockDevice import Clock
|
from ClockDevice import Clock
|
||||||
from RNGDevice import RNG
|
from RNGDevice import RNG
|
||||||
|
@ -241,24 +240,24 @@ class Retro:
|
||||||
def i_add(self):
|
def i_add(self):
|
||||||
t = self.stack.pop()
|
t = self.stack.pop()
|
||||||
v = 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):
|
def i_subtract(self):
|
||||||
t = self.stack.pop()
|
t = self.stack.pop()
|
||||||
v = 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):
|
def i_multiply(self):
|
||||||
t = self.stack.pop()
|
t = self.stack.pop()
|
||||||
v = 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):
|
def i_divmod(self):
|
||||||
t = self.stack.pop()
|
t = self.stack.pop()
|
||||||
v = self.stack.pop()
|
v = self.stack.pop()
|
||||||
b, a = self.div_mod(v, t)
|
b, a = self.div_mod(v, t)
|
||||||
self.stack.push(unpack("=l", pack("=L", a & 0xFFFFFFFF))[0])
|
self.stack.push(struct.unpack("=l", struct.pack("=L", a & 0xFFFFFFFF))[0])
|
||||||
self.stack.push(unpack("=l", pack("=L", b & 0xFFFFFFFF))[0])
|
self.stack.push(struct.unpack("=l", struct.pack("=L", b & 0xFFFFFFFF))[0])
|
||||||
|
|
||||||
def i_and(self):
|
def i_and(self):
|
||||||
t = self.stack.pop()
|
t = self.stack.pop()
|
||||||
|
|
Loading…
Reference in a new issue