ir start
This commit is contained in:
@@ -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
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
@@ -1,4 +1,4 @@
|
||||
x : i32 = 3;
|
||||
x : u32 = 3;
|
||||
while true {
|
||||
print("hello");
|
||||
print(x);
|
||||
|
||||
Reference in New Issue
Block a user