Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
nqp::invokewithcapture; stub multi cache ops.
The multi-dispatch cache can come later; may be a good LHF task since
it's porting something that already exists, mostly.
  • Loading branch information
jnthn committed Feb 7, 2013
1 parent 07feece commit c8228f6
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 10 deletions.
5 changes: 5 additions & 0 deletions lib/QAST/JASTCompiler.nqp
Expand Up @@ -1189,6 +1189,11 @@ QAST::OperationsJAST.map_classlib_core_op('captureposarg_n', $TYPE_OPS, 'capture
QAST::OperationsJAST.map_classlib_core_op('captureposarg_s', $TYPE_OPS, 'captureposarg_s', [$RT_OBJ, $RT_INT], $RT_STR, :tc);
QAST::OperationsJAST.map_classlib_core_op('captureposprimspec', $TYPE_OPS, 'captureposprimspec', [$RT_OBJ, $RT_INT], $RT_INT, :tc);

# Multiple dispatch related.
QAST::OperationsJAST.map_classlib_core_op('invokewithcapture', $TYPE_OPS, 'invokewithcapture', [$RT_OBJ, $RT_OBJ], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('multicacheadd', $TYPE_OPS, 'multicacheadd', [$RT_OBJ, $RT_OBJ, $RT_OBJ], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('multicachefind', $TYPE_OPS, 'multicachefind', [$RT_OBJ, $RT_OBJ], $RT_OBJ, :tc);

# Default way to do positional and associative lookups.
QAST::OperationsJAST.map_classlib_core_op('positional_get', $TYPE_OPS, 'atpos', [$RT_OBJ, $RT_INT], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('positional_bind', $TYPE_OPS, 'bindpos', [$RT_OBJ, $RT_INT, $RT_OBJ], $RT_OBJ, :tc);
Expand Down
58 changes: 48 additions & 10 deletions src/org/perl6/nqp/runtime/Ops.java
Expand Up @@ -947,7 +947,14 @@ public static void invoke(ThreadContext tc, SixModelObject invokee, int callsite
}
throw throwee;
}


// TODO Find a smarter way to do this without all the pointer chasing.
if (callsiteIndex >= 0)
invokeInternal(tc, invokee, tc.curFrame.codeRef.staticInfo.compUnit.callSites[callsiteIndex]);
else
invokeInternal(tc, invokee, emptyCallSite);
}
private static void invokeInternal(ThreadContext tc, SixModelObject invokee, CallSiteDescriptor csd) throws Exception {
// Otherwise, get the code ref.
CodeRef cr;
if (invokee instanceof CodeRef) {
Expand All @@ -965,18 +972,11 @@ public static void invoke(ThreadContext tc, SixModelObject invokee, int callsite
StaticCodeInfo sci = cr.staticInfo;

// Create a new call frame and set caller and callsite.
// TODO Find a smarter way to do this without all the pointer chasing.
CallFrame cf = new CallFrame();
cf.tc = tc;
cf.codeRef = cr;
if (callsiteIndex >= 0) {
cf.caller = tc.curFrame;
cf.callSite = tc.curFrame.codeRef.staticInfo.compUnit.callSites[callsiteIndex];
}
else {
cf.caller = tc.curFrame;
cf.callSite = emptyCallSite;
}
cf.caller = tc.curFrame;
cf.callSite = csd;

// Set outer; if it's explicitly in the code ref, use that. If not,
// go hunting for one. Fall back to outer's prior invocation.
Expand Down Expand Up @@ -1035,6 +1035,34 @@ public static void invoke(ThreadContext tc, SixModelObject invokee, int callsite
tc.curFrame = cf.caller;
}
}
public static SixModelObject invokewithcapture(SixModelObject invokee, SixModelObject capture, ThreadContext tc) throws Exception {
if (capture instanceof CallCaptureInstance) {
CallCaptureInstance cc = (CallCaptureInstance)capture;

SixModelObject[] oArgOrig = tc.curFrame.oArg;
long[] iArgOrig = tc.curFrame.iArg;
double[] nArgOrig = tc.curFrame.nArg;
String[] sArgOrig = tc.curFrame.sArg;

try {
tc.curFrame.oArg = cc.oArg;
tc.curFrame.iArg = cc.iArg;
tc.curFrame.nArg = cc.nArg;
tc.curFrame.sArg = cc.sArg;
invokeInternal(tc, invokee, cc.descriptor);
return result_o(tc.curFrame);
}
finally {
tc.curFrame.oArg = oArgOrig;
tc.curFrame.iArg = iArgOrig;
tc.curFrame.nArg = nArgOrig;
tc.curFrame.sArg = sArgOrig;
}
}
else {
throw new RuntimeException("invokewithcapture requires a CallCapture");
}
}

/* Lexotic. */
public static SixModelObject lexotic(long target) {
Expand All @@ -1043,6 +1071,16 @@ public static SixModelObject lexotic(long target) {
return res;
}

/* Multi-dispatch cache. */
public static SixModelObject multicacheadd(SixModelObject cache, SixModelObject capture, SixModelObject result, ThreadContext tc) {
// TODO
return null;
}
public static SixModelObject multicachefind(SixModelObject cache, SixModelObject capture, ThreadContext tc) {
// TODO
return null;
}

/* Basic 6model operations. */
public static SixModelObject what(SixModelObject o) {
return o.st.WHAT;
Expand Down

0 comments on commit c8228f6

Please sign in to comment.