lausek/lovm2

Redesign code layout

lausek opened this issue · 2 comments

Current

The current Module looks like this:

  • CodeObject main
    • globals
    • locals
    • consts
    • code
  • CodeObject add
    • globals
    • locals
    • consts
    • code
  • ...

New Layout

  • idents: globals + locals
  • consts
  • entries: HashMap<Variable, usize> mapping the function name to the offset inside code
  • code which is the concatenated list of bytecode instructions from main and add
main:
    ...
    ret
add:
    ...
    ret

Pros

  • Size of Module is expected to decrease by a lot
    • CodeObject can reuse identifiers and constants
  • The new layout is way simpler than the previous one

Steps for redesign

  • remove current struct Module
  • redefine CodeObject according to new layout
    • wait until #6 is resolved
    • refactor ModuleProtocol trait -> remove slot method
    • implement ModuleProtocol
  • create new type CodeObjectFunction wip name
    • tuple containing a reference to the CodeObject and an offset
    • implement CallProtocol

If we define the ENTRY_POINT to be always at offset 0, resolution of a programs starting point will become way simpler. Modules without an entry point will have a ret as first instruction.

implemented by #7