[macruby-changes] [1565] MacRuby/branches/experimental

source_changes at macosforge.org source_changes at macosforge.org
Mon May 11 15:50:15 PDT 2009


Revision: 1565
          http://trac.macosforge.org/projects/ruby/changeset/1565
Author:   lsansonetti at apple.com
Date:     2009-05-11 15:50:13 -0700 (Mon, 11 May 2009)
Log Message:
-----------
implement $! + fixed a bug in the way we save+pop the current VM exception

Modified Paths:
--------------
    MacRuby/branches/experimental/eval.c
    MacRuby/branches/experimental/roxor.cpp
    MacRuby/branches/experimental/test_vm/exception.rb

Modified: MacRuby/branches/experimental/eval.c
===================================================================
--- MacRuby/branches/experimental/eval.c	2009-05-11 20:07:05 UTC (rev 1564)
+++ MacRuby/branches/experimental/eval.c	2009-05-11 22:50:13 UTC (rev 1565)
@@ -1,16 +1,14 @@
-/**********************************************************************
+/* 
+ * MacRuby implementation of Ruby 1.9's eval.c.
+ *
+ * This file is covered by the Ruby license. See COPYING for more details.
+ * 
+ * Copyright (C) 2007-2008, Apple Inc. All rights reserved.
+ * Copyright (C) 1993-2007 Yukihiro Matsumoto
+ * Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
+ * Copyright (C) 2000 Information-technology Promotion Agency, Japan
+ */
 
-  eval.c -
-
-  $Author: nobu $
-  created at: Thu Jun 10 14:22:17 JST 1993
-
-  Copyright (C) 1993-2007 Yukihiro Matsumoto
-  Copyright (C) 2000  Network Applied Communication Laboratory, Inc.
-  Copyright (C) 2000  Information-technology Promotion Agency, Japan
-
-**********************************************************************/
-
 #include "ruby/ruby.h"
 #include "ruby/node.h"
 #include "roxor.h"
@@ -680,15 +678,17 @@
 static VALUE
 get_errinfo(void)
 {
-    // TODO
-    return Qnil;
+    VALUE exc = rb_vm_current_exception();
+    if (NIL_P(exc)) {
+	exc = rb_errinfo();
+    }
+    return exc;
 }
 
 static VALUE
 errinfo_getter(ID id)
 {
-    // TODO
-    return Qnil;
+    return get_errinfo();
 }
 
 VALUE

Modified: MacRuby/branches/experimental/roxor.cpp
===================================================================
--- MacRuby/branches/experimental/roxor.cpp	2009-05-11 20:07:05 UTC (rev 1564)
+++ MacRuby/branches/experimental/roxor.cpp	2009-05-11 22:50:13 UTC (rev 1565)
@@ -290,6 +290,7 @@
 	Function *gvarGetFunc;
 	Function *cvarSetFunc;
 	Function *cvarGetFunc;
+	Function *currentExceptionFunc;
 	Function *popExceptionFunc;
 	Function *getSpecialFunc;
 	Function *breakFunc;
@@ -776,6 +777,7 @@
     gvarGetFunc = NULL;
     cvarSetFunc = NULL;
     cvarGetFunc = NULL;
+    currentExceptionFunc = NULL;
     popExceptionFunc = NULL;
     getSpecialFunc = NULL;
     breakFunc = NULL;
@@ -1967,6 +1969,14 @@
 void
 RoxorCompiler::compile_landing_pad_footer(void)
 {
+    if (popExceptionFunc == NULL) {
+	// void rb_vm_pop_exception(void);
+	popExceptionFunc = cast<Function>(
+		module->getOrInsertFunction("rb_vm_pop_exception", 
+		    Type::VoidTy, NULL));
+    }
+    CallInst::Create(popExceptionFunc, "", bb);
+
     Function *endCatchFunc = NULL;
     if (endCatchFunc == NULL) {
 	// void __cxa_end_catch(void);
@@ -4704,13 +4714,14 @@
 
 	case NODE_ERRINFO:
 	    {
-		if (popExceptionFunc == NULL) {
-		    // VALUE rb_vm_pop_exception(void);
-		    popExceptionFunc = cast<Function>(
-			    module->getOrInsertFunction("rb_vm_pop_exception", 
+		if (currentExceptionFunc == NULL) {
+		    // VALUE rb_vm_current_exception(void);
+		    currentExceptionFunc = cast<Function>(
+			    module->getOrInsertFunction(
+				"rb_vm_current_exception", 
 				RubyObjTy, NULL));
 		}
-		return CallInst::Create(popExceptionFunc, "", bb);
+		return CallInst::Create(currentExceptionFunc, "", bb);
 	    }
 	    break;
 
@@ -8786,14 +8797,13 @@
 }
 
 extern "C"
-VALUE
+void
 rb_vm_pop_exception(void)
 {
     VALUE exc = GET_VM()->current_exception;
     assert(exc != Qnil);
     rb_objc_release((void *)exc);
     GET_VM()->current_exception = Qnil;
-    return exc; 
 }
 
 extern "C"
@@ -9017,7 +9027,6 @@
     rb_objc_retain((void *)err);
 }
 
-
 extern "C"
 const char *
 rb_sourcefile(void)

Modified: MacRuby/branches/experimental/test_vm/exception.rb
===================================================================
--- MacRuby/branches/experimental/test_vm/exception.rb	2009-05-11 20:07:05 UTC (rev 1564)
+++ MacRuby/branches/experimental/test_vm/exception.rb	2009-05-11 22:50:13 UTC (rev 1565)
@@ -133,3 +133,48 @@
   end
   foo
 }
+
+assert ':ok', %{
+  p :ok if $!.nil?
+}
+
+assert ':ok', %{
+  begin
+    p :ok if $!.nil?
+    raise
+  rescue
+  end
+}
+
+assert ':ok', %{
+  begin
+    raise 'foo'
+  rescue
+  end
+  p :ok if $!.nil?
+}
+
+assert ':ok', %{
+  begin
+    raise 'foo'
+  rescue => e
+  end
+  p :ok if $!.nil?
+}
+
+assert ':ok', %{
+  e = RuntimeError.new('foo')
+  begin
+    raise e
+  rescue
+    p :ok if $! == e
+  end
+}
+
+assert ':ok', %{
+  begin
+    raise 'foo'
+  rescue => e
+    p :ok if $! == e
+  end
+}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090511/57869c0c/attachment-0001.html>


More information about the macruby-changes mailing list