pub mod value_visitor;
use crate::{
compiler::{
ast_node_to_instructions::AstNodeToInstructions,
compilation_result::CompilationResult,
error::CompilerError,
precompiler::precompiled_ast::{AstMetadata, RichAst},
scope::CompilationScope,
},
core_compiler::{
core_compilation_context::{
CompileInput, CoreCompilationContext, DXBWithSharedValues,
},
to_instructions::ToInstructions,
},
prelude::*,
runtime::{
cache::shared_references_cache::SharedReferencesCache,
execution::context::ExecutionMode,
},
values::value_container::ValueContainer,
};
pub struct CompilationContext<'a> {
pub core_context: CoreCompilationContext<'a>,
pub inserted_value_index: usize,
pub inserted_values: Vec<Option<ValueContainer>>,
pub has_non_static_value: bool,
pub execution_mode: ExecutionMode,
pub scope: CompilationScope,
}
impl<'a> CompilationContext<'a> {
pub fn new(
inserted_values: Vec<Option<ValueContainer>>,
execution_mode: ExecutionMode,
input: CompileInput<'a>,
scope: CompilationScope,
) -> Self {
CompilationContext {
inserted_value_index: 0,
core_context: CoreCompilationContext::new(input),
inserted_values,
has_non_static_value: false,
execution_mode, scope,
}
}
pub fn compile_to_dxb_with_shared_values(
self,
input: &impl ToInstructions,
cache: &mut SharedReferencesCache,
) -> DXBWithSharedValues {
self.core_context
.compile_to_dxb_with_shared_values(input, cache)
}
pub fn compile_ast_node_to_dxb_with_shared_values(
mut self,
ast_node: &impl AstNodeToInstructions,
metadata: &mut AstMetadata,
cache: &mut SharedReferencesCache,
) -> Result<CompilationResult, CompilerError> {
let dxb = ast_node.try_compile_to_dxb(&mut self, cache, metadata)?;
Ok(CompilationResult {
dxb_with_shared_values: self
.core_context
.append_preamble_to_dxb(dxb, cache),
scope: self.scope,
has_non_static_value: self.has_non_static_value,
})
}
pub fn compile_ast_with_metadata_to_dxb_with_shared_values(
self,
rich_ast: RichAst,
cache: &mut SharedReferencesCache,
) -> Result<CompilationResult, CompilerError> {
self.compile_ast_node_to_dxb_with_shared_values(
&*rich_ast.ast.data,
&mut rich_ast.metadata.borrow_mut(),
cache,
)
}
pub fn core_context(&mut self) -> &mut CoreCompilationContext<'a> {
&mut self.core_context
}
pub fn mark_has_non_static_value(&mut self) {
self.has_non_static_value = true;
}
}