Compare commits

..

No commits in common. "1a5e3ef1d9644bce53191d5b630f2097ce209deb" and "ccb574166644ea5d09e5ed4489ece7462736f343" have entirely different histories.

14 changed files with 12 additions and 167 deletions

View File

@ -1,15 +0,0 @@
// Arithmetic, function calls and imports!
fn main() -> u32 {
for i in 0 to 10 {
print("hello")
}
let mut num = 0;
while num < 10 {
num = num + 1;
}
return num;
}

View File

@ -178,8 +178,6 @@ pub enum BlockLevelStatement {
}, },
Expression(Expression), Expression(Expression),
Return(ReturnType, Expression), Return(ReturnType, Expression),
ForLoop(String, TokenRange, Expression, Expression, Block),
WhileLoop(Expression, Block),
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]

View File

@ -231,10 +231,10 @@ impl Parse for PrimaryExpression {
stream.expect(Token::BracketClose)?; stream.expect(Token::BracketClose)?;
Expression(Kind::Array(expressions), stream.get_range().unwrap()) Expression(Kind::Array(expressions), stream.get_range().unwrap())
} }
_ => Err(stream.expecting_err("expression")?)?, _ => Err(stream.expected_err("expression inner")?)?,
} }
} else { } else {
Err(stream.expecting_err("expression")?)? Err(stream.expected_err("expression")?)?
}; };
while let Ok(index) = stream.parse::<ValueIndex>() { while let Ok(index) = stream.parse::<ValueIndex>() {
@ -667,14 +667,6 @@ impl Parse for BlockLevelStatement {
stream.expect(Token::Semi)?; stream.expect(Token::Semi)?;
Stmt::Return(ReturnType::Hard, exp) Stmt::Return(ReturnType::Hard, exp)
} }
Some(Token::For) => {
let for_stmt = stream.parse::<ForStatement>()?;
Stmt::ForLoop(for_stmt.0, for_stmt.1, for_stmt.2, for_stmt.3, for_stmt.4)
}
Some(Token::While) => {
let while_stmt = stream.parse::<WhileStatement>()?;
Stmt::WhileLoop(while_stmt.0, while_stmt.1)
}
_ => { _ => {
if let Ok(SetStatement(ident, expr, range)) = stream.parse() { if let Ok(SetStatement(ident, expr, range)) = stream.parse() {
Stmt::Set(ident, expr, range) Stmt::Set(ident, expr, range)
@ -691,35 +683,6 @@ impl Parse for BlockLevelStatement {
} }
} }
#[derive(Debug)]
pub struct ForStatement(String, TokenRange, Expression, Expression, Block);
#[derive(Debug)]
pub struct WhileStatement(Expression, Block);
impl Parse for ForStatement {
fn parse(mut stream: TokenStream) -> Result<Self, Error> {
stream.expect(Token::For)?;
let Some(Token::Identifier(idx)) = stream.next() else {
return Err(stream.expected_err("loop counter")?);
};
let start_range = stream.get_range().unwrap();
stream.expect(Token::In)?;
let start = stream.parse()?;
stream.expect(Token::To)?;
let end = stream.parse()?;
Ok(ForStatement(idx, start_range, start, end, stream.parse()?))
}
}
impl Parse for WhileStatement {
fn parse(mut stream: TokenStream) -> Result<Self, Error> {
stream.expect(Token::While)?;
Ok(WhileStatement(stream.parse()?, stream.parse()?))
}
}
#[derive(Debug)] #[derive(Debug)]
pub struct SetStatement(Expression, Expression, TokenRange); pub struct SetStatement(Expression, Expression, TokenRange);

View File

@ -3,8 +3,8 @@ use std::path::PathBuf;
use crate::{ use crate::{
ast::{self}, ast::{self},
mir::{ mir::{
self, CustomTypeKey, ForStatement, ModuleMap, NamedVariableRef, SourceModuleId, StmtKind, self, CustomTypeKey, ModuleMap, NamedVariableRef, SourceModuleId, StmtKind, StructField,
StructField, StructType, WhileStatement, StructType,
}, },
}; };
@ -148,28 +148,6 @@ impl ast::Block {
ast::BlockLevelStatement::Return(_, e) => { ast::BlockLevelStatement::Return(_, e) => {
(StmtKind::Expression(e.process(module_id)), e.1) (StmtKind::Expression(e.process(module_id)), e.1)
} }
ast::BlockLevelStatement::ForLoop(counter, counter_range, start, end, block) => (
StmtKind::For(ForStatement {
counter: NamedVariableRef(
mir::TypeKind::Vague(mir::VagueType::Unknown),
counter.clone(),
counter_range.as_meta(module_id),
),
start: start.process(module_id),
end: end.process(module_id),
block: block.into_mir(module_id),
meta: self.2.as_meta(module_id),
}),
self.2,
),
ast::BlockLevelStatement::WhileLoop(expression, block) => (
StmtKind::While(WhileStatement {
condition: expression.process(module_id),
block: block.into_mir(module_id),
meta: self.2.as_meta(module_id),
}),
self.2,
),
}; };
mir_statements.push(mir::Statement(kind, range.as_meta(module_id))); mir_statements.push(mir::Statement(kind, range.as_meta(module_id)));

View File

@ -598,8 +598,6 @@ impl mir::Statement {
} }
mir::StmtKind::Import(_) => todo!(), mir::StmtKind::Import(_) => todo!(),
mir::StmtKind::Expression(expression) => expression.codegen(scope, state), mir::StmtKind::Expression(expression) => expression.codegen(scope, state),
mir::StmtKind::For(for_statement) => todo!(),
mir::StmtKind::While(while_statement) => todo!(),
} }
} }
} }

View File

@ -42,16 +42,6 @@ pub enum Token {
Extern, Extern,
/// `struct` /// `struct`
Struct, Struct,
/// `while`
While,
/// `for`
For,
/// `from`
From,
/// `to`
To,
/// `to`
In,
// Symbols // Symbols
/// `;` /// `;`
@ -146,11 +136,6 @@ impl ToString for Token {
Token::Extern => String::from("extern"), Token::Extern => String::from("extern"),
Token::Struct => String::from("struct"), Token::Struct => String::from("struct"),
Token::AsKeyword => String::from("as"), Token::AsKeyword => String::from("as"),
Token::For => String::from("for"),
Token::From => String::from("from"),
Token::In => String::from("in"),
Token::To => String::from("to"),
Token::While => String::from("while"),
Token::Semi => String::from(';'), Token::Semi => String::from(';'),
Token::Equals => String::from('='), Token::Equals => String::from('='),
Token::Colon => String::from(':'), Token::Colon => String::from(':'),
@ -337,11 +322,6 @@ pub fn tokenize<T: Into<String>>(to_tokenize: T) -> Result<Vec<FullToken>, Error
"pub" => Token::PubKeyword, "pub" => Token::PubKeyword,
"struct" => Token::Struct, "struct" => Token::Struct,
"as" => Token::AsKeyword, "as" => Token::AsKeyword,
"for" => Token::For,
"while" => Token::While,
"in" => Token::In,
"from" => Token::From,
"to" => Token::To,
_ => Token::Identifier(value), _ => Token::Identifier(value),
}; };
variant variant

View File

@ -112,9 +112,6 @@ pub fn compile_module<'map>(
is_main, is_main,
}; };
#[cfg(debug_assertions)]
dbg!(&ast_module);
Ok(ast_module.process(module_id)) Ok(ast_module.process(module_id))
} }

View File

@ -147,7 +147,7 @@ impl Display for Statement {
impl Display for StmtKind { impl Display for StmtKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self { match self {
StmtKind::Let(var, mutable, block) => { Self::Let(var, mutable, block) => {
write!( write!(
f, f,
"let{} {} = {}", "let{} {} = {}",
@ -156,26 +156,9 @@ impl Display for StmtKind {
block block
) )
} }
StmtKind::Set(var, expr) => write!(f, "{} = {}", var, expr), Self::Set(var, expr) => write!(f, "{} = {}", var, expr),
StmtKind::Import(n) => write!(f, "import {}", n), Self::Import(n) => write!(f, "import {}", n),
StmtKind::Expression(exp) => Display::fmt(exp, f), Self::Expression(exp) => Display::fmt(exp, f),
StmtKind::For(for_statement) => {
write!(
f,
"for {} in {} to {} {}",
for_statement.counter,
for_statement.start,
for_statement.end,
for_statement.block
)
}
StmtKind::While(while_statement) => {
write!(
f,
"while {} {}",
while_statement.condition, while_statement.block,
)
}
} }
} }
} }

View File

@ -9,7 +9,6 @@ pub enum ReturnTypeOther {
NoBlockReturn(Metadata), NoBlockReturn(Metadata),
IndexingNonArray(Metadata), IndexingNonArray(Metadata),
DerefNonBorrow(Metadata), DerefNonBorrow(Metadata),
Loop,
} }
impl TypeKind { impl TypeKind {
@ -375,8 +374,6 @@ impl Statement {
), ),
Import(_) => todo!(), Import(_) => todo!(),
Expression(expression) => expression.return_type(refs, mod_id), Expression(expression) => expression.return_type(refs, mod_id),
For(_) => Err(ReturnTypeOther::Loop),
While(_) => Err(ReturnTypeOther::Loop),
} }
} }
@ -386,8 +383,6 @@ impl Statement {
StmtKind::Set(_, _) => None, StmtKind::Set(_, _) => None,
StmtKind::Import(_) => None, StmtKind::Import(_) => None,
StmtKind::Expression(expr) => expr.backing_var(), StmtKind::Expression(expr) => expr.backing_var(),
StmtKind::For(_) => None,
StmtKind::While(_) => None,
} }
} }
} }

View File

@ -188,6 +188,7 @@ impl<'map> Pass for LinkerPass<'map> {
.borrow_mut(); .borrow_mut();
let func_name = unsafe { path.get_unchecked(1) }; let func_name = unsafe { path.get_unchecked(1) };
let imported_mod_name = imported.name.clone();
let Some(func) = imported.functions.iter_mut().find(|f| f.name == *func_name) let Some(func) = imported.functions.iter_mut().find(|f| f.name == *func_name)
else { else {

View File

@ -338,24 +338,6 @@ pub enum StmtKind {
Set(Expression, Expression), Set(Expression, Expression),
Import(Import), Import(Import),
Expression(Expression), Expression(Expression),
For(ForStatement),
While(WhileStatement),
}
#[derive(Debug)]
pub struct ForStatement {
pub counter: NamedVariableRef,
pub start: Expression,
pub end: Expression,
pub block: Block,
pub meta: Metadata,
}
#[derive(Debug)]
pub struct WhileStatement {
pub condition: Expression,
pub block: Block,
pub meta: Metadata,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]

View File

@ -390,19 +390,10 @@ impl Statement {
StmtKind::Set(_, expression) => { StmtKind::Set(_, expression) => {
expression.pass(pass, state, scope, mod_id)?; expression.pass(pass, state, scope, mod_id)?;
} }
StmtKind::Import(_) => {} StmtKind::Import(_) => {} // Never exists at this stage
StmtKind::Expression(expression) => { StmtKind::Expression(expression) => {
expression.pass(pass, state, scope, mod_id)?; expression.pass(pass, state, scope, mod_id)?;
} }
StmtKind::For(for_statement) => {
for_statement.start.pass(pass, state, scope, mod_id);
for_statement.end.pass(pass, state, scope, mod_id);
for_statement.block.pass(pass, state, scope, mod_id);
}
StmtKind::While(while_statement) => {
while_statement.condition.pass(pass, state, scope, mod_id);
while_statement.block.pass(pass, state, scope, mod_id);
}
} }
pass.stmt(self, PassState::from(state, scope, Some(mod_id)))?; pass.stmt(self, PassState::from(state, scope, Some(mod_id)))?;
@ -421,10 +412,8 @@ impl Statement {
.ok(); .ok();
} }
StmtKind::Set(_, _) => {} StmtKind::Set(_, _) => {}
StmtKind::Import(_) => {} StmtKind::Import(_) => {} // Never exists at this stage
StmtKind::Expression(_) => {} StmtKind::Expression(_) => {}
StmtKind::For(_) => {}
StmtKind::While(_) => {}
}; };
Ok(()) Ok(())
} }

View File

@ -323,7 +323,7 @@ impl Block {
None None
} }
StmtKind::Import(_) => todo!(), StmtKind::Import(_) => todo!(), // TODO
StmtKind::Expression(expression) => { StmtKind::Expression(expression) => {
let res = expression.typecheck(&mut state, &typerefs, None); let res = expression.typecheck(&mut state, &typerefs, None);
state.or_else(res, TypeKind::Void, expression.1); state.or_else(res, TypeKind::Void, expression.1);
@ -335,8 +335,6 @@ impl Block {
None None
} }
} }
StmtKind::For(for_statement) => todo!(),
StmtKind::While(while_statement) => todo!(),
}; };
if let Some((ReturnKind::Hard, _)) = ret { if let Some((ReturnKind::Hard, _)) = ret {

View File

@ -126,8 +126,6 @@ impl Block {
let expr_res = expr.infer_types(&mut state, &inner_refs); let expr_res = expr.infer_types(&mut state, &inner_refs);
state.ok(expr_res, expr.1); state.ok(expr_res, expr.1);
} }
StmtKind::For(for_statement) => todo!(),
StmtKind::While(while_statement) => todo!(),
}; };
} }