Minor fixes

This commit is contained in:
Mattia Giambirtone 2023-10-14 11:40:26 +02:00
parent f7f6ae052f
commit 8cac75ecef
Signed by: nocturn9x
GPG Key ID: 8270F9F467971E59
3 changed files with 18 additions and 21 deletions

View File

@ -335,9 +335,9 @@ proc toIntrinsic(name: string): Type =
elif name == "pointer":
return Type(kind: Pointer, intrinsic: true, value: "any".toIntrinsic())
elif name == "lent":
return Type(kind: Lent, intrinsic: true, value: "any".toIntrinsic())
return Type(kind: TypeKind.Lent, intrinsic: true, value: "any".toIntrinsic())
elif name == "const":
return Type(kind: Const, intrinsic: true, value: "any".toIntrinsic())
return Type(kind: TypeKind.Const, intrinsic: true, value: "any".toIntrinsic())
elif name == "ref":
return Type(kind: Reference, intrinsic: true, value: "any".toIntrinsic())
@ -476,7 +476,7 @@ proc compare(self: TypeChecker, a, b: Type): bool =
return a.size == b.size and a.signed == b.signed
of Float:
return a.width == b.width
of Lent, Reference, Pointer, Const:
of TypeKind.Lent, Reference, Pointer, TypeKind.Const:
return self.compare(a.value, b.value)
of Union:
return self.compareUnions(a.types, b.types)
@ -722,7 +722,7 @@ proc stringify*(self: TypeChecker, typ: Type): string =
result &= &"ptr {self.stringify(typ.value)}"
of Reference:
result &= &"ref {self.stringify(typ.value)}"
of Const:
of TypeKind.Const:
result &= &"const {self.stringify(typ.value)}"
of Function:
result &= "fn "
@ -761,7 +761,7 @@ proc stringify*(self: TypeChecker, typ: Type): string =
result &= ", "
else:
result &= "}"
of Lent:
of TypeKind.Lent:
result &= &"lent {self.stringify(typ.value)}"
of Union:
for i, condition in typ.types:

View File

@ -1261,7 +1261,6 @@ proc typeDecl(self: Parser): TypeDecl =
if self.match(LeftBracket):
self.parseGenerics(result)
self.expect("=", "expecting '=' after type name")
var hasNone = false
case self.peek().lexeme:
of "ref":
discard self.step()
@ -1273,20 +1272,18 @@ proc typeDecl(self: Parser): TypeDecl =
of "object":
discard self.step()
else:
hasNone = true
if hasNone:
result.value = self.expression()
while not self.check(";"):
case self.peek().lexeme:
of "|": # Untagged type unions
result.value = newBinaryExpr(result.value, self.step(), self.expression())
result.file = self.file
of "~":
result.value = newUnaryExpr(self.step(), result.value)
result.file = self.file
else:
discard
elif not result.isEnum and self.match("of"):
result.value = self.expression()
while not self.check(";"):
case self.peek().lexeme:
of "|": # Untagged type unions
result.value = newBinaryExpr(result.value, self.step(), self.expression())
result.file = self.file
of "~":
result.value = newUnaryExpr(self.step(), result.value)
result.file = self.file
else:
discard
if not result.isEnum and self.match("of"):
# Type has a parent (and is not an enumeration)
result.parent = self.expression()
if not self.match(";"):

View File

@ -233,7 +233,7 @@ when isMainModule:
of "debug-parser":
debugParser = true
else:
stderr.styledWriteLine(fgRed, styleBright, "Error: ", fgDefault, &"error: unkown option '{key}'")
stderr.styledWriteLine(fgRed, styleBright, "Error: ", fgDefault, &"unkown option '{key}'")
quit()
of cmdShortOption:
case key: