All Projects → murarth → Rusti

murarth / Rusti

Licence: other
REPL for the Rust programming language

Programming Languages

rust
11053 projects

Labels

Projects that are alternatives of or similar to Rusti

Ronin
Experimental Graphics Terminal
Stars: ✭ 1,065 (-19.07%)
Mutual labels:  repl
Akilang
A compiler for a simple language, built with Python and LLVM
Stars: ✭ 71 (-94.6%)
Mutual labels:  repl
Omnia
Stars: ✭ 81 (-93.84%)
Mutual labels:  repl
Baapan
✨ Super Cool NPM Playground right on the Node REPL ✨
Stars: ✭ 60 (-95.44%)
Mutual labels:  repl
Drepl
A REPL for D
Stars: ✭ 70 (-94.68%)
Mutual labels:  repl
Boot Cljs Repl
Boot task providing a REPL for ClojureScript development.
Stars: ✭ 74 (-94.38%)
Mutual labels:  repl
Indium
A JavaScript development environment for Emacs
Stars: ✭ 1,058 (-19.6%)
Mutual labels:  repl
Kubeplay
kubeplay – a new way to interact with Kubernetes API from your terminal
Stars: ✭ 83 (-93.69%)
Mutual labels:  repl
Repl
🐚 an instant REPL for any command
Stars: ✭ 71 (-94.6%)
Mutual labels:  repl
Goto
Goto is an interpreted programming language written in go.
Stars: ✭ 79 (-94%)
Mutual labels:  repl
Trymodule
➰ It's never been easier to try nodejs modules!
Stars: ✭ 1,115 (-15.27%)
Mutual labels:  repl
Ts Node
TypeScript execution and REPL for node.js
Stars: ✭ 9,571 (+627.28%)
Mutual labels:  repl
Gistlyn
Run Roslyn Gists
Stars: ✭ 75 (-94.3%)
Mutual labels:  repl
I8086.js
16bit Intel 8086 / 80186 + X87 emulator written in TypeScript with REPL assembly compiler and tiny C compiler
Stars: ✭ 54 (-95.9%)
Mutual labels:  repl
Clj Suitable
ClojureScript "IntelliSense" support for JS objects and their properties/methods. Via figwheel and Emacs CIDER.
Stars: ✭ 82 (-93.77%)
Mutual labels:  repl
Nclap
NClap is a .NET library for parsing command-line arguments and building interactive command shells. It's driven by a declarative attribute syntax, and easy to extend.
Stars: ✭ 51 (-96.12%)
Mutual labels:  repl
Ramtuary
Ramda + Ramda Fantasy + Sanctuary REPL 🌿
Stars: ✭ 72 (-94.53%)
Mutual labels:  repl
Evaluate
A version of eval for R that returns more information about what happened
Stars: ✭ 88 (-93.31%)
Mutual labels:  repl
Psysh
A REPL for PHP
Stars: ✭ 9,161 (+596.12%)
Mutual labels:  repl
Ultra
A Leiningen plugin for a superior development environment
Stars: ✭ 1,213 (-7.83%)
Mutual labels:  repl

Rusti

A REPL for the Rust programming language.

The rusti project is deprecated. It is not recommended for regular use.

Dependencies

On Unix systems, Rusti requires libncursesw (libncurses on Mac OS).

Building

Rusti builds with Rust nightly, using the Cargo build system.
Currently, it must be built using a nightly release of the Rust compiler released no later than 2016-08-01.

The recommended method of installation is to use the following command to rustup:

rustup install nightly-2016-08-01

Installation using Cargo

Rusti can be installed directly using Cargo. The following command will download, compile, and install Rusti, placing it in ~/.cargo/bin/ or your operating system equivalent, assuming you haved installed nightly-2016-08-01 using rustup:

rustup run nightly-2016-08-01 cargo install --git https://github.com/murarth/rusti

Then you can run it like this:

rustup run nightly-2016-08-01 ~/.cargo/bin/rusti

Building from a Git clone

If using rustup, the following command will create an override to use the correct nightly build within the rusti source tree:

rustup override add nightly-2016-08-01

