Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ziflex committed Oct 23, 2024
1 parent 39dccbc commit cd3d36e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
3 changes: 2 additions & 1 deletion pkg/runtime/frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ type Frame struct {
Operands *Stack
Variables *Stack
State *Stack
ReturnPC int
Parent *Frame
PC int
}

func NewFrame(size int) *Frame {
Expand Down
16 changes: 9 additions & 7 deletions pkg/runtime/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import (
)

type VM struct {
pc int
frames []*Frame
globals map[string]core.Value
env *Environment
env *Environment
globals map[string]core.Value
frames []*Frame
currentFrame *Frame
pc int
}

func NewVM(opts ...EnvironmentOption) *VM {
Expand All @@ -36,15 +37,16 @@ func (vm *VM) Run(ctx context.Context, program *Program) ([]byte, error) {

// TODO: Add code analysis to calculate the number of operands and variables
frame := NewFrame(32)
vm.currentFrame = frame
vm.frames = []*Frame{frame}
vm.globals = make(map[string]core.Value)
vm.pc = 0

loop:
for vm.pc < len(program.Bytecode) {
stack := frame.Operands
variables := frame.Variables
state := frame.State
stack := vm.currentFrame.Operands
variables := vm.currentFrame.Variables
state := vm.currentFrame.State
op := program.Bytecode[vm.pc]
arg := program.Arguments[vm.pc]
vm.pc++
Expand Down

0 comments on commit cd3d36e

Please sign in to comment.