diff options
| author | 2023-02-11 14:28:43 +0000 | |
|---|---|---|
| committer | 2023-02-11 14:28:43 +0000 | |
| commit | 582a0a2c9a476abe9dec3410ff4f555433ed9e0f (patch) | |
| tree | 422878d94f091f440143348d7f52fcfa42b294dc /asm/ffi.py | |
| parent | test pop (diff) | |
enable compiling and add compile test
Diffstat (limited to 'asm/ffi.py')
| -rw-r--r-- | asm/ffi.py | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -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): |
