aboutsummaryrefslogtreecommitdiff
path: root/src/tools
diff options
context:
space:
mode:
authorGravatar zinc <zinc@downsta.ir> 2026-10-14 16:16:59 +0330
committerGravatar zinc <zinc@downsta.ir> 2026-10-14 16:16:59 +0330
commitb92c7fe87239279646fcbef493cf628d260f51ff (patch)
tree8603b1f43e1c8f6342787f0a3a38bc33db9033b9 /src/tools
parentzc0: x as T reads a whole type (x as int*, x as char**) (diff)
zc0: embed of an array type inside a function
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/zc0.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/tools/zc0.c b/src/tools/zc0.c
index f28c655..51ea9f8 100644
--- a/src/tools/zc0.c
+++ b/src/tools/zc0.c
@@ -994,12 +994,13 @@ static void embeddecl(int local)
}
} else {
int count; w = embed_width(ty, star);
- if (local) die("zc0 embeds an array at the top level, not in a function");
if (!w) die("embed declares a bstr, a char*, a number or an array of numbers");
if (len % w) die("the embedded file's size is not a whole number of elements");
count = (int)(len / w);
if (arr >= 0 && count > arr) die("the embedded file is larger than the array it is declared as");
if (arr >= 0) count = arr;
+ /* in a function the elements sit in the code, jumped over, and the local holds their address */
+ if (local) { j = here; lit(0); op(O_JMP); }
a = here;
for (i = 0; i < count; i++) {
uint64_t u = 0; int k;
@@ -1009,7 +1010,8 @@ static void embeddecl(int local)
emit((int64_t)u);
}
if (!count) emit(0);
- add(n, K_GARR, a);
+ if (local) { setlit(j, here); l = newloc(n); lit(a); laddr(l->slot); op(O_ST); }
+ else add(n, K_GARR, a);
}
free(buf);
}