Fixed inference of unary and binary operators
This commit is contained in:
parent
cc49cb98a6
commit
3fba30b8ac
|
@ -589,6 +589,8 @@ proc inferType(self: Compiler, node: LiteralExpr): Type =
|
|||
else:
|
||||
discard # TODO
|
||||
|
||||
proc matchImpl(self: Compiler, name: string, kind: Type): Name
|
||||
|
||||
|
||||
proc inferType(self: Compiler, node: Expression): Type =
|
||||
## Infers the type of a given expression and
|
||||
|
@ -604,15 +606,11 @@ proc inferType(self: Compiler, node: Expression): Type =
|
|||
else:
|
||||
result = node.name.lexeme.toIntrinsic()
|
||||
of unaryExpr:
|
||||
let f = self.inferType(newIdentExpr(UnaryExpr(node).operator))
|
||||
if f.isNil():
|
||||
return f
|
||||
return f.returnType
|
||||
let node = UnaryExpr(node)
|
||||
return self.matchImpl(node.operator.lexeme, Type(kind: Function, returnType: Type(kind: Any), args: @[("", self.inferType(node.a))])).valueType.returnType
|
||||
of binaryExpr:
|
||||
let f = self.inferType(newIdentExpr(BinaryExpr(node).operator))
|
||||
if f.isNil():
|
||||
return f
|
||||
return f.returnType
|
||||
let node = BinaryExpr(node)
|
||||
return self.matchImpl(node.operator.lexeme, Type(kind: Function, returnType: Type(kind: Any), args: @[("", self.inferType(node.a)), ("", self.inferType(node.b))])).valueType.returnType
|
||||
of {intExpr, hexExpr, binExpr, octExpr,
|
||||
strExpr, falseExpr, trueExpr, infExpr,
|
||||
nanExpr, floatExpr, nilExpr
|
||||
|
@ -1333,6 +1331,7 @@ proc checkCallIsPure(self: Compiler, node: ASTnode): bool =
|
|||
|
||||
proc callExpr(self: Compiler, node: CallExpr): Name {.discardable.} =
|
||||
## Compiles code to call a function
|
||||
echo node
|
||||
var args: seq[tuple[name: string, kind: Type]] = @[]
|
||||
var argExpr: seq[Expression] = @[]
|
||||
var kind: Type
|
||||
|
@ -1340,6 +1339,7 @@ proc callExpr(self: Compiler, node: CallExpr): Name {.discardable.} =
|
|||
# TODO: Keyword arguments
|
||||
for i, argument in node.arguments.positionals:
|
||||
kind = self.inferType(argument)
|
||||
echo argument
|
||||
if kind.isNil():
|
||||
if argument.kind == identExpr:
|
||||
self.error(&"reference to undeclared name '{IdentExpr(argument).name.lexeme}'")
|
||||
|
|
Loading…
Reference in New Issue