nsbaci 1.0
Loading...
Searching...
No Matches
nsbaci::services::CompilerService Class Reference

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
CompilerServiceoperator= (const CompilerService &)=delete
 CompilerService (CompilerService &&)=default
CompilerServiceoperator= (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.

Detailed Description

service for compiling nsbaci (or maybe other stuff in the future) source code.

The service functions like the following:

  1. Call compile() with source code
  2. Check hasProgramReady() to verify success
  3. Call takeInstructions() and takeSymbols() to retrieve compiled data

After taking the instructions, the program is no longer considered ready until a new successful compilation occurs.

Usage example:

auto result = cs.compile(sourceCode);
if (result.ok && cs.hasProgramReady()) {
auto instructions = cs.takeInstructions();
auto symbols = cs.takeSymbols();
// Load into runtime...
}
CompilerService(std::unique_ptr< nsbaci::compiler::Compiler > c=std::make_unique< nsbaci::compiler::NsbaciCompiler >())
Constructs the CompilerService with a compiler implementation.
Definition compilerService.cpp:17
nsbaci::types::SymbolTable takeSymbols()
Retrieves and releases ownership of the symbol table.
Definition compilerService.cpp:55
nsbaci::compiler::InstructionStream takeInstructions()
Retrieves and releases ownership of the compiled instructions.
Definition compilerService.cpp:50
bool hasProgramReady() const
Checks if a compiled program is available for execution.
Definition compilerService.cpp:48
nsbaci::compiler::CompilerResult compile(nsbaci::types::Text raw)
Compiles nsbaci source code into p-code instructions.
Definition compilerService.cpp:20

Constructor & Destructor Documentation

◆ CompilerService()

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.

Parameters
cUnique pointer to a Compiler implementation. Defaults to NsbaciCompiler.
Here is the caller graph for this function:

Member Function Documentation

◆ compile()

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().

Parameters
rawThe nsbaci source code to compile.
Returns
CompilerResult containing success status and any compilation errors.

◆ hasProgramReady()

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.

Returns
True if compiled instructions are available, false otherwise.

◆ takeInstructions()

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.

Returns
The compiled instruction stream.
Warning
Only call when hasProgramReady() returns true.

◆ takeSymbols()

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.

Returns
The symbol table from the last successful compilation.

The documentation for this class was generated from the following files: