]> git.mdlowis.com Git - proto/sclpl.git/commitdiff
Broke dependency on stdlib for vmkernel (also broke number parsing but nevermind...
authorMichael D. Lowis <mike@mdlowis.com>
Tue, 6 May 2014 17:42:18 +0000 (13:42 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Tue, 6 May 2014 17:42:18 +0000 (13:42 -0400)
SConstruct
source/slvm/kernel/pal.h [moved from source/slvm/pal.h with 78% similarity]
source/slvm/kernel/parser.c [moved from source/slvm/parser.c with 93% similarity]
source/slvm/kernel/parser.h [moved from source/slvm/parser.h with 100% similarity]
source/slvm/kernel/slvm.c [moved from source/slvm/main.c with 95% similarity]
source/slvm/kernel/slvm.h [moved from source/slvm/slvm.h with 99% similarity]
source/slvm/platforms/C99/pal.c [moved from source/slvm/platform/C99/pal.c with 82% similarity]

index 59fbac4b2a1302cd2db39bc3514dde873fec5657..c4097347005ca9bdf2c0f601ea0f5323b250d44b 100644 (file)
@@ -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'))
 
similarity index 78%
rename from source/slvm/pal.h
rename to source/slvm/kernel/pal.h
index 86171cafb1c47e26692fe092143bda350dbbebd7..634c2dccdf9548d6ffb320dfd532de688acd90e8 100644 (file)
@@ -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 */
similarity index 93%
rename from source/slvm/parser.c
rename to source/slvm/kernel/parser.c
index 8da82fd82cbdd0b74612ca8f7ba1da28fedbace9..019dc7548fc32fcbff831344171c732410b18bae 100644 (file)
@@ -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];
similarity index 95%
rename from source/slvm/main.c
rename to source/slvm/kernel/slvm.c
index e647b88e641647c1c2acaec944f43e580153e9c9..73cf2be1cd3bd8f0f446d904ac8d2a750c400973 100644 (file)
@@ -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
 
-
similarity index 99%
rename from source/slvm/slvm.h
rename to source/slvm/kernel/slvm.h
index 3600d1e098c47dbddbc102212704a07e67188786..c84a42d9083feace17918adaad7866d5d51205c3 100644 (file)
@@ -143,4 +143,6 @@ typedef struct dict_t {
  * */
 void docolon(val_t* code);
 
+void slvm_init(void);
+
 #endif /* SLVM_H */
similarity index 82%
rename from source/slvm/platform/C99/pal.c
rename to source/slvm/platforms/C99/pal.c
index e04e4fa20797f81e5a3c5aa4fbcd17c565dc62b3..40bc0cf0bebb84dc896601a52480150b2e39f8e8 100644 (file)
@@ -4,7 +4,7 @@
   $Revision$
   $HeadURL$
 */
-#include "../../pal.h"
+#include "pal.h"
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -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);
+}