[macruby-changes] [4224] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Wed Jun 16 02:05:27 PDT 2010


Revision: 4224
          http://trac.macosforge.org/projects/ruby/changeset/4224
Author:   lsansonetti at apple.com
Date:     2010-06-16 02:05:24 -0700 (Wed, 16 Jun 2010)
Log Message:
-----------
started to trim out the static library

Modified Paths:
--------------
    MacRuby/trunk/MacRuby.m
    MacRuby/trunk/bridgesupport.cpp
    MacRuby/trunk/bridgesupport.h
    MacRuby/trunk/bs.c
    MacRuby/trunk/class.c
    MacRuby/trunk/compiler.cpp
    MacRuby/trunk/compiler.h
    MacRuby/trunk/debugger.cpp
    MacRuby/trunk/debugger.h
    MacRuby/trunk/dispatcher.cpp
    MacRuby/trunk/interpreter.cpp
    MacRuby/trunk/interpreter.h
    MacRuby/trunk/llvm.h
    MacRuby/trunk/objc.m
    MacRuby/trunk/proc.c
    MacRuby/trunk/rakelib/builder/builder.rb
    MacRuby/trunk/rakelib/builder/options.rb
    MacRuby/trunk/rakelib/builder.rake
    MacRuby/trunk/version.h
    MacRuby/trunk/vm.cpp
    MacRuby/trunk/vm.h

Modified: MacRuby/trunk/MacRuby.m
===================================================================
--- MacRuby/trunk/MacRuby.m	2010-06-14 23:53:49 UTC (rev 4223)
+++ MacRuby/trunk/MacRuby.m	2010-06-16 09:05:24 UTC (rev 4224)
@@ -56,7 +56,12 @@
 
 - (void)loadBridgeSupportFileAtPath:(NSString *)path
 {
+#if MACRUBY_STATIC
+    printf("loadBridgeSupportFileAtPath: not supported in MacRuby static\n");
+    abort();
+#else
     rb_vm_load_bridge_support([path fileSystemRepresentation], NULL, 0);
+#endif
 }
 
 - (void)loadBridgeSupportFileAtURL:(NSURL *)URL

Modified: MacRuby/trunk/bridgesupport.cpp
===================================================================
--- MacRuby/trunk/bridgesupport.cpp	2010-06-14 23:53:49 UTC (rev 4223)
+++ MacRuby/trunk/bridgesupport.cpp	2010-06-16 09:05:24 UTC (rev 4224)
@@ -6,20 +6,26 @@
  * Copyright (C) 2007-2010, Apple Inc. All rights reserved.
  */
 
-#include <llvm/Module.h>
-#include <llvm/DerivedTypes.h>
-#include <llvm/Constants.h>
-#include <llvm/CallingConv.h>
-#include <llvm/Instructions.h>
-#if !defined(LLVM_TOT)
-# include <llvm/ModuleProvider.h>
+#if MACRUBY_STATIC
+# include <vector>
+# include <map>
+# include <string>
+#else
+# include <llvm/Module.h>
+# include <llvm/DerivedTypes.h>
+# include <llvm/Constants.h>
+# include <llvm/CallingConv.h>
+# include <llvm/Instructions.h>
+# if !defined(LLVM_TOT)
+#  include <llvm/ModuleProvider.h>
+# endif
+# include <llvm/Intrinsics.h>
+# include <llvm/Analysis/DebugInfo.h>
+# include <llvm/ExecutionEngine/JIT.h>
+# include <llvm/PassManager.h>
+# include <llvm/Target/TargetData.h>
+using namespace llvm;
 #endif
-#include <llvm/Intrinsics.h>
-#include <llvm/Analysis/DebugInfo.h>
-#include <llvm/ExecutionEngine/JIT.h>
-#include <llvm/PassManager.h>
-#include <llvm/Target/TargetData.h>
-using namespace llvm;
 
 #include "ruby/ruby.h"
 #include "ruby/node.h"
@@ -47,6 +53,8 @@
     }
 }
 
+VALUE rb_cBoxed;
+
 static VALUE bs_const_magic_cookie = Qnil;
 
 extern "C"
@@ -77,8 +85,115 @@
     return v;
 }
 
-VALUE rb_cBoxed;
 
+bs_element_constant_t *
+RoxorCore::find_bs_const(ID name)
+{
+    std::map<ID, bs_element_constant_t *>::iterator iter =
+	bs_consts.find(name);
+
+    return iter == bs_consts.end() ? NULL : iter->second;
+}
+
+bs_element_method_t *
+RoxorCore::find_bs_method(Class klass, SEL sel)
+{
+    std::map<std::string, std::map<SEL, bs_element_method_t *> *> &map =
+	class_isMetaClass(klass) ? bs_classes_class_methods
+	: bs_classes_instance_methods;
+
+    do {
+	std::map<std::string,
+		 std::map<SEL, bs_element_method_t *> *>::iterator iter =
+		     map.find(class_getName(klass));
+
+	if (iter != map.end()) {
+	    std::map<SEL, bs_element_method_t *> *map2 = iter->second;
+	    std::map<SEL, bs_element_method_t *>::iterator iter2 =
+		map2->find(sel);
+
+	    if (iter2 != map2->end()) {
+		return iter2->second;
+	    }
+	}
+
+	klass = class_getSuperclass(klass);
+    }
+    while (klass != NULL);
+
+    return NULL;
+}
+
+rb_vm_bs_boxed_t *
+RoxorCore::find_bs_boxed(std::string type)
+{
+    std::map<std::string, rb_vm_bs_boxed_t *>::iterator iter =
+	bs_boxed.find(type);
+
+    if (iter == bs_boxed.end()) {
+	return NULL;
+    }
+
+    return iter->second;
+}
+
+rb_vm_bs_boxed_t *
+RoxorCore::find_bs_struct(std::string type)
+{
+    rb_vm_bs_boxed_t *boxed = find_bs_boxed(type);
+    if (boxed != NULL) {
+	if (boxed->is_struct()) {
+	    return boxed;
+	}
+	return NULL;
+    }
+
+#if MACRUBY_STATIC
+    return NULL;
+#else
+    // Given structure type does not exist... but it may be an anonymous
+    // type (like {?=qq}) which is sometimes present in BridgeSupport files...
+    return register_anonymous_bs_struct(type.c_str());
+#endif
+}
+
+rb_vm_bs_boxed_t *
+RoxorCore::find_bs_opaque(std::string type)
+{
+    rb_vm_bs_boxed_t *boxed = find_bs_boxed(type);
+    return boxed == NULL ? NULL : boxed->is_struct() ? NULL : boxed;
+}
+
+bs_element_cftype_t *
+RoxorCore::find_bs_cftype(std::string type)
+{
+    std::map<std::string, bs_element_cftype_t *>::iterator iter =
+	bs_cftypes.find(type);
+
+    return iter == bs_cftypes.end() ? NULL : iter->second;
+}
+
+std::string *
+RoxorCore::find_bs_informal_protocol_method(SEL sel, bool class_method)
+{
+    std::map<SEL, std::string *> &map = class_method
+	? bs_informal_protocol_cmethods : bs_informal_protocol_imethods;
+
+    std::map<SEL, std::string *>::iterator iter = map.find(sel);
+
+    return iter == map.end() ? NULL : iter->second;
+}
+
+bs_element_function_t *
+RoxorCore::find_bs_function(std::string &name)
+{
+    std::map<std::string, bs_element_function_t *>::iterator iter =
+	bs_funcs.find(name);
+
+    return iter == bs_funcs.end() ? NULL : iter->second;
+}
+
+#if !defined(MACRUBY_STATIC)
 extern "C"
 void
 rb_vm_check_arity(int given, int requested)
@@ -936,109 +1051,6 @@
     return rcv;
 }
 
-bs_element_constant_t *
-RoxorCore::find_bs_const(ID name)
-{
-    std::map<ID, bs_element_constant_t *>::iterator iter =
-	bs_consts.find(name);
-
-    return iter == bs_consts.end() ? NULL : iter->second;
-}
-
-bs_element_method_t *
-RoxorCore::find_bs_method(Class klass, SEL sel)
-{
-    std::map<std::string, std::map<SEL, bs_element_method_t *> *> &map =
-	class_isMetaClass(klass) ? bs_classes_class_methods
-	: bs_classes_instance_methods;
-
-    do {
-	std::map<std::string,
-		 std::map<SEL, bs_element_method_t *> *>::iterator iter =
-		     map.find(class_getName(klass));
-
-	if (iter != map.end()) {
-	    std::map<SEL, bs_element_method_t *> *map2 = iter->second;
-	    std::map<SEL, bs_element_method_t *>::iterator iter2 =
-		map2->find(sel);
-
-	    if (iter2 != map2->end()) {
-		return iter2->second;
-	    }
-	}
-
-	klass = class_getSuperclass(klass);
-    }
-    while (klass != NULL);
-
-    return NULL;
-}
-
-rb_vm_bs_boxed_t *
-RoxorCore::find_bs_boxed(std::string type)
-{
-    std::map<std::string, rb_vm_bs_boxed_t *>::iterator iter =
-	bs_boxed.find(type);
-
-    if (iter == bs_boxed.end()) {
-	return NULL;
-    }
-
-    return iter->second;
-}
-
-rb_vm_bs_boxed_t *
-RoxorCore::find_bs_struct(std::string type)
-{
-    rb_vm_bs_boxed_t *boxed = find_bs_boxed(type);
-    if (boxed != NULL) {
-	if (boxed->is_struct()) {
-	    return boxed;
-	}
-	return NULL;
-    }
-
-    // Given structure type does not exist... but it may be an anonymous
-    // type (like {?=qq}) which is sometimes present in BridgeSupport files...
-    return register_anonymous_bs_struct(type.c_str());
-}
-
-rb_vm_bs_boxed_t *
-RoxorCore::find_bs_opaque(std::string type)
-{
-    rb_vm_bs_boxed_t *boxed = find_bs_boxed(type);
-    return boxed == NULL ? NULL : boxed->is_struct() ? NULL : boxed;
-}
-
-bs_element_cftype_t *
-RoxorCore::find_bs_cftype(std::string type)
-{
-    std::map<std::string, bs_element_cftype_t *>::iterator iter =
-	bs_cftypes.find(type);
-
-    return iter == bs_cftypes.end() ? NULL : iter->second;
-}
-
-std::string *
-RoxorCore::find_bs_informal_protocol_method(SEL sel, bool class_method)
-{
-    std::map<SEL, std::string *> &map = class_method
-	? bs_informal_protocol_cmethods : bs_informal_protocol_imethods;
-
-    std::map<SEL, std::string *>::iterator iter = map.find(sel);
-
-    return iter == map.end() ? NULL : iter->second;
-}
-
-bs_element_function_t *
-RoxorCore::find_bs_function(std::string &name)
-{
-    std::map<std::string, bs_element_function_t *>::iterator iter =
-	bs_funcs.find(name);
-
-    return iter == bs_funcs.end() ? NULL : iter->second;
-}
-
 static void
 index_bs_class_methods(const char *name,
 	std::map<std::string, std::map<SEL, bs_element_method_t *> *> &map,
@@ -1397,39 +1409,6 @@
 #endif
 }
 
-extern "C"
-void
-Init_BridgeSupport(void)
-{
-    // Boxed
-    rb_cBoxed = rb_define_class("Boxed", rb_cObject);
-    rb_objc_define_method(*(VALUE *)rb_cBoxed, "type",
-	    (void *)rb_boxed_objc_type, 0);
-    rb_objc_define_method(*(VALUE *)rb_cBoxed, "opaque?",
-	    (void *)rb_boxed_is_opaque, 0);
-    boxed_ivar_type = rb_intern("__octype__");
-
-    // Pointer
-    rb_cPointer = rb_define_class("Pointer", rb_cObject);
-    rb_objc_define_method(*(VALUE *)rb_cPointer, "new",
-	    (void *)rb_pointer_s_new, -1);
-    rb_objc_define_method(*(VALUE *)rb_cPointer, "new_with_type",
-	    (void *)rb_pointer_s_new, -1);
-    rb_objc_define_method(rb_cPointer, "[]",
-	    (void *)rb_pointer_aref, 1);
-    rb_objc_define_method(rb_cPointer, "[]=",
-	    (void *)rb_pointer_aset, 2);
-    rb_objc_define_method(rb_cPointer, "assign",
-	    (void *)rb_pointer_assign, 1);
-    rb_objc_define_method(rb_cPointer, "type",
-	    (void *)rb_pointer_type, 0);
-    rb_objc_define_method(rb_cPointer, "cast!",
-	    (void *)rb_pointer_cast, 1);
-
-    bs_const_magic_cookie = rb_str_new2("bs_const_magic_cookie");
-    rb_objc_retain((void *)bs_const_magic_cookie);
-}
-
 // FFI
 
 static const char *
@@ -1601,12 +1580,52 @@
     return Qnil;
 }
 
+#endif // !MACRUBY_STATIC
+
 extern "C"
 void
+Init_BridgeSupport(void)
+{
+#if !defined(MACRUBY_STATIC)
+    // Boxed
+    rb_cBoxed = rb_define_class("Boxed", rb_cObject);
+    rb_objc_define_method(*(VALUE *)rb_cBoxed, "type",
+	    (void *)rb_boxed_objc_type, 0);
+    rb_objc_define_method(*(VALUE *)rb_cBoxed, "opaque?",
+	    (void *)rb_boxed_is_opaque, 0);
+    boxed_ivar_type = rb_intern("__octype__");
+
+    // Pointer
+    rb_cPointer = rb_define_class("Pointer", rb_cObject);
+    rb_objc_define_method(*(VALUE *)rb_cPointer, "new",
+	    (void *)rb_pointer_s_new, -1);
+    rb_objc_define_method(*(VALUE *)rb_cPointer, "new_with_type",
+	    (void *)rb_pointer_s_new, -1);
+    rb_objc_define_method(rb_cPointer, "[]",
+	    (void *)rb_pointer_aref, 1);
+    rb_objc_define_method(rb_cPointer, "[]=",
+	    (void *)rb_pointer_aset, 2);
+    rb_objc_define_method(rb_cPointer, "assign",
+	    (void *)rb_pointer_assign, 1);
+    rb_objc_define_method(rb_cPointer, "type",
+	    (void *)rb_pointer_type, 0);
+    rb_objc_define_method(rb_cPointer, "cast!",
+	    (void *)rb_pointer_cast, 1);
+#endif
+
+    bs_const_magic_cookie = rb_str_new2("bs_const_magic_cookie");
+    rb_objc_retain((void *)bs_const_magic_cookie);
+}
+
+extern "C"
+void
 Init_FFI(void)
 {
+#if !defined(MACRUBY_STATIC)
     VALUE mFFI = rb_define_module("FFI");
     VALUE mFFILib = rb_define_module_under(mFFI, "Library");
     rb_objc_define_method(mFFILib, "attach_function",
 	    (void *)rb_ffi_attach_function, 3);
+#endif
 }
+

Modified: MacRuby/trunk/bridgesupport.h
===================================================================
--- MacRuby/trunk/bridgesupport.h	2010-06-14 23:53:49 UTC (rev 4223)
+++ MacRuby/trunk/bridgesupport.h	2010-06-16 09:05:24 UTC (rev 4224)
@@ -31,7 +31,9 @@
 	bs_element_opaque_t *o;
 	void *v;
     } as;
+#if !defined(MACRUBY_STATIC)
     Type *type;
+#endif
     VALUE klass;
 } rb_vm_bs_boxed_t;
 

Modified: MacRuby/trunk/bs.c
===================================================================
--- MacRuby/trunk/bs.c	2010-06-14 23:53:49 UTC (rev 4223)
+++ MacRuby/trunk/bs.c	2010-06-16 09:05:24 UTC (rev 4224)
@@ -26,6 +26,8 @@
  *  POSSIBILITY OF SUCH DAMAGE.
  */
 
+#if !defined(MACRUBY_STATIC)
+
 #include "bs.h"
 
 #include <libxml/xmlreader.h>
@@ -1410,3 +1412,5 @@
   }
   free(value);
 }
+
+#endif // !MACRUBY_STATIC

Modified: MacRuby/trunk/class.c
===================================================================
--- MacRuby/trunk/class.c	2010-06-14 23:53:49 UTC (rev 4223)
+++ MacRuby/trunk/class.c	2010-06-16 09:05:24 UTC (rev 4224)
@@ -993,8 +993,12 @@
 rb_add_mri_method(VALUE klass, const char *name, void *imp, const int arity,
 	const int noex)
 {
+#if MACRUBY_STATIC
+    rb_raise(rb_eRuntimeError, "MRI methods are not supported in MacRuby static");
+#else
     imp = rb_vm_generate_mri_stub(imp, arity);
     rb_objc_add_method(klass, name, imp, arity, noex, false);
+#endif
 }
 
 void

Modified: MacRuby/trunk/compiler.cpp
===================================================================
--- MacRuby/trunk/compiler.cpp	2010-06-14 23:53:49 UTC (rev 4223)
+++ MacRuby/trunk/compiler.cpp	2010-06-16 09:05:24 UTC (rev 4224)
@@ -6,6 +6,8 @@
  * Copyright (C) 2008-2010, Apple Inc. All rights reserved.
  */
 
+#if !defined(MACRUBY_STATIC)
+
 #define ROXOR_COMPILER_DEBUG 	0
 
 #if !defined(DW_LANG_Ruby)
@@ -6633,3 +6635,5 @@
 
     return pn;
 }
+
+#endif // !MACRUBY_STATIC

Modified: MacRuby/trunk/compiler.h
===================================================================
--- MacRuby/trunk/compiler.h	2010-06-14 23:53:49 UTC (rev 4223)
+++ MacRuby/trunk/compiler.h	2010-06-16 09:05:24 UTC (rev 4224)
@@ -31,6 +31,8 @@
 
 #if defined(__cplusplus)
 
+#if !defined(MACRUBY_STATIC)
+
 class RoxorInterpreter;
 
 class RoxorCompiler {
@@ -478,6 +480,8 @@
 	}
 };
 
+#endif // !MACRUBY_STATIC
+
 #endif /* __cplusplus */
 
 #endif /* __COMPILER_H_ */

Modified: MacRuby/trunk/debugger.cpp
===================================================================
--- MacRuby/trunk/debugger.cpp	2010-06-14 23:53:49 UTC (rev 4223)
+++ MacRuby/trunk/debugger.cpp	2010-06-16 09:05:24 UTC (rev 4224)
@@ -6,6 +6,8 @@
  * Copyright (C) 2010, Apple Inc. All rights reserved.
  */
 
+#if !defined(MACRUBY_STATIC)
+
 #include <llvm/Module.h>
 #include <llvm/DerivedTypes.h>
 #include <llvm/Constants.h>
@@ -422,3 +424,5 @@
     }
     return false;
 }
+
+#endif // !MACRUBY_STATIC

Modified: MacRuby/trunk/debugger.h
===================================================================
--- MacRuby/trunk/debugger.h	2010-06-14 23:53:49 UTC (rev 4223)
+++ MacRuby/trunk/debugger.h	2010-06-16 09:05:24 UTC (rev 4224)
@@ -11,6 +11,8 @@
 
 #if defined(__cplusplus)
 
+#if !defined(MACRUBY_STATIC)
+
 class RoxorBreakPoint {
     public:
 	static unsigned int IDs;
@@ -60,6 +62,8 @@
 		rb_vm_block_t *block, int lvars_size, va_list lvars);
 };
 
+#endif // !MACRUBY_STATIC
+
 #endif /* __cplusplus */
 
 #endif /* __DEBUGGER_H_ */

Modified: MacRuby/trunk/dispatcher.cpp
===================================================================
--- MacRuby/trunk/dispatcher.cpp	2010-06-14 23:53:49 UTC (rev 4223)
+++ MacRuby/trunk/dispatcher.cpp	2010-06-16 09:05:24 UTC (rev 4224)
@@ -122,9 +122,14 @@
 		    argv[3], argv[4], argv[5], argv[6], argv[7], argv[8]);
     }
 
+#if MACRUBY_STATIC
+    rb_raise(rb_eRuntimeError,
+	    "MacRuby static doesn't support passing more than 9 arguments");
+#else
     rb_vm_long_arity_bstub_t *stub = (rb_vm_long_arity_bstub_t *)
 	GET_CORE()->gen_large_arity_stub(argc, true);
     return (*stub)(pimp, (id)self, sel, dvars, b, argc, argv);
+#endif
 }
 
 static force_inline VALUE
@@ -184,9 +189,14 @@
 		    argv[10]);
     }
 
+#if MACRUBY_STATIC
+    rb_raise(rb_eRuntimeError,
+	    "MacRuby static doesn't support passing more than 9 arguments");
+#else
     rb_vm_long_arity_stub_t *stub = (rb_vm_long_arity_stub_t *)
 	GET_CORE()->gen_large_arity_stub(argc);
     return (*stub)(pimp, (id)self, sel, argc, argv);
+#endif
 }
 
 static void
@@ -619,11 +629,13 @@
 	else {
 	    // Method is not found...
 
+#if !defined(MACRUBY_STATIC)
 	    // Force a method resolving, because the objc cache might be
 	    // wrong.
 	    if (rb_vm_resolve_method(klass, sel)) {
 		goto recache;
 	    }
+#endif
 
 	    // Does the receiver implements -forwardInvocation:?
 	    if ((opt & DISPATCH_SUPER) == 0
@@ -1308,9 +1320,13 @@
 		b->imp = (IMP)function;
 	    }
 	    else {
+#if MACRUBY_STATIC
+		abort();
+#else
 		GET_CORE()->lock();
 		b->imp = GET_CORE()->compile((Function *)function);
 		GET_CORE()->unlock();
+#endif
 	    }
 	    b->userdata = (VALUE)function;
 	}

Modified: MacRuby/trunk/interpreter.cpp
===================================================================
--- MacRuby/trunk/interpreter.cpp	2010-06-14 23:53:49 UTC (rev 4223)
+++ MacRuby/trunk/interpreter.cpp	2010-06-16 09:05:24 UTC (rev 4224)
@@ -6,6 +6,8 @@
  * Copyright (C) 2008-2010, Apple Inc. All rights reserved.
  */
 
+#if !defined(MACRUBY_STATIC)
+
 #include "llvm.h"
 #include "ruby/ruby.h"
 #include "ruby/node.h"
@@ -227,3 +229,5 @@
     BasicBlock &b = func->getEntryBlock();
     return interpret_basicblock(&b);
 }
+
+#endif // !MACRUBY_STATIC

Modified: MacRuby/trunk/interpreter.h
===================================================================
--- MacRuby/trunk/interpreter.h	2010-06-14 23:53:49 UTC (rev 4223)
+++ MacRuby/trunk/interpreter.h	2010-06-16 09:05:24 UTC (rev 4224)
@@ -11,6 +11,8 @@
 
 #if defined(__cplusplus)
 
+#if !defined(MACRUBY_STATIC)
+
 class RoxorInterpreter {
     public:
 	static RoxorInterpreter *shared;
@@ -34,6 +36,8 @@
 	VALUE interpret_call(CallInst *call);
 };
 
+#endif // !MACRUBY_STATIC
+
 #endif // __cplusplus
 
 #endif // __INTERPRETER_H_

Modified: MacRuby/trunk/llvm.h
===================================================================
--- MacRuby/trunk/llvm.h	2010-06-14 23:53:49 UTC (rev 4223)
+++ MacRuby/trunk/llvm.h	2010-06-16 09:05:24 UTC (rev 4224)
@@ -1,6 +1,12 @@
 #ifndef __MR_LLVM_H_
 #define __MR_LLVM_H_
 
+#if MACRUBY_STATIC
+# include <string>
+# include <vector>
+# include <map>
+#else
+
 // This file must be included at the very beginning of every C++ file in the
 // project, due to type collisions between LLVM and the MRI C API.
 
@@ -19,4 +25,6 @@
 #include <llvm/Target/TargetData.h>
 using namespace llvm;
 
+#endif // !MACRUBY_STATIC
+
 #endif // __MR_LLVM_H_

Modified: MacRuby/trunk/objc.m
===================================================================
--- MacRuby/trunk/objc.m	2010-06-14 23:53:49 UTC (rev 4223)
+++ MacRuby/trunk/objc.m	2010-06-16 09:05:24 UTC (rev 4224)
@@ -285,10 +285,15 @@
 static VALUE
 rb_objc_load_bs(VALUE recv, SEL sel, VALUE path)
 {
+#if MACRUBY_STATIC
+    not_implemented_in_static(sel);
+#else
     rb_vm_load_bridge_support(StringValuePtr(path), NULL, 0);
     return recv;
+#endif
 }
 
+#if !defined(MACRUBY_STATIC)
 static void
 rb_objc_search_and_load_bridge_support(const char *framework_path)
 {
@@ -299,6 +304,7 @@
                                     BS_PARSE_OPTIONS_LOAD_DYLIBS);
     }
 }
+#endif
 
 static void
 reload_class_constants(void)
@@ -331,47 +337,14 @@
     free(buf);
 }
 
-static void
-reload_protocols(void)
-{
-#if 0
-    Protocol **prots;
-    unsigned int i, prots_count;
-
-    prots = objc_copyProtocolList(&prots_count);
-    for (i = 0; i < prots_count; i++) {
-	Protocol *p;
-	struct objc_method_description *methods;
-	unsigned j, methods_count;
-
-	p = prots[i];
-
-#define REGISTER_MDESCS(t) // TODO
-
-	methods = protocol_copyMethodDescriptionList(p, true, true,
-		&methods_count);
-	REGISTER_MDESCS(bs_inf_prot_imethods);
-	methods = protocol_copyMethodDescriptionList(p, false, true,
-		&methods_count);
-	REGISTER_MDESCS(bs_inf_prot_imethods);
-	methods = protocol_copyMethodDescriptionList(p, true, false,
-		&methods_count);
-	REGISTER_MDESCS(bs_inf_prot_cmethods);
-	methods = protocol_copyMethodDescriptionList(p, false, false,
-		&methods_count);
-	REGISTER_MDESCS(bs_inf_prot_cmethods);
-
-#undef REGISTER_MDESCS
-    }
-    free(prots);
-#endif
-}
-
 bool rb_objc_enable_ivar_set_kvo_notifications = false;
 
 VALUE
 rb_require_framework(VALUE recv, SEL sel, int argc, VALUE *argv)
 {
+#if MACRUBY_STATIC
+    not_implemented_in_static(sel);
+#else
     VALUE framework;
     VALUE search_network;
     const char *cstr;
@@ -479,11 +452,11 @@
 
     rb_objc_search_and_load_bridge_support(cstr);
     reload_class_constants();
-    reload_protocols();
 
     rb_objc_enable_ivar_set_kvo_notifications = true;
 
     return loaded ? Qfalse : Qtrue;
+#endif
 }
 
 void rb_vm_init_compiler(void);

Modified: MacRuby/trunk/proc.c
===================================================================
--- MacRuby/trunk/proc.c	2010-06-14 23:53:49 UTC (rev 4223)
+++ MacRuby/trunk/proc.c	2010-06-16 09:05:24 UTC (rev 4224)
@@ -949,6 +949,9 @@
 static VALUE
 rb_mod_define_method(VALUE mod, SEL sel, int argc, VALUE *argv)
 {
+#if MACRUBY_STATIC
+    not_implemented_in_static(sel);
+#else
     ID id;
     VALUE body;
 
@@ -997,6 +1000,7 @@
     }
 
     return body;
+#endif
 }
 
 static VALUE

Modified: MacRuby/trunk/rakelib/builder/builder.rb
===================================================================
--- MacRuby/trunk/rakelib/builder/builder.rb	2010-06-14 23:53:49 UTC (rev 4223)
+++ MacRuby/trunk/rakelib/builder/builder.rb	2010-06-16 09:05:24 UTC (rev 4224)
@@ -15,6 +15,9 @@
   nkf
 }.sort
 
+FULL_OBJS_DIR = '.objs'
+STATIC_OBJS_DIR = '.static-objs'
+
 class Builder
   # Runs the given array of +commands+ in parallel. The amount of spawned
   # simultaneous jobs is determined by the `jobs' env variable. The default
@@ -34,21 +37,51 @@
     end.each { |t| t.join }
   end
 
-  attr_reader :objs, :cflags, :cxxflags
-  attr_accessor :objc_cflags, :ldflags, :dldflags
+  attr_reader :objs, :objsdir, :cflags, :cxxflags
+  attr_accessor :cflags, :cxxflags, :objc_cflags, :ldflags, :dldflags
 
   def initialize(objs)
-    @objs = objs.dup
-    @cflags = CFLAGS
-    @cxxflags = CXXFLAGS
-    @objc_cflags = OBJC_CFLAGS
-    @ldflags = LDFLAGS
-    @dldflags = DLDFLAGS
-    @objs_cflags = OBJS_CFLAGS
-    @obj_sources = {}
-    @header_paths = {}
+    @all_objs = objs.dup
+    self.mode = :full
   end
 
+  def mode=(m)
+    if @mode != m
+      @mode = m
+      case @mode
+        when :full
+          @objs = @all_objs
+          @cflags = CFLAGS
+          @cxxflags = CXXFLAGS
+          @objc_cflags = OBJC_CFLAGS
+          @ldflags = LDFLAGS
+          @objsdir = FULL_OBJS_DIR
+        when :static
+          @objs = @all_objs - %w{bs compiler debugger interpreter}
+          @cflags = CFLAGS_STATIC
+          @cxxflags = CXXFLAGS_STATIC
+          @objc_cflags = OBJC_CFLAGS_STATIC
+          @ldflags = LDFLAGS_STATIC
+          @objsdir = STATIC_OBJS_DIR
+        else
+          raise
+      end
+      @objs_cflags = OBJS_CFLAGS
+      @dldflags = DLDFLAGS
+      @obj_sources = {}
+      @header_paths = {}
+      FileUtils.mkdir_p(@objsdir)
+    end
+  end
+
+  def objsdir=(d)
+    if @objsdir != d
+      @objsdir = d.dup
+      FileUtils.mkdir_p(@objsdir)
+      @obj_sources.clear
+    end
+  end
+
   def build(objs=nil)
     objs ||= @objs
     commands = []
@@ -65,7 +98,7 @@
         if f = @objs_cflags[obj]
           flags += " #{f}"
         end
-        commands << "#{cc} #{flags} -c #{s} -o #{obj}.o"
+        commands << "#{cc} #{flags} -c #{s} -o #{obj_path(obj)}"
       end
     end
     self.class.parallel_execute(commands)
@@ -83,29 +116,30 @@
     objs ||= @objs
     if should_link?(name, objs)
       rm_f(name)
-      sh("/usr/bin/ar rcu #{name} #{objs.map { |x| x + '.o' }.join(' ') }")
+      sh("/usr/bin/ar rcu #{name} #{objs.map { |x| obj_path(x) }.join(' ') }")
       sh("/usr/bin/ranlib #{name}")
     end
   end
-
-  def clean
-    @objs.map { |o| o + '.o' }.select { |o| File.exist?(o) }.each { |o| rm_f(o) }
-  end
  
   private
 
+  def obj_path(o)
+    raise unless @objsdir
+    File.join(@objsdir, o + '.o')
+  end
+
   def link(objs, ldflags, args, name)
     objs ||= @objs
     ldflags ||= @ldflags
     if should_link?(name, objs)
-      sh("#{CXX} #{@cflags} #{objs.map { |x| x + '.o' }.join(' ') } #{ldflags} #{args}")
+      sh("#{CXX} #{@cflags} #{objs.map { |x| obj_path(x) }.join(' ') } #{ldflags} #{args}")
     end
   end
 
   def should_build?(obj)
-    if File.exist?(obj + '.o')
+    if File.exist?(obj_path(obj))
       src_time = File.mtime(obj_source(obj))
-      obj_time = File.mtime(obj + '.o')
+      obj_time = File.mtime(obj_path(obj))
       src_time > obj_time \
         or dependencies[obj].any? { |f| File.mtime(f) > obj_time }
     else
@@ -116,7 +150,7 @@
   def should_link?(bin, objs)
     if File.exist?(bin)
       mtime = File.mtime(bin)
-      objs.any? { |o| File.mtime(o + '.o') > mtime }
+      objs.any? { |o| File.mtime(obj_path(o)) > mtime }
     else
       true
     end

Modified: MacRuby/trunk/rakelib/builder/options.rb
===================================================================
--- MacRuby/trunk/rakelib/builder/options.rb	2010-06-14 23:53:49 UTC (rev 4223)
+++ MacRuby/trunk/rakelib/builder/options.rb	2010-06-16 09:05:24 UTC (rev 4224)
@@ -121,21 +121,23 @@
 EXPORTED_SYMBOLS_LIST = "./exported_symbols_list"
 
 OPTZFLAG = "-O#{OPTZ_LEVEL}"
-CFLAGS = "-I. -I./include #{ARCHFLAGS} -fno-common -pipe -g -Wall -fexceptions #{OPTZFLAG}"
+STATIC_FLAGS = "-DMACRUBY_STATIC"
+CFLAGS = "-std=c99 -I. -I./include #{ARCHFLAGS} -fno-common -pipe -g -Wall -fexceptions #{OPTZFLAG}"
 CFLAGS << " -Wno-deprecated-declarations -Werror" if NO_WARN_BUILD
 OBJC_CFLAGS = CFLAGS + " -fobjc-gc-only"
-CXXFLAGS = `#{LLVM_CONFIG} --cxxflags #{LLVM_MODULES}`.sub(/-DNDEBUG/, '').sub(/-fno-exceptions/, '').sub(/-Wcast-qual/, '').strip
+CFLAGS_STATIC = "#{CFLAGS} #{STATIC_FLAGS}"
+CXXFLAGS_STATIC = "-I. -I./include -g -Wall #{ARCHFLAGS}"
+CXXFLAGS_STATIC << " -Wno-deprecated-declarations -Werror" if NO_WARN_BUILD
+CXXFLAGS = CXXFLAGS_STATIC + ' ' + `#{LLVM_CONFIG} --cxxflags #{LLVM_MODULES}`.sub(/-DNDEBUG/, '').sub(/-fno-exceptions/, '').sub(/-Wcast-qual/, '').strip
 CXXFLAGS.sub!(/-O\d/, OPTZFLAG)
