Permalink
Browse files

Add op for looking up attribute access hints.

These allow better compilation of attribute lookups, saving a hash
lookup per attribute access that can be resolved at compile time.
  • Loading branch information...
jnthn committed Jun 11, 2013
1 parent 5adf255 commit 4e615b3bddb68b5687bea44928e452fae55ee84a
@@ -2197,6 +2197,7 @@ QAST::OperationsJAST.map_classlib_core_op('bindattr_i', $TYPE_OPS, 'bindattr_i',
QAST::OperationsJAST.map_classlib_core_op('bindattr_n', $TYPE_OPS, 'bindattr_n', [$RT_OBJ, $RT_OBJ, $RT_STR, $RT_NUM], $RT_NUM, :tc);
QAST::OperationsJAST.map_classlib_core_op('bindattr_s', $TYPE_OPS, 'bindattr_s', [$RT_OBJ, $RT_OBJ, $RT_STR, $RT_STR], $RT_STR, :tc);
QAST::OperationsJAST.map_classlib_core_op('attrinited', $TYPE_OPS, 'attrinited', [$RT_OBJ, $RT_OBJ, $RT_STR], $RT_INT, :tc);
QAST::OperationsJAST.map_classlib_core_op('attrhintfor', $TYPE_OPS, 'attrhintfor', [$RT_OBJ, $RT_STR], $RT_INT, :tc);
QAST::OperationsJAST.map_classlib_core_op('unbox_i', $TYPE_OPS, 'unbox_i', [$RT_OBJ], $RT_INT, :tc);
QAST::OperationsJAST.map_classlib_core_op('unbox_n', $TYPE_OPS, 'unbox_n', [$RT_OBJ], $RT_NUM, :tc);
QAST::OperationsJAST.map_classlib_core_op('unbox_s', $TYPE_OPS, 'unbox_s', [$RT_OBJ], $RT_STR, :tc);
@@ -1833,6 +1833,10 @@ public static String bindattr_s(SixModelObject obj, SixModelObject ch, String na
public static long attrinited(SixModelObject obj, SixModelObject ch, String name, ThreadContext tc) {
return obj.is_attribute_initialized(tc, decont(ch, tc), name, STable.NO_HINT);
}
public static long attrhintfor(SixModelObject ch, String name, ThreadContext tc) {
ch = decont(ch, tc);
return ch.st.REPR.hint_for(tc, ch.st, ch, name);
}
/* Positional operations. */
public static SixModelObject atpos(SixModelObject arr, long idx, ThreadContext tc) {
@@ -593,6 +593,20 @@ public StorageSpec get_storage_spec(ThreadContext tc, STable st) {
return ss;
}
public long hint_for(ThreadContext tc, STable st, SixModelObject classHandle, String name) {
P6OpaqueREPRData rd = (P6OpaqueREPRData)st.REPRData;
for (int i = 0; i < rd.classHandles.length; i++) {
if (rd.classHandles[i] == classHandle) {
Integer idx = rd.nameToHintMap[i].get(name);
if (idx != null)
return idx;
else
break;
}
}
return STable.NO_HINT;
}
private class ByteClassLoader extends ClassLoader {
private byte[] bytes;

0 comments on commit 4e615b3

Please sign in to comment.