Ruby: prism_compile.h Source File

Ruby 3.4.5p51 (2025-07-16 revision 20cda200d3ce092571d0b5d342dadca69636cb0f)

prism_compile.h
1#include "prism/prism.h"
2#include "ruby/encoding.h"
3
12 typedef struct pm_local_index_struct {
13 int index, level;
14} pm_local_index_t;
15
16// A declaration for the struct that lives in compile.c.
17struct iseq_link_anchor;
18
19// ScopeNodes are helper nodes, and will never be part of the AST. We manually
20// declare them here to avoid generating them.
21 typedef struct pm_scope_node {
22 pm_node_t base;
23 struct pm_scope_node *previous;
24 pm_node_t *ast_node;
25 pm_node_t *parameters;
26 pm_node_t *body;
27 pm_constant_id_list_t locals;
28
29 const pm_parser_t *parser;
30 rb_encoding *encoding;
31
40 VALUE *script_lines;
41
47 rb_encoding *filepath_encoding;
48
49 // The size of the local table on the iseq which includes locals and hidden
50 // variables.
51 int local_table_for_iseq_size;
52
53 ID *constants;
54 st_table *index_lookup_table;
55
56 // The current coverage setting, passed down through the various scopes.
57 int coverage_enabled;
58
63 struct iseq_link_anchor *pre_execution_anchor;
64} pm_scope_node_t;
65
66void pm_scope_node_init(const pm_node_t *node, pm_scope_node_t *scope, pm_scope_node_t *previous);
67void pm_scope_node_destroy(pm_scope_node_t *scope_node);
68
69 typedef struct {
71 pm_parser_t parser;
72
74 pm_options_t options;
75
77 pm_string_t input;
78
80 pm_scope_node_t node;
81
83 bool parsed;
84} pm_parse_result_t;
85
86#define PM_SPECIAL_CONSTANT_FLAG ((pm_constant_id_t)(1 << 31))
87#define PM_CONSTANT_AND ((pm_constant_id_t)(idAnd | PM_SPECIAL_CONSTANT_FLAG))
88#define PM_CONSTANT_DOT3 ((pm_constant_id_t)(idDot3 | PM_SPECIAL_CONSTANT_FLAG))
89#define PM_CONSTANT_MULT ((pm_constant_id_t)(idMULT | PM_SPECIAL_CONSTANT_FLAG))
90#define PM_CONSTANT_POW ((pm_constant_id_t)(idPow | PM_SPECIAL_CONSTANT_FLAG))
91
92 VALUE pm_load_file(pm_parse_result_t *result, VALUE filepath, bool load_error);
93 VALUE pm_parse_file(pm_parse_result_t *result, VALUE filepath, VALUE *script_lines);
94 VALUE pm_load_parse_file(pm_parse_result_t *result, VALUE filepath, VALUE *script_lines);
95 VALUE pm_parse_string(pm_parse_result_t *result, VALUE source, VALUE filepath, VALUE *script_lines);
96 VALUE pm_parse_stdin(pm_parse_result_t *result);
97void pm_parse_result_free(pm_parse_result_t *result);
98
99rb_iseq_t *pm_iseq_new(pm_scope_node_t *node, VALUE name, VALUE path, VALUE realpath, const rb_iseq_t *parent, enum rb_iseq_type, int *error_state);
100rb_iseq_t *pm_iseq_new_top(pm_scope_node_t *node, VALUE name, VALUE path, VALUE realpath, const rb_iseq_t *parent, int *error_state);
101rb_iseq_t *pm_iseq_new_main(pm_scope_node_t *node, VALUE path, VALUE realpath, const rb_iseq_t *parent, int opt, int *error_state);
102rb_iseq_t *pm_iseq_new_eval(pm_scope_node_t *node, VALUE name, VALUE path, VALUE realpath, int first_lineno, const rb_iseq_t *parent, int isolated_depth, int *error_state);
103rb_iseq_t *pm_iseq_new_with_opt(pm_scope_node_t *node, VALUE name, VALUE path, VALUE realpath, int first_lineno, const rb_iseq_t *parent, int isolated_depth, enum rb_iseq_type, const rb_compile_option_t *option, int *error_state);
104
105 VALUE pm_iseq_compile_node(rb_iseq_t *iseq, pm_scope_node_t *node);
pm_node_t
struct pm_node pm_node_t
This is the base structure that represents a node in the syntax tree.
encoding.h
Encoding relates APIs.
pm_options_t
struct pm_options pm_options_t
The options that can be passed to the parser.
pm_parser_t
struct pm_parser pm_parser_t
The parser used to parse Ruby source.
Definition parser.h:267
prism.h
The main header file for the prism parser.
iseq_link_anchor
Definition compile.c:66
pm_constant_id_list_t
A list of constant IDs.
Definition pm_constant_pool.h:36
pm_local_index_struct
the getlocal and setlocal instructions require two parameters.
Definition prism_compile.h:12
pm_parse_result_t
Definition prism_compile.h:69
pm_parse_result_t::parsed
bool parsed
Whether or not this parse result has performed its parsing yet.
Definition prism_compile.h:83
pm_parse_result_t::node
pm_scope_node_t node
The resulting scope node that will hold the generated AST.
Definition prism_compile.h:80
pm_parse_result_t::input
pm_string_t input
The input that represents the source to be parsed.
Definition prism_compile.h:77
pm_parse_result_t::parser
pm_parser_t parser
The parser that will do the actual parsing.
Definition prism_compile.h:71
pm_parse_result_t::options
pm_options_t options
The options that will be passed to the parser.
Definition prism_compile.h:74
pm_scope_node
Definition prism_compile.h:21
pm_scope_node::filepath_encoding
rb_encoding * filepath_encoding
This is the encoding of the actual filepath object that will be used when a FILE node is compiled or ...
Definition prism_compile.h:47
pm_scope_node::pre_execution_anchor
struct iseq_link_anchor * pre_execution_anchor
This will only be set on the top-level scope node.
Definition prism_compile.h:63
pm_scope_node::script_lines
VALUE * script_lines
This is a pointer to the list of script lines for the ISEQs that will be associated with this scope n...
Definition prism_compile.h:40
pm_string_t
A generic string type that can have various ownership semantics.
Definition pm_string.h:33
st_table
Definition st.h:79
ID
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
Definition value.h:52
VALUE
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40