diff options
-rw-r--r-- | ast.c (renamed from ext/-test-/ast/ast.c) | 2 | ||||
-rw-r--r-- | common.mk | 7 | ||||
-rw-r--r-- | ext/-test-/ast/extconf.rb | 3 | ||||
-rw-r--r-- | inits.c | 1 | ||||
-rw-r--r-- | test/-ext-/ast/test_ast.rb | 59 |
5 files changed, 39 insertions, 33 deletions
diff --git a/ext/-test-/ast/ast.c b/ast.c index dfb31197ef..f6af7ce1b3 100644 --- a/ext/-test-/ast/ast.c +++ b/ast.c @@ -479,7 +479,7 @@ rb_ast_node_inspect(VALUE self) void Init_ast(void) { - rb_mAST = rb_define_module("AST"); + rb_mAST = rb_define_module_under(rb_cRubyVM, "AST"); rb_cNode = rb_define_class_under(rb_mAST, "Node", rb_cObject); rb_define_alloc_func(rb_cNode, rb_ast_node_alloc); @@ -75,6 +75,7 @@ MAKE_ENC = -f $(ENC_MK) V="$(V)" UNICODE_HDR_DIR="$(UNICODE_HDR_DIR)" \ RUBY="$(MINIRUBY)" MINIRUBY="$(MINIRUBY)" $(mflags) COMMONOBJS = array.$(OBJEXT) \ + ast.$(OBJEXT) \ bignum.$(OBJEXT) \ class.$(OBJEXT) \ compar.$(OBJEXT) \ @@ -1445,6 +1446,12 @@ array.$(OBJEXT): {$(VPATH)}ruby_assert.h array.$(OBJEXT): {$(VPATH)}st.h array.$(OBJEXT): {$(VPATH)}subst.h array.$(OBJEXT): {$(VPATH)}util.h +ast.$(OBJEXT): $(hdrdir)/ruby/ruby.h +ast.$(OBJEXT): $(top_srcdir)/include/ruby.h +ast.$(OBJEXT): {$(VPATH)}encoding.h +ast.$(OBJEXT): {$(VPATH)}internal.h +ast.$(OBJEXT): {$(VPATH)}node.h +ast.$(OBJEXT): {$(VPATH)}vm_core.h bignum.$(OBJEXT): $(hdrdir)/ruby/ruby.h bignum.$(OBJEXT): $(top_srcdir)/include/ruby.h bignum.$(OBJEXT): {$(VPATH)}bignum.c diff --git a/ext/-test-/ast/extconf.rb b/ext/-test-/ast/extconf.rb deleted file mode 100644 index d786b15db9..0000000000 --- a/ext/-test-/ast/extconf.rb +++ /dev/null @@ -1,3 +0,0 @@ -# frozen_string_literal: false -require_relative "../auto_ext.rb" -auto_ext(inc: true) @@ -61,5 +61,6 @@ rb_call_inits(void) CALL(Complex); CALL(version); CALL(vm_trace); + CALL(ast); } #undef CALL diff --git a/test/-ext-/ast/test_ast.rb b/test/-ext-/ast/test_ast.rb index 06bb0bf5e2..9133c75311 100644 --- a/test/-ext-/ast/test_ast.rb +++ b/test/-ext-/ast/test_ast.rb @@ -1,38 +1,39 @@ # frozen_string_literal: false require 'test/unit' -require "-test-/ast" - -module AST - class Node - class CodePosition - include Comparable - attr_reader :lineno, :column - def initialize(lineno, column) - @lineno = lineno - @column = column - end - def <=>(other) - case - when lineno < other.lineno - -1 - when lineno == other.lineno - column <=> other.column - when lineno > other.lineno - 1 +class RubyVM + module AST + class Node + class CodePosition + include Comparable + attr_reader :lineno, :column + def initialize(lineno, column) + @lineno = lineno + @column = column + end + + def <=>(other) + case + when lineno < other.lineno + -1 + when lineno == other.lineno + column <=> other.column + when lineno > other.lineno + 1 + end end end - end - def beg_pos - CodePosition.new(first_lineno, first_column) - end + def beg_pos + CodePosition.new(first_lineno, first_column) + end - def end_pos - CodePosition.new(last_lineno, last_column) - end + def end_pos + CodePosition.new(last_lineno, last_column) + end - alias to_s inspect + alias to_s inspect + end end end @@ -62,7 +63,7 @@ class TestAst < Test::Unit::TestCase def ast return @ast if defined?(@ast) - ast = AST.parse_file(@path) + ast = RubyVM::AST.parse_file(@path) raise "Syntax error: #{@path}" if ast.nil? @ast = ast end @@ -132,7 +133,7 @@ class TestAst < Test::Unit::TestCase def test_column_with_long_heredoc_identifier term = "A"*257 - ast = AST.parse("<<-#{term}\n""ddddddd\n#{term}\n") + ast = RubyVM::AST.parse("<<-#{term}\n""ddddddd\n#{term}\n") node = ast.children[1] assert_equal("NODE_STR", node.type) assert_equal(0, node.first_column) |