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