Skip to content

Instantly share code, notes, and snippets.

@mlschroe
Created June 26, 2013 12:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlschroe/5867111 to your computer and use it in GitHub Desktop.
Save mlschroe/5867111 to your computer and use it in GitHub Desktop.
Get rid of priorInvokation
diff --git a/src/vm/jvm/runtime/org/perl6/nqp/runtime/CallFrame.java b/src/vm/jvm/runtime/org/perl6/nqp/runtime/CallFrame.java
index bc7c752..9246140 100644
--- a/src/vm/jvm/runtime/org/perl6/nqp/runtime/CallFrame.java
+++ b/src/vm/jvm/runtime/org/perl6/nqp/runtime/CallFrame.java
@@ -96,7 +96,7 @@ public class CallFrame implements Cloneable {
this.caller = tc.curFrame;
// 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.
+ // go hunting for one.
StaticCodeInfo sci = cr.staticInfo;
if (cr.outer != null) {
this.outer = cr.outer;
@@ -114,8 +114,6 @@ public class CallFrame implements Cloneable {
checkFrame = checkFrame.caller;
}
if (this.outer == null)
- this.outer = wanted.priorInvocation;
- if (this.outer == null)
this.autoClose(wanted);
}
}
@@ -187,8 +185,6 @@ public class CallFrame implements Cloneable {
checkFrame = checkFrame.caller;
}
if (this.outer == null)
- this.outer = wanted.priorInvocation;
- if (this.outer == null)
this.autoClose(wanted);
}
@@ -205,12 +201,10 @@ public class CallFrame implements Cloneable {
public void autoClose(StaticCodeInfo wanted) {
this.outer = new CallFrame(tc, wanted);
- wanted.priorInvocation = this.outer;
}
// Does work needed to leave this callframe.
public void leave() {
- this.codeRef.staticInfo.priorInvocation = this;
this.tc.curFrame = this.caller;
}
diff --git a/src/vm/jvm/runtime/org/perl6/nqp/runtime/CodeRef.java b/src/vm/jvm/runtime/org/perl6/nqp/runtime/CodeRef.java
index e0951e4..bc83740 100644
--- a/src/vm/jvm/runtime/org/perl6/nqp/runtime/CodeRef.java
+++ b/src/vm/jvm/runtime/org/perl6/nqp/runtime/CodeRef.java
@@ -58,10 +58,7 @@ public class CodeRef extends SixModelObject {
CodeRef clone = new CodeRef();
clone.st = this.st;
clone.staticInfo = this.staticInfo;
- if (this.outer != null)
- clone.outer = this.outer;
- else
- clone.outer = staticInfo.outerStaticInfo.priorInvocation;
+ clone.outer = this.outer;
return clone;
}
diff --git a/src/vm/jvm/runtime/org/perl6/nqp/runtime/StaticCodeInfo.java b/src/vm/jvm/runtime/org/perl6/nqp/runtime/StaticCodeInfo.java
index 07e523f..6a1fc89 100644
--- a/src/vm/jvm/runtime/org/perl6/nqp/runtime/StaticCodeInfo.java
+++ b/src/vm/jvm/runtime/org/perl6/nqp/runtime/StaticCodeInfo.java
@@ -44,11 +44,6 @@ public class StaticCodeInfo implements Cloneable {
public StaticCodeInfo outerStaticInfo;
/**
- * Most recent invocation, if any.
- */
- public CallFrame priorInvocation;
-
- /**
* Static lexicals.
*/
public SixModelObject[] oLexStatic;
diff --git a/src/NQP/Actions.nqp b/src/NQP/Actions.nqp
index 680fac5..feb5eb9 100644
--- a/src/NQP/Actions.nqp
+++ b/src/NQP/Actions.nqp
@@ -921,8 +921,8 @@ class NQP::Actions is HLL::Actions {
}
}
- my $lexpast := QAST::Op.new( :op('takeclosure'), $past );
- $lexpast<sink> := $past;
+ my $lexpast := QAST::Op.new( :op('takeclosure'), QAST::Op.new( :op('captureouter'), $past ));
+ $lexpast<sink> := QAST::Op.new( :op('captureouter'), $past );
$lexpast<block_past> := $block;
make $lexpast;
@@ -1001,8 +1001,8 @@ class NQP::Actions is HLL::Actions {
}
# Install AST node in match object, then apply traits.
- my $lexpast := QAST::Op.new( :op('takeclosure'), $past );
- $lexpast<sink> := $past;
+ my $lexpast := QAST::Op.new( :op('takeclosure'), QAST::Op.new( :op('captureouter'), $past ));
+ $lexpast<sink> := QAST::Op.new( :op('captureouter'), $past );
$lexpast<block_past> := $past;
$lexpast<code_obj> := $past<code_obj>;
make $lexpast;
@@ -1230,6 +1230,7 @@ class NQP::Actions is HLL::Actions {
);
$*W.pkg_add_method($*PACKAGE, 'add_method', $name,
$*W.create_code($past, $name, 0, :code_type_name<NQPRegex>));
+ $past := QAST::Op.new( :op('captureouter'), $past);
}
else {
my $block := $*W.pop_lexpad();
@@ -1265,8 +1266,8 @@ class NQP::Actions is HLL::Actions {
$past := QAST::Op.new(
:op<callmethod>, :name<new>,
lexical_package_lookup(['NQPRegexMethod'], $/),
- $regex);
- $past<sink> := $regex;
+ QAST::Op.new( :op('captureouter'), $regex ));
+ $past<sink> := QAST::Op.new( :op('captureouter'), $regex );
}
make $past;
}
diff --git a/src/vm/jvm/QAST/Compiler.nqp b/src/vm/jvm/QAST/Compiler.nqp
index 52e1b21..286a7fa 100644
--- a/src/vm/jvm/QAST/Compiler.nqp
+++ b/src/vm/jvm/QAST/Compiler.nqp
@@ -2233,6 +2233,7 @@ QAST::OperationsJAST.map_classlib_core_op('getlexrelcaller', $TYPE_OPS, 'getlexr
# code object related opcodes
QAST::OperationsJAST.map_classlib_core_op('takeclosure', $TYPE_OPS, 'takeclosure', [$RT_OBJ], $RT_OBJ, :tc);
+QAST::OperationsJAST.map_classlib_core_op('captureouter', $TYPE_OPS, 'captureouter', [$RT_OBJ], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('getcodeobj', $TYPE_OPS, 'getcodeobj', [$RT_OBJ], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('setcodeobj', $TYPE_OPS, 'setcodeobj', [$RT_OBJ, $RT_OBJ], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('getcodename', $TYPE_OPS, 'getcodename', [$RT_OBJ], $RT_STR, :tc);
diff --git a/src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java b/src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java
index ef1b02e..227be3a 100644
--- a/src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java
+++ b/src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java
@@ -3286,6 +3286,15 @@ public final class Ops {
throw ExceptionHandling.dieInternal(tc, "takeclosure can only be used with a CodeRef");
}
}
+ public static SixModelObject captureouter(SixModelObject code, ThreadContext tc) {
+ if (code instanceof CodeRef) {
+ ((CodeRef)code).outer = tc.curFrame;
+ return code;
+ }
+ else {
+ throw ExceptionHandling.dieInternal(tc, "captureouter can only be used with a CodeRef");
+ }
+ }
public static SixModelObject getcodeobj(SixModelObject code, ThreadContext tc) {
if (code instanceof CodeRef)
return ((CodeRef)code).codeObject;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment