Skip to content

[specification] Make static function table for classes #203

@mrodz

Description

@mrodz
  • Create a class_register pipe instruction that does not modify the stack but copies the class' function layout to a shared (Gc<GcCell>) vtable mapped to a unique integer id before memory contents are initialized with the constructor.
  • Create a class_alloc instruction. If the class memory/function layout is known, it preallocates the known size of member variables and returns an uninitialized class, then jumps {N} instructions. Otherwise, fall through to build the class vtable at runtime like normal and store it with a class_register.
  • Change the memory layout of classes: one Gc<GcCell> to include instance variables and another Gc<VTABLE> for functions

Example

function Dog
    arg 0
    store_fast constructor_arg0
    store_fast constructor_arg{N}
    class_alloc 12345 {N}
    make_function Dog::bark a b c
    make_function Dog::...
    class_register 12345
    done
...
    load_fast constructor_arg0
...
    call path/to/file.mmm#Dog::constructor
    ret
end

Metadata

Metadata

Assignees

Labels

bytecodeIssues related to bytecodecompilerIssues related to compilation & parsingenhancementNew feature or requestinstructionBytecode instruction

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions