Browse Source

change up some types

master
Martin Dørum 3 years ago
parent
commit
5d8bcf692e
6 changed files with 19 additions and 63 deletions
  1. 3
    20
      include/lang2/bytecode.h
  2. 2
    2
      include/lang2/vm/vm.h
  3. 2
    2
      lib/gen/gen.c
  4. 2
    2
      lib/vm/builtins.c
  5. 6
    14
      lib/vm/print.c
  6. 4
    23
      lib/vm/vm.c

+ 3
- 20
include/lang2/bytecode.h View File

@@ -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.

+ 2
- 2
include/lang2/vm/vm.h View File

@@ -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;

+ 2
- 2
lib/gen/gen.c View File

@@ -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) {

+ 2
- 2
lib/vm/builtins.c View File

@@ -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:

+ 6
- 14
lib/vm/print.c View File

@@ -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:

+ 4
- 23
lib/vm/vm.c View File

@@ -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]);

Loading…
Cancel
Save