pub struct LlirFunctionBuilder<'builder, 'ctx> {
ancestor: Option<&'builder LlirFunctionBuilder<'builder, 'ctx>>,
call_stack: CallStack<'builder>,
pub(crate) shared: SharedState,
block_id: BlockId,
nodes: PeepholeOptimizer,
pub(crate) builder: &'builder LlirBuilder<'ctx>,
pub(crate) pending_runtime_functions: FunctionBuilderRuntime,
contexts: &'ctx FxHashMap<MirContextId, MirContext>,
}
Fields§
§ancestor: Option<&'builder LlirFunctionBuilder<'builder, 'ctx>>
§call_stack: CallStack<'builder>
§block_id: BlockId
§nodes: PeepholeOptimizer
§builder: &'builder LlirBuilder<'ctx>
§pending_runtime_functions: FunctionBuilderRuntime
Stores function ids pending to be added to the runtime
contexts: &'ctx FxHashMap<MirContextId, MirContext>
Implementations§
source§impl<'builder, 'ctx> LlirFunctionBuilder<'builder, 'ctx>
impl<'builder, 'ctx> LlirFunctionBuilder<'builder, 'ctx>
pub fn new( ancestor: Option<&'builder LlirFunctionBuilder<'builder, 'ctx>>, state_ancestor: Option<SharedStateId>, call_stack: CallStack<'builder>, block_id: BlockId, builder: &'builder LlirBuilder<'ctx>, contexts: &'ctx FxHashMap<MirContextId, MirContext> ) -> Self
pub fn build(&mut self, context: &'ctx MirContext) -> Result<()>
sourcefn debug_print_stacktrace(&self)
fn debug_print_stacktrace(&self)
Prints the current compiler stacktrace for debugging purposes
fn get_compiled_context(&self, context_id: MirContextId) -> Option<BlockId>
fn get_function(&self, block_id: BlockId) -> Option<&Function>
sourcepub(crate) fn get_obj(&self, obj_id: MirObjectId) -> ObjectRef
pub(crate) fn get_obj(&self, obj_id: MirObjectId) -> ObjectRef
Gets an object in the current state or panics
sourcepub(crate) fn get_obj_opt(&self, obj_id: MirObjectId) -> Option<ObjectRef>
pub(crate) fn get_obj_opt(&self, obj_id: MirObjectId) -> Option<ObjectRef>
Tries to get an object in the current state
sourcepub(crate) fn get_obj_in<'a>(
&'a self,
obj_id: MirObjectId,
state: &'a SharedState
) -> Option<&CloneCell<ObjectRef>>
pub(crate) fn get_obj_in<'a>( &'a self, obj_id: MirObjectId, state: &'a SharedState ) -> Option<&CloneCell<ObjectRef>>
Gets an object in a specific SharedState
sourcefn get_state(&self, id: SharedStateId) -> &SharedState
fn get_state(&self, id: SharedStateId) -> &SharedState
This method looks up a state from the global states map. If the state is not available yet, it is looked up in the ancestor hierarchy.
pub(crate) fn _set_obj(&mut self, obj_id: MirObjectId, value: ObjectRef)
fn get_function_generics( &self, function_id: NativeFunctionId ) -> &FunctionGenerics<'ctx>
fn compile_context( &mut self, context_id: MirContextId, call_stack_frame: CallStackFrame, mode: EvaluationMode ) -> Result<(BlockId, ObjectRef)>
sourcefn force_compile_context(
&mut self,
context_id: MirContextId,
block_id: BlockId,
parameters: &[(MirObjectId, ObjectRef)],
call_stack_frame: CallStackFrame,
mode: EvaluationMode
) -> Result<(BlockId, ObjectRef)>
fn force_compile_context( &mut self, context_id: MirContextId, block_id: BlockId, parameters: &[(MirObjectId, ObjectRef)], call_stack_frame: CallStackFrame, mode: EvaluationMode ) -> Result<(BlockId, ObjectRef)>
Compiles any context, even if it is already compiled. Force compiling a context does not modify the state of this context (Except for maybe some id counters) Returns the generated function, the return value, and the accumulated state
fn handle_on_tick_functions(&mut self) -> Result<()>
fn handle_exported_functions(&mut self) -> Result<()>
sourcepub(crate) fn compile_null_function(
&mut self,
function_id: NativeFunctionId,
span: Span
) -> Result<BlockId>
pub(crate) fn compile_null_function( &mut self, function_id: NativeFunctionId, span: Span ) -> Result<BlockId>
Helper to compile a function that takes no parameters and returns null
sourcefn declare_obj(
&mut self,
target: MirObjectId,
value: ObjectRef,
target_span: Span
) -> Result<()>
fn declare_obj( &mut self, target: MirObjectId, value: ObjectRef, target_span: Span ) -> Result<()>
Sets an object, with comptime_update_allowed
set. This can be used for e.g. declarations
or for places where it is known that this operation is valid to be performed at compile time
fn set_obj( &mut self, target: MirObjectId, value: ObjectRef, target_span: Span, comptime_update_allowed: bool ) -> Result<()>
sourcefn promote_obj(
ctx: &mut FunctionContext<'_, '_, '_>
) -> Option<Result<ObjectRef>>
fn promote_obj( ctx: &mut FunctionContext<'_, '_, '_> ) -> Option<Result<ObjectRef>>
Tries to promote an object to the target
class and returns the promoted object in case of success.
target
must be a class object.
sourcefn verify_parameters(
&mut self,
function_id: NativeFunctionId,
parameters: &mut [ObjectRef],
call_span: Span
) -> Result<()>
fn verify_parameters( &mut self, function_id: NativeFunctionId, parameters: &mut [ObjectRef], call_span: Span ) -> Result<()>
Verifies that the given parameters
match the signature of a given function .
and performs automatic value promotion if supported by the type (e.g. ComptimeInt
-> Int
).
Returns a compile error if the parameters did not match the signature and value promotion was not possible.
fn call_builtin_function( &mut self, function: &ObjFunction, parameters: &[ObjectRef], self_value: Option<ObjectRef>, span: Span ) -> Result<ObjectRef>
fn copy_if_runtime(&mut self, obj: ObjectRef) -> ObjectRef
fn handle_node(&mut self, node: &'ctx MirNode) -> Result<()>
fn handle_branch(&mut self, branch: &Branch) -> Result<ObjectRef>
fn handle_static_branch( &mut self, branch: &Branch, condition: &ObjStaticBool ) -> Result<ObjectRef>
fn handle_dynamic_branch( &mut self, branch: &Branch, condition: &ObjBool ) -> Result<ObjectRef>
fn handle_primitive_declaration( &mut self, declaration: &'ctx PrimitiveDeclaration ) -> Result<()>
fn handle_variable_update( &mut self, variable_update: &VariableUpdate ) -> Result<()>
fn handle_property_update( &mut self, property_update: &PropertyUpdate ) -> Result<()>
fn handle_property_access( &mut self, property_access: &PropertyAccess ) -> Result<()>
fn handle_goto(&mut self, goto: &Goto) -> Result<()>
fn handle_module(&mut self, module: &MirModule) -> Result<ObjectRef>
fn handle_runtime_promotion( &mut self, runtime_promotion: &RuntimePromotion ) -> Result<()>
fn handle_runtime_copy(&mut self, runtime_copy: &RuntimeCopy) -> Result<()>
fn handle_function_call( &mut self, function_call: &FunctionCall ) -> Result<ObjectRef>
fn handle_native_function_call( &mut self, function_call: &FunctionCall, function: &ObjNativeFunction ) -> Result<ObjectRef>
fn call_native_function( &mut self, function_id: NativeFunctionId, is_fn_comptime: bool, parameters: Vec<ObjectRef>, self_value: Option<ObjectRef>, call_span: Span ) -> Result<ObjectRef>
sourcefn call_native_function_no_alias(
&mut self,
function_id: usize,
parameters: Vec<ObjectRef>,
call_span: Span
) -> Result<ObjectRef>
fn call_native_function_no_alias( &mut self, function_id: usize, parameters: Vec<ObjectRef>, call_span: Span ) -> Result<ObjectRef>
Calls a native function where it has been verified that its parameters cannot reference the same value
sourcefn compile_native_function(
&mut self,
function_id: NativeFunctionId,
parameters: &mut [ObjectRef],
call_span: Span
) -> Result<usize>
fn compile_native_function( &mut self, function_id: NativeFunctionId, parameters: &mut [ObjectRef], call_span: Span ) -> Result<usize>
Compiles function with function_id
.
Caller has to guarantee that the parameters don’t alias.
Return
The index of the monomorphized function
sourcefn monomorphize_native_function(
&mut self,
function_id: NativeFunctionId,
params: &[ObjectRef]
) -> Result<MonomorphizedFunction>
fn monomorphize_native_function( &mut self, function_id: NativeFunctionId, params: &[ObjectRef] ) -> Result<MonomorphizedFunction>
Compiles the function with the given parameters into a new block. It is executed with the specific parameters and an entry in the function instantiations gets created.
sourcefn monomorphize_raw(
&mut self,
function_id: usize,
parameters: &[(MirObjectId, ObjectRef)]
) -> Result<(BlockId, ObjectRef)>
fn monomorphize_raw( &mut self, function_id: usize, parameters: &[(MirObjectId, ObjectRef)] ) -> Result<(BlockId, ObjectRef)>
Actual monomorphization happening here Compiles the context of the function and assumes that all required parameters are set Returns the id of the generated block and the return value of the block