imaqtkatt / grape

An experimental virtual machine
5 stars 0 forks source link

Support OOP/Classes #5

Closed imaqtkatt closed 5 months ago

imaqtkatt commented 6 months ago

Modules should support 0 or many class definitions and each class should be unique at the Runtime context.

struct Module {
  ...
  pub classes:   BTreeMap<Rc<str>, Class { name, fields, methods }>,
  pub functions: BTreeMap<Rc<str>, Function>,
  ...
}

- Each class must have a unique new/initializer method.

Should all classes come before the functions? Or it's better to have a CLASS/STRUCT/FUNCTION tag before reading it?

A class can be stored as a Box<[Value]> at the heap where every field will have an offset/identifier, this can be done by a compiler or as a VM transformation.

Both fields and methods in a class can be private or public. I believe this also implies on adding accessors for module functions.