This is a WIP project. Tested only in linux (Ubuntu 18.04).
To run all tests successfully you must have installed in your machine:
- Java
- PHP CLI
- Python 2
- Python 3
- Bash
These above requirements will be removed soon.
To setup a new compiler is pretty simple. You have three ways to add a new compiler:
- Go to
src/common/langs.ts
file. It look like this:
export const lang = {
java: {
compileCommand: 'javac {fileName}',
runCommand: 'java {compiledFileName}',
filePath: './__tests__/files/java'
},
python: {
runCommand: 'python{version} {fileName}',
filePath: './__tests__/files/python'
}
}
- You can add a new object that sets up your new compiler. Here, we add a C compiler that uses GCC:
c: {
compileCommand: 'gcc MyFile.c -o MyFile',
runCommand: './MyFile',
filePath: 'path/to/c/file'
}
- Now you can use your compiler. In the constructor you need only pass a lang option that references your compiler definitions in langs file:
let myCompiler: Compiler = new Compiler({
lang: lang.c
})
myCompiler.execute().subscribe((result) => {
console.log(result.output)
})
- In a Compiler constructor you can pass compiler options (CompilerOptions interface), same names as you passed in langs file:
let myCompiler: Compiler = new Compiler({
compileCommand: 'gcc MyFile.c -o MyFile',
runCommand: './MyFile',
filePath: 'path/to/c/file'
})
- And than, execute it!
myCompiler.execute().subscribe((result) => {
console.log(result.output)
})
If you noticed, we set a fixed file name in the compileCommand
and runCommand
option. But if we need a dynamic file name? Let's make some changes to our compiler definition in langs file.
- We can pass dynamic variables in our commands:
c: {
compileCommand: 'gcc {fileName} -o {compiledFileName}',
runCommand: './{compiledFileName}',
filePath: 'path/to/c/file'
}
Variables are always used inside two braces ({variableName}
). By default there are four types of variables. These variables will be replaced by the compiler options that have the same name:
Variable name | Description |
---|---|
version | Replaced by version compiler option |
fileName | Replaced by fileName compiler option |
compiledFileName | Replaced by compiledFileName option |
filePath | Replaced by compiledFileName option |
- Now you can define a "template" of your commands in the langs file and in the constructor options you can define the variables values:
let myCompiler: Compiler = new Compiler({
lang: lang.c,
fileName: 'MyCFile.c',
compiledFileName: 'MyCFile'
})
- Finally you can normaly execute your compiler:
myCompiler.execute().subscribe((result) => {
console.log(result.output)
})
Note that {fileName}
and {compiledFileName}
will be replaced by MyCFile.c
and MyCFile
respectively.
BE CAREFUL: Compiler options defined in the constructor overrides lang file defined options.
NOTE: The C and Java language, other than Python, for example, needs to be compiled before it can be run. For these cases add the option compileCommand
and runCommand
. If the language can be executed directly, only the runCommand
is needed.