vsm2

exeprimental virtual stack machine for *nix
Log | Files | Refs

commit 7df45e4e8f41c4a6c8bbb8f4011d9d1849e25708
parent 774465336717a6dd001a5fcab4fbea9f56225575
Author: prenev <an2qzavok@gmail.com>
Date:   Sun, 31 Jul 2022 02:39:43 +0300

get ready to send stuff to bus

Diffstat:
Mrepl.c | 33++++++++++++++++++++++++++++++---
1 file changed, 30 insertions(+), 3 deletions(-)

diff --git a/repl.c b/repl.c @@ -4,6 +4,8 @@ #include <string.h> #include "cell.h" +#include "bus.h" +#include "mem.h" #include "util.h" #define StackSize 256 @@ -18,9 +20,10 @@ Cell * pop(void); #define CMD(x) void x(void) CMD(str); CMD(hex); -CMD(stk); +CMD(top); CMD(drp); CMD(hlp); +CMD(snd); struct { const char *cmd; @@ -28,9 +31,10 @@ struct { } dict[]= { {"str", str}, {"hex", hex}, - {"stk", stk}, + {"top", top}, {"drp", drp}, {"hlp", hlp}, + {"snd", snd}, }; void @@ -87,6 +91,11 @@ hex(void) n = read(0, buf, 1024); buf[n-1] = '\0'; x = strtoll(buf, 0, 16); + + Cell *c = createcell(sizeof(long long), NULL); + c->p = malloc(c->n); + memcpy(c->p, &x, c->n); + push(c); } void @@ -100,7 +109,7 @@ hlp(void) } void -stk(void) +top(void) { unsigned int n; n = stack.n - 1; @@ -119,6 +128,24 @@ drp(void) } void +snd(void) +{ + /* send a message to the bus */ + Cell *dat, *dstcell; + int dst; + + dstcell = pop(); + dst = ((int*)dstcell->p)[0]; + dat = pop(); + + // Msg *msg = createmsg(ChDebug, ???, ???); + // buspush(???, msg); + printf("snd %d %s\n", dst, dat->p); + freecell(dstcell); + freecell(dat); +} + +void push(Cell *new) { stack.mem[stack.n] = *new;