Coder Social home page Coder Social logo

mcool's Introduction

COOL - Classroom Object Oriented Language

This is a C++17/LLVM implementation of the language.

Dependencies

  1. gcc with C++17 support (e.g., v11.3)
  2. flex v2.6
  3. bison v3.5
  4. llvm v12.0.1
  5. googletest v1.10

Installation

You can install cool on your machine as follows

mkdir build && cd build
cmake ../mcool -DCMAKE_INSTALL_PREFIX=<installation directory>
make -j2
make install

Example

$ cat ./fibonacci.cl
class Main inherits IO {
  main(): Object {{
    out_string("Enter an integer greater-than or equal-to 0: ");

    let input: Int <- in_int() in
      if input < 0 then
        out_string("ERROR: Number must be greater-than or equal-to 0\n")
      else {
        out_string("The fibonacci number of ").out_int(input);
        out_string(" is ").out_int(fibonacci(input));
        out_string("\n");
      }
      fi;
  }};

  fibonacci(num: Int): Int {
    if num = 0 then 0 else { if num = 1 then 1 else fibonacci(num - 1) + fibonacci(num - 2) fi; } fi
  };
};
$ mcool -i ./fibonacci.cl -o ./fibonacci
$ clang ./fibonacci.o -o ./fibonacci
$ ./fibonacci

Note, we use clang (or gcc) as a linker.

Run COOL with Docker

If you experience problems with installing dependencies you can build a Docker image from the provided Dockerfile

docker build --build-arg UID=$(id -u) --build-arg GID=$(id -u) -t mcool .

Let's assume that your cool source files are located in $(pwd)/dir. Then you can compile your program as follows

docker run --rm -v $(pwd)/dir:/home/user/workspace mcool:latest mcool -i ./<file>.cl -o ./<file>
gcc ./dir/<file>.o -o ./dir/<file>

Miscellaneous

Use mcool --help to see all available compiler options

Current Status

Systems Status Tests
Lexer ✔️ ✔️
Parser ✔️ ✔️
Type Checking ✔️ ✔️
Code Generation ✔️
Garbage Collector

mcool's People

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

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.