nitron

commit b477fce7d8dc49ab8003fb3b896546425b144663

Author: mesyeti <mesyeti@mesyeti.uk>

fix compiler and standard library

 basic-std/compile_test.sh | 2 +-
 basic-std/std/file.bas | 6 +++++-
 basic-std/test.bas | 11 ++++-------
 basic/source/frontend/c89.c | 5 ++++-
 basic/source/parser.c | 2 +-
 basic/source/semanticAnalysis.c | 5 +++--


diff --git a/basic/source/frontend/c89.c b/basic/source/frontend/c89.c
index 6f009dfc18fb3b81ad737cece4221c5b2ff759c8..01888d5ff283b8e04a9b31989986df439fb80629 100644
--- a/basic/source/frontend/c89.c
+++ b/basic/source/frontend/c89.c
@@ -123,7 +123,10 @@ 	UsedType usedType = SemanticAnalysis_NodeAsUsedType(node->varType);
 	Type*    type     = &state.types[usedType.typeIdx];
 
 	CompileType(node->varType);
-	fprintf(out, " nitron_%s = %s;\n", node->name, type->type == TYPE_PRIM? "0" : "{0}");
+	fprintf(
+		out, " nitron_%s = %s;\n", node->name,
+		((usedType.ptr > 0) || (type->type == TYPE_PRIM))? "0" : "{0}"
+	);
 
 	// add variable to state
 	Var var;




diff --git a/basic/source/parser.c b/basic/source/parser.c
index 7639ba55f501ab953e4c0919e358ded7950b33c4..820ae36e28455159876ff29ccb94bb197d36b3f6 100644
--- a/basic/source/parser.c
+++ b/basic/source/parser.c
@@ -508,7 +508,7 @@ }
 
 static Node ParseFuncCall(Parser* p) {
 	FuncCallNode ret;
-	ret.i    = INFO(NODE_FUNC_CALL);
+	ret.i = INFO(NODE_FUNC_CALL);
 
 	Expect(p, TOKEN_LPAREN);
 




diff --git a/basic/source/semanticAnalysis.c b/basic/source/semanticAnalysis.c
index f8dae06330eefdf9177162c762d02e931c496f94..108a458fbb9b6896d6c5a764e782746e175656da 100644
--- a/basic/source/semanticAnalysis.c
+++ b/basic/source/semanticAnalysis.c
@@ -185,8 +185,9 @@ 			func->paramsLen - (left.method? 1 : 0), call->funcCall.paramsNum
 		);
 	}
 
-	for (size_t i = left.method? 1 : 0; i < func->paramsLen; ++ i) {
-		UsedType type      = SemanticAnalysis_EvalType(&call->funcCall.params[i]);
+	size_t j = 0;
+	for (size_t i = left.method? 1 : 0; i < func->paramsLen; ++ i, ++ j) {
+		UsedType type      = SemanticAnalysis_EvalType(&call->funcCall.params[j]);
 		UsedType param     = func->params[i].type;
 		Type*    paramType = State_GetTypeFromUsed(param);
 		Type*    callType  = State_GetTypeFromUsed(type);




diff --git a/basic-std/compile_test.sh b/basic-std/compile_test.sh
index 1ee714748d2a199726ca818d521656b8099dad3c..209872670d899d2b15f7de2bc1e5084b52efbaba 100755
--- a/basic-std/compile_test.sh
+++ b/basic-std/compile_test.sh
@@ -1,4 +1,4 @@
-nitron-basic $1 --obj -o test.o
+nitron-basic --obj $1 -o test.o
 
 if [ $? -ne 0 ]; then
 	exit




diff --git a/basic-std/std/file.bas b/basic-std/std/file.bas
index 578a2a272d7cace55314cb10bfd53157bc6c62ca..cd5d4346748ed2c6feacdaf5d6bedf65d357c2ec 100644
--- a/basic-std/std/file.bas
+++ b/basic-std/std/file.bas
@@ -19,10 +19,14 @@ 	end
 
 	file = fopen(path, modeStr)
 
-	if file != null then
+	if file == null then
 		return false
 	end
 
 	this.file = file
 	return true
 end
+
+func File_Close(this as ptr(File)) bool
+	return fclose(this.file) == 0
+end




diff --git a/basic-std/test.bas b/basic-std/test.bas
index b4285bfd17e6af9feb9db2b6f8ec6beb3d2090d0..33e3ab3fd8da94275ecbc55df911105da664ec1d 100644
--- a/basic-std/test.bas
+++ b/basic-std/test.bas
@@ -3,12 +3,9 @@
 program test
 
 import std.io
+import std.file
 
-dim i as int
+dim file as File
 
-while i != 10 do
-	PrintStr("Hello, world! ")
-	i = i + 1
-end
-
-NewLine()
+file.Open("std/file.bas", false)
+file.Close()