Permalink
Browse files

Fixed 1 arg form of parse_tree_for_proc

[git-p4: depot-paths = "//src/ParseTree/dev/": change = 4437]
  • Loading branch information...
1 parent bd45c74 commit 6d188f7d9491c7fc0b60d9e8621299974f938d82 @zenspider zenspider committed Nov 1, 2008
Showing with 60 additions and 7 deletions.
  1. +8 −1 History.txt
  2. +6 −3 lib/parse_tree.rb
  3. +46 −3 test/test_parse_tree_extensions.rb
View
@@ -1,6 +1,13 @@
+=== 3.0.2 / 2008-11-01
+
+* N bug fixes:
+
+ * Fixed 1 arg form of parse_tree_for_proc
+ * KNOWN ISSUE: 0 arg form (||) of parse_tree_for_proc segfaults.
+
=== 3.0.1 / 2008-10-23
-* 1 bug fix
+* 1 bug fix:
* Fixed the dependency on sexp_processor (accidentally camelcased). thanks ez!
View
@@ -43,7 +43,7 @@ def modules
class RawParseTree
- VERSION = '3.0.1'
+ VERSION = '3.0.2'
##
# Front end translation method.
@@ -276,7 +276,8 @@ def self.has_alloca
builder.add_compile_flags "-Wno-long-long"
# NOTE: this flag doesn't work w/ gcc 2.95.x - the FreeBSD default
- # builder.add_compile_flags "-Wno-strict-aliasing"
+ builder.add_compile_flags "-Wno-strict-aliasing"
+
# ruby.h screws these up hardcore:
# builder.add_compile_flags "-Wundef"
# builder.add_compile_flags "-Wconversion"
@@ -298,6 +299,7 @@ def self.has_alloca
static unsigned case_level = 0;
static unsigned when_level = 0;
static unsigned inside_case_args = 0;
+ static int masgn_level = 0;
}
builder.prefix %{
@@ -350,7 +352,6 @@ def self.has_alloca
VALUE current;
VALUE node_name;
static VALUE node_names = Qnil;
- static int masgn_level = 0;
if (NIL_P(node_names)) {
node_names = rb_const_get_at(rb_path2class("RawParseTree"),rb_intern("NODE_NAMES"));
@@ -1051,12 +1052,14 @@ def self.has_alloca
rb_ary_push(result, _sym("iter"));
rb_ary_push(result, rb_ary_new3(4, _sym("call"), Qnil, _sym("proc"),
rb_ary_new3(1, _sym("arglist"))));
+ masgn_level++;
if (data->var) {
add_to_parse_tree(self, result, data->var, NULL);
} else {
rb_ary_push(result, Qnil);
}
add_to_parse_tree(self, result, data->body, NULL);
+ masgn_level--;
return result;
}
@@ -13,6 +13,25 @@ def test_proc_to_ruby
assert_equal 'proc { puts("something") }', block.to_ruby
end
+ # TODO: bus error
+# def test_proc_to_ruby_args_0
+# util_setup_inline
+# block = proc { || puts 42 }
+# assert_equal 'proc { || puts(42) }', block.to_ruby
+# end
+
+ def test_proc_to_ruby_args_1
+ util_setup_inline
+ block = proc { |x| puts x }
+ assert_equal 'proc { |x| puts(x) }', block.to_ruby
+ end
+
+ def test_proc_to_ruby_args_n
+ util_setup_inline
+ block = proc { |x| puts x }
+ assert_equal 'proc { |x| puts(x) }', block.to_ruby
+ end
+
def test_proc_to_sexp
util_setup_inline
p = proc { 1 + 1 }
@@ -23,12 +42,36 @@ def test_proc_to_sexp
assert_equal s, p.to_sexp
end
- def test_proc_to_sexp_args
+ # TODO: bus error
+# def test_proc_to_sexp_args_0
+# util_setup_inline
+# p = proc { || 1 + 1 }
+# s = s(:iter,
+# s(:call, nil, :proc, s(:arglist)),
+# nil,
+# s(:call, s(:lit, 1), :+, s(:arglist, s(:lit, 1))))
+# assert_equal s, p.to_sexp
+# end
+
+ def test_proc_to_sexp_args_1
util_setup_inline
- p = proc {|a, b, c|}
+ p = proc {|x| puts x }
s = s(:iter,
s(:call, nil, :proc, s(:arglist)),
- s(:masgn, s(:array, s(:lasgn, :a), s(:lasgn, :b), s(:lasgn, :c))))
+ s(:lasgn, :x),
+ s(:call, nil, :puts, s(:arglist, s(:lvar, :x))))
+
+ assert_equal s, p.to_sexp
+ end
+
+ def test_proc_to_sexp_args_n
+ util_setup_inline
+ p = proc {|x, y| puts x + y }
+ s = s(:iter,
+ s(:call, nil, :proc, s(:arglist)),
+ s(:masgn, s(:array, s(:lasgn, :x), s(:lasgn, :y))),
+ s(:call, nil, :puts,
+ s(:arglist, s(:call, s(:lvar, :x), :+, s(:arglist, s(:lvar, :y))))))
assert_equal s, p.to_sexp
end

0 comments on commit 6d188f7

Please sign in to comment.