CodeRunner: multi-language support
camerondurham opened this issue · comments
Design/Refactor CodeRunner
module to support running compiled and interpreted languages.
Currently, to support compiled languages, the compile and run step have to be executed "together" (link). This issue is to create a PreRunHook interface that implements any steps required before running the code. An example of how this could be used is writing the sourcecode to file for Python or writing to file and compiling to binary for C++.
Requirements:
- "easy" to add another language (easy can be defined many ways, let's say adding support for Node shouldn't take more than a week?)
- supports compiled and interpreted code execution
Example interface:
type CodeRunner interface {
PreRunHook(lang Language, filename string) (RunProps, error)
Run(props RunProps) (RunResponse, error)
PostRunHook(filepath string) (error)
}
Currently implementation is here.
Example execution structure:
func (r *CodeRunner) Run(req *RunnerProps) (*RunnerOutput, error) {
// error handling ...
// handles writing to filename.extension and compiling code if needed
runProps, err = r.runner.PreRunHook(r.language, runDirectoryTmp)
// error handling
resp, err := Run(runProps)
// cleanup
// ...
// return output
}
-
CodeRunner function accepts variable language and code snippet
- CodeRunner can internally handles compiling step if needed
- CodeRunner may temporarily store user code in filesystem
- CodeRunner deletes user code after running
- Unit test for multi-language feature
-
End to End test for basic code snippet