make index operator just read 1 byte
This commit is contained in:
@@ -9,38 +9,38 @@ func main[] : I64
|
||||
let p: I64 = 0
|
||||
|
||||
while i < src_len
|
||||
let op: U8 = str.nth(src, i)
|
||||
let op: U8 = src[i]
|
||||
|
||||
if op == '>'
|
||||
p = p + 1
|
||||
else if op == '<'
|
||||
p = p - 1
|
||||
else if op == '+'
|
||||
str.set(memory, p, mem.read8(memory + p)+1)
|
||||
str.set(memory, p, memory[p]+1)
|
||||
else if op == '-'
|
||||
str.set(memory, p, mem.read8(memory + p)-1)
|
||||
str.set(memory, p, memory[p]-1)
|
||||
else if op == '.'
|
||||
c.printf("%c", mem.read8(memory + p))
|
||||
c.printf("%c", memory[p])
|
||||
else if op == ','
|
||||
str.set(memory, p, c.getchar())
|
||||
else if op == '['
|
||||
if !mem.read8(memory + p)
|
||||
if !memory[p]
|
||||
i = i + 1
|
||||
let opened: I64 = 0
|
||||
while i < src_len & !(str.nth(src, i) == ']' & !opened)
|
||||
if str.nth(src, i) == '['
|
||||
while i < src_len & !(src[i] == ']' & !opened)
|
||||
if src[i] == '['
|
||||
opened = opened + 1
|
||||
else if str.nth(src, i) == ']'
|
||||
else if src[i] == ']'
|
||||
opened = opened - 1
|
||||
i = i + 1
|
||||
else if op == ']'
|
||||
if mem.read8(memory + p)
|
||||
if memory[p]
|
||||
i = i - 1
|
||||
let closed: I64 = 0
|
||||
while i >= 0 & !(str.nth(src, i) == '[' & !closed)
|
||||
if str.nth(src, i) == ']'
|
||||
while i >= 0 & !(src[i] == '[' & !closed)
|
||||
if src[i] == ']'
|
||||
closed = closed + 1
|
||||
else if str.nth(src, i) == '['
|
||||
else if src[i] == '['
|
||||
closed = closed - 1
|
||||
i = i - 1
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ func main[argc: I64, argv: Ptr] : I64
|
||||
let host_start: I64 = 7
|
||||
let i: I64 = host_start
|
||||
while i < url_len
|
||||
if str.nth(url, i) == '/'
|
||||
if url[i] == '/'
|
||||
break
|
||||
i = i + 1
|
||||
|
||||
@@ -44,7 +44,7 @@ func main[argc: I64, argv: Ptr] : I64
|
||||
let current_size: I64 = header_size + n
|
||||
i = 0
|
||||
while i <= current_size - 4
|
||||
if str.nth(header_buf, i) == 13 & str.nth(header_buf, i+1) == 10 & str.nth(header_buf, i+2) == 13 & str.nth(header_buf, i+3) == 10
|
||||
if header_buf[i] == 13 & header_buf[i+1] == 10 & header_buf[i+2] == 13 & header_buf[i+3] == 10
|
||||
found = true
|
||||
end_index = i + 4
|
||||
break
|
||||
|
||||
@@ -7,7 +7,7 @@ func main[] : I64
|
||||
let s: I64 = 1
|
||||
let j: I64 = 0
|
||||
while j < 13
|
||||
s = s * (str.nth(n, i + j) - '0')
|
||||
s = s * (n[i + j] - '0')
|
||||
j = j + 1
|
||||
if s > out
|
||||
out = s
|
||||
|
||||
@@ -4,12 +4,12 @@ func main[] : I64
|
||||
array.push(arr, math.abs(math.urandom() % 1000))
|
||||
|
||||
for i in 0..array.size(arr)
|
||||
io.print_i64(arr[i])
|
||||
io.print_i64(array.nth(arr, i))
|
||||
io.print("------------")
|
||||
|
||||
alg.quicksort(arr)
|
||||
|
||||
for i in 0..array.size(arr)
|
||||
io.print_i64(arr[i])
|
||||
io.print_i64(array.nth(arr, i))
|
||||
|
||||
array.free(arr)
|
||||
@@ -5,11 +5,11 @@ func rule110_step[state: Array] : Array
|
||||
for i in 0..state_len
|
||||
let left: Bool = false
|
||||
if i - 1 >= 0
|
||||
left = state[i-1]
|
||||
let center: Bool = state[i]
|
||||
left = array.nth(state, i-1)
|
||||
let center: Bool = array.nth(state, i)
|
||||
let right: Bool = false
|
||||
if i + 1 < state_len
|
||||
right = state[i+1]
|
||||
right = array.nth(state, i+1)
|
||||
|
||||
array.push(new_state, !((!left & !center & !right) | (left & !center & !right) | (left & center & right)))
|
||||
|
||||
@@ -17,7 +17,7 @@ func rule110_step[state: Array] : Array
|
||||
|
||||
func print_state[state: Array]: Void
|
||||
for i in 0..array.size(state)
|
||||
if state[i]
|
||||
if array.nth(state, i)
|
||||
c.putchar('#')
|
||||
else
|
||||
c.putchar(' ')
|
||||
|
||||
Reference in New Issue
Block a user