Fixed some bugs with void functions in the compiler

This commit is contained in:
Mattia Giambirtone 2022-08-18 23:49:20 +02:00
parent d1a0005f7e
commit 058b021493
4 changed files with 20 additions and 12 deletions

View File

@ -712,6 +712,8 @@ proc inferType(self: Compiler, node: Declaration, strictMutable: bool = true): T
proc typeToStr(self: Compiler, typ: Type): string =
## Returns the string representation of a
## type object
if typ.isNil():
return "nil"
case typ.kind:
of Int8, UInt8, Int16, UInt16, Int32,
UInt32, Int64, UInt64, Float32, Float64,
@ -1802,7 +1804,7 @@ proc funDecl(self: Compiler, node: FunDecl, fn: Name = nil, args: seq[Expression
# the jump offset
self.patchJump(jmp)
# Pops a call frame
discard self.frames.pop()
# discard self.frames.pop()
# Restores the enclosing function (if any).
# Makes nested calls work (including recursion)
self.currentFunction = function

View File

@ -116,7 +116,7 @@ proc addOperator(self: OperatorTable, lexeme: string) =
## criteria are similar to Nim's)
if lexeme in self.tokens:
return # We've already added it!
var prec = Precedence.high()
var prec = Power
if lexeme.len() >= 2 and lexeme[^2..^1] in ["->", "~>", "=>"]:
prec = Arrow
elif lexeme.endsWith("=") and lexeme[0] notin {'<', '>', '!', '?', '~', '='} or lexeme == "=":

View File

@ -1,4 +1,7 @@
fn first(a, b: int): int {
import std;
fn first(a, b, c: int): int {
return a;
}
@ -8,19 +11,17 @@ fn second(a, b: int): int {
fn last(a, b, c: int): int {
return c;
return c;
}
fn middle(a, b, c: int): int {
return last(a, c, b);
return last(a, c, b);
}
fn first(a, b, c: int): int {
return middle(b, a, c);
}
first(1, 2, 3);
var x = first(second(1, 2), 3);
print(first(1, 2, 3) == 1);
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);

View File

@ -567,3 +567,8 @@ fn print*(x: float) {
fn print*(x: string) {
#pragma[magic: "PrintString"]
}
fn print*(x: bool) {
#pragma[magic: "PrintBool"]
}