Minor refactor + fix minor oopsie

This commit is contained in:
Mattia Giambirtone 2023-06-28 17:33:48 +02:00
parent f0ae805773
commit 6979d0316f
Signed by: nocturn9x
GPG Key ID: 8270F9F467971E59
1 changed files with 22 additions and 21 deletions

View File

@ -247,14 +247,14 @@ method unary*(self: Compiler, node: UnaryExpr, compile: bool = true): Type {.dis
method binary*(self: Compiler, node: BinaryExpr, compile: bool = true): Type {.discardable, base.} = nil
method lambdaExpr*(self: Compiler, node: LambdaExpr, compile: bool = true): Type {.discardable, base.} = nil
method literal*(self: Compiler, node: ASTNode, compile: bool = true): Type {.discardable, base.} = nil
method infer*(self: Compiler, node: LiteralExpr): Type
method infer*(self: Compiler, node: Expression): Type
method inferOrError*(self: Compiler, node: Expression): Type
method findByName*(self: Compiler, name: string): seq[Name]
method findInModule*(self: Compiler, name: string, module: Name): seq[Name]
method findByType*(self: Compiler, name: string, kind: Type): seq[Name]
method compare*(self: Compiler, a, b: Type): bool
method match*(self: Compiler, name: string, kind: Type, node: ASTNode = nil, allowFwd: bool = true): Name
proc infer*(self: Compiler, node: LiteralExpr): Type
proc infer*(self: Compiler, node: Expression): Type
proc inferOrError*(self: Compiler, node: Expression): Type
proc findByName*(self: Compiler, name: string): seq[Name]
proc findInModule*(self: Compiler, name: string, module: Name): seq[Name]
proc findByType*(self: Compiler, name: string, kind: Type): seq[Name]
proc compare*(self: Compiler, a, b: Type): bool
proc match*(self: Compiler, name: string, kind: Type, node: ASTNode = nil, allowFwd: bool = true): Name
method prepareFunction*(self: Compiler, name: Name) {.base.} = discard
method dispatchPragmas(self: Compiler, name: Name) {.base.} = discard
method dispatchDelayedPragmas(self: Compiler, name: Name) {.base.} = discard
@ -417,7 +417,7 @@ proc compareUnions*(self: Compiler, a, b: seq[tuple[match: bool, kind: Type]]):
return i >= short.len()
method compare*(self: Compiler, a, b: Type): bool =
proc compare*(self: Compiler, a, b: Type): bool =
## Compares two type objects
## for equality
result = false
@ -462,14 +462,14 @@ method compare*(self: Compiler, a, b: Type): bool =
return false
var i = 0
for (argA, argB) in zip(a.args, b.args):
if not self.compare(argA.kind, argB.kind):
return false
if argA.name == "":
continue
if argB.name == "":
continue
if argA.name != argB.name:
return false
if not self.compare(argA.kind, argB.kind):
return false
if a.forwarded or b.forwarded:
# We need to be more strict when checking forward
# declarations
@ -569,7 +569,7 @@ proc toIntrinsic*(name: string): Type =
return Type(kind: String)
method infer*(self: Compiler, node: LiteralExpr): Type =
proc infer*(self: Compiler, node: LiteralExpr): Type =
## Infers the type of a given literal expression
if node.isNil():
return nil
@ -602,7 +602,7 @@ method infer*(self: Compiler, node: LiteralExpr): Type =
discard # Unreachable
method infer*(self: Compiler, node: Expression): Type =
proc infer*(self: Compiler, node: Expression): Type =
## Infers the type of a given expression and
## returns it
if node.isNil():
@ -636,7 +636,7 @@ method infer*(self: Compiler, node: Expression): Type =
discard # TODO
method inferOrError*(self: Compiler, node: Expression): Type =
proc inferOrError*(self: Compiler, node: Expression): Type =
## Attempts to infer the type of
## the given expression and raises an
## error if it fails
@ -645,7 +645,7 @@ method inferOrError*(self: Compiler, node: Expression): Type =
self.error("expression has no type", node)
method stringify*(self: Compiler, typ: Type): string =
proc stringify*(self: Compiler, typ: Type): string =
## Returns the string representation of a
## type object
if typ.isNil():
@ -717,7 +717,7 @@ method stringify*(self: Compiler, typ: Type): string =
discard
method findByName*(self: Compiler, name: string): seq[Name] =
proc findByName*(self: Compiler, name: string): seq[Name] =
## Looks for objects that have been already declared
## with the given name. Returns all objects that apply.
for obj in reversed(self.names):
@ -728,7 +728,7 @@ method findByName*(self: Compiler, name: string): seq[Name] =
result.add(obj)
method findInModule*(self: Compiler, name: string, module: Name): seq[Name] =
proc findInModule*(self: Compiler, name: string, module: Name): seq[Name] =
## Looks for objects that have been already declared as
## public within the given module with the given name.
## Returns all objects that apply. If the name is an
@ -748,7 +748,7 @@ method findInModule*(self: Compiler, name: string, module: Name): seq[Name] =
result.add(obj)
method findByType*(self: Compiler, name: string, kind: Type): seq[Name] =
proc findByType*(self: Compiler, name: string, kind: Type): seq[Name] =
## Looks for objects that have already been declared
## with the given name and type. Returns all objects
## that apply
@ -757,7 +757,7 @@ method findByType*(self: Compiler, name: string, kind: Type): seq[Name] =
result.add(obj)
method findAtDepth*(self: Compiler, name: string, depth: int): seq[Name] {.used.} =
proc findAtDepth*(self: Compiler, name: string, depth: int): seq[Name] {.used.} =
## Looks for objects that have been already declared
## with the given name at the given scope depth.
## Returns all objects that apply
@ -796,7 +796,7 @@ proc isAny*(typ: Type): bool =
return false
method match*(self: Compiler, name: string, kind: Type, node: ASTNode = nil, allowFwd: bool = true): Name =
proc match*(self: Compiler, name: string, kind: Type, node: ASTNode = nil, allowFwd: bool = true): Name =
## Tries to find a matching function implementation
## compatible with the given type and returns its
## name object
@ -829,6 +829,7 @@ method match*(self: Compiler, name: string, kind: Type, node: ASTNode = nil, all
msg = &"call to undefined function '{name}'"
self.error(msg, node)
elif impl.len() > 1:
echo "AAAAAA\n\n"
# If we happen to find more than one match, we try again
# and ignore forward declarations and automatic functions
impl = filterIt(impl, not it.valueType.forwarded and not it.valueType.isAuto)
@ -859,7 +860,7 @@ proc beginScope*(self: Compiler) =
proc unpackTypes*(self: Compiler, condition: Expression, list: var seq[tuple[match: bool, kind: Type]], accept: bool = true) =
## Recursively unpacks a type constraint in a generic type
## Recursively unpacks a type constraint
case condition.kind:
of identExpr:
var typ = self.inferOrError(condition)