2021-02-07 15:40:00 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021 Thakee Nathees
|
|
|
|
* Licensed under: MIT License
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef COMPILER_H
|
|
|
|
#define COMPILER_H
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "var.h"
|
|
|
|
|
2021-06-06 22:24:13 +08:00
|
|
|
typedef enum {
|
|
|
|
#define OPCODE(name, _, __) OP_##name,
|
|
|
|
#include "opcodes.h"
|
|
|
|
#undef OPCODE
|
|
|
|
} Opcode;
|
|
|
|
|
2021-06-01 19:50:41 +08:00
|
|
|
// 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).
|
2021-02-07 15:40:00 +08:00
|
|
|
typedef struct Compiler Compiler;
|
|
|
|
|
2021-06-01 19:50:41 +08:00
|
|
|
// 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).
|
2021-05-09 18:28:00 +08:00
|
|
|
bool compile(PKVM* vm, Script* script, const char* source);
|
2021-02-07 15:40:00 +08:00
|
|
|
|
2021-06-01 19:50:41 +08:00
|
|
|
// Mark the heap allocated ojbects of the compiler at the garbage collection
|
|
|
|
// called at the marking phase of vmCollectGarbage().
|
2021-05-19 02:59:09 +08:00
|
|
|
void compilerMarkObjects(PKVM* vm, Compiler* compiler);
|
2021-04-26 17:34:30 +08:00
|
|
|
|
2021-02-07 15:40:00 +08:00
|
|
|
#endif // COMPILER_H
|