Giter VIP home page Giter VIP logo

reple's Introduction

reple

"Replay-based" REPLs for compiled languages.

reple provides an "interpreter" (REPL) for compiled languages. Each time you enter a line of code, reple will add the new code to your program, compile and run the new iteration of your program, and then print any new output. reple currently supports C, C++, D, Go, Rust, UPC, MPI, DASH, BCL, Unicon, and Zig.

Installation

Just install the reple pip package.

[xiii@reple ~]$ pip3 install reple
[xiii@reple ~]$ reple -env cxx
> printf("Hello, World!\n");
Hello, World!

If you install the package locally, you might need to add ~/.local/bin to your path. As well, you will need to have the compilers installed seperately for each language you wish to use.

Usage

To start an interactive REPL session, call reple with the title of a configuration file defined in the /configs directory.

[xiii@reple xiii]$ reple -env cxx
> printf("Hello, World!\n");
Hello, World!
> int x = 12;
> int y = x + 2;
> std::cout << y << std::endl;
14

Functions and Global Variables

To define a new function or global variable, surround your expression with $.

> $void foo() {
  printf("Hello, World!\n");
}$
> foo();
Hello, World!

Errors

reple automatically detects compilation errors, printing them out for you without trashing your REPL state.

> int x = ;                                                                                         
/tmp/repl/repl0.cpp:8:9: error: expected expression
int x = ;
        ^
1 error generated.
>                                                                                                   

Multi-Line Statements

It also automatically detects most multi-line expressions, like if statements.

> int x = 12;
> if (x == 12) {
>   printf("Hello, World!\n");
> }
Hello, World!

Runtime Options

Some more complicated runtimes have optional runtime flags. An example of this is the number of processes to run a program with in MPI.

[xiii@reple home]$ reple -env mpicxx --rargs "-n 8"
> int rank, nprocs;
> MPI_Comm_rank(MPI_COMM_WORLD, &rank);
> MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
> printf("Hello, world! I'm %d/%d\n", rank, nprocs);
Hello, world! I'm 0/8
Hello, world! I'm 1/8
Hello, world! I'm 2/8
Hello, world! I'm 4/8
Hello, world! I'm 6/8
Hello, world! I'm 3/8
Hello, world! I'm 5/8
Hello, world! I'm 7/8
> 

Adding New Languages

Adding a new language to reple is easy. All you need to do is write a short JSON file that describes (1) how to append REPL lines to form a program, (2) how to compile and run a program, and (3) terminal options, which are things like characters that enclose expressions that can span multiple lines (like {} in C). These config files are typically only about 20 lines, and you can find examples in /reple/configs.

Issues and Contributions

We've tested reple on MacOS, FreeBSD, and a few Linux distros. If you run into any issues installing or using reple, please make an issue using our GitHub repo.

We welcome contributions in the form of pull requests, particularly if you'd like to add support for a new language or runtime system.

reple's People

Contributors

benbrock avatar hejsil avatar mollymorphic avatar moonlightsentinel avatar nobodywasishere avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

reple's Issues

Request: Allow free functions in c++

As all the code is encapsulated in main(), free functions are not possible (though classes are).
A workaround is of course the following:

$ reple -env cxx
> struct FreeFuncs {
>   static void do_stuff() {
>     std::cout << "Hello from do_stuff" << std::endl;
>   }
> };
> FreeFuncs::do_stuff();
Hello from do_stuff
>

or:

> struct {
>   void operator()() {
>    std::cout << "Hello from do_stuff" << std::endl;
>   }
> } do_stuff;
> do_stuff();
Hello from do_stuff
>

even:

> struct { int operator()(int a, int b) { return a+b;} } add;
> std::cout << add( 1, 3) << "\n";
4
>

but that is some weird and annoying boilerplate just to write a function.

It would be nice if the way to write your reple code mimics your usual c++ style.
I know it's a nice to have but are there any easy solution to this in the python code?

feat: showing the welcome message in the interpreter

It would be nice if information is shown before the prompt in interpreter.
For example, the python command:

Python 3.10.4 (main, Mar 23 2022, 23:05:40) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>>
>>>

Here are some info which can be shown by default:

  • language version
  • compiler version
  • reple version

We can also add some hints for the special commands like clear or quit:

Printing without newlines results in incorrect behavior


