Skip to content

Commit b9932bf

Browse files
committed
CHANGE: logic, none and datatype values are now always molded using construction syntax
resolves: Oldes/Rebol-issues#2159
1 parent 9c2d34d commit b9932bf

File tree

4 files changed

+24
-28
lines changed

4 files changed

+24
-28
lines changed

src/core/s-mold.c

+11-15
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,14 @@ enum {
124124
case 'N': // Symbol name
125125
Append_UTF8(series, Get_Sym_Name(va_arg(args, REBCNT)), -1);
126126
break;
127-
case '+': // Add #[ if mold/all
127+
case '+': // Add #( if mold/all
128128
if (GET_MOPT(mold, MOPT_MOLD_ALL)) {
129129
Append_Bytes(series, "#(");
130130
ender = ')';
131131
}
132132
break;
133-
case 'D': // Datatype symbol: #[type
134-
if (ender) {
135-
Append_UTF8(series, Get_Sym_Name(va_arg(args, REBCNT)), -1);
136-
Append_Byte(series, ' ');
137-
} else va_arg(args, REBCNT); // ignore it
133+
case 'D': // Datatype symbol: #(type
134+
Append_UTF8(series, Get_Sym_Name(va_arg(args, REBCNT)), -1);
138135
break;
139136
case 'B': // Boot string
140137
Append_Boot_Str(series, va_arg(args, REBINT));
@@ -1181,14 +1178,11 @@ STOID Mold_Error(REBVAL *value, REB_MOLD *mold, REBFLG molded)
11811178

11821179
switch (VAL_TYPE(value)) {
11831180
case REB_NONE:
1184-
Emit(mold, "+N", SYM_NONE);
1181+
Append_Bytes(ser, molded ? "#(none)" : "none");
11851182
break;
11861183

11871184
case REB_LOGIC:
1188-
// if (!molded || !VAL_LOGIC_WORDS(value) || !GET_MOPT(mold, MOPT_MOLD_ALL))
1189-
Emit(mold, "+N", VAL_LOGIC(value) ? SYM_TRUE : SYM_FALSE);
1190-
// else
1191-
// Mold_Logic(mold, value);
1185+
Append_Bytes(ser, VAL_LOGIC(value) ? (molded?"#(true)":"true") : (molded?"#(false)":"false"));
11921186
break;
11931187

11941188
case REB_INTEGER:
@@ -1329,10 +1323,12 @@ STOID Mold_Error(REBVAL *value, REB_MOLD *mold, REBFLG molded)
13291323
break;
13301324

13311325
case REB_DATATYPE:
1332-
if (!molded)
1333-
Emit(mold, "N", VAL_DATATYPE(value) + 1);
1334-
else
1335-
Emit(mold, "+N", VAL_DATATYPE(value) + 1);
1326+
if (molded) {
1327+
Emit(mold, "#(D)", VAL_DATATYPE(value) + 1);
1328+
}
1329+
else {
1330+
Append_UTF8(ser, Get_Sym_Name(VAL_DATATYPE(value) + 1), -1);
1331+
}
13361332
break;
13371333

13381334
case REB_TYPESET:

src/mezz/mezz-help.reb

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ import (module [
8888
]
8989

9090
form-type: func [value] [
91-
a-an head clear back tail mold type? :value
91+
a-an head clear back tail form type? :value
9292
]
9393

9494
form-val: func [val /local limit hdr tmp] [
@@ -111,7 +111,7 @@ import (module [
111111
image? :val [ mold/part/all/flat val max-desc-width]
112112
gob? :val [ return reform ["offset:" val/offset "size:" val/size] ]
113113
vector? :val [ mold/part/all/flat val max-desc-width]
114-
;none? :val [ mold/all val]
114+
any [logic? :val none? :val unset? :val] [ form val ]
115115
true [:val]
116116
]
117117
unless string? val [val: mold/part/flat val max-desc-width]

src/tests/units/evaluation-test.r3

+3-3
Original file line numberDiff line numberDiff line change
@@ -558,15 +558,15 @@ Rebol [
558558
obj: object [a: 3 b: 4]
559559
obj2: object [z: 0 a: none b: 7]
560560
--assert obj2 = set obj obj2
561-
--assert "make object! [a: none b: 7]" = mold/flat obj
562-
--assert "make object! [z: 0 a: none b: 7]" = mold/flat obj2
561+
--assert "make object! [a: #(none) b: 7]" = mold/flat obj
562+
--assert "make object! [z: 0 a: #(none) b: 7]" = mold/flat obj2
563563

564564
--test-- "set-11"
565565
obj: object [a: 3 b: 4]
566566
obj2: object [z: 0 a: none b: 7]
567567
--assert obj2 = set/some obj obj2
568568
--assert "make object! [a: 3 b: 7]" = mold/flat obj
569-
--assert "make object! [z: 0 a: none b: 7]" = mold/flat obj2
569+
--assert "make object! [z: 0 a: #(none) b: 7]" = mold/flat obj2
570570

571571
--test-- "set-12"
572572
o1: object [a: 1 b: 2 ]

src/tests/units/mold-test.r3

+8-8
Original file line numberDiff line numberDiff line change
@@ -263,23 +263,23 @@ Rebol [
263263

264264

265265
===start-group=== "mold-all"
266-
267-
--test-- "mold-true" --assert "true" = mold true
266+
;@@ https://github.com/Oldes/Rebol-issues/issues/2159
267+
--test-- "mold-true" --assert "#(true)" = mold true
268268

269269
--test-- "mold-all-true" --assert "#(true)" = mold/all true
270270

271-
--test-- "mold-false" --assert "false" = mold false
271+
--test-- "mold-false" --assert "#(false)" = mold false
272272

273273
--test-- "mold-all-false" --assert "#(false)" = mold/all false
274274

275-
--test-- "mold-none" --assert "none" = mold none
275+
--test-- "mold-none" --assert "#(none)" = mold none
276276

277277
--test-- "mold-all-none" --assert "#(none)" = mold/all none
278278

279-
--test-- "mold-block" --assert "[true false none]" = mold [#(true) #(false) #(none)]
279+
--test-- "mold-block" --assert "[true false none #(true) #(false) #(none)]" = mold [true false none #(true) #(false) #(none)]
280280

281281
--test-- "mold-all-block"
282-
--assert "[#(true) #(false) #(none)]" = mold/all [#(true) #(false) #(none)]
282+
--assert "[true false none #(true) #(false) #(none)]" = mold/all [true false none #(true) #(false) #(none)]
283283

284284
--test-- "mold/all block at tail"
285285
;@@ https://github.com/Oldes/Rebol-issues/issues/1192
@@ -567,7 +567,7 @@ Rebol [
567567
--test-- "mold unset!"
568568
--assert "#(unset)" = mold ()
569569
--assert "#(unset)" = mold/all ()
570-
--assert "unset!" = mold type? ()
570+
--assert "#(unset!)" = mold type? ()
571571
--assert "#(unset!)" = mold/all type? ()
572572
--test-- "form unset!"
573573
--assert "" = form ()
@@ -634,7 +634,7 @@ Rebol [
634634
===start-group=== "mold error!"
635635
--test-- "mold error!"
636636
;@@ https://github.com/Oldes/Rebol-issues/issues/1003
637-
--assert {make error! [code: 101 type: 'Note id: 'exited arg1: none arg2: none arg3: none near: none where: none]} = mold/flat make error! [type: 'Note id: 'exited]
637+
--assert {make error! [code: 101 type: 'Note id: 'exited arg1: #(none) arg2: #(none) arg3: #(none) near: #(none) where: #(none)]} = mold/flat make error! [type: 'Note id: 'exited]
638638
--assert {#(error! [code: 101 type: Note id: exited arg1: #(none) arg2: #(none) arg3: #(none) near: #(none) where: #(none)])} = mold/all/flat make error! [type: 'Note id: 'exited]
639639
--assert {#(error! [code: 401 type: Math id: overflow arg1: #(none) arg2: #(none) arg3: #(none) near: #(none) where: #(none)])} = mold/all/flat make error! [type: 'Math id: 'overflow]
640640
===end-group===

0 commit comments

Comments
 (0)