Skip to content

Commit 1ca9df5

Browse files
committed
FIX: implemented append/part and append/dup
resolves: Oldes/Rebol-issues#1754
1 parent dbb8751 commit 1ca9df5

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

src/core/t-object.c

+9-5
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ static REBOOL Equal_Object(REBVAL *val, REBVAL *arg)
7070
return TRUE;
7171
}
7272

73-
static void Append_Obj(REBSER *obj, REBVAL *arg)
73+
static void Append_Obj(REBSER *obj, REBVAL *arg, REBCNT part)
7474
{
75-
REBCNT i, len;
75+
REBCNT i, n, len;
7676
REBVAL *word, *val;
7777
REBINT *binds; // for binding table
7878

@@ -102,7 +102,7 @@ static void Append_Obj(REBSER *obj, REBVAL *arg)
102102
Collect_Object(obj);
103103

104104
// Examine word/value argument block
105-
for (word = arg; NOT_END(word); word += 2) {
105+
for (word = arg, n = 0; ++n < part && NOT_END(word); word += 2, n++) {
106106

107107
if (!IS_WORD(word) && !IS_SET_WORD(word)) {
108108
// release binding table
@@ -138,7 +138,7 @@ static void Append_Obj(REBSER *obj, REBVAL *arg)
138138
Append_Frame(obj, 0, VAL_WORD_SYM(word));
139139

140140
// Set new values to obj words
141-
for (word = arg; NOT_END(word); word += 2) {
141+
for (word = arg, n = 0; ++n < part && NOT_END(word); word += 2, n++) {
142142

143143
i = binds[VAL_WORD_CANON(word)];
144144
val = FRM_VALUE(obj, i);
@@ -440,7 +440,11 @@ static REBSER *Trim_Object(REBSER *obj)
440440
case A_INSERT:
441441
TRAP_PROTECT(VAL_SERIES(value));
442442
if (IS_OBJECT(value)) {
443-
Append_Obj(VAL_OBJ_FRAME(value), arg);
443+
if (DS_REF(AN_DUP)) {
444+
n = Int32(DS_ARG(AN_COUNT));
445+
if (n <= 0) break;
446+
}
447+
Append_Obj(VAL_OBJ_FRAME(value), arg, Partial1(arg, D_ARG(AN_LENGTH)));
444448
return R_ARG1;
445449
}
446450
else

src/tests/units/object-test.r3

+17-2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,19 @@ Rebol [
6060
error? e: try [append obj [a: 2]]
6161
e/id = 'hidden
6262
]
63+
--test-- "append/part object!"
64+
;@@ https://github.com/Oldes/Rebol-issues/issues/1754
65+
--assert [] == body-of append/part make object! [] [a 1 b 2 c 3] 1
66+
--assert [a: 1] == body-of append/part make object! [] [a 1 b 2 c 3] 2
67+
--assert [a: 1] == body-of append/part make object! [] [a 1 b 2 c 3] 3
68+
--assert [a: 1 b: 2] == body-of append/part make object! [] [a 1 b 2 c 3] 4
69+
--assert [a: 1 b: 2] == body-of append/part make object! [] b: [a 1 b 2 c 3] find b 'c
70+
--assert [a: 1 b: 2] == body-of append/part make object! [a: 10] [a 1 b 2 c 3] 4
71+
--assert [b: 2 c: 3] == body-of append/part make object! [] tail [a 1 b 2 c 3] -4
72+
--test-- "append/dup object!"
73+
--assert [] == body-of append/dup make object! [] [a 1] 0
74+
--assert [a: 1] == body-of append/dup make object! [] [a 1] 1
75+
--assert [a: 1] == body-of append/dup make object! [] [a 1] 10
6376
===end-group===
6477

6578

@@ -295,8 +308,10 @@ Rebol [
295308
o: object []
296309
append o 'x
297310
--assert unset? o/x
298-
append o [y]
299-
--assert unset? o/y
311+
append o [y] ; does nothing now!
312+
--assert [x] = keys-of o
313+
append o [y 100]
314+
--assert o/y = 100
300315
--assert object? append o [x: 1 y: 2]
301316
--assert o/x = 1
302317
--assert o/y = 2

0 commit comments

Comments
 (0)