(lazily) codegen parsed expressions. v0.0.9 (rebase)

master
Araozu 2024-01-06 19:07:41 -05:00
parent 02f3c9aee6
commit eb3b755a3c
7 changed files with 39 additions and 7 deletions

View File

@ -15,11 +15,15 @@
- Watch mode
- Formatter
- Simple language server
- Decide how to handle comments in the syntax (?)
- Decide how to handle comments in the syntax (?)(should comments mean something like in rust?)
## v0.0.10
- [ ] Typecheck current AST
- [ ] Begin work on semantic analysis
- [ ] Symbol table
- [ ] Typecheck bindings
- [ ] Typecheck functions
- [ ] Transform simple THP expression into PHP statements
## v0.0.9
@ -27,7 +31,7 @@
- [x] Compile a single file
- [x] Display error messages during compilation instead of panicking
- [x] Improve error messages
- [ ] Implement code generation for ast nodes implemented as of now
- [x] Implement code generation for ast nodes implemented as of now

View File

@ -6,7 +6,7 @@ impl Transpilable for Binding {
fn transpile(&self) -> String {
let expression_str = self.expression.transpile();
format!("${} = {};", self.identifier, expression_str)
format!("${} = {}", self.identifier, expression_str)
}
}
@ -28,6 +28,6 @@ mod tests {
let result = binding.transpile();
assert_eq!("$identifier = 322;", result);
assert_eq!("$identifier = 322", result);
}
}

View File

@ -18,11 +18,21 @@ impl Transpilable for Expression {
Expression::Boolean(value) => String::from(if *value { "true" } else { "false" }),
Expression::Identifier(value) => format!("{}", *value),
Expression::FunctionCall(f) => f.transpile(),
<<<<<<< HEAD
Expression::BinaryOperator(_, _, _) => {
todo!("BinaryOperator codegen is not implemented yet")
=======
Expression::BinaryOperator(left_expr, right_expr, operator) => {
format!(
"{}{}{}",
left_expr.transpile(),
operator,
right_expr.transpile()
)
>>>>>>> f71f9ab ((lazily) codegen parsed expressions. v0.0.9)
}
Expression::UnaryOperator(_, _) => {
todo!("UnaryOperator codegen is not implemented yet")
Expression::UnaryOperator(operator, expression) => {
format!("{}{}", operator, expression.transpile())
}
}
}

View File

@ -4,6 +4,10 @@ use super::Transpilable;
impl Transpilable for FunctionCall {
fn transpile(&self) -> String {
<<<<<<< HEAD
format!("{}();", self.function.transpile())
=======
format!("{}()", self.identifier)
>>>>>>> f71f9ab ((lazily) codegen parsed expressions. v0.0.9)
}
}

View File

@ -5,6 +5,7 @@ mod block;
mod expression;
mod function_call;
mod function_declaration;
mod function_call;
mod module_ast;
mod statement;
mod top_level_construct;

View File

@ -37,6 +37,10 @@ mod tests {
let result = module.transpile();
<<<<<<< HEAD
assert_eq!("<?php\n\n$identifier = 322;\n", result);
=======
assert_eq!("<?php\n\n$identifier = 322\n", result);
>>>>>>> f71f9ab ((lazily) codegen parsed expressions. v0.0.9)
}
}

View File

@ -4,9 +4,18 @@ use super::Transpilable;
impl Transpilable for Statement {
fn transpile(&self) -> String {
<<<<<<< HEAD
match self {
Statement::Binding(binding) => binding.transpile(),
Statement::FunctionCall(function_call) => function_call.transpile(),
}
=======
let stmt = match self {
Statement::FunctionCall(f) => f.transpile(),
Statement::Binding(b) => b.transpile(),
};
format!("{stmt};")
>>>>>>> f71f9ab ((lazily) codegen parsed expressions. v0.0.9)
}
}