diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2023-11-03 20:02:03 +0200 |
|---|---|---|
| committer | Jan Tuomi <jans.tuomi@gmail.com> | 2023-11-03 20:02:03 +0200 |
| commit | 4fbe8d2d27dd8873c1f309e15b116f8800a5e605 (patch) | |
| tree | 709d25abaa5c0a7d1ea7484750cb54765d33cd59 | |
| parent | abf6cbdecc8eb006a859205dee7500c2b70c0998 (diff) | |
Improve string I/O helper macros
| -rw-r--r-- | asm/ext_string_io.py | 2 | ||||
| -rw-r--r-- | asm/text_mode.atk16 | 8 | ||||
| -rw-r--r-- | digital/atk16_mem.dig | 2 | ||||
| -rw-r--r-- | src/tokenizer.py | 13 |
4 files changed, 19 insertions, 6 deletions
diff --git a/asm/ext_string_io.py b/asm/ext_string_io.py index cf7d598..7b026ba 100644 --- a/asm/ext_string_io.py +++ b/asm/ext_string_io.py @@ -13,6 +13,7 @@ def get_unique_name(prefix: str): return ret def expand_put_char(cursor_reg: str, scratch_reg: str, c: str) -> ExpandResult: + c = c.strip("\"") return [ ["ldi", str(to_char_code(c)), scratch_reg], ["str", scratch_reg, cursor_reg], @@ -21,6 +22,7 @@ def expand_put_char(cursor_reg: str, scratch_reg: str, c: str) -> ExpandResult: def expand_put_string(cursor_reg: str, scratch_reg: str, *rest: str) -> ExpandResult: string = " ".join(rest) + string = string.strip("\"") result: ExpandResult = [] for c in string: result += expand_put_char(cursor_reg, scratch_reg, c) diff --git a/asm/text_mode.atk16 b/asm/text_mode.atk16 index f4d84ae..f33120d 100644 --- a/asm/text_mode.atk16 +++ b/asm/text_mode.atk16 @@ -9,11 +9,9 @@ @label main cursor_to_line RA 1 - put_char RA RB %SPACE - put_string RA RB HELLO CORECAMP - cursor_to_line RA 3 - put_char RA RB %SPACE - put_string RA RB BY JAN + put_string RA RB " HELLO CORECAMP" + cursor_to_line RA 2 + put_string RA RB " BY JAN" ; set graphics mode to sprite mode ; set_graphics_mode gr_sprite_mode diff --git a/digital/atk16_mem.dig b/digital/atk16_mem.dig index 31fe276..a5279d0 100644 --- a/digital/atk16_mem.dig +++ b/digital/atk16_mem.dig @@ -41,7 +41,7 @@ ,2000,4200,3008,1008,4208,3008,1008,4205,3008,1008,420c,3008,1008 ,420c,3008,1008,420f,3008,1008,4200,3008,1008,4203,3008,1008,420f ,3008,1008,4212,3008,1008,4205,3008,1008,4203,3008,1008,4201,3008 -,1008,420d,3008,1008,4210,3008,1008,6001,f8c0,4063,2000,4200,3008 +,1008,420d,3008,1008,4210,3008,1008,6001,f880,4063,2000,4200,3008 ,1008,4202,3008,1008,4219,3008,1008,4200,3008,1008,420a,3008,1008 ,4201,3008,1008,420e,3008,1008,4017,2000,4201,3008,61ff</data> </entry> diff --git a/src/tokenizer.py b/src/tokenizer.py index 2049461..d9c6058 100644 --- a/src/tokenizer.py +++ b/src/tokenizer.py @@ -2,6 +2,7 @@ def tokenize(line: str) -> list[str]: cur: str = "" result: list[str] = [] is_py_expr = False + is_string = False idx = 0 while idx < len(line): c = line[idx] @@ -18,6 +19,16 @@ def tokenize(line: str) -> list[str]: cur = "" elif is_py_expr: cur += c + elif not is_string and c == "\"": + cur += "\"" + is_string = True + elif is_string and c == "\"": + cur += "\"" + is_string = False + result.append(cur) + cur = "" + elif is_string: + cur += c elif c == " " or c == "\t": result.append(cur) cur = "" @@ -29,4 +40,6 @@ def tokenize(line: str) -> list[str]: if len(cur) > 0: result.append(cur) + print(result) + return [r for r in result if r != ""]
\ No newline at end of file |
