summaryrefslogtreecommitdiff
path: root/libtnsl/box
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2022-10-14 01:21:12 -0400
committerKyle Gunger <kgunger12@gmail.com>2022-10-14 01:21:12 -0400
commit01d6580a17d5dc00b84cc3e72e0a86b090c1c6bd (patch)
tree0e023e9fac2f030037a3ddce6da0db6d675fad48 /libtnsl/box
parent0d2c569ed2e408d0c1cbac7f170f4e281601eb24 (diff)
Start to fill out compile_statement more
Diffstat (limited to 'libtnsl/box')
-rw-r--r--libtnsl/box/list.tnsl8
-rw-r--r--libtnsl/box/string.tnsl25
-rw-r--r--libtnsl/box/vector.tnsl6
3 files changed, 23 insertions, 16 deletions
diff --git a/libtnsl/box/list.tnsl b/libtnsl/box/list.tnsl
index 11ba4e1..cdf39d7 100644
--- a/libtnsl/box/list.tnsl
+++ b/libtnsl/box/list.tnsl
@@ -49,18 +49,18 @@
;/
;/
-;struct List {
+;struct List (type T) {
uint length,
- LNode
+ LNode(T)
first,
last
}
-;struct DList {
+;struct DList (type T) {
uint length,
- DLNode
+ DLNode(T)
first,
last
} \ No newline at end of file
diff --git a/libtnsl/box/string.tnsl b/libtnsl/box/string.tnsl
index d661676..675db06 100644
--- a/libtnsl/box/string.tnsl
+++ b/libtnsl/box/string.tnsl
@@ -30,19 +30,26 @@
}
/; method String
- /; cmp (String str) [int]
- /; loop (self.)
+ # Returns index of first difference, or -1 if there is no difference
+ /; diff_index (String str) [int]
+ ;uint l = math.mint(uint, str.length, self.length)
+ /; loop (uint i = 0; i < l) [i++]
+ /; if (self{i} != str{i})
+ ;return i [int]
+ ;/
+ ;/
+
+ /; if ()
;/
+
+ ;return -1
;/
/; override operator == (String str) [bool]
- ;return cmp(str) == 0
+ /; if (self.encoding != str.encoding || self.length != str.length)
+ ;return false
+ ;/
+ ;return diff_index(str) == -1
;/
;/
-
-;struct WString extends Vector (uint16) {}
-
-/; method WString
-
-;/ \ No newline at end of file
diff --git a/libtnsl/box/vector.tnsl b/libtnsl/box/vector.tnsl
index 724393f..85e6c3c 100644
--- a/libtnsl/box/vector.tnsl
+++ b/libtnsl/box/vector.tnsl
@@ -19,7 +19,7 @@
EXPRESS OR IMPLIED
#/
-;struct Vector (type T) {
+;struct Vector (raw type T) {
uint
length,
dataSize,
@@ -109,7 +109,7 @@
/; add (T item, uint index)
/; if (index < 0 || index > self.length)
- ;throw Error{"Bad Index"}
+ ;throw Error("Bad index", ERROR_CODE.OUT_OF_RANGE)
;/
# If it checks out then we check if we should grow
@@ -122,7 +122,7 @@
;self.data{i} = self.data{i - 1}
;/
- ;self{} = replace
+ ;self{index} = replace
;self.length += 1
;/