Skip to content

Commit

Permalink
added function bindings model
Browse files Browse the repository at this point in the history
  • Loading branch information
lexa-diky committed May 13, 2024
1 parent 74aa701 commit 56e007e
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/compiler/rst/compilation_context.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::compiler::cst::CstFile;
use crate::compiler::cst::{CstConstantStatement, CstEmitStatement, CstFile, CstFunctionStatement};
use std::collections::HashMap;
use std::path::PathBuf;

Expand All @@ -9,16 +9,24 @@ pub(crate) struct ConstantBinding {
pub(crate) byte_buffer: ByteBuffer,
}

pub(crate) struct FunctionBinding {
pub(crate) name: String,
pub(crate) byte_buffer: ByteBuffer,
pub(crate) sub_context: CompilationContext,
}

pub(crate) struct CompilationContext {
self_path: PathBuf,
constant_table: HashMap<String, ConstantBinding>,
function_table: HashMap<String, FunctionBinding>,
}

impl CompilationContext {
pub(crate) fn new(path: &PathBuf) -> CompilationContext {
return CompilationContext {
self_path: path.clone(),
constant_table: HashMap::new(),
function_table: HashMap::new(),
};
}

Expand All @@ -33,4 +41,16 @@ impl CompilationContext {
pub(crate) fn get_constant(&self, name: &String) -> Option<&ConstantBinding> {
return self.constant_table.get(name);
}

pub(crate) fn bind_function(&mut self, function: FunctionBinding) {
self.function_table.insert(function.name.clone(), function);
}

pub(crate) fn has_function(&self, name: &String) -> bool {
return self.function_table.contains_key(name);
}

pub(crate) fn get_function(&self, name: &String) -> Option<&FunctionBinding> {
return self.function_table.get(name);
}
}

0 comments on commit 56e007e

Please sign in to comment.