aboutsummaryrefslogtreecommitdiffstats
path: root/src/asm_eval.py
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2024-02-20 16:55:14 +0200
committerJan Tuomi <jans.tuomi@gmail.com>2024-02-20 16:56:09 +0200
commit549901c85044b6ccd912688d6be007c2fdacc6c6 (patch)
tree15d1123eedb4347472e4b47fec880e2e5b79927e /src/asm_eval.py
parentabf0594c78087434bced59054896f7f411e18faf (diff)
Refactor dir structure
Diffstat (limited to 'src/asm_eval.py')
-rw-r--r--src/asm_eval.py47
1 files changed, 0 insertions, 47 deletions
diff --git a/src/asm_eval.py b/src/asm_eval.py
deleted file mode 100644
index c05fc03..0000000
--- a/src/asm_eval.py
+++ /dev/null
@@ -1,47 +0,0 @@
-constants: dict[str, str] = {
- # Registers
- "ra": "0",
- "rb": "1",
- "rc": "2",
- "rd": "3",
- "re": "4",
- "rf": "5",
- "rg": "6",
- "rh": "7",
- # ALU instructions
- "al_plus": "0",
- "al_minus": "1",
- "al_and": "2",
- "al_or": "3",
- "al_xor": "4",
- "al_slr": "5",
- "al_sar": "6",
- "al_sll": "7",
- # ALU flags
- "carry": "0",
- "overflow": "1",
- "zero": "2",
- "sign": "3",
-}
-
-Symbols = dict[str, int]
-
-def check_size(bits: int, val: int) -> None:
- if val >= 2 ** bits:
- raise Exception(f"Value does not fit in {bits} bits: 0x{val:>04x}")
-
-def eval_symbol(symbols: Symbols, c: str) -> str:
- if c in symbols:
- return str(symbols[c])
-
- if c in constants:
- return constants[c]
-
- return c
-
-def eval_expr(symbols: Symbols, expr: str, bits: int = 16) -> int:
- expr = expr.lower()
- expr = eval_symbol(symbols, expr)
- ret = eval(expr, symbols.copy()) # eval as Python expr
- check_size(bits, ret)
- return ret