Skip to content

Commit

Permalink
refactor: merge analyzer to compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
siyul-park committed Feb 17, 2025
1 parent 34c2a11 commit 9ce5aa4
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 425 deletions.
16 changes: 8 additions & 8 deletions internal/bytecode/bytecode.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,7 @@ func (b *Bytecode) Emit(instructions ...Instruction) int {
return offset
}

func (b *Bytecode) Store(constants []byte) int {
offset := len(b.Constants)
b.Constants = append(b.Constants, constants...)
return offset
}

func (b *Bytecode) Instruction(offset int) (Instruction, int) {
func (b *Bytecode) Fetch(offset int) (Instruction, int) {
if offset >= len(b.Instructions) {
return nil, 0
}
Expand All @@ -37,6 +31,12 @@ func (b *Bytecode) Instruction(offset int) (Instruction, int) {
return b.Instructions[offset : offset+width], width
}

func (b *Bytecode) Store(constants []byte) int {
offset := len(b.Constants)
b.Constants = append(b.Constants, constants...)
return offset
}

func (b *Bytecode) String() string {
var out strings.Builder

Expand All @@ -46,7 +46,7 @@ func (b *Bytecode) String() string {

offset := 0
for offset < len(b.Instructions) {
bytecode, read := b.Instruction(offset)
bytecode, read := b.Fetch(offset)
if read == 0 {
break
}
Expand Down
161 changes: 0 additions & 161 deletions internal/compiler/analyzer.go

This file was deleted.

185 changes: 0 additions & 185 deletions internal/compiler/analyzer_test.go

This file was deleted.

Loading

0 comments on commit 9ce5aa4

Please sign in to comment.