in progress commit
- added vars to lib - fixed adders and getters to both vtable and ftable - made function operations a dual type (enum) - prototyped calling of stored external ASTs with arguments (additional operation type - stub for eval - added index function to Cell
This commit is contained in:
parent
61e3985592
commit
d2f60314f9
6 changed files with 162 additions and 54 deletions
38
src/vars.rs
38
src/vars.rs
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
use std::boxed::Box;
|
||||
use std::collections::HashMap;
|
||||
use crate::cell::{Ctr, Cell};
|
||||
use crate::cell::{Ctr};
|
||||
|
||||
/* Mapping between a string token and a tree of Cells
|
||||
* The string token can be found in any Ctr::Symbol value
|
||||
|
|
@ -25,23 +25,25 @@ use crate::cell::{Ctr, Cell};
|
|||
* Considerations: should I use a structure of cells for this?
|
||||
* Current thoughts: if this was a language without proper data types, yes.
|
||||
*/
|
||||
pub type VTable = HashMap<String, Cell>;
|
||||
pub type VTable = HashMap<String, Box<Ctr>>;
|
||||
|
||||
impl VTable {
|
||||
pub fn define(
|
||||
&mut self,
|
||||
identifier: String,
|
||||
var_tree: Box<Cell>
|
||||
) {
|
||||
if let Some(boxed_cell) = self.insert(identifier, var_tree) {
|
||||
drop(boxed_cell);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get(
|
||||
&self,
|
||||
identifier: String
|
||||
) -> Option<Box<Cell>> {
|
||||
self.get(identifier)
|
||||
pub fn define(
|
||||
vt: Box<VTable>,
|
||||
identifier: String,
|
||||
var_tree: Box<Ctr>
|
||||
) {
|
||||
if let Some(boxed_cell) = vt.insert(identifier, var_tree) {
|
||||
drop(boxed_cell);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get(
|
||||
vt: Box<VTable>,
|
||||
identifier: String
|
||||
) -> Option<Box<Ctr>> {
|
||||
if let Some(c) = vt.get(&identifier) {
|
||||
Some(*c)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue