removed all string related builtin functions and moved them to separate routines in new 'string' library module

This commit is contained in:
Irmen de Jong 2021-01-07 23:01:31 +01:00
parent 9d9ca0f08d
commit 61784a03bb
4 changed files with 6 additions and 87 deletions

View File

@ -176,7 +176,7 @@ _found sty P8ZP_SCRATCH_B1
}}
}
asmsub compare(uword string1 @R0, uword string2 @AY) clobbers(Y) -> ubyte @A {
asmsub compare(uword string1 @R0, uword string2 @AY) clobbers(Y) -> byte @A {
; Compares two strings for sorting.
; Returns -1 (255), 0 or 1 depeding on wether string1 sorts before, equal or after string2.
; Note that you can also directly compare strings and string values with eachother using

View File

@ -62,7 +62,7 @@ textparse {
}
uword value = conv.any2uword(word_addrs[2])
if word_addrs[0] == "*" { ; TODO does this string compare work?
if string.compare(word_addrs[0], "*")==0 {
program_counter = value
} else {
set_symbol(word_addrs[0], value)

View File

@ -55,7 +55,7 @@ main {
;txt.print(filenameptr)
;txt.chrout('\n')
uword extension = filenameptr + rfind(filenameptr, '.')
if extension == ".iff" { ; TODO does this compare work?
if string.compare(extension, ".iff")==0 {
;txt.print("loading ")
;txt.print("iff\n")
if iff_module.show_image(filenameptr) {
@ -71,7 +71,7 @@ main {
load_error(filenameptr)
}
}
else if extension == ".pcx" { ; TODO works?
else if string.compare(extension, ".pcx")==0 {
;txt.print("loading ")
;txt.print("pcx\n")
if pcx_module.show_image(filenameptr) {
@ -80,7 +80,7 @@ main {
load_error(filenameptr)
}
}
else if extension == ".koa" { ; TODO works?
else if string.compare(extension,".koa")==0 {
;txt.print("loading ")
;txt.print("koala\n")
if koala_module.show_image(filenameptr) {
@ -89,7 +89,7 @@ main {
load_error(filenameptr)
}
}
else if extension == ".bmp" { ; TODO works?
else if string.compare(extension, ".bmp")==0 {
;txt.print("loading ")
;txt.print("bmp\n")
if bmp_module.show_image(filenameptr) {

View File

@ -8,88 +8,7 @@ main {
; TODO: error when a parameter has the same name as an existing module/block/subroutine: sub print_right(ubyte width, uword string) {
sub start() {
str s1 = "irmen"
str s2 = "what"
str s3 = "irmen2"
s3[5] = 0
txt.print("length:\n")
txt.print_ub(len(s1))
txt.chrout('\n')
txt.print_ub(string.length(s1))
txt.print("\n\ncopy:\n")
txt.print(s3)
txt.chrout('\n')
s3 = s2
txt.print(s3)
txt.chrout('\n')
txt.print_ub(string.copy("new", s3))
txt.print(s3)
txt.print("\n\ncompare:\n")
txt.chrout('\n')
txt.print_ub(string.compare(s1, s2))
txt.chrout('\n')
txt.print_ub(string.compare(s2, s1))
txt.chrout('\n')
txt.print_ub(string.compare(s1, s3))
txt.chrout('\n')
txt.chrout('\n')
txt.print_ub(s1==s2)
txt.chrout('\n')
txt.print_ub(s1<s2)
txt.chrout('\n')
txt.print_ub(s1>s2)
txt.chrout('\n')
txt.print("\n\nleft:")
string.left(s2,2,s3)
txt.print(s3)
txt.chrout('\n')
txt.print("\n\nright:\n")
txt.print(s2)
txt.chrout('\n')
string.right(s2,2,s3)
txt.print(s3)
txt.chrout('\n')
txt.print("\n\nfind:\n")
txt.print(s1)
txt.chrout('\n')
uword found = string.find(s1, 'e')
txt.print_uwhex(found, 1)
if found
txt.print(found)
txt.chrout('\n')
found = string.find(s1, 'i')
txt.print_uwhex(found, 1)
if found
txt.print(found)
txt.chrout('\n')
found = string.find(s1, 'x')
txt.print_uwhex(found, 1)
if found
txt.print(found)
txt.chrout('\n')
txt.print("\n\nslice:\n")
string.slice(s1, 0, 5, s2)
txt.print(s2)
txt.chrout('\n')
string.slice(s1, 1, 4, s2)
txt.print(s2)
txt.chrout('\n')
string.slice(s1, 2, 2, s2)
txt.print(s2)
txt.chrout('\n')
string.slice(s1, 3, 2, s2)
txt.print(s2)
txt.chrout('\n')
test_stack.test()
}