Renamed compareTypes to compare
This commit is contained in:
parent
c168d1584b
commit
807b48bac9
|
@ -212,7 +212,7 @@ proc infer(self: Compiler, node: LiteralExpr): Type
|
|||
proc infer(self: Compiler, node: Expression): Type
|
||||
proc findByName(self: Compiler, name: string): seq[Name]
|
||||
proc findByType(self: Compiler, name: string, kind: Type, depth: int = -1): seq[Name]
|
||||
proc compareTypes(self: Compiler, a, b: Type): bool
|
||||
proc compare(self: Compiler, a, b: Type): bool
|
||||
proc patchReturnAddress(self: Compiler, pos: int)
|
||||
proc handleMagicPragma(self: Compiler, pragma: Pragma, node: ASTnode)
|
||||
proc handlePurePragma(self: Compiler, pragma: Pragma, node: ASTnode)
|
||||
|
@ -519,7 +519,7 @@ proc resolve(self: Compiler, name: string,
|
|||
|
||||
|
||||
|
||||
proc compareTypes(self: Compiler, a, b: Type): bool =
|
||||
proc compare(self: Compiler, a, b: Type): bool =
|
||||
## Compares two type objects
|
||||
## for equality (works with nil!)
|
||||
# The nil code here is for void functions (when
|
||||
|
@ -559,15 +559,15 @@ proc compareTypes(self: Compiler, a, b: Type): bool =
|
|||
# a and b are of either of the two
|
||||
# types in this branch, so we just need
|
||||
# to compare their values
|
||||
return self.compareTypes(a.value, b.value)
|
||||
return self.compare(a.value, b.value)
|
||||
of Function:
|
||||
# Functions are a bit trickier
|
||||
if a.args.len() != b.args.len():
|
||||
return false
|
||||
elif not self.compareTypes(a.returnType, b.returnType):
|
||||
elif not self.compare(a.returnType, b.returnType):
|
||||
return false
|
||||
for (argA, argB) in zip(a.args, b.args):
|
||||
if not self.compareTypes(argA.kind, argB.kind):
|
||||
if not self.compare(argA.kind, argB.kind):
|
||||
return false
|
||||
return true
|
||||
else:
|
||||
|
@ -631,7 +631,7 @@ proc infer(self: Compiler, node: LiteralExpr): Type =
|
|||
if size.len() == 1:
|
||||
return Type(kind: Int64)
|
||||
let typ = size[1].toIntrinsic()
|
||||
if not self.compareTypes(typ, nil):
|
||||
if not self.compare(typ, nil):
|
||||
return typ
|
||||
else:
|
||||
self.error(&"invalid type specifier '{size[1]}' for int")
|
||||
|
@ -642,7 +642,7 @@ proc infer(self: Compiler, node: LiteralExpr): Type =
|
|||
if size.len() == 1 or size[1] == "f64":
|
||||
return Type(kind: Float64)
|
||||
let typ = size[1].toIntrinsic()
|
||||
if not self.compareTypes(typ, nil):
|
||||
if not self.compare(typ, nil):
|
||||
return typ
|
||||
else:
|
||||
self.error(&"invalid type specifier '{size[1]}' for float")
|
||||
|
@ -793,7 +793,7 @@ proc findByType(self: Compiler, name: string, kind: Type, depth: int = -1): seq[
|
|||
## with the given name and type. If depth is not -1,
|
||||
## it also compares the name's scope depth
|
||||
for obj in self.findByName(name):
|
||||
if self.compareTypes(obj.valueType, kind) and depth == -1 or depth == obj.depth:
|
||||
if self.compare(obj.valueType, kind) and depth == -1 or depth == obj.depth:
|
||||
result.add(obj)
|
||||
|
||||
|
||||
|
@ -830,7 +830,7 @@ proc matchImpl(self: Compiler, name: string, kind: Type): Name =
|
|||
if name.valueType.args[i].kind.mutable and not arg.kind.mutable:
|
||||
msg &= &", first mismatch at position {i + 1}: {name.valueType.args[i].name} is immutable, not 'var'"
|
||||
break
|
||||
elif not self.compareTypes(arg.kind, name.valueType.args[i].kind):
|
||||
elif not self.compare(arg.kind, name.valueType.args[i].kind):
|
||||
msg &= &", first mismatch at position {i + 1}: expected argument of type '{self.typeToStr(name.valueType.args[i].kind)}', got '{self.typeToStr(arg.kind)}' instead"
|
||||
break
|
||||
self.error(msg)
|
||||
|
@ -853,7 +853,7 @@ proc check(self: Compiler, term: Expression, kind: Type) =
|
|||
elif term.kind == callExpr and CallExpr(term).callee.kind == identExpr:
|
||||
self.error(&"call to undeclared function '{CallExpr(term).callee.token.lexeme}'", term)
|
||||
self.error(&"expecting value of type '{self.typeToStr(kind)}', but expression has no type", term)
|
||||
elif not self.compareTypes(k, kind):
|
||||
elif not self.compare(k, kind):
|
||||
self.error(&"expecting value of type '{self.typeToStr(kind)}', got '{self.typeToStr(k)}' instead", term)
|
||||
|
||||
|
||||
|
@ -1890,7 +1890,7 @@ proc varDecl(self: Compiler, node: VarDecl) =
|
|||
self.error(&"'{node.name.token.lexeme}' has no type")
|
||||
elif not expected.isNil() and expected.mutable: # I mean, variables *are* already mutable (some of them anyway)
|
||||
self.error(&"invalid type '{self.typeToStr(expected)}' for var")
|
||||
elif not self.compareTypes(expected, actual):
|
||||
elif not self.compare(expected, actual):
|
||||
if not expected.isNil():
|
||||
self.error(&"expected value of type '{self.typeToStr(expected)}', but '{node.name.token.lexeme}' is of type '{self.typeToStr(actual)}'")
|
||||
self.expression(node.value)
|
||||
|
|
Loading…
Reference in New Issue