-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow 'super' in property accesses (both direct, and indexed).
- Loading branch information
Showing
10 changed files
with
126 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...14/src/main/java/com/endoflineblog/truffle/part_13/nodes/exprs/objects/SuperExprNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.endoflineblog.truffle.part_13.nodes.exprs.objects; | ||
|
||
import com.endoflineblog.truffle.part_13.exceptions.EasyScriptException; | ||
import com.endoflineblog.truffle.part_13.nodes.exprs.EasyScriptExprNode; | ||
import com.endoflineblog.truffle.part_13.runtime.ClassPrototypeChainObject; | ||
import com.endoflineblog.truffle.part_13.runtime.ClassPrototypeObject; | ||
import com.endoflineblog.truffle.part_13.runtime.JavaScriptObject; | ||
import com.oracle.truffle.api.dsl.Specialization; | ||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.nodes.Node; | ||
|
||
/** | ||
* The Node implementing the 'super' expression. | ||
*/ | ||
public final class SuperExprNode extends EasyScriptExprNode { | ||
static abstract class ReadParentPrototypeNode extends Node { | ||
abstract Object executeReadParentPrototype(Object object); | ||
|
||
@Specialization | ||
protected Object parentPrototypeOfJavaScriptObject(JavaScriptObject javaScriptObject) { | ||
ClassPrototypeObject classPrototypeObject = javaScriptObject.classPrototypeObject; | ||
if (classPrototypeObject instanceof ClassPrototypeChainObject) { | ||
return ((ClassPrototypeChainObject) classPrototypeObject).superClassPrototype; | ||
} else { | ||
throw new EasyScriptException("Class '" + classPrototypeObject.className + | ||
"' does not have a superclass that can be accessed with 'super'"); | ||
} | ||
} | ||
|
||
@Specialization | ||
protected void parentPrototypeOfNonJavaScriptObject(Object object) { | ||
throw new EasyScriptException("Cannot access prototype with 'super' of: " + object); | ||
} | ||
} | ||
|
||
@SuppressWarnings("FieldMayBeFinal") | ||
@Child | ||
private ThisExprNode thisExprNode = new ThisExprNode(); | ||
|
||
@SuppressWarnings("FieldMayBeFinal") | ||
@Child | ||
private ReadParentPrototypeNode readParentPrototypeNode = SuperExprNodeFactory.ReadParentPrototypeNodeGen.create(); | ||
|
||
@Override | ||
public Object executeGeneric(VirtualFrame frame) { | ||
// executeGeneric() simply returns 'this' | ||
// (that will be the method that property access Nodes use to establish the method call receiver, | ||
// in their evaluateAsReceiver() methods) | ||
return this.thisExprNode.executeGeneric(frame); | ||
} | ||
|
||
public Object readParentPrototype(Object thisValue) { | ||
// this method is called from the property access Nodes | ||
// to find the parent prototype | ||
return this.readParentPrototypeNode.executeReadParentPrototype(thisValue); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters