nitron

commit 383a64573f48db61dbef4c6d47a0ee77147eddd9

Author: mesyeti <mesyeti@mesyeti.uk>

add nitron-man

 basic-std/std/file.bas | 6 +++---
 basic/source/frontend/c89.c | 7 +++++++
 basic/source/semanticAnalysis.c | 13 ++++++++++---
 basic/source/state.h | 1 +
 build.sh | 5 +++++
 scripts/README.md | 2 ++
 scripts/nitron-man | 7 +++++++


diff --git a/basic/source/frontend/c89.c b/basic/source/frontend/c89.c
index f07d25118bacb86a265c93539df9771c0343e5d9..6f009dfc18fb3b81ad737cece4221c5b2ff759c8 100644
--- a/basic/source/frontend/c89.c
+++ b/basic/source/frontend/c89.c
@@ -38,6 +38,9 @@ static void BeginMain(void) {
 	inMain = true;
 
 	fprintf(out, "int main(int argc, char** argv) {\n");
+	fprintf(out, "    nitron_null  = (void*) 0;\n");
+	fprintf(out, "    nitron_true  = true;\n");
+	fprintf(out, "    nitron_false = false;\n");
 }
 
 // static void Unexpected(ErrorInfo err, NodeType type) {
@@ -418,6 +421,10 @@ 		Var*  var     = &state.scopes[0][i];
 		Type* varType = State_GetTypeFromUsed(var->type);
 
 		if (varType->type == TYPE_FUNC) continue;
+
+		if (var->isStatic) {
+			fprintf(out, "static ");
+		}
 
 		CompileUsedType(var->type);
 		fprintf(out, " nitron_%s", var->name);




diff --git a/basic/source/semanticAnalysis.c b/basic/source/semanticAnalysis.c
index 149285cc63ec92f133572243354fe8751ef5c754..f8dae06330eefdf9177162c762d02e931c496f94 100644
--- a/basic/source/semanticAnalysis.c
+++ b/basic/source/semanticAnalysis.c
@@ -9,6 +9,12 @@ #include "semanticAnalysis.h"
 
 static Function* thisFunc = NULL;
 
+#define GET_PRIM(NAME, PTR) \
+	((UsedType) {(PTR), State_GetType(NAME) - state.types, 0, false})
+
+#define NEW_VAR(TYPE, NAME, PTR, STATIC) \
+	((Var) {GET_PRIM(TYPE, PTR), NAME, STATIC})
+
 void SemanticAnalysis_Init(size_t wordSize) {
 	State_Init();
 
@@ -33,6 +39,10 @@ 	Type type;
 	type.name = NewString("unit");
 	type.type = TYPE_UNIT;
 	State_AddType(type);
+
+	State_AddVar(NEW_VAR("unit", "null",  true, true));
+	State_AddVar(NEW_VAR("bool", "true",  false, true));
+	State_AddVar(NEW_VAR("bool", "false", false, true));
 
 	thisFunc = NULL;
 }
@@ -80,9 +90,6 @@ 			}
 		}
 	}
 }
-
-#define GET_PRIM(NAME, PTR) \
-	((UsedType) {(PTR), State_GetType(NAME) - state.types, 0, false})
 
 static bool AssignCompatible(UsedType left, UsedType right) {
 	Type* leftType  = State_GetTypeFromUsed(left);




diff --git a/basic/source/state.h b/basic/source/state.h
index 993d767c25cd8c8b66b9fefd8222882ad7b37907..d061f217182188b328501d040e97b40a85cf72dc 100644
--- a/basic/source/state.h
+++ b/basic/source/state.h
@@ -64,6 +64,7 @@
 typedef struct {
 	UsedType type;
 	char*    name;
+	bool     isStatic;
 } Var;
 
 typedef struct {




diff --git a/basic-std/std/file.bas b/basic-std/std/file.bas
index f89c1c1a239e6c0b0cbe06c25546fa7541ce5d22..578a2a272d7cace55314cb10bfd53157bc6c62ca 100644
--- a/basic-std/std/file.bas
+++ b/basic-std/std/file.bas
@@ -19,10 +19,10 @@ 	end
 
 	file = fopen(path, modeStr)
 
-	if file != 0 then
-		return 0
+	if file != null then
+		return false
 	end
 
 	this.file = file
-	return 1
+	return true
 end




diff --git a/build.sh b/build.sh
index 0db8b6bb440c6920a3eb24a874b35aeae3934536..ceeebd100d1ce8eaaf7340fd77c305626dd8a356 100755
--- a/build.sh
+++ b/build.sh
@@ -35,6 +35,11 @@ cd ..
 cp basic-std/libstd.a out/lib
 cp -r basic-std/std out/src
 
+echo "=================="
+echo "=    Scripts     ="
+echo "=================="
+cp -r scripts/* out/bin
+
 echo "========================"
 echo "Finished building nitron"
 echo "========================"




diff --git a/scripts/README.md b/scripts/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..ace21582316570a9d050a82b7ec863539f015f11
--- /dev/null
+++ b/scripts/README.md
@@ -0,0 +1,2 @@
+# Scripts
+Temporary bash scripts which will later be replaced with portable NitronBASIC programs.




diff --git a/scripts/nitron-man b/scripts/nitron-man
new file mode 100755
index 0000000000000000000000000000000000000000..87f2271abdb67e71884f52ab46e3cbe474964b51
--- /dev/null
+++ b/scripts/nitron-man
@@ -0,0 +1,7 @@
+#!/bin/bash
+if [ $# -ne 1 ]; then
+	ls $NITRON_MAN/ | cat | sed "s/.md//g"
+	exit
+fi
+
+cat $NITRON_MAN/$1.md | less