@@ -54,7 +54,7 @@ extern RL_LIB *RL; // Link back to reb-lib from embedded extensions
54
54
static REBCNT Handle_XTest ;
55
55
typedef struct XTest_Context {
56
56
REBCNT id ;
57
- REBINT num ;
57
+ REBCNT flags ;
58
58
} XTEST ;
59
59
60
60
u32 * x_arg_words ;
@@ -113,13 +113,13 @@ char *RX_Spec =
113
113
"vec0: command [{return vector size in bytes} v [vector!]]\n"
114
114
"vec1: command [{return vector size in bytes (from object)} o [object!]]\n"
115
115
"blk1: command [{print type ids of all values in a block} b [block!]]\n"
116
- "hob1: command [{creates XTEST handle} bin [binary!]]"
116
+ "hob1: command [{creates XTEST handle} bin [binary!] /with hnd [handle!] ]"
117
117
"hob2: command [{prints XTEST handle's data} hndl [handle!]]"
118
118
"str0: command [{return a constructed string}]"
119
119
"echo: command [{return the input value} value]"
120
120
121
121
"init-words [id data length] protect/hide 'init-words\n"
122
- "a: b: c: h: x: none\n"
122
+ "a: b: c: h: x: y: none\n"
123
123
"i: make image! 2x2\n"
124
124
"s: #[struct! [r [uint8!]]]\n"
125
125
"xtest: does [\n"
@@ -129,6 +129,10 @@ char *RX_Spec =
129
129
"[x/id: 2 print [{now the id is:} x/id]]\n"
130
130
"[print [{It is not possible to change its length:} error? try [x/length: 3]]]\n"
131
131
"[hob2 x]"
132
+
133
+ // Sometimes handle may depend on another handle.. this test simulates it.
134
+ "[y: hob1/with #{00} x x: none print [{The new handle keeps reference to the second handle:} mold y/data y/data/2/id]]\n"
135
+
132
136
"[h: hndl1]\n"
133
137
"[hndl2 h]\n"
134
138
"[xarg0]\n"
@@ -356,7 +360,7 @@ RXIEXT int RX_Call(int cmd, RXIFRM *frm, void *ctx) {
356
360
return RXR_UNSET ;
357
361
}
358
362
break ;
359
- case CMD_hob1 : //command [{creates XTEST handle} bin [binary!]]"
363
+ case CMD_hob1 : //command [{creates XTEST handle} bin [binary!] /with hnd [handle!] ]"
360
364
{
361
365
REBHOB * hob = RL_MAKE_HANDLE_CONTEXT (Handle_XTest );
362
366
REBSER * bin = RXA_SERIES (frm , 1 );
@@ -365,12 +369,20 @@ RXIEXT int RX_Call(int cmd, RXIFRM *frm, void *ctx) {
365
369
if (SERIES_REST (bin ) < 1 ) {
366
370
RL_EXPAND_SERIES (bin , SERIES_TAIL (bin ), 1 );
367
371
}
368
- hob -> series = bin ;
369
372
370
- printf ("data=> id: %u num: %i\n" , data -> id , data -> num );
373
+ if (RXA_REF (frm , 2 )) {
374
+ hob -> series = RL_MAKE_BLOCK (2 );
375
+ data -> flags = 1 ;
376
+ RL_SET_VALUE (hob -> series , 0 , RXA_ARG (frm , 1 ), RXT_BINARY );
377
+ RL_SET_VALUE (hob -> series , 1 , RXA_ARG (frm , 3 ), RXT_HANDLE );
378
+ } else {
379
+ hob -> series = bin ;
380
+ data -> flags = 0 ;
381
+ }
382
+
383
+ printf ("data=> id: %u flags: %i\n" , data -> id , data -> flags );
371
384
data -> id = 1 ;
372
- data -> num = SERIES_TAIL (bin );
373
- printf ("data=> id: %u num: %i\n" , data -> id , data -> num );
385
+ printf ("data=> id: %u flags: %i\n" , data -> id , data -> flags );
374
386
375
387
RXA_HANDLE (frm , 1 ) = hob ;
376
388
RXA_HANDLE_TYPE (frm , 1 ) = hob -> sym ;
@@ -383,10 +395,20 @@ RXIEXT int RX_Call(int cmd, RXIFRM *frm, void *ctx) {
383
395
REBHOB * hob = RXA_HANDLE (frm , 1 );
384
396
if (hob -> sym == Handle_XTest ) {
385
397
XTEST * data = (XTEST * )hob -> data ;
386
- REBSER * bin = hob -> series ;
398
+ REBSER * bin , * ser ;
399
+ REBCNT type ;
400
+ if (data -> flags == 1 ) {
401
+ type = RL_GET_VALUE (hob -> series , 0 , & RXA_ARG (frm , 2 ));
402
+ if (type != RXT_BINARY ) return RXR_FALSE ;
403
+ bin = RXA_SERIES (frm , 2 );
404
+ } else {
405
+ bin = hob -> series ;
406
+ }
407
+
408
+
387
409
SERIES_DATA (bin )[0 ] = SERIES_DATA (bin )[0 ] + 1 ;
388
- printf ("data=> id: %u num : %i b: %i\n" , data -> id , data -> num , (u8 )SERIES_DATA (bin )[0 ]);
389
- RXA_INT64 (frm , 1 ) = data -> num ;
410
+ printf ("data=> id: %u flags : %i b: %i\n" , data -> id , data -> flags , (u8 )SERIES_DATA (bin )[0 ]);
411
+ RXA_INT64 (frm , 1 ) = SERIES_DATA ( bin )[ 0 ] ;
390
412
RXA_TYPE (frm , 1 ) = RXT_INTEGER ;
391
413
}
392
414
else {
@@ -424,9 +446,9 @@ int XTestContext_release(void* ctx) {
424
446
XTEST * data = (XTEST * )ctx ;
425
447
printf ("Relasing XTest context handle: %p\n" , data );
426
448
// do some final cleaning off the context's content
427
- printf ("data=> id: %u num: %i\n" , data -> id , data -> num );
449
+ printf ("data=> id: %u num: %i\n" , data -> id , data -> flags );
428
450
CLEARS (data );
429
- printf ("data=> id: %u num: %i\n" , data -> id , data -> num );
451
+ printf ("data=> id: %u num: %i\n" , data -> id , data -> flags );
430
452
return 0 ;
431
453
}
432
454
@@ -442,11 +464,11 @@ int XTestContext_get_path(REBHOB *hob, REBCNT word, REBCNT *type, RXIARG *arg) {
442
464
case W_DATA :
443
465
arg -> series = hob -> series ;
444
466
arg -> index = 0 ;
445
- * type = RXT_BINARY ;
467
+ * type = ( xtest -> flags == 1 ) ? RXT_BLOCK : RXT_BINARY ;
446
468
break ;
447
469
case W_LENGTH :
448
470
* type = RXT_INTEGER ;
449
- arg -> int64 = xtest -> num ;
471
+ arg -> int64 = SERIES_TAIL ( hob -> series ) ;
450
472
break ;
451
473
default :
452
474
return PE_BAD_SELECT ;
@@ -467,7 +489,7 @@ int XTestContext_set_path(REBHOB *hob, REBCNT word, REBCNT *type, RXIARG *arg) {
467
489
case W_DATA :
468
490
if (* type != RXT_BINARY ) return PE_BAD_SET_TYPE ;
469
491
hob -> series = arg -> series ;
470
- xtest -> num = SERIES_TAIL (hob -> series );
492
+ // xtest->num = SERIES_TAIL(hob->series);
471
493
break ;
472
494
default :
473
495
return PE_BAD_SET ;
0 commit comments