![]() |
nsbaci 1.0
|
service for compiling nsbaci (or maybe other stuff in the future) source code. More...
#include <compilerService.h>
Public Member Functions | |
| CompilerService (std::unique_ptr< nsbaci::compiler::Compiler > c=std::make_unique< nsbaci::compiler::NsbaciCompiler >()) | |
| Constructs the CompilerService with a compiler implementation. | |
| ~CompilerService ()=default | |
| Default destructor. | |
| CompilerService (const CompilerService &)=delete | |
| CompilerService & | operator= (const CompilerService &)=delete |
| CompilerService (CompilerService &&)=default | |
| CompilerService & | operator= (CompilerService &&)=default |
| nsbaci::compiler::CompilerResult | compile (nsbaci::types::Text raw) |
| Compiles nsbaci source code into p-code instructions. | |
| bool | hasProgramReady () const |
| Checks if a compiled program is available for execution. | |
| nsbaci::compiler::InstructionStream | takeInstructions () |
| Retrieves and releases ownership of the compiled instructions. | |
| nsbaci::types::SymbolTable | takeSymbols () |
| Retrieves and releases ownership of the symbol table. | |
service for compiling nsbaci (or maybe other stuff in the future) source code.
The service functions like the following:
After taking the instructions, the program is no longer considered ready until a new successful compilation occurs.
Usage example:
| nsbaci::services::CompilerService::CompilerService | ( | std::unique_ptr< nsbaci::compiler::Compiler > | c = std::make_unique<nsbaci::compiler::NsbaciCompiler>() | ) |
Constructs the CompilerService with a compiler implementation.
By default, creates an NsbaciCompiler instance. Custom compiler implementations can be injected for testing or alternative language support.
| c | Unique pointer to a Compiler implementation. Defaults to NsbaciCompiler. |

| nsbaci::compiler::CompilerResult nsbaci::services::CompilerService::compile | ( | nsbaci::types::Text | raw | ) |
Compiles nsbaci source code into p-code instructions.
Passes the source code to the underlying compiler and stores the results if compilation succeeds. The compiled instructions and symbols can then be retrieved using takeInstructions() and takeSymbols().
| raw | The nsbaci source code to compile. |
| bool nsbaci::services::CompilerService::hasProgramReady | ( | ) | const |
Checks if a compiled program is available for execution.
Returns true after a successful compile() call and before takeInstructions() is called. Used to verify that valid instructions are available before attempting to load them into the runtime.
| nsbaci::compiler::InstructionStream nsbaci::services::CompilerService::takeInstructions | ( | ) |
Retrieves and releases ownership of the compiled instructions.
Moves the instruction stream out of the service. After this call, hasProgramReady() will return false until a new successful compilation.
| nsbaci::types::SymbolTable nsbaci::services::CompilerService::takeSymbols | ( | ) |
Retrieves and releases ownership of the symbol table.
Moves the symbol table out of the service. The symbol table contains information about all declared variables including names, types, and memory addresses.