parent
3881e97a40
commit
41e88423aa
|
@ -376,7 +376,7 @@ pub fn (a &array) clone_to_depth(depth int) array {
|
||||||
}
|
}
|
||||||
return arr
|
return arr
|
||||||
} else {
|
} else {
|
||||||
if a.data != 0 {
|
if !isnil(a.data) {
|
||||||
unsafe { C.memcpy(&byte(arr.data), a.data, a.cap * a.element_size) }
|
unsafe { C.memcpy(&byte(arr.data), a.data, a.cap * a.element_size) }
|
||||||
}
|
}
|
||||||
return arr
|
return arr
|
||||||
|
@ -409,7 +409,7 @@ fn (mut a array) push(val voidptr) {
|
||||||
// `val` is array.data and user facing usage is `a << [1,2,3]`
|
// `val` is array.data and user facing usage is `a << [1,2,3]`
|
||||||
[unsafe]
|
[unsafe]
|
||||||
pub fn (mut a3 array) push_many(val voidptr, size int) {
|
pub fn (mut a3 array) push_many(val voidptr, size int) {
|
||||||
if a3.data == val && val != 0 {
|
if a3.data == val && !isnil(a3.data) {
|
||||||
// handle `arr << arr`
|
// handle `arr << arr`
|
||||||
copy := a3.clone()
|
copy := a3.clone()
|
||||||
a3.ensure_cap(a3.len + size)
|
a3.ensure_cap(a3.len + size)
|
||||||
|
@ -419,7 +419,7 @@ pub fn (mut a3 array) push_many(val voidptr, size int) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
a3.ensure_cap(a3.len + size)
|
a3.ensure_cap(a3.len + size)
|
||||||
if a3.data != 0 && val != 0 {
|
if !isnil(a3.data) && !isnil(val) {
|
||||||
unsafe { C.memcpy(a3.get_unsafe(a3.len), val, a3.element_size * size) }
|
unsafe { C.memcpy(a3.get_unsafe(a3.len), val, a3.element_size * size) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -204,7 +204,7 @@ fn (a &array) clone_to_depth_noscan(depth int) array {
|
||||||
}
|
}
|
||||||
return arr
|
return arr
|
||||||
} else {
|
} else {
|
||||||
if a.data != 0 {
|
if !isnil(a.data) {
|
||||||
unsafe { C.memcpy(&byte(arr.data), a.data, a.cap * a.element_size) }
|
unsafe { C.memcpy(&byte(arr.data), a.data, a.cap * a.element_size) }
|
||||||
}
|
}
|
||||||
return arr
|
return arr
|
||||||
|
@ -221,7 +221,7 @@ fn (mut a array) push_noscan(val voidptr) {
|
||||||
// `val` is array.data and user facing usage is `a << [1,2,3]`
|
// `val` is array.data and user facing usage is `a << [1,2,3]`
|
||||||
[unsafe]
|
[unsafe]
|
||||||
fn (mut a3 array) push_many_noscan(val voidptr, size int) {
|
fn (mut a3 array) push_many_noscan(val voidptr, size int) {
|
||||||
if a3.data == val && val != 0 {
|
if a3.data == val && !isnil(a3.data) {
|
||||||
// handle `arr << arr`
|
// handle `arr << arr`
|
||||||
copy := a3.clone()
|
copy := a3.clone()
|
||||||
a3.ensure_cap_noscan(a3.len + size)
|
a3.ensure_cap_noscan(a3.len + size)
|
||||||
|
@ -231,7 +231,7 @@ fn (mut a3 array) push_many_noscan(val voidptr, size int) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
a3.ensure_cap_noscan(a3.len + size)
|
a3.ensure_cap_noscan(a3.len + size)
|
||||||
if a3.data != 0 && val != 0 {
|
if !isnil(a3.data) && !isnil(val) {
|
||||||
unsafe { C.memcpy(a3.get_unsafe(a3.len), val, a3.element_size * size) }
|
unsafe { C.memcpy(a3.get_unsafe(a3.len), val, a3.element_size * size) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,7 +110,7 @@ fn print_backtrace_skipping_top_frames_linux(skipframes int) bool {
|
||||||
cmd := 'addr2line -e $executable $addr'
|
cmd := 'addr2line -e $executable $addr'
|
||||||
// taken from os, to avoid depending on the os module inside builtin.v
|
// taken from os, to avoid depending on the os module inside builtin.v
|
||||||
f := C.popen(&char(cmd.str), c'r')
|
f := C.popen(&char(cmd.str), c'r')
|
||||||
if f == 0 {
|
if isnil(f) {
|
||||||
eprintln(sframe)
|
eprintln(sframe)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,7 +73,7 @@ fn (mut m SortedMap) set(key string, value voidptr) {
|
||||||
mut parent := &mapnode(0)
|
mut parent := &mapnode(0)
|
||||||
for {
|
for {
|
||||||
if node.len == max_len {
|
if node.len == max_len {
|
||||||
if parent != 0 {
|
if isnil(parent) {
|
||||||
parent = new_node()
|
parent = new_node()
|
||||||
m.root = parent
|
m.root = parent
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ fn (mut m SortedMap) set(key string, value voidptr) {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if node.children == 0 {
|
if isnil(node.children) {
|
||||||
mut j := node.len - 1
|
mut j := node.len - 1
|
||||||
for j >= 0 && key < node.keys[j] {
|
for j >= 0 && key < node.keys[j] {
|
||||||
node.keys[j + 1] = node.keys[j]
|
node.keys[j + 1] = node.keys[j]
|
||||||
|
@ -130,7 +130,7 @@ fn (mut n mapnode) split_child(child_index int, mut y mapnode) {
|
||||||
z.keys[j] = y.keys[j + degree]
|
z.keys[j] = y.keys[j + degree]
|
||||||
z.values[j] = y.values[j + degree]
|
z.values[j] = y.values[j + degree]
|
||||||
}
|
}
|
||||||
if y.children != 0 {
|
if !isnil(y.children) {
|
||||||
z.children = unsafe { &voidptr(malloc(int(children_bytes))) }
|
z.children = unsafe { &voidptr(malloc(int(children_bytes))) }
|
||||||
for jj := degree - 1; jj >= 0; jj-- {
|
for jj := degree - 1; jj >= 0; jj-- {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -139,7 +139,7 @@ fn (mut n mapnode) split_child(child_index int, mut y mapnode) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unsafe {
|
unsafe {
|
||||||
if n.children == 0 {
|
if isnil(n.children) {
|
||||||
n.children = &voidptr(malloc(int(children_bytes)))
|
n.children = &voidptr(malloc(int(children_bytes)))
|
||||||
}
|
}
|
||||||
n.children[n.len + 1] = n.children[n.len]
|
n.children[n.len + 1] = n.children[n.len]
|
||||||
|
@ -173,7 +173,7 @@ fn (m SortedMap) get(key string, out voidptr) bool {
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if node.children == 0 {
|
if isnil(node.children) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
node = unsafe { &mapnode(node.children[i + 1]) }
|
node = unsafe { &mapnode(node.children[i + 1]) }
|
||||||
|
@ -182,7 +182,7 @@ fn (m SortedMap) get(key string, out voidptr) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (m SortedMap) exists(key string) bool {
|
fn (m SortedMap) exists(key string) bool {
|
||||||
if m.root == 0 { // TODO: find out why root can be nil
|
if isnil(m.root) { // TODO: find out why root can be nil
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
mut node := m.root
|
mut node := m.root
|
||||||
|
@ -194,7 +194,7 @@ fn (m SortedMap) exists(key string) bool {
|
||||||
if i != -1 && key == node.keys[i] {
|
if i != -1 && key == node.keys[i] {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if node.children == 0 {
|
if isnil(node.children) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
node = unsafe { &mapnode(node.children[i + 1]) }
|
node = unsafe { &mapnode(node.children[i + 1]) }
|
||||||
|
@ -213,14 +213,14 @@ fn (n &mapnode) find_key(k string) int {
|
||||||
fn (mut n mapnode) remove_key(k string) bool {
|
fn (mut n mapnode) remove_key(k string) bool {
|
||||||
idx := n.find_key(k)
|
idx := n.find_key(k)
|
||||||
if idx < n.len && n.keys[idx] == k {
|
if idx < n.len && n.keys[idx] == k {
|
||||||
if n.children == 0 {
|
if isnil(n.children) {
|
||||||
n.remove_from_leaf(idx)
|
n.remove_from_leaf(idx)
|
||||||
} else {
|
} else {
|
||||||
n.remove_from_non_leaf(idx)
|
n.remove_from_non_leaf(idx)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
if n.children == 0 {
|
if isnil(n.children) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
flag := if idx == n.len { true } else { false }
|
flag := if idx == n.len { true } else { false }
|
||||||
|
@ -250,7 +250,7 @@ fn (mut n mapnode) remove_from_non_leaf(idx int) {
|
||||||
k := n.keys[idx]
|
k := n.keys[idx]
|
||||||
if unsafe { &mapnode(n.children[idx]) }.len >= degree {
|
if unsafe { &mapnode(n.children[idx]) }.len >= degree {
|
||||||
mut current := unsafe { &mapnode(n.children[idx]) }
|
mut current := unsafe { &mapnode(n.children[idx]) }
|
||||||
for current.children != 0 {
|
for !isnil(current.children) {
|
||||||
current = unsafe { &mapnode(current.children[current.len]) }
|
current = unsafe { &mapnode(current.children[current.len]) }
|
||||||
}
|
}
|
||||||
predecessor := current.keys[current.len - 1]
|
predecessor := current.keys[current.len - 1]
|
||||||
|
@ -260,7 +260,7 @@ fn (mut n mapnode) remove_from_non_leaf(idx int) {
|
||||||
node.remove_key(predecessor)
|
node.remove_key(predecessor)
|
||||||
} else if unsafe { &mapnode(n.children[idx + 1]) }.len >= degree {
|
} else if unsafe { &mapnode(n.children[idx + 1]) }.len >= degree {
|
||||||
mut current := unsafe { &mapnode(n.children[idx + 1]) }
|
mut current := unsafe { &mapnode(n.children[idx + 1]) }
|
||||||
for current.children != 0 {
|
for !isnil(current.children) {
|
||||||
current = unsafe { &mapnode(current.children[0]) }
|
current = unsafe { &mapnode(current.children[0]) }
|
||||||
}
|
}
|
||||||
successor := current.keys[0]
|
successor := current.keys[0]
|
||||||
|
@ -294,7 +294,7 @@ fn (mut n mapnode) borrow_from_prev(idx int) {
|
||||||
child.keys[i + 1] = child.keys[i]
|
child.keys[i + 1] = child.keys[i]
|
||||||
child.values[i + 1] = child.values[i]
|
child.values[i + 1] = child.values[i]
|
||||||
}
|
}
|
||||||
if child.children != 0 {
|
if !isnil(child.children) {
|
||||||
for i := child.len; i >= 0; i-- {
|
for i := child.len; i >= 0; i-- {
|
||||||
unsafe {
|
unsafe {
|
||||||
child.children[i + 1] = child.children[i]
|
child.children[i + 1] = child.children[i]
|
||||||
|
@ -303,7 +303,7 @@ fn (mut n mapnode) borrow_from_prev(idx int) {
|
||||||
}
|
}
|
||||||
child.keys[0] = n.keys[idx - 1]
|
child.keys[0] = n.keys[idx - 1]
|
||||||
child.values[0] = n.values[idx - 1]
|
child.values[0] = n.values[idx - 1]
|
||||||
if child.children != 0 {
|
if !isnil(child.children) {
|
||||||
unsafe {
|
unsafe {
|
||||||
child.children[0] = sibling.children[sibling.len]
|
child.children[0] = sibling.children[sibling.len]
|
||||||
}
|
}
|
||||||
|
@ -319,7 +319,7 @@ fn (mut n mapnode) borrow_from_next(idx int) {
|
||||||
mut sibling := unsafe { &mapnode(n.children[idx + 1]) }
|
mut sibling := unsafe { &mapnode(n.children[idx + 1]) }
|
||||||
child.keys[child.len] = n.keys[idx]
|
child.keys[child.len] = n.keys[idx]
|
||||||
child.values[child.len] = n.values[idx]
|
child.values[child.len] = n.values[idx]
|
||||||
if child.children != 0 {
|
if !isnil(child.children) {
|
||||||
unsafe {
|
unsafe {
|
||||||
child.children[child.len + 1] = sibling.children[0]
|
child.children[child.len + 1] = sibling.children[0]
|
||||||
}
|
}
|
||||||
|
@ -330,7 +330,7 @@ fn (mut n mapnode) borrow_from_next(idx int) {
|
||||||
sibling.keys[i - 1] = sibling.keys[i]
|
sibling.keys[i - 1] = sibling.keys[i]
|
||||||
sibling.values[i - 1] = sibling.values[i]
|
sibling.values[i - 1] = sibling.values[i]
|
||||||
}
|
}
|
||||||
if sibling.children != 0 {
|
if !isnil(sibling.children) {
|
||||||
for i := 1; i <= sibling.len; i++ {
|
for i := 1; i <= sibling.len; i++ {
|
||||||
unsafe {
|
unsafe {
|
||||||
sibling.children[i - 1] = sibling.children[i]
|
sibling.children[i - 1] = sibling.children[i]
|
||||||
|
@ -350,7 +350,7 @@ fn (mut n mapnode) merge(idx int) {
|
||||||
child.keys[i + degree] = sibling.keys[i]
|
child.keys[i + degree] = sibling.keys[i]
|
||||||
child.values[i + degree] = sibling.values[i]
|
child.values[i + degree] = sibling.values[i]
|
||||||
}
|
}
|
||||||
if child.children != 0 {
|
if !isnil(child.children) {
|
||||||
for i := 0; i <= sibling.len; i++ {
|
for i := 0; i <= sibling.len; i++ {
|
||||||
unsafe {
|
unsafe {
|
||||||
child.children[i + degree] = sibling.children[i]
|
child.children[i + degree] = sibling.children[i]
|
||||||
|
@ -383,10 +383,11 @@ pub fn (mut m SortedMap) delete(key string) {
|
||||||
|
|
||||||
if m.root.len == 0 {
|
if m.root.len == 0 {
|
||||||
// tmp := t.root
|
// tmp := t.root
|
||||||
if m.root.children == 0 {
|
if isnil(m.root.children) {
|
||||||
return
|
return
|
||||||
|
} else {
|
||||||
|
m.root = unsafe { &mapnode(m.root.children[0]) }
|
||||||
}
|
}
|
||||||
m.root = unsafe { &mapnode(m.root.children[0]) }
|
|
||||||
// free(tmp)
|
// free(tmp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -395,7 +396,7 @@ pub fn (mut m SortedMap) delete(key string) {
|
||||||
// starting at `at`. Keys are inserted in order.
|
// starting at `at`. Keys are inserted in order.
|
||||||
fn (n &mapnode) subkeys(mut keys []string, at int) int {
|
fn (n &mapnode) subkeys(mut keys []string, at int) int {
|
||||||
mut position := at
|
mut position := at
|
||||||
if n.children != 0 {
|
if !isnil(n.children) {
|
||||||
// Traverse children and insert
|
// Traverse children and insert
|
||||||
// keys inbetween children
|
// keys inbetween children
|
||||||
for i in 0 .. n.len {
|
for i in 0 .. n.len {
|
||||||
|
@ -420,7 +421,7 @@ fn (n &mapnode) subkeys(mut keys []string, at int) int {
|
||||||
|
|
||||||
pub fn (m &SortedMap) keys() []string {
|
pub fn (m &SortedMap) keys() []string {
|
||||||
mut keys := []string{len: m.len}
|
mut keys := []string{len: m.len}
|
||||||
if m.root == 0 || m.root.len == 0 {
|
if isnil(m.root) || m.root.len == 0 {
|
||||||
return keys
|
return keys
|
||||||
}
|
}
|
||||||
m.root.subkeys(mut keys, 0)
|
m.root.subkeys(mut keys, 0)
|
||||||
|
@ -432,7 +433,7 @@ fn (mut n mapnode) free() {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut m SortedMap) free() {
|
pub fn (mut m SortedMap) free() {
|
||||||
if m.root == 0 {
|
if isnil(m.root) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
m.root.free()
|
m.root.free()
|
||||||
|
|
|
@ -38,7 +38,7 @@ pub fn new_scope(parent &Scope, start_pos int) &Scope {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
fn (s &Scope) dont_lookup_parent() bool {
|
fn (s &Scope) dont_lookup_parent() bool {
|
||||||
return s.parent == 0 || s.detached_from_parent
|
return isnil(s.parent) || s.detached_from_parent
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (s &Scope) find_with_scope(name string) ?(ScopeObject, &Scope) {
|
pub fn (s &Scope) find_with_scope(name string) ?(ScopeObject, &Scope) {
|
||||||
|
|
|
@ -2842,7 +2842,7 @@ fn (mut g Gen) trace_autofree(line string) {
|
||||||
|
|
||||||
// fn (mut g Gen) autofree_scope_vars2(scope &ast.Scope, end_pos int) {
|
// fn (mut g Gen) autofree_scope_vars2(scope &ast.Scope, end_pos int) {
|
||||||
fn (mut g Gen) autofree_scope_vars2(scope &ast.Scope, start_pos int, end_pos int, line_nr int, free_parent_scopes bool, stop_pos int) {
|
fn (mut g Gen) autofree_scope_vars2(scope &ast.Scope, start_pos int, end_pos int, line_nr int, free_parent_scopes bool, stop_pos int) {
|
||||||
if scope == 0 {
|
if isnil(scope) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, obj in scope.objects {
|
for _, obj in scope.objects {
|
||||||
|
|
Loading…
Reference in New Issue