]> gitweb.factorcode.org Git - factor.git/blobdiff - vm/dispatch.cpp
Put brackets around ipv6 addresses in `inet6 present`
[factor.git] / vm / dispatch.cpp
index 3aab4f9ffe83b0bcd67f2c875c110aa7f97b6f9f..810f5eb83ee79543c3a0826378316cbc789b9d82 100644 (file)
@@ -2,34 +2,29 @@
 
 namespace factor {
 
-cell factor_vm::search_lookup_alist(cell table, cell klass) {
+static cell search_lookup_alist(cell table, cell klass) {
   array* elements = untag<array>(table);
-  fixnum index = array_capacity(elements) - 2;
-  while (index >= 0) {
+  for (fixnum index = array_capacity(elements) - 2; index >= 0; index -= 2) {
     if (array_nth(elements, index) == klass)
       return array_nth(elements, index + 1);
-    else
-      index -= 2;
   }
-
   return false_object;
 }
 
-cell factor_vm::search_lookup_hash(cell table, cell klass, cell hashcode) {
+static cell search_lookup_hash(cell table, cell klass, cell hashcode) {
   array* buckets = untag<array>(table);
   cell bucket = array_nth(buckets, hashcode & (array_capacity(buckets) - 1));
   if (TAG(bucket) == ARRAY_TYPE)
     return search_lookup_alist(bucket, klass);
-  else
-    return bucket;
+  return bucket;
 }
 
-cell factor_vm::nth_superclass(tuple_layout* layout, fixnum echelon) {
+static cell nth_superclass(tuple_layout* layout, fixnum echelon) {
   cell* ptr = (cell*)(layout + 1);
   return ptr[echelon * 2];
 }
 
-cell factor_vm::nth_hashcode(tuple_layout* layout, fixnum echelon) {
+static cell nth_hashcode(tuple_layout* layout, fixnum echelon) {
   cell* ptr = (cell*)(layout + 1);
   return ptr[echelon * 2 + 1];
 }
@@ -40,12 +35,12 @@ cell factor_vm::lookup_tuple_method(cell obj, cell methods) {
   array* echelons = untag<array>(methods);
 
   fixnum echelon = std::min(untag_fixnum(layout->echelon),
-                            (fixnum) array_capacity(echelons) - 1);
+                            (fixnum)array_capacity(echelons) - 1);
 
   while (echelon >= 0) {
     cell echelon_methods = array_nth(echelons, echelon);
 
-    if (tagged<object>(echelon_methods).type_p(WORD_TYPE))
+    if (TAG(echelon_methods) == WORD_TYPE)
       return echelon_methods;
     else if (to_boolean(echelon_methods)) {
       cell klass = nth_superclass(layout, echelon);
@@ -69,10 +64,9 @@ cell factor_vm::lookup_method(cell obj, cell methods) {
   if (tag == TUPLE_TYPE) {
     if (TAG(method) == ARRAY_TYPE)
       return lookup_tuple_method(obj, method);
-    else
-      return method;
-  } else
     return method;
+  }
+  return method;
 }
 
 void factor_vm::primitive_lookup_method() {
@@ -85,11 +79,10 @@ cell factor_vm::object_class(cell obj) {
   cell tag = TAG(obj);
   if (tag == TUPLE_TYPE)
     return untag<tuple>(obj)->layout;
-  else
-    return tag_fixnum(tag);
+  return tag_fixnum(tag);
 }
 
-cell factor_vm::method_cache_hashcode(cell klass, array* array) {
+static cell method_cache_hashcode(cell klass, array* array) {
   cell capacity = (array_capacity(array) >> 1) - 1;
   return ((klass >> TAG_BITS) & capacity) << 1;
 }
@@ -121,34 +114,9 @@ void factor_vm::primitive_reset_dispatch_stats() {
   memset(&dispatch_stats, 0, sizeof(dispatch_statistics));
 }
 
-/* Allocates memory */
+// Allocates memory
 void factor_vm::primitive_dispatch_stats() {
   ctx->push(tag<byte_array>(byte_array_from_value(&dispatch_stats)));
 }
 
-void quotation_jit::emit_mega_cache_lookup(cell methods_, fixnum index,
-                                           cell cache_) {
-  data_root<array> methods(methods_, parent);
-  data_root<array> cache(cache_, parent);
-
-  /* The object must be on the top of the datastack at this point. */
-
-  /* Do a cache lookup. */
-  emit_with_literal(parent->special_objects[MEGA_LOOKUP], cache.value());
-
-  /* If we end up here, the cache missed. */
-  emit(parent->special_objects[JIT_PROLOG]);
-
-  /* Push index, method table and cache on the stack. */
-  push(methods.value());
-  push(tag_fixnum(index));
-  push(cache.value());
-  word_call(parent->special_objects[MEGA_MISS_WORD]);
-
-  /* Now the new method has been stored into the cache, and its on
-     the stack. */
-  emit(parent->special_objects[JIT_EPILOG]);
-  emit(parent->special_objects[JIT_EXECUTE]);
-}
-
 }