From: Michael D. Lowis Date: Wed, 7 May 2014 17:42:19 +0000 (-0400) Subject: Added build targets for 'extensions'. Moved some of the disabled code from slvm.c... X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=05ccc5b3f435a59d5df2a3f264811c3a276b1e53;p=proto%2Fsclpl.git Added build targets for 'extensions'. Moved some of the disabled code from slvm.c to new extension modules in preparation for a plugin architecture. --- diff --git a/source/slvm/extensions/core/core.c b/source/slvm/extensions/core/core.c new file mode 100644 index 0000000..b3d303b --- /dev/null +++ b/source/slvm/extensions/core/core.c @@ -0,0 +1,72 @@ +#include "core.h" +#include "pal.h" +#include + +#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 index 0000000..a48644f --- /dev/null +++ b/source/slvm/extensions/core/core.h @@ -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 index 0000000..11541c2 --- /dev/null +++ b/source/slvm/extensions/io/io.c @@ -0,0 +1,64 @@ +/** + @file io.c + @brief See header for details + $Revision$ + $HeadURL$ + */ +#include "io.h" +#include +#include + +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 index 0000000..4ad9825 --- /dev/null +++ b/source/slvm/extensions/io/io.h @@ -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 */ diff --git a/source/slvm/kernel/slvm.c b/source/slvm/kernel/slvm.c index 73cf2be..3e24213 100644 --- a/source/slvm/kernel/slvm.c +++ b/source/slvm/kernel/slvm.c @@ -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 *****************************************************************************/ diff --git a/source/slvm/kernel/slvm.h b/source/slvm/kernel/slvm.h index c84a42d..4da3715 100644 --- a/source/slvm/kernel/slvm.h +++ b/source/slvm/kernel/slvm.h @@ -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 */