Compare commits
No commits in common. "0edbc46aa0297b18b5b15a749f744bee805d02ae" and "b3bdc41a3ebc198f7d99b96bbf44aaea41159ec9" have entirely different histories.
0edbc46aa0
...
b3bdc41a3e
11
demo.lang
11
demo.lang
|
@ -1,6 +1,9 @@
|
|||
i := 0;
|
||||
i := 0x0;
|
||||
|
||||
while i < 10 {
|
||||
i = i + 1;
|
||||
print;
|
||||
if i > 10 {
|
||||
print "a";
|
||||
} else if i > 5 {
|
||||
print "b";
|
||||
} else {
|
||||
print "c";
|
||||
}
|
||||
|
|
|
@ -62,7 +62,10 @@ fn test_expression(expr: &str) {
|
|||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
/*
|
||||
let module = frontend::Module::from_file("./demo.lang")?;
|
||||
module.execute();
|
||||
*/
|
||||
test_expression("(a: b) -> c {}");
|
||||
Ok(())
|
||||
}
|
||||
|
|
65
src/types.rs
65
src/types.rs
|
@ -1,5 +1,3 @@
|
|||
use crate::Expression;
|
||||
|
||||
use super::err::*;
|
||||
|
||||
macro_rules! primitives {
|
||||
|
@ -48,12 +46,15 @@ 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) => Ok(w),
|
||||
| (w @ (w8 | w16 | w32 | w64 | i8 | i16 | i32 | i64), whole_ambiguous) => {
|
||||
w
|
||||
},
|
||||
// Integer? coerces to any integer
|
||||
(integer_ambiguous, i @ (i8 | i16 | i32 | i64))
|
||||
| (i @ (i8 | i16 | i32 | i64), integer_ambiguous) => Ok(i),
|
||||
_ => error(),
|
||||
}
|
||||
| (i @ (i8 | i16 | i32 | i64), integer_ambiguous) => i,
|
||||
_ => 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);
|
||||
|
||||
#[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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
all_selfsame!(
|
||||
w8, w16, w32, w64, whole, i8, i16, i32, i64, integer, r32, r64, real, string
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue