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

Overview

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);
    }
    
    opened by MakotoE 2
  • 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 :)

    opened by alpacaaa 1
  • 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
    
    opened by nyxkrage 1
  • 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.

    opened by mothfuzz 1
  • 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...)

    opened by zseri 1
  • 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.

    opened by tuqqu 0
  • 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.

    opened by CryZe 0
  • 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.

    opened by MakotoE 0
  • 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.

    opened by zackradisic 0
Releases(v0.1.0-alpha2-register-based)
Owner
null
Create a Python project automatically with rust (like create-react-app but for python)

create-python-project Create a Python project automatically with rust (like create-react-app but for python) Installation cargo install create-python-

Dhravya Shah 2 Mar 12, 2022
A Web-App written in Rust with Yew, using the same SyntaxHighlighter from Google Code Archive as planetb.ca

PlanetB SyntaxHighlighter About This is a small app, providing static files to have a frontend to format your code so you can paste it with styles to

Christof Weickhardt 2 Dec 14, 2022
πŸ±β€πŸ‘€ Cross-language static library for accessing the Lua state in Garry's Mod server plugins

gmserverplugin This is a utility library for making Server Plugins that access the Lua state in Garry's Mod. Currently, accessing the Lua state from a

William 5 Feb 7, 2022
A parser, compiler, and virtual machine evaluator for a minimal subset of Lua; written from scratch in Rust.

lust: Lua in Rust This project implements a parser, compiler, and virtual machine evaluator for a minimal subset of Lua. It is written from scratch in

Phil Eaton 146 Dec 16, 2022
⚑ Fast Web Security Scanner written in Rust based on Lua Scripts πŸŒ– πŸ¦€

⚑ Fast Web Security Scanner written in Rust based on Lua Scripts ?? ??

Rusty Sec 14 Nov 28, 2022
Create, open, manage your Python projects with ease, a project aimed to make python development experience a little better

Create, open, manage your Python projects with ease, a project aimed to make python development experience a little better

Dhravya Shah 7 Nov 18, 2022
Lua 5.3 bindings for Rust

rust-lua53 Aims to be complete Rust bindings for Lua 5.3 and beyond. Currently, master is tracking Lua 5.3.3. Requires a Unix-like environment. On Win

J.C. Moyer 150 Dec 14, 2022
Safe Rust bindings to Lua 5.1

rust-lua Copyright 2014 Lily Ballard Description This is a set of Rust bindings to Lua 5.1. The goal is to provide a (relatively) safe interface to Lu

Lily Ballard 124 Jan 5, 2023
Zero-cost high-level lua 5.3 wrapper for Rust

td_rlua This library is a high-level binding for Lua 5.3. You don't have access to the Lua stack, all you can do is read/write variables (including ca

null 47 May 4, 2022
Rust library to interface with Lua

hlua This library is a high-level binding for Lua 5.2. You don't have access to the Lua stack, all you can do is read/write variables (including callb

Pierre Krieger 488 Dec 26, 2022
Pure Rust Lua implementation

purua Pure Rust Lua implementation Usage $ bat lua_examples/defun.lua ───────┬────────────────────────────────────────── β”‚ File: lua_examples/d

Kondo Uchio 35 Dec 28, 2021
Rust scaffold system with Lua embedded applets.

brickpack-2022 Demo Powered by Github Actions CI/CD (Heroku) https://demo-1642622230.herokuapp.com/#/users Frontent Runner Rendered sample code (Lua 5

null 0 Nov 24, 2022
πŸ“¦ Pack hundreds of Garry's Mod Lua files into just a handful

?? gluapack gluapack is a program that can pack hundreds of Garry's Mod Lua files into just a handful. Features Quick, easy and portable - perfect for

null 11 Aug 10, 2021
A memory safe Lua interpreter

Hematita Da Lua Hematita Da Lua is an interpreter for the scripting language Lua, written entirely in 100% safe Rust. Hematita is the portugese word f

Daniel 149 Dec 29, 2022
A super-lightweight Lua microservice (toy) framework.

Hive A super-lightweight microservice (toy) framework written in Rust. It uses Lua as interface to provide simple, fun developing experience and fast

Eric Long 39 Aug 14, 2022
This tool converts Lua code to TS automatically, including the conversion of common standards to their TS equivalents.

lua-to-ts This tool converts Lua code to TS automatically, including the conversion of common standards to their TS equivalents. Code that fails to be

Dion 11 Nov 21, 2022
Another cursed Garry's Mod module. This time, it adds the C preprocessor to Lua scripts

gm_cpreprocessor Another cursed Garry's Mod module. This time, it adds the C preprocessor to Lua scripts. It works by detouring RunStringEx and overri

William 6 Aug 14, 2022
Node.js bindings to Lua

Node.js bindings to Lua

Connor Brewster 6 Dec 19, 2022
C-like language compiler, the final project of ZJU Compiler Principle course

cc99 cc99 (not cc98.org) is a C-like language compiler, which is the final project of ZJU Compiler Principle course. It supports many of the C99 langu

Ralph 37 Oct 18, 2022