summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--examples/targets/chipKitMax32.rb36
-rw-r--r--src/codegen.c4
-rw-r--r--test/assert.rb33
-rw-r--r--test/t/exception.rb28
4 files changed, 101 insertions, 0 deletions
diff --git a/examples/targets/chipKitMax32.rb b/examples/targets/chipKitMax32.rb
new file mode 100644
index 000000000..2fa97b05b
--- /dev/null
+++ b/examples/targets/chipKitMax32.rb
@@ -0,0 +1,36 @@
+# Cross Compiling configuration for Digilent chipKIT Max32
+# http://www.digilentinc.com/Products/Detail.cfm?Prod=CHIPKIT-MAX32
+#
+# Requires MPIDE (https://github.com/chipKIT32/chipKIT32-MAX)
+#
+# This configuration is based on @kyab's version
+# http://d.hatena.ne.jp/kyab/20130201
+MRuby::CrossBuild.new("chipKitMax32") do |conf|
+ toolchain :gcc
+
+ # Mac OS X
+ # MPIDE_PATH = '/Applications/mpide.app/Contents/Resources/Java'
+ # GNU Linux
+ MPIDE_PATH = '/opt/mpide-0023-linux-20120903'
+
+ PIC32_PATH = "#{MPIDE_PATH}/hardware/pic32"
+
+ conf.cc do |cc|
+ cc.command="#{PIC32_PATH}/compiler/pic32-tools/bin/pic32-gcc"
+ cc.include_paths = ["#{PIC32_PATH}/cores/pic32",
+ "#{PIC32_PATH}/variants/Max32",
+ "#{MRUBY_ROOT}/include"]
+ cc.flags << "-O2 -mno-smart-io -w -ffunction-sections -fdata-sections -g -mdebugger -Wcast-align " +
+ "-fno-short-double -mprocessor=32MX795F512L -DF_CPU=80000000L -DARDUINO=23 -D_BOARD_MEGA_ " +
+ "-DMPIDEVER=0x01000202 -DMPIDE=23"
+ cc.compile_options = "%{flags} -o %{outfile} -c %{infile}"
+ end
+
+ conf.archiver do |archiver|
+ archiver.command = "#{PIC32_PATH}/compiler/pic32-tools/bin/pic32-ar"
+ archiver.archive_options = 'rcs %{outfile} %{objs}'
+ end
+
+ # No binaries necessary
+ conf.bins = []
+end
diff --git a/src/codegen.c b/src/codegen.c
index 1052f6dbf..53324f321 100644
--- a/src/codegen.c
+++ b/src/codegen.c
@@ -1083,6 +1083,7 @@ codegen(codegen_scope *s, node *tree, int val)
}
if (n3->cdr->cdr->car) {
codegen(s, n3->cdr->cdr->car, val);
+ if (val) pop();
}
tmp = new_label(s);
genop(s, MKOP_sBx(OP_JMP, exend));
@@ -1102,6 +1103,9 @@ codegen(codegen_scope *s, node *tree, int val)
if (tree->car) {
codegen(s, tree->car, val);
}
+ else if (val) {
+ push();
+ }
dispatch_linked(s, exend);
loop_pop(s, NOVAL);
}
diff --git a/test/assert.rb b/test/assert.rb
index 9f3231cd4..027d2a66f 100644
--- a/test/assert.rb
+++ b/test/assert.rb
@@ -79,6 +79,39 @@ def assert_nil(obj, msg = nil)
assert_true(obj.nil?, msg, diff)
end
+def assert_include(collection, obj, msg = nil)
+ msg = "Expected #{collection.inspect} to include #{obj.inspect}" unless msg
+ diff = " Collection: #{collection.inspect}\n" +
+ " Object: #{obj.inspect}"
+ assert_true(collection.include?(obj), msg, diff)
+end
+
+def assert_raise(*exp)
+ if $mrbtest_assert
+ $mrbtest_assert_idx += 1
+ msg = exp.last.class == String ? exp.pop : nil
+ msg = msg.to_s + " : " if msg
+ should_raise = false
+ begin
+ yield
+ should_raise = true
+ rescue Exception => e
+ msg = "#{msg}#{exp.inspect} exception expected, not"
+ diff = " Class: <#{e.class}>\n" +
+ " Message: #{e.message}"
+ if exp.any?{|ex| ex.instance_of?(Module) ? e.kind_of?(ex) : ex == e.class }
+ $mrbtest_assert.push([$mrbtest_assert_idx, msg, diff])
+ end
+ end
+
+ exp = exp.first if exp.first
+ if should_raise
+ msg = "#{msg}#{exp.inspect} expected but nothing was raised."
+ $mrbtest_assert.push([$mrbtest_assert_idx, msg, nil])
+ end
+ end
+end
+
##
# Report the test result and print all assertions
# which were reported broken.
diff --git a/test/t/exception.rb b/test/t/exception.rb
index a2e6acc07..663c8f337 100644
--- a/test/t/exception.rb
+++ b/test/t/exception.rb
@@ -287,6 +287,34 @@ assert('Exception 16') do
end
end
+assert('Exception 17') do
+ begin
+ raise "a" # StandardError
+ rescue ArgumentError
+ 1
+ rescue StandardError
+ 2
+ else
+ 3
+ ensure
+ 4
+ end == 2
+end
+
+assert('Exception 18') do
+ begin
+ 0
+ rescue ArgumentError
+ 1
+ rescue StandardError
+ 2
+ else
+ 3
+ ensure
+ 4
+ end == 3
+end
+
assert('Exception#inspect without message') do
Exception.new.inspect
end