Fixed some bugs with void functions in the compiler
This commit is contained in:
parent
d1a0005f7e
commit
058b021493
|
@ -712,6 +712,8 @@ proc inferType(self: Compiler, node: Declaration, strictMutable: bool = true): T
|
||||||
proc typeToStr(self: Compiler, typ: Type): string =
|
proc typeToStr(self: Compiler, typ: Type): string =
|
||||||
## Returns the string representation of a
|
## Returns the string representation of a
|
||||||
## type object
|
## type object
|
||||||
|
if typ.isNil():
|
||||||
|
return "nil"
|
||||||
case typ.kind:
|
case typ.kind:
|
||||||
of Int8, UInt8, Int16, UInt16, Int32,
|
of Int8, UInt8, Int16, UInt16, Int32,
|
||||||
UInt32, Int64, UInt64, Float32, Float64,
|
UInt32, Int64, UInt64, Float32, Float64,
|
||||||
|
@ -1802,7 +1804,7 @@ proc funDecl(self: Compiler, node: FunDecl, fn: Name = nil, args: seq[Expression
|
||||||
# the jump offset
|
# the jump offset
|
||||||
self.patchJump(jmp)
|
self.patchJump(jmp)
|
||||||
# Pops a call frame
|
# Pops a call frame
|
||||||
discard self.frames.pop()
|
# discard self.frames.pop()
|
||||||
# Restores the enclosing function (if any).
|
# Restores the enclosing function (if any).
|
||||||
# Makes nested calls work (including recursion)
|
# Makes nested calls work (including recursion)
|
||||||
self.currentFunction = function
|
self.currentFunction = function
|
||||||
|
|
|
@ -116,7 +116,7 @@ proc addOperator(self: OperatorTable, lexeme: string) =
|
||||||
## criteria are similar to Nim's)
|
## criteria are similar to Nim's)
|
||||||
if lexeme in self.tokens:
|
if lexeme in self.tokens:
|
||||||
return # We've already added it!
|
return # We've already added it!
|
||||||
var prec = Precedence.high()
|
var prec = Power
|
||||||
if lexeme.len() >= 2 and lexeme[^2..^1] in ["->", "~>", "=>"]:
|
if lexeme.len() >= 2 and lexeme[^2..^1] in ["->", "~>", "=>"]:
|
||||||
prec = Arrow
|
prec = Arrow
|
||||||
elif lexeme.endsWith("=") and lexeme[0] notin {'<', '>', '!', '?', '~', '='} or lexeme == "=":
|
elif lexeme.endsWith("=") and lexeme[0] notin {'<', '>', '!', '?', '~', '='} or lexeme == "=":
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
fn first(a, b: int): int {
|
import std;
|
||||||
|
|
||||||
|
|
||||||
|
fn first(a, b, c: int): int {
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,10 +20,8 @@ fn middle(a, b, c: int): int {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn first(a, b, c: int): int {
|
print(first(1, 2, 3) == 1);
|
||||||
return middle(b, a, c);
|
var x = first(second(1, 2), 3, 4);
|
||||||
}
|
print(x == 2);
|
||||||
|
print(middle(3, 1, 2) == 1);
|
||||||
|
print(first(last(second(2, 1), 3, 0), 4, 5) == 0);
|
||||||
first(1, 2, 3);
|
|
||||||
var x = first(second(1, 2), 3);
|
|
|
@ -567,3 +567,8 @@ fn print*(x: float) {
|
||||||
fn print*(x: string) {
|
fn print*(x: string) {
|
||||||
#pragma[magic: "PrintString"]
|
#pragma[magic: "PrintString"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn print*(x: bool) {
|
||||||
|
#pragma[magic: "PrintBool"]
|
||||||
|
}
|
Loading…
Reference in New Issue