}
defcode("wsize", wflags, 0, &wlink){
- *(ArgStackPtr) = (val_t)(((word_t*)*(ArgStackPtr))->flags.codesize);
+ *(ArgStackPtr) = (val_t)(((word_t*)*(ArgStackPtr))->flags.attr.codesize);
}
defcode("wname", wname, 0, &wflags){
defcode("here", here, 0, &wcode){
ArgStackPtr++;
- *(ArgStackPtr) = (val_t)((((word_t*)latest_val)->flags.codesize) - 1);
+ *(ArgStackPtr) = (val_t)((((word_t*)latest_val)->flags.attr.codesize) - 1);
}
/* Input/Output Words
char* name = (char*)*(ArgStackPtr);
while(curr)
{
- if (!(curr->flags.f_hidden) && (0 == strcmp(curr->name,name)))
+ if (!(curr->flags.attr.hidden) && (0 == strcmp(curr->name,name)))
{
break;
}
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 = 1;
+ word->flags.attr.immed = 0;
+ word->flags.attr.hidden = 1;
+ word->flags.attr.codesize = 1;
/* Initialize the name, codeword, and bytecode */
word->name = name;
word->codeword = &docolon;
word_t* word = (word_t*)latest_val;
/* Put the next instruction in place of the terminating 'ret' that "here"
* points too */
- word->code[word->flags.codesize-1] = *(ArgStackPtr);
+ word->code[word->flags.attr.codesize-1] = *(ArgStackPtr);
ArgStackPtr--;
/* Resize the code section and relocate if necessary */
- word->flags.codesize++;
- word->code = (val_t*)realloc(word->code, word->flags.codesize * sizeof(val_t));
+ word->flags.attr.codesize++;
+ word->code = (val_t*)realloc(word->code, word->flags.attr.codesize * sizeof(val_t));
/* Update "here" and terminate the code section */
- word->code[word->flags.codesize-1] = (val_t)&ret;
+ word->code[word->flags.attr.codesize-1] = (val_t)&ret;
}
defcode("hidden", hidden, 1, &comma){
- ((word_t*)*(ArgStackPtr))->flags.f_hidden ^= 1;
+ ((word_t*)*(ArgStackPtr))->flags.attr.hidden ^= 1;
}
defcode("immediate", immediate, 1, &hidden){
- ((word_t*)*(ArgStackPtr))->flags.f_immed ^= 1;
+ ((word_t*)*(ArgStackPtr))->flags.attr.immed ^= 1;
}
defcode(":", colon, 0, &immediate){
if (*ArgStackPtr)
{
/* If we are in immediate mode or the found word is marked immediate */
- if((state_val == 0) || (((word_t*)*ArgStackPtr)->flags.f_immed))
+ if((state_val == 0) || (((word_t*)*ArgStackPtr)->flags.attr.immed))
{
/* Execute the word */
EXEC(exec_word);
{
printf("%s\t%ld %ld",
word->name,
- word->flags.f_immed,
- word->flags.f_hidden);
+ word->flags.attr.immed,
+ word->flags.attr.hidden);
word = word->link;
}
}
*/
typedef void (*codeword_t)(val_t* code);
+/** A collection of flags describing attributes of the word. */
+typedef union {
+ /** The value of all flag bits combined */
+ val_t value;
+ /** Accessors for individual flag fields */
+ struct {
+ /** Flag if this word should be hidden from the interpreter */
+ val_t hidden : 1;
+ /** flag if this word should be executed at compile time */
+ val_t immed : 1;
+ /** Pads the flags to 8-bits */
+ val_t padding : 6;
+ /** The length of the bytecode section of the word */
+ val_t codesize : CODE_SZ_BITS;
+ } attr;
+} flags_t;
+
/**
This structure contains all of the relevant attributes of a word definition
*/
/** Pointer to the next most recently defined word in the dictionary. */
struct word_t const* link;
/** A collection of flags describing attributes of the word. */
- struct {
- val_t f_hidden : 1; /*< Flag if this word should be hidden from the interpreter */
- val_t f_immed : 1; /*< flag if this word should be executed at compile time */
- val_t padding : 6; /*< Pads the flags to 8-bits */
- val_t codesize : CODE_SZ_BITS; /*< The length of the bytecode section of the word */
- } flags;
+ //struct {
+ // val_t f_hidden : 1; /*< Flag if this word should be hidden from the interpreter */
+ // val_t f_immed : 1; /*< flag if this word should be executed at compile time */
+ // val_t padding : 6; /*< Pads the flags to 8-bits */
+ // val_t codesize : CODE_SZ_BITS; /*< The length of the bytecode section of the word */
+ //} flags;
+ flags_t flags;
/** Pointer to the null terminated string that holds the name of the word. */
char const* name;
/**
/**
* Define a built-in word that executes native code */
-#define defcode(name_str,c_name,immed,prev) \
+#define defcode(name_str,c_name,immed,prev) \
static void c_name##_code(val_t* code); \
- static word_t const c_name = { \
- prev, \
- { 0, immed, 0, 0 }, \
- name_str, \
- &c_name##_code, \
- 0 \
- }; \
+ static word_t const c_name = { \
+ prev, \
+ {.attr = { 0, immed, 0, 0 }}, \
+ name_str, \
+ &c_name##_code, \
+ 0 \
+ }; \
static void c_name##_code(val_t* inst_ptr) \
/**