1 #include "prism/prism.h"
2 #include "ruby/encoding.h"
5 * the getlocal and setlocal instructions require two parameters. level is how
6 * many hops up the iseq stack one needs to go before finding the correct local
7 * table. The index is the index in that table where our variable is.
9 * Because these are always calculated and used together, we'll bind them
10 * together as a tuple.
12 typedef struct pm_local_index_struct
{
16 // A declaration for the struct that lives in compile.c.
17 struct iseq_link_anchor
;
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
{
23 struct pm_scope_node
*previous
;
25 pm_node_t
*parameters
;
27 pm_constant_id_list_t locals
;
29 const pm_parser_t
*parser
;
30 rb_encoding
*encoding
;
33 * This is the encoding of the actual filepath object that will be used when
34 * a __FILE__ node is compiled or when the path has to be set on a syntax
37 rb_encoding
*filepath_encoding
;
39 // The size of the local table
40 // on the iseq which includes
41 // locals and hidden variables
42 int local_table_for_iseq_size
;
45 st_table
*index_lookup_table
;
48 * This will only be set on the top-level scope node. It will contain all of
49 * the instructions pertaining to BEGIN{} nodes.
51 struct iseq_link_anchor
*pre_execution_anchor
;
54 void pm_scope_node_init(const pm_node_t
*node
, pm_scope_node_t
*scope
, pm_scope_node_t
*previous
);
55 void pm_scope_node_destroy(pm_scope_node_t
*scope_node
);
56 bool *rb_ruby_prism_ptr(void);
59 /** The parser that will do the actual parsing. */
62 /** The options that will be passed to the parser. */
65 /** The input that represents the source to be parsed. */
68 /** The resulting scope node that will hold the generated AST. */
71 /** Whether or not this parse result has performed its parsing yet. */
75 VALUE
pm_load_file(pm_parse_result_t
*result
, VALUE filepath
, bool load_error
);
76 VALUE
pm_parse_file(pm_parse_result_t
*result
, VALUE filepath
);
77 VALUE
pm_load_parse_file(pm_parse_result_t
*result
, VALUE filepath
);
78 VALUE
pm_parse_string(pm_parse_result_t
*result
, VALUE source
, VALUE filepath
);
79 VALUE
pm_parse_stdin(pm_parse_result_t
*result
);
80 void pm_parse_result_free(pm_parse_result_t
*result
);
82 rb_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
);
83 rb_iseq_t
*pm_iseq_new_top(pm_scope_node_t
*node
, VALUE name
, VALUE path
, VALUE realpath
, const rb_iseq_t
*parent
);
84 rb_iseq_t
*pm_iseq_new_main(pm_scope_node_t
*node
, VALUE path
, VALUE realpath
, const rb_iseq_t
*parent
, int opt
);
85 rb_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
);
86 rb_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
*);
88 VALUE
pm_iseq_compile_node(rb_iseq_t
*iseq
, pm_scope_node_t
*node
);