Refactoring with macros.
h3rald h3rald@h3rald.com
Fri, 06 Feb 2026 08:30:48 +0100
6 files changed,
25 insertions(+),
12 deletions(-)
M
examples/_macros.xyw
→
examples/_macros.xyw
@@ -40,3 +40,12 @@ .macro beeper.state $40
.macro beeper.samples $41 .macro beeper.n_samples $43 .macro beeper.on_stop $45 + +; Other macros +.macro MOD DIV POP +.macro LBYTE SWP POP +.macro PUTC $11 STB +.macro NL $0A PUTC +.macro SP $20 PUTC +.macro arg.sep $1E +.macro arg.end $1D
M
examples/d6.xyw
→
examples/d6.xyw
@@ -1,12 +1,8 @@
.include "_macros.xyw" ; Get random number and calculate modulo 6 -system.random LDB $6 DIV POP +system.random LDB $6 MOD ; Print result+1 and new line -$31 ADD terminal.output STB -$0A terminal.output STB - -; Terminate -$0 system.state STB - +$31 ADD PUTC +NL
M
examples/factorial16.xyw
→
examples/factorial16.xyw
@@ -3,7 +3,7 @@
; Main program: calculate and print factorial of 7 $00 $07 fact JSRw PUTDw JSRw -$0A terminal.output STB +NL end JMPw ; Factorial subroutine@@ -14,7 +14,7 @@ POPxyw
.label fact.loop ; Need to work with 16-bit comparisons ; but JCN only works with 8-bit values, so remove high byte first - PSHyw $00 $00 EQUw SWP POP fact.end0 JCNw + PSHyw $00 $00 EQUw LBYTE fact.end0 JCNw PSHyw $00 $01 EQUw SWP POP fact.end1 JCNw ; Decrement y and multiply DECyw PSHxw PSHyw MULxw POPxw
M
examples/factorial8.xyw
→
examples/factorial8.xyw
@@ -3,7 +3,7 @@
; Main program: calculate and print factorial of 5 $5 fact JSRw PUTD JSRw -$0A terminal.output STB +NL end JMPw ; Factorial subroutine
M
xyw-vscode/syntaxes/xyw.tmLanguage.json
→
xyw-vscode/syntaxes/xyw.tmLanguage.json
@@ -161,8 +161,13 @@ "match": "\\b(system|terminal|file|clock|beeper|)\\.[a-zA-Z0-9_.\\-]*\\b"
}, { "comment": "Library subroutines", - "name": "keyword.other.library.xyw", + "name": "support.class.subroutine.xyw", "match": "\\b(PUTD|PUTDw|PUTS)\\b" + }, + { + "comment": "Other library macros", + "name": "support.class.macro.xyw", + "match": "\\b(LBYTE|SP|NL|PUTC|MOD|arg.sep|arg.end)\\b" }, { "comment": "Label/macro references: starts with letter/underscore, can contain letters, numbers, underscores, dashes, or dots",
M
xyw.vim
→
xyw.vim
@@ -36,6 +36,9 @@
" Library subroutines syntax match xywLibrary "\<\(PUTD\|PUTDw\|PUTS\)\>" +" Library macros +syntax match xywLibrary "\<\(LBYTE\|SP\|NL\|MOD\|arg.end\|arg.sep\)\>" + " Instructions - BRK and RTS have no modifiers syntax match xywInstruction "\<\(BRK\|RTS\)\>"@@ -58,7 +61,7 @@ highlight default link xywEscape SpecialChar
highlight default link xywHexNumber Number highlight default link xywBinNumber Number highlight default link xywInstruction Statement -highlight default link xywLibrary Keyword +highlight default link xywLibrary Constant highlight default link xywDeviceId Type highlight default link xywIdentifier Identifier