Skip to content

Commit fe0886f

Browse files
committed
FEAT: added support for copy/deep and copy/types on map! datatype
1 parent d7eb95c commit fe0886f

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

src/core/t-map.c

+22-5
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,15 @@
299299

300300
/***********************************************************************
301301
**
302-
*/ REBFLG MT_Map(REBVAL *out, REBVAL *data, REBCNT type)
302+
*/ REBFLG MT_Map(REBVAL *out, REBVAL *data, REBCNT type, REBU64 types)
303303
/*
304304
***********************************************************************/
305305
{
306+
/*
307+
Oldes asking:
308+
1. What means the MT in the function name?
309+
2. What is purpose of the unused `type` argument?
310+
*/
306311
REBCNT n;
307312
REBSER *series;
308313

@@ -316,6 +321,8 @@
316321
//COPY_BLK_PART(series, VAL_BLK_DATA(data), n);
317322
Append_Map(series, data, UNKNOWN);
318323

324+
if (types != 0) Copy_Deep_Values(series, 0, SERIES_TAIL(series), types);
325+
319326
Rehash_Hash(series);
320327

321328
Set_Series(REB_MAP, out, series);
@@ -466,7 +473,7 @@
466473
case A_TO:
467474
// make map! [word val word val]
468475
if (IS_BLOCK(arg) || IS_PAREN(arg) || IS_MAP(arg)) {
469-
if (MT_Map(D_RET, arg, 0)) return R_RET;
476+
if (MT_Map(D_RET, arg, 0, 0)) return R_RET;
470477
Trap_Arg(arg);
471478
// } else if (IS_NONE(arg)) {
472479
// n = 3; // just a start
@@ -481,10 +488,20 @@
481488
Set_Series(REB_MAP, D_RET, series);
482489
break;
483490

484-
case A_COPY:
485-
if (MT_Map(D_RET, val, 0)) return R_RET;
491+
case A_COPY: {
492+
REBU64 types = 0;
493+
if (D_REF(ARG_COPY_DEEP)) {
494+
//puts("deep copy wanted");
495+
types |= CP_DEEP | (D_REF(ARG_COPY_TYPES) ? 0 : TS_STD_SERIES);
496+
}
497+
if D_REF(ARG_COPY_TYPES) {
498+
arg = D_ARG(ARG_COPY_KINDS);
499+
if (IS_DATATYPE(arg)) types |= TYPESET(VAL_DATATYPE(arg));
500+
else types |= VAL_TYPESET(arg);
501+
}
502+
if (MT_Map(D_RET, val, 0, types)) return R_RET;
486503
Trap_Arg(val);
487-
504+
}
488505
case A_CLEAR:
489506
Clear_Series(series);
490507
if (series->series) Clear_Series(series->series);

0 commit comments

Comments
 (0)