Build with Cargo:

cargo build

Run tests:

cargo test

Run rusti:

cargo run

Install:

cargo install

Usage

Running rusti gives a prompt that accepts (most) any valid Rust code. If the final statement is an expression, the result will be displayed using the std::fmt::Debug trait. This is equivalent to println!("{:?}", expr);.

rusti=> println!("Hello, world!");
Hello, world!
rusti=> 2 + 2
4
rusti=> (0..5).collect::<Vec<_>>()
[0, 1, 2, 3, 4]

If any delimiters are left open, rusti will continue reading input until they are closed. Only then will the code be executed.

rusti=> fn factorial(n: u32) -> u32 {
rusti.>     match n {
rusti.>         0 => 0,
rusti.>         1 => 1,
rusti.>         n => n * factorial(n - 1),
rusti.>     }
rusti.> }
rusti=> factorial(3)
6
rusti=> factorial(4)
24
rusti=> factorial(5)
120

rusti can also run a file given on the command line.
Note that a rusti input file is not quite the same as a typical Rust program. A typical Rust program contains a function named main. While a rusti program can define functions, no functions will be called automatically. Instead, all statements not within a function body will be executed sequentially, just like interactive mode.

Loading Crates

Loading crates which are part of the standard Rust distribution is as easy as declaring the crate, thusly:

extern crate foo;

However, loading a crate that you have compiled yourself requires some extra steps:

  • First, rusti must be able to find the location of compiled crate.
    You can add a path to its search list using the command line option -L path.
    rusti accepts any number of -L arguments.

  • Secondly, rusti requires both an rlib and a dylib version of the compiled crate. If you're building your crate with Cargo, the following command will build the required files for your project's library:

    cargo rustc --lib -- --crate-type=rlib,dylib
    

    If you're building with rustc directly, simply add --crate-type=rlib,dylib to the build command to produce the required files.

Code completion

rusti provides optional support for code completion using Racer.

To enable code completion, install Racer as outlined in the Installation Instructions and place the racer executable into your PATH.

Commands

These are special inputs interpreted by rusti that are not directly evaluated as Rust code, though they may operate on Rust code.

Commands are invoked by entering a line beginning with . or :, followed by the name of the command and, perhaps, some text used by the command.

Command names may be arbitrarily abbreviated.
For example, .type may be abbreviated as .typ, .ty, or .t.

.block

The .block command will run multiple lines of Rust code as one program.

To end the command and run all code, input . on its own line.

rusti=> .block
rusti+> let a = 1;
rusti+> let b = a * 2;
rusti+> let c = b * 3;
rusti+> c
rusti+> .
6

Entering .q instead will end the command without running code.

.exit

The .exit command exits the REPL loop.

.help

The .help command shows usage text for any available commands.

.load

The .load command evaluates the contents of a named file.

.print

The .print command will display the value of an expression, using the std::fmt::Display trait. This is equivalent to println!("{}", expr);.

.type

The .type command will display the type of an expression without running it.

rusti=> .type 42
42 = i32
rusti=> .t 'x'
'x' = char
rusti=> .t "Hello!"
"Hello!" = &'static str
rusti=> .t (1i32, 2u32)
(1i32, 2u32) = (i32, u32)
rusti=> fn foo() -> i32 { 1 }
rusti=> .t foo
foo = fn() -> i32 {foo}
rusti=> .t foo()
foo() = i32

Limitations

Currently, Rusti has the following limitations. I hope to fix each of them, but some may prove to be large problems to tackle.

  • Functions and types are redefined in each round of input.
    This is inefficient.
  • static items are also redefined in each round of input.
    This means that the address of a static item will change in every round of input and that the values of mut items or those with interior mutability will be reset to their initial definition on each round of input.
    This is bad.
  • Use of thread_local! causes a crash.
    This is bad.
  • let declarations are local to the input in which they are defined.
    They cannot be referenced later and are destroyed after that round of input completes its execution.
    This is inconvenient.
  • And more!

License

Rusti is distributed under the terms of both the MIT license and the Apache License (Version 2.0).

See LICENSE-APACHE and LICENSE-MIT for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].