$  reple -env cxx
> $template <typename X> void id(X s) { std::cout << s; }$
> id("Hello");
Hello
> id(2);
> id("Hello");
>

Works fine with endl

$  reple -env cxx
> $template <typename X> void id(X s) { std::cout << s << std::endl
; }$
> id("Hello");
Hello
> id(34);
34
> id("Hey");
Hey
> id(4354);
4354
>

Allow local config file

There are two ways to provide a config file: Using the the -env foo and -f foo.json arguments. I feel this is redundant as they are basically the same.

Instead, I would expect -f foo.json to read a local file. I would also expect -f /home/user/foo.json to work.

[Bug] Can't include <iomanip> in cxx environment

Using reple -env cxx, enter the following commands:

  • #include <iostream>
  • #include <iomanip>
    Results in a bunch of errors (running on Arch Linux, gcc 12). Error log:
In file included from /usr/include/c++/12.1.0/bits/locale_facets_nonio.h:39,
                 from /usr/include/c++/12.1.0/locale:41,
                 from /usr/include/c++/12.1.0/iomanip:43,
                 from /tmp/repl/repl1.cpp:10:
/usr/include/c++/12.1.0/ctime: In function ‘int main(int, char**)’:
/usr/include/c++/12.1.0/ctime:58:1: error: ‘namespace’ definition is not allowed here
   58 | namespace std
      | ^~~~~~~~~
/usr/include/c++/12.1.0/ctime:77:1: error: ‘namespace’ definition is not allowed here
   77 | namespace std
      | ^~~~~~~~~
In file included from /usr/include/c++/12.1.0/cstdlib:41,
                 from /tmp/repl/repl1.cpp:1:
/usr/include/c++/12.1.0/bits/locale_facets_nonio.h:41:15: error: expected ‘=’ before ‘__attribute__’
   41 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/12.1.0/bits/locale_facets_nonio.h:41:15: error: expected identifier before ‘__attribute__’
/usr/include/c++/12.1.0/bits/locale_facets_nonio.h:41:14: error: expected ‘;’ before ‘__attribute__’
   41 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/12.1.0/bits/locale_facets_nonio.h:42:1: error: expected primary-expression before ‘{’ token
   42 | {
      | ^
/usr/include/c++/12.1.0/x86_64-pc-linux-gnu/bits/time_members.h:37:15: error: expected ‘=’ before ‘__attribute__’
   37 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/12.1.0/x86_64-pc-linux-gnu/bits/time_members.h:37:15: error: expected identifier before ‘__attribute__’
In file included from /usr/include/c++/12.1.0/bits/locale_facets_nonio.h:352:
/usr/include/c++/12.1.0/x86_64-pc-linux-gnu/bits/time_members.h:37:14: error: expected ‘;’ before ‘__attribute__’
   37 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/12.1.0/x86_64-pc-linux-gnu/bits/time_members.h:38:1: error: expected primary-expression before ‘{’ token
   38 | {
      | ^
/usr/include/c++/12.1.0/bits/locale_facets_nonio.h:354:15: error: expected ‘=’ before ‘__attribute__’
  354 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/12.1.0/bits/locale_facets_nonio.h:354:15: error: expected identifier before ‘__attribute__’
/usr/include/c++/12.1.0/bits/locale_facets_nonio.h:354:14: error: expected ‘;’ before ‘__attribute__’
  354 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/12.1.0/bits/locale_facets_nonio.h:355:1: error: expected primary-expression before ‘{’ token
  355 | {
      | ^
In file included from /usr/include/features.h:490,
                 from /usr/include/c++/12.1.0/x86_64-pc-linux-gnu/bits/os_defines.h:39,
                 from /usr/include/c++/12.1.0/x86_64-pc-linux-gnu/bits/c++config.h:655:
/usr/include/libintl.h:34:1: error: expected unqualified-id before string constant
   34 | __BEGIN_DECLS
      | ^~~~~~~~~~~~~
/usr/include/c++/12.1.0/x86_64-pc-linux-gnu/bits/messages_members.h:38:15: error: expected ‘=’ before ‘__attribute__’
   38 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/12.1.0/x86_64-pc-linux-gnu/bits/messages_members.h:38:15: error: expected identifier before ‘__attribute__’
In file included from /usr/include/c++/12.1.0/bits/locale_facets_nonio.h:2064:
/usr/include/c++/12.1.0/x86_64-pc-linux-gnu/bits/messages_members.h:38:14: error: expected ‘;’ before ‘__attribute__’
   38 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/12.1.0/x86_64-pc-linux-gnu/bits/messages_members.h:39:1: error: expected primary-expression before ‘{’ token
   39 | {
      | ^
/usr/include/c++/12.1.0/bits/codecvt.h:44:15: error: expected ‘=’ before ‘__attribute__’
   44 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/12.1.0/bits/codecvt.h:44:15: error: expected identifier before ‘__attribute__’
In file included from /usr/include/c++/12.1.0/bits/locale_facets_nonio.h:2067:
/usr/include/c++/12.1.0/bits/codecvt.h:44:14: error: expected ‘;’ before ‘__attribute__’
   44 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/12.1.0/bits/codecvt.h:45:1: error: expected primary-expression before ‘{’ token
   45 | {
      | ^
/usr/include/c++/12.1.0/bits/locale_facets_nonio.tcc:35:15: error: expected ‘=’ before ‘__attribute__’
   35 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/12.1.0/bits/locale_facets_nonio.tcc:35:15: error: expected identifier before ‘__attribute__’
In file included from /usr/include/c++/12.1.0/bits/locale_facets_nonio.h:2069:
/usr/include/c++/12.1.0/bits/locale_facets_nonio.tcc:35:14: error: expected ‘;’ before ‘__attribute__’
   35 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/12.1.0/bits/locale_facets_nonio.tcc:36:1: error: expected primary-expression before ‘{’ token
   36 | {
      | ^
/usr/include/c++/12.1.0/bits/locale_conv.h:42:15: error: expected ‘=’ before ‘__attribute__’
   42 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/12.1.0/bits/locale_conv.h:42:15: error: expected identifier before ‘__attribute__’
In file included from /usr/include/c++/12.1.0/locale:43:
/usr/include/c++/12.1.0/bits/locale_conv.h:42:14: error: expected ‘;’ before ‘__attribute__’
   42 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/12.1.0/bits/locale_conv.h:43:1: error: expected primary-expression before ‘{’ token
   43 | {
      | ^
/usr/include/c++/12.1.0/sstream:48:15: error: expected ‘=’ before ‘__attribute__’
   48 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/12.1.0/sstream:48:15: error: expected identifier before ‘__attribute__’
In file included from /usr/include/c++/12.1.0/bits/quoted_string.h:38,
                 from /usr/include/c++/12.1.0/iomanip:45:
/usr/include/c++/12.1.0/sstream:48:14: error: expected ‘;’ before ‘__attribute__’
   48 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/12.1.0/sstream:49:1: error: expected primary-expression before ‘{’ token
   49 | {
      | ^
/usr/include/c++/12.1.0/bits/sstream.tcc:39:15: error: expected ‘=’ before ‘__attribute__’
   39 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/12.1.0/bits/sstream.tcc:39:15: error: expected identifier before ‘__attribute__’
In file included from /usr/include/c++/12.1.0/sstream:1217:
/usr/include/c++/12.1.0/bits/sstream.tcc:39:14: error: expected ‘;’ before ‘__attribute__’
   39 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/12.1.0/bits/sstream.tcc:40:1: error: expected primary-expression before ‘{’ token
   40 | {
      | ^
/usr/include/c++/12.1.0/bits/quoted_string.h:40:15: error: expected ‘=’ before ‘__attribute__’
   40 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/12.1.0/bits/quoted_string.h:40:15: error: expected identifier before ‘__attribute__’
/usr/include/c++/12.1.0/bits/quoted_string.h:40:14: error: expected ‘;’ before ‘__attribute__’
   40 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/12.1.0/bits/quoted_string.h:41:1: error: expected primary-expression before ‘{’ token
   41 | {
      | ^
/usr/include/c++/12.1.0/iomanip:49:15: error: expected ‘=’ before ‘__attribute__’
   49 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/12.1.0/iomanip:49:15: error: expected identifier before ‘__attribute__’
/usr/include/c++/12.1.0/iomanip:49:14: error: expected ‘;’ before ‘__attribute__’
   49 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/12.1.0/iomanip:50:1: error: expected primary-expression before ‘{’ token
   50 | {
      | ^

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.