Mercurial > hg > index.cgi
diff lwasm/pseudo.c @ 519:724bcc4508bc
Add SETSTR/INCLUDESTR for some basic code building
It seemed useful to have the ability to build up a variable containing
arbitrary text and then to be able to include that in the assembly process
like an include file. So add, undocumented for now, the following:
SETTSTR varname="string"
INCLUDESTSR "string"
"string" must be enclosed in double quotes and may contain most of the usual
escape sequences (\t, \r, etc.) as well as %(varname) to interpolate a
variable value.
To use it to create assembleable source code, you need to make sure it
creates lines (ended by either \r or \n) with appropriate whitespace in
appropriate places.
author | William Astle <lost@l-w.ca> |
---|---|
date | Sun, 19 Dec 2021 17:01:42 -0700 |
parents | c33b4abff860 |
children | 56c32bc798f8 |
line wrap: on
line diff
--- a/lwasm/pseudo.c Tue Apr 13 15:41:23 2021 -0600 +++ b/lwasm/pseudo.c Sun Dec 19 17:01:42 2021 -0700 @@ -1583,6 +1583,41 @@ lw_free(fn); } +PARSEFUNC(pseudo_parse_includestr) +{ + char *str; + char buf[110]; + + l -> len = 0; + + if (!**p) + { + // no operand - include nothing + return; + } + + str = lwasm_parse_general_string(l, p); + if (!str) + { + // string parsing failed + return; + } + if (*str == '\0') + { + // empty string; don't do anything + lw_free(str); + return; + } + + /* add a book-keeping entry for line numbers */ + snprintf(buf, 100, "\001\001SETLINENO %d\n", l -> lineno + 1); + input_openstring(as, "INTERNAL", buf); + + /* add the constructed string to the input */ + input_openstring(as, "INCLUDESTR", str); + lw_free(str); +} + PARSEFUNC(pseudo_parse_align) { lw_expr_t e;