Skip to content

Commit 8a44eae

Browse files
committed
FEAT: implemented passing a struct value to an extension
resolves: Oldes/Rebol-issues#2536
1 parent 5f4f434 commit 8a44eae

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

src/boot/types-ext.reb

+2
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,5 @@ gob 47 ser
6161
object 48 object
6262
module * object
6363

64+
struct 54 struct
65+

src/core/f-extension.c

+11
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ enum {
4747
RXE_DATE, // from upper section
4848
RXE_OBJECT, // any object
4949
RXE_TUPLE, // 3-12 bytes tuple value
50+
RXE_STRUCT, // structure data and fields spec series
5051
RXE_MAX
5152
};
5253

@@ -121,6 +122,10 @@ x*/ RXIARG Value_To_RXI(REBVAL *val)
121122
arg.tuple_len = VAL_TUPLE_LEN(val);
122123
COPY_MEM(arg.tuple_bytes, VAL_TUPLE(val), MAX_TUPLE);
123124
break;
125+
case RXE_STRUCT:
126+
arg.structure.data = VAL_STRUCT_DATA(val);
127+
arg.structure.fields = VAL_STRUCT_FIELDS(val);
128+
break;
124129
case RXE_NULL:
125130
default:
126131
arg.int64 = 0;
@@ -176,6 +181,12 @@ x*/ void RXI_To_Value(REBVAL *val, RXIARG arg, REBCNT type)
176181
VAL_TUPLE_LEN(val) = arg.tuple_len;
177182
COPY_MEM(VAL_TUPLE(val), arg.tuple_bytes, MAX_TUPLE);
178183
break;
184+
case RXE_STRUCT:
185+
//TODO: review!
186+
// There is no room in RXIARG to pass the spec part of the struct!
187+
VAL_STRUCT_DATA(val) = arg.structure.data;
188+
VAL_STRUCT_FIELDS(val) = arg.structure.fields;
189+
break;
179190
case RXE_NULL:
180191
VAL_INT64(val) = 0;
181192
break;

src/include/reb-ext.h

+5
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ typedef union rxi_arg_val {
9797
REBYTE tuple_len;
9898
REBYTE tuple_bytes[MAX_TUPLE];
9999
};
100+
struct {
101+
REBSER *data;
102+
REBSER *fields;
103+
} structure;
104+
100105
} RXIARG;
101106

102107
// For direct access to arg array:

src/os/host-ext-test.c

+4
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ char *RX_Spec =
8989

9090
"a: b: c: h: x: none\n"
9191
"i: make image! 2x2\n"
92+
"s: #[struct! [r [uint8!]]]\n"
9293
"xtest: does [\n"
9394
"foreach blk [\n"
9495
"[x: hob1 #{0102}]"
@@ -124,6 +125,9 @@ char *RX_Spec =
124125
"[echo i]\n"
125126
"[probe i probe echo i]\n"
126127
"[loop 1 [probe echo i]]\n"
128+
129+
// https://github.com/Oldes/Rebol-issues/issues/2536
130+
"[same? s probe echo s]\n"
127131
"][\n"
128132
"print [{^/^[[7mtest:^[[0m^[[1;32m} mold blk {^[[0m}]\n"
129133
//"replace {x} {x} {y}\n"

0 commit comments

Comments
 (0)