(lazily) codegen parsed expressions. v0.0.9 (rebase)
This commit is contained in:
parent
02f3c9aee6
commit
eb3b755a3c
10
CHANGELOG.md
10
CHANGELOG.md
@ -15,11 +15,15 @@
|
|||||||
- Watch mode
|
- Watch mode
|
||||||
- Formatter
|
- Formatter
|
||||||
- Simple language server
|
- 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
|
## 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
|
## v0.0.9
|
||||||
|
|
||||||
@ -27,7 +31,7 @@
|
|||||||
- [x] Compile a single file
|
- [x] Compile a single file
|
||||||
- [x] Display error messages during compilation instead of panicking
|
- [x] Display error messages during compilation instead of panicking
|
||||||
- [x] Improve error messages
|
- [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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ impl Transpilable for Binding {
|
|||||||
fn transpile(&self) -> String {
|
fn transpile(&self) -> String {
|
||||||
let expression_str = self.expression.transpile();
|
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();
|
let result = binding.transpile();
|
||||||
|
|
||||||
assert_eq!("$identifier = 322;", result);
|
assert_eq!("$identifier = 322", result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,11 +18,21 @@ impl Transpilable for Expression {
|
|||||||
Expression::Boolean(value) => String::from(if *value { "true" } else { "false" }),
|
Expression::Boolean(value) => String::from(if *value { "true" } else { "false" }),
|
||||||
Expression::Identifier(value) => format!("{}", *value),
|
Expression::Identifier(value) => format!("{}", *value),
|
||||||
Expression::FunctionCall(f) => f.transpile(),
|
Expression::FunctionCall(f) => f.transpile(),
|
||||||
|
<<<<<<< HEAD
|
||||||
Expression::BinaryOperator(_, _, _) => {
|
Expression::BinaryOperator(_, _, _) => {
|
||||||
todo!("BinaryOperator codegen is not implemented yet")
|
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(_, _) => {
|
Expression::UnaryOperator(operator, expression) => {
|
||||||
todo!("UnaryOperator codegen is not implemented yet")
|
format!("{}{}", operator, expression.transpile())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,10 @@ use super::Transpilable;
|
|||||||
|
|
||||||
impl Transpilable for FunctionCall {
|
impl Transpilable for FunctionCall {
|
||||||
fn transpile(&self) -> String {
|
fn transpile(&self) -> String {
|
||||||
|
<<<<<<< HEAD
|
||||||
format!("{}();", self.function.transpile())
|
format!("{}();", self.function.transpile())
|
||||||
|
=======
|
||||||
|
format!("{}()", self.identifier)
|
||||||
|
>>>>>>> f71f9ab ((lazily) codegen parsed expressions. v0.0.9)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ mod block;
|
|||||||
mod expression;
|
mod expression;
|
||||||
mod function_call;
|
mod function_call;
|
||||||
mod function_declaration;
|
mod function_declaration;
|
||||||
|
mod function_call;
|
||||||
mod module_ast;
|
mod module_ast;
|
||||||
mod statement;
|
mod statement;
|
||||||
mod top_level_construct;
|
mod top_level_construct;
|
||||||
|
@ -37,6 +37,10 @@ mod tests {
|
|||||||
|
|
||||||
let result = module.transpile();
|
let result = module.transpile();
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
assert_eq!("<?php\n\n$identifier = 322;\n", result);
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,18 @@ use super::Transpilable;
|
|||||||
|
|
||||||
impl Transpilable for Statement {
|
impl Transpilable for Statement {
|
||||||
fn transpile(&self) -> String {
|
fn transpile(&self) -> String {
|
||||||
|
<<<<<<< HEAD
|
||||||
match self {
|
match self {
|
||||||
Statement::Binding(binding) => binding.transpile(),
|
Statement::Binding(binding) => binding.transpile(),
|
||||||
Statement::FunctionCall(function_call) => function_call.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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user