Revision: 1298 http://trac.macosforge.org/projects/ruby/changeset/1298 Author: lsansonetti@apple.com Date: 2009-04-02 23:24:41 -0700 (Thu, 02 Apr 2009) Log Message: ----------- moved the VM exception handler to main() Modified Paths: -------------- MacRuby/branches/experimental/include/ruby/ruby.h MacRuby/branches/experimental/roxor.cpp Added Paths: ----------- MacRuby/branches/experimental/main.cpp Removed Paths: ------------- MacRuby/branches/experimental/main.c Modified: MacRuby/branches/experimental/include/ruby/ruby.h =================================================================== --- MacRuby/branches/experimental/include/ruby/ruby.h 2009-04-03 05:44:40 UTC (rev 1297) +++ MacRuby/branches/experimental/include/ruby/ruby.h 2009-04-03 06:24:41 UTC (rev 1298) @@ -1255,13 +1255,6 @@ static char *dln_libs_to_be_linked[] = { EXTLIB, 0 }; #endif -#if (defined(__APPLE__) || defined(__NeXT__)) && defined(__MACH__) && !defined(WITH_OBJC) -/* to link startup code with ObjC support */ -#define RUBY_GLOBAL_SETUP static void objcdummyfunction(void) {objc_msgSend(NULL,NULL);} -#else -#define RUBY_GLOBAL_SETUP -#endif - void ruby_sysinit(int *, char ***); #define RUBY_VM 1 /* YARV */ Deleted: MacRuby/branches/experimental/main.c =================================================================== --- MacRuby/branches/experimental/main.c 2009-04-03 05:44:40 UTC (rev 1297) +++ MacRuby/branches/experimental/main.c 2009-04-03 06:24:41 UTC (rev 1298) @@ -1,35 +0,0 @@ -/********************************************************************** - - main.c - - - $Author: nobu $ - created at: Fri Aug 19 13:19:58 JST 1994 - - Copyright (C) 1993-2007 Yukihiro Matsumoto - -**********************************************************************/ - -#undef RUBY_EXPORT -#include "ruby.h" -#ifdef HAVE_LOCALE_H -#include <locale.h> -#endif - -RUBY_GLOBAL_SETUP - -int -main(int argc, char **argv, char **envp) -{ -#ifdef RUBY_DEBUG_ENV - ruby_set_debug_option(getenv("RUBY_DEBUG")); -#endif -#ifdef HAVE_LOCALE_H - setlocale(LC_CTYPE, ""); -#endif - - ruby_sysinit(&argc, &argv); - { - ruby_init(); - rb_exit(ruby_run_node(ruby_options(argc, argv))); - } -} Copied: MacRuby/branches/experimental/main.cpp (from rev 1288, MacRuby/branches/experimental/main.c) =================================================================== --- MacRuby/branches/experimental/main.cpp (rev 0) +++ MacRuby/branches/experimental/main.cpp 2009-04-03 06:24:41 UTC (rev 1298) @@ -0,0 +1,32 @@ +/* + * 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 + */ + +#undef RUBY_EXPORT +#include "ruby.h" +#ifdef HAVE_LOCALE_H +#include <locale.h> +#endif + +extern "C" void rb_vm_print_current_exception(void); + +int +main(int argc, char **argv, char **envp) +{ +#ifdef HAVE_LOCALE_H + setlocale(LC_CTYPE, ""); +#endif + + try { + ruby_sysinit(&argc, &argv); + ruby_init(); + rb_exit(ruby_run_node(ruby_options(argc, argv))); + } + catch (...) { + rb_vm_print_current_exception(); + exit(1); + } +} Modified: MacRuby/branches/experimental/roxor.cpp =================================================================== --- MacRuby/branches/experimental/roxor.cpp 2009-04-03 05:44:40 UTC (rev 1297) +++ MacRuby/branches/experimental/roxor.cpp 2009-04-03 06:24:41 UTC (rev 1298) @@ -4235,8 +4235,10 @@ // VALUE rb_vm_yield_args(int argc, ...) std::vector<const Type *> types; types.push_back(Type::Int32Ty); - FunctionType *ft = FunctionType::get(RubyObjTy, types, true); - yieldFunc = cast<Function>(module->getOrInsertFunction("rb_vm_yield_args", ft)); + FunctionType *ft = + FunctionType::get(RubyObjTy, types, true); + yieldFunc = cast<Function>(module->getOrInsertFunction( + "rb_vm_yield_args", ft)); } std::vector<Value *>params; @@ -4253,8 +4255,16 @@ args = args->nd_next; } } +#if 0 // TODO + else { + params.push_back(ConstantInt::get(Type::Int32Ty, 1)); + params.push_back(splatArgFollowsVal); + params.push_back(compile_node(args->nd_head)); + } +#endif - return CallInst::Create(yieldFunc, params.begin(), params.end(), "", bb); + return CallInst::Create(yieldFunc, params.begin(), + params.end(), "", bb); } break; @@ -6265,15 +6275,16 @@ printf("rb_vm_debug\n"); } -// END OF VM primitives +extern "C" +void +rb_vm_print_current_exception(void) +{ + VALUE exc = GET_VM()->current_exception; + if (exc == Qnil) { + printf("uncatched Objective-C/C++ exception..."); + return; + } -#include <llvm/Target/TargetData.h> -#include <llvm/Target/TargetMachine.h> -#include <llvm/Target/TargetOptions.h> - -static void -rb_vm_print_exception(VALUE exc) -{ static SEL sel_message = 0; if (sel_message == 0) { sel_message = sel_registerName("message"); @@ -6284,6 +6295,12 @@ printf("%s (%s)\n", RSTRING_PTR(message), rb_class2name(*(VALUE *)exc)); } +// END OF VM primitives + +#include <llvm/Target/TargetData.h> +#include <llvm/Target/TargetMachine.h> +#include <llvm/Target/TargetOptions.h> + extern "C" bool rb_vm_parse_in_eval(void) @@ -6374,19 +6391,7 @@ GET_VM()->bindings.pop_back(); } - try { - return ((VALUE(*)(VALUE, SEL))imp)(GET_VM()->current_top_object, 0); - } - catch (...) { - VALUE exc = GET_VM()->current_exception; - if (exc != Qnil) { - rb_vm_print_exception(exc); - } - else { - printf("uncatched C++/Objective-C exception...\n"); - } - exit(1); - } + return ((VALUE(*)(VALUE, SEL))imp)(GET_VM()->current_top_object, 0); } extern "C"