Ruby 3.5.0dev (2025-02-20 revision 34098b669c0cbc024cd08e686891f1dfe0a10aaf)
prism_compile.h (34098b669c0cbc024cd08e686891f1dfe0a10aaf)
1#include "prism/prism.h"
2#include "ruby/encoding.h"
3
12typedef struct pm_local_index_struct {
13 int index, level;
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.
21typedef 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;
28
29 const pm_parser_t *parser;
30 rb_encoding *encoding;
31
41
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
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
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
92VALUE pm_load_file(pm_parse_result_t *result, VALUE filepath, bool load_error);
93VALUE pm_parse_file(pm_parse_result_t *result, VALUE filepath, VALUE *script_lines);
94VALUE pm_load_parse_file(pm_parse_result_t *result, VALUE filepath, VALUE *script_lines);
95VALUE pm_parse_string(pm_parse_result_t *result, VALUE source, VALUE filepath, VALUE *script_lines);
96VALUE 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
105VALUE pm_iseq_compile_node(rb_iseq_t *iseq, pm_scope_node_t *node);
Encoding relates APIs.
The main header file for the prism parser.
A list of constant IDs.
the getlocal and setlocal instructions require two parameters.
This is the base structure that represents a node in the syntax tree.
Definition ast.h:1069
The options that can be passed to the parser.
Definition options.h:98
bool parsed
Whether or not this parse result has performed its parsing yet.
pm_scope_node_t node
The resulting scope node that will hold the generated AST.
pm_string_t input
The input that represents the source to be parsed.
pm_parser_t parser
The parser that will do the actual parsing.
pm_options_t options
The options that will be passed to the parser.
This struct represents the overall parser.
Definition parser.h:640
rb_encoding * filepath_encoding
This is the encoding of the actual filepath object that will be used when a FILE node is compiled or ...
struct iseq_link_anchor * pre_execution_anchor
This will only be set on the top-level scope node.
VALUE * script_lines
This is a pointer to the list of script lines for the ISEQs that will be associated with this scope n...
A generic string type that can have various ownership semantics.
Definition pm_string.h:33
Definition st.h:79
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
Definition value.h:52
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40