From 09a99f9af4e71dd6448665f6e165da81f8131efd Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Fri, 9 May 2014 16:44:55 -0400 Subject: [PATCH] Started to add a return stack rather than using the C stack --- SConstruct | 14 +++++++------- source/slvm/extensions/core/core.c | 10 +++++----- source/slvm/kernel/pal.h | 1 + source/slvm/kernel/slvm.h | 4 ++-- source/slvm/platforms/C99/pal.c | 7 +++++-- 5 files changed, 20 insertions(+), 16 deletions(-) diff --git a/SConstruct b/SConstruct index c409734..e5c6d5d 100644 --- a/SConstruct +++ b/SConstruct @@ -121,11 +121,11 @@ c_cpp.StaticLibrary('build/lib/stdpf', # VM Executable Using Standard Platform c_cpp.Program('build/bin/slvm', [], LIBS = ['vmkernel', 'stdpf']) -#nostdlib.Program('build/bin/slvm', -# glob.glob('source/slvm/*.c'), -# LIBPATH = ['build/lib'], -# LIBS = ['gcc', 'stdpf']) - -# VM Extensions -#c_cpp.SharedLibrary('build/lib/ioext', glob.glob('source/slvm/ext/io/*.c')) +# Build all VM Extensions +for ext in glob.glob('source/slvm/extensions/*/'): + name = os.path.basename(ext.strip('\\/')) + c_cpp.StaticLibrary('build/lib/'+name+'ext', + glob.glob(ext + '/*.c'), + CPPPATH = ['source/slvm/kernel'], + LIBS = ['stdpf']) diff --git a/source/slvm/extensions/core/core.c b/source/slvm/extensions/core/core.c index b3d303b..ee202e9 100644 --- a/source/slvm/extensions/core/core.c +++ b/source/slvm/extensions/core/core.c @@ -2,8 +2,10 @@ #include "pal.h" #include -#if 0 -defcode("if", _if, 1, &bytemove){ +extern word_t zbranch, comma, here, swap, dup, wcode, nrot, rot, sub, wordsz, + mul, add, store, branch; + +defcode("if", _if, 1, NULL){ /* Compile branch instruction */ ArgStack++; *(ArgStack) = (val_t)&zbranch; @@ -59,14 +61,12 @@ defcode("else", _else, 1, &_then){ EXEC(_then); EXEC(swap); } -#endif dict_t* core_init(dict_t* p_prev) { dict_t* p_dict = (dict_t*)pal_allocate(sizeof(dict_t)); p_dict->name = "core"; p_dict->p_prev = p_prev; - p_dict->p_words = (word_t*)NULL; - //p_dict->p_words = (word_t*)&_fpeekc; + p_dict->p_words = (word_t*)&_else; return p_dict; } diff --git a/source/slvm/kernel/pal.h b/source/slvm/kernel/pal.h index 634c2dc..8217d92 100644 --- a/source/slvm/kernel/pal.h +++ b/source/slvm/kernel/pal.h @@ -12,6 +12,7 @@ #include extern val_t* ArgStack; +extern val_t* RetStack; extern val_t* CodePtr; dict_t* pal_init(dict_t* p_prev_dict); diff --git a/source/slvm/kernel/slvm.h b/source/slvm/kernel/slvm.h index dab6db1..421bf9b 100644 --- a/source/slvm/kernel/slvm.h +++ b/source/slvm/kernel/slvm.h @@ -91,8 +91,8 @@ typedef struct dict_t { #define EXEC(word) (word).codeword((word).code) /** The maximum number of entries that can be on the argument stack */ -#ifndef ARG_STACK_SIZE -#define ARG_STACK_SIZE 32 +#ifndef STACK_SIZE +#define STACK_SIZE 32 #endif /** diff --git a/source/slvm/platforms/C99/pal.c b/source/slvm/platforms/C99/pal.c index b6f76d2..cf58660 100644 --- a/source/slvm/platforms/C99/pal.c +++ b/source/slvm/platforms/C99/pal.c @@ -8,9 +8,12 @@ #include #include -static val_t Stack[ARG_STACK_SIZE]; +static val_t AStack[STACK_SIZE]; +static val_t RStack[STACK_SIZE]; static bool Line_Read = true; -val_t* ArgStack = Stack - 1; + +val_t* ArgStack = AStack - 1; +val_t* RetStack = RStack - 1; val_t* CodePtr = 0; defcode("allocate", mem_alloc, 1, NULL){ -- 2.52.0