Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement setting invocation spec.
It's not actually used yet, however.
  • Loading branch information
jnthn committed Feb 1, 2013
1 parent 23578d4 commit 18e278b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/QAST/JASTCompiler.nqp
Expand Up @@ -1396,6 +1396,7 @@ QAST::OperationsJAST.map_classlib_core_op('setmethcache', $TYPE_OPS, 'setmethcac
QAST::OperationsJAST.map_classlib_core_op('setmethcacheauth', $TYPE_OPS, 'setmethcacheauth', [$RT_OBJ, $RT_INT], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('settypecache', $TYPE_OPS, 'settypecache', [$RT_OBJ, $RT_OBJ], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('isinvokable', $TYPE_OPS, 'isinvokable', [$RT_OBJ], $RT_INT, :tc);
QAST::OperationsJAST.map_classlib_core_op('setinvokespec', $TYPE_OPS, 'setinvokespec', [$RT_OBJ, $RT_OBJ, $RT_STR, $RT_OBJ], $RT_OBJ, :tc);

# defined - overridden by HLL, but by default same as .DEFINITE.
QAST::OperationsJAST.map_classlib_core_op('defined', $TYPE_OPS, 'isconcrete', [$RT_OBJ], $RT_INT, :tc);
Expand Down
13 changes: 11 additions & 2 deletions src/org/perl6/nqp/runtime/Ops.java
Expand Up @@ -1081,9 +1081,18 @@ public static SixModelObject settypecache(SixModelObject obj, SixModelObject typ
obj.st.TypeCheckCache = cache;
return obj;
}
public static SixModelObject setinvokespec(SixModelObject obj, SixModelObject ch,
String name, SixModelObject invocationHandler, ThreadContext tc) {
InvocationSpec is = new InvocationSpec();
is.ClassHandle = ch;
is.AttrName = name;
is.Hint = STable.NO_HINT;
is.InvocationHandler = invocationHandler;
obj.st.InvocationSpec = is;
return obj;
}
public static long isinvokable(SixModelObject obj, ThreadContext tc) {
// TODO: Update when invocation protocol done.
return obj instanceof CodeRef ? 1 : 0;
return obj instanceof CodeRef || obj.st.InvocationSpec != null ? 1 : 0;
}

/* Box/unbox operations. */
Expand Down
25 changes: 25 additions & 0 deletions src/org/perl6/nqp/sixmodel/InvocationSpec.java
@@ -0,0 +1,25 @@
package org.perl6.nqp.sixmodel;

/* How do we invoke this thing? Specifies either an attribute to look at for
* an invokable thing, or alternatively a method to call. */
public class InvocationSpec {
/**
* Class handle where we find the attribute to invoke.
*/
public SixModelObject ClassHandle;

/**
* Attribute name where we find the attribute to invoke.
*/
public String AttrName;

/**
* Attribute lookup hint used in gradual typing.
*/
public long Hint;

/**
* Thing that handles invocation.
*/
public SixModelObject InvocationHandler;
}
6 changes: 6 additions & 0 deletions src/org/perl6/nqp/sixmodel/STable.java
Expand Up @@ -95,6 +95,12 @@ public STable(REPR REPR, SixModelObject HOW) {
*/
public ContainerSpec ContainerSpec;

/**
* If this is invokable, then this contains information needed to
* figure out how to invoke it. If not, it'll be null.
*/
public InvocationSpec InvocationSpec;

/**
* Information - if any - about how we can turn something of this type
* into a boolean.
Expand Down

0 comments on commit 18e278b

Please sign in to comment.