Implemented a union type to make vm_push_* routines uniform
Function dispatch
This commit is contained in:
16
src/main.c
16
src/main.c
@@ -35,20 +35,26 @@ typedef struct
|
|||||||
} stack;
|
} stack;
|
||||||
} vm_t;
|
} vm_t;
|
||||||
|
|
||||||
void vm_push_byte(vm_t *vm, byte b)
|
typedef union
|
||||||
|
{
|
||||||
|
byte as_byte;
|
||||||
|
word as_word;
|
||||||
|
} data_t;
|
||||||
|
|
||||||
|
void vm_push_byte(vm_t *vm, data_t b)
|
||||||
{
|
{
|
||||||
if (vm->stack.pointer >= VM_STACK_MAX)
|
if (vm->stack.pointer >= VM_STACK_MAX)
|
||||||
return;
|
return;
|
||||||
vm->stack.data[vm->stack.pointer++] = b;
|
vm->stack.data[vm->stack.pointer++] = b.as_byte;
|
||||||
}
|
}
|
||||||
|
|
||||||
void vm_push_word(vm_t *vm, word w)
|
void vm_push_word(vm_t *vm, data_t w)
|
||||||
{
|
{
|
||||||
// NOTE: Relies on sizeof measuring in bytes
|
// NOTE: Relies on sizeof measuring in bytes
|
||||||
if (vm->stack.pointer + sizeof(w) >= VM_STACK_MAX)
|
if (vm->stack.pointer + sizeof(w) >= VM_STACK_MAX)
|
||||||
return;
|
return;
|
||||||
memcpy(vm->stack.data + vm->stack.pointer, &w, sizeof(w));
|
memcpy(vm->stack.data + vm->stack.pointer, &w.as_word, sizeof(w.as_word));
|
||||||
vm->stack.pointer += sizeof(w);
|
vm->stack.pointer += sizeof(w.as_word);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
|
|||||||
Reference in New Issue
Block a user