]> git.mdlowis.com Git - projs/onward.git/commitdiff
restructured code to allow accessing core words from other modules
authorMichael D. Lowis <mike.lowis@gentex.com>
Thu, 13 Nov 2014 21:22:08 +0000 (16:22 -0500)
committerMichael D. Lowis <mike.lowis@gentex.com>
Thu, 13 Nov 2014 21:22:08 +0000 (16:22 -0500)
build.rb
source/main.c
source/onward/onward.c
source/onward/onward.h

index 75ccdc55035d700b5fd535612bf7e02a8fd6a2b2..a719734bef6f721bad24cfd1ab1dda396171277b 100644 (file)
--- a/build.rb
+++ b/build.rb
@@ -26,22 +26,20 @@ test_env = base_env.clone do |env|
   end
 end
 
+#------------------------------------------------------------------------------
+# Test Build Targets
+#------------------------------------------------------------------------------
+unless Opts[:profile].include? "no-tests"
+  test_env.Program('onward-tests', [
+      'source/onward/onward.c',
+      'modules/atf/source/atf.c'] +
+      Dir['tests/**/*.c'])
+  test_env.Command('TESTS', [], 'CMD' => ['./onward-tests'])
+end
+
 #------------------------------------------------------------------------------
 # Release Build Targets
 #------------------------------------------------------------------------------
 main_env.Library('libonward.a', FileList['source/onward/*.c'])
 main_env.Program('onward', ['source/main.c', 'libonward.a'])
 
-#------------------------------------------------------------------------------
-# Test Build Targets
-#------------------------------------------------------------------------------
-if Opts[:profile].include? "test"
-    test_env.Program('onward-tests', [
-        'source/onward/onward.c',
-        'modules/atf/source/atf.c'] +
-        Dir['tests/**/*.c'])
-    test_env.Command('TESTS', [], 'CMD' => ['./onward-tests'])
-#    FileList['source/sclpl/*.c', 'build/lib/libopts.a', 'build/lib/libcds.a'])
-#  test_env.Command('RSpec', [], 'CMD' => [
-#      'rspec', '--pattern', 'spec/**{,/*/**}/*_spec.rb', '--format', 'documentation'])
-end
index a6f68d2e04a81b35df9a9c549c539f4d2030c2ff..8e66262016573256441e910e476a71096c91a65a 100755 (executable)
@@ -1,13 +1,6 @@
 #include "onward.h"
 #include <stdio.h>
 
-//extern value_t input;
-//extern value_t state;
-//extern value_t errno;
-//extern value_t asb;
-//extern value_t asp;
-//extern value_t rsb;
-//extern value_t rsp;
 
 #define STACK_SZ (64u)
 
@@ -36,7 +29,16 @@ int main(int argc, char** argv) {
     (void)argc;
     (void)argv;
 
-    onward_init(Arg_Stack_Buf, Ret_Stack_Buf, Ram_Data_Buf, (word_t*)&bnot);
+    onward_init_t init_data = {
+        Arg_Stack_Buf,
+        STACK_SZ,
+        Ret_Stack_Buf,
+        STACK_SZ,
+        Ram_Data_Buf,
+        8192/sizeof(value_t),
+        (word_t*)&bnot
+    };
+    onward_init(&init_data);
 
     printf(":> ");
     while(0 != (input = (value_t)fgets(Input_Line, 1024u, stdin))) {
index d1bd30e843f919413436b4f39fee9905796627a0..4e4a5c6c09b579204ff65f15f72455759589e913 100755 (executable)
@@ -27,14 +27,18 @@ defvar("pc", pc, 0, &F_IMMEDIATE_word);
 /** The address of the base of the argument stack */
 defvar("asb", asb, 0, &pc_word);
 
+defvar("assz", assz, 0, &asb_word);
+
 /** The address of the top of the argument stack */
-defvar("asp", asp, 0, &asb_word);
+defvar("asp", asp, 0, &assz_word);
 
 /** The address of the base of the return stack */
 defvar("rsb", rsb, 0, &asp_word);
 
+defvar("rssz", rssz, 0, &rsb_word);
+
 /** The address of the top of the return stack */
-defvar("rsp", rsp, 0, &rsb_word);
+defvar("rsp", rsp, 0, &rssz_word);
 
 /** The address of the current input string */
 defvar("input", input, 0, &rsp_word);
@@ -449,13 +453,14 @@ defcode("~", bnot, &bxor, 0u) {
 
 /* Helper C Functions
  *****************************************************************************/
-void onward_init(value_t* arg_stack, value_t* ret_stack, value_t* ram_buf, word_t* latest_word) {
-    asb    = (value_t)arg_stack;
-    asp    = (value_t)arg_stack;
-    rsb    = (value_t)ret_stack;
-    rsp    = (value_t)ret_stack;
-    latest = (value_t)latest_word;
-    here   = (value_t)ram_buf;
+
+void onward_init(onward_init_t* init_data) {
+    asb    = (value_t)(init_data->arg_stack - 1);
+    asp    = (value_t)(init_data->arg_stack - 1);
+    rsb    = (value_t)(init_data->ret_stack - 1);
+    rsp    = (value_t)(init_data->ret_stack - 1);
+    here   = (value_t)(init_data->word_buf);
+    latest = (value_t)(init_data->latest);
 }
 
 value_t onward_pcfetch(void) {
index 6b8c20bbcd0701084ca876c7c0f127b80a3abcd0..b630b11e9273474d81267c5cd146e66e9c5e91bc 100755 (executable)
@@ -6,6 +6,7 @@
 #define ONWARD_H
 
 #include <stdint.h>
+
 #if defined(BITS_16)
     typedef int16_t value_t;
 #elif defined(BITS_32)
@@ -32,6 +33,16 @@ typedef struct word_t {
 /** Type definition for the C function associated with primitive words */
 typedef void (*primitive_t)(void);
 
+typedef struct {
+    value_t* arg_stack;
+    value_t  arg_stack_sz;
+    value_t* ret_stack;
+    value_t  ret_stack_sz;
+    value_t* word_buf;
+    value_t  word_buf_sz;
+    word_t*  latest;
+} onward_init_t;
+
 #define deccode(c_name)       \
     void c_name##_code(void); \
     const word_t c_name       \
@@ -102,6 +113,14 @@ typedef void (*primitive_t)(void);
 /** Macro to get use the word pointer in a defined word */
 #define W(name) ((value_t)&name)
 
+void onward_init(onward_init_t* init_data);
+value_t onward_pcfetch(void);
+void onward_aspush(value_t val);
+value_t onward_aspeek(value_t val);
+value_t onward_aspop(void);
+void onward_rspush(value_t val);
+value_t onward_rspop(void);
+
 decconst(VERSION);
 decconst(CELLSZ);
 decconst(BITCOUNT);
@@ -163,12 +182,4 @@ deccode(bor);
 deccode(bxor);
 deccode(bnot);
 
-value_t onward_pcfetch(void);
-void onward_aspush(value_t val);
-value_t onward_aspeek(value_t val);
-value_t onward_aspop(void);
-void onward_rspush(value_t val);
-value_t onward_rspop(void);
-void onward_init(value_t* arg_stack, value_t* ret_stack, value_t* ram_buf, word_t* latest_word);
-
 #endif /* ONWARD_H */