@@ -88,29 +88,12 @@ enum l2_opcode { | |||
L2_OP_RET, | |||
/* | |||
* Allocate an integer from one word. | |||
* Allocate an atom from one word. | |||
* Pop <word> | |||
* Alloc integer <var> from <word> | |||
* Push <var> | |||
*/ | |||
L2_OP_ALLOC_INTEGER_32, | |||
/* | |||
* Allocate an integer from two words. | |||
* Pop <word1> | |||
* Pop <word2> | |||
* Alloc integer <var> from <word1> << 32 | <word2> | |||
* Push <var> | |||
*/ | |||
L2_OP_ALLOC_INTEGER_64, | |||
/* | |||
* Allocate a real from one word. | |||
* Pop <word> | |||
* Alloc real <var> from <word> | |||
* Push <var> | |||
*/ | |||
L2_OP_ALLOC_REAL_32, | |||
L2_OP_ALLOC_ATOM, | |||
/* | |||
* Allocate a real from two words. | |||
@@ -119,7 +102,7 @@ enum l2_opcode { | |||
* Alloc real <var> from <high> << 32 | <low> | |||
* Push <var> | |||
*/ | |||
L2_OP_ALLOC_REAL_64, | |||
L2_OP_ALLOC_REAL, | |||
/* | |||
* Allocate a buffer from static data. |
@@ -12,7 +12,7 @@ typedef l2_word (*l2_vm_cfunction)(struct l2_vm *vm, struct l2_vm_array *args); | |||
enum l2_value_type { | |||
L2_VAL_TYPE_NONE, | |||
L2_VAL_TYPE_INTEGER, | |||
L2_VAL_TYPE_ATOM, | |||
L2_VAL_TYPE_REAL, | |||
L2_VAL_TYPE_BUFFER, | |||
L2_VAL_TYPE_ARRAY, | |||
@@ -41,7 +41,7 @@ struct l2_vm_value { | |||
// Byte 8: 8 bytes | |||
union { | |||
int64_t integer; | |||
l2_word atom; | |||
double real; | |||
struct l2_vm_buffer *buffer; | |||
struct l2_vm_array *array; |
@@ -67,14 +67,14 @@ void l2_gen_number(struct l2_generator *gen, double num) { | |||
put(gen, L2_OP_PUSH_2); | |||
put(gen, n); | |||
put(gen, n >> 32); | |||
put(gen, L2_OP_ALLOC_REAL_64); | |||
put(gen, L2_OP_ALLOC_REAL); | |||
} | |||
void l2_gen_atom(struct l2_generator *gen, char **str) { | |||
size_t id = l2_strset_put(&gen->atomset, str); | |||
put(gen, L2_OP_PUSH); | |||
put(gen, id); | |||
put(gen, L2_OP_ALLOC_INTEGER_32); | |||
put(gen, L2_OP_ALLOC_ATOM); | |||
} | |||
void l2_gen_string(struct l2_generator *gen, char **str) { |
@@ -8,8 +8,8 @@ static void print_val(struct l2_vm *vm, struct l2_vm_value *val) { | |||
printf("(none)"); | |||
break; | |||
case L2_VAL_TYPE_INTEGER: | |||
printf("%zi", val->integer); | |||
case L2_VAL_TYPE_ATOM: | |||
printf("(atom %u)", val->atom); | |||
break; | |||
case L2_VAL_TYPE_REAL: |
@@ -10,8 +10,8 @@ void l2_vm_print_val(struct l2_vm_value *val) { | |||
printf("NONE\n"); | |||
break; | |||
case L2_VAL_TYPE_INTEGER: | |||
printf("INTEGER %zi\n", val->integer); | |||
case L2_VAL_TYPE_ATOM: | |||
printf("ATOM %u\n", val->atom); | |||
break; | |||
case L2_VAL_TYPE_REAL: | |||
@@ -165,20 +165,12 @@ void l2_vm_print_op(l2_word *ops, size_t opcount, size_t *ptr) { | |||
printf("RET\n"); | |||
break; | |||
case L2_OP_ALLOC_INTEGER_32: | |||
printf("ALLOC_INTEGER_32\n"); | |||
case L2_OP_ALLOC_ATOM: | |||
printf("ALLOC_ATOM\n"); | |||
break; | |||
case L2_OP_ALLOC_INTEGER_64: | |||
printf("ALLOC_INTEGER_64\n"); | |||
break; | |||
case L2_OP_ALLOC_REAL_32: | |||
printf("ALLOC_REAL_32\n"); | |||
break; | |||
case L2_OP_ALLOC_REAL_64: | |||
printf("ALLOC_REAL_64\n"); | |||
case L2_OP_ALLOC_REAL: | |||
printf("ALLOC_REAL\n"); | |||
break; | |||
case L2_OP_ALLOC_BUFFER_STATIC: |
@@ -317,33 +317,14 @@ void l2_vm_step(struct l2_vm *vm) { | |||
} | |||
break; | |||
case L2_OP_ALLOC_INTEGER_32: | |||
case L2_OP_ALLOC_ATOM: | |||
word = alloc_val(vm); | |||
vm->values[word].flags = L2_VAL_TYPE_INTEGER; | |||
vm->values[word].integer = vm->stack[--vm->sptr]; | |||
vm->values[word].flags = L2_VAL_TYPE_ATOM; | |||
vm->values[word].atom= vm->stack[--vm->sptr]; | |||
vm->stack[vm->sptr++] = word; | |||
break; | |||
case L2_OP_ALLOC_INTEGER_64: | |||
word = alloc_val(vm); | |||
vm->values[word].flags = L2_VAL_TYPE_INTEGER; | |||
vm->values[word].integer = (int64_t)( | |||
(uint64_t)vm->stack[vm->sptr - 1] << 32 | | |||
(uint64_t)vm->stack[vm->sptr - 2]); | |||
vm->sptr -= 2; | |||
vm->stack[vm->sptr] = word; | |||
vm->sptr += 1; | |||
break; | |||
case L2_OP_ALLOC_REAL_32: | |||
word = alloc_val(vm); | |||
vm->values[word].flags = L2_VAL_TYPE_REAL; | |||
vm->values[word].real = u32_to_float(vm->stack[--vm->sptr]); | |||
vm->stack[vm->sptr] = word; | |||
vm->sptr += 1; | |||
break; | |||
case L2_OP_ALLOC_REAL_64: | |||
case L2_OP_ALLOC_REAL: | |||
word = alloc_val(vm); | |||
vm->values[word].flags = L2_VAL_TYPE_REAL; | |||
vm->values[word].real = u32s_to_double(vm->stack[vm->sptr - 1], vm->stack[vm->sptr - 2]); |