devalang_core/core/store/
function.rs1use crate::core::parser::statement::Statement;
2use std::collections::HashMap;
3
4#[derive(Debug, Clone)]
5pub struct FunctionDef {
6 pub name: String,
7 pub parameters: Vec<String>,
8 pub body: Vec<Statement>,
9}
10
11#[derive(Debug, Clone)]
12pub struct FunctionTable {
13 pub functions: HashMap<String, FunctionDef>,
14}
15
16impl Default for FunctionTable {
17 fn default() -> Self {
18 Self::new()
19 }
20}
21
22impl FunctionTable {
23 pub fn new() -> Self {
24 FunctionTable {
25 functions: HashMap::new(),
26 }
27 }
28
29 pub fn add_function(&mut self, function: FunctionDef) {
30 self.functions.insert(function.name.clone(), function);
31 }
32
33 pub fn get_function(&self, name: &str) -> Option<&FunctionDef> {
34 self.functions.get(name)
35 }
36
37 pub fn remove_function(&mut self, name: &str) -> Option<FunctionDef> {
38 self.functions.remove(name)
39 }
40}