Skip to content

Commit

Permalink
FEAT: added support for copy/deep and copy/types on map! datatype
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Mar 1, 2018
1 parent d7eb95c commit fe0886f
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/core/t-map.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,15 @@

/***********************************************************************
**
*/ REBFLG MT_Map(REBVAL *out, REBVAL *data, REBCNT type)
*/ REBFLG MT_Map(REBVAL *out, REBVAL *data, REBCNT type, REBU64 types)
/*
***********************************************************************/
{
/*
Oldes asking:
1. What means the MT in the function name?
2. What is purpose of the unused `type` argument?

This comment has been minimized.

Copy link
@hostilefork

hostilefork Mar 1, 2018

Some "Make Type" handlers are for a class of types. E.g. a MT_String is used for TAG!, BINARY!, etc. too:

https://github.com/rebol/rebol/blob/25033f897b2bd466068d7663563cd3ff64740b94/src/core/t-string.c#L275

MAP! doesn't use it because there is nothing else in its class. It could say:

assert(type == REB_MAP);
UNUSED(type);

And Ren-C does this kind of thing. Because all unused parameters must be explicitly marked so.

This catches bugs--really! Your case here would be a good example, because ignoring the /DEEP and /TYPES refinements without giving some kind of reaction causes a compiler error. That way you don't have to invisibly discover that it didn't heed them.

*/
REBCNT n;
REBSER *series;

Expand All @@ -316,6 +321,8 @@
//COPY_BLK_PART(series, VAL_BLK_DATA(data), n);
Append_Map(series, data, UNKNOWN);

if (types != 0) Copy_Deep_Values(series, 0, SERIES_TAIL(series), types);

Rehash_Hash(series);

Set_Series(REB_MAP, out, series);
Expand Down Expand Up @@ -466,7 +473,7 @@
case A_TO:
// make map! [word val word val]
if (IS_BLOCK(arg) || IS_PAREN(arg) || IS_MAP(arg)) {
if (MT_Map(D_RET, arg, 0)) return R_RET;
if (MT_Map(D_RET, arg, 0, 0)) return R_RET;
Trap_Arg(arg);
// } else if (IS_NONE(arg)) {
// n = 3; // just a start
Expand All @@ -481,10 +488,20 @@
Set_Series(REB_MAP, D_RET, series);
break;

case A_COPY:
if (MT_Map(D_RET, val, 0)) return R_RET;
case A_COPY: {
REBU64 types = 0;
if (D_REF(ARG_COPY_DEEP)) {
//puts("deep copy wanted");
types |= CP_DEEP | (D_REF(ARG_COPY_TYPES) ? 0 : TS_STD_SERIES);
}
if D_REF(ARG_COPY_TYPES) {
arg = D_ARG(ARG_COPY_KINDS);
if (IS_DATATYPE(arg)) types |= TYPESET(VAL_DATATYPE(arg));
else types |= VAL_TYPESET(arg);
}
if (MT_Map(D_RET, val, 0, types)) return R_RET;
Trap_Arg(val);

}
case A_CLEAR:
Clear_Series(series);
if (series->series) Clear_Series(series->series);
Expand Down

0 comments on commit fe0886f

Please sign in to comment.