-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Towards a full-blown builtins DSL (part 3)
WIP Partially auto-generated, partially manually written builtins nodes for File. The next step is to auto-generate builtins craft using enhanced annotation processor.
- Loading branch information
Showing
26 changed files
with
545 additions
and
100 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
50 changes: 50 additions & 0 deletions
50
.../runtime/src/main/java/org/enso/interpreter/node/controlflow/caseexpr/FileBranchNode.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,50 @@ | ||
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.callable.atom.Atom; | ||
import org.enso.interpreter.runtime.callable.atom.AtomConstructor; | ||
import org.enso.interpreter.runtime.data.EnsoFile; | ||
|
||
@NodeInfo(shortName = "FileMatch", description = "Allows matching on the File type.") | ||
public abstract class FileBranchNode extends BranchNode { | ||
private final AtomConstructor file; | ||
private final ConditionProfile profile = ConditionProfile.createCountingProfile(); | ||
|
||
FileBranchNode(AtomConstructor file, RootCallTarget branch) { | ||
super(branch); | ||
this.file = file; | ||
} | ||
|
||
/** | ||
* Create a new node to handle matching with the File constructor. | ||
* | ||
* @param file the constructor used for matching in this case | ||
* @param branch the code to execute in this case | ||
* @return a file branch node | ||
*/ | ||
public static FileBranchNode build(AtomConstructor file, RootCallTarget branch) { | ||
return FileBranchNodeGen.create(file, branch); | ||
} | ||
|
||
@Specialization | ||
void doConstructor(VirtualFrame frame, Object state, Atom target) { | ||
if (profile.profile(file == target.getConstructor())) { | ||
accept(frame, state, target.getFields()); | ||
} | ||
} | ||
|
||
@Specialization | ||
void doFile(VirtualFrame frame, Object state, EnsoFile target) { | ||
accept(frame, state, new Object[0]); | ||
} | ||
|
||
@Fallback | ||
void doFallback(VirtualFrame frame, Object state, Object target) {} | ||
} |
Oops, something went wrong.