#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;
STACK_SZ,
Ram_Data_Buf,
8192/sizeof(value_t),
- (word_t*)&bnot
+ (word_t*)&dumpw
};
onward_init(&init_data);
/** 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 */
}
/** Set the interpreter mode to "interpret" */
-defcode("[", lbrack, &comma, 0u) {
+defcode("[", lbrack, &comma, F_IMMEDIATE_MSK) {
state = 0;
}
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();
}
/** 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);