1 // ================================================================
2 // This is for map-valued contexts: LHS/RHS of assignments,
3 // UDF/subroutine arguments, and UDF return values.
4
5 // The is_ephemeral flag is TRUE for map-literals, function return values, and
6 // data copied out of srecs. It is FALSE when the pointer is into an existing
7 // data structure's memory (e.g. oosvars or locals).
8 // ================================================================
9
10 #ifndef BOXED_XVAL_H
11 #define BOXED_XVAL_H
12
13 #include "../lib/mlrval.h"
14 #include "../containers/mlhmmv.h"
15
16 // ----------------------------------------------------------------
17 typedef struct _boxed_xval_t {
18 mlhmmv_xvalue_t xval;
19 char is_ephemeral;
20 } boxed_xval_t;
21
22 // ----------------------------------------------------------------
box_ephemeral_val(mv_t val)23 static inline boxed_xval_t box_ephemeral_val(mv_t val) {
24 return (boxed_xval_t) {
25 .xval = mlhmmv_xvalue_wrap_terminal(val),
26 .is_ephemeral = TRUE,
27 };
28 }
29
box_non_ephemeral_val(mv_t val)30 static inline boxed_xval_t box_non_ephemeral_val(mv_t val) {
31 return (boxed_xval_t) {
32 .xval = mlhmmv_xvalue_wrap_terminal(val),
33 .is_ephemeral = FALSE,
34 };
35 }
36
box_ephemeral_xval(mlhmmv_xvalue_t xval)37 static inline boxed_xval_t box_ephemeral_xval(mlhmmv_xvalue_t xval) {
38 return (boxed_xval_t) {
39 .xval = xval,
40 .is_ephemeral = TRUE,
41 };
42 }
43
box_non_ephemeral_xval(mlhmmv_xvalue_t xval)44 static inline boxed_xval_t box_non_ephemeral_xval(mlhmmv_xvalue_t xval) {
45 return (boxed_xval_t) {
46 .xval = xval,
47 .is_ephemeral = FALSE,
48 };
49 }
50
51 #endif // BOXED_XVAL_H
52