• Stars
    star
    161
  • Rank 233,470 (Top 5 %)
  • Language
    Rust
  • Created almost 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A lightweight, elegant scripting language with built-in Rust-FFI.

Forge

Forge is a dynamically-typed language written in Rust. It is inspired by JavaScript, Rust, Python and Rhai. In the future, you'll be able to use Forge as a general-purpose lightweight scripting language in your applications.

You can try out Forge in your browser here!

Example

# A function to square numbers
var square = |x| {
	return x * x;
};

var n = input "How many squares? ";

# Create a list of squares
var squares = [];
for x in 1..n + 1 {
	squares += square(x);
}

# Iterate and print squares
for square in squares {
	print square;
}

Goals

  • Simple, familiar syntax
  • Lightweight, quick to parse
  • Moderately fast execution speeds
  • Well-considered, 'common-sense' design
  • Useful, informative error messages
  • Easy to build into an existing codebase
  • Python-like REPL prompt

Usage

Using Forge is similar in principle to using Python. Once compiled, running the shell or executing scripts with the interpreter is trivial. You'll need to compile the cli/ crate to gain access to the interpreter binary.

To access the REPL shell, run:

$ forge

To execute a script, run:

$ forge my_script.fg

Roadmap

  • Numbers, strings and booleans
  • Arithmetic operators +, -, *, /, %
  • Logical operators and, or, xor, ==, !=, !, <, <=, >, >=
  • if/else statements
  • while and for statements
  • Assignment operators =, +=, -=, *=, /=, %=
  • Scoped variable declaration
  • Function objects
  • Function calling
  • Rust-to-Forge object interface
  • Rust-to-Forge type coercion
  • Rust callbacks Only Rust closures with no arguments or functions are currently supported
  • Iterators
  • Rust-to-Forge iterators
  • Lists
  • List splicing
  • Indexing and ranges
  • clone and mirror operators
  • Lvalues vs rvalues
  • Maps
  • Map construction
  • Map iteration
  • Immutability by default
  • Structures
  • Enums
  • Objects
  • Modules as objects
  • Scoped constants
  • C-based FFI for non-Rust integration
  • AST optimisation
  • Bytecode generation
  • Bytecode interpretation
  • LLVM-driven recompilation

Some Syntax Examples

List splicing

>> var my_list = [0, 1, 2, 3];
>> my_list[1..2]
[1]
>> my_list[1..3] = ["this", "is", "a", "list", "splice"];
>> my_list
[0, this, is, a, list, splice, 3]

String splicing

>> "Hello, world!"[7..12]
world
>> var test = "An apple is what I am eating";
>> test[3..8] = "pear";
>> test
An pear is what I am eating
>>

Design

Types

Forge has several distinct types:

  • Number 64-bit, floating-point
  • String unicode-compliant
  • Char unicode-compliant
  • Boolean
  • Range
  • Function
  • List
  • Map
  • Object Currently unimplemented
  • Custom Used to call to and from Rust
  • Null

Things To Do

  • Investigate design features that would make the dynamic type system easier to optimise

Interpreter

Currently, Forge is only implemented as an AST-walking interpreter. In the future, I aim to generate more efficient low-level bytecode for the language. I also aim to implement many a variety of optimisations throughout the compilation process.

Error Messages

Forge aims to produce the most useful, informative and intelligence error messages it can. Errors can be emitted at compile-time or run-time. Below are a few examples.

Parser errors:

[ERROR] Parsing error at 1:45...
   ...while parsing if-else statement...
   ...while parsing print statement...
        1| var x = 1; if x > 2 { print "Hello, world!" oops; }
         |                                             ^^^^
   Expected ';', found identifier 'oops'.

Runtime errors:

[ERROR] Runtime error at 1:21...
        1| var p = true; while p { print "On the next iteration, p will be null"; p = null; }
         |                     ^
   Cannot determine the truthiness of value of type 'null'. Did you mean for this to be a bool?

Runtime errors that produce error messages that reference code written during the previous declaration of a function object:

[ERROR] Runtime error at 1:10...
        1| var say_hello = || { print "Hello, world!"; };
         |                 ^^
        1| say_hello(1); # Wrong number of parameters
         |          ^^^
   Tried to call a function with the wrong number of parameters. Expected 0, found 1.

More Repositories

1

chumsky

Write expressive, high-performance parsers with ease.
Rust
3,334
star
2

flume

A safe and fast multi-producer, multi-consumer channel.
Rust
1,820
star
3

ariadne

A fancy diagnostics & error reporting crate
Rust
1,309
star
4

tao

A statically-typed functional language with generics, typeclasses, sum types, pattern-matching, first-class functions, currying, algebraic effects, associated types, good diagnostics, etc.
Rust
923
star
5

pollster

A minimal async executor that lets you block on a future
Rust
288
star
6

broom

An ergonomic tracing garbage collector that supports mark 'n sweep garbage collection
Rust
243
star
7

