bonobo-lang / bonobo

Strongly-typed, safe, opinionated systems language that compiles to C.
https://bonobo-lang.github.io
Apache License 2.0
14 stars 1 forks source link

BVM - One number type to rule them all. #86

Open thosakwe opened 6 years ago

thosakwe commented 6 years ago

The BVM should handle all numbers through a common abstraction: Bonobo_Number. This will mean that there won't need to be a million number-handling instructions; rather, the VM will perform operations differently depending on a number's type.

However, in the Bonobo language, this abstraction does not exist in the same way. The Bonobo language defines: Int and Float.

I believe it's best that users don't have to worry about the precision of numbers. In actual Bonobo code, the precision will not matter.

The only complication will be how to handle FFI. That is a problem to worry about in the future, not now.

typedef enum {
  int8,
  int16,
  int32,
  int64,
  uint8,
  uint16,
  uint32,
  uint64,
  float32,
  float64
} Bonobo_NumberType;

typedef struct {
  Bonobo_NumberType type;
  union {
    int8_t asInt8;
    int16_t asInt16;
    // etc.
  };
} Bonobo_Number;
thosakwe commented 6 years ago

The accompanying instructions would be simple:

INT

FLOAT