Skip to content

Commit ed5e1e8

Browse files
committed
CHANGE: Better construction syntax for datatypes (compatible with Red language)
resolves: Oldes/Rebol-issues#2508
1 parent d382ab2 commit ed5e1e8

13 files changed

+147
-78
lines changed

src/core/l-types.c

+9-10
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,10 @@ bad_hex: Trap0(RE_INVALID_CHARS);
10961096
SET_TRUE(value);
10971097
return TRUE;
10981098

1099+
case SYM_UNSET:
1100+
SET_UNSET(value);
1101+
return TRUE;
1102+
10991103
default:
11001104
if (type >= SYM_I8X && type < SYM_DATATYPES) {
11011105
if (MT_Vector(value, val, REB_VECTOR)) return TRUE;
@@ -1105,19 +1109,14 @@ bad_hex: Trap0(RE_INVALID_CHARS);
11051109
}
11061110
type--; // The global word for datatype x is at word x+1.
11071111

1108-
// Check for trivial types:
1109-
if (type == REB_UNSET) {
1110-
SET_UNSET(value);
1111-
return TRUE;
1112-
}
1113-
if (type == REB_NONE) {
1114-
SET_NONE(value);
1112+
val++;
1113+
if (IS_END(val)) {
1114+
VAL_SET(value, REB_DATATYPE);
1115+
VAL_DATATYPE(value) = type;
1116+
VAL_TYPE_SPEC(value) = 0;
11151117
return TRUE;
11161118
}
11171119

1118-
val++;
1119-
if (IS_END(val)) return FALSE;
1120-
11211120
// Dispatch maker:
11221121
if (NZ(func = Make_Dispatch[type])) {
11231122
if (func(value, val, type)) return TRUE;

src/core/s-mold.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,7 @@ STOID Mold_Error(REBVAL *value, REB_MOLD *mold, REBFLG molded)
12991299
if (!molded)
13001300
Emit(mold, "N", VAL_DATATYPE(value) + 1);
13011301
else
1302-
Emit(mold, "+DN", SYM_DATATYPE_TYPE, VAL_DATATYPE(value) + 1);
1302+
Emit(mold, "+N", VAL_DATATYPE(value) + 1);
13031303
break;
13041304

13051305
case REB_TYPESET:
@@ -1417,11 +1417,12 @@ STOID Mold_Error(REBVAL *value, REB_MOLD *mold, REBFLG molded)
14171417
else Emit(mold, "+T", value);
14181418
break;
14191419

1420-
case REB_END:
14211420
case REB_UNSET:
1422-
if (molded) Emit(mold, "+T", value);
1421+
if(molded) Append_Bytes(ser,"#[unset]");
1422+
break;
1423+
case REB_END:
1424+
if(molded) Append_Bytes(ser,"#[end]");
14231425
break;
1424-
14251426
default:
14261427
Crash(RP_DATATYPE+5, VAL_TYPE(value));
14271428
}

src/tests/units/conditional-test.r3

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ Rebol [
171171
switch sb15-i [
172172
1 [sb15-j: "Earl"]
173173
integer! [sb15-j: "Peter"]
174-
#[datatype! integer!] [sb15-j: "Red"]
175-
#[datatype! char!] [sb15-j: "Blue"]
174+
#[integer!] [sb15-j: "Red"]
175+
#[char!] [sb15-j: "Blue"]
176176
]
177177
--assert sb15-j = "Red"
178178

src/tests/units/datatype-test.r3

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ Rebol [
2424

2525
--test-- "find datatype!"
2626
;@@ https://github.com/Oldes/Rebol-issues/issues/256
27+
--assert not none? find [#[string!] #[binary!]] #[binary!]
2728
--assert not none? find [#[datatype! string!] #[datatype! binary!]] #[datatype! binary!]
2829
--assert not none? find reduce [string! binary!] binary!
29-
--assert not none? find [#[datatype! string!] #[datatype! binary!]] #[datatype! binary!]
30+
--assert not none? find [#[string!] #[binary!]] binary!
31+
--assert not none? find [#[datatype! string!] #[datatype! binary!]] binary!
3032
--assert not none? find ["test"] string!
3133
--assert not none? find ["test"] series!
3234
--assert none? find reduce [integer! binary!] series!

src/tests/units/error-test.r3

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ Rebol [
119119
;@@ https://github.com/Oldes/Rebol-issues/issues/1364
120120
--assert assert/type [x #[typeset! [char! string!]]]
121121
--assert assert/type [x any-string!]
122-
--assert assert/type [x #[datatype! string!]]
122+
--assert assert/type [x #[string!]]
123123

124124
--test-- "invalid assert"
125125
;@@ https://github.com/Oldes/Rebol-issues/issues/1363

src/tests/units/evaluation-test.r3

+3-3
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,8 @@ Rebol [
320320

321321
--test-- "reduce/only"
322322
;@@ https://github.com/Oldes/Rebol-issues/issues/359
323-
--assert [1 #[unset!] 2] = reduce/only [1 no-such-word 2] []
324-
--assert [1 #[unset!] 2] = reduce/only [1 no-such-word 2] none
323+
--assert [1 #[unset] 2] = reduce/only [1 no-such-word 2] []
324+
--assert [1 #[unset] 2] = reduce/only [1 no-such-word 2] none
325325
--assert [1 some-word 2] = reduce/only [1 some-word 2] [some-word]
326326
--assert native? second reduce/only [1 now 2] none
327327
--assert word? second reduce/only [1 now 2] [now]
@@ -487,7 +487,7 @@ Rebol [
487487

488488
--test-- "to-value"
489489
;@@ https://github.com/Oldes/Rebol-issues/issues/2003
490-
--assert none? to-value #[unset!]
490+
--assert none? to-value #[unset]
491491
--assert integer? to-value 1
492492

493493
--test-- "unset unbind 'x"

src/tests/units/func-test.r3

+1-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ Rebol [
313313
f: func [v [any-type!]] [type? get/any 'v]
314314
--assert unset! = f make unset! none
315315
f: func [v [unset!]] [type? get/any 'v]
316-
--assert unset! = f #[unset!]
316+
--assert unset! = f #[unset]
317317

318318
--test-- "issue-196"
319319
;@@ https://github.com/Oldes/Rebol-issues/issues/196

src/tests/units/lexer-test.r3

+64
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,70 @@ Rebol [
407407
;@@ https://github.com/Oldes/Rebol-issues/issues/1114
408408
--assert function? first transcode to binary! {#[function! [[a [series!]][print a]]]}
409409

410+
--test-- {datatype!}
411+
;@@ https://github.com/Oldes/Rebol-issues/issues/2508
412+
--assert datatype? first transcode/only to binary! {#[unset!]}
413+
--assert datatype? first transcode/only to binary! {#[none!]}
414+
--assert datatype? first transcode/only to binary! {#[logic!]}
415+
--assert datatype? first transcode/only to binary! {#[integer!]}
416+
--assert datatype? first transcode/only to binary! {#[decimal!]}
417+
--assert datatype? first transcode/only to binary! {#[percent!]}
418+
--assert datatype? first transcode/only to binary! {#[money!]}
419+
--assert datatype? first transcode/only to binary! {#[char!]}
420+
--assert datatype? first transcode/only to binary! {#[pair!]}
421+
--assert datatype? first transcode/only to binary! {#[tuple!]}
422+
--assert datatype? first transcode/only to binary! {#[time!]}
423+
--assert datatype? first transcode/only to binary! {#[date!]}
424+
--assert datatype? first transcode/only to binary! {#[binary!]}
425+
--assert datatype? first transcode/only to binary! {#[string!]}
426+
--assert datatype? first transcode/only to binary! {#[file!]}
427+
--assert datatype? first transcode/only to binary! {#[email!]}
428+
--assert datatype? first transcode/only to binary! {#[ref!]}
429+
--assert datatype? first transcode/only to binary! {#[url!]}
430+
--assert datatype? first transcode/only to binary! {#[tag!]}
431+
--assert datatype? first transcode/only to binary! {#[bitset!]}
432+
--assert datatype? first transcode/only to binary! {#[image!]}
433+
--assert datatype? first transcode/only to binary! {#[vector!]}
434+
--assert datatype? first transcode/only to binary! {#[block!]}
435+
--assert datatype? first transcode/only to binary! {#[paren!]}
436+
--assert datatype? first transcode/only to binary! {#[path!]}
437+
--assert datatype? first transcode/only to binary! {#[set-path!]}
438+
--assert datatype? first transcode/only to binary! {#[get-path!]}
439+
--assert datatype? first transcode/only to binary! {#[lit-path!]}
440+
--assert datatype? first transcode/only to binary! {#[map!]}
441+
--assert datatype? first transcode/only to binary! {#[datatype!]}
442+
--assert datatype? first transcode/only to binary! {#[typeset!]}
443+
--assert datatype? first transcode/only to binary! {#[word!]}
444+
--assert datatype? first transcode/only to binary! {#[set-word!]}
445+
--assert datatype? first transcode/only to binary! {#[get-word!]}
446+
--assert datatype? first transcode/only to binary! {#[lit-word!]}
447+
--assert datatype? first transcode/only to binary! {#[refinement!]}
448+
--assert datatype? first transcode/only to binary! {#[issue!]}
449+
--assert datatype? first transcode/only to binary! {#[native!]}
450+
--assert datatype? first transcode/only to binary! {#[action!]}
451+
--assert datatype? first transcode/only to binary! {#[rebcode!]}
452+
--assert datatype? first transcode/only to binary! {#[command!]}
453+
--assert datatype? first transcode/only to binary! {#[op!]}
454+
--assert datatype? first transcode/only to binary! {#[closure!]}
455+
--assert datatype? first transcode/only to binary! {#[function!]}
456+
--assert datatype? first transcode/only to binary! {#[frame!]}
457+
--assert datatype? first transcode/only to binary! {#[object!]}
458+
--assert datatype? first transcode/only to binary! {#[module!]}
459+
--assert datatype? first transcode/only to binary! {#[error!]}
460+
--assert datatype? first transcode/only to binary! {#[task!]}
461+
--assert datatype? first transcode/only to binary! {#[port!]}
462+
--assert datatype? first transcode/only to binary! {#[gob!]}
463+
--assert datatype? first transcode/only to binary! {#[event!]}
464+
--assert datatype? first transcode/only to binary! {#[handle!]}
465+
--assert datatype? first transcode/only to binary! {#[struct!]}
466+
--assert datatype? first transcode/only to binary! {#[library!]}
467+
--assert datatype? first transcode/only to binary! {#[utype!]}
468+
--test-- {direct values}
469+
--assert logic? first transcode/only to binary! {#[true]}
470+
--assert logic? first transcode/only to binary! {#[false]}
471+
--assert none? first transcode/only to binary! {#[none]}
472+
--assert unset? first transcode/only to binary! {#[unset]}
473+
410474
===end-group===
411475

412476
===start-group=== "BINARY"

0 commit comments

Comments
 (0)