cell megamorphic_cache_hits;
cell megamorphic_cache_misses;
-static cell search_lookup_alist(cell table, cell klass)
+cell factorvm::search_lookup_alist(cell table, cell klass)
{
array *elements = untag<array>(table);
fixnum index = array_capacity(elements) - 2;
return F;
}
-static cell search_lookup_hash(cell table, cell klass, cell hashcode)
+cell search_lookup_alist(cell table, cell klass)
+{
+ return vm->search_lookup_alist(table,klass);
+}
+
+cell factorvm::search_lookup_hash(cell table, cell klass, cell hashcode)
{
array *buckets = untag<array>(table);
cell bucket = array_nth(buckets,hashcode & (array_capacity(buckets) - 1));
return search_lookup_alist(bucket,klass);
}
-static cell nth_superclass(tuple_layout *layout, fixnum echelon)
+cell search_lookup_hash(cell table, cell klass, cell hashcode)
+{
+ return vm->search_lookup_hash(table,klass,hashcode);
+}
+
+cell factorvm::nth_superclass(tuple_layout *layout, fixnum echelon)
{
cell *ptr = (cell *)(layout + 1);
return ptr[echelon * 2];
}
-static cell nth_hashcode(tuple_layout *layout, fixnum echelon)
+cell nth_superclass(tuple_layout *layout, fixnum echelon)
+{
+ return vm->nth_superclass(layout,echelon);
+}
+
+cell factorvm::nth_hashcode(tuple_layout *layout, fixnum echelon)
{
cell *ptr = (cell *)(layout + 1);
return ptr[echelon * 2 + 1];
}
-static cell lookup_tuple_method(cell obj, cell methods)
+cell nth_hashcode(tuple_layout *layout, fixnum echelon)
+{
+ return vm->nth_hashcode(layout,echelon);
+}
+
+cell factorvm::lookup_tuple_method(cell obj, cell methods)
{
tuple_layout *layout = untag<tuple_layout>(untag<tuple>(obj)->layout);
return F;
}
-static cell lookup_hi_tag_method(cell obj, cell methods)
+cell lookup_tuple_method(cell obj, cell methods)
+{
+ return vm->lookup_tuple_method(obj,methods);
+}
+
+cell factorvm::lookup_hi_tag_method(cell obj, cell methods)
{
array *hi_tag_methods = untag<array>(methods);
cell tag = untag<object>(obj)->h.hi_tag() - HEADER_TYPE;
return array_nth(hi_tag_methods,tag);
}
-static cell lookup_hairy_method(cell obj, cell methods)
+cell lookup_hi_tag_method(cell obj, cell methods)
+{
+ return vm->lookup_hi_tag_method(obj,methods);
+}
+
+cell factorvm::lookup_hairy_method(cell obj, cell methods)
{
cell method = array_nth(untag<array>(methods),TAG(obj));
if(tagged<object>(method).type_p(WORD_TYPE))
}
}
-cell lookup_method(cell obj, cell methods)
+cell lookup_hairy_method(cell obj, cell methods)
+{
+ return vm->lookup_hairy_method(obj,methods);
+}
+
+cell factorvm::lookup_method(cell obj, cell methods)
{
cell tag = TAG(obj);
if(tag == TUPLE_TYPE || tag == OBJECT_TYPE)
return array_nth(untag<array>(methods),TAG(obj));
}
-PRIMITIVE(lookup_method)
+cell lookup_method(cell obj, cell methods)
+{
+ return vm->lookup_method(obj,methods);
+}
+
+inline void factorvm::vmprim_lookup_method()
{
cell methods = dpop();
cell obj = dpop();
dpush(lookup_method(obj,methods));
}
-cell object_class(cell obj)
+PRIMITIVE(lookup_method)
+{
+ PRIMITIVE_GETVM()->vmprim_lookup_method();
+}
+
+cell factorvm::object_class(cell obj)
{
switch(TAG(obj))
{
}
}
-static cell method_cache_hashcode(cell klass, array *array)
+cell object_class(cell obj)
+{
+ return vm->object_class(obj);
+}
+
+cell factorvm::method_cache_hashcode(cell klass, array *array)
{
cell capacity = (array_capacity(array) >> 1) - 1;
return ((klass >> TAG_BITS) & capacity) << 1;
}
-static void update_method_cache(cell cache, cell klass, cell method)
+cell method_cache_hashcode(cell klass, array *array)
+{
+ return vm->method_cache_hashcode(klass,array);
+}
+
+void factorvm::update_method_cache(cell cache, cell klass, cell method)
{
array *cache_elements = untag<array>(cache);
cell hashcode = method_cache_hashcode(klass,cache_elements);
set_array_nth(cache_elements,hashcode + 1,method);
}
-PRIMITIVE(mega_cache_miss)
+void update_method_cache(cell cache, cell klass, cell method)
+{
+ return vm->update_method_cache(cache,klass,method);
+}
+
+inline void factorvm::vmprim_mega_cache_miss()
{
megamorphic_cache_misses++;
dpush(method);
}
-PRIMITIVE(reset_dispatch_stats)
+PRIMITIVE(mega_cache_miss)
+{
+ PRIMITIVE_GETVM()->vmprim_mega_cache_miss();
+}
+
+inline void factorvm::vmprim_reset_dispatch_stats()
{
megamorphic_cache_hits = megamorphic_cache_misses = 0;
}
-PRIMITIVE(dispatch_stats)
+PRIMITIVE(reset_dispatch_stats)
+{
+ PRIMITIVE_GETVM()->vmprim_reset_dispatch_stats();
+}
+
+inline void factorvm::vmprim_dispatch_stats()
{
growable_array stats;
stats.add(allot_cell(megamorphic_cache_hits));
dpush(stats.elements.value());
}
+PRIMITIVE(dispatch_stats)
+{
+ PRIMITIVE_GETVM()->vmprim_dispatch_stats();
+}
+
void quotation_jit::emit_mega_cache_lookup(cell methods_, fixnum index, cell cache_)
{
gc_root<array> methods(methods_);
fixnum quot_code_offset_to_scan(cell quot_, cell offset);
cell lazy_jit_compile_impl(cell quot_, stack_frame *stack);
inline void vmprim_quot_compiled_p();
+
+ //dispatch
+ cell search_lookup_alist(cell table, cell klass);
+ cell search_lookup_hash(cell table, cell klass, cell hashcode);
+ cell nth_superclass(tuple_layout *layout, fixnum echelon);
+ cell nth_hashcode(tuple_layout *layout, fixnum echelon);
+ cell lookup_tuple_method(cell obj, cell methods);
+ cell lookup_hi_tag_method(cell obj, cell methods);
+ cell lookup_hairy_method(cell obj, cell methods);
+ cell lookup_method(cell obj, cell methods);
+ inline void vmprim_lookup_method();
+ cell object_class(cell obj);
+ cell method_cache_hashcode(cell klass, array *array);
+ void update_method_cache(cell cache, cell klass, cell method);
+ inline void vmprim_mega_cache_miss();
+ inline void vmprim_reset_dispatch_stats();
+ inline void vmprim_dispatch_stats();
// next method here: