FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
daScript/src/simulate/runtime_array.cpp at master · harold-b/daScript · GitHub
harold-b
/
daScript
Public
forked from
GaijinEntertainment/daScript
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
daScript
/
src
/
simulate
/
runtime_array.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
143 lines (125 loc) · 5 KB
Breadcrumbs
daScript
/
src
/
simulate
/
runtime_array.cpp
Copy path
File metadata and controls
143 lines (125 loc) · 5 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#
include
"
daScript/misc/platform.h
"
#
include
"
daScript/simulate/runtime_array.h
"
namespace
das
{
void
array_clear
( Context & context, Array & arr ) {
if
( arr.
isLocked
() ) context.
throw_error
(
"
can't clear locked array
"
);
arr.
size
=
0
;
}
void
array_lock
( Context & context, Array & arr ) {
if
( arr.
shared
|| arr.
hopeless
)
return
;
arr.
lock
++;
if
( arr.
lock
==
0
) context.
throw_error
(
"
array lock overflow
"
);
}
void
array_unlock
( Context & context, Array & arr ) {
if
( arr.
shared
|| arr.
hopeless
)
return
;
if
( arr.
lock
==
0
) context.
throw_error
(
"
array lock underflow
"
);
arr.
lock
--;
}
void
array_reserve
(Context & context, Array & arr,
uint32_t
newCapacity,
uint32_t
stride) {
if
( arr.
isLocked
() ) context.
throw_error
(
"
can't change capacity of a locked array
"
);
if
( arr.
capacity
>= newCapacity )
return
;
auto
newData = (
char
*)context.
heap
->
reallocate
(arr.
data
, arr.
capacity
*stride, newCapacity*stride);
if
( !newData ) context.
throw_error
(
"
out of linear allocator memory
"
);
context.
heap
->
mark_comment
(newData,
"
array
"
);
if
( newData != arr.
data
) {
//
memcpy(newData, arr.data, arr.capacity);
arr.
data
= newData;
}
arr.
capacity
= newCapacity;
}
void
array_resize
( Context & context, Array & arr,
uint32_t
newSize,
uint32_t
stride,
bool
zero ) {
if
( arr.
isLocked
() ) context.
throw_error
(
"
can't resize locked array
"
);
if
( newSize > arr.
capacity
) {
uint32_t
newCapacity =
1
<< (
32
-
__builtin_clz
(
das::max
(newSize,
2u
) -
1
));
newCapacity =
das::max
(newCapacity,
16u
);
array_reserve
(context, arr, newCapacity, stride);
}
if
( zero && newSize>arr.
size
) {
memset
( arr.
data
+ arr.
size
*stride,
0
, (newSize-arr.
size
)*stride );
}
arr.
size
= newSize;
}
//
GoodArrayIterator
bool
GoodArrayIterator::first
( Context & context,
char
* _value ) {
char
** value = (
char
**) _value;
array_lock
(context, *array);
data = array->
data
;
*value = data;
array_end = data + array->
size
* stride;
return
(
bool
) array->
size
;
}
bool
GoodArrayIterator::next
( Context &,
char
* _value ) {
char
** value = (
char
**) _value;
data += stride;
*value = data;
return
data != array_end;
}
void
GoodArrayIterator::close
( Context & context,
char
* _value ) {
if
( _value ) {
char
** value = (
char
**) _value;
*value =
nullptr
;
}
array_unlock
(context, *array);
context.
heap
->
free
((
char
*)
this
,
sizeof
(GoodArrayIterator));
}
vec4f
SimNode_GoodArrayIterator::eval
( Context & context ) {
DAS_PROFILE_NODE
vec4f ll = source->
eval
(context);
Array * arr = cast<Array *>::
to
(ll);
char
* iter = context.
heap
->
allocate
(
sizeof
(GoodArrayIterator));
context.
heap
->
mark_comment
(iter,
"
array<> iterator
"
);
context.
heap
->
mark_location
(iter,&debugInfo);
new
(iter)
GoodArrayIterator
(arr, stride);
return
cast<
char
*>::
from
(iter);
}
//
FixedArrayIterator
bool
FixedArrayIterator::first
( Context &,
char
* _value ) {
char
** value = (
char
**) _value;
*value = data;
fixed_array_end = data + size*stride;
return
(
bool
) size;
}
bool
FixedArrayIterator::next
( Context & ,
char
* _value ) {
char
** value = (
char
**) _value;
data += stride;
*value = data;
return
data != fixed_array_end;
}
void
FixedArrayIterator::close
( Context & context,
char
* _value ) {
if
( _value ) {
char
** value = (
char
**) _value;
*value =
nullptr
;
}
context.
heap
->
free
((
char
*)
this
,
sizeof
(FixedArrayIterator));
}
vec4f
SimNode_FixedArrayIterator::eval
( Context & context ) {
DAS_PROFILE_NODE
vec4f ll = source->
eval
(context);
char
* data = cast<
char
*>::
to
(ll);
char
* iter = context.
heap
->
allocate
(
sizeof
(FixedArrayIterator));
context.
heap
->
mark_comment
(iter,
"
fixed array iterator
"
);
context.
heap
->
mark_location
(iter,&debugInfo);
new
(iter)
FixedArrayIterator
(data, size, stride);
return
cast<
char
*>::
from
(iter);
}
//
delete
vec4f
SimNode_DeleteArray::eval
( Context & context ) {
DAS_PROFILE_NODE
auto
pArray = (Array *) subexpr->
evalPtr
(context);
pArray = pArray + total -
1
;
for
(
uint32_t
i=
0
; i!=total; ++i, pArray-- ) {
if
( pArray->
data
) {
if
( !pArray->
isLocked
() ) {
uint32_t
oldSize = pArray->
capacity
*stride;
context.
heap
->
free
(pArray->
data
, oldSize);
}
else
{
context.
throw_error
(
"
deleting locked array
"
);
return
v_zero
();
}
}
memset
( pArray,
0
,
sizeof
(Array) );
}
return
v_zero
();
}
}
Back
|
FazBrowse Home
|
New Git URL