Go specs implemented as a scripting language in Rust.

Goscript

A script language like Python or Lua written in Rust, with exactly the same syntax as Go's.

The Goal

  • Runs most pure Go code, probably add some dynamic features if requested.

How do I try

The project "engine" is the entry/wrapper. there are test cases in here to browse through.

  • Make sure your Rust installation is up to date.
  • Clone this repository.
  • Go to goscript/engine
  • Run cargo test -- --nocapture

Use Cases

  • As an embedded language like Lua.
  • As a glue language like Python.

Rationale

  • A scripting language that can be embedded in Rust.
  • Go is popular and easy(even as a scripting language), why invent new grammars?
  • In some cases, when your project gets big:
    • If Go were an embedded language it would be better than Lua.
    • If Go were a glue language it would be better than Python, in terms of project maintainability.
  • I found a new hammer(Rust) that I like, and decided to use it on a nail(Go) that I like.

Implementation

  • There are five projects:
    • parser -- a port of the official implementation that comes with the Go installer.
    • type checker -- a port of the official implementation that comes with the Go installer.
    • codegen -- generates the bytecode.
    • vm -- runs the bytecode.
    • engine -- the wrapper.

Progress

  • Language: Feature complete (except the features that are so insignificant that I forgot -_-) Some of the features are, probably for the first time, implemented in a script language, like Select/Defer/Pointer/Interface/Struct.
  • Standard library: just got started.
  • Production readiness: far from. The parser and the type checker are probably ok because they were ported and passes the test cases comes with the original code. The backend has a lot of rough edges, and we need much more test cases.
  • Next step: no new features for now, polish then work on the standard library.

Get in touch

