Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
thosakwe opened this issue May 31, 2018 · 1 comment
Open

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

thosakwe opened this issue May 31, 2018 · 1 comment

Comments

@thosakwe
Copy link
Contributor

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
Copy link
Contributor Author

The accompanying instructions would be simple:

INT

  • Op1: Size in bytes (1, 2, 4, or 8)
  • Op2: A 16-bit offset corresponding to where the constant is in the program data.

FLOAT

  • Op1: Size in bytes (4 or 8)
  • Op2: A 16-bit offset corresponding to where the constant is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant