/07120

Primary LanguageDockerfileThe UnlicenseUnlicense

07-120 - Intro to Software Construction

Installation of the C0 Language

C0 is a safe subset of C augmented with contracts. This language has been specifically designed to support the learning objectives of 15-122, titled Principles of Imperative Computation. It provides

  • garbage collection
  • fixed range modular integer arithmetic
  • an unambiguous language definition
  • contracts

This Wiki doc provides instructions for installing C0 on different operating systems, including those running on MacOS ARM machines. We've modified this doc and will provide feedback on any issues.

Ubuntu and other Debian-based Linux distributions

Download the package and install it:

wget https://c0.cs.cmu.edu/downloads/cc0-debian.deb
sudo apt install ./cc0-debian.deb

To uninstall, run:

sudo apt remove cc0

MacOS

Apple Silicon/ARM Macs

Follow these steps:

  • Install a Universal version of libgmp using MacPorts, though this may work with Homebrew now as well.

    sudo port install gmp +universal
  • Download two versions ofthe latest MLTon:

    You can find more release packages here. For downloads on MacOS, you may need to override security setings.

  • Compile the MLTon source code you downloaded, using the amd64 statically-linked version of mlton from mlton.org in your $PATH:

    cd <where-you-placed-mlton-source-code>
    env PATH=<where-you-placed-mlton-amd64-static>/bin:$PATH LIBRARY_PATH=/opt/local/lib/ C_INCLUDE_PATH=/opt/local/include/ make WITH_GMP_DIR=/opt/local

Note: you might need to disable gatekeeper as described here: https://osxdaily.com/2015/05/04/disable-gatekeeper-command-line-mac-osx/

  • Install the CC0 dependencies using Homebrew or MacPorts (brew example shown here):

    brew install autoconf automake libpng pkg-config gnu-getopt
  • Finally, download and compile the C0/CC0 source:

    git clone https://github.com/zeeshanlakhani/07120
    cd c0/cc0
    ./configure
    env PATH=<where-you-built-mlton-in-the-previous-step/mlton>/build/bin:$PATH LIBRARY_PATH=/opt/local/lib/ C_INCLUDE_PATH=/opt/local/include/  make -j
  • Then bin/cc0 and bin/coin (coin is the C0 interpreter, cc0 is the compiler) in can be used normally. You can create links to these files from some directory on your $PATH.

Note: while all of these steps look somewhat daunting, I (Zeeshan Lakhani) was personally able to compile everything with just the statically-linked MLTon in my path, the required installs (GMP, Automake, etc) and running just:

git clone https://github.com/zeeshanlakhani/07120
cd c0/cc0
./configure
make -j

Nonetheless, I've kept everything here from what the C0 team recommends.

Intel/x86 Macs

  • The first and easiest step is use to Homebrew, and run

    brew tap cmu/cc0 https://bitbucket.org/c0-lang/downloads.git
    brew install cc0
  • To test the installation, run:

    brew test cc0
  • To uninstall, run:

    brew uninstall cc0

Windows

On Windows, we recommend installing Windows Subsystem for Linux v2 and then following the directions for Ubuntu/Debian above.

Installing from source

C0 depends on libpng and libncurses. If you have those installed (e.g. via a package manager), you should be able to compile from scratch:

git clone https://github.com/zeeshanlakhani/07120
cd c0/cc0
./configure
make -j
make install PREFIX=<your-prefix>

Using Docker

If you have Docker installed, you can install our container and run coin and cc0 binaries directly.

First, install our container:

docker pull ghcr.io/zeeshanlakhani/07120:latest

Then you can run it with a mounted volume of your .c0 files for example:

$ docker run --platform linux/amd64 -it --rm -v <path-to-my-c0-files>:/home/07120 -w /home/07120 ghcr.io/zeeshanlakhani/07120

Another option is first invoke the container like so:

$ docker run --platform linux/amd64 --name=c0-docker -it -v <path-to-my-c0-files>:/home/07120 -w /home/07120 ghcr.io/zeeshanlakhani/07120

and then just start it on subsequent invocations:

docker start -i c0-docker

You can remove the c0-docker container by running:

docker container ls -a | grep c0-docker
docker container rm [container_id]

where [container_id] is the first output of the first command.

You can also run the container in the background (in detached mode) and docker attach or docker exec into it.

Running Stepwise Debugging for containers in Visual Studio Code

TBD

Visual Studio Code extension

We highly recommend using Visual Studio Code with the C0 plugin for working with C0. The plugin provide IDE features such as code completion, parsing/typchecking of errors, go-to-definition, and more.

VisualC0

VisualC0 is a browser-based C0 playground that may be helpful for debugging C0 programs.

Other Resources

We highly recommend these reads from the 15-122 class to start out: