contents declaration

This commit is contained in:
Fernando Herrera 2021-09-25 17:28:15 +01:00
parent 6387401041
commit d9c42eb194
3 changed files with 10 additions and 0 deletions

View file

@ -67,6 +67,8 @@ pub fn create_default_context() -> Rc<RefCell<EngineState>> {
working_set.add_decl(sig.predeclare()); working_set.add_decl(sig.predeclare());
let sig = Signature::build("stack"); let sig = Signature::build("stack");
working_set.add_decl(sig.predeclare()); working_set.add_decl(sig.predeclare());
let sig = Signature::build("contents");
working_set.add_decl(sig.predeclare());
working_set.render() working_set.render()
}; };

View file

@ -113,6 +113,11 @@ impl EngineState {
} }
} }
pub fn print_contents(&self) {
let string = String::from_utf8_lossy(&self.file_contents);
println!("{}", string);
}
pub fn find_decl(&self, name: &[u8]) -> Option<DeclId> { pub fn find_decl(&self, name: &[u8]) -> Option<DeclId> {
for scope in self.scope.iter().rev() { for scope in self.scope.iter().rev() {
if let Some(decl_id) = scope.decls.get(name) { if let Some(decl_id) = scope.decls.get(name) {

View file

@ -102,6 +102,9 @@ fn main() -> Result<()> {
} else if s.trim() == "stack" { } else if s.trim() == "stack" {
stack.print_stack(); stack.print_stack();
continue; continue;
} else if s.trim() == "contents" {
engine_state.borrow().print_contents();
continue;
} }
let (block, delta) = { let (block, delta) = {