Skip to content

cs121-team-panda/coconut-interpreter

Repository files navigation

Coconut is a functional programming language that compiles to Python. The online interpreter provides an instant programming environment for Coconut. Users can enter and execute Coconut code and view the output.

Architecture

architecture

The project's architecture deploys a server-less backend, AWS Lambda, that compiles and executes user-submitted Coconut code. The frontend is built with React. For local development, a Flask app serves as the backend.

Prerequisites

Backend and package manager

Notable Python Packages (installed with pip install -r requirements.txt below)

  • coconut: compiles Coconut code into Python code.
  • flask: serves backend API for local development.
  • zappa: packages and deploys Flask app to AWS Lambda.

Installation

For backend installation, we recommend users use Anaconda to handle Python packages. If Python 3.x is not the default Python version, the users may have to use pip3 instead of pip to install Python packages and python3 instead of python to run Python. We recommend the users check their location and version of Python they are currently using by using which pip and pip --version commands. If users have Python from Anaconda, we further recommend the users install all Python packages within a new virtual environment.

For frontend installation of node and yarn, we recommend users install these separately using the latest stable version. For Mac users, installations with Homebrew for both node and yarn should be perfectly fine.

Note that users should not have to use sudo privileges to install all Python requirement packages. If the users encounter a permission issue, it may suggest they have previously installed one of our required packages with sudo privileges.

# Clone the repository
> git clone https://github.com/cs121-team-panda/coconut-interpreter.git
> cd coconut-interpreter

# Backend Installation
> which pip
/Users/<your username>/anaconda3/bin/pip
> pip --version
pip 9.0.1 from /Users/<your username>/anaconda3/lib/python3.6/site-packages (python 3.6)
> pip install -r requirements.txt

# Frontend Installation
> node --version
v8.11.1
> yarn --version
1.5.1
> cd client
> yarn install

Running Locally

> cd coconut-interpreter
> which python
/Users/<your username>/anaconda3/bin/python
> python manage.py runserver 

...and in a separate shell:

> cd coconut-interpreter/client
> yarn start

Open http://localhost:3000 to see the app.

Functionality

The interpreter consists of an easy-to-use webpage (shown below) that enables user to easily enter and execute Coconut code.

demo1

  • Code Editor: The code editor, which is on the left side of the webpage, is where the user types in their Coconut code. The editor has line numbers and Coconut-specific syntax highlighting.

  • Compilation Settings: Clicking the settings gear will display a settings drawer. From within the drawer, the user can select which version of Python the Coconut code will compile to. By default, the latest version of Python 3 is selected.

  • Saving to a Coconut File: Clicking the save icon will download the contents of the code editor into a Coconut file called coconut.coco.

  • Code Execution: Clicking RUN or using the keyboard shortcut Ctrl + Enter for Windows or ⌘ + Enter for Mac will compile and execute the program.

  • Showing the Compiled Python: Checking the box labeled PYTHON will replace the output with the compiled Python, which is the output of the Coconut compiler. The Python code will be displayed using Python syntax highlighting.

  • Code Execution Output: The code execution output is on the right side of the webpage.

  • Traceback Highlighting: If an error came from the Coconut compiler, the offending Coconut line will be highlighted in red in the code editor. If an error occurred at runtime, then the offending line will be highlighted in red in the Python code, if the Python checkbox is checked:

demo2 1

Known Problems

There is no support for Coconut's parallel_map function due to limitations of AWS Lambda. Our client is aware and is ok with this issue since it is not major (users can use map instead).

Contributing

When contributing to this repository, please first discuss the change you wish to make via issue with the owners of this repository before making a change.

Pull Request Process

  1. Ensure any install or build dependencies are removed before the end of the layer when doing a build.
  2. Update the README.md with details of changes to the interface.
  3. Increase the version numbers in any examples files and the README.md to the new version that this Pull Request would represent.
  4. You may merge the Pull Request in once you have the sign-off of two other developers, or if you do not have permission to do that, you may request the second reviewer to merge it for you.

Documentation

License

MIT. Copyright (c) Jonathan Cruz, Teerapat Jenrungrot, Natalie Kadonaga, Brittany Wang.