Skip to content

Implementation Decisions

Russell Blickhan edited this page Jul 14, 2018 · 4 revisions

VM

  • For comparison operators, we will only use equality, non-equality (to handle NaN appropriately), greater, and greater-equal. Lesser and lesser-equal will be implemented by flipping.

Function Calling Convention

  • On call:
    • Caller pushes parameters in backwards order, then function object.
    • Caller uses CALL instruction.
      • Push the frame pointer.
      • Push the program counter.
      • Set the new frame pointer to be at the stack pointer.
  • On return:
    • Callee uses RET instruction.
      • RET assumes the return value is on top of the stack.
      • Read the return value and store temporarily.
      • Set stack pointer to frame pointer.
      • Reset program counter.
      • Reset frame pointer.
      • Pop function object.
      • Pop parameters.
      • Push return value to the top of the stack.

Bytecode File Format

  • Metadata:
    • Magic number (consider versioning?)
    • Maximum number of global values
    • Execution start index
    • Length (?)
  • Static data:
    • Strings
    • Function definition:
      • Name
      • Number of parameters
      • Body bytecode
  • Instructions
Clone this wiki locally