diff options
| author | Edvard Thörnros <edvard.thornros@gmail.com> | 2021-02-28 19:10:27 +0100 |
|---|---|---|
| committer | Edvard Thörnros <edvard.thornros@gmail.com> | 2021-02-28 19:10:27 +0100 |
| commit | 2090888dce496f893638268b0aef981c96b68ac3 (patch) | |
| tree | 246dc16652c7b98e18bbe2b9d5820142d365f5e5 /src/compiler.rs | |
| parent | 630bd52c8d5a7d362066d8d05c88a1e76c6c81b1 (diff) | |
| download | sylt-2090888dce496f893638268b0aef981c96b68ac3.tar.gz | |
imports almost work
Diffstat (limited to 'src/compiler.rs')
| -rw-r--r-- | src/compiler.rs | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/src/compiler.rs b/src/compiler.rs index 984a666..339bd0f 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -1040,11 +1040,18 @@ impl<'a, 'b> Compiler { } fn variable_expression(&'b mut self, block: &mut Block) { - let name = match self.eat() { + let name = match self.peek() { Token::Identifier(name) => name, _ => unreachable!(), }; + if let Some(_) = self.find_namespace(&name) { + self.blob_field(block); + return; + } + + self.eat(); + // Global functions take precedence if let Some(slot) = self.find_extern_function(&name) { let string = self.add_constant(Value::ExternFunction(slot)); @@ -1432,22 +1439,8 @@ impl<'a, 'b> Compiler { _ => unreachable!(), }; if let Some(_) = self.find_namespace(&name) { - expect!(self, Token::Dot, "Expected '.' after namespace."); - if let Token::Identifier(ident) = self.eat() { - println!("{:#?}", self.find_namespace(&name)); - match self.find_namespace(&name).unwrap().get(&ident) { - Some(Name::Slot(slot, _)) | - Some(Name::Unknown(slot, _)) => { - add_op(self, block, Op::Constant(*slot)); - self.call_maybe(block); - } - _ => { - error!(self, format!("Cannot find constant '{}' in namespace '{}'.", ident, name)); - } - } - } else { - error!(self, "Expected identifier after namespace."); - } + error!(self, "Cannot treat namespace as blob."); + return; } else if let Some(var) = self.find_variable(&name) { self.mark_read(self.frames().len() - 1, &var); if var.upvalue { @@ -1569,8 +1562,9 @@ impl<'a, 'b> Compiler { } (Token::Identifier(_), Token::Dot, ..) => { - //parse_branch!(self, block, [self.blob_field(block), self.expression(block)]); - self.blob_field(block); + if !parse_branch!(self, block, self.blob_field(block)) { + self.expression(block); + } } (Token::Identifier(name), Token::Colon, ..) => { @@ -1659,6 +1653,7 @@ impl<'a, 'b> Compiler { for section in 0..self.sections.len() { self.init_section(section); let section = &self.sections[section]; + println!("SECTION: {:?} -- {:?}", section.path, section.tokens.first()); match (section.tokens.get(0), section.tokens.get(1), section.tokens.get(2)) { (Some((Token::Use, _)), Some((Token::Identifier(name), _)), ..) => { |