euc

A software rendering crate that lets you write shaders with Rust
Rust
241
star
8

atto

An insanely simple self-hosted functional programming language
Rust
141
star
9

parze

A clean, efficient parser combinator
Rust
123
star
10

teloren

A command-line frontend for Veloren
Rust
90
star
11

funkicrab

Optimising Brainfuck compiler: Run your beloved Brainfuck code, but faster.
Rust
64
star
12

openmw-volumetric-clouds

A volumetric clouds mod for OpenMW
64
star
13

openmw-shaders

Photorealistic shaders for Morrowind
GLSL
59
star
14

vulcan

A minimalistic text editor designed for both ordinary use and software development
Vala
45
star
15

lagoon

A thread pool crate with an array of features
Rust
36
star
16

mutation

Unleash the power of nightly Rust to write code that's generic over mutation!
Rust
23
star
17

coord-rs

[deprecated] A simple, ergonomic vector mathematics crate for Rust
Rust
22
star
18

errant

A (mostly) drop-in replacement for Rust's Result that provides backtrace support.
Rust
22
star
19

leon

A lightweight scripting language for Rust
Rust
19
star
20

zte

Zesterer's Text Editor
Rust
18
star
21

tupai

A modular POSIX-like operating system created for educational purposes
C++
16
star
22

gui

An experimental stateful, structured, declarative GUI crate
Rust
12
star
23

the-bitwise-challenge

Challenge: Can you develop a game with only 8 bytes of state?
9
star
24

vast-outdated

As The Name Suggests: A Pretty Large Space Sim
C++
8
star
25

vm-perf

Performance comparisons between various virtual interpreter implementation strategies
Rust
8
star
26

gba-test

Software rasterisation on the GBA in Rust. Some experiments from a while ago.
Rust
7
star
27

thoth

A modular, x86_64 micro-kernel operating system
C
6
star
28

alonzo

A pure Rust functional compiler backend
Rust
6
star
29

que

An experimental lock-free queue
Rust
6
star
30

cargo-veloren

Name-squatting, for the moment
Rust
5
star
31

fula

A functional programming language with Hindley-Milner type inference
Rust
5
star
32

babble

A (horrendously hackish) clean room reimplementation of the Library of Babel, originally at https://libraryofbabel.info (seriously, check it out)
Python
5
star
33

synco

An experimental ECS crate that makes use of GATs
Rust
5
star
34

fuckvm

A highly experimental Brainfuck-targetting LLVM-like compiler backend
Rust
4
star
35

smash

Yet another blazingly fast hashmap written in Rust
Rust
4
star
36

emul8

Yet another CHIP-8 emulator written in Rust
Rust
4
star
37

bitwise-examples

Example games that persist just 8 bytes of state between frames
Rust
4
star
38

browser

Vala
4
star
39

nilts-old

A game about many things. I don't know what, since most content is randomly generated.
C
3
star
40

oms

[WIP] Orbital mechanics simulation tool/library
Rust
3
star
41

hire-me

Hire me! Here's why...
3
star
42

turk

A generic minmax algorithm that may be used as an AI player for 2-player games
Rust
3
star
43

libvolume

A voxel engine library used primarily in my other projects
C++
3
star
44

wavefront

A Wavefront OBJ parser and utility crate
Rust
3
star
45

voxeltest

A test voxel engine program
C++
3
star
46

emul8or

A CHIP-8 emulator written using Vala and SDL
Vala
3
star
47

sdf-test

An experiment in Signed Distance Field (SDF) raytracing and raymarching
C++
3
star
48

ir

An experimental language intermediate representation
Rust
2
star
49

yurt

A highly experiment portable runtime
Rust
2
star
50

parze-new

Rust
2
star
51

nilts

Work in progress which will hopefully one day be good
C++
2
star
52

picos

Raspberry Pi Card Operating System
C
2
star
53

async-priority-queue

An async-aware priority queue
Rust
2
star
54

spurv

A free, open-source CPU and instruction set specification with a minimalist design
2
star
55

jsbarretto

A personal website
HTML
2
star
56

opplyse

A clean, efficient GTK3 text editor for programmers. The big brother of Vulcan.
Vala
2
star
57

nilts-oldish

The procedurally generated game
C++
2
star
58

super-block

A platforming game written for the CHIP-8
1
star
59

forge-demo

Run Forge code online!
JavaScript
1
star
60

cragmoor

A text-based ASCII RPG procedurally generated game inspired by Dwarf Fortress
C++
1
star
61

snakes-on-a-continuous-plane

A 2D Continuous Snakes Game Created For Ludum Dare 34
CMake
1
star
62

timber

I got bored one afternoon and started writing a desktop panel
Vala
1
star
63

vast-old

Vast is a space sim written in C++ using OpenGL
C++
1
star
64

pokerom

A GameBoy Color (GBC) emulator written in C++ with SDL 2
CMake
1
star