aboutsummaryrefslogtreecommitdiffstats
path: root/asm/ffi.py
diff options
context:
space:
mode:
authorGravatar Peter McGoron 2023-02-11 14:28:43 +0000
committerGravatar Peter McGoron 2023-02-11 14:28:43 +0000
commit582a0a2c9a476abe9dec3410ff4f555433ed9e0f (patch)
tree422878d94f091f440143348d7f52fcfa42b294dc /asm/ffi.py
parenttest pop (diff)
enable compiling and add compile test
Diffstat (limited to 'asm/ffi.py')
-rw-r--r--asm/ffi.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/asm/ffi.py b/asm/ffi.py
index 39d9800..a1907c6 100644
--- a/asm/ffi.py
+++ b/asm/ffi.py
@@ -13,6 +13,20 @@ class CompileRet(Enum):
LABEL_OVERFLOW = 7
TYPE_ERROR = 8
CLEARED_INSTRUCTION = 9
+ PROGRAM_OVERFLOW = 10
+
+class RunRet(Enum):
+ CONTINUE = 0
+ SYSCALL = 1
+ STOP = 2
+ STACK_OVERFLOW = 3
+ STACK_UNDERFLOW = 4
+ RUN_LABEL_OVERFLOW = 5
+ REGISTER_OVERFLOW = 6
+ UNKNOWN_OPCODE = 7
+
+ def is_halt(self):
+ return not (self == RunRet.CONTINUE or self == RunRet.SYSCALL)
class CIns(Structure):
_fields_ = [("opcode", c_int),
@@ -76,6 +90,17 @@ class Environment:
ret = dll.creole_compile(byref(self.cenv), byref(rd))
return CompileRet(ret)
+ def syscall(self, sc):
+ pass
+ def __call__(self):
+ sc = c_size_t()
+ ret = RunRet.CONTINUE
+ while not ret.is_halt():
+ ret = RunRet(dll.creole_step(byref(self.cenv), byref(sc)))
+ if ret == RunRet.SYSCALL:
+ self.syscall(sc)
+ return ret
+
class CParseLineException(Exception):
pass
def parse_line(line):