mirror of
https://github.com/vsariola/sointu.git
synced 2025-07-18 21:14:31 -04:00
feat(sointu, vm): implement pure-Go interpreter for bytecode
The old "native" compiler bridged version is now started with cmd/sointu-nativetrack, while the new pure-Go bytecode implemented bytecode interpreter is started with cmd/sointu-track Thus, you do not need any of the CMake / cgo stuff to run cmd/sointu-track
This commit is contained in:
47
vm/generate/generate.go
Normal file
47
vm/generate/generate.go
Normal file
@ -0,0 +1,47 @@
|
||||
// +build ignore
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/vsariola/sointu/vm"
|
||||
)
|
||||
|
||||
func check(e error) {
|
||||
if e != nil {
|
||||
panic(e)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
outputFile, err := os.Create("opcodes.go")
|
||||
check(err)
|
||||
defer outputFile.Close()
|
||||
fmt.Fprintln(outputFile, "// Code generated by go generate; DO NOT EDIT.")
|
||||
fmt.Fprintln(outputFile, "package vm")
|
||||
fmt.Fprintln(outputFile, "")
|
||||
fmt.Fprintln(outputFile, "const (")
|
||||
features := vm.AllFeatures{}
|
||||
max := 0
|
||||
for _, instr := range features.Instructions() {
|
||||
if l := len(instr); max < l {
|
||||
max = l
|
||||
}
|
||||
}
|
||||
for i, instr := range features.Instructions() {
|
||||
format := fmt.Sprintf("\top%%-%vv = %%v\n", max)
|
||||
fmt.Fprintf(outputFile, format, strings.Title(instr), i+1)
|
||||
}
|
||||
fmt.Fprintln(outputFile, ")")
|
||||
fmt.Fprintln(outputFile, "")
|
||||
fmt.Fprintf(outputFile, "var transformCounts = [...]int{")
|
||||
for i, instr := range features.Instructions() {
|
||||
if i > 0 {
|
||||
fmt.Fprintf(outputFile, ", ")
|
||||
}
|
||||
fmt.Fprintf(outputFile, "%v", features.TransformCount(instr))
|
||||
}
|
||||
fmt.Fprintln(outputFile, "}")
|
||||
}
|
Reference in New Issue
Block a user