mirror of
https://github.com/zekexiao/pocketlang.git
synced 2025-02-06 12:46:53 +08:00
30 lines
1.1 KiB
C
30 lines
1.1 KiB
C
/*
|
|
* Copyright (c) 2021 Thakee Nathees
|
|
* Licensed under: MIT License
|
|
*/
|
|
|
|
#ifndef COMPILER_H
|
|
#define COMPILER_H
|
|
|
|
#include "common.h"
|
|
#include "var.h"
|
|
|
|
// 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
|