This is a C++17/LLVM implementation of the language.
gcc
with C++17 support (e.g., v11.3)flex v2.6
bison v3.5
llvm v12.0.1
googletest v1.10
You can install cool
on your machine as follows
mkdir build && cd build
cmake ../mcool -DCMAKE_INSTALL_PREFIX=<installation directory>
make -j2
make install
$ 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.
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>
Use mcool --help
to see all available compiler options
Systems | Status | Tests |
---|---|---|
Lexer | ✔️ | ✔️ |
Parser | ✔️ | ✔️ |
Type Checking | ✔️ | ✔️ |
Code Generation | ✔️ | ❌ |
Garbage Collector | ❌ | ❌ |