/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 | | /* Bytemap of indexes of used nameds, so the |
14 | | * named slurpy knows which ones not to grab. |
15 | | * XXX cache and free this at the proper times. */ |
16 | | MVMuint8 *named_used; |
17 | | MVMuint16 named_used_size; |
18 | | |
19 | | /* The total argument count (including 2 for each |
20 | | * named arg). */ |
21 | | MVMuint16 arg_count; |
22 | | |
23 | | /* Number of positionals. */ |
24 | | MVMuint16 num_pos; |
25 | | |
26 | | /* The number of arg flags; only valid if arg_flags isn't NULL. */ |
27 | | MVMuint16 flag_count; |
28 | | }; |
29 | | |
30 | | /* Expected return type flags. */ |
31 | | typedef enum { |
32 | | /* Argument is an object. */ |
33 | | MVM_RETURN_VOID = 0, |
34 | | |
35 | | /* Argument is an object. */ |
36 | | MVM_RETURN_OBJ = 1, |
37 | | |
38 | | /* Argument is a native integer, signed. */ |
39 | | MVM_RETURN_INT = 2, |
40 | | |
41 | | /* Argument is a native floating point number. */ |
42 | | MVM_RETURN_NUM = 4, |
43 | | |
44 | | /* Argument is a native NFG string (MVMString REPR). */ |
45 | | MVM_RETURN_STR = 8, |
46 | | } MVMReturnType; |
47 | | |
48 | | /* Struct used for returning information about an argument. */ |
49 | | struct MVMArgInfo { |
50 | | MVMRegister arg; |
51 | | MVMCallsiteEntry flags; |
52 | | MVMuint8 exists; |
53 | | }; |
54 | | |
55 | | /* Argument processing context handling. */ |
56 | | void MVM_args_proc_init(MVMThreadContext *tc, MVMArgProcContext *ctx, MVMCallsite *callsite, MVMRegister *args); |
57 | | void MVM_args_proc_cleanup(MVMThreadContext *tc, MVMArgProcContext *ctx); |
58 | | void MVM_args_checkarity(MVMThreadContext *tc, MVMArgProcContext *ctx, MVMuint16 min, MVMuint16 max); |
59 | | void MVM_args_checkarity_for_jit(MVMThreadContext *tc, MVMuint16 min, MVMuint16 max); |
60 | | MVMCallsite * MVM_args_copy_callsite(MVMThreadContext *tc, MVMArgProcContext *ctx); |
61 | | MVMCallsite * MVM_args_proc_to_callsite(MVMThreadContext *tc, MVMArgProcContext *ctx, MVMuint8 *owns_callsite); |
62 | | MVM_PUBLIC MVMObject * MVM_args_use_capture(MVMThreadContext *tc, MVMFrame *f); |
63 | | MVM_PUBLIC MVMObject * MVM_args_save_capture(MVMThreadContext *tc, MVMFrame *f); |
64 | | |
65 | | /* Argument access by position. */ |
66 | | MVMArgInfo MVM_args_get_pos_obj(MVMThreadContext *tc, MVMArgProcContext *ctx, MVMuint32 pos, MVMuint8 required); |
67 | | MVMArgInfo MVM_args_get_pos_int(MVMThreadContext *tc, MVMArgProcContext *ctx, MVMuint32 pos, MVMuint8 required); |
68 | | MVMArgInfo MVM_args_get_pos_num(MVMThreadContext *tc, MVMArgProcContext *ctx, MVMuint32 pos, MVMuint8 required); |
69 | | MVMArgInfo MVM_args_get_pos_str(MVMThreadContext *tc, MVMArgProcContext *ctx, MVMuint32 pos, MVMuint8 required); |
70 | | MVMArgInfo MVM_args_get_pos_uint(MVMThreadContext *tc, MVMArgProcContext *ctx, MVMuint32 pos, MVMuint8 required); |
71 | | MVMObject * MVM_args_slurpy_positional(MVMThreadContext *tc, MVMArgProcContext *ctx, MVMuint16 pos); |
72 | | |
73 | | /* Argument access by name. */ |
74 | | MVMArgInfo MVM_args_get_named_obj(MVMThreadContext *tc, MVMArgProcContext *ctx, MVMString *name, MVMuint8 required); |
75 | | MVMArgInfo MVM_args_get_named_int(MVMThreadContext *tc, MVMArgProcContext *ctx, MVMString *name, MVMuint8 required); |
76 | | MVMArgInfo MVM_args_get_named_num(MVMThreadContext *tc, MVMArgProcContext *ctx, MVMString *name, MVMuint8 required); |
77 | | MVMArgInfo MVM_args_get_named_str(MVMThreadContext *tc, MVMArgProcContext *ctx, MVMString *name, MVMuint8 required); |
78 | | MVMArgInfo MVM_args_get_named_uint(MVMThreadContext *tc, MVMArgProcContext *ctx, MVMString *name, MVMuint8 required); |
79 | | MVMObject * MVM_args_slurpy_named(MVMThreadContext *tc, MVMArgProcContext *ctx); |
80 | | MVMint64 MVM_args_has_named(MVMThreadContext *tc, MVMArgProcContext *ctx, MVMString *name); |
81 | | void MVM_args_assert_nameds_used(MVMThreadContext *tc, MVMArgProcContext *ctx); |
82 | | |
83 | | /* Result setting. */ |
84 | | void MVM_args_set_result_obj(MVMThreadContext *tc, MVMObject *result, MVMint32 frameless); |
85 | | void MVM_args_set_result_int(MVMThreadContext *tc, MVMint64 result, MVMint32 frameless); |
86 | | void MVM_args_set_result_num(MVMThreadContext *tc, MVMnum64 result, MVMint32 frameless); |
87 | | void MVM_args_set_result_str(MVMThreadContext *tc, MVMString *result, MVMint32 frameless); |
88 | | void MVM_args_assert_void_return_ok(MVMThreadContext *tc, MVMint32 frameless); |
89 | | |
90 | | /* Setting up calls from C-land. */ |
91 | | MVM_PUBLIC void MVM_args_setup_thunk(MVMThreadContext *tc, MVMRegister *return_value, MVMReturnType return_type, |
92 | | MVMCallsite *callsite); |
93 | | |
94 | | /* Custom bind failure handling. */ |
95 | | void MVM_args_bind_failed(MVMThreadContext *tc); |
96 | | |
97 | | /* Result setting frame constants. */ |
98 | 5.88M | #define MVM_RETURN_CALLER_FRAME 0 |
99 | 4.47k | #define MVM_RETURN_CURRENT_FRAME 1 |
100 | | |
101 | | /* Required/optional constants. */ |
102 | 1.31M | #define MVM_ARG_OPTIONAL 0 |
103 | 7.35M | #define MVM_ARG_REQUIRED 1 |