![]() |
Phasor 2.2.0
Stack VM based Programming Language
|
Code generator for Phasor VM. More...
#include <CodeGen.hpp>
Public Member Functions | |
| Bytecode | generate (const AST::Program &program, const std::map< std::string, int > &existingVars={}, int nextVarIdx=0, bool replMode=false) |
| Generate bytecode from program. | |
Private Member Functions | |
| uint8_t | allocateRegister () |
| Allocate a new register. | |
| void | freeRegister (uint8_t reg) |
| Free a register. | |
| void | resetRegisters () |
| Reset register allocator. | |
| bool | isLiteralExpression (const AST::Expression *expr, Value &outValue) |
| Check if expression is a compile-time literal. | |
| ValueType | inferExpressionType (const AST::Expression *expr, bool &known) |
| Simple expression type inference (conservative). | |
| void | generateStatement (const AST::Statement *stmt) |
| Generate bytecode from Statement. | |
| void | generateExpression (const AST::Expression *expr) |
| Generate bytecode from Expression. | |
| void | generateVarDecl (const AST::VarDecl *varDecl) |
| Generate bytecode from Variable Declaration. | |
| void | generateExpressionStmt (const AST::ExpressionStmt *exprStmt) |
| Generate bytecode from Expression Statement. | |
| void | generatePrintStmt (const AST::PrintStmt *printStmt) |
| Generate bytecode from Print Statement. | |
| void | generateImportStmt (const AST::ImportStmt *importStmt) |
| Generate bytecode from Import Statement. | |
| void | generateExportStmt (const AST::ExportStmt *exportStmt) |
| Generate bytecode from Export Statement. | |
| void | generateNumberExpr (const AST::NumberExpr *numExpr) |
| Generate bytecode from Numeral Expression. | |
| void | generateStringExpr (const AST::StringExpr *strExpr) |
| Generate bytecode from String Expression. | |
| void | generateIdentifierExpr (const AST::IdentifierExpr *identExpr) |
| Generate bytecode from Identifier Expression. | |
| void | generateUnaryExpr (const AST::UnaryExpr *unaryExpr) |
| Generate bytecode from Unary Expression. | |
| void | generateCallExpr (const AST::CallExpr *callExpr) |
| Generate bytecode from Call Expression. | |
| void | generateBinaryExpr (const AST::BinaryExpr *binExpr) |
| Generate bytecode from Binary Expression. | |
| void | generateBlockStmt (const AST::BlockStmt *blockStmt) |
| Generate bytecode from Block Statement. | |
| void | generateIfStmt (const AST::IfStmt *ifStmt) |
| Generate bytecode from If Statement. | |
| void | generateWhileStmt (const AST::WhileStmt *whileStmt) |
| Generate bytecode from While Statement. | |
| void | generateForStmt (const AST::ForStmt *forStmt) |
| Generate bytecode from For Statement. | |
| void | generateReturnStmt (const AST::ReturnStmt *returnStmt) |
| Generate bytecode from Return Statement. | |
| void | generateUnsafeBlockStmt (const AST::UnsafeBlockStmt *unsafeStmt) |
| Generate bytecode from Unsafe Block Statement. | |
| void | generateFunctionDecl (const AST::FunctionDecl *funcDecl) |
| Generate bytecode from Function Declaration. | |
| void | generateBooleanExpr (const AST::BooleanExpr *boolExpr) |
| Generate bytecode from Boolean Expression. | |
| void | generateNullExpr (const AST::NullExpr *nullExpr) |
| Generate bytecode from Null Expression. | |
| void | generateAssignmentExpr (const AST::AssignmentExpr *assignExpr) |
| Generate bytecode from Assignment Expression. | |
| void | generateStructDecl (const AST::StructDecl *decl) |
| void | generateStructInstanceExpr (const AST::StructInstanceExpr *expr) |
| void | generateFieldAccessExpr (const AST::FieldAccessExpr *expr) |
| void | generatePostfixExpr (const AST::PostfixExpr *expr) |
| void | generateBreakStmt () |
| void | generateContinueStmt () |
| void | generateSwitchStmt (const AST::SwitchStmt *switchStmt) |
Private Attributes | |
| Bytecode | bytecode |
| Generated bytecode. | |
| bool | isRepl = false |
| REPL mode. | |
| std::map< std::string, ValueType > | inferredTypes |
| uint8_t | nextRegister = 0 |
| Next available register. | |
| std::vector< bool > | registerInUse |
| Track which registers are in use. | |
| std::vector< int > | loopStartStack |
| std::vector< std::vector< int > > | breakJumpsStack |
| std::vector< std::vector< int > > | continueJumpsStack |
Definition at line 242 of file CodeGen.hpp.
|
inlineprivate |
Allocate a new register.
Definition at line 268 of file CodeGen.hpp.
|
inlineprivate |
Free a register.
Definition at line 286 of file CodeGen.hpp.
| Bytecode Phasor::CodeGenerator::generate | ( | const AST::Program & | program, |
| const std::map< std::string, int > & | existingVars = {}, | ||
| int | nextVarIdx = 0, | ||
| bool | replMode = false ) |
Generate bytecode from program.
| program | Program to generate bytecode for |
| existingVars | Existing variables to use |
| nextVarIdx | Next available variable index |
| replMode | REPL mode |
Definition at line 7 of file CodeGen.cpp.
|
private |
Generate bytecode from Assignment Expression.
Definition at line 903 of file CodeGen.cpp.
|
private |
Generate bytecode from Binary Expression.
Definition at line 429 of file CodeGen.cpp.
|
private |
Generate bytecode from Block Statement.
Definition at line 681 of file CodeGen.cpp.
|
private |
Generate bytecode from Boolean Expression.
Definition at line 886 of file CodeGen.cpp.
|
private |
|
private |
Generate bytecode from Call Expression.
Definition at line 335 of file CodeGen.cpp.
|
private |
|
private |
Generate bytecode from Export Statement.
Definition at line 268 of file CodeGen.cpp.
|
private |
Generate bytecode from Expression.
Definition at line 157 of file CodeGen.cpp.
|
private |
Generate bytecode from Expression Statement.
Definition at line 243 of file CodeGen.cpp.
|
private |
Definition at line 986 of file CodeGen.cpp.
|
private |
Generate bytecode from For Statement.
Definition at line 752 of file CodeGen.cpp.
|
private |
Generate bytecode from Function Declaration.
Definition at line 855 of file CodeGen.cpp.
|
private |
Generate bytecode from Identifier Expression.
Definition at line 305 of file CodeGen.cpp.
|
private |
Generate bytecode from If Statement.
Definition at line 689 of file CodeGen.cpp.
|
private |
Generate bytecode from Import Statement.
Definition at line 262 of file CodeGen.cpp.
|
private |
Generate bytecode from Null Expression.
Definition at line 898 of file CodeGen.cpp.
|
private |
Generate bytecode from Numeral Expression.
Definition at line 274 of file CodeGen.cpp.
|
private |
|
private |
Generate bytecode from Print Statement.
Definition at line 256 of file CodeGen.cpp.
|
private |
Generate bytecode from Return Statement.
Definition at line 837 of file CodeGen.cpp.
|
private |
Generate bytecode from Statement.
Definition at line 88 of file CodeGen.cpp.
|
private |
Generate bytecode from String Expression.
Definition at line 299 of file CodeGen.cpp.
|
private |
|
private |
Definition at line 953 of file CodeGen.cpp.
|
private |
Definition at line 1080 of file CodeGen.cpp.
|
private |
Generate bytecode from Unary Expression.
Definition at line 311 of file CodeGen.cpp.
|
private |
Generate bytecode from Unsafe Block Statement.
Definition at line 850 of file CodeGen.cpp.
|
private |
Generate bytecode from Variable Declaration.
Definition at line 208 of file CodeGen.cpp.
|
private |
Generate bytecode from While Statement.
Definition at line 714 of file CodeGen.cpp.
|
private |
Simple expression type inference (conservative).
| expr | expression to inspect |
| known | set to true when a type is known |
Definition at line 62 of file CodeGen.cpp.
|
private |
Check if expression is a compile-time literal.
Definition at line 23 of file CodeGen.cpp.
|
inlineprivate |
Reset register allocator.
Definition at line 295 of file CodeGen.hpp.
|
private |
Definition at line 344 of file CodeGen.hpp.
|
private |
Generated bytecode.
Definition at line 258 of file CodeGen.hpp.
|
private |
Definition at line 345 of file CodeGen.hpp.
|
private |
Definition at line 261 of file CodeGen.hpp.
|
private |
REPL mode.
Definition at line 259 of file CodeGen.hpp.
|
private |
Definition at line 343 of file CodeGen.hpp.
|
private |
Next available register.
Definition at line 264 of file CodeGen.hpp.
|
private |
Track which registers are in use.
Definition at line 265 of file CodeGen.hpp.