[fine] More test more!
This commit is contained in:
parent
2f8e1bad85
commit
257a7e64c2
2 changed files with 51 additions and 32 deletions
|
|
@ -653,6 +653,7 @@ impl<'a> Semantics<'a> {
|
||||||
TreeKind::LetStatement => Some(Type::Nothing),
|
TreeKind::LetStatement => Some(Type::Nothing),
|
||||||
TreeKind::ReturnStatement => Some(Type::Unreachable),
|
TreeKind::ReturnStatement => Some(Type::Unreachable),
|
||||||
TreeKind::ExpressionStatement => self.type_of_expression_statement(tree),
|
TreeKind::ExpressionStatement => self.type_of_expression_statement(tree),
|
||||||
|
TreeKind::IfStatement => self.type_of_if_statement(tree),
|
||||||
TreeKind::Identifier => self.type_of_identifier(t, tree),
|
TreeKind::Identifier => self.type_of_identifier(t, tree),
|
||||||
|
|
||||||
TreeKind::FunctionDecl => self.type_of_function_decl(tree),
|
TreeKind::FunctionDecl => self.type_of_function_decl(tree),
|
||||||
|
|
@ -1020,6 +1021,10 @@ impl<'a> Semantics<'a> {
|
||||||
Some(Type::Function(parameter_types, return_type))
|
Some(Type::Function(parameter_types, return_type))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn type_of_if_statement(&self, tree: &Tree) -> Option<Type> {
|
||||||
|
Some(self.type_of(tree.nth_tree(0)?))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn dump_compiler_state(&self, tr: Option<TreeRef>) {
|
pub fn dump_compiler_state(&self, tr: Option<TreeRef>) {
|
||||||
eprintln!("Parsed the tree as:");
|
eprintln!("Parsed the tree as:");
|
||||||
eprintln!("\n{}", self.syntax_tree.dump(true));
|
eprintln!("\n{}", self.syntax_tree.dump(true));
|
||||||
|
|
|
||||||
|
|
@ -1,51 +1,59 @@
|
||||||
if true { "discarded"; 23 } else { 45 }
|
fun test() {
|
||||||
|
if true { "discarded"; 23 } else { 45 }
|
||||||
|
}
|
||||||
|
|
||||||
// @no-errors
|
// @no-errors
|
||||||
// Here come some type probes!
|
// Here come some type probes!
|
||||||
// (type of the condition)
|
// (type of the condition)
|
||||||
// @type: 3 bool
|
// @type: 20 bool
|
||||||
//
|
//
|
||||||
// (the discarded expression)
|
// (the discarded expression)
|
||||||
// @type: 10 string
|
// @type: 27 string
|
||||||
//
|
//
|
||||||
// (the "then" clause)
|
// (the "then" clause)
|
||||||
// @type: 23 f64
|
// @type: 40 f64
|
||||||
// @type: 26 f64
|
// @type: 43 f64
|
||||||
//
|
//
|
||||||
// (the "else" clause)
|
// (the "else" clause)
|
||||||
// @type: 35 f64
|
// @type: 52 f64
|
||||||
// @type: 38 f64
|
// @type: 55 f64
|
||||||
//
|
|
||||||
// (the overall expression)
|
|
||||||
// @type: 0 f64
|
|
||||||
//
|
//
|
||||||
// @concrete:
|
// @concrete:
|
||||||
// | File
|
// | File
|
||||||
// | IfStatement
|
// | FunctionDecl
|
||||||
// | ConditionalExpression
|
// | Fun:'"fun"'
|
||||||
// | If:'"if"'
|
// | Identifier:'"test"'
|
||||||
// | LiteralExpression
|
// | ParamList
|
||||||
// | True:'"true"'
|
// | LeftParen:'"("'
|
||||||
// | Block
|
// | RightParen:'")"'
|
||||||
// | LeftBrace:'"{"'
|
// | Block
|
||||||
// | ExpressionStatement
|
// | LeftBrace:'"{"'
|
||||||
|
// | IfStatement
|
||||||
|
// | ConditionalExpression
|
||||||
|
// | If:'"if"'
|
||||||
// | LiteralExpression
|
// | LiteralExpression
|
||||||
// | String:'"\"discarded\""'
|
// | True:'"true"'
|
||||||
// | Semicolon:'";"'
|
// | Block
|
||||||
// | ExpressionStatement
|
// | LeftBrace:'"{"'
|
||||||
// | LiteralExpression
|
// | ExpressionStatement
|
||||||
// | Number:'"23"'
|
// | LiteralExpression
|
||||||
// | RightBrace:'"}"'
|
// | String:'"\"discarded\""'
|
||||||
// | Else:'"else"'
|
// | Semicolon:'";"'
|
||||||
// | Block
|
// | ExpressionStatement
|
||||||
// | LeftBrace:'"{"'
|
// | LiteralExpression
|
||||||
// | ExpressionStatement
|
// | Number:'"23"'
|
||||||
// | LiteralExpression
|
// | RightBrace:'"}"'
|
||||||
// | Number:'"45"'
|
// | Else:'"else"'
|
||||||
// | RightBrace:'"}"'
|
// | Block
|
||||||
|
// | LeftBrace:'"{"'
|
||||||
|
// | ExpressionStatement
|
||||||
|
// | LiteralExpression
|
||||||
|
// | Number:'"45"'
|
||||||
|
// | RightBrace:'"}"'
|
||||||
|
// | RightBrace:'"}"'
|
||||||
//
|
//
|
||||||
// @compiles-to:
|
// @compiles-to:
|
||||||
// | function << module >> (0 args, 0 locals):
|
// | function test (0 args, 0 locals):
|
||||||
// | strings (1):
|
// | strings (1):
|
||||||
// | 0: "discarded"
|
// | 0: "discarded"
|
||||||
// | code (8):
|
// | code (8):
|
||||||
|
|
@ -57,4 +65,10 @@ if true { "discarded"; 23 } else { 45 }
|
||||||
// | 5: Jump(7)
|
// | 5: Jump(7)
|
||||||
// | 6: PushFloat(45.0)
|
// | 6: PushFloat(45.0)
|
||||||
// | 7: Return
|
// | 7: Return
|
||||||
|
// | function << module >> (0 args, 0 locals):
|
||||||
|
// | strings (0):
|
||||||
|
// | code (2):
|
||||||
|
// | 0: PushNothing
|
||||||
|
// | 1: Return
|
||||||
// |
|
// |
|
||||||
|
// @eval: Float(23.0)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue