Skip to content

Commit

Permalink
Add fibonacci example
Browse files Browse the repository at this point in the history
  • Loading branch information
paked committed Feb 2, 2019
1 parent 83a7494 commit 313e208
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 25 deletions.
28 changes: 7 additions & 21 deletions example.ls
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
x := 1337
var y bool
var z number
func fib(n number) number {
if (n == 0 || n == 1) {
return n
}

g := 11

func hello(a number, b number) number {
z := 22 - a

return z + 2
return fib(n - 1) + fib(n - 2)
}

x = hello(g, 10)
n := fib(8);

x
n
log

if x >= 1999 {
var l bool
var m number

m = m + x

m
log
}
29 changes: 25 additions & 4 deletions src/typing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,21 @@ bool typeCheck(ASTNode* node, SymbolTable* symbols) {
SymbolTable childSymbols = {};
symbolTable_init(&childSymbols, &DefaultSymbols);

Symbol me = function;
me.nameLen = 0;
// TODO(harrison): clean this the fuck up
if (!symbolTable_add(&childSymbols, &function)) {
logf("can't add this\n");

return false;
}

Symbol* f = 0;
if (!symbolTable_get(&childSymbols, tok, &f)) {
logf("not clue whtf\n");

return false;
}

Symbol me = symbol_makeDeclaration(0, 0, f);

if (!symbolTable_add(&childSymbols, &me)) {
logf("can't add this\n");
Expand Down Expand Up @@ -563,18 +576,26 @@ bool typeCheck(ASTNode* node, SymbolTable* symbols) {
return false;
}

if (me->type != SYMBOL_FUNCTION) {
if (me->type != SYMBOL_DECLARATION) {
logf("not in function: can't get 'this' type\n");

return false;
}

if (me->info.declaration.typeSymbol->type != SYMBOL_FUNCTION) {
logf("this is not a function\n");

return false;
}

Symbol* realRetType = me->info.declaration.typeSymbol;

Symbol* retType = 0;
if (!getType(node->Return.child, symbols, &retType)) {
return false;
}

if (me->info.function.returnType->id != retType->id) {
if (realRetType->id != retType->id) {
logf("function and return type are different\n");

return false;
Expand Down

0 comments on commit 313e208

Please sign in to comment.