-
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.
Change hierarchy of objects to unify JavaScriptObject and ClassProtot…
…ypeObject.
- Loading branch information
Showing
11 changed files
with
107 additions
and
143 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
34 changes: 0 additions & 34 deletions
34
...src/main/java/com/endoflineblog/truffle/part_13/runtime/AbstractClassPrototypeObject.java
This file was deleted.
Oops, something went wrong.
38 changes: 19 additions & 19 deletions
38
part-14/src/main/java/com/endoflineblog/truffle/part_13/runtime/ClassPrototypeObject.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 |
---|---|---|
@@ -1,34 +1,34 @@ | ||
package com.endoflineblog.truffle.part_13.runtime; | ||
|
||
import com.oracle.truffle.api.interop.InteropLibrary; | ||
import com.oracle.truffle.api.interop.UnknownIdentifierException; | ||
import com.oracle.truffle.api.interop.UnsupportedMessageException; | ||
import com.oracle.truffle.api.library.CachedLibrary; | ||
import com.oracle.truffle.api.library.ExportLibrary; | ||
import com.oracle.truffle.api.library.ExportMessage; | ||
import com.oracle.truffle.api.object.DynamicObjectLibrary; | ||
import com.oracle.truffle.api.object.DynamicObject; | ||
import com.oracle.truffle.api.object.Shape; | ||
|
||
/** | ||
* A {@link DynamicObject} that represents the prototype of class. | ||
* That can be a user-defined class, or a built-in class, | ||
* like for functions, or arrays. | ||
* Identical to the class with the same name from part 12. | ||
*/ | ||
@ExportLibrary(InteropLibrary.class) | ||
public final class ClassPrototypeObject extends AbstractClassPrototypeObject { | ||
public final AbstractClassPrototypeObject superClassPrototype; | ||
public class ClassPrototypeObject extends JavaScriptObject { | ||
public final String className; | ||
|
||
public ClassPrototypeObject(Shape shape, String className, | ||
AbstractClassPrototypeObject superClassPrototype) { | ||
super(shape, className); | ||
public ClassPrototypeObject(Shape shape, String className, DynamicObject prototype) { | ||
super(shape, prototype); | ||
|
||
this.superClassPrototype = superClassPrototype; | ||
this.className = className; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[class " + this.className + "]"; | ||
} | ||
|
||
@ExportMessage | ||
Object readMember(String member, | ||
@CachedLibrary("this") DynamicObjectLibrary instanceObjectLibrary, | ||
@CachedLibrary("this.superClassPrototype") InteropLibrary superClassInteropLibrary) | ||
throws UnknownIdentifierException, UnsupportedMessageException { | ||
Object value = instanceObjectLibrary.getOrDefault(this, member, null); | ||
if (value == null) { | ||
return superClassInteropLibrary.readMember(this.superClassPrototype, member); | ||
} | ||
return value; | ||
Object toDisplayString(@SuppressWarnings("unused") boolean allowSideEffects) { | ||
return this.toString(); | ||
} | ||
} |
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
63 changes: 0 additions & 63 deletions
63
part-14/src/main/java/com/endoflineblog/truffle/part_13/runtime/InteropDynamicObject.java
This file was deleted.
Oops, something went wrong.
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
39 changes: 37 additions & 2 deletions
39
part-14/src/main/java/com/endoflineblog/truffle/part_13/runtime/ObjectPrototype.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 |
---|---|---|
@@ -1,12 +1,47 @@ | ||
package com.endoflineblog.truffle.part_13.runtime; | ||
|
||
import com.oracle.truffle.api.interop.InteropLibrary; | ||
import com.oracle.truffle.api.interop.UnknownIdentifierException; | ||
import com.oracle.truffle.api.interop.UnsupportedMessageException; | ||
import com.oracle.truffle.api.library.CachedLibrary; | ||
import com.oracle.truffle.api.library.ExportLibrary; | ||
import com.oracle.truffle.api.library.ExportMessage; | ||
import com.oracle.truffle.api.object.DynamicObject; | ||
import com.oracle.truffle.api.object.DynamicObjectLibrary; | ||
import com.oracle.truffle.api.object.Shape; | ||
|
||
@ExportLibrary(InteropLibrary.class) | ||
public final class ObjectPrototype extends AbstractClassPrototypeObject { | ||
public final class ObjectPrototype extends ClassPrototypeObject { | ||
public ObjectPrototype(Shape shape) { | ||
super(shape, "Object"); | ||
super(shape, "Object", new DynamicObject(shape) {}); | ||
} | ||
|
||
@ExportMessage | ||
boolean isMemberReadable(String member, | ||
@CachedLibrary("this") DynamicObjectLibrary instanceObjectLibrary) { | ||
return instanceObjectLibrary.containsKey(this, member); | ||
} | ||
|
||
@ExportMessage | ||
Object readMember(String member, | ||
@CachedLibrary("this") DynamicObjectLibrary instanceObjectLibrary) | ||
throws UnknownIdentifierException, UnsupportedMessageException { | ||
Object value = instanceObjectLibrary.getOrDefault(this, member, null); | ||
if (value == null) { | ||
throw UnknownIdentifierException.create(member); | ||
} | ||
return value; | ||
} | ||
|
||
@ExportMessage | ||
boolean isMemberModifiable(String member, | ||
@CachedLibrary("this") DynamicObjectLibrary instanceObjectLibrary) { | ||
return this.isMemberReadable(member, instanceObjectLibrary); | ||
} | ||
|
||
@ExportMessage | ||
boolean isMemberInsertable(String member, | ||
@CachedLibrary("this") DynamicObjectLibrary instanceObjectLibrary) { | ||
return !this.isMemberModifiable(member, instanceObjectLibrary); | ||
} | ||
} |
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