From: Michael D. Lowis Date: Sat, 22 Nov 2014 18:24:29 +0000 (-0500) Subject: Added an implementation specific dumpw word for decompiling defined words X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=68aeb2dca82e229c3c9953de31d8ea69897bc3e8;p=projs%2Fonward.git Added an implementation specific dumpw word for decompiling defined words --- diff --git a/source/main.c b/source/main.c index 8e66262..14565f7 100755 --- a/source/main.c +++ b/source/main.c @@ -1,14 +1,31 @@ #include "onward.h" #include - #define STACK_SZ (64u) - value_t Arg_Stack_Buf[STACK_SZ]; value_t Ret_Stack_Buf[STACK_SZ]; char Input_Line[1024]; value_t Ram_Data_Buf[8192/sizeof(value_t)]; +defcode("dumpw", dumpw, LATEST_BUILTIN, 0u) { + word_t* word = (word_t*)onward_aspop(); + printf("name:\t'%s'\n", word->name); + printf("flags:\t%#lx\n", word->flags); + printf("link:\t%p\n", word->link); + /* Print the word's instructions */ + if (word->flags & F_PRIMITIVE_MSK) { + printf("code:\t%p\n", word->code); + } else { + printf("code:"); + word_t** code = (word_t**)word->code; + while(*code) { + printf("\t%s\n", (*code)->name); + code++; + } + printf("\tret\n"); + } +} + void print_stack(void) { value_t* base = (value_t*)asb; value_t* top = (value_t*)asp; @@ -36,7 +53,7 @@ int main(int argc, char** argv) { STACK_SZ, Ram_Data_Buf, 8192/sizeof(value_t), - (word_t*)&bnot + (word_t*)&dumpw }; onward_init(&init_data); diff --git a/source/onward/onward.c b/source/onward/onward.c index 992e058..13f192d 100755 --- a/source/onward/onward.c +++ b/source/onward/onward.c @@ -76,7 +76,7 @@ defcode("word", word, &here_word, 0u) { /** Ignore the rest of a given line of input */ defcode("\\", dropline, &word, F_IMMEDIATE_MSK) { - input = (char*)""; + input = (intptr_t)""; } /** Parses a string as a number literal */ @@ -213,7 +213,7 @@ defcode(",", comma, &create, 0u) { } /** Set the interpreter mode to "interpret" */ -defcode("[", lbrack, &comma, 0u) { +defcode("[", lbrack, &comma, F_IMMEDIATE_MSK) { state = 0; } @@ -262,7 +262,7 @@ defcode("interp", interp, &zbr, 0u) { if (onward_aspop()) { /* If we're compiling, then append the number to the word */ if (state == 1) { - onward_aspush(&lit); + onward_aspush((intptr_t)&lit); comma_code(); comma_code(); } diff --git a/source/onward/onward.h b/source/onward/onward.h index a08c151..a1dd754 100755 --- a/source/onward/onward.h +++ b/source/onward/onward.h @@ -120,6 +120,9 @@ typedef struct { /** Macro to get use the word pointer in a defined word */ #define W(name) ((value_t)&name) +/** Macro that expands to the address of the latest built-in word */ +#define LATEST_BUILTIN (&bnot) + void onward_init(onward_init_t* init_data); value_t onward_pcfetch(void); void onward_aspush(value_t val);