From b8446c868707ac1b86b482aac03002a2b585dbb6 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Fri, 24 Jan 2025 10:45:22 -0500 Subject: [PATCH] branching, if-else-then; test arm compile --- Makefile | 7 +++++-- foci.c | 8 +++++++- foci.h | 21 +++++++++++++++------ 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index e3ccc3d..3408355 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,9 @@ +#CC := arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb CC := gcc CFLAGS := -O3 -ggdb -g3 -Wall -Wextra -all: - $(CC) $(CFLAGS) -c foci.c +all: foci $(CC) $(CFLAGS) main.c foci.o -o main + +foci: + $(CC) $(CFLAGS) -c foci.c diff --git a/foci.c b/foci.c index 9c73a04..2ca054f 100644 --- a/foci.c +++ b/foci.c @@ -101,7 +101,13 @@ W(colon, ":", &w_align) FTH(here), LIT(0), comma, FTH(latest), comma, poke, comp, END I(semic, ";", &w_colon) LIT(fexit), comma, LIT(&latest), poke, intr, END I(literal, "literal", &w_semic) LIT(push), comma, comma, END -#define LATEST &w_literal +N(b, "_b", &w_literal) { ++pp; pp = (intptr_t **)*pp; NEXT; } +N(bz, "_bz", &w_literal) { ++pp; if (!*sp++) { pp = (intptr_t **)*pp; } NEXT; } +I(fif, "if", &w_b) LIT(bz), comma, FTH(here), LIT(0), comma, END +I(then, "then", &w_fif) FTH(here), LIT(sizeof(intptr_t)), sub, swap, poke, END +I(felse, "else", &w_then) LIT(b), comma, FTH(here), LIT(0), comma, swap, + FTH(here), LIT(sizeof(intptr_t)), sub, swap, poke, END +#define LATEST &w_felse void call(void *ptr) { diff --git a/foci.h b/foci.h index 48c5871..6a96f32 100644 --- a/foci.h +++ b/foci.h @@ -49,8 +49,6 @@ #define N(name, tname, prev) NATIVE(name, tname, prev, 0) #define C(name, tname, prev) NATIVE(name, tname, prev, ATTR_IMMEDIATE) -#define STASH asm("push %r12; push %r13; push %r14; push %r15") -#define RESTORE asm("pop %r15; pop %r14; pop %r13; pop %r12") #define NEXT { goto *(*++pp); } struct word_t @@ -61,10 +59,21 @@ struct word_t char name[]; } __attribute__ ((packed)); -register intptr_t tmp asm("r12"); -register intptr_t * sp asm("r13"); // pointer to stack cells -register intptr_t *** rp asm("r14"); // stack of pp -register intptr_t ** pp asm("r15"); // pointer to ip +// ARM Cortex-M: +//register intptr_t * sp asm("r0"); // pointer to stack cells +//register intptr_t *** rp asm("r1"); // stack of pp +//register intptr_t ** pp asm("r2"); // pointer to ip +//register intptr_t tmp asm("r8"); +//#define STASH asm("push {r0-r2,r8}") +//#define RESTORE asm("pop {r0-r2,r8}") + +// x86_64 +register intptr_t * sp asm("r12"); // pointer to stack cells +register intptr_t *** rp asm("r13"); // stack of pp +register intptr_t ** pp asm("r14"); // pointer to ip +register intptr_t tmp asm("r15"); +#define STASH asm("push %r12; push %r13; push %r14") +#define RESTORE asm("pop %r14; pop %r13; pop %r12") void init(void); int depth(void);