]> git.mdlowis.com Git - proto/sclpl.git/commitdiff
added some basic built-in words
authorMike D. Lowis <mdlowis@loki.att.net>
Tue, 1 Apr 2014 01:43:14 +0000 (21:43 -0400)
committerMike D. Lowis <mdlowis@loki.att.net>
Tue, 1 Apr 2014 01:43:14 +0000 (21:43 -0400)
SConstruct
source/slvm/main.c
source/slvm/wordlist.c
source/slvm/wordlist.h

index edb84402a2e1711eebcf0c18750e6378011ce1c9..2303401125d9548dccf4555ece20e403a2263431 100644 (file)
@@ -72,33 +72,33 @@ scheme.PrependENVPath('PATH', './build')
 #------------------------------------------------------------------------------
 
 # SOF Shared Library
-c_cpp.SharedLibrary('build/sof', find_files('source/libsof/','*.c'))
+#c_cpp.SharedLibrary('build/sof', find_files('source/libsof/','*.c'))
 
 # SBC Shared Library
-c_cpp.SharedLibrary('build/sbc', find_files('source/libsbc/','*.c'))
+#c_cpp.SharedLibrary('build/sbc', find_files('source/libsbc/','*.c'))
 
 # readsof Command Line Utility
-readsof = c_cpp.Clone(
-        CPPPATH = [ 'source/libsof/' ],
-        LIBS = [ 'sof' ],
-        LIBPATH = [ 'build' ])
-readsof.Program('build/readsof', find_files('source/readsof/','*.c'))
-readsof.Depends('readsof', 'sof')
-
-# SCLPL Compiler
-SchemeBuildAndTest( 'build/slc',
-                    find_files('source/slc/','*.scm'),
-                    find_files('tests/slc/','*.scm') )
-
-# SCLPL Package Manager
-SchemeBuildAndTest( 'build/slpkg',
-                    find_files('source/slpkg/','*.scm'),
-                    find_files('tests/slpkg/','*.scm') )
-
-# SCLPL Assembler
-SchemeBuildAndTest( 'build/slas',
-                    find_files('source/slas/','*.scm'),
-                    find_files('tests/slas/','*.scm') )
+#readsof = c_cpp.Clone(
+#        CPPPATH = [ 'source/libsof/' ],
+#        LIBS = [ 'sof' ],
+#        LIBPATH = [ 'build' ])
+#readsof.Program('build/readsof', find_files('source/readsof/','*.c'))
+#readsof.Depends('readsof', 'sof')
+
+## SCLPL Compiler
+#SchemeBuildAndTest( 'build/slc',
+#                    find_files('source/slc/','*.scm'),
+#                    find_files('tests/slc/','*.scm') )
+#
+## SCLPL Package Manager
+#SchemeBuildAndTest( 'build/slpkg',
+#                    find_files('source/slpkg/','*.scm'),
+#                    find_files('tests/slpkg/','*.scm') )
+#
+## SCLPL Assembler
+#SchemeBuildAndTest( 'build/slas',
+#                    find_files('source/slas/','*.scm'),
+#                    find_files('tests/slas/','*.scm') )
 
 # SCLPL Virtual Machine
 c_cpp.Program('build/slvm', find_files('source/slvm/','*.c'))
index d56b5af2954fb2a04edd3ecd69a2acddb4b3305f..dbcffb8049a14b5bdcf2062a91daf9f79fdb449a 100644 (file)
@@ -1,11 +1,51 @@
 #include <stdio.h>
 #include <stdint.h>
+#include <string.h>
 #include "wordlist.h"
 
+static word_t* find_word(char* name);
+static void exec_word(word_t* word);
+
 long* ArgStackPtr;
+long* InstructionPtr;
 
 int main(int argc, char** argv)
 {
-    puts("Hello, World!");
+    long stack[] = {0,42,0,0};
+    ArgStackPtr = &stack[1];
+
+    //exec_word(find_word("dupdup"));
+    exec_word(find_word("dup"));
+
+    printf("stack[3] = %d\n", (int)stack[3]);
+    printf("stack[2] = %d\n", (int)stack[2]);
+    printf("stack[1] = %d\n", (int)stack[1]);
+    printf("stack[0] = %d\n", (int)stack[0]);
     return 0;
 }
+
+static word_t* find_word(char* name) {
+    word_t* curr = LatestWord;
+    while(curr)
+    {
+        if (0 == strcmp(curr->name,name))
+        {
+            break;
+        }
+        curr = curr->link;
+    }
+    return curr;
+}
+
+static void exec_word(word_t* word) {
+    word->codeword(word->code);
+}
+
+void exec_word_def(long* code) {
+    while(*code)
+    {
+        exec_word( (word_t*)(*code) );
+        code++;
+    }
+}
+
index 12404ea6566aac9effb0a455617421c1d3028ec7..2a0d075f2794fb2e1492e237fe837a85098af280 100644 (file)
@@ -2,20 +2,22 @@
 
 extern long* ArgStackPtr;
 
+extern void exec_word_def(long* code);
+
 /**
  * Define a built-in word that executes native code */
 #define defcode(name_str,c_name,flags,prev) \
-    extern void c_name##_code(void);   \
-    extern char c_name##_str[];        \
-    word_t c_name = {                  \
-        prev,                          \
-        flags,                         \
-        c_name##_str,                  \
-        &c_name##_code,                \
-        0                              \
-    };                                 \
-    char c_name##_str[] = name_str;    \
-    void c_name##_code(void)           \
+    extern void c_name##_code(long* code);  \
+    extern char c_name##_str[];             \
+    word_t c_name = {                       \
+        prev,                               \
+        flags,                              \
+        c_name##_str,                       \
+        &c_name##_code,                     \
+        0                                   \
+    };                                      \
+    char c_name##_str[] = name_str;         \
+    void c_name##_code(long* inst_ptr)      \
 
 /**
  * Define a built-in word that is defined by references to other words. */
@@ -26,13 +28,16 @@ extern long* ArgStackPtr;
         prev,                          \
         flags,                         \
         c_name##_str,                  \
-        &do_colon,                     \
+        &exec_word_def,                \
         c_name##_code                  \
     };                                 \
     char c_name##_str[] = name_str;    \
     long c_name##_code[] =
 
-/*****************************************************************************/
+#define w(name) (long)&name
+
+/* Built-in Primitive Words
+ *****************************************************************************/
 defcode("drop", drop, 0, 0){
     ArgStackPtr--;
 }
@@ -67,6 +72,98 @@ defcode("-rot", nrot, 0, &rot){
     *(ArgStackPtr) = temp;
 }
 
-/*****************************************************************************/
-word_t* LatestWord = &nrot;
+defcode("2drop", twodrop, 0, &nrot){}
+
+defcode("2dup", twodup, 0, &twodrop){}
+
+defcode("2swap", twoswap, 0, &twodup){}
+
+defcode("?dup", qdup, 0, &twoswap){}
+
+defcode("1+", incr, 0, &qdup){}
+
+defcode("1-", decr, 0, &incr){}
+
+defcode("4+", incr4, 0, &decr){}
+
+defcode("4-", decr4, 0, &incr4){}
+
+defcode("+", add, 0, &decr4){}
+
+defcode("-", sub, 0, &add){}
+
+defcode("*", mul, 0, &sub){}
+
+defcode("/", div, 0, &mul){}
+
+defcode("/mod", divmod, 0, &div){}
+
+defcode("=", equal, 0, &divmod){}
+
+defcode("!=", notequal, 0, &equal){}
+
+defcode("<", lessthan, 0, &notequal){}
+
+defcode(">", greaterthan, 0, &lessthan){}
+
+defcode("<=", lessthaneq, 0, &greaterthan){}
+
+defcode(">=", greaterthaneq, 0, &lessthaneq){}
+
+defcode("0=", zeroeq, 0, &greaterthaneq){}
+
+defcode("0!=", zeroneq, 0, &zeroeq){}
+
+defcode("0<", zerolt, 0, &zeroneq){}
+
+defcode("0>", zerogt, 0, &zerolt){}
+
+defcode("0<=", zerolte, 0, &zerogt){}
+
+defcode("0>=", zerogte, 0, &zerolte){}
+
+defcode("and", and, 0, &zerogte){}
+
+defcode("or", or, 0, &and){}
+
+defcode("not", not, 0, &or){}
+
+defcode("band", band, 0, &not){}
+
+defcode("bor", bor, 0, &band){}
+
+defcode("bxor", bxor, 0, &bor){}
+
+defcode("bnot", bnot, 0, &bxor){}
+
+defcode("lit", lit, 0, &bnot){}
+
+defcode("!", store, 0, &lit){}
+
+defcode("@", fetch, 0, &store){}
+
+defcode("+!", addstore, 0, &fetch){}
+
+defcode("-!", substore, 0, &addstore){}
+
+defcode("b!", bytestore, 0, &substore){}
+
+defcode("b@", bytefetch, 0, &bytestore){}
+
+defcode("b@b!", bytecopy, 0, &bytefetch){}
+
+defcode("bmove", bytemove, 0, &bytecopy){}
+
+/* Built-in Variables
+ *****************************************************************************/
+
+/* Built-in Constants
+ *****************************************************************************/
+
+/* Built-in Defined Words
+ *****************************************************************************/
+
+/* Latest Defined Word
+ *****************************************************************************/
+word_t* LatestWord = &bytemove;
 
index 49fa6f9b4ca26941924823dda7ee86a75dc26d42..4171735a894e511eb48864c6aa7add929ed0742e 100644 (file)
@@ -7,7 +7,7 @@
 #ifndef WORDLIST_H
 #define WORDLIST_H
 
-typedef void (*codeword_t)(void);
+typedef void (*codeword_t)(long*);
 
 typedef struct word_t {
     struct word_t* link;