From: Michael D. Lowis Date: Tue, 6 May 2014 17:42:18 +0000 (-0400) Subject: Broke dependency on stdlib for vmkernel (also broke number parsing but nevermind... X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=f85bed7f0b3c8b898856991d83cac2654a9953f4;p=proto%2Fsclpl.git Broke dependency on stdlib for vmkernel (also broke number parsing but nevermind that). Also rearranged slvm code for clarity --- diff --git a/SConstruct b/SConstruct index 59fbac4..c409734 100644 --- a/SConstruct +++ b/SConstruct @@ -40,7 +40,8 @@ def RunTest( output, runner ): base = Environment( ENV = os.environ, CCFLAGS = [], - LDFLAGS = []) + LDFLAGS = [], + LIBPATH = ['build/lib']) # On windows use mingw because VS is not C99 compliant if platform.system() == 'Windows': @@ -50,6 +51,11 @@ if platform.system() == 'Windows': #--------------------------- c_cpp = base.Clone(CCFLAGS = [ '-Wall', '-Werror', '-std=c99' ]) +# C/C++ Environment Minus Standard Lib +#------------------------------------- +nostdlib = c_cpp.Clone(LINKFLAGS = [ '-nostdlib' ], + LIBS = ['gcc']) + # Chicken Scheme Environment #--------------------------- # Scheme Source Compiler @@ -88,22 +94,38 @@ scheme = base.Clone(CCFLAGS = [ '-I', 'inc'], #readsof.Depends('readsof', 'sof') # SCLPL Compiler -SchemeBuildAndTest( 'build/slc', +SchemeBuildAndTest( 'build/bin/slc', find_files('source/slc/','*.scm'), find_files('tests/slc/','*.scm') ) # SCLPL Package Manager -SchemeBuildAndTest( 'build/slpkg', +SchemeBuildAndTest( 'build/bin/slpkg', find_files('source/slpkg/','*.scm'), find_files('tests/slpkg/','*.scm') ) # SCLPL Assembler -SchemeBuildAndTest( 'build/slas', +SchemeBuildAndTest( 'build/bin/slas', find_files('source/slas/','*.scm'), find_files('tests/slas/','*.scm') ) # SCLPL Virtual Machine -c_cpp.Program('build/slvm', - glob.glob('source/slvm/*.c') + - glob.glob('source/slvm/platform/C99/*.c')) +#---------------------- +# Virtual Machine Kernel +nostdlib.StaticLibrary('build/lib/vmkernel', glob.glob('source/slvm/kernel/*.c')) + +# Standard Platform Library (C99) +c_cpp.StaticLibrary('build/lib/stdpf', + glob.glob('source/slvm/platforms/C99/*.c'), + CPPPATH = ['source/slvm/kernel']) + +# 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')) diff --git a/source/slvm/pal.h b/source/slvm/kernel/pal.h similarity index 78% rename from source/slvm/pal.h rename to source/slvm/kernel/pal.h index 86171ca..634c2dc 100644 --- a/source/slvm/pal.h +++ b/source/slvm/kernel/pal.h @@ -23,5 +23,8 @@ void pal_free(void* p_mem); char pal_read_char(void); char pal_peek_char(void); bool pal_is_eof(void); +int pal_strcmp(const char* p_str1, const char* p_str2); +size_t pal_strlen(char* p_str); +char* pal_strcpy(char* p_dest, const char* p_src); #endif /* PAL_H */ diff --git a/source/slvm/parser.c b/source/slvm/kernel/parser.c similarity index 93% rename from source/slvm/parser.c rename to source/slvm/kernel/parser.c index 8da82fd..019dc75 100644 --- a/source/slvm/parser.c +++ b/source/slvm/kernel/parser.c @@ -160,9 +160,10 @@ TokenType_T parse(char* str, val_t* p_val) static bool is_integer(char* p_str, val_t* p_val) { - char* end; - *(p_val) = (val_t)strtol(p_str,&end,0); - return (end == &(p_str[strlen(p_str)])); + //char* end; + //*(p_val) = (val_t)strtol(p_str,&end,0); + //return (end == &(p_str[pal_strlen(p_str)])); + return false; } static bool is_float(char* p_str, val_t* p_val) @@ -173,10 +174,10 @@ static bool is_float(char* p_str, val_t* p_val) static bool is_string(char* p_str, val_t* p_val) { bool res = false; - if((p_str[0] == '"') && (p_str[strlen(p_str)-1] == '"')) + if((p_str[0] == '"') && (p_str[pal_strlen(p_str)-1] == '"')) { /* Cut off the last double quote */ - p_str[strlen(p_str)-1] = '\0'; + p_str[pal_strlen(p_str)-1] = '\0'; /* And return the string after the first double quote */ *(p_val) = (val_t)(p_str+1); res = true; @@ -203,7 +204,7 @@ static bool is_char(char* p_str, val_t* p_val) /* If the string starts with a char indicator (backslash) */ if (p_str[0] == '\\') { - size_t length = strlen(p_str); + size_t length = pal_strlen(p_str); /* and it only has one character following it */ if(length == 2) { @@ -220,7 +221,7 @@ static bool is_char(char* p_str, val_t* p_val) while(named_chars[index]) { /* If we found a match */ - if( 0 == strcmp( (p_str + 1), (named_chars[index] + 2) ) ) + if( 0 == pal_strcmp( (p_str + 1), (named_chars[index] + 2) ) ) { /* Return the character value and indicate success */ *(p_val) = named_chars[index][0]; diff --git a/source/slvm/parser.h b/source/slvm/kernel/parser.h similarity index 100% rename from source/slvm/parser.h rename to source/slvm/kernel/parser.h diff --git a/source/slvm/main.c b/source/slvm/kernel/slvm.c similarity index 95% rename from source/slvm/main.c rename to source/slvm/kernel/slvm.c index e647b88..73cf2be 100644 --- a/source/slvm/main.c +++ b/source/slvm/kernel/slvm.c @@ -46,14 +46,14 @@ void docolon(val_t* code) { /* Built-in Constants *****************************************************************************/ -defconst("VERSION", version, 0, NULL, 1); -defconst("EXECDEF", execdef, 0, &version, (val_t)&docolon); -defconst("WORDSZ", wordsz, 0, &execdef, sizeof(val_t)); +defconst("VERSION", version, 0, NULL, 1) +defconst("EXECDEF", execdef, 0, &version, (val_t)&docolon) +defconst("WORDSZ", wordsz, 0, &execdef, sizeof(val_t)) /* Built-in Variables *****************************************************************************/ -defvar("state", state, 0, &wordsz, 0); -defvar("latest", latest, 0, &state, 0); +defvar("state", state, 0, &wordsz, 0) +defvar("latest", latest, 0, &state, 0) /* Word Words *****************************************************************************/ @@ -95,7 +95,7 @@ defcode("find", find, 0, &exec){ char* name = (char*)*(ArgStack); while(curr) { - if (!(curr->flags.attr.hidden) && (0 == strcmp(curr->name,name))) + if (!(curr->flags.attr.hidden) && (0 == pal_strcmp(curr->name,name))) { break; } @@ -164,9 +164,9 @@ defcode("create", create, 0, &rbrack){ char* name = 0u; if (*(ArgStack)) { - size_t namesz = strlen((char*)*(ArgStack)); + size_t namesz = pal_strlen((char*)*(ArgStack)); name = (char*)pal_allocate( namesz ); - strcpy(name, (char*)*(ArgStack)); + pal_strcpy(name, (char*)*(ArgStack)); } /* Create the word entry */ word_t* word = (word_t*)pal_allocate(sizeof(word_t)); @@ -454,20 +454,15 @@ defcode("b@b!", bytecopy, 0, &bytefetch){ defcode("bmove", bytemove, 0, &bytecopy){ } -/* Main - *****************************************************************************/ int main(int argc, char** argv) { - /* Default Kernel dictionary */ - //static dict_t kernel_dict = { NULL, (word_t*)&bytemove }; + (void)argc; + (void)argv; /* Compile-time Assertions */ CT_ASSERT(sizeof(val_t) == sizeof(val_t*)); CT_ASSERT(sizeof(val_t) == sizeof(flags_t)); /* Platform specific initialization */ - //_stdin_val = (val_t)stdin; - //_stdout_val = (val_t)stdout; - //_stderr_val = (val_t)stderr; latest_val = (val_t)&bytemove; /* Start the interpreter */ @@ -475,6 +470,22 @@ int main(int argc, char** argv) return 0; } +/* Main + *****************************************************************************/ +//int main(int argc, char** argv) +//{ +// /* Compile-time Assertions */ +// CT_ASSERT(sizeof(val_t) == sizeof(val_t*)); +// CT_ASSERT(sizeof(val_t) == sizeof(flags_t)); +// +// /* Platform specific initialization */ +// latest_val = (val_t)&bytemove; +// +// /* Start the interpreter */ +// EXEC(quit); +// return 0; +//} + /* Input/Output Words *****************************************************************************/ #if 0 @@ -680,4 +691,3 @@ defcode("printdefw", printdefw, 0, &printallw){ } #endif - diff --git a/source/slvm/slvm.h b/source/slvm/kernel/slvm.h similarity index 99% rename from source/slvm/slvm.h rename to source/slvm/kernel/slvm.h index 3600d1e..c84a42d 100644 --- a/source/slvm/slvm.h +++ b/source/slvm/kernel/slvm.h @@ -143,4 +143,6 @@ typedef struct dict_t { * */ void docolon(val_t* code); +void slvm_init(void); + #endif /* SLVM_H */ diff --git a/source/slvm/platform/C99/pal.c b/source/slvm/platforms/C99/pal.c similarity index 82% rename from source/slvm/platform/C99/pal.c rename to source/slvm/platforms/C99/pal.c index e04e4fa..40bc0cf 100644 --- a/source/slvm/platform/C99/pal.c +++ b/source/slvm/platforms/C99/pal.c @@ -4,7 +4,7 @@ $Revision$ $HeadURL$ */ -#include "../../pal.h" +#include "pal.h" #include #include @@ -79,4 +79,18 @@ bool pal_is_eof(void) return feof(stdin); } +int pal_strcmp(const char* p_str1, const char* p_str2) +{ + return strcmp(p_str1, p_str2); +} + +size_t pal_strlen(char* p_str) +{ + return strlen( p_str ); +} + +char* pal_strcpy(char* p_dest, const char* p_src) +{ + return strcpy(p_dest, p_src); +}