Feature: Compile to a custom bytecode VM #17

Open
opened 2024-07-31 08:57:21 +00:00 by j · 0 comments
Owner

Feature Progress

  • Define a minimal instruction set
  • Progressively lower Conlang code into that instruction set, emulating features where necessary
  • Decide on calling convention (Lua's calling convention looks nice!)
  • Decide how to layout data structures
  • LValue and RValue expressions?
  • References/pointers?
    • Reading
    • Writing
  • Implement struct/tuple field accesses
    • Reading
    • Writing
  • Implement array indexing
    • Reading
    • Writing
  • Implement closures
    • Upvar analysis (What names are being captured?)
    • Capture variables (By value?)
    • Do closures get automatically heap allocated?
      • NO! PLEASE NO!

Feature description

Currently, the AST interpreter has to follow dozens of pointer indirections just to execute a single operation. Having a language VM will allow Conlang to run considerably faster, assuming the eventual implementation doesn't thrash the heap or cache too badly.

Might be fun to model the VM off a real RISC architecture.

Example

fn returns_10 () {
    10
}
returns_10:
   mov     r15, $10
   ret
# Feature Progress <!-- Describe the steps for implementing this feature --> - [ ] Define a minimal instruction set - [ ] Progressively lower Conlang code into that instruction set, emulating features where necessary - [ ] Decide on calling convention (Lua's calling convention looks nice!) - [ ] Decide how to layout data structures - [ ] LValue and RValue expressions? - [ ] References/pointers? - [ ] Reading - [ ] Writing - [ ] Implement struct/tuple field accesses - [ ] Reading - [ ] Writing - [ ] Implement array indexing - [ ] Reading - [ ] Writing - [ ] Implement closures - [ ] Upvar analysis (What names are being captured?) - [ ] Capture variables (By value?) - [x] Do closures get automatically heap allocated? - [x] NO! PLEASE NO! # Feature description <!-- [Feature name] does a cool thing that you should describe here --> Currently, the AST interpreter has to follow dozens of pointer indirections just to execute a single operation. Having a language VM will allow Conlang to run considerably faster, assuming the eventual implementation doesn't thrash the heap or cache too badly. Might be fun to model the VM off a real RISC architecture. # Example <!-- Demonstrate this feature with a clear, concise code example Right now, we're (ab)using Rust syntax highlighting, since it most closely matches what I'm currently aiming for --> ```rust fn returns_10 () { 10 } ``` ```asm returns_10: mov r15, $10 ret ```
j added the
enhancement
label 2024-07-31 08:57:21 +00:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: j/Conlang#17
No description provided.