]> git.mdlowis.com Git - proto/sclpl.git/commitdiff
Added build targets for 'extensions'. Moved some of the disabled code from slvm.c...
authorMichael D. Lowis <mike@mdlowis.com>
Wed, 7 May 2014 17:42:19 +0000 (13:42 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Wed, 7 May 2014 17:42:19 +0000 (13:42 -0400)
source/slvm/extensions/core/core.c [new file with mode: 0644]
source/slvm/extensions/core/core.h [new file with mode: 0644]
source/slvm/extensions/io/io.c [new file with mode: 0644]
source/slvm/extensions/io/io.h [new file with mode: 0644]
source/slvm/kernel/slvm.c
source/slvm/kernel/slvm.h

diff --git a/source/slvm/extensions/core/core.c b/source/slvm/extensions/core/core.c
new file mode 100644 (file)
index 0000000..b3d303b
--- /dev/null
@@ -0,0 +1,72 @@
+#include "core.h"
+#include "pal.h"
+#include <stdlib.h>
+
+#if 0
+defcode("if", _if, 1, &bytemove){
+    /* Compile branch instruction */
+    ArgStack++;
+    *(ArgStack) = (val_t)&zbranch;
+    EXEC(comma);
+
+    /* Save off the current offset */
+    EXEC(here);
+
+    /* Compile a dummy offset */
+    ArgStack++;
+    *(ArgStack) = (val_t)0;
+    EXEC(comma);
+}
+
+defcode("then", _then, 1, &_if){
+    /* calculate the address where the offset should be stored */
+    EXEC(swap);
+    EXEC(dup);
+    EXEC(wcode);
+    EXEC(nrot);
+
+    /* Calculate the branch offset */
+    EXEC(dup);
+    EXEC(here);
+    EXEC(swap);
+    EXEC(sub);
+
+    /* Store the offset */
+    EXEC(swap);
+    EXEC(wordsz);
+    EXEC(mul);
+    EXEC(nrot);
+    EXEC(add);
+    EXEC(store);
+}
+
+defcode("else", _else, 1, &_then){
+    /* Compile the branch instruction */
+    ArgStack++;
+    *(ArgStack) = (val_t)&branch;
+    EXEC(comma);
+
+    /* Save off the current offset */
+    EXEC(here);
+    EXEC(rot);
+
+    /* Compile a dummy offset */
+    ArgStack++;
+    *(ArgStack) = 0;
+    EXEC(comma);
+
+    /* Set the branch offset for the first branch */
+    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;
+    return p_dict;
+}
diff --git a/source/slvm/extensions/core/core.h b/source/slvm/extensions/core/core.h
new file mode 100644 (file)
index 0000000..a48644f
--- /dev/null
@@ -0,0 +1,14 @@
+/**
+  @file core.h
+  @brief TODO: Describe this file
+  $Revision$
+  $HeadURL$
+  */
+#ifndef HDR_H
+#define HDR_H
+
+#include "slvm.h"
+
+dict_t* core_init(dict_t* p_prev);
+
+#endif /* HDR_H */
diff --git a/source/slvm/extensions/io/io.c b/source/slvm/extensions/io/io.c
new file mode 100644 (file)
index 0000000..11541c2
--- /dev/null
@@ -0,0 +1,64 @@
+/**
+  @file io.c
+  @brief See header for details
+  $Revision$
+  $HeadURL$
+  */
+#include "io.h"
+#include <stdio.h>
+#include <pal.h>
+
+defvar("stdin",  _stdin,  0, NULL,     0);
+defvar("stdout", _stdout, 0, &_stdin,  0);
+defvar("stderr", _stderr, 0, &_stdout, 0);
+
+defconst("F_R",  f_r,  0, &_stderr, (val_t)"r");
+defconst("F_W",  f_w,  0, &f_r,     (val_t)"w");
+defconst("F_A",  f_a,  0, &f_w,     (val_t)"a");
+defconst("F_R+", f_ru, 0, &f_a,     (val_t)"r+");
+defconst("F_W+", f_wu, 0, &f_ru,    (val_t)"w+");
+defconst("F_A+", f_au, 0, &f_wu,    (val_t)"a+");
+
+defcode("fopen",  _fopen,  0, &f_au){
+    *(ArgStack-1) = (val_t)fopen( (const char*)*(ArgStack-1), (const char*)*(ArgStack) );
+    ArgStack--;
+}
+
+defcode("fclose", _fclose, 0, &_fopen){
+    fclose((FILE*)*(ArgStack));
+    ArgStack--;
+}
+
+defcode("fflush", _fflush, 0, &_fclose){
+    fflush((FILE*)*(ArgStack));
+    ArgStack--;
+}
+
+defcode("fgetc",  _fgetc,  0, &_fflush){
+    *(ArgStack) = fgetc((FILE*)*(ArgStack));
+}
+
+defcode("fputc",  _fputc,  0, &_fgetc){
+    fputc((char)*(ArgStack-1), (FILE*)*(ArgStack));
+    ArgStack -= 2;
+}
+
+defcode("fputs",  _fputs,  0, &_fputc){
+    fputs((char*)*(ArgStack-1), (FILE*)*(ArgStack));
+    ArgStack -= 2;
+}
+
+defcode("fpeekc", _fpeekc, 0, &_fputs){
+    FILE* p_file = (FILE*)*(ArgStack);
+    *(ArgStack) = fgetc(p_file);
+    ungetc((char)*(ArgStack), p_file);
+}
+
+dict_t* io_init(dict_t* p_prev)
+{
+    dict_t* p_dict = (dict_t*)pal_allocate(sizeof(dict_t));
+    p_dict->name    = "io";
+    p_dict->p_prev  = p_prev;
+    p_dict->p_words = (word_t*)&_fpeekc;
+    return p_dict;
+}
diff --git a/source/slvm/extensions/io/io.h b/source/slvm/extensions/io/io.h
new file mode 100644 (file)
index 0000000..4ad9825
--- /dev/null
@@ -0,0 +1,14 @@
+/**
+  @file io.h
+  @brief TODO: Describe this file
+  $Revision$
+  $HeadURL$
+  */
+#ifndef IO_H
+#define IO_H
+
+#include "slvm.h"
+
+dict_t* io_init(dict_t* p_prev);
+
+#endif /* IO_H */
index 73cf2be1cd3bd8f0f446d904ac8d2a750c400973..3e242135edc73d7f455e3144fd7863fc72365c21 100644 (file)
@@ -486,116 +486,8 @@ int main(int argc, char** argv)
 //    return 0;
 //}
 
-/* Input/Output Words
- *****************************************************************************/
-#if 0
-defvar("stdin",  _stdin,  0, &here,    0);
-defvar("stdout", _stdout, 0, &_stdin,  0);
-defvar("stderr", _stderr, 0, &_stdout, 0);
-
-defconst("F_R",  f_r,  0, &_stderr, (val_t)"r");
-defconst("F_W",  f_w,  0, &f_r,     (val_t)"w");
-defconst("F_A",  f_a,  0, &f_w,     (val_t)"a");
-defconst("F_R+", f_ru, 0, &f_a,     (val_t)"r+");
-defconst("F_W+", f_wu, 0, &f_ru,    (val_t)"w+");
-defconst("F_A+", f_au, 0, &f_wu,    (val_t)"a+");
-
-defcode("fopen",  _fopen,  0, &f_au){
-    *(ArgStack-1) = (val_t)fopen( (const char*)*(ArgStack-1), (const char*)*(ArgStack) );
-    ArgStack--;
-}
-
-defcode("fclose", _fclose, 0, &_fopen){
-    fclose((FILE*)*(ArgStack));
-    ArgStack--;
-}
-
-defcode("fflush", _fflush, 0, &_fclose){
-    fflush((FILE*)*(ArgStack));
-    ArgStack--;
-}
-
-defcode("fgetc",  _fgetc,  0, &_fflush){
-    *(ArgStack) = fgetc((FILE*)*(ArgStack));
-}
-
-defcode("fputc",  _fputc,  0, &_fgetc){
-    fputc((char)*(ArgStack-1), (FILE*)*(ArgStack));
-    ArgStack -= 2;
-}
-
-defcode("fputs",  _fputs,  0, &_fputc){
-    fputs((char*)*(ArgStack-1), (FILE*)*(ArgStack));
-    ArgStack -= 2;
-}
-
-defcode("fpeekc", _fpeekc, 0, &_fputs){
-    FILE* p_file = (FILE*)*(ArgStack);
-    *(ArgStack) = fgetc(p_file);
-    ungetc((char)*(ArgStack), p_file);
-}
-#endif
-
 /* Control Flow Words
  *****************************************************************************/
-#if 0
-defcode("if", _if, 1, &bytemove){
-    /* Compile branch instruction */
-    ArgStack++;
-    *(ArgStack) = (val_t)&zbranch;
-    EXEC(comma);
-
-    /* Save off the current offset */
-    EXEC(here);
-
-    /* Compile a dummy offset */
-    ArgStack++;
-    *(ArgStack) = (val_t)0;
-    EXEC(comma);
-}
-
-defcode("then", _then, 1, &_if){
-    /* calculate the address where the offset should be stored */
-    EXEC(swap);
-    EXEC(dup);
-    EXEC(wcode);
-    EXEC(nrot);
-
-    /* Calculate the branch offset */
-    EXEC(dup);
-    EXEC(here);
-    EXEC(swap);
-    EXEC(sub);
-
-    /* Store the offset */
-    EXEC(swap);
-    EXEC(wordsz);
-    EXEC(mul);
-    EXEC(nrot);
-    EXEC(add);
-    EXEC(store);
-}
-
-defcode("else", _else, 1, &_then){
-    /* Compile the branch instruction */
-    ArgStack++;
-    *(ArgStack) = (val_t)&branch;
-    EXEC(comma);
-
-    /* Save off the current offset */
-    EXEC(here);
-    EXEC(rot);
-
-    /* Compile a dummy offset */
-    ArgStack++;
-    *(ArgStack) = 0;
-    EXEC(comma);
-
-    /* Set the branch offset for the first branch */
-    EXEC(_then);
-    EXEC(swap);
-}
-#endif
 
 /* Memory Management Words
  *****************************************************************************/
index c84a42d9083feace17918adaad7866d5d51205c3..4da3715ab26eaf2e7d2bbb252f0b81700e33e9cd 100644 (file)
@@ -80,11 +80,11 @@ typedef struct word_t {
 /** This structure defines a dictionary of defined words. */
 typedef struct dict_t {
     /** Pointer to the previously loaded dictionary */
-    struct dict_t* link;
+    struct dict_t* p_prev;
     /** The name of the dictionary */
     char* name;
     /** Pointer to the most recently defined word in this dictionary */
-    word_t* words;
+    word_t* p_words;
 } dict_t;
 
 /** Execute a built-in word directly */