added block expression

This commit is contained in:
Andrew Segavac
2021-05-29 11:01:34 -06:00
parent 374e080f26
commit 03fb361e0b
3 changed files with 9 additions and 2 deletions

View File

@@ -91,7 +91,7 @@ class VariableUsage:
@dataclass
class Expression:
expression: Union[LiteralInt, LiteralFloat, FunctionCall, VariableUsage, Operation]
expression: Union[LiteralInt, LiteralFloat, FunctionCall, "Block", VariableUsage, Operation]
type: TypeUsage
@@ -163,6 +163,7 @@ boring_grammar = r"""
| variable_usage
| function_call
| "(" expression ")"
| block
let_statement : "let" identifier "=" expression ";"
| "let" identifier ":" type_usage "=" expression ";"

View File

@@ -139,6 +139,10 @@ class TypeChecker:
if self.with_function_call(env, type_env, subexpression):
changed = True
return changed
if isinstance(subexpression, parse.Block):
if self.with_block(env, type_env, subexpression):
changed = True
return changed
if isinstance(subexpression, parse.VariableUsage):
if self.with_variable_usage(env, type_env, subexpression):
changed = True

View File

@@ -1,6 +1,8 @@
fn add(a: I32, b: I32): I32 {
let foo = 4;
let test_float: F32 = 10.2;
let test_float: F32 = {
10.2
};
a + b + foo
}