-
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.
Fixing #5768 and #5765 and co. Introducing `Meta.Type` and giving it the desired methods. # Important Notes `Type` is no longer a `Meta.Atom`, but it has a dedicated `Meta.Type` representation.
- Loading branch information
1 parent
75fda33
commit b46be10
Showing
8 changed files
with
217 additions
and
18 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
54 changes: 54 additions & 0 deletions
54
.../main/java/org/enso/interpreter/node/expression/builtin/meta/GetTypeConstructorsNode.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.CompilerDirectives; | ||
import com.oracle.truffle.api.dsl.Fallback; | ||
import com.oracle.truffle.api.dsl.Specialization; | ||
import com.oracle.truffle.api.nodes.Node; | ||
import org.enso.interpreter.dsl.BuiltinMethod; | ||
import org.enso.interpreter.runtime.EnsoContext; | ||
import org.enso.interpreter.runtime.callable.atom.Atom; | ||
import org.enso.interpreter.runtime.callable.atom.AtomConstructor; | ||
import org.enso.interpreter.runtime.data.Array; | ||
import org.enso.interpreter.runtime.data.Type; | ||
import org.enso.interpreter.runtime.error.PanicException; | ||
import org.enso.interpreter.runtime.type.TypesGen; | ||
|
||
@BuiltinMethod( | ||
type = "Meta", | ||
name = "get_type_constructors", | ||
description = "Gets the constructors of a type.", | ||
autoRegister = false) | ||
public abstract class GetTypeConstructorsNode extends Node { | ||
static GetTypeConstructorsNode build() { | ||
return GetTypeConstructorsNodeGen.create(); | ||
} | ||
|
||
abstract Array execute(Object type, Object factory); | ||
|
||
@Specialization | ||
@CompilerDirectives.TruffleBoundary | ||
Array allConstructors(Type type, AtomConstructor factory) { | ||
var rawConstructors = type.getConstructors().values(); | ||
var rawResult = new Object[rawConstructors.size()]; | ||
int at = 0; | ||
for (var cons : rawConstructors) { | ||
var metaCons = factory.newInstance(cons); | ||
rawResult[at++] = metaCons; | ||
} | ||
return new Array(rawResult); | ||
} | ||
|
||
@Fallback | ||
@CompilerDirectives.TruffleBoundary | ||
Array empty(Object type, Object factory) { | ||
var ctx = EnsoContext.get(this); | ||
var builtins = ctx.getBuiltins(); | ||
Atom payload; | ||
if (TypesGen.isType(type)) { | ||
payload = builtins.error().makeTypeError("AtomConstructor", factory, "factory"); | ||
} else { | ||
payload = builtins.error().makeTypeError("Type", type, "type"); | ||
} | ||
throw new PanicException(payload, this); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...e/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetTypeMethodsNode.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,41 @@ | ||
package org.enso.interpreter.node.expression.builtin.meta; | ||
|
||
import com.oracle.truffle.api.CompilerDirectives; | ||
import com.oracle.truffle.api.dsl.Fallback; | ||
import com.oracle.truffle.api.dsl.Specialization; | ||
import com.oracle.truffle.api.nodes.Node; | ||
import org.enso.interpreter.dsl.BuiltinMethod; | ||
import org.enso.interpreter.runtime.EnsoContext; | ||
import org.enso.interpreter.runtime.callable.atom.Atom; | ||
import org.enso.interpreter.runtime.data.Array; | ||
import org.enso.interpreter.runtime.data.Type; | ||
import org.enso.interpreter.runtime.error.PanicException; | ||
|
||
@BuiltinMethod( | ||
type = "Meta", | ||
name = "get_type_methods", | ||
description = "Gets the method names of a type.", | ||
autoRegister = false) | ||
public abstract class GetTypeMethodsNode extends Node { | ||
static GetTypeMethodsNode build() { | ||
return GetTypeMethodsNodeGen.create(); | ||
} | ||
|
||
abstract Array execute(Object type); | ||
|
||
@Specialization | ||
@CompilerDirectives.TruffleBoundary | ||
Array allMethods(Type type) { | ||
var methodNames = type.getDefinitionScope().getMethods().get(type).keySet(); | ||
return new Array(methodNames.toArray()); | ||
} | ||
|
||
@Fallback | ||
@CompilerDirectives.TruffleBoundary | ||
Array empty(Object type) { | ||
var ctx = EnsoContext.get(this); | ||
var builtins = ctx.getBuiltins(); | ||
Atom payload = builtins.error().makeTypeError("Type", type, "type"); | ||
throw new PanicException(payload, this); | ||
} | ||
} |
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
17 changes: 17 additions & 0 deletions
17
...e/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/IsTypeNode.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,17 @@ | ||
package org.enso.interpreter.node.expression.builtin.meta; | ||
|
||
import com.oracle.truffle.api.nodes.Node; | ||
import org.enso.interpreter.dsl.AcceptsError; | ||
import org.enso.interpreter.dsl.BuiltinMethod; | ||
import org.enso.interpreter.runtime.data.Type; | ||
|
||
@BuiltinMethod( | ||
type = "Meta", | ||
name = "is_type", | ||
description = "Checks if the argument is a type", | ||
autoRegister = false) | ||
public class IsTypeNode extends Node { | ||
boolean execute(@AcceptsError Object value) { | ||
return value instanceof Type; | ||
} | ||
} |
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