pocketlang/src/compiler.h
2021-06-07 07:20:06 +05:30

36 lines
1.2 KiB
C

/*
* Copyright (c) 2021 Thakee Nathees
* Licensed under: MIT License
*/
#ifndef COMPILER_H
#define COMPILER_H
#include "common.h"
#include "var.h"
typedef enum {
#define OPCODE(name, _, __) OP_##name,
#include "opcodes.h"
#undef OPCODE
} Opcode;
// Pocketlang compiler is a single pass compiler, which means it doesn't go
// throught the basic compilation pipline such as lexing, parsing (AST),
// analyzing, intermediate codegeneration, and target codegeneration one by one
// instead it'll generate the target code as it reads the source (directly from
// lexing to codegen). Despite it's faster than multipass compilers, we're
// restricted syntax-wise and from compiletime optimizations, yet we support
// "forward names" to call functions before they defined (unlike C/Python).
typedef struct Compiler Compiler;
// This will take source code as a cstring, compiles it to pocketlang bytecodes
// and append them to the script's implicit main (the $SourceBody function).
bool compile(PKVM* vm, Script* script, const char* source);
// Mark the heap allocated ojbects of the compiler at the garbage collection
// called at the marking phase of vmCollectGarbage().
void compilerMarkObjects(PKVM* vm, Compiler* compiler);
#endif // COMPILER_H