finally add real logical operators

This commit is contained in:
2025-12-26 11:52:23 +01:00
parent 270386da95
commit db2e639cc8
16 changed files with 96 additions and 49 deletions

View File

@@ -113,32 +113,32 @@ func str.set[s: str, n: i64, c: u8] : void
func str.equal[a: str, b: str] : bool
let i = 0
while a[i] != 0 & b[i] != 0
while a[i] != 0 && b[i] != 0
if a[i] != b[i]
return false
i = i + 1
return a[i] == b[i]
func str.is_whitespace[x: u8] : bool
return x == ' ' | x == 10 | x == 13 | x == 9
return x == ' ' || x == 10 || x == 13 || x == 9
func str.is_digit[x: u8] : bool
return x >= '0' & x <= '9'
return x >= '0' && x <= '9'
func str.is_hex_digit[x: u8] : bool
return (x >= '0' & x <= '9') | (x >= 'a' & x <= 'f') | (x >= 'A' & x <= 'F')
return (x >= '0' && x <= '9') || (x >= 'a' && x <= 'f') || (x >= 'A' && x <= 'F')
func str.is_lowercase[x: u8] : bool
return x >= 'a' & x <= 'z'
return x >= 'a' && x <= 'z'
func str.is_uppercase[x: u8] : bool
return x >= 'A' & x <= 'Z'
return x >= 'A' && x <= 'Z'
func str.is_letter[x: u8] : bool
return str.is_uppercase(x) | str.is_lowercase(x)
return str.is_uppercase(x) || str.is_lowercase(x)
func str.is_alphanumeric[x: u8] : bool
return str.is_letter(x) | str.is_digit(x)
return str.is_letter(x) || str.is_digit(x)
func str.concat[a: str, b: str] : str
let a_len: i64 = str.len(a)
@@ -169,7 +169,7 @@ func str.find[haystack: str, needle: str] : i64
return -1
func str.substr[s: str, start: i64, length: i64] : str
if start < 0 | length < 0 | start + length > str.len(s)
if start < 0 || length < 0 || start + length > str.len(s)
dbg.panic("str.substr out of bounds")
let out: str = mem.alloc(length + 1)
@@ -186,10 +186,10 @@ func str.trim[s: str] : str
let start = 0
let end: i64 = len - 1
while start <= end & str.is_whitespace(s[start])
while start <= end && str.is_whitespace(s[start])
start = start + 1
while end >= start & str.is_whitespace(s[end])
while end >= start && str.is_whitespace(s[end])
end = end - 1
return str.substr(s, start, end - start + 1)
@@ -269,14 +269,14 @@ func str.parse_i64[s: str] : i64
let i = 0
let sign = 1
if i < len & s[i] == '-'
if i < len && s[i] == '-'
sign = -1
i = i + 1
let num = 0
while i < len
let d: u8 = s[i]
if d < '0' | d > '9'
if d < '0' || d > '9'
break
num = num * 10 + (d - '0')
i = i + 1
@@ -299,9 +299,9 @@ func str.hex_encode[s: str] : str
return out
func str._hex_digit_to_int[d: u8] : i64
if d >= 'a' & d <= 'f'
if d >= 'a' && d <= 'f'
return d - 'a' + 10
if d >= 'A' & d <= 'F'
if d >= 'A' && d <= 'F'
return d - 'A' + 10
return d - '0'
@@ -353,7 +353,7 @@ func math.lcm[a: i64, b: i64] : i64
func math.isqrt[n: i64] : i64
if n < 0
dbg.panic("negative number passed to math.isqrt")
if n == 0 | n == 1
if n == 0 || n == 1
return n
let guess: i64 = n
@@ -368,14 +368,14 @@ func math.isqrt[n: i64] : i64
func math.is_prime[n: i64]: bool
if n <= 1
return false
if n == 2 | n == 3
if n == 2 || n == 3
return true
if n % 2 == 0 | n % 3 == 0
if n % 2 == 0 || n % 3 == 0
return false
let i = 5
while i * i <= n
if n % i == 0 | n % (i + 2) == 0
if n % i == 0 || n % (i + 2) == 0
return false
i = i + 6
return true
@@ -387,13 +387,13 @@ func array.new[] : array
return arr
func array.nth[xs: array, n: i64] : i64
if n < 0 | n >= array.size(xs)
if n < 0 || n >= array.size(xs)
dbg.panic("array.nth out of bounds")
let data: ptr = mem.read64(xs)
return mem.read64(data + n * 8)
func array.set[xs: array, n: i64, x: i64] : void
if n < 0 | n >= array.size(xs)
if n < 0 || n >= array.size(xs)
dbg.panic("array.set out of bounds")
let data: ptr = mem.read64(xs)
mem.write64(data + n * 8, x)
@@ -433,7 +433,7 @@ func array.pop[xs: array] : i64
return x
func array.slice[xs: array, start: i64, length: i64] : array
if start < 0 | length < 0 | start + length > array.size(xs)
if start < 0 || length < 0 || start + length > array.size(xs)
dbg.panic("array.slice out of bounds")
let new_array: array = []