tuqqu / cogo

Golang Bytecode Compiler & Virtual Machine

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cogo

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--
        }
    }
}

Implemented Features

  • 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 (with breaks and continue)
    • switch statements (with fallthrough)
  • functions
    • recursive functions
    • variadic functions
    • multiple return values
  • partial support of builtin.go
  • arrays
  • slices (partially)
  • closures
  • range and for range loops

About

Golang Bytecode Compiler & Virtual Machine

License:MIT License


Languages

Language:Rust 100.0%