commit d6c5ae7743c00874b4b9a392dba3a1220c04612e
parent 63205c73d9c1a696f6fd482055621c8601611930
Author: thing1 <thing1@seacrossedlovers.xyz>
Date: Thu, 2 Oct 2025 15:58:51 +0100
started work on call stack
Diffstat:
4 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/examples/callstack.ll b/examples/callstack.ll
@@ -0,0 +1,9 @@
+|0x0 @stdin |0x1 @stdout |0x2 @stderr
+
+|0x100 @tester
+p65 &stdout storeb
+ret
+
+|0x1000
+call &tester
+halt
diff --git a/lli.c b/lli.c
@@ -52,6 +52,13 @@ lliexec() {
};
s.sptr = s.arr;
+ stack cs = {
+ .cap = 512,
+ .arr = malloc(512),
+ };
+ cs.sptr = s.arr;
+
+
step:
uint8_t opcode = *(uint8_t *)pc, val8;
uint16_t val16;
@@ -97,6 +104,15 @@ step:
pc = &memory[loc];
goto step;
+ case CALL:
+ loc = pop_uint32_t(&s);
+ push_uint32_t(&cs, (uint32_t *)(pc - &memory[0]));
+ pc = &memory[loc];
+ goto step;
+ case RET:
+ pc = &memory[pop_uint32_t(&cs)];
+ goto step;
+
case PUSHA:
case PUSH:
pc++;
diff --git a/lli.h b/lli.h
@@ -26,7 +26,9 @@ typedef enum ttype {
LOADI,
JMP,
- HALT = 'A',
+ CALL,
+ RET,
+ HALT,
} ttype;
typedef struct tval {
diff --git a/lliasm.c b/lliasm.c
@@ -135,6 +135,11 @@ tokenize(char *word, int *size) {
else if (SAME(word, "jmp"))
val->type = JMP;
+ else if (SAME(word, "call"))
+ val->type = JMP;
+ else if (SAME(word, "ret"))
+ val->type = JMP;
+
else if (SAME(word, "halt"))
val->type = HALT;
else {