/home/travis/build/MoarVM/MoarVM/src/core/args.h
Line | Count | Source |
1 | | /* Argument processing context. */ |
2 | | struct MVMArgProcContext { |
3 | | /* The callsite we're processing. */ |
4 | | MVMCallsite *callsite; |
5 | | |
6 | | /* The set of flags (only set if we flattened, otherwise we use the ones |
7 | | * from callsite). */ |
8 | | MVMCallsiteEntry *arg_flags; |
9 | | |
10 | | /* The arguments. */ |
11 | | MVMRegister *args; |
12 | | |
13 | | /* Indexes of used nameds. If named_used_size is less than or equal to |
14 | | * 64, it will be a bit field. Otherwise, it will be a pointer to a |
15 | | * byte array. */ |
16 | | union { |
17 | | MVMuint8 *byte_array; |
18 | | MVMuint64 bit_field; |
19 | | } named_used; |
20 | | MVMuint16 named_used_size; |
21 | | |
22 | | /* The total argument count (including 2 for each |
23 | | * named arg). */ |
24 | | MVMuint16 arg_count; |
25 | | |
26 | | /* Number of positionals. */ |
27 | | MVMuint16 num_pos; |
28 | | |
29 | | /* The number of arg flags; only valid if arg_flags isn't NULL. */ |
30 | | MVMuint16 flag_count; |
31 | | }; |
32 | | |
33 | | /* Expected return type flags. */ |
34 | | typedef MVMuint8 MVMReturnType; |
35 | 1.04M | #define MVM_RETURN_VOID 0 |
36 | 28.7M | #define MVM_RETURN_OBJ 1 |
37 | 316k | #define MVM_RETURN_INT 2 |
38 | 1.25k | #define MVM_RETURN_NUM 4 |
39 | 292k | #define MVM_RETURN_STR 8 |
40 | | |
41 | | /* Struct used for returning information about an argument. */ |
42 | | struct MVMArgInfo { |
43 | | MVMRegister arg; |
44 | | MVMCallsiteEntry flags; |
45 | | MVMuint8 exists; |
46 | | MVMuint16 arg_idx; /* Set only for nameds, obvious for pos */ |
47 | | }; |
48 | | |
49 | | /* Argument processing context handling. */ |
50 | | void MVM_args_proc_init(MVMThreadContext *tc, MVMArgProcContext *ctx, MVMCallsite *callsite, MVMRegister *args); |
51 | | void MVM_args_proc_cleanup(MVMThreadContext *tc, MVMArgProcContext *ctx); |
52 | | void MVM_args_checkarity(MVMThreadContext *tc, MVMArgProcContext *ctx, MVMuint16 min, MVMuint16 max); |
53 | | void MVM_args_checkarity_for_jit(MVMThreadContext *tc, MVMuint16 min, MVMuint16 max); |
54 | | MVMCallsite * MVM_args_copy_callsite(MVMThreadContext *tc, MVMArgProcContext *ctx); |
55 | | MVMCallsite * MVM_args_copy_uninterned_callsite(MVMThreadContext *tc, MVMArgProcContext *ctx); |
56 | | MVM_PUBLIC MVMObject * MVM_args_use_capture(MVMThreadContext *tc, MVMFrame *f); |
57 | | MVM_PUBLIC MVMObject * MVM_args_save_capture(MVMThreadContext *tc, MVMFrame *f); |
58 | | void MVM_args_marked_named_used(MVMThreadContext *tc, MVMuint32 idx); |
59 | | void MVM_args_throw_named_unused_error(MVMThreadContext *tc, MVMString *name); |
60 | | |
61 | | /* Argument access by position. */ |
62 | | MVMObject * MVM_args_get_required_pos_obj(MVMThreadContext *tc, MVMArgProcContext *ctx, MVMuint32 pos); |
63 | | MVMArgInfo MVM_args_get_optional_pos_obj(MVMThreadContext *tc, MVMArgProcContext *ctx, MVMuint32 pos); |
64 | | MVMint64 MVM_args_get_required_pos_int(MVMThreadContext *tc, MVMArgProcContext *ctx, MVMuint32 pos); |
65 | | MVMArgInfo MVM_args_get_optional_pos_int(MVMThreadContext *tc, MVMArgProcContext *ctx, MVMuint32 pos); |
66 | | MVMArgInfo MVM_args_get_pos_num(MVMThreadContext *tc, MVMArgProcContext *ctx, MVMuint32 pos, MVMuint8 required); |
67 | | MVMString * MVM_args_get_required_pos_str(MVMThreadContext *tc, MVMArgProcContext *ctx, MVMuint32 pos); |
68 | | MVMArgInfo MVM_args_get_optional_pos_str(MVMThreadContext *tc, MVMArgProcContext *ctx, MVMuint32 pos); |
69 | | MVMArgInfo MVM_args_get_pos_uint(MVMThreadContext *tc, MVMArgProcContext *ctx, MVMuint32 pos, MVMuint8 required); |
70 | | MVMObject * MVM_args_slurpy_positional(MVMThreadContext *tc, MVMArgProcContext *ctx, MVMuint16 pos); |
71 | | |
72 | | /* Argument access by name. */ |
73 | | MVMArgInfo MVM_args_get_named_obj(MVMThreadContext *tc, MVMArgProcContext *ctx, MVMString *name, MVMuint8 required); |
74 | | MVMArgInfo MVM_args_get_named_int(MVMThreadContext *tc, MVMArgProcContext *ctx, MVMString *name, MVMuint8 required); |
75 | | MVMArgInfo MVM_args_get_named_num(MVMThreadContext *tc, MVMArgProcContext *ctx, MVMString *name, MVMuint8 required); |
76 | | MVMArgInfo MVM_args_get_named_str(MVMThreadContext *tc, MVMArgProcContext *ctx, MVMString *name, MVMuint8 required); |
77 | | MVMArgInfo MVM_args_get_named_uint(MVMThreadContext *tc, MVMArgProcContext *ctx, MVMString *name, MVMuint8 required); |
78 | | MVMObject * MVM_args_slurpy_named(MVMThreadContext *tc, MVMArgProcContext *ctx); |
79 | | MVMint64 MVM_args_has_named(MVMThreadContext *tc, MVMArgProcContext *ctx, MVMString *name); |
80 | | void MVM_args_assert_nameds_used(MVMThreadContext *tc, MVMArgProcContext *ctx); |
81 | | |
82 | | /* Result setting. */ |
83 | | void MVM_args_set_result_obj(MVMThreadContext *tc, MVMObject *result, MVMint32 frameless); |
84 | | void MVM_args_set_result_int(MVMThreadContext *tc, MVMint64 result, MVMint32 frameless); |
85 | | void MVM_args_set_result_num(MVMThreadContext *tc, MVMnum64 result, MVMint32 frameless); |
86 | | void MVM_args_set_result_str(MVMThreadContext *tc, MVMString *result, MVMint32 frameless); |
87 | | void MVM_args_assert_void_return_ok(MVMThreadContext *tc, MVMint32 frameless); |
88 | | |
89 | | /* Setting up calls from C-land. */ |
90 | | MVM_PUBLIC void MVM_args_setup_thunk(MVMThreadContext *tc, MVMRegister *return_value, MVMReturnType return_type, |
91 | | MVMCallsite *callsite); |
92 | | |
93 | | /* Custom bind failure handling. */ |
94 | | void MVM_args_bind_failed(MVMThreadContext *tc); |
95 | | |
96 | | /* Result setting frame constants. */ |
97 | 7.88M | #define MVM_RETURN_CALLER_FRAME 0 |
98 | 4.83k | #define MVM_RETURN_CURRENT_FRAME 1 |
99 | | |
100 | | /* Required/optional constants. */ |
101 | 1.12M | #define MVM_ARG_OPTIONAL 0 |
102 | 203k | #define MVM_ARG_REQUIRED 1 |