]> git.mdlowis.com Git - projs/onward.git/commitdiff
Added an implementation specific dumpw word for decompiling defined words
authorMichael D. Lowis <mike@mdlowis.com>
Sat, 22 Nov 2014 18:24:29 +0000 (13:24 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Sat, 22 Nov 2014 18:24:29 +0000 (13:24 -0500)
source/main.c
source/onward/onward.c
source/onward/onward.h

index 8e66262016573256441e910e476a71096c91a65a..14565f77eb494bf1ce16f4541965652e89fc572e 100755 (executable)
@@ -1,14 +1,31 @@
 #include "onward.h"
 #include <stdio.h>
 
-
 #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);
 
index 992e058c7b6687f8b6cdd9eeddbf677aaf332eff..13f192d8da64caf720dec6ebb25deaeeeb8e44a0 100755 (executable)
@@ -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();
             }
index a08c151b164923aab5c33100b99150d21739e206..a1dd75499d5d25412ddaba91243bd414ef58f341 100755 (executable)
@@ -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);