-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This change implements a simple `type_of` method that returns a type of a given value, including for polyglot objects. The change also allows for pattern matching on various time-related instances. It is a nice-to-have on its own, but it was primarily needed here to write some tests. For equality checks on types we currently can't use `==` due to a known _feature_ which essentially does wrong dispatching. This will be improved in the upcoming statics PR so we agreed that there is no point in duplicating that work and we can replace it later. Also, note that this PR changes `Meta.is_same_object`. Comparing types revealed that it was wrong when comparing polyglot wrappers over the same value.
- Loading branch information
Showing
24 changed files
with
617 additions
and
53 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
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
59 changes: 59 additions & 0 deletions
59
.../runtime/src/main/java/org/enso/interpreter/node/controlflow/caseexpr/DateBranchNode.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,59 @@ | ||
package org.enso.interpreter.node.controlflow.caseexpr; | ||
|
||
import com.oracle.truffle.api.RootCallTarget; | ||
import com.oracle.truffle.api.dsl.Fallback; | ||
import com.oracle.truffle.api.dsl.Specialization; | ||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.interop.InteropLibrary; | ||
import com.oracle.truffle.api.library.CachedLibrary; | ||
import com.oracle.truffle.api.nodes.NodeInfo; | ||
import com.oracle.truffle.api.profiles.ConditionProfile; | ||
import org.enso.interpreter.runtime.data.Type; | ||
import org.enso.interpreter.runtime.data.EnsoDate; | ||
|
||
/** An implementation of the case expression specialised to working on Date. */ | ||
@NodeInfo(shortName = "DateMatch") | ||
public abstract class DateBranchNode extends BranchNode { | ||
private final Type date; | ||
private final ConditionProfile profile = ConditionProfile.createCountingProfile(); | ||
|
||
DateBranchNode(Type vector, RootCallTarget branch) { | ||
super(branch); | ||
this.date = vector; | ||
} | ||
|
||
/** | ||
* Creates a new node for handling matching on a case expression. | ||
* | ||
* @param date the expression to use for matching | ||
* @param branch the expression to be executed if (@code matcher} matches | ||
* @return a node for matching in a case expression | ||
*/ | ||
public static DateBranchNode build(Type date, RootCallTarget branch) { | ||
return DateBranchNodeGen.create(date, branch); | ||
} | ||
|
||
@Specialization | ||
void doType(VirtualFrame frame, Object state, Type target) { | ||
if (profile.profile(date == target)) { | ||
accept(frame, state, new Object[0]); | ||
} | ||
} | ||
|
||
@Specialization | ||
void doEnsoDate(VirtualFrame frame, Object state, EnsoDate date) { | ||
accept(frame, state, new Object[0]); | ||
} | ||
|
||
@Specialization(guards = {"interop.isDate(date)", "!interop.isTime(date)"}) | ||
void doDate( | ||
VirtualFrame frame, | ||
Object state, | ||
Object date, | ||
@CachedLibrary(limit = "10") InteropLibrary interop) { | ||
accept(frame, state, new Object[0]); | ||
} | ||
|
||
@Fallback | ||
void doFallback(VirtualFrame frame, Object state, Object target) {} | ||
} |
63 changes: 63 additions & 0 deletions
63
...time/src/main/java/org/enso/interpreter/node/controlflow/caseexpr/DateTimeBranchNode.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,63 @@ | ||
package org.enso.interpreter.node.controlflow.caseexpr; | ||
|
||
import com.oracle.truffle.api.RootCallTarget; | ||
import com.oracle.truffle.api.dsl.Fallback; | ||
import com.oracle.truffle.api.dsl.Specialization; | ||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.interop.InteropLibrary; | ||
import com.oracle.truffle.api.library.CachedLibrary; | ||
import com.oracle.truffle.api.nodes.NodeInfo; | ||
import com.oracle.truffle.api.profiles.ConditionProfile; | ||
import org.enso.interpreter.runtime.data.EnsoDateTime; | ||
import org.enso.interpreter.runtime.data.Type; | ||
|
||
/** An implementation of the case expression specialised to working on Date_Time. */ | ||
@NodeInfo(shortName = "DateTimeMatch") | ||
public abstract class DateTimeBranchNode extends BranchNode { | ||
private final Type dateTime; | ||
private final ConditionProfile profile = ConditionProfile.createCountingProfile(); | ||
|
||
DateTimeBranchNode(Type vector, RootCallTarget branch) { | ||
super(branch); | ||
this.dateTime = vector; | ||
} | ||
|
||
/** | ||
* Creates a new node for handling matching on a case expression. | ||
* | ||
* @param dateTime the expression to use for matching | ||
* @param branch the expression to be executed if (@code matcher} matches | ||
* @return a node for matching in a case expression | ||
*/ | ||
public static DateTimeBranchNode build(Type dateTime, RootCallTarget branch) { | ||
return DateTimeBranchNodeGen.create(dateTime, branch); | ||
} | ||
|
||
@Specialization | ||
void doType(VirtualFrame frame, Object state, Type target) { | ||
if (profile.profile(dateTime == target)) { | ||
accept(frame, state, new Object[0]); | ||
} | ||
} | ||
|
||
@Specialization | ||
void doEnsoDateTime(VirtualFrame frame, Object state, EnsoDateTime dateTime) { | ||
accept(frame, state, new Object[0]); | ||
} | ||
|
||
@Specialization( | ||
guards = { | ||
"interop.isDate(dateTime)", | ||
"interop.isTime(dateTime)", | ||
}) | ||
void doDateTime( | ||
VirtualFrame frame, | ||
Object state, | ||
Object dateTime, | ||
@CachedLibrary(limit = "10") InteropLibrary interop) { | ||
accept(frame, state, new Object[0]); | ||
} | ||
|
||
@Fallback | ||
void doFallback(VirtualFrame frame, Object state, Object target) {} | ||
} |
Oops, something went wrong.