optimizer fixes and added applySome
authortimmy <timmy@timmy-desktop.(none)>
Sat, 6 Feb 2010 02:36:37 +0000 (21:36 -0500)
committertimmy <timmy@timmy-desktop.(none)>
Sat, 6 Feb 2010 02:36:37 +0000 (21:36 -0500)
src/lib/method.slate [new file with mode: 0644]
src/mobius/prelude.slate
src/vm/method.cpp
src/vm/optimizer.cpp

diff --git a/src/lib/method.slate b/src/lib/method.slate
new file mode 100644 (file)
index 0000000..8922c51
--- /dev/null
@@ -0,0 +1,7 @@
+
+"Method functions that are not needed in the bootstrap process"
+
+m@(Method traits) applySome: args@(Sequence traits)
+"Apply a block with as many arguments as it expects."
+[ m applyTo: (args first: m arity) ].
+
index 416dbd4..3552485 100644 (file)
@@ -11,7 +11,7 @@ code which is compiled in to the kernel image."
    'multi-dimensional'.
    'precedence'.
    'inspect'. 'directory'.
-   'time'. 'concurrency'. 'observer'. 'devsupport'}
+   'time'. 'concurrency'. 'observer'. 'devsupport'. 'method'}
      collect: #; `er <- 'src/lib/') ;
   {'src/mobius/role'.
    'src/lib/image'.
index 31665c8..5b70610 100644 (file)
@@ -270,12 +270,32 @@ struct MethodDefinition* method_dispatch_on(struct object_heap* oh, struct Symbo
 }
 
 
+bool method_on_call_stack(struct object_heap* oh, struct CompiledMethod* method) {
+
+  struct Interpreter* i = oh->cached.interpreter;
+  word_t fp = i->framePointer;
+  struct Closure* closure = (struct Closure*)i->method;
+  do {
+    if (closure->method == method) return true;
+    fp = object_to_smallint(i->stack->elements[fp - FRAME_OFFSET_PREVIOUS_FRAME_POINTER]);
+    if (fp < FUNCTION_FRAME_SIZE) break;
+    closure = (struct Closure*)i->stack->elements[fp - FRAME_OFFSET_METHOD];
+  } while (fp >= FUNCTION_FRAME_SIZE);
+
+  if (closure->method == method) return true;
+  return false;
+}
 
 
 void method_unoptimize(struct object_heap* oh, struct CompiledMethod* method) {
 #ifdef PRINT_DEBUG_UNOPTIMIZER
   printf("Unoptimizing '"); print_symbol(method->selector); printf("'\n");
 #endif
+  if (method_on_call_stack(oh, method)) {
+    printf("Fixme cannot unoptimizing because on call stack: '"); print_symbol(method->selector); printf("'\n");
+    return;
+  }
+
   method->code = method->oldCode;
   heap_store_into(oh, (struct Object*) method->code, (struct Object*) method->oldCode);
   method->isInlined = oh->cached.false_object;
@@ -305,21 +325,6 @@ void method_remove_optimized_sending(struct object_heap* oh, struct Symbol* symb
 
 }
 
-bool method_on_call_stack(struct object_heap* oh, struct CompiledMethod* method) {
-
-  struct Interpreter* i = oh->cached.interpreter;
-  word_t fp = i->framePointer;
-  struct Closure* closure = (struct Closure*)i->method;
-  do {
-    if (closure->method == method) return true;
-    fp = object_to_smallint(i->stack->elements[fp - FRAME_OFFSET_PREVIOUS_FRAME_POINTER]);
-    if (fp < FUNCTION_FRAME_SIZE) break;
-    closure = (struct Closure*)i->stack->elements[fp - FRAME_OFFSET_METHOD];
-  } while (fp >= FUNCTION_FRAME_SIZE);
-
-  if (closure->method == method) return true;
-  return false;
-}
 
 
 void method_optimize(struct object_heap* oh, struct CompiledMethod* method) {
@@ -361,7 +366,6 @@ void method_optimize(struct object_heap* oh, struct CompiledMethod* method) {
   }
   //whether to start with a fresh slate
   //not starting may give us another degree of inlining
-  //method->code = method->oldCode;
   heap_store_into(oh, (struct Object*) method->oldCode, (struct Object*) method->code);
 
   method->isInlined = oh->cached.true_object;
index f0076c3..87849a8 100644 (file)
@@ -338,6 +338,7 @@ bool optimizer_method_can_be_optimized(struct object_heap* oh, struct CompiledMe
   if (method->restVariable == oh->cached.true_object) return false;
   struct Object* traitsWindow = method->base.map->delegates->elements[0];
   if (traitsWindow == oh->cached.primitive_method_window) return false;
+  if (array_size(method->optionalKeywords) != 0) return false;
   std::vector<struct Object*> code;
   optimizer_append_code_to_vector(method->code, code);
   if (code.size() > INLINER_MAX_METHOD_SIZE) return false;