diff --git a/Cargo.lock b/Cargo.lock index 4836928..1057875 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -102,9 +102,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.177" +version = "0.2.182" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976" +checksum = "6800badb6cb2082ffd7b6a67e6125bb39f18782f793520caee8cb8846be06112" [[package]] name = "libloading" @@ -136,7 +136,7 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "mruby-compiler2-sys" -version = "0.2.2" +version = "0.3.0" dependencies = [ "bindgen", "cc", diff --git a/Cargo.toml b/Cargo.toml index 5402199..df71c9b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mruby-compiler2-sys" -version = "0.2.2" +version = "0.3.0" edition = "2024" authors = [ "Uchio Kondo ", @@ -19,7 +19,7 @@ include = [ ] [dependencies] -libc = { version = "0.2.177", optional = true } +libc = { version = "0.2.182", optional = true } [build-dependencies] bindgen = ">= 0" diff --git a/build.rs b/build.rs index 5ac13e9..cb90a9f 100644 --- a/build.rs +++ b/build.rs @@ -22,6 +22,9 @@ fn main() { .define("MRB_INT64", "1") .define("PRISM_XALLOCATOR", "") .define("PRISM_BUILD_MINIMAL", "") + .define("PICORB_VM_MRUBYC", "") + .define("MRBC_ALLOC_LIBC", "") + .include("./vendor/include") .include("./vendor/mruby-compiler2/include") .include("./vendor/mruby-compiler2/lib/prism/include") .flag("-fPIC") diff --git a/vendor/include/mrubyc.h b/vendor/include/mrubyc.h new file mode 100644 index 0000000..8041d95 --- /dev/null +++ b/vendor/include/mrubyc.h @@ -0,0 +1 @@ +// Dummy inclusion header \ No newline at end of file diff --git a/vendor/mruby-compiler2/include/mrc_common.h b/vendor/mruby-compiler2/include/mrc_common.h index 3e00f69..7c17cd4 100644 --- a/vendor/mruby-compiler2/include/mrc_common.h +++ b/vendor/mruby-compiler2/include/mrc_common.h @@ -30,9 +30,15 @@ #endif #include "prism.h" -#define MRC_RELEASE_YEAR 2024 -#define MRC_RELEASE_MONTH 9 -#define MRC_RELEASE_DAY 9 +#ifndef PICORUBY_VERSION + #define MRC_VERSION "unknown (standalone)" +#else + #define MRC_VERSION PICORUBY_VERSION +#endif + +#define MRC_RELEASE_YEAR 2026 +#define MRC_RELEASE_MONTH 1 +#define MRC_RELEASE_DAY 21 #define MRC_RELEASE_DATE MRC_STRINGIZE(MRC_RELEASE_YEAR) "-" \ MRC_STRINGIZE(MRC_RELEASE_MONTH) "-" \ MRC_STRINGIZE(MRC_RELEASE_DAY) diff --git a/vendor/mruby-compiler2/include/mrc_dump.h b/vendor/mruby-compiler2/include/mrc_dump.h index 8cbd956..7e64f8a 100644 --- a/vendor/mruby-compiler2/include/mrc_dump.h +++ b/vendor/mruby-compiler2/include/mrc_dump.h @@ -145,7 +145,7 @@ mrc_bin_to_uint8(const uint8_t *bin) static inline const char* mrc_description(void) { - return "(" MRC_RELEASE_DATE ") Parser: " RITE_PARSER_NAME ", RITE: " RITE_BINARY_FORMAT_VER; + return MRC_VERSION " (" MRC_RELEASE_DATE ") Parser: " RITE_PARSER_NAME ", RITE: " RITE_BINARY_FORMAT_VER; } MRC_END_DECL diff --git a/vendor/mruby-compiler2/include/mrc_irep.h b/vendor/mruby-compiler2/include/mrc_irep.h index e5f9cff..3ae3ea8 100644 --- a/vendor/mruby-compiler2/include/mrc_irep.h +++ b/vendor/mruby-compiler2/include/mrc_irep.h @@ -14,15 +14,6 @@ */ MRC_BEGIN_DECL -enum irep_pool_type { - IREP_TT_STR = 0, /* string (need free) */ - IREP_TT_SSTR = 2, /* string (static) */ - IREP_TT_INT32 = 1, /* 32bit integer */ - IREP_TT_INT64 = 3, /* 64bit integer */ - IREP_TT_BIGINT = 7, /* big integer (not yet supported) */ - IREP_TT_FLOAT = 5, /* float (double/float) */ -}; - #define IREP_TT_NFLAG 1 /* number (non string) flag */ #define IREP_TT_SFLAG 2 /* static string flag */ diff --git a/vendor/mruby-compiler2/include/mrc_irep_pool_type.h b/vendor/mruby-compiler2/include/mrc_irep_pool_type.h new file mode 100644 index 0000000..c0d861a --- /dev/null +++ b/vendor/mruby-compiler2/include/mrc_irep_pool_type.h @@ -0,0 +1,17 @@ +#ifndef MRB_IREP_POOL_TYPE_H +#define MRB_IREP_POOL_TYPE_H + +MRC_BEGIN_DECL + +enum irep_pool_type { + IREP_TT_STR = 0, /* string (need free) */ + IREP_TT_SSTR = 2, /* string (static) */ + IREP_TT_INT32 = 1, /* 32bit integer */ + IREP_TT_INT64 = 3, /* 64bit integer */ + IREP_TT_BIGINT = 7, /* big integer (not yet supported) */ + IREP_TT_FLOAT = 5, /* float (double/float) */ +}; + +MRC_END_DECL + +#endif diff --git a/vendor/mruby-compiler2/include/mrc_presym.inc b/vendor/mruby-compiler2/include/mrc_presym.inc index 15ea471..e204890 100644 --- a/vendor/mruby-compiler2/include/mrc_presym.inc +++ b/vendor/mruby-compiler2/include/mrc_presym.inc @@ -30,3 +30,4 @@ MRC_SYM_1(compile, 28) MRC_SYM_1(__ENCODING__, 29) MRC_SYM_2(nil_p, nil?,30) MRC_SYM_2(back_ref, $+, 31) +MRC_SYM_2(defined_p, defined?, 32) diff --git a/vendor/mruby-compiler2/lib/prism/prism.gemspec b/vendor/mruby-compiler2/lib/prism/prism.gemspec new file mode 100644 index 0000000..1947eed --- /dev/null +++ b/vendor/mruby-compiler2/lib/prism/prism.gemspec @@ -0,0 +1,170 @@ +# frozen_string_literal: true + +Gem::Specification.new do |spec| + spec.name = "prism" + spec.version = "1.4.0" + spec.authors = ["Shopify"] + spec.email = ["ruby@shopify.com"] + + spec.summary = "Prism Ruby parser" + spec.homepage = "https://github.com/ruby/prism" + spec.license = "MIT" + + spec.required_ruby_version = ">= 2.7.0" + + spec.require_paths = ["lib"] + spec.files = [ + "BSDmakefile", + "CHANGELOG.md", + "CODE_OF_CONDUCT.md", + "CONTRIBUTING.md", + "LICENSE.md", + "Makefile", + "README.md", + "config.yml", + "docs/build_system.md", + "docs/configuration.md", + "docs/cruby_compilation.md", + "docs/design.md", + "docs/encoding.md", + "docs/fuzzing.md", + "docs/heredocs.md", + "docs/javascript.md", + "docs/local_variable_depth.md", + "docs/mapping.md", + "docs/parser_translation.md", + "docs/parsing_rules.md", + "docs/releasing.md", + "docs/relocation.md", + "docs/ripper_translation.md", + "docs/ruby_api.md", + "docs/ruby_parser_translation.md", + "docs/serialization.md", + "docs/testing.md", + "ext/prism/api_node.c", + "ext/prism/api_pack.c", + "ext/prism/extension.c", + "ext/prism/extension.h", + "include/prism.h", + "include/prism/ast.h", + "include/prism/defines.h", + "include/prism/diagnostic.h", + "include/prism/encoding.h", + "include/prism/node.h", + "include/prism/options.h", + "include/prism/pack.h", + "include/prism/parser.h", + "include/prism/prettyprint.h", + "include/prism/regexp.h", + "include/prism/static_literals.h", + "include/prism/util/pm_buffer.h", + "include/prism/util/pm_char.h", + "include/prism/util/pm_constant_pool.h", + "include/prism/util/pm_integer.h", + "include/prism/util/pm_list.h", + "include/prism/util/pm_memchr.h", + "include/prism/util/pm_newline_list.h", + "include/prism/util/pm_strncasecmp.h", + "include/prism/util/pm_string.h", + "include/prism/util/pm_strpbrk.h", + "include/prism/version.h", + "lib/prism.rb", + "lib/prism/compiler.rb", + "lib/prism/desugar_compiler.rb", + "lib/prism/dispatcher.rb", + "lib/prism/dot_visitor.rb", + "lib/prism/dsl.rb", + "lib/prism/ffi.rb", + "lib/prism/inspect_visitor.rb", + "lib/prism/lex_compat.rb", + "lib/prism/mutation_compiler.rb", + "lib/prism/node_ext.rb", + "lib/prism/node.rb", + "lib/prism/pack.rb", + "lib/prism/parse_result.rb", + "lib/prism/parse_result/comments.rb", + "lib/prism/parse_result/errors.rb", + "lib/prism/parse_result/newlines.rb", + "lib/prism/pattern.rb", + "lib/prism/polyfill/append_as_bytes.rb", + "lib/prism/polyfill/byteindex.rb", + "lib/prism/polyfill/unpack1.rb", + "lib/prism/reflection.rb", + "lib/prism/relocation.rb", + "lib/prism/serialize.rb", + "lib/prism/string_query.rb", + "lib/prism/translation.rb", + "lib/prism/translation/parser.rb", + "lib/prism/translation/parser33.rb", + "lib/prism/translation/parser34.rb", + "lib/prism/translation/parser35.rb", + "lib/prism/translation/parser/builder.rb", + "lib/prism/translation/parser/compiler.rb", + "lib/prism/translation/parser/lexer.rb", + "lib/prism/translation/ripper.rb", + "lib/prism/translation/ripper/sexp.rb", + "lib/prism/translation/ripper/shim.rb", + "lib/prism/translation/ruby_parser.rb", + "lib/prism/visitor.rb", + "prism.gemspec", + "rbi/prism.rbi", + "rbi/prism/compiler.rbi", + "rbi/prism/dsl.rbi", + "rbi/prism/inspect_visitor.rbi", + "rbi/prism/node_ext.rbi", + "rbi/prism/node.rbi", + "rbi/prism/parse_result.rbi", + "rbi/prism/reflection.rbi", + "rbi/prism/string_query.rbi", + "rbi/prism/translation/parser.rbi", + "rbi/prism/translation/parser33.rbi", + "rbi/prism/translation/parser34.rbi", + "rbi/prism/translation/parser35.rbi", + "rbi/prism/translation/ripper.rbi", + "rbi/prism/visitor.rbi", + "sig/prism.rbs", + "sig/prism/compiler.rbs", + "sig/prism/dispatcher.rbs", + "sig/prism/dot_visitor.rbs", + "sig/prism/dsl.rbs", + "sig/prism/inspect_visitor.rbs", + "sig/prism/lex_compat.rbs", + "sig/prism/mutation_compiler.rbs", + "sig/prism/node_ext.rbs", + "sig/prism/node.rbs", + "sig/prism/pack.rbs", + "sig/prism/parse_result.rbs", + "sig/prism/pattern.rbs", + "sig/prism/reflection.rbs", + "sig/prism/relocation.rbs", + "sig/prism/serialize.rbs", + "sig/prism/string_query.rbs", + "sig/prism/visitor.rbs", + "src/diagnostic.c", + "src/encoding.c", + "src/node.c", + "src/options.c", + "src/pack.c", + "src/prettyprint.c", + "src/prism.c", + "src/regexp.c", + "src/serialize.c", + "src/static_literals.c", + "src/token_type.c", + "src/util/pm_buffer.c", + "src/util/pm_char.c", + "src/util/pm_constant_pool.c", + "src/util/pm_integer.c", + "src/util/pm_list.c", + "src/util/pm_memchr.c", + "src/util/pm_newline_list.c", + "src/util/pm_string.c", + "src/util/pm_strncasecmp.c", + "src/util/pm_strpbrk.c" + ] + + spec.extensions = ["ext/prism/extconf.rb"] + spec.metadata["allowed_push_host"] = "https://rubygems.org" + spec.metadata["source_code_uri"] = "https://github.com/ruby/prism" + spec.metadata["changelog_uri"] = "https://github.com/ruby/prism/blob/main/CHANGELOG.md" +end diff --git a/vendor/mruby-compiler2/src/cdump.c b/vendor/mruby-compiler2/src/cdump.c index 853a83e..51446df 100644 --- a/vendor/mruby-compiler2/src/cdump.c +++ b/vendor/mruby-compiler2/src/cdump.c @@ -10,6 +10,7 @@ #include "../include/mrc_irep.h" #include "../include/mrc_dump.h" #include "../include/mrc_debug.h" +#include "../include/mrc_irep_pool_type.h" #ifndef MRC_NO_STDIO diff --git a/vendor/mruby-compiler2/src/codedump.c b/vendor/mruby-compiler2/src/codedump.c index 4a1987a..974919c 100644 --- a/vendor/mruby-compiler2/src/codedump.c +++ b/vendor/mruby-compiler2/src/codedump.c @@ -6,6 +6,7 @@ #include "../include/mrc_parser_util.h" #include "../include/mrc_pool.h" #include "../include/mrc_debug.h" +#include "../include/mrc_irep_pool_type.h" #include const char * diff --git a/vendor/mruby-compiler2/src/codegen.c b/vendor/mruby-compiler2/src/codegen.c index 79dcb0b..54e4aa2 100644 --- a/vendor/mruby-compiler2/src/codegen.c +++ b/vendor/mruby-compiler2/src/codegen.c @@ -9,6 +9,7 @@ #include "../include/mrc_pool.h" #include "../include/mrc_dump.h" #include "../include/mrc_debug.h" +#include "../include/mrc_irep_pool_type.h" #if defined(PICORB_VM_MRUBY) #include "../include/mrc_proc.h" diff --git a/vendor/mruby-compiler2/src/codegen_prism.inc b/vendor/mruby-compiler2/src/codegen_prism.inc index 9892d5f..094e56f 100644 --- a/vendor/mruby-compiler2/src/codegen_prism.inc +++ b/vendor/mruby-compiler2/src/codegen_prism.inc @@ -13,6 +13,13 @@ nsym(mrc_parser_state *p, const uint8_t *start, size_t length) return sym; } +static int32_t +node_lineno(mrc_ccontext *c, mrc_node *node) +{ + pm_location_t *loc = &((pm_node_t *)node)->location; + return pm_newline_list_line(&c->p->newline_list, loc->start, 1); +} + static mrc_bool true_always(mrc_node *tree) { @@ -1165,8 +1172,7 @@ codegen(mrc_codegen_scope *s, mrc_node *tree, int val) int nt = nint(tree); - //TODO lineno - // s->lineno = tree->lineno; + s->lineno = node_lineno(s->c, tree); switch (nt) { case PM_PROGRAM_NODE: { @@ -2786,6 +2792,39 @@ codegen(mrc_codegen_scope *s, mrc_node *tree, int val) } break; } + case PM_RESCUE_MODIFIER_NODE: + { + CAST(rescue_modifier); + int catch_entry, begin_pos, end_pos; + struct loopinfo *lp; + + lp = loop_push(s, LOOP_BEGIN); + lp->pc0 = new_label(s); + catch_entry = catch_handler_new(s); + begin_pos = s->pc; + + /* evaluate main expression */ + codegen(s, cast->expression, val); + if (val) pop(); + + lp->type = LOOP_RESCUE; + end_pos = s->pc; + int noexc = genjmp_0(s, OP_JMP); + catch_handler_set(s, catch_entry, MRC_CATCH_RESCUE, begin_pos, end_pos, s->pc); + + /* rescue expression */ + int exc = cursp(); + genop_1(s, OP_EXCEPT, exc); + push(); + pop(); + codegen(s, cast->rescue_expression, val); + if (val) pop(); + + dispatch(s, noexc); + if (val) push(); + loop_pop(s, NOVAL); + break; + } case PM_BLOCK_ARGUMENT_NODE: { CAST(block_argument); @@ -2894,6 +2933,17 @@ codegen(mrc_codegen_scope *s, mrc_node *tree, int val) } break; } + case PM_DEFINED_NODE: + { + CAST(defined); + push(); + codegen(s, cast->value, VAL); + pop(); + pop(); + genop_3(s, OP_SSEND, cursp(), new_sym(s, MRC_SYM_2(defined_p)), 1); + push(); + break; + } default: { char buf[256]; diff --git a/vendor/mruby-compiler2/src/dump.c b/vendor/mruby-compiler2/src/dump.c index 70cd726..a1da7da 100644 --- a/vendor/mruby-compiler2/src/dump.c +++ b/vendor/mruby-compiler2/src/dump.c @@ -4,6 +4,7 @@ #include "../include/mrc_dump.h" #include "../include/mrc_parser_util.h" #include "../include/mrc_debug.h" +#include "../include/mrc_irep_pool_type.h" #if !defined(BYTE_ORDER) && defined(__BYTE_ORDER__) # define BYTE_ORDER __BYTE_ORDER__ diff --git a/vendor/mruby-compiler2/src/irep.c b/vendor/mruby-compiler2/src/irep.c index d8fe1da..92108fe 100644 --- a/vendor/mruby-compiler2/src/irep.c +++ b/vendor/mruby-compiler2/src/irep.c @@ -1,5 +1,6 @@ #include "../include/mrc_irep.h" #include "../include/mrc_debug.h" +#include "../include/mrc_irep_pool_type.h" void mrc_irep_remove_lv(mrc_ccontext *c, mrc_irep *irep)