--- /dev/null
+#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;
+}
--- /dev/null
+/**
+ @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 */
--- /dev/null
+/**
+ @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;
+}
--- /dev/null
+/**
+ @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 */
// 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
*****************************************************************************/
/** 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 */