Coder Social home page Coder Social logo

rustrepl's Introduction

About

This is a really simple implementation of what I'd like a real interactive mode for rust to look like. You can enter statements (right now, use, import, fn declarations, and any expression) and it will evaluate the output. The way it is actually implemented is a hack - it stores view items (use and import), declarations (let and fn) and a statement (which is updated as you go). It then writes them to a file, compiles that, and runs it. If it encounters an error compiling, it shows just that error. It actually works surprisingly well.

Example session

rust> 1+1
2
rust> 1+'a'
error: internal compiler error: char type passed to convert_integral_ty_to_int_ty_set()
rust> 1+~"a"
error: mismatched types: expected `<VI0>` but found `~str` (integral variable vs ~str)
rust> 1+a
error: unresolved name: a
rust> fn hello() { ~"hello world" }
error: mismatched types: expected `()` but found `~str` (() vs ~str)
rust> fn hello() -> ~str { ~"hello world" }
rust> hello()
~"hello world"
rust> hello() + ~"...goodbye"
~"hello world...goodbye"
rust> let a = 23
rust> a/2
11
rust> (a as float)/2.0
11.5

Readline

It is really convenient to be able to move around the line (ie, back arrow to correct, move to the beginning / end) to edit it. This can be accomplished with the readline library, which, if this were anything but a hack, would eventually be integrated. But, in the spirit of this being a hack, you can install a wrapper (ie, rlwrap), and then run the repl like: rlwrap rustrepl and get readline support.

Future

The way forward for this is here: https://github.com/z0w0/rust-repl. This is a JIT based approach that should (eventually) function better than this does, and more importantly, be much faster (and eventually provide more features, like type inspection, etc). Right now, it is pretty rough, I believe, but it is improving rapidly!

rustrepl's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

rustrepl's Issues

wont run here :/

rust version 0.3.1:

david@debian ~/src/rust-stuff/repls/rustrepl
% /tmp/rust031/bin/rustc rustrepl.rs
rustrepl.rs:3:14: 3:15 error: expecting '{' but found ''
rustrepl.rs:3 extern mod std;
^

rust git version built yesterday:

david@debian ~/src/rust-stuff/repls/rustrepl
% rustc rustrepl.rs
rustrepl.rs:124:26: 124:44 error: mismatched types: expected &mut ~[<V34>] but found ~[<V26>] (expected &-ptr but found vector)
rustrepl.rs:124 vec::push(session.view_items, input);
^~~~~~~~~~~~~~~~~~
rustrepl.rs:130:26: 130:45 error: mismatched types: expected &mut ~[<V37>] but found ~[<V27>] (expected &-ptr but found vector)
rustrepl.rs:130 vec::push(session.definitions, input);
^~~~~~~~~~~~~~~~~~~
error: aborting due to 2 previous errors

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.