for loops
This commit is contained in:
@@ -59,6 +59,7 @@ Kind :: enum u8 {
|
||||
Array,
|
||||
Pointer,
|
||||
Slice,
|
||||
Range,
|
||||
Optional,
|
||||
Function,
|
||||
Named,
|
||||
@@ -392,7 +393,7 @@ is_concrete_scalar :: proc(value: Type) -> bool {
|
||||
is_concrete :: proc(value: Type, store: ^Store = nil) -> bool {
|
||||
value_kind := kind(value, store)
|
||||
if value_kind == .Scalar || value_kind == .Array || value_kind == .Pointer ||
|
||||
value_kind == .Slice || value_kind == .Optional {
|
||||
value_kind == .Slice || value_kind == .Range || value_kind == .Optional {
|
||||
return true
|
||||
}
|
||||
if value_kind == .Struct || value_kind == .Union {
|
||||
@@ -414,6 +415,10 @@ is_slice :: proc(value: Type, store: ^Store) -> bool {
|
||||
return kind(value, store) == .Slice
|
||||
}
|
||||
|
||||
is_range :: proc(value: Type, store: ^Store) -> bool {
|
||||
return kind(value, store) == .Range
|
||||
}
|
||||
|
||||
is_optional :: proc(value: Type, store: ^Store) -> bool {
|
||||
return kind(value, store) == .Optional
|
||||
}
|
||||
@@ -486,7 +491,7 @@ is_runtime_value :: proc(value: Type, store: ^Store) -> bool {
|
||||
if value_kind == .Scalar || value_kind == .Pointer {
|
||||
return true
|
||||
}
|
||||
if value_kind == .Slice || value_kind == .Array || value_kind == .Optional {
|
||||
if value_kind == .Slice || value_kind == .Array || value_kind == .Range || value_kind == .Optional {
|
||||
return !contains_c_struct_by_value(value, store)
|
||||
}
|
||||
if value_kind == .Struct || value_kind == .Union {
|
||||
@@ -521,7 +526,7 @@ contains_c_struct_by_value :: proc(value: Type, store: ^Store, depth := 0) -> bo
|
||||
if item.kind == .Union {
|
||||
return item.opaque || (item.c_layout && item.field_count == 0)
|
||||
}
|
||||
if item.kind == .Array || item.kind == .Slice || item.kind == .Optional {
|
||||
if item.kind == .Array || item.kind == .Slice || item.kind == .Range || item.kind == .Optional {
|
||||
return contains_c_struct_by_value(item.child, store, depth+1)
|
||||
}
|
||||
return false
|
||||
@@ -665,6 +670,10 @@ slice :: proc(store: ^Store, child: Type, mutable: bool, has_sentinel := false,
|
||||
})
|
||||
}
|
||||
|
||||
range :: proc(store: ^Store, child: Type) -> Type {
|
||||
return intern(store, Node{kind=.Range, child=child})
|
||||
}
|
||||
|
||||
array :: proc(
|
||||
store: ^Store,
|
||||
child: Type,
|
||||
@@ -805,6 +814,11 @@ size :: proc(value: Type, store: ^Store, selected := target.DEFAULT) -> u64 {
|
||||
return u64(target.pointer_bits(selected)/8)
|
||||
case .Slice:
|
||||
return u64(target.pointer_bits(selected)/8*2)
|
||||
case .Range:
|
||||
child_size := size(child_type(value, store), store, selected)
|
||||
child_align := u64(alignment_of(child_type(value, store), store, selected))
|
||||
raw_size := child_size*2+1
|
||||
return (raw_size+child_align-1)/child_align*child_align
|
||||
case .Array:
|
||||
item, _ := node(store, value)
|
||||
return physical_count(value, store)*size(item.child, store, selected)
|
||||
@@ -855,7 +869,7 @@ alignment_of :: proc(value: Type, store: ^Store, selected := target.DEFAULT) ->
|
||||
return alignment(value, selected)
|
||||
case .Pointer, .Slice:
|
||||
return target.pointer_bits(selected)/8
|
||||
case .Array, .Optional:
|
||||
case .Array, .Range, .Optional:
|
||||
return alignment_of(child_type(value, store), store, selected)
|
||||
case .Function:
|
||||
return 1
|
||||
|
||||
Reference in New Issue
Block a user