aboutsummaryrefslogtreecommitdiffstats
path: root/src/asm_eval.py
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2023-04-13 14:48:34 +0300
committerJan Tuomi <jans.tuomi@gmail.com>2023-04-13 14:49:59 +0300
commit9d4c6fc299294ac36f7082599edce19286fa0f99 (patch)
treee7601bb1cd9950482f125377d25b6d5d40b72e62 /src/asm_eval.py
parentafd5f32e56d3d30bfa98fb35deff51febf50e594 (diff)
Add @let directive, start pondering interrupt control
Diffstat (limited to 'src/asm_eval.py')
-rw-r--r--src/asm_eval.py16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/asm_eval.py b/src/asm_eval.py
index 691e4eb..c05fc03 100644
--- a/src/asm_eval.py
+++ b/src/asm_eval.py
@@ -24,24 +24,24 @@ constants: dict[str, str] = {
"sign": "3",
}
-Labels = dict[str, int]
+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: {val}")
+ raise Exception(f"Value does not fit in {bits} bits: 0x{val:>04x}")
-def eval_symbol(labels: Labels, c: str) -> str:
- if c in labels:
- return str(labels[c])
+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(labels: Labels, expr: str, bits: int = 16) -> int:
+def eval_expr(symbols: Symbols, expr: str, bits: int = 16) -> int:
expr = expr.lower()
- expr = eval_symbol(labels, expr)
- ret = eval(expr, labels.copy()) # eval as Python expr
+ expr = eval_symbol(symbols, expr)
+ ret = eval(expr, symbols.copy()) # eval as Python expr
check_size(bits, ret)
return ret