Skip to content

Commit

Permalink
CHANGE: logic, none and datatype values are now always molded using c…
Browse files Browse the repository at this point in the history
…onstruction syntax

resolves: Oldes/Rebol-issues#2159
  • Loading branch information
Oldes committed Jul 19, 2024
1 parent 9c2d34d commit b9932bf
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 28 deletions.
26 changes: 11 additions & 15 deletions src/core/s-mold.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,14 @@ enum {
case 'N': // Symbol name
Append_UTF8(series, Get_Sym_Name(va_arg(args, REBCNT)), -1);
break;
case '+': // Add #[ if mold/all
case '+': // Add #( if mold/all
if (GET_MOPT(mold, MOPT_MOLD_ALL)) {
Append_Bytes(series, "#(");
ender = ')';
}
break;
case 'D': // Datatype symbol: #[type
if (ender) {
Append_UTF8(series, Get_Sym_Name(va_arg(args, REBCNT)), -1);
Append_Byte(series, ' ');
} else va_arg(args, REBCNT); // ignore it
case 'D': // Datatype symbol: #(type
Append_UTF8(series, Get_Sym_Name(va_arg(args, REBCNT)), -1);
break;
case 'B': // Boot string
Append_Boot_Str(series, va_arg(args, REBINT));
Expand Down Expand Up @@ -1181,14 +1178,11 @@ STOID Mold_Error(REBVAL *value, REB_MOLD *mold, REBFLG molded)

switch (VAL_TYPE(value)) {
case REB_NONE:
Emit(mold, "+N", SYM_NONE);
Append_Bytes(ser, molded ? "#(none)" : "none");
break;

case REB_LOGIC:
// if (!molded || !VAL_LOGIC_WORDS(value) || !GET_MOPT(mold, MOPT_MOLD_ALL))
Emit(mold, "+N", VAL_LOGIC(value) ? SYM_TRUE : SYM_FALSE);
// else
// Mold_Logic(mold, value);
Append_Bytes(ser, VAL_LOGIC(value) ? (molded?"#(true)":"true") : (molded?"#(false)":"false"));
break;

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

case REB_DATATYPE:
if (!molded)
Emit(mold, "N", VAL_DATATYPE(value) + 1);
else
Emit(mold, "+N", VAL_DATATYPE(value) + 1);
if (molded) {
Emit(mold, "#(D)", VAL_DATATYPE(value) + 1);
}
else {
Append_UTF8(ser, Get_Sym_Name(VAL_DATATYPE(value) + 1), -1);
}
break;

case REB_TYPESET:
Expand Down
4 changes: 2 additions & 2 deletions src/mezz/mezz-help.reb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ import (module [
]

form-type: func [value] [
a-an head clear back tail mold type? :value
a-an head clear back tail form type? :value
]

form-val: func [val /local limit hdr tmp] [
Expand All @@ -111,7 +111,7 @@ import (module [
image? :val [ mold/part/all/flat val max-desc-width]
gob? :val [ return reform ["offset:" val/offset "size:" val/size] ]
vector? :val [ mold/part/all/flat val max-desc-width]
;none? :val [ mold/all val]
any [logic? :val none? :val unset? :val] [ form val ]
true [:val]
]
unless string? val [val: mold/part/flat val max-desc-width]
Expand Down
6 changes: 3 additions & 3 deletions src/tests/units/evaluation-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -558,15 +558,15 @@ Rebol [
obj: object [a: 3 b: 4]
obj2: object [z: 0 a: none b: 7]
--assert obj2 = set obj obj2
--assert "make object! [a: none b: 7]" = mold/flat obj
--assert "make object! [z: 0 a: none b: 7]" = mold/flat obj2
--assert "make object! [a: #(none) b: 7]" = mold/flat obj
--assert "make object! [z: 0 a: #(none) b: 7]" = mold/flat obj2

--test-- "set-11"
obj: object [a: 3 b: 4]
obj2: object [z: 0 a: none b: 7]
--assert obj2 = set/some obj obj2
--assert "make object! [a: 3 b: 7]" = mold/flat obj
--assert "make object! [z: 0 a: none b: 7]" = mold/flat obj2
--assert "make object! [z: 0 a: #(none) b: 7]" = mold/flat obj2

--test-- "set-12"
o1: object [a: 1 b: 2 ]
Expand Down
16 changes: 8 additions & 8 deletions src/tests/units/mold-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -263,23 +263,23 @@ Rebol [


===start-group=== "mold-all"

--test-- "mold-true" --assert "true" = mold true
;@@ https://github.com/Oldes/Rebol-issues/issues/2159
--test-- "mold-true" --assert "#(true)" = mold true

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

--test-- "mold-false" --assert "false" = mold false
--test-- "mold-false" --assert "#(false)" = mold false

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

--test-- "mold-none" --assert "none" = mold none
--test-- "mold-none" --assert "#(none)" = mold none

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

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

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

--test-- "mold/all block at tail"
;@@ https://github.com/Oldes/Rebol-issues/issues/1192
Expand Down Expand Up @@ -567,7 +567,7 @@ Rebol [
--test-- "mold unset!"
--assert "#(unset)" = mold ()
--assert "#(unset)" = mold/all ()
--assert "unset!" = mold type? ()
--assert "#(unset!)" = mold type? ()
--assert "#(unset!)" = mold/all type? ()
--test-- "form unset!"
--assert "" = form ()
Expand Down Expand Up @@ -634,7 +634,7 @@ Rebol [
===start-group=== "mold error!"
--test-- "mold error!"
;@@ https://github.com/Oldes/Rebol-issues/issues/1003
--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]
--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]
--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]
--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]
===end-group===
Expand Down

0 comments on commit b9932bf

Please sign in to comment.