pub struct CodeGenInterfaceOptions {
custom_arguments []string
ast []&frontend.BrainfuckASTNode
struct EasyGenBackendDispatch {
backend_json map[string]string
fn (mut dp EasyGenBackendDispatch) register_egen_backend(name string, json_str string) {
dp.backend_json[name] = json_str
fn (mut dp EasyGenBackendDispatch) str() string {
mut res := 'Available EasyGen backends:\n'
for key, _ in dp.backend_json {
res += ' - ' + key + '\n'
fn (mut dp EasyGenBackendDispatch) generate_code(backend string, options CodeGenInterfaceOptions) ! {
if backend !in dp.backend_json {
return error('Backend ${backend} not found')
return egen_generate_code(dp.backend_json[backend], options)
pub fn generator_call_backend(backend_name string, options CodeGenInterfaceOptions) ! {
mut dp := EasyGenBackendDispatch{}
dp.register_egen_backend('cpp', $embed_file('generators/egen/cpp.json').to_string())
dp.register_egen_backend('py', $embed_file('generators/egen/python.json').to_string())
dp.register_egen_backend('js', $embed_file('generators/egen/nodejs.json').to_string())
mut cgen := CGenBackend{}
return cgen.generate_code(options)
mut vgen := VGenBackend{}
return vgen.generate_code(options)
return dp.generate_code(backend_name, options)