From bff36013fb1f14738efa56b3a98f49e8f3c508bc Mon Sep 17 00:00:00 2001 From: Logan Gatlin Date: Thu, 17 Oct 2024 17:12:32 -0500 Subject: [PATCH] Work on laptop --- demo.lang | 11 ++++----- src/main.rs | 3 --- src/types.rs | 65 ++++++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 59 insertions(+), 20 deletions(-) diff --git a/demo.lang b/demo.lang index 45a1565..790ccc9 100644 --- a/demo.lang +++ b/demo.lang @@ -1,9 +1,6 @@ -i := 0x0; +i := 0; -if i > 10 { - print "a"; -} else if i > 5 { - print "b"; -} else { - print "c"; +while i < 10 { + i = i + 1; + print; } diff --git a/src/main.rs b/src/main.rs index cb66d12..79e4c2f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -62,10 +62,7 @@ fn test_expression(expr: &str) { } fn main() -> Result<()> { - /* let module = frontend::Module::from_file("./demo.lang")?; module.execute(); - */ - test_expression("(a: b) -> c {}"); Ok(()) } diff --git a/src/types.rs b/src/types.rs index 4dc3a00..fb4e6f2 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,3 +1,5 @@ +use crate::{Expression, Parameter}; + use super::err::*; macro_rules! primitives { @@ -46,15 +48,12 @@ impl Primitive { match (a, b) { // Whole? coerces to any whole or integer (whole_ambiguous, w @ (w8 | w16 | w32 | w64 | i8 | i16 | i32 | i64)) - | (w @ (w8 | w16 | w32 | w64 | i8 | i16 | i32 | i64), whole_ambiguous) => { - w - }, + | (w @ (w8 | w16 | w32 | w64 | i8 | i16 | i32 | i64), whole_ambiguous) => Ok(w), // Integer? coerces to any integer (integer_ambiguous, i @ (i8 | i16 | i32 | i64)) - | (i @ (i8 | i16 | i32 | i64), integer_ambiguous) => i, - _ => whole_ambiguous, - }; - todo!() + | (i @ (i8 | i16 | i32 | i64), integer_ambiguous) => Ok(i), + _ => error(), + } } } @@ -86,6 +85,52 @@ macro_rules! all_selfsame { }; } -all_selfsame!( - w8, w16, w32, w64, whole, i8, i16, i32, i64, integer, r32, r64, real, string -); +all_selfsame!(w8, w16, w32, w64, whole, i8, i16, i32, i64, integer, r32, r64, real, string); + +#[derive(Debug, Clone)] +pub enum Type { + Ambiguous, + Empty, + Primitive(Primitive), + Struct(String), +} + +#[derive(Debug, Clone)] +pub enum Symbol { + Mutable { + name: String, + value: Option, + type_: Type, + }, + Immutable { + name: String, + value: Expression, + type_: Type, + }, + Struct { + name: String, + }, + BlockStart, +} + +#[derive(Debug, Clone)] +pub struct SymbolTable { + stack: Vec, +} + +impl SymbolTable { + pub fn define(&mut self, sym: Symbol) { + self.stack.push(sym); + } + pub fn start_block(&mut self) { + self.stack.push(Symbol::BlockStart); + } + + pub fn end_block(&mut self) { + while !self.stack.is_empty() { + if let Some(Symbol::BlockStart) = self.stack.pop() { + break; + } + } + } +}