diff options
Diffstat (limited to 'asm')
| -rw-r--r-- | asm/atk16.py | 4 | ||||
| -rw-r--r-- | asm/ext_std.py | 24 | ||||
| -rw-r--r-- | asm/test_py_src.atk16 | 112 | ||||
| -rw-r--r-- | asm/test_py_src.atk16_optimized | 78 | ||||
| -rw-r--r-- | asm/test_py_src.py | 36 |
5 files changed, 104 insertions, 150 deletions
diff --git a/asm/atk16.py b/asm/atk16.py index f1a2c95..6d9bc10 100644 --- a/asm/atk16.py +++ b/asm/atk16.py @@ -1,5 +1,4 @@ from typing import Literal, Any, TypeVar, NewType, Never -a = ["A", "B", "C"] Char = Literal['\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07', '\x08', '\t', '\n', '\x0b', '\x0c', '\r', '\x0e', '\x0f', '\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17', '\x18', '\x19', '\x1a', '\x1b', '\x1c', '\x1d', '\x1e', '\x1f', ' ', '!', '"', '#', '$', '%', '&', "'", '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', '\x7f', '\x80', '\x81', '\x82', '\x83', '\x84', '\x85', '\x86', '\x87', '\x88', '\x89', '\x8a', '\x8b', '\x8c', '\x8d', '\x8e', '\x8f', '\x90', '\x91', '\x92', '\x93', '\x94', '\x95', '\x96', '\x97', '\x98', '\x99', '\x9a', '\x9b', '\x9c', '\x9d', '\x9e', '\x9f', '\xa0', '¡', '¢', '£', '¤', '¥', '¦', '§', '¨', '©', 'ª', '«', '¬', '\xad', '®', '¯', '°', '±', '²', '³', '´', 'µ', '¶', '·', '¸', '¹', 'º', '»', '¼', '½', '¾', '¿', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', '×', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'Þ', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ð', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', '÷', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'þ', 'ÿ'] ConstInt = int @@ -12,9 +11,6 @@ def load(addr: int) -> int: def put_char(c: int): return NotImplemented -def set_graphics_mode(mode: Literal[0, 1, 2]): - return NotImplemented - T = TypeVar("T") def call_inline(expr: T) -> T: """Inline the function call `expr` at the callsite. diff --git a/asm/ext_std.py b/asm/ext_std.py index 3d87372..fd18953 100644 --- a/asm/ext_std.py +++ b/asm/ext_std.py @@ -12,14 +12,29 @@ def expand_addi(left: str, imm: str, target: str) -> ExpandResult: def expand_subi(left: str, imm: str, target: str) -> ExpandResult: return [["ali", "al_minus", left, imm, target]] +def expand_not(reg: str, target: str) -> ExpandResult: + return [["alr", "al_xor", reg, "0xFFFF", target]] + +def expand_noti(imm: str, target: str) -> ExpandResult: + return [["ali", "al_xor", imm, "0xFFFF", target]] + def expand_and(left: str, right: str, target: str) -> ExpandResult: return [["alr", "al_and", left, right, target]] +def expand_andi(left: str, imm: str, target: str) -> ExpandResult: + return [["ali", "al_and", left, imm, target]] + def expand_or(left: str, right: str, target: str) -> ExpandResult: return [["alr", "al_or", left, right, target]] -def expand_xor(left: str, right: str, target: str) -> ExpandResult: - return [["alr", "al_xor", left, right, target]] +def expand_ori(left: str, imm: str, target: str) -> ExpandResult: + return [["ali", "al_or", left, imm, target]] + +def expand_xor(left: str, imm: str, target: str) -> ExpandResult: + return [["alr", "al_xor", left, imm, target]] + +def expand_xori(left: str, right: str, target: str) -> ExpandResult: + return [["ali", "al_xor", left, right, target]] def expand_sll(left: str, right: str, target: str) -> ExpandResult: return [["alr", "al_sll", left, right, target]] @@ -105,9 +120,14 @@ expansions: OpExpansionDict = { "sub": expand_sub, "addi": expand_addi, "subi": expand_subi, + "not": expand_not, + "noti": expand_noti, "and": expand_and, + "andi": expand_andi, "or": expand_or, + "ori": expand_ori, "xor": expand_xor, + "xori": expand_xori, "sll": expand_sll, "slr": expand_slr, "sar": expand_sar, diff --git a/asm/test_py_src.atk16 b/asm/test_py_src.atk16 index c1bf1af..c035b72 100644 --- a/asm/test_py_src.atk16 +++ b/asm/test_py_src.atk16 @@ -73,88 +73,44 @@ ;; END BOOTSTRAP -@label TEXT_MODE - 1 -@label int_0 - 23 -@label int_1 - 63488 -@label int_2 - 72 -@label int_3 - 63489 -@label int_4 - 69 -@label int_5 - 63490 -@label int_6 - 76 -@label int_7 - 63491 -@label int_8 - 76 -@label int_9 - 63492 -@label int_10 - 79 + @label main -; builtin call store [<ast.Constant object at 0x1045a3d90>, <ast.Name object at 0x1045a3d60>] - ldi int_0 RA - ldr RA RA - spu RA - spo RB - spo RA - str RB RA -; builtin call store [<ast.Constant object at 0x1045a3c70>, <ast.Constant object at 0x1045a3c40>] - ldi int_1 RA - ldr RA RA - spu RA - ldi int_2 RA - ldr RA RA - spu RA - spo RB - spo RA - str RB RA -; builtin call store [<ast.Constant object at 0x1045a3b50>, <ast.Constant object at 0x1045a3b20>] - ldi int_3 RA - ldr RA RA - spu RA - ldi int_4 RA - ldr RA RA - spu RA - spo RB - spo RA - str RB RA -; builtin call store [<ast.Constant object at 0x1045a3a30>, <ast.Constant object at 0x1045a3a00>] - ldi int_5 RA - ldr RA RA - spu RA - ldi int_6 RA - ldr RA RA - spu RA - spo RB - spo RA - str RB RA -; builtin call store [<ast.Constant object at 0x1045a3910>, <ast.Constant object at 0x1045a38e0>] - ldi int_7 RA - ldr RA RA - spu RA - ldi int_8 RA - ldr RA RA +; <ast.If object at 0x1013c1e40> +; <ast.Constant object at 0x1013c20b0> + ldi 1 RA spu RA - spo RB spo RA - str RB RA -; builtin call store [<ast.Constant object at 0x1045a37f0>, <ast.Constant object at 0x1045a37c0>] - ldi int_9 RA - ldr RA RA + addi RA 0 RA + bri zero If_false_branch_0 +; <ast.Constant object at 0x1013c2110> + ldi 2 RA spu RA - ldi int_10 RA - ldr RA RA + jpi If_end_branch_1 +@label If_false_branch_0 +; <ast.Constant object at 0x1013c2170> + ldi 3 RA spu RA - spo RB +@label If_end_branch_1 +; <ast.While object at 0x1013c2230> +@label While_test_2 +; <ast.Constant object at 0x1013c2260> + ldi 3 RB + spu RB spo RA - str RB RA -; builtin call asm [<ast.Constant object at 0x1045a2c20>] - ldi 1 RA
\ No newline at end of file + addi RA 0 RA + bri zero While_else_3 +; <ast.Constant object at 0x1013c22c0> + ldi 4 RB + spu RB +; <ast.Break object at 0x1013c22f0> + jpi While_end_4 +; <ast.Constant object at 0x1013c2350> + ldi 5 RB + spu RB + jpi While_test_2 +@label While_else_3 +; <ast.Constant object at 0x1013c2470> + ldi 6 RB + spu RB +@label While_end_4
\ No newline at end of file diff --git a/asm/test_py_src.atk16_optimized b/asm/test_py_src.atk16_optimized index a6a77ab..673800b 100644 --- a/asm/test_py_src.atk16_optimized +++ b/asm/test_py_src.atk16_optimized @@ -58,58 +58,28 @@ ldi gr_disabled_mode RB str RB RA jpi main -@label TEXT_MODE - 1 -@label int_0 - 23 -@label int_1 - 63488 -@label int_2 - 72 -@label int_3 - 63489 -@label int_4 - 69 -@label int_5 - 63490 -@label int_6 - 76 -@label int_7 - 63491 -@label int_8 - 76 -@label int_9 - 63492 -@label int_10 - 79 @label main - ldi int_0 RA - ldr RA RB - spo RA - str RB RA - ldi int_1 RA - ldr RA RA - ldi int_2 RB - ldr RB RB - str RB RA - ldi int_3 RA - ldr RA RA - ldi int_4 RB - ldr RB RB - str RB RA - ldi int_5 RA - ldr RA RA - ldi int_6 RB - ldr RB RB - str RB RA - ldi int_7 RA - ldr RA RA - ldi int_8 RB - ldr RB RB - str RB RA - ldi int_9 RA - ldr RA RA - ldi int_10 RB - ldr RB RB - str RB RA - ldi 1 RA
\ No newline at end of file + ldi 1 RA + addi RA 0 RA + bri zero If_false_branch_0 + ldi 2 RA + spu RA + jpi If_end_branch_1 +@label If_false_branch_0 + ldi 3 RA + spu RA +@label If_end_branch_1 +@label While_test_2 + ldi 3 RA + addi RA 0 RA + bri zero While_else_3 + ldi 4 RB + spu RB + jpi While_end_4 + ldi 5 RB + spu RB + jpi While_test_2 +@label While_else_3 + ldi 6 RB + spu RB +@label While_end_4
\ No newline at end of file diff --git a/asm/test_py_src.py b/asm/test_py_src.py index a1eca3f..48a5cac 100644 --- a/asm/test_py_src.py +++ b/asm/test_py_src.py @@ -1,17 +1,29 @@ import atk16 -TEXT_MODE: atk16.ConstInt = 1 -GRAPHICS_MODE_ADDR: atk16.ConstInt = 0x17 +if True: + 2 +else: + 3 -atk16.store(GRAPHICS_MODE_ADDR, TEXT_MODE) -atk16.store(0xF800, 'H') -atk16.store(0xF801, 'E') -atk16.store(0xF802, 'L') -atk16.store(0xF803, 'L') -atk16.store(0xF804, 'O') +while 3: + 4 + break + 5 +else: + 6 -a = atk16.call_inline( - atk16.load(0xF000) -) +# TEXT_MODE: atk16.ConstInt = 1 +# GRAPHICS_MODE_ADDR: atk16.ConstInt = 0x17 -atk16.asm("ldi 1 RA") +# atk16.store(GRAPHICS_MODE_ADDR, TEXT_MODE) +# atk16.store(0xF800, 'H') +# atk16.store(0xF801, 'E') +# atk16.store(0xF802, 'L') +# atk16.store(0xF803, 'L') +# atk16.store(0xF804, 'O') + +# a = atk16.call_inline( +# atk16.load(0xF000) +# ) + +# atk16.asm("ldi 1 RA") |
