This commit is contained in:
2026-06-01 23:03:35 -04:00
parent 1d568f8ce3
commit c2a8c50a6d
5 changed files with 64 additions and 8 deletions
+24
View File
@@ -0,0 +1,24 @@
mod namespace;
pub use namespace::*;
use super::Id;
pub struct Fn {
pub body: Body,
}
pub struct Body {
pub statements: Vec<Statement>,
}
pub struct Statement {
ty: StatementTy,
}
pub enum StatementTy {
Define,
Assign,
Call { target: VarId, args: VarId },
}
pub type VarId = usize;
+1 -4
View File
@@ -44,10 +44,7 @@ impl<T> Default for IdVec<T> {
impl<T> Clone for Id<T> {
fn clone(&self) -> Self {
Self {
idx: self.idx.clone(),
_pd: self._pd.clone(),
}
*self
}
}
+35
View File
@@ -4,4 +4,39 @@ pub use namespace::*;
use super::Id;
pub struct Fn {
pub body: Body,
}
pub struct Body {
pub statements: Vec<Statement>,
}
pub struct Statement {
ty: StatementTy,
}
pub enum StatementTy {
Define,
Assign {
target: VarId,
ty: TypeId,
val: VarId,
},
Call {
target: VarId,
args: Vec<VarId>,
},
}
pub struct Var {
const_: bool,
ty: TypeId,
}
pub enum Type {
Unsigned(u8),
Signed(u8),
}
pub type VarId = u32;
pub type TypeId = u32;
+3 -3
View File
@@ -18,9 +18,9 @@ pub fn parse_program(path: impl AsRef<Path>, 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}"),
+1 -1
View File
@@ -1,4 +1,4 @@
x : i32 = 3;
x : u32 = 3;
while true {
print("hello");
print(x);