Skip to content

Commit e0ad684

Browse files
committed
Adicionado Interpretador de Assert e Hashmap de Testes no Scope
Asserts executam no interpretador e retornam um Computation Continue caso passem ou Erro caso falhem. Environments podem armazenar declaração de testes (ainda a ser implementado pelo TestDef)
1 parent c3e2abb commit e0ad684

2 files changed

Lines changed: 349 additions & 0 deletions

File tree

src/environment/environment.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub struct Scope<A> {
99
pub variables: HashMap<Name, (bool, A)>,
1010
pub functions: HashMap<Name, Function>,
1111
pub adts: HashMap<Name, Vec<ValueConstructor>>,
12+
pub tests: HashMap<Name, Function>,
1213
}
1314

1415
impl<A: Clone> Scope<A> {
@@ -17,6 +18,7 @@ impl<A: Clone> Scope<A> {
1718
variables: HashMap::new(),
1819
functions: HashMap::new(),
1920
adts: HashMap::new(),
21+
tests: HashMap::new(),
2022
}
2123
}
2224

@@ -30,6 +32,11 @@ impl<A: Clone> Scope<A> {
3032
return ();
3133
}
3234

35+
fn map_test(&mut self, test: Function) -> () {
36+
self.tests.insert(test.name.clone(), test);
37+
return ();
38+
}
39+
3340
fn map_adt(&mut self, name: Name, adt: Vec<ValueConstructor>) -> () {
3441
self.adts.insert(name.clone(), adt);
3542
return ();
@@ -45,6 +52,10 @@ impl<A: Clone> Scope<A> {
4552
self.functions.get(name)
4653
}
4754

55+
fn lookup_test(&self, name: &Name) -> Option<&Function> {
56+
self.tests.get(name)
57+
}
58+
4859
fn lookup_adt(&self, name: &Name) -> Option<&Vec<ValueConstructor>> {
4960
self.adts.get(name)
5061
}
@@ -78,6 +89,13 @@ impl<A: Clone> Environment<A> {
7889
}
7990
}
8091

92+
pub fn map_test(&mut self, test: Function) -> () {
93+
match self.stack.front_mut() {
94+
None => self.globals.map_test(test),
95+
Some(top) => top.map_test(test),
96+
}
97+
}
98+
8199
pub fn map_adt(&mut self, name: Name, cons: Vec<ValueConstructor>) -> () {
82100
match self.stack.front_mut() {
83101
None => self.globals.map_adt(name, cons),
@@ -103,6 +121,15 @@ impl<A: Clone> Environment<A> {
103121
self.globals.lookup_function(name)
104122
}
105123

124+
pub fn lookup_test(&self, name: &Name) -> Option<&Function> {
125+
for scope in self.stack.iter() {
126+
if let Some(test) = scope.lookup_test(name) {
127+
return Some(test);
128+
}
129+
}
130+
self.globals.lookup_test(name)
131+
}
132+
106133
pub fn lookup_adt(&self, name: &Name) -> Option<&Vec<ValueConstructor>> {
107134
for scope in self.stack.iter() {
108135
if let Some(cons) = scope.lookup_adt(name) {

0 commit comments

Comments
 (0)