Skip to content

ravil-mobile/mcool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

LLVM-based COOL compiler

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published