Comments
  • Infinite loop with certain input

    Infinite loop with certain input

    This section of the code loops infinitely with input `.

    #[test]
    fn test() {
        let mut fs = fe::FileSet::new();
        let o = &mut fe::objects::Objects::new();
        let el = &mut fe::errors::ErrorList::new();
        parse_file(o, &mut fs, el, "/a", "`", false);
    }
    
  • Functions with variadic arguments don't work when called with zero params

    Functions with variadic arguments don't work when called with zero params

    Sample:

    package main
    
    func broken(elems ...int) {}
    
    func main() {
      broken()
    }
    
    thread 'test_std_temp' panicked at 'index out of bounds: the len is 0 but the index is 0', codegen/src/codegen.rs:965:32
    

    This is a pretty amazing project, thanks for putting it out there :)

  • Dot import does not work

    Dot import does not work

    The Dot import syntax brings the entire package into the current namespace. So, you don’t have to call the functions using the package name. You can directly call them.

    Reproduction code

    package main
    
    import (
      . "fmt2"
    )
    
    func main() {
      Println("Hello, World!")
    }
    

    Expected Results

    That it would print out "Hello, World!"

    Actual Results

    thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', ...goscript/codegen/src/package.rs:47:60
    
  • member resolution fails with embedded structs

    member resolution fails with embedded structs

    Hello! Wonderful project. I was playing around with embedded structs as they're a golang feature I quite like, and I found that fields and methods aren't promoted in goscript like they are in golang proper:

    package main
    
    import (
    	"fmt"
    )
    
    type Base struct {
    	name string
    }
    func (b Base) PrintField() {
    	fmt.Println(b.name)
    }
    
    type Container struct {
    	Base
    }
    
    func main() {
    	t := Container{Base{"go"}}
            //t.PrintField() //error in goscript, but works in golang
    	t.Base.PrintField() //have to use this instead
    }
    

    I'm not sure if this is an issue with the go specs, or simply this implementation. I'm not even sure if implementing field promotion is on the table. But I felt it was worth bringing up anyway. The error specifically when trying to run this script is: thread 'main' panicked at 'no entry found for key', ...\vm\src\metadata.rs:493:9 so it seems to be an error with field name resolution.

  • some refactoring and reformatting

    some refactoring and reformatting

    the only change of functionality is in the function shorten_with_ellipsis. I also hope I fixed the issue with array into_iter()... (I didn't test it, there may be some errors in it...)

  • Octal integer improvements

    Octal integer improvements

    This PR aims to fix two problems with octal integers:

    1. It fixes the radix notation for integer conversion.
    2. It adds support for "bare" octal notation, e.g. 01, 023 etc. Currently those numbers are treated as if they were decimals (1, 23), whilst their decimal value is different (1, 27).

    Also now integers such as 09 etc. throw lexer error, instead of being converted to decimals, as they should.

  • Remove `smol` and replace it by its dependencies

    Remove `smol` and replace it by its dependencies

    smol brings in a lot of IO related dependencies that are not used by goscript. They are also quite problematic when compiling to WebAssembly. Fortunately since they are not used, we can just remove them and also get faster compile times and a smaller dependency tree out of it.

  • add fuzz target

    add fuzz target

    I found that running a fuzz test on the parser uncovers some bugs. After installing cargo-fuzz, the target can be run with cargo +nightly fuzz run parse_file.

  • Don't call canonicalize when building for wasm32-wasi

    Don't call canonicalize when building for wasm32-wasi

    After building for the wasm32-wasi target, running the engine failed and I narrowed it down to calls to canonicalize() and printing the errors give the following message:

    Error { kind: Unsupported, message: "operation not supported on this platform" }
    

    It appears that wasi doesn't support canonicalize.

    The changes I made simply skip invoking canonicalize() if the build target is wasm-wasi, and I don't think it's too much to just require that wasm users of the library provide an absolute path if they wish to run goscripts.

CodePlayground is a playground tool for go and rust language.

CodePlayground CodePlayground is a playground tool for go and rust language. Installation Use homebrews to install code-playground. brew tap trendyol/

Mar 5, 2022
Go implementation of the Rust `dbg` macro

godbg ?? godbg is an implementation of the Rust2018 builtin debugging macro dbg. The purpose of this package is to provide a better and more effective

Dec 14, 2022
XSD (XML Schema Definition) parser and Go/C/Java/Rust/TypeScript code generator

xgen Introduction xgen is a library written in pure Go providing a set of functions that allow you to parse XSD (XML schema definition) files. This li

Jan 1, 2023
An online Zig compiler inspired by Go and Rust

Zig Playground This is a rudimentary online compiler for the Zig programming language. It is inspired by the Go playground. Setup The main server is a

Jan 3, 2023
A Go implementation of Rust's evmap

A Go implementation of Rust's evmap which optimizes for high-read, low-write workloads and uses eventual consistency to ensure that readers and writers never block each other.

Sep 3, 2022
Slabmap - Ported from Rust library slabmap

slabmap Ported from Rust library slabmap Examples import "github.com/pourplusquo

Jul 30, 2022
simple bank which is implemented using Golang

Banker The service that we’re going to build is a simple bank. It will provide APIs for the frontend to do following things: Create and manage bank ac

Nov 15, 2021
A Simple Bank Web Service implemented in Go, HTTP & GRPC, PostgreSQL, Docker, Kubernetes, GitHub Actions CI

simple-bank Based on this Backend Master Class by TECH SCHOOL: https://youtube.com/playlist?list=PLy_6D98if3ULEtXtNSY_2qN21VCKgoQAE Requirements Insta

Dec 9, 2021
Let's Go is task sharing app implemented in golang.

Let's Go - A sample GO app Overview Let's Go is an HTTP server. It has various apis to play with. It is a small app that can group users of a company

Dec 13, 2021
libFFM-gp: Pure Golang implemented library for FM (factorization machines)

libFFM-gp: Pure Golang implemented library for FM (factorization machines)

Oct 10, 2022
Seekable ZSTD compression format implemented in Golang.

ZSTD seekable compression format implementation in Go Seekable ZSTD compression format implemented in Golang. This library provides a random access re

Jan 7, 2023
Some utilities for Persian language in Go (Golang)

persian Some utilities for Persian language in Go (Golang). Installation go get github.com/mavihq/persian API .ToPersianDigits Converts all English d

Oct 22, 2022
Unit tests generator for Go programming language
Unit tests generator for Go programming language

GoUnit GoUnit is a commandline tool that generates tests stubs based on source function or method signature. There are plugins for Vim Emacs Atom Subl

Jan 1, 2023
FreeSWITCH Event Socket library for the Go programming language.

eventsocket FreeSWITCH Event Socket library for the Go programming language. It supports both inbound and outbound event socket connections, acting ei

Dec 11, 2022
Simple interface to libmagic for Go Programming Language

File Magic in Go Introduction Provides simple interface to libmagic for Go Programming Language. Table of Contents Contributing Versioning Author Copy

Dec 22, 2021
Go language interface to the PAPI performance API

go-papi Description go-papi provides a Go interface to PAPI, the Performance Application Programming Interface. PAPI provides convenient access to har

Dec 22, 2022
go language generics system

Gotgo This document describes the third iteration of my attempt at a reasonable implementation of generics for go based on the idea of template packag

Dec 31, 2022
The Gorilla Programming Language
The Gorilla Programming Language

Gorilla Programming Language Gorilla is a tiny, dynamically typed, multi-engine programming language It has flexible syntax, a compiler, as well as an

Apr 16, 2022
Elastic is an Elasticsearch client for the Go programming language.

Elastic is an Elasticsearch client for the Go programming language.

Jan 9, 2023