From 6a362119925cbcf7d14c7fa2a0d41c0745e86d92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edvard=20Th=C3=B6rnros?= Date: Mon, 1 Mar 2021 18:50:29 +0100 Subject: fixed everything with a clone! --- main.sy | 1 + src/compiler.rs | 12 ++++++++---- third.sy | 2 ++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/main.sy b/main.sy index e7c344d..2e21a69 100644 --- a/main.sy +++ b/main.sy @@ -9,4 +9,5 @@ start :: fn { other.third.print_the_third() third.print_the_third() + third.main.other.third.main.third.print_the_third() } diff --git a/src/compiler.rs b/src/compiler.rs index 5d8b2bd..df88c7d 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -331,7 +331,7 @@ impl CompilerContext { } } -#[derive(Debug)] +#[derive(Debug, Clone)] enum Name { Slot(usize, usize), Unknown(usize, usize), @@ -1051,21 +1051,25 @@ impl<'a, 'b> Compiler { if let Some(_) = self.find_namespace(&name) { self.eat(); - let mut name = name; + // TODO(ed): This is a clone I would love to get rid of... + let mut namespace = self.find_namespace(&name).unwrap().clone(); loop { if self.eat() != Token::Dot { error!(self, "Expect '.' after namespace."); return; } if let Token::Identifier(field) = self.eat() { - match self.find_namespace(&name).unwrap().get(&field) { + match namespace.get(&field) { Some(Name::Slot(slot, _)) | Some(Name::Unknown(slot, _)) => { add_op(self, block, Op::Constant(*slot)); self.call_maybe(block); return; } Some(Name::Namespace(inner_name)) => { - name = self.to_namespace(&inner_name); + namespace = self.contextes + .get(inner_name) + .unwrap().namespace + .clone(); } _ => { error!(self, "Invalid namespace field."); diff --git a/third.sy b/third.sy index 0477077..777dd6d 100644 --- a/third.sy +++ b/third.sy @@ -1,3 +1,5 @@ +use main + print_the_third :: fn { print "three" } -- cgit v1.2.1