-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Type.Atom... yields Meta.AtomConstructor
- Loading branch information
1 parent
30e5005
commit d426ab3
Showing
11 changed files
with
102 additions
and
33 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
54 changes: 54 additions & 0 deletions
54
.../main/java/org/enso/interpreter/node/expression/builtin/meta/FindAtomConstructorNode.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,54 @@ | ||
package org.enso.interpreter.node.expression.builtin.meta; | ||
|
||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.nodes.Node; | ||
import org.enso.interpreter.dsl.AcceptsError; | ||
import org.enso.interpreter.dsl.BuiltinMethod; | ||
import org.enso.interpreter.dsl.Suspend; | ||
import org.enso.interpreter.node.BaseNode; | ||
import org.enso.interpreter.node.MethodRootNode; | ||
import org.enso.interpreter.node.callable.thunk.ThunkExecutorNode; | ||
import org.enso.interpreter.runtime.EnsoContext; | ||
import org.enso.interpreter.runtime.callable.function.Function; | ||
import org.enso.interpreter.runtime.data.EnsoObject; | ||
import org.enso.interpreter.runtime.data.atom.AtomConstructor; | ||
import org.enso.interpreter.runtime.state.State; | ||
|
||
@BuiltinMethod( | ||
type = "Meta", | ||
name = "find_atom_constructor", | ||
description = "Checks if the argument is a constructor.", | ||
autoRegister = false) | ||
final class FindAtomConstructorNode extends Node { | ||
EnsoObject execute(VirtualFrame frame, @Suspend @AcceptsError Object value, State state) { | ||
var ac = findConstructor(value, frame, state); | ||
if (ac != null) { | ||
return ac; | ||
} else { | ||
var ctx = EnsoContext.get(this); | ||
return ctx.getNothing(); | ||
} | ||
} | ||
|
||
static AtomConstructor findConstructor(Object value, VirtualFrame frame, State state) { | ||
for (; ; ) { | ||
if (value instanceof AtomConstructor atom) { | ||
return atom; | ||
} | ||
if (value instanceof Function fn) { | ||
if (AtomConstructor.accessorFor(fn) instanceof AtomConstructor atom) { | ||
return atom; | ||
} | ||
if (MethodRootNode.constructorFor(fn) instanceof AtomConstructor atom) { | ||
return atom; | ||
} | ||
if (fn.isThunk()) { | ||
var thunkSolver = ThunkExecutorNode.getUncached(); | ||
value = thunkSolver.executeThunk(frame, value, state, BaseNode.TailStatus.NOT_TAIL); | ||
continue; | ||
} | ||
} | ||
return null; | ||
} | ||
} | ||
} |
17 changes: 0 additions & 17 deletions
17
...rc/main/java/org/enso/interpreter/node/expression/builtin/meta/IsAtomConstructorNode.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
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