diff --git a/[ b/[ new file mode 100644 index 0000000..183df37 --- /dev/null +++ b/[ @@ -0,0 +1,24 @@ +mod namespace; +pub use namespace::*; + +use super::Id; + +pub struct Fn { + pub body: Body, +} + +pub struct Body { + pub statements: Vec, +} + +pub struct Statement { + ty: StatementTy, +} + +pub enum StatementTy { + Define, + Assign, + Call { target: VarId, args: VarId }, +} + +pub type VarId = usize; diff --git a/src/ir/id.rs b/src/ir/id.rs index 7ff7bec..791462e 100644 --- a/src/ir/id.rs +++ b/src/ir/id.rs @@ -44,10 +44,7 @@ impl Default for IdVec { impl Clone for Id { fn clone(&self) -> Self { - Self { - idx: self.idx.clone(), - _pd: self._pd.clone(), - } + *self } } diff --git a/src/ir/structs/mod.rs b/src/ir/structs/mod.rs index 530afd3..22a9d66 100644 --- a/src/ir/structs/mod.rs +++ b/src/ir/structs/mod.rs @@ -4,4 +4,39 @@ pub use namespace::*; use super::Id; pub struct Fn { + pub body: Body, } + +pub struct Body { + pub statements: Vec, +} + +pub struct Statement { + ty: StatementTy, +} + +pub enum StatementTy { + Define, + Assign { + target: VarId, + ty: TypeId, + val: VarId, + }, + Call { + target: VarId, + args: Vec, + }, +} + +pub struct Var { + const_: bool, + ty: TypeId, +} + +pub enum Type { + Unsigned(u8), + Signed(u8), +} + +pub type VarId = u32; +pub type TypeId = u32; diff --git a/src/parser_ir/mod.rs b/src/parser_ir/mod.rs index e65798f..3cb5c70 100644 --- a/src/parser_ir/mod.rs +++ b/src/parser_ir/mod.rs @@ -18,9 +18,9 @@ pub fn parse_program(path: impl AsRef, output: &mut CompilerOutput) -> Opt imports.done.insert(next.clone()); let path = dir.join(next + ".lang"); println!("=== {path:?}"); - let root = parse_file(path, output)?; - print!("{}", root.new_dsp()); - let defs = scan(&mut imports, &root, output); + let body = parse_file(path, output)?; + print!("{}", body.new_dsp()); + let defs = scan(&mut imports, &body, output); for (name, spans) in &defs.duplicates { output.error(CompilerMsg { msg: format!("Multiple definitions found for {name}"), diff --git a/test/main.lang b/test/main.lang index 2b1a365..1ddf40d 100644 --- a/test/main.lang +++ b/test/main.lang @@ -1,4 +1,4 @@ -x : i32 = 3; +x : u32 = 3; while true { print("hello"); print(x);