-CXXFLAGS << " -I. -I./include -g -Wall #{ARCHFLAGS}"
-CXXFLAGS << " -Wno-deprecated-declarations -Werror" if NO_WARN_BUILD
 CXXFLAGS << " -fno-rtti" unless CXXFLAGS.index("-fno-rtti")
 CXXFLAGS << " -DLLVM_TOT" if ENV['LLVM_TOT']
 CXXFLAGS << " -DLLVM_PRE_TOT" if ENV['LLVM_PRE_TOT']
-LDFLAGS = `#{LLVM_CONFIG} --ldflags --libs #{LLVM_MODULES}`.strip.gsub(/\n/, '')
-LDFLAGS << " -lpthread -ldl -lxml2 -lobjc -lauto -licucore -framework Foundation"
+CXXFLAGS_STATIC << " #{OPTZFLAG} -fno-rtti #{STATIC_FLAGS}"
+LDFLAGS_STATIC = "-lpthread -ldl -lxml2 -lobjc -lauto -licucore -framework Foundation"
+LDFLAGS = LDFLAGS_STATIC + ' ' + `#{LLVM_CONFIG} --ldflags --libs #{LLVM_MODULES}`.strip.gsub(/\n/, '')
 DLDFLAGS = "-dynamiclib -undefined suppress -flat_namespace -install_name #{INSTALL_NAME} -current_version #{MACRUBY_VERSION} -compatibility_version #{MACRUBY_VERSION} -exported_symbols_list #{EXPORTED_SYMBOLS_LIST}"
-CFLAGS << " -std=c99" # we add this one later to not conflict with C++ flags
-OBJC_CFLAGS << " -std=c99"
+OBJC_CFLAGS_STATIC = "#{OBJC_CFLAGS} #{STATIC_FLAGS}"
 
 if `sw_vers -productVersion`.to_f <= 10.6
   CFLAGS << " -I./icu-1060"

Modified: MacRuby/trunk/rakelib/builder.rake
===================================================================
--- MacRuby/trunk/rakelib/builder.rake	2010-06-14 23:53:49 UTC (rev 4223)
+++ MacRuby/trunk/rakelib/builder.rake	2010-06-16 09:05:24 UTC (rev 4224)
@@ -7,14 +7,16 @@
   end
 end
 
-desc "Build known objects"
-task :objects => [:config_h, :dtrace_h, :revision_h, :mark_gc] do
+task :files => [:config_h, :dtrace_h, :revision_h, :mark_gc] do
+end
+
+def build_objects
   if !File.exist?('parse.c') or File.mtime('parse.y') > File.mtime('parse.c')
     sh("/usr/bin/bison -o y.tab.c parse.y")
     sh("/usr/bin/sed -f ./tool/ytab.sed -e \"/^#/s!y\.tab\.c!parse.c!\" y.tab.c > parse.c.new")
     if !File.exist?('parse.c') or File.read('parse.c.new') != File.read('parse.c')
       mv('parse.c.new', 'parse.c')
-      rm_f('parse.o')
+      rm_f(File.join($builder.objsdir, 'parse.o'))
     else
       rm('parse.c.new')
     end
@@ -52,18 +54,21 @@
       sh "/bin/rm #{output}"
     end
   end
-  t = File.exist?('dispatcher.o') ? File.mtime('dispatcher.o') : nil
+  dispatcher_o = File.join($builder.objsdir, 'dispatcher.o')
+  t = File.exist?(dispatcher_o) ? File.mtime(dispatcher_o) : nil
   $builder.build
-  if t == nil or File.mtime('dispatcher.o') > t
+  if t == nil or File.mtime(dispatcher_o) > t
     # dispatcher.o must be marked as GC compliant to avoid a linker problem.
     # We do not build it using -fobjc-gc because gcc generates unnecessary (and slow)
     # write barriers.
-    sh "./markgc ./dispatcher.o"
+    sh "./markgc #{dispatcher_o}"
   end
 end
 
 desc "Create miniruby"
-task :miniruby => :objects do
+task :miniruby => :files do
+  $builder.mode = :full
+  build_objects
   $builder.link_executable('miniruby', OBJS)
 end
 
@@ -74,8 +79,10 @@
 end
 
 namespace :macruby do
-  desc "Build dynamic libraries for MacRuby"
-  task :dylib => [:rbconfig, :miniruby] do
+  desc "Build dynamic library"
+  task :dylib => [:rbconfig, :files] do
+    $builder.mode = :full
+    build_objects
     dylib = "lib#{RUBY_SO_NAME}.#{NEW_RUBY_VERSION}.dylib"
     $builder.link_dylib(dylib, $builder.objs - ['main', 'gc-stub'])
     major, minor, teeny = NEW_RUBY_VERSION.scan(/\d+/)
@@ -87,13 +94,16 @@
     end
   end
 
-  desc "Build static libraries for MacRuby"
-  task :static => :dylib do
+  desc "Build static library"
+  task :static => :files do
+    $builder.mode = :static
+    build_objects
     $builder.link_archive("lib#{RUBY_SO_NAME}-static.a", $builder.objs - ['main', 'gc-stub'])
   end
 
   desc "Build MacRuby"
-  task :build => :dylib do
+  task :build => [:dylib, :static] do
+    $builder.mode = :full
     $builder.link_executable(RUBY_INSTALL_NAME, ['main', 'gc-stub'], "-L. -l#{RUBY_SO_NAME} -lobjc")
   end
 end
@@ -181,7 +191,8 @@
 namespace :clean do
   desc "Clean local build files"
   task :local do
-    $builder.clean
+    rm_rf(FULL_OBJS_DIR)
+    rm_rf(STATIC_OBJS_DIR)
     list = ['parse.c', 'lex.c', INSTALLED_LIST, 'Makefile', RUBY_INSTALL_NAME, 'miniruby', 'kernel_data.c']
     list.concat(Dir['*.inc'])
     list.concat(Dir['lib*.{dylib,a}'])

Modified: MacRuby/trunk/version.h
===================================================================
--- MacRuby/trunk/version.h	2010-06-14 23:53:49 UTC (rev 4223)
+++ MacRuby/trunk/version.h	2010-06-16 09:05:24 UTC (rev 4224)
@@ -57,9 +57,15 @@
 #  endif
 #endif
 
-#define RUBY_DESCRIPTION	    \
-    "MacRuby " MACRUBY_VERSION	    \
-    " (ruby "RUBY_VERSION	    \
+#if MACRUBY_STATIC
+# define MACRUBY_NAME "MacRuby-static"
+#else
+# define MACRUBY_NAME "MacRuby"
+#endif
+
+#define RUBY_DESCRIPTION	    	\
+    MACRUBY_NAME " " MACRUBY_VERSION	\
+    " (ruby "RUBY_VERSION	    	\
     ") ["RUBY_PLATFORM", "RUBY_ARCH"]"
 
 #define RUBY_COPYRIGHT 	    \

Modified: MacRuby/trunk/vm.cpp
===================================================================
--- MacRuby/trunk/vm.cpp	2010-06-14 23:53:49 UTC (rev 4223)
+++ MacRuby/trunk/vm.cpp	2010-06-16 09:05:24 UTC (rev 4224)
@@ -9,37 +9,43 @@
 #define ROXOR_VM_DEBUG		0
 #define ROXOR_COMPILER_DEBUG 	0
 
-#include <llvm/Module.h>
-#include <llvm/DerivedTypes.h>
-#include <llvm/Constants.h>
-#include <llvm/CallingConv.h>
-#include <llvm/Instructions.h>
-#if !defined(LLVM_TOT)
-# include <llvm/ModuleProvider.h>
-#endif
-#include <llvm/PassManager.h>
-#include <llvm/Analysis/DebugInfo.h>
-#include <llvm/Analysis/Verifier.h>
-#include <llvm/Target/TargetData.h>
-#include <llvm/CodeGen/MachineFunction.h>
-#include <llvm/ExecutionEngine/JIT.h>
-#include <llvm/ExecutionEngine/JITMemoryManager.h>
-#include <llvm/ExecutionEngine/JITEventListener.h>
-#include <llvm/ExecutionEngine/GenericValue.h>
-#include <llvm/Target/TargetData.h>
-#include <llvm/Target/TargetMachine.h>
-#include <llvm/Target/TargetOptions.h>
-#include <llvm/Target/TargetSelect.h>
-#include <llvm/Transforms/Scalar.h>
-#include <llvm/Transforms/IPO.h>
-#include <llvm/Support/raw_ostream.h>
-#include <llvm/Support/PrettyStackTrace.h>
-#include <llvm/Support/MemoryBuffer.h>
-#include <llvm/Support/StandardPasses.h>
-#include <llvm/Intrinsics.h>
-#include <llvm/Bitcode/ReaderWriter.h>
-#include <llvm/LLVMContext.h>
+#if MACRUBY_STATIC
+# include <vector>
+# include <map>
+# include <string>
+#else
+# include <llvm/Module.h>
+# include <llvm/DerivedTypes.h>
+# include <llvm/Constants.h>
+# include <llvm/CallingConv.h>
+# include <llvm/Instructions.h>
+# if !defined(LLVM_TOT)
+#  include <llvm/ModuleProvider.h>
+# endif
+# include <llvm/PassManager.h>
+# include <llvm/Analysis/DebugInfo.h>
+# include <llvm/Analysis/Verifier.h>
+# include <llvm/Target/TargetData.h>
+# include <llvm/CodeGen/MachineFunction.h>
+# include <llvm/ExecutionEngine/JIT.h>
+# include <llvm/ExecutionEngine/JITMemoryManager.h>
+# include <llvm/ExecutionEngine/JITEventListener.h>
+# include <llvm/ExecutionEngine/GenericValue.h>
+# include <llvm/Target/TargetData.h>
+# include <llvm/Target/TargetMachine.h>
+# include <llvm/Target/TargetOptions.h>
+# include <llvm/Target/TargetSelect.h>
+# include <llvm/Transforms/Scalar.h>
+# include <llvm/Transforms/IPO.h>
+# include <llvm/Support/raw_ostream.h>
+# include <llvm/Support/PrettyStackTrace.h>
+# include <llvm/Support/MemoryBuffer.h>
+# include <llvm/Support/StandardPasses.h>
+# include <llvm/Intrinsics.h>
+# include <llvm/Bitcode/ReaderWriter.h>
+# include <llvm/LLVMContext.h>
 using namespace llvm;
+#endif // MACRUBY_STATIC
 
 #if ROXOR_COMPILER_DEBUG
 # include <mach/mach.h>
@@ -99,6 +105,7 @@
 	}
 };
 
+#if !defined(MACRUBY_STATIC)
 class RoxorFunction {
     public: 
 	// Information retrieved from JITManager.
@@ -286,6 +293,7 @@
 	    function->path = path;
 	}
 };
+#endif
 
 extern "C" void *__cxa_allocate_exception(size_t);
 extern "C" void __cxa_throw(void *, void *, void (*)(void *));
@@ -311,13 +319,14 @@
     threads = rb_ary_new();
     GC_RETAIN(threads);
 
+#if !MACRUBY_STATIC
     bs_parser = NULL;
 
     llvm_start_multithreaded();
 
-#if !defined(LLVM_TOT)
+# if !defined(LLVM_TOT)
     emp = new ExistingModuleProvider(RoxorCompiler::module);
-#endif
+# endif
     jmm = new RoxorJITManager;
 
     InitializeNativeTarget();
@@ -351,12 +360,12 @@
     }
 
     std::string err;
-#if LLVM_TOT
+# if LLVM_TOT
     ee = ExecutionEngine::createJIT(RoxorCompiler::module, &err, jmm, opt,
 	    false);
-#else
+# else
     ee = ExecutionEngine::createJIT(emp, &err, jmm, opt, false);
-#endif
+# endif
     if (ee == NULL) {
 	fprintf(stderr, "error while creating JIT: %s\n", err.c_str());
 	abort();
@@ -364,11 +373,11 @@
     ee->DisableLazyCompilation();
     ee->RegisterJITEventListener(jmm);
 
-#if LLVM_TOT
+# if LLVM_TOT
     fpm = new FunctionPassManager(RoxorCompiler::module);
-#else
+# else
     fpm = new FunctionPassManager(emp);
-#endif
+# endif
     fpm->add(new TargetData(*ee->getTargetData()));
 
     // Do simple "peephole" optimizations and bit-twiddling optzns.
@@ -384,9 +393,10 @@
     // Eliminate tail calls.
     fpm->add(createTailCallEliminationPass());
 
-#if ROXOR_VM_DEBUG
+# if ROXOR_VM_DEBUG
     functions_compiled = 0;
-#endif
+# endif
+#endif // !MACRUBY_STATIC
 }
 
 RoxorCore::~RoxorCore(void)
@@ -540,6 +550,7 @@
     return s;
 }
 
+#if !defined(MACRUBY_STATIC)
 void
 RoxorCore::optimize(Function *func)
 {
@@ -646,6 +657,7 @@
     func->eraseFromParent();
 #endif
 }
+#endif
 
 // Dummy function to be used for debugging (in gdb).
 extern "C"
@@ -670,6 +682,9 @@
 RoxorCore::symbolize_call_address(void *addr, void **startp, char *path,
 	size_t path_len, unsigned long *ln, char *name, size_t name_len)
 {
+#if MACRUBY_STATIC
+    return false;
+#else
     void *start = NULL;
 
     RoxorFunction *f = jmm->find_function((unsigned char *)addr);
@@ -728,6 +743,7 @@
     }
 
     return true;
+#endif
 }
 
 void
@@ -820,6 +836,7 @@
     return GET_CORE()->method_node_get(m) != NULL;
 }
 
+#if !defined(MACRUBY_STATIC)
 size_t
 RoxorCore::get_sizeof(const Type *type)
 {
@@ -868,6 +885,7 @@
     }
     return gvar;
 }
+#endif
 
 bool
 RoxorCore::should_invalidate_inline_op(SEL sel, Class klass)
@@ -1017,6 +1035,7 @@
     invalidate_method_cache(sel);
 
     // Invalidate inline operations.
+#if !defined(MACRUBY_STATIC)
     if (running) {
 	GlobalVariable *gvar = redefined_op_gvar(sel, false);
 	if (gvar != NULL && should_invalidate_inline_op(sel, klass)) {
@@ -1030,6 +1049,7 @@
 	    *(unsigned char *)val = 1;
 	}
     }
+#endif
 
     // If alloc is redefined, mark the class as such.
     if (sel == selAlloc
@@ -1730,6 +1750,9 @@
 RoxorCore::retype_method(Class klass, rb_vm_method_node_t *node,
 	const char *old_types, const char *new_types)
 {
+#if MACRUBY_STATIC
+    rb_raise(rb_eRuntimeError, "methods cannot be retyped in MacRuby static");
+#else
     if (strcmp(old_types, new_types) == 0) {
 	// No need to retype.
 	// XXX might be better to compare every type after filtering stack
@@ -1759,12 +1782,12 @@
     objc_to_ruby_stubs[node->ruby_imp] = node->objc_imp;
 
     // Re-add the method.
-    node = add_method(klass, node->sel, node->objc_imp, node->ruby_imp,
+    return add_method(klass, node->sel, node->objc_imp, node->ruby_imp,
 	    node->arity, node->flags, new_types);
-
-    return node;
+#endif
 }
 
+#if !defined(MACRUBY_STATIC)
 rb_vm_method_node_t *
 RoxorCore::resolve_method(Class klass, SEL sel, Function *func,
 	const rb_vm_arity_t &arity, int flags, IMP imp, Method m)
@@ -1915,8 +1938,11 @@
 
     invalidate_respond_to_cache();
 }
+#endif
 
+#if !defined(MACRUBY_STATIC)
 static bool class_has_custom_resolver(Class klass);
+#endif
 
 static void
 prepare_method(Class klass, bool dynamic_class, SEL sel, void *data,
@@ -1948,7 +1974,9 @@
 
     const char *sel_name = sel_getName(sel);
     const bool genuine_selector = sel_name[strlen(sel_name) - 1] == ':';
+#if !defined(MACRUBY_STATIC)
     const bool custom_resolver = class_has_custom_resolver(klass);
+#endif
     bool redefined = false;
     bool added_modfunc = false;
     SEL orig_sel = sel;
@@ -1957,7 +1985,18 @@
 
 prepare_method:
 
+#if MACRUBY_STATIC
     m = class_getInstanceMethod(klass, sel);
+    assert(m != NULL);
+
+    assert(precompiled);
+
+    if (imp == NULL) {
+	imp = (IMP)data;
+    }
+    //XXX GET_CORE()->resolve_method(klass, sel, NULL, arity, flags, imp, m);
+#else
+    m = class_getInstanceMethod(klass, sel);
     if (m == NULL && rb_vm_resolve_method(klass, sel)) {
 	m = class_getInstanceMethod(klass, sel);
 	assert(m != NULL);
@@ -1984,6 +2023,7 @@
 	    GET_CORE()->prepare_method(klass, sel, func, arity, flags);
 	}
     }
+#endif
 
     if (!redefined) {
 	char buf[100];
@@ -2045,6 +2085,7 @@
     }
 }
 
+#if !defined(MACRUBY_STATIC)
 extern "C"
 void
 rb_vm_prepare_method(Class klass, unsigned char dynamic_class, SEL sel,
@@ -2053,6 +2094,7 @@
     prepare_method(klass, dynamic_class, sel, (void *)func, arity,
 	    flags, false);
 }
+#endif
 
 extern "C"
 void
@@ -2101,6 +2143,7 @@
     }
 } 
 
+#if !defined(MACRUBY_STATIC)
 rb_vm_method_source_t *
 RoxorCore::method_source_get(Class klass, SEL sel)
 {
@@ -2116,6 +2159,7 @@
     }
     return NULL;
 }
+#endif
 
 void
 RoxorCore::get_methods(VALUE ary, Class klass, bool include_objc_methods,
@@ -2138,6 +2182,7 @@
 	free(methods);
     }
 
+#if !defined(MACRUBY_STATIC)
     Class k = klass;
     std::multimap<Class, SEL>::iterator iter =
 	method_source_sels.find(k);
@@ -2153,6 +2198,7 @@
 	    push_method(ary, sel, src->flags, filter);
 	}
     }
+#endif
 }
 
 extern "C"
@@ -2223,6 +2269,7 @@
 		continue;
 	    }
 
+#if !defined(MACRUBY_STATIC)
 	    SEL sel = method_getName(m);
 	    std::map<Class, rb_vm_method_source_t *> *map =
 		method_sources_for_sel(sel, false);
@@ -2230,10 +2277,12 @@
 		// There might be some non-JIT'ed yet methods on subclasses.
 		resolve_methods(map, to_class, sel);
 	    }
+#endif
 	}
 	free(methods);
     }
 
+#if !defined(MACRUBY_STATIC)
     // Copy methods that have not been JIT'ed yet.
 
     // First, make a list of selectors.
@@ -2313,6 +2362,7 @@
 	    ++i) {
 	method_source_sels.insert(std::make_pair(to_class, *i));
     }
+#endif
 }
 
 extern "C"
@@ -2367,6 +2417,9 @@
     assert(klass != NULL);
     assert(read || write);
 
+#if MACRUBY_STATIC
+    rb_raise(rb_eRuntimeError, "attr_* is not supported in MacRuby static");
+#else
     char buf[100];
     snprintf(buf, sizeof buf, "@%s", name);
     ID iname = rb_intern(buf);
@@ -2385,6 +2438,7 @@
 	rb_vm_prepare_method(klass, false, sel, f, rb_vm_arity(1),
 		VM_METHOD_FBODY);
     }
+#endif
 }
 
 static rb_vm_method_node_t *
@@ -2466,6 +2520,7 @@
 	    node->arity, flags, direct);
 }
 
+#if !defined(MACRUBY_STATIC)
 extern "C"
 void
 rb_vm_define_method3(Class klass, ID mid, rb_vm_block_t *block)
@@ -2504,6 +2559,7 @@
     }
     return (void *)GET_CORE()->compile(func, false); 
 }
+#endif
 
 void
 RoxorCore::undef_method(Class klass, SEL sel)
@@ -2693,10 +2749,15 @@
     std::map<int, void *>::iterator iter = stubs.find(argc);
     void *stub;
     if (iter == stubs.end()) {
+#if MACRUBY_STATIC
+	printf("uncached large arity stub (%d)\n", argc);
+	abort();
+#else
 	Function *f = RoxorCompiler::shared->compile_long_arity_stub(argc,
 		is_block);
 	stub = (void *)compile(f, false);
 	stubs.insert(std::make_pair(argc, stub));
+#endif
     }
     else {
 	stub = iter->second;
@@ -2720,10 +2781,15 @@
     std::map<std::string, void *>::iterator iter = stubs.find(types);
     void *stub;
     if (iter == stubs.end()) {
+#if MACRUBY_STATIC
+	printf("uncached stub %s\n", types.c_str());
+	abort();
+#else
 	Function *f = RoxorCompiler::shared->compile_stub(types.c_str(),
 		variadic, min_argc, is_objc);
 	stub = (void *)compile(f);
 	stubs.insert(std::make_pair(types, stub));
+#endif
     }
     else {
 	stub = iter->second;
@@ -2741,12 +2807,17 @@
 	return iter->second;
     }
 
+#if MACRUBY_STATIC
+    printf("uncached to_rval convertor %s\n", type.c_str());
+    abort();
+#else
     Function *f = RoxorCompiler::shared->compile_to_rval_convertor(
 	    type.c_str());
     void *convertor = (void *)compile(f);
     to_rval_convertors.insert(std::make_pair(type, convertor));
     
     return convertor; 
+#endif
 }
 
 void *
@@ -2758,12 +2829,17 @@
 	return iter->second;
     }
 
+#if MACRUBY_STATIC
+    printf("uncached to_ocval convertor %s\n", type.c_str());
+    abort();
+#else
     Function *f = RoxorCompiler::shared->compile_to_ocval_convertor(
 	    type.c_str());
     void *convertor = (void *)compile(f);
     to_ocval_convertors.insert(std::make_pair(type, convertor));
     
     return convertor; 
+#endif
 }
 
 static const int VM_LVAR_USES_SIZE = 8;
@@ -3597,6 +3673,7 @@
 void
 rb_vm_init_compiler(void)
 {
+#if !defined(MACRUBY_STATIC)
     if (ruby_aot_compile && ruby_debug_socket_path) {
 	fprintf(stderr, "cannot run in both AOT and debug mode\n");
 	exit(1);
@@ -3604,6 +3681,7 @@
     RoxorCompiler::shared = ruby_aot_compile
 	? new RoxorAOTCompiler()
 	: new RoxorCompiler(ruby_debug_socket_path);
+#endif
 }
 
 extern "C" void rb_node_release(NODE *node);
@@ -3613,6 +3691,9 @@
 rb_vm_run(const char *fname, NODE *node, rb_vm_binding_t *binding,
 	bool inside_eval)
 {
+#if MACRUBY_STATIC
+    rb_raise(rb_eRuntimeError, "codegen is not supported in MacRuby static");
+#else
     RoxorVM *vm = GET_VM();
     RoxorCompiler *compiler = RoxorCompiler::shared;
 
@@ -3668,6 +3749,7 @@
     rb_node_release(node);
 
     return ret;
+#endif
 }
 
 extern "C"
@@ -3675,6 +3757,9 @@
 rb_vm_run_under(VALUE klass, VALUE self, const char *fname, NODE *node,
 	rb_vm_binding_t *binding, bool inside_eval)
 {
+#if MACRUBY_STATIC
+    rb_raise(rb_eRuntimeError, "codegen is not supported in MacRuby static");
+#else
     RoxorVM *vm = GET_VM();
 
     VALUE old_top_object = vm->get_current_top_object();
@@ -3711,6 +3796,7 @@
     } finalizer(vm, old_dynamic_class, old_class, old_top_object);
 
     return rb_vm_run(fname, node, binding, inside_eval);
+#endif
 }
 
 extern VALUE rb_progname;
@@ -3719,6 +3805,9 @@
 void
 rb_vm_aot_compile(NODE *node)
 {
+#if MACRUBY_STATIC
+    abort();
+#else
     assert(ruby_aot_compile);
     assert(ruby_aot_init_func);
 
@@ -3747,6 +3836,7 @@
     }
     WriteBitcodeToFile(RoxorCompiler::module, out);
     out.close();
+#endif
 }
 
 extern "C"
@@ -4502,6 +4592,7 @@
     GET_CORE()->insert_stub("#@:", (void *)builtin_ostub1, true);
 }
 
+#if !defined(MACRUBY_STATIC)
 static IMP old_resolveClassMethod_imp = NULL;
 static IMP old_resolveInstanceMethod_imp = NULL;
 static SEL sel_resolveClassMethod = 0;
@@ -4541,6 +4632,7 @@
     }
     return false;
 }
+#endif
 
 // We can't trust LLVM to pick the right target at runtime.
 #if __LP64__
@@ -4555,6 +4647,7 @@
 void 
 Init_PreVM(void)
 {
+#if !defined(MACRUBY_STATIC)
     // To emit DWARF exception tables. 
 #if LLVM_TOT
     llvm::JITExceptionHandling = true;
@@ -4597,6 +4690,8 @@
 
     RoxorCompiler::module->setTargetTriple(TARGET_TRIPLE);
     RoxorInterpreter::shared = new RoxorInterpreter();
+#endif
+
     RoxorCore::shared = new RoxorCore();
     RoxorVM::main = new RoxorVM();
 
@@ -4606,6 +4701,7 @@
 
     setup_builtin_stubs();
 
+#if !defined(MACRUBY_STATIC)
     Class ns_object = (Class)objc_getClass("NSObject");
     Method m;
     sel_resolveClassMethod = sel_registerName("resolveClassMethod:");
@@ -4619,6 +4715,7 @@
     assert(m != NULL);
     old_resolveInstanceMethod_imp = method_getImplementation(m);
     method_setImplementation(m, (IMP)resolveInstanceMethod_imp);
+#endif
 
     // Early define some classes.
     rb_cNSString = (VALUE)objc_getClass("NSString");
@@ -4842,6 +4939,7 @@
 void
 rb_vm_finalize(void)
 {
+#if !defined(MACRUBY_STATIC)
     if (getenv("VM_DUMP_IR") != NULL) {
 	printf("IR dump ----------------------------------------------\n");
 	RoxorCompiler::module->dump();
@@ -4852,11 +4950,11 @@
 	    GET_CORE()->get_functions_compiled());
 #endif
 
-
     if (getenv("VM_VERIFY_IR") != NULL) {
 	rb_verify_module();
 	printf("IR verified!\n");
     }
+#endif
 
     // XXX: deleting the core is not safe at this point because there might be
     // threads still running and trying to unregister.

Modified: MacRuby/trunk/vm.h
===================================================================
--- MacRuby/trunk/vm.h	2010-06-14 23:53:49 UTC (rev 4223)
+++ MacRuby/trunk/vm.h	2010-06-16 09:05:24 UTC (rev 4224)
@@ -630,11 +630,13 @@
 #if defined(__cplusplus)
 }
 
+#if !defined(MACRUBY_STATIC)
 typedef struct {
     Function *func;
     rb_vm_arity_t arity;
     int flags;
 } rb_vm_method_source_t;
+#endif
 
 #define rb_vm_long_arity_stub_t rb_vm_objc_stub_t
 typedef VALUE rb_vm_long_arity_bstub_t(IMP imp, id self, SEL sel,
@@ -666,12 +668,14 @@
 
     private:
 	// LLVM objects.
-#if !defined(LLVM_TOT)
+#if !defined(MACRUBY_STATIC)
+# if !defined(LLVM_TOT)
 	ExistingModuleProvider *emp;
-#endif
+# endif
 	RoxorJITManager *jmm;
 	ExecutionEngine *ee;
 	FunctionPassManager *fpm;
+#endif
 
 	// Running threads.
 	VALUE threads;
@@ -698,8 +702,10 @@
 	std::map<int, VALUE> trap_cmd;
 	std::map<int, int> trap_level;
 
+#if !defined(MACRUBY_STATIC)
 	// Cache to avoid compiling the same Function twice.
 	std::map<Function *, IMP> JITcache;
+#endif
 
 	// Cache to identify pure Ruby implementations / methods.
 	std::map<IMP, rb_vm_method_node_t *> ruby_imps;
@@ -708,11 +714,18 @@
 	// Constants cache.
 	std::map<ID, struct ccache *> ccache;
 
+	// Outers map (where a class is actually defined).
+	std::map<Class, struct rb_vm_outer *> outers;
+
+#if !defined(MACRUBY_STATIC)
 	// Optimized selectors redefinition cache.
 	std::map<SEL, GlobalVariable *> redefined_ops_gvars;
 
-	// Outers map (where a class is actually defined).
-	std::map<Class, struct rb_vm_outer *> outers;
+	// Caches for the lazy JIT.
+	std::map<SEL, std::map<Class, rb_vm_method_source_t *> *>
+	    method_sources;
+	std::multimap<Class, SEL> method_source_sels;
+#endif
 
 	// Maps to cache compiled stubs for a given Objective-C runtime type.
 	std::map<std::string, void *> c_stubs, objc_stubs,
@@ -721,11 +734,6 @@
 	std::map<int, void *> rb_large_arity_rstubs; // Large arity Ruby calls
 	std::map<int, void *> rb_large_arity_bstubs; // Large arity block calls
 
-	// Caches for the lazy JIT.
-	std::map<SEL, std::map<Class, rb_vm_method_source_t *> *>
-	    method_sources;
-	std::multimap<Class, SEL> method_source_sels;
-
 	// BridgeSupport caches.
 	bs_parser_t *bs_parser;
 	std::map<std::string, rb_vm_bs_boxed_t *> bs_boxed;
@@ -778,12 +786,14 @@
 	void register_thread(VALUE thread);
 	void unregister_thread(VALUE thread);
 
+#if !defined(MACRUBY_STATIC)
 	void optimize(Function *func);
 	IMP compile(Function *func, bool optimize=true);
 	void delenda(Function *func);
 
 	void load_bridge_support(const char *path, const char *framework_path,
 		int options);
+#endif
 
 	bs_element_constant_t *find_bs_const(ID name);
 	bs_element_method_t *find_bs_method(Class klass, SEL sel);
@@ -798,18 +808,19 @@
 	// This callback is public for the only reason it's called by C.
 	void bs_parse_cb(bs_element_type_t type, void *value, void *ctx);
 
+	void insert_stub(const char *types, void *stub, bool is_objc) {
+	    std::map<std::string, void *> &m =
+		is_objc ? objc_stubs : c_stubs;
+	    m.insert(std::make_pair(types, stub));
+	}
+
 	void *gen_large_arity_stub(int argc, bool is_block=false);
 	void *gen_stub(std::string types, bool variadic, int min_argc,
 		bool is_objc);
 	void *gen_to_rval_convertor(std::string type);
 	void *gen_to_ocval_convertor(std::string type);
 
-	void insert_stub(const char *types, void *stub, bool is_objc) {
-	    std::map<std::string, void *> &m =
-		is_objc ? objc_stubs : c_stubs;
-	    m.insert(std::make_pair(types, stub));
-	}
-
+#if !defined(MACRUBY_STATIC)
 	std::map<Class, rb_vm_method_source_t *> *
 	method_sources_for_sel(SEL sel, bool create) {
 	    std::map<SEL, std::map<Class, rb_vm_method_source_t *> *>::iterator
@@ -828,6 +839,7 @@
 	    }
 	    return map;
 	}
+#endif
 
 	bool symbolize_call_address(void *addr, void **startp,
 		char *path, size_t path_len, unsigned long *ln,
@@ -841,30 +853,34 @@
 	rb_vm_method_node_t *method_node_get(IMP imp, bool create=false);
 	rb_vm_method_node_t *method_node_get(Method m, bool create=false);
 
+#if !defined(MACRUBY_STATIC)
 	rb_vm_method_source_t *method_source_get(Class klass, SEL sel);
 
 	void prepare_method(Class klass, SEL sel, Function *func,
 		const rb_vm_arity_t &arity, int flag);
+	rb_vm_method_node_t *resolve_method(Class klass, SEL sel,
+		Function *func, const rb_vm_arity_t &arity, int flags,
+		IMP imp, Method m);
+	bool resolve_methods(std::map<Class, rb_vm_method_source_t *> *map,
+		Class klass, SEL sel);
+#endif
 	rb_vm_method_node_t *add_method(Class klass, SEL sel, IMP imp,
 		IMP ruby_imp, const rb_vm_arity_t &arity, int flags,
 		const char *types);
-	rb_vm_method_node_t *resolve_method(Class klass, SEL sel,
-		Function *func, const rb_vm_arity_t &arity, int flags,
-		IMP imp, Method m);
 	rb_vm_method_node_t *retype_method(Class klass,
 		rb_vm_method_node_t *node, const char *old_types,
 		const char *new_types);
 	void undef_method(Class klass, SEL sel);
 	void remove_method(Class klass, SEL sel);
-	bool resolve_methods(std::map<Class, rb_vm_method_source_t *> *map,
-		Class klass, SEL sel);
 	bool copy_method(Class klass, Method m);
 	void copy_methods(Class from_class, Class to_class);
 	void get_methods(VALUE ary, Class klass, bool include_objc_methods,
 		int (*filter) (VALUE, ID, VALUE));
 	void method_added(Class klass, SEL sel);
 
+#if !defined(MACRUBY_STATIC)
 	GlobalVariable *redefined_op_gvar(SEL sel, bool create);
+#endif
 	bool should_invalidate_inline_op(SEL sel, Class klass);
 
 	struct ccache *constant_cache_get(ID path);
@@ -873,9 +889,11 @@
 	struct rb_vm_outer *get_outer(Class klass);
 	void set_outer(Class klass, Class mod);
 
+#if !defined(MACRUBY_STATIC)
 	size_t get_sizeof(const Type *type);
 	size_t get_sizeof(const char *type);
 	bool is_large_struct_type(const Type *type);
+#endif
 
 	void register_finalizer(rb_vm_finalizer_t *finalizer);
 	void unregister_finalizer(rb_vm_finalizer_t *finalizer);
@@ -1130,4 +1148,7 @@
 
 #endif /* __cplusplus */
 
+#define not_implemented_in_static(s) \
+    rb_raise(rb_eRuntimeError, "%s is not supported in MacRuby static", sel_getName(s))
+
 #endif /* __VM_H_ */
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100616/3fa1fcc7/attachment-0001.html>


More information about the macruby-changes mailing list