Implemented include
h3rald h3rald@h3rald.com
Fri, 28 Nov 2025 13:45:07 +0100
2 files changed,
70 insertions(+),
6 deletions(-)
A
devices.xyw
@@ -0,0 +1,53 @@
+;system +.macro system.state $FF00 +.macro system.error $FF01 +.macro system.ssp $FF02 +.macro system.usp $FF03 +.macro system.x $FF04 +.macro system.y $FF05 +.macro system.xw $FF06 +.macro system.yw $FF08 +.macro system.pc $FF0a +.macro system.page $FF0c +.macro system.on_error $FF0d + +;console +.macro console.input $FF10 +.macro console.output $FF11 +.macro console.error $FF12 +.macro console.on_keypress $FF13 + +;clock +.macro clock.year $FF20 +.macro clock.month $FF22 +.macro clock.week $FF23 +.macro clock.monthday $FF24 +.macro clock.weekday $FF25 +.macro clock.hour $FF26 +.macro clock.minute $FF27 +.macro clock.second $FF28 +.macro clock.timer $FF29 +.macro clock.on_timer_elapsed $FF2b + +;file +.macro file.path $FF30 +.macro file.operation $FF32 +.macro file.state $FF33 +.macro file.type $FF34 +.macro file.read $FF35 +.macro file.write $FF36 +.macro file.append $FF37 + +;display +.macro display.width $FF40 +.macro display.height $FF41 +.macro display.fill $FF42 +.macro display.x $FF43 +.macro display.y $FF44 +.macro display.on_render $FF45 + +;buzzer +.macro buzzer.state $FF50 +.macro buzzer.samples $FF51 +.macro buzzer.n_samples $FF53 +.macro buzzer.on_stop $FF55
M
xywasm.c
→
xywasm.c
@@ -157,7 +157,8 @@ }
//// Forward declarations static xyw_token_terminator next_token(xyw_context *ctx); -static int assemble_string(xyw_context *ctx, const char *text); +static int assemble_string(xyw_context *ctx); +static int assemble_file(xyw_context *ctx); //// Utilities@@ -557,7 +558,8 @@ xyw_symbol *sym = &symbols[i];
if (sym->type == SYMBOL_TYPE_MACRO) { printf("-> Macro:\t%s\n", sym->contents); - assemble_string(ctx, sym->contents); + ctx->sp = sym->contents; + assemble_string(ctx); ctx->src = SRC_FILE; ctx->sp = NULL; }@@ -630,8 +632,18 @@ return -1;
} process_string(ctx); printf("Directive:\t.include %s\n", token); - // TODO: process include - return validate_single_directive_argument(ctx, r); + xyw_context include_ctx; + include_ctx.src = SRC_FILE; + // Ignore token quotes for file name + token[token_length - 1] = '\0'; + include_ctx.file = dict_store(token + 1); + include_ctx.line = 1; + include_ctx.column = 1; + if (validate_single_directive_argument(ctx, r) != 0) + { + return -1; + } + return assemble_file(&include_ctx); } static int process_directive_string(xyw_context *ctx)@@ -948,10 +960,9 @@ return r;
} // Process tokens from an in-memory string buffer (mainly for macro body) -static int assemble_string(xyw_context *ctx, const char *text) +static int assemble_string(xyw_context *ctx) { ctx->src = SRC_STRING; - ctx->sp = text; int r; while (1) {