Compare commits

..

No commits in common. "0edbc46aa0297b18b5b15a749f744bee805d02ae" and "b3bdc41a3ebc198f7d99b96bbf44aaea41159ec9" have entirely different histories.

3 changed files with 20 additions and 59 deletions

View file

@ -1,6 +1,9 @@
i := 0; i := 0x0;
while i < 10 { if i > 10 {
i = i + 1; print "a";
print; } else if i > 5 {
print "b";
} else {
print "c";
} }

View file

@ -62,7 +62,10 @@ fn test_expression(expr: &str) {
} }
fn main() -> Result<()> { fn main() -> Result<()> {
/*
let module = frontend::Module::from_file("./demo.lang")?; let module = frontend::Module::from_file("./demo.lang")?;
module.execute(); module.execute();
*/
test_expression("(a: b) -> c {}");
Ok(()) Ok(())
} }

View file

@ -1,5 +1,3 @@
use crate::Expression;
use super::err::*; use super::err::*;
macro_rules! primitives { macro_rules! primitives {
@ -48,12 +46,15 @@ impl Primitive {
match (a, b) { match (a, b) {
// Whole? coerces to any whole or integer // Whole? coerces to any whole or integer
(whole_ambiguous, w @ (w8 | w16 | w32 | w64 | i8 | i16 | i32 | i64)) (whole_ambiguous, w @ (w8 | w16 | w32 | w64 | i8 | i16 | i32 | i64))
| (w @ (w8 | w16 | w32 | w64 | i8 | i16 | i32 | i64), whole_ambiguous) => Ok(w), | (w @ (w8 | w16 | w32 | w64 | i8 | i16 | i32 | i64), whole_ambiguous) => {
w
},
// Integer? coerces to any integer // Integer? coerces to any integer
(integer_ambiguous, i @ (i8 | i16 | i32 | i64)) (integer_ambiguous, i @ (i8 | i16 | i32 | i64))
| (i @ (i8 | i16 | i32 | i64), integer_ambiguous) => Ok(i), | (i @ (i8 | i16 | i32 | i64), integer_ambiguous) => i,
_ => error(), _ => whole_ambiguous,
} };
todo!()
} }
} }
@ -85,52 +86,6 @@ 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<Expression>,
type_: Type,
},
Immutable {
name: String,
value: Expression,
type_: Type,
},
Struct {
name: String,
},
BlockStart,
}
#[derive(Debug, Clone)]
pub struct SymbolTable {
stack: Vec<Symbol>,
}
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;
}
}
}
}