From ca227e249861a659fa397044a8f391b65dbc317a Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Mon, 5 May 2014 16:48:26 -0400 Subject: [PATCH] kernel code no longer depends on C standard lib --- source/slvm/main.c | 20 +++++++------------- source/slvm/pal.h | 1 + source/slvm/platform/C99/pal.c | 5 +++++ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/source/slvm/main.c b/source/slvm/main.c index c859dd9..f552c58 100644 --- a/source/slvm/main.c +++ b/source/slvm/main.c @@ -1,9 +1,3 @@ -#include -#include -#include -#include -#include -#include #include "slvm.h" #include "parser.h" #include "pal.h" @@ -175,7 +169,7 @@ defcode("parse", _parse, 0, &_fetch){ if (*(ArgStack) > STRING) { /* Free the mem */ - free(p_str); + pal_free(p_str); } } @@ -223,11 +217,11 @@ defcode("create", create, 0, &rbrack){ if (*(ArgStack)) { size_t namesz = strlen((char*)*(ArgStack)); - name = (char*)malloc( namesz ); + name = (char*)pal_allocate( namesz ); strcpy(name, (char*)*(ArgStack)); } /* Create the word entry */ - word_t* word = (word_t*)malloc(sizeof(word_t)); + word_t* word = (word_t*)pal_allocate(sizeof(word_t)); word->link = (word_t*)latest_val; /* Initialize the flags (hidden and non-immediate by default) */ word->flags.attr.immed = 0; @@ -236,7 +230,7 @@ defcode("create", create, 0, &rbrack){ /* Initialize the name, codeword, and bytecode */ word->name = name; word->codeword = &docolon; - word->code = (val_t*)malloc(sizeof(val_t)); + word->code = (val_t*)pal_allocate(sizeof(val_t)); word->code[0] = (val_t)&ret; /* Update Latest and Return the new word */ latest_val = (val_t)word; @@ -252,7 +246,7 @@ defcode(",", comma, 0, &create){ ArgStack--; /* Resize the code section and relocate if necessary */ word->flags.attr.codesize++; - word->code = (val_t*)realloc(word->code, word->flags.attr.codesize * sizeof(val_t)); + word->code = (val_t*)pal_reallocate(word->code, word->flags.attr.codesize * sizeof(val_t)); /* Update "here" and terminate the code section */ word->code[word->flags.attr.codesize-1] = (val_t)&ret; } @@ -317,7 +311,7 @@ defcode("interp", interp, 0, &_parse){ else { /* Ask the user what gives */ - printf("%s ?\n", p_str); + pal_unknown_word(p_str); /* Consume the token */ ArgStack--; } @@ -335,7 +329,7 @@ defcode("interp", interp, 0, &_parse){ } /* If we saved off a pointer, we're done with it so free the memory */ - if(p_str) free(p_str); + if(p_str) pal_free(p_str); } defcode("quit", quit, 0, &interp){ diff --git a/source/slvm/pal.h b/source/slvm/pal.h index 2b8f514..86171ca 100644 --- a/source/slvm/pal.h +++ b/source/slvm/pal.h @@ -16,6 +16,7 @@ extern val_t* CodePtr; dict_t* pal_init(dict_t* p_prev_dict); void pal_prompt(void); +void pal_unknown_word(char* p_str); void* pal_allocate(size_t size); void* pal_reallocate(void* p_mem, size_t size); void pal_free(void* p_mem); diff --git a/source/slvm/platform/C99/pal.c b/source/slvm/platform/C99/pal.c index 247a3a4..e04e4fa 100644 --- a/source/slvm/platform/C99/pal.c +++ b/source/slvm/platform/C99/pal.c @@ -38,6 +38,11 @@ void pal_prompt(void) } } +void pal_unknown_word(char* p_str) +{ + printf("%s ?\n", p_str); +} + void* pal_allocate(size_t size) { return malloc(size); -- 2.55.0