Skip to content

Commit

Permalink
Implement a bunch of missing conversion lookups
Browse files Browse the repository at this point in the history
  • Loading branch information
kustosz authored and ekmett committed Jan 14, 2022
1 parent 8cfa7b2 commit d48c8d5
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 13 deletions.
Expand Up @@ -11,7 +11,9 @@
import com.oracle.truffle.api.library.ExportMessage;
import org.enso.interpreter.Language;
import org.enso.interpreter.runtime.Context;
import org.enso.interpreter.runtime.callable.UnresolvedConversion;
import org.enso.interpreter.runtime.callable.UnresolvedSymbol;
import org.enso.interpreter.runtime.callable.atom.AtomConstructor;
import org.enso.interpreter.runtime.callable.function.Function;
import org.enso.interpreter.runtime.library.dispatch.MethodDispatchLibrary;

Expand Down Expand Up @@ -160,4 +162,54 @@ static Function resolve(
return function;
}
}

@ExportMessage
static boolean canConvertFrom(Array receiver) {
return true;
}

@ExportMessage
static class GetConversionFunction {
static final int CACHE_SIZE = 10;

@CompilerDirectives.TruffleBoundary
static Function doResolve(
Context context, AtomConstructor target, UnresolvedConversion conversion) {
return conversion.resolveFor(
target, context.getBuiltins().mutable().array(), context.getBuiltins().any());
}

@Specialization(
guards = {
"!context.isInlineCachingDisabled()",
"cachedConversion == conversion",
"cachedTarget == target",
"function != null"
},
limit = "CACHE_SIZE")
static Function resolveCached(
Array _this,
AtomConstructor target,
UnresolvedConversion conversion,
@CachedContext(Language.class) Context context,
@Cached("conversion") UnresolvedConversion cachedConversion,
@Cached("target") AtomConstructor cachedTarget,
@Cached("doResolve(context, cachedTarget, cachedConversion)") Function function) {
return function;
}

@Specialization(replaces = "resolveCached")
static Function resolve(
Array _this,
AtomConstructor target,
UnresolvedConversion conversion,
@CachedContext(Language.class) Context context)
throws MethodDispatchLibrary.NoSuchConversionException {
Function function = doResolve(context, target, conversion);
if (function == null) {
throw new MethodDispatchLibrary.NoSuchConversionException();
}
return function;
}
}
}
Expand Up @@ -12,7 +12,9 @@
import org.enso.interpreter.node.expression.builtin.text.util.ToJavaStringNode;
import org.enso.interpreter.runtime.Context;
import org.enso.interpreter.runtime.builtin.Number;
import org.enso.interpreter.runtime.callable.UnresolvedConversion;
import org.enso.interpreter.runtime.callable.UnresolvedSymbol;
import org.enso.interpreter.runtime.callable.atom.AtomConstructor;
import org.enso.interpreter.runtime.callable.function.Function;
import org.enso.interpreter.runtime.library.dispatch.MethodDispatchLibrary;

Expand Down Expand Up @@ -220,4 +222,60 @@ static Function resolve(
return function;
}
}

@ExportMessage
public static boolean canConvertFrom(Text receiver) {
return true;
}

@ExportMessage
public static boolean hasSpecialConversion(Text receiver) {
return false;
}

@ExportMessage
static class GetConversionFunction {

static final int CACHE_SIZE = 10;

@CompilerDirectives.TruffleBoundary
static Function doResolve(
Context context, AtomConstructor target, UnresolvedConversion conversion) {
return conversion.resolveFor(
target, context.getBuiltins().text().getText(), context.getBuiltins().any());
}

@Specialization(
guards = {
"!context.isInlineCachingDisabled()",
"cachedTarget == target",
"cachedConversion == conversion",
"function != null"
},
limit = "CACHE_SIZE")
static Function resolveCached(
Text _this,
AtomConstructor target,
UnresolvedConversion conversion,
@CachedContext(Language.class) Context context,
@Cached("target") AtomConstructor cachedTarget,
@Cached("conversion") UnresolvedConversion cachedConversion,
@Cached("doResolve(context, cachedTarget, cachedConversion)") Function function) {
return function;
}

@Specialization(replaces = "resolveCached")
static Function resolve(
Text _this,
AtomConstructor target,
UnresolvedConversion conversion,
@CachedContext(Language.class) Context context)
throws MethodDispatchLibrary.NoSuchConversionException {
Function function = doResolve(context, target, conversion);
if (function == null) {
throw new MethodDispatchLibrary.NoSuchConversionException();
}
return function;
}
}
}
Expand Up @@ -93,4 +93,9 @@ public String toDisplayString(
boolean hasSpecialDispatch() {
return true;
}

@ExportMessage
boolean hasSpecialConversion() {
return true;
}
}
Expand Up @@ -49,4 +49,9 @@ public String getMessage() {
boolean hasSpecialDispatch() {
return true;
}

@ExportMessage
boolean hasSpecialConversion() {
return true;
}
}
Expand Up @@ -9,9 +9,7 @@
import org.enso.interpreter.Language;
import org.enso.interpreter.runtime.Context;
import org.enso.interpreter.runtime.builtin.Bool;
import org.enso.interpreter.runtime.builtin.Number;
import org.enso.interpreter.runtime.callable.UnresolvedConversion;
import org.enso.interpreter.runtime.callable.UnresolvedConversionGen;
import org.enso.interpreter.runtime.callable.UnresolvedSymbol;
import org.enso.interpreter.runtime.callable.atom.AtomConstructor;
import org.enso.interpreter.runtime.callable.function.Function;
Expand Down Expand Up @@ -118,12 +116,12 @@ static Function resolve(
}

@ExportMessage
public static boolean canConvertFrom(Object receiver) {
public static boolean canConvertFrom(Boolean receiver) {
return true;
}

@ExportMessage
public static boolean hasSpecialConversion(Object receiver) {
public static boolean hasSpecialConversion(Boolean receiver) {
return false;
}

Expand Down Expand Up @@ -158,9 +156,10 @@ static Function resolveMethodOnBool(Context context, boolean self, AtomConstruct
limit = "CACHE_SIZE")
static Function resolveCached(
Boolean _this,
AtomConstructor target,
UnresolvedConversion conversion,
@CachedContext(Language.class) Context context,
@Cached("symbol") UnresolvedConversion cachedConversion,
@Cached("conversion") UnresolvedConversion cachedConversion,
@Cached("target") AtomConstructor cachedTarget,
@Cached("resolveMethodOnPrimBoolean(context, cachedTarget, cachedConversion)") Function function) {
return function;
Expand All @@ -181,7 +180,7 @@ static Function resolveTrueCached(
AtomConstructor target,
UnresolvedConversion conversion,
@CachedContext(Language.class) Context context,
@Cached("target") AtomConstructor cachedTaqrget,
@Cached("target") AtomConstructor cachedTarget,
@Cached("conversion") UnresolvedConversion cachedConversion,
@Cached("resolveMethodOnBool(context, _this, cachedTarget, cachedConversion)") Function function) {
return function;
Expand All @@ -201,7 +200,7 @@ static Function resolveFalseCached(
Boolean _this,
AtomConstructor target,
UnresolvedConversion conversion,
@Cached("symbol") UnresolvedConversion cachedConversion,
@Cached("conversion") UnresolvedConversion cachedConversion,
@Cached("target") AtomConstructor cachedTarget,
@CachedContext(Language.class) Context context,
@Cached("resolveMethodOnBool(context, _this, cachedTarget, cachedConversion)") Function function) {
Expand Down
Expand Up @@ -62,12 +62,12 @@ static Function resolve(
}

@ExportMessage
public static boolean canConvertFrom(Object receiver) {
public static boolean canConvertFrom(Double receiver) {
return true;
}

@ExportMessage
public static boolean hasSpecialConversion(Object receiver) {
public static boolean hasSpecialConversion(Double receiver) {
return false;
}

Expand Down
Expand Up @@ -64,12 +64,12 @@ static Function resolve(
}

@ExportMessage
public static boolean canConvertFrom(Object receiver) {
public static boolean canConvertFrom(Long receiver) {
return true;
}

@ExportMessage
public static boolean hasSpecialConversion(Object receiver) {
public static boolean hasSpecialConversion(Long receiver) {
return false;
}

Expand Down
Expand Up @@ -93,8 +93,9 @@ public boolean hasSpecialConversion(Object receiver) {
}

@GenerateLibrary.Abstract(ifExported = {"canConvertFrom"})
public Function getConversionFunction(Object receiver, AtomConstructor target, UnresolvedConversion symbol)
throws MethodDispatchLibrary.NoSuchConversionException {
public Function getConversionFunction(
Object receiver, AtomConstructor target, UnresolvedConversion symbol)
throws MethodDispatchLibrary.NoSuchConversionException {
throw new MethodDispatchLibrary.NoSuchConversionException();
}
}
Expand Up @@ -12,7 +12,9 @@
import org.enso.interpreter.Language;
import org.enso.interpreter.runtime.Context;
import org.enso.interpreter.runtime.builtin.Number;
import org.enso.interpreter.runtime.callable.UnresolvedConversion;
import org.enso.interpreter.runtime.callable.UnresolvedSymbol;
import org.enso.interpreter.runtime.callable.atom.AtomConstructor;
import org.enso.interpreter.runtime.callable.function.Function;
import org.enso.interpreter.runtime.library.dispatch.MethodDispatchLibrary;

Expand Down Expand Up @@ -98,4 +100,60 @@ static Function resolve(
return function;
}
}

@ExportMessage
public static boolean canConvertFrom(EnsoBigInteger receiver) {
return true;
}

@ExportMessage
static class GetConversionFunction {

static final int CACHE_SIZE = 10;

@CompilerDirectives.TruffleBoundary
static Function doResolve(
Context context, AtomConstructor target, UnresolvedConversion conversion) {
Number number = context.getBuiltins().number();
return conversion.resolveFor(
target,
number.getBigInteger(),
number.getInteger(),
number.getNumber(),
context.getBuiltins().any());
}

@Specialization(
guards = {
"!context.isInlineCachingDisabled()",
"cachedTarget == target",
"cachedConversion == conversion",
"function != null"
},
limit = "CACHE_SIZE")
static Function resolveCached(
EnsoBigInteger _this,
AtomConstructor target,
UnresolvedConversion conversion,
@CachedContext(Language.class) Context context,
@Cached("conversion") UnresolvedConversion cachedConversion,
@Cached("target") AtomConstructor cachedTarget,
@Cached("doResolve(context, cachedTarget, cachedConversion)") Function function) {
return function;
}

@Specialization(replaces = "resolveCached")
static Function resolve(
EnsoBigInteger _this,
AtomConstructor target,
UnresolvedConversion conversion,
@CachedContext(Language.class) Context context)
throws MethodDispatchLibrary.NoSuchConversionException {
Function function = doResolve(context, target, conversion);
if (function == null) {
throw new MethodDispatchLibrary.NoSuchConversionException();
}
return function;
}
}
}

0 comments on commit d48c8d5

Please sign in to comment.