Skip to content

Commit c98c9f8

Browse files
ADD array_repositioned
1 parent ec969d8 commit c98c9f8

File tree

5 files changed

+54
-27
lines changed

5 files changed

+54
-27
lines changed

std/core/structs.mx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
;; - inplace initialization of values
1515
;; %deinit()
1616
;; - inplace deinitialization of values
17+
;; %void_method repositioned(this)
18+
;; - move / duplicate values after copy (ie. referenced data)
19+
;; - calling this is user's responsibility
1720

1821

1922
%namespace struct {

std/ds/array.mx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@
5454
%seg:this(0, %init())
5555
}
5656

57+
; this ->
58+
; duplicates value array after repositioning (call after struct:move)
59+
%void_method{ array_repositioned, 1, 0,
60+
%seg:this(%capacity, str 0) ; force copy: this.capacity = 0
61+
%seg:push(%this, %size) ; this.reserve(this.size)
62+
%call(at_least_capacity)
63+
}
64+
5765
; this, index -> item (G_DEST)
5866
; safely indexes array
5967
%method{ index, 2, 0,

tests/std-array.mx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,18 @@
145145
%seg:push_addr(%local, 0)
146146
%call(array_print)
147147

148+
; copying
149+
%seg:push_addr(%local, 0)
150+
%array:shallow_copy()
151+
%stack:dup()
152+
%call(array_repositioned)
153+
%stack:top() ; copy stays at stack:top
154+
movm
155+
%print_endl(
156+
outc 'C'
157+
%array:default_print()
158+
)
159+
148160
%seg:push_addr(%local, 0)
149161
%stack:push(proc_int_lt_with_emit)
150162
%call(array_sort)
@@ -153,6 +165,8 @@
153165
%seg:push_addr(%local, 0)
154166
%call(array_print)
155167

168+
%call(array_print) ; unchanged copy
169+
156170
; init(1) = 32, sum with rest
157171
%seg:push_addr(%local, 0)
158172
%stack:push(proc_debug_reduce_init)

tests/std-array.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
:returncode 0
22

3-
:stdout 479
3+
:stdout 512
44
[]
55
[7, 8]
66
8
@@ -27,8 +27,10 @@ F: 2056 7 8 0
2727
725
2828
[8, 1, 3, 4]
2929
[6, 8, 9, 1, 3, 4, 7]
30+
C 2066 7 8
3031
6<8 8<9 9<1 8<1 6<1 9<3 8<3 6<3 1<3 9<4 8<4 6<4 3<4 9<7 8<7 6<7
3132
[1, 3, 4, 6, 7, 8, 9]
33+
[6, 8, 9, 1, 3, 4, 7]
3234
69
3335
36288
3436
2@65535

tests/std-struct.txt

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,38 @@ P 6 4 4 6
1515
1 2050 6,4
1616
2048: 2 1 6 4 61432 0 0 0
1717

18-
:stderr 2355
18+
:stderr 2357
1919
tests\std-struct.mx:19:3 ERROR: Invalid directive name '1st'
20-
std\core\structs.mx:107:11 ERROR: Define redefinition 'struct_id'
21-
std\core\structs.mx:27:10 ERROR: Macro redefinition 'new'
22-
std\core\structs.mx:31:10 ERROR: Macro redefinition 'dealloc'
23-
std\core\structs.mx:38:10 ERROR: Macro redefinition 'constructor'
24-
std\core\structs.mx:47:10 ERROR: Macro redefinition 'destructor'
25-
std\core\structs.mx:56:10 ERROR: Macro redefinition 'shallow_move'
26-
std\core\structs.mx:63:10 ERROR: Macro redefinition 'shallow_copy'
27-
std\core\structs.mx:75:10 ERROR: Macro redefinition 'at'
28-
std\core\structs.mx:80:10 ERROR: Macro redefinition 'reset'
29-
std\core\structs.mx:86:10 ERROR: Macro redefinition 'do_at'
30-
std\core\structs.mx:93:10 ERROR: Macro redefinition 'set'
31-
std\core\structs.mx:97:10 ERROR: Macro redefinition 'default_print'
20+
std\core\structs.mx:110:11 ERROR: Define redefinition 'struct_id'
21+
std\core\structs.mx:30:10 ERROR: Macro redefinition 'new'
22+
std\core\structs.mx:34:10 ERROR: Macro redefinition 'dealloc'
23+
std\core\structs.mx:41:10 ERROR: Macro redefinition 'constructor'
24+
std\core\structs.mx:50:10 ERROR: Macro redefinition 'destructor'
25+
std\core\structs.mx:59:10 ERROR: Macro redefinition 'shallow_move'
26+
std\core\structs.mx:66:10 ERROR: Macro redefinition 'shallow_copy'
27+
std\core\structs.mx:78:10 ERROR: Macro redefinition 'at'
28+
std\core\structs.mx:83:10 ERROR: Macro redefinition 'reset'
29+
std\core\structs.mx:89:10 ERROR: Macro redefinition 'do_at'
30+
std\core\structs.mx:96:10 ERROR: Macro redefinition 'set'
31+
std\core\structs.mx:100:10 ERROR: Macro redefinition 'default_print'
3232
tests\std-struct.mx:21:3 ERROR: Invalid directive name '2nd'
3333
tests\std-struct.mx:23:3 ERROR: Invalid directive name '3rd'
34-
std\core\structs.mx:107:11 ERROR: Define redefinition 'struct_id'
35-
std\core\structs.mx:27:10 ERROR: Macro redefinition 'new'
36-
std\core\structs.mx:31:10 ERROR: Macro redefinition 'dealloc'
37-
std\core\structs.mx:38:10 ERROR: Macro redefinition 'constructor'
38-
std\core\structs.mx:47:10 ERROR: Macro redefinition 'destructor'
39-
std\core\structs.mx:56:10 ERROR: Macro redefinition 'shallow_move'
40-
std\core\structs.mx:63:10 ERROR: Macro redefinition 'shallow_copy'
41-
std\core\structs.mx:75:10 ERROR: Macro redefinition 'at'
42-
std\core\structs.mx:80:10 ERROR: Macro redefinition 'reset'
43-
std\core\structs.mx:86:10 ERROR: Macro redefinition 'do_at'
44-
std\core\structs.mx:93:10 ERROR: Macro redefinition 'set'
45-
std\core\structs.mx:97:10 ERROR: Macro redefinition 'default_print'
34+
std\core\structs.mx:110:11 ERROR: Define redefinition 'struct_id'
35+
std\core\structs.mx:30:10 ERROR: Macro redefinition 'new'
36+
std\core\structs.mx:34:10 ERROR: Macro redefinition 'dealloc'
37+
std\core\structs.mx:41:10 ERROR: Macro redefinition 'constructor'
38+
std\core\structs.mx:50:10 ERROR: Macro redefinition 'destructor'
39+
std\core\structs.mx:59:10 ERROR: Macro redefinition 'shallow_move'
40+
std\core\structs.mx:66:10 ERROR: Macro redefinition 'shallow_copy'
41+
std\core\structs.mx:78:10 ERROR: Macro redefinition 'at'
42+
std\core\structs.mx:83:10 ERROR: Macro redefinition 'reset'
43+
std\core\structs.mx:89:10 ERROR: Macro redefinition 'do_at'
44+
std\core\structs.mx:96:10 ERROR: Macro redefinition 'set'
45+
std\core\structs.mx:100:10 ERROR: Macro redefinition 'default_print'
4646
tests\std-struct.mx:12:3 ERROR: Undeclared identifier '------------ 1 ------------'
4747
tests\std-struct.mx:31:2 ERROR: Missing directive name
4848
tests\std-struct.mx:12:3 ERROR: Undeclared identifier '------------ 2 ------------'
49-
std\core\structs.mx:119:11 ERROR: Define redefinition 'sizeof'
49+
std\core\structs.mx:122:11 ERROR: Define redefinition 'sizeof'
5050
tests\std-struct.mx:12:3 ERROR: Undeclared identifier '------------ 3 ------------'
5151
tests\std-struct.mx:46:2 ERROR: Undeclared identifier '0'
5252
tests\std-struct.mx:47:2 ERROR: Undeclared identifier '0'

0 commit comments

Comments
 (0)