Skip to content

Commit

Permalink
FEAT: implemented passing a struct value to an extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Feb 2, 2023
1 parent 5f4f434 commit 8a44eae
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/boot/types-ext.reb
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@ gob 47 ser
object 48 object
module * object

struct 54 struct

11 changes: 11 additions & 0 deletions src/core/f-extension.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ enum {
RXE_DATE, // from upper section
RXE_OBJECT, // any object
RXE_TUPLE, // 3-12 bytes tuple value
RXE_STRUCT, // structure data and fields spec series
RXE_MAX
};

Expand Down Expand Up @@ -121,6 +122,10 @@ x*/ RXIARG Value_To_RXI(REBVAL *val)
arg.tuple_len = VAL_TUPLE_LEN(val);
COPY_MEM(arg.tuple_bytes, VAL_TUPLE(val), MAX_TUPLE);
break;
case RXE_STRUCT:
arg.structure.data = VAL_STRUCT_DATA(val);
arg.structure.fields = VAL_STRUCT_FIELDS(val);
break;
case RXE_NULL:
default:
arg.int64 = 0;
Expand Down Expand Up @@ -176,6 +181,12 @@ x*/ void RXI_To_Value(REBVAL *val, RXIARG arg, REBCNT type)
VAL_TUPLE_LEN(val) = arg.tuple_len;
COPY_MEM(VAL_TUPLE(val), arg.tuple_bytes, MAX_TUPLE);
break;
case RXE_STRUCT:
//TODO: review!
// There is no room in RXIARG to pass the spec part of the struct!
VAL_STRUCT_DATA(val) = arg.structure.data;
VAL_STRUCT_FIELDS(val) = arg.structure.fields;
break;
case RXE_NULL:
VAL_INT64(val) = 0;
break;
Expand Down
5 changes: 5 additions & 0 deletions src/include/reb-ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ typedef union rxi_arg_val {
REBYTE tuple_len;
REBYTE tuple_bytes[MAX_TUPLE];
};
struct {
REBSER *data;
REBSER *fields;
} structure;

} RXIARG;

// For direct access to arg array:
Expand Down
4 changes: 4 additions & 0 deletions src/os/host-ext-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ char *RX_Spec =

"a: b: c: h: x: none\n"
"i: make image! 2x2\n"
"s: #[struct! [r [uint8!]]]\n"
"xtest: does [\n"
"foreach blk [\n"
"[x: hob1 #{0102}]"
Expand Down Expand Up @@ -124,6 +125,9 @@ char *RX_Spec =
"[echo i]\n"
"[probe i probe echo i]\n"
"[loop 1 [probe echo i]]\n"

// https://github.com/Oldes/Rebol-issues/issues/2536
"[same? s probe echo s]\n"
"][\n"
"print [{^/^[[7mtest:^[[0m^[[1;32m} mold blk {^[[0m}]\n"
//"replace {x} {x} {y}\n"
Expand Down

0 comments on commit 8a44eae

Please sign in to comment.