[rubygems/rubygems] Use a constant empty tar header to avoid extra allocations
[ruby.git] / prism_compile.h
blob0f82782ec024077c1a6b0a4da9a9e59e39b77a82
1 #include "prism/prism.h"
2 #include "ruby/encoding.h"
4 /**
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 {
13 int index, level;
14 } pm_local_index_t;
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 {
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;
29 const pm_parser_t *parser;
30 rb_encoding *encoding;
32 /**
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
35 * error.
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;
44 ID *constants;
45 st_table *index_lookup_table;
47 /**
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;
52 } pm_scope_node_t;
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);
58 typedef struct {
59 /** The parser that will do the actual parsing. */
60 pm_parser_t parser;
62 /** The options that will be passed to the parser. */
63 pm_options_t options;
65 /** The input that represents the source to be parsed. */
66 pm_string_t input;
68 /** The resulting scope node that will hold the generated AST. */
69 pm_scope_node_t node;
71 /** Whether or not this parse result has performed its parsing yet. */
72 bool parsed;
73 } pm_parse_result_t;
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);