defcode("lit", literal, 0, 0, &find_word){
ArgStackPtr++;
*(ArgStackPtr) = *CodePtr;
+ CodePtr++;
}
defcode("br", branch, 0, 0, &literal){
- CodePtr++;
CodePtr += *(CodePtr);
+ CodePtr++;
}
defcode("0br", zbranch, 0, 0, &branch){
if (!(*ArgStackPtr))
{
- CodePtr++;
CodePtr += *(CodePtr);
+ CodePtr++;
}
}
/* Create the word entry */
word_t* word = (word_t*)malloc(sizeof(word_t));
word->link = (word_t*)latest_val;
+ /* Initialize the flags (hidden and non-immediate by default) */
word->flags.f_immed = 0;
word->flags.f_hidden = 1;
word->flags.codesize = 0;
+ /* Initialize the name, codeword, and bytecode */
word->name = name;
word->codeword = &docolon;
word->code = (long*)malloc(sizeof(long));
defcode(",", comma, 0, 0, &create){
/* Get the word we are currently compiling */
word_t* word = (word_t*)latest_val;
- /* Put the next instruction in place of the terminating NULL that "here"
+ /* Put the next instruction in place of the terminating 'ret' that "here"
* points too */
*((long*)here_val) = *(ArgStackPtr);
ArgStackPtr--;
/* Resize the code section and relocate if necessary */
long currsize = sizeof(long) + (here_val - (long)word->code);
word->code = (long*)realloc(word->code, currsize + sizeof(long));
- /* Update "here" and null terminate the code section */
- here_val = (long)&(word->code[ (currsize / sizeof(long)) ]);
+ /* Update "here" and terminate the code section */
+ here_val = (long)(((long*)here_val) + 1);
*((long*)here_val) = (long)&ret;
}
{
puts("CodeFn: docolon");
puts("Bytecode:");
- while(*bytecode)
+ while(bytecode)
{
- printf("\t%s\n", ((word_t*) *bytecode)->name);
- bytecode++;
+ if (*bytecode == (long)&literal)
+ {
+ bytecode++;
+ printf("\tlit %lu\n", *bytecode);
+ }
+ else
+ {
+ printf("\t%s\n", ((word_t*) *bytecode)->name);
+ }
+
+ if (*bytecode == (long)&ret)
+ {
+ bytecode = 0;
+ break;
+ }
+ else
+ {
+ bytecode++;
+ }
}
- printf("\tret\n");
}
else
{