A bytecode compiler and a virtual machine for a subset of Go, written in Rust
// an example of a fully compiling program
package main
var (
x uint8 = 255
vec = []int{45, 23, -7, int(x), 0, -102}
)
func main() {
insertionSort(vec) // [-102 -7 0 23 45 255]
println("Vector is sorted.")
}
func insertionSort(vec []int) {
for i, n := 1, len(vec); i < n; i++ {
j := i
for j > 0 {
if vec[j-1] > vec[j] {
vec[j], vec[j-1] = vec[j-1], vec[j]
}
j--
}
}
}
- primitive types and type conversions
- comparison, math, logic, bitwise operations
- variables and constants
- global and scoped
- group declarations
- multiple declarations and assignments
- control flow
-
if
statements -
for
statements (withbreaks
andcontinue
) -
switch
statements (withfallthrough
)
-
- functions
- recursive functions
- variadic functions
- multiple return values
- partial support of
builtin.go
- arrays
- slices (partially)
- closures
-
range
andfor range
loops