Author: mesyeti <mesyeti@mesyeti.uk>
fix compiler and add read file example
basic-std/compile_test.sh | 2 -- basic-std/examples/read_file.bas | 30 ++++++++++++++++++++++++++++++ basic-std/std/stringView.bas | 26 ++++++++++++++++++++++++++ basic-std/test.bas | 8 +++++--- basic/source/frontend/c89.c | 2 +- basic/source/lexer.c | 2 +-
diff --git a/basic/source/frontend/c89.c b/basic/source/frontend/c89.c
index b6a60463bca17e61aa9322e3d8c23b9e5f3798c9..39aea7e1830a570bb71fce79e6911259adcf6743 100644
--- a/basic/source/frontend/c89.c
+++ b/basic/source/frontend/c89.c
@@ -245,7 +245,7 @@ if (node->bin.left->i.flags == 1) {
isMethod = true;
methodParam = node->bin.left->bin.left;
- UsedType methodType = SemanticAnalysis_EvalType(node->bin.left->bin.left);
+ methodType = SemanticAnalysis_EvalType(node->bin.left->bin.left);
leftNode.i = left->i;
leftNode.i.type = NODE_IDENTIFIER;
diff --git a/basic/source/lexer.c b/basic/source/lexer.c
index fcd317d3b96cbb7932fb6286fafa9d302c48a193..30bdb2f1e1fd91bfdb238088817ca8d1c05703cd 100644
--- a/basic/source/lexer.c
+++ b/basic/source/lexer.c
@@ -170,7 +170,7 @@ char next;
GET_CHAR(next);
if (next == '=') {
- *token = TOKEN(TOKEN_LESS_EQ, NULL);
+ *token = TOKEN(TOKEN_GREATER_EQ, NULL);
}
else {
*token = TOKEN(TOKEN_GREATER, NULL);
diff --git a/basic-std/compile_test.sh b/basic-std/compile_test.sh
index 209872670d899d2b15f7de2bc1e5084b52efbaba..9afd5d34305244941954d47518d8e9a4b212683b 100755
--- a/basic-std/compile_test.sh
+++ b/basic-std/compile_test.sh
@@ -9,5 +9,3 @@
if [ $? -ne 0 ]; then
exit
fi
-
-rm test.o.c test.o
diff --git a/basic-std/examples/read_file.bas b/basic-std/examples/read_file.bas
new file mode 100644
index 0000000000000000000000000000000000000000..6a5c47f56fb403626c83230c795051a8c6892088
--- /dev/null
+++ b/basic-std/examples/read_file.bas
@@ -0,0 +1,30 @@
+'NITRON
+
+program test
+
+import std.io
+import std.file
+import std.heap
+import std.stringView
+
+dim file as File
+dim size as uint
+
+file.Open("test.bas", false)
+file.Seek(SEEK_END, 0)
+size = file.Peek()
+file.Seek(SEEK_SET, 0)
+
+dim contents as ptr(char)
+contents = Alloc(size) as ptr(char)
+
+if ((contents as ptr(unit)) == null) then
+ PrintStrLn("Failed to allocate contents")
+end
+
+file.Read(size, contents as ptr(unit))
+file.Close()
+
+dim sv as StringView
+sv.Init(contents, size)
+sv.PrintLn()
diff --git a/basic-std/std/stringView.bas b/basic-std/std/stringView.bas
index 497707ddc1081360227ffa119b77e8b13a790feb..adca26b4f16d034031c40cb4f58e85ab6fca70af 100644
--- a/basic-std/std/stringView.bas
+++ b/basic-std/std/stringView.bas
@@ -1,10 +1,17 @@
'NITRON
+import io
+
type Char = u32
type StringView
string as ptr(char)
length as uint
+end
+
+sub StringView_Init(this as ptr(StringView), string as ptr(char), size as uint)
+ this.string = string
+ this.length = size
end
sub StringView_FromNTStr(this as ptr(StringView), string as ptr(char))
@@ -29,3 +36,22 @@
func StringView_Length(this as ptr(StringView)) uint
return this.length
end
+
+sub StringView_Print(this as ptr(StringView))
+ dim i as uint
+ dim length as uint
+
+ i = 0
+ length = this.Length()
+
+ while i < length do
+ PrintChar(this.Get(i) as char)
+
+ i = i + 1
+ end
+end
+
+sub StringView_PrintLn(this as ptr(StringView))
+ this.Print()
+ NewLine()
+end
diff --git a/basic-std/test.bas b/basic-std/test.bas
index 88750300f26c5506342ac580d54a7442556fe783..6a5c47f56fb403626c83230c795051a8c6892088 100644
--- a/basic-std/test.bas
+++ b/basic-std/test.bas
@@ -5,6 +5,7 @@
import std.io
import std.file
import std.heap
+import std.stringView
dim file as File
dim size as uint
@@ -22,7 +23,8 @@ PrintStrLn("Failed to allocate contents")
end
file.Read(size, contents as ptr(unit))
+file.Close()
-PrintStr(contents)
-
-file.Close()
+dim sv as StringView
+sv.Init(contents, size)
+sv.PrintLn()