Skip to content

Commit

Permalink
"fixes"
Browse files Browse the repository at this point in the history
  • Loading branch information
radeusgd committed Apr 6, 2023
1 parent c3ded1f commit fddb05c
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 34 deletions.
2 changes: 2 additions & 0 deletions distribution/lib/Standard/Base/0.0.0-dev/src/IO.enso
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import project.Any.Any
import project.Data.Text.Text
import project.Nothing.Nothing

from project.Data.Boolean import Boolean, False

## PRIVATE
ADVANCED
Prints the provided message to standard error.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.oracle.truffle.api.library.CachedLibrary;
import com.oracle.truffle.api.nodes.Node;
import org.enso.interpreter.dsl.AcceptsError;
import org.enso.interpreter.dsl.AcceptsWarning;
import org.enso.interpreter.dsl.BuiltinMethod;
import org.enso.interpreter.node.callable.InvokeCallableNode;
import org.enso.interpreter.runtime.EnsoContext;
Expand All @@ -31,7 +32,7 @@ public abstract class PrintlnNode extends Node {
InvokeCallableNode.DefaultsExecutionMode.EXECUTE,
InvokeCallableNode.ArgumentsExecutionMode.PRE_EXECUTED);

abstract Object execute(VirtualFrame frame, State state, @AcceptsError Object message);
abstract Object execute(VirtualFrame frame, State state, @AcceptsWarning @AcceptsError Object message, boolean warnings);

@Specialization(guards = {"strings.isString(message)", "!hasWarningsToPrint(warningsLibrary, warnings, message)"})
Object doPrintText(
Expand Down Expand Up @@ -105,7 +106,7 @@ Object doPrintWithWarnings(
return ctx.getNothing();
}

private static boolean hasWarningsToPrint(WarningsLibrary warningsLibrary, boolean shouldPrintWarnings, Object obj) {
static boolean hasWarningsToPrint(WarningsLibrary warningsLibrary, boolean shouldPrintWarnings, Object obj) {
return shouldPrintWarnings && warningsLibrary.hasWarnings(obj);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,17 +322,13 @@ boolean equalsWithWarnings(Object selfWithWarnings, Object otherWithWarnings,
@CachedLibrary("otherWithWarnings") WarningsLibrary otherWarnLib,
@Cached EqualsNode equalsNode
) {
try {
Object self =
Object self =
selfWarnLib.hasWarnings(selfWithWarnings) ? selfWarnLib.removeWarnings(selfWithWarnings)
: selfWithWarnings;
Object other =
Object other =
otherWarnLib.hasWarnings(otherWithWarnings) ? otherWarnLib.removeWarnings(otherWithWarnings)
: otherWithWarnings;
return equalsNode.execute(self, other);
} catch (UnsupportedMessageException e) {
throw new IllegalStateException(e);
}
return equalsNode.execute(self, other);
}

/** Interop libraries **/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,7 @@ long hashCodeForWarning(
Object selfWithWarning,
@CachedLibrary("selfWithWarning") WarningsLibrary warnLib,
@Cached HashCodeNode hashCodeNode) {
try {
return hashCodeNode.execute(warnLib.removeWarnings(selfWithWarning));
} catch (UnsupportedMessageException e) {
throw new IllegalStateException(e);
}
return hashCodeNode.execute(warnLib.removeWarnings(selfWithWarning));
}

/** Specializations for interop values * */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,13 @@ Object lessWithWarnings(Object selfWithWarnings, Object otherWithWarnings,
@CachedLibrary("otherWithWarnings") WarningsLibrary otherWarnLib,
@Cached LessThanNode lessThanNode
) {
try {
Object self =
Object self =
selfWarnLib.hasWarnings(selfWithWarnings) ? selfWarnLib.removeWarnings(selfWithWarnings)
: selfWithWarnings;
Object other =
Object other =
otherWarnLib.hasWarnings(otherWithWarnings) ? otherWarnLib.removeWarnings(otherWithWarnings)
: otherWithWarnings;
return lessThanNode.execute(self, other);
} catch (UnsupportedMessageException e) {
throw new IllegalStateException(e);
}
return lessThanNode.execute(self, other);
}

@Specialization(limit = "3")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ String doString(String str) {

@Specialization(guards = "warnings.hasWarnings(warning)")
String doWarning(Object warning, @CachedLibrary(limit = "3") WarningsLibrary warnings) {
try {
return execute(warnings.removeWarnings(warning));
} catch (UnsupportedMessageException e) {
throw new IllegalStateException(e);
}
return execute(warnings.removeWarnings(warning));
}

@Fallback
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,15 @@ boolean hasWarnings(@CachedLibrary(limit = "3") WarningsLibrary warnings) {
return withWarnings;
}

@ExportMessage
long countWarnings(@CachedLibrary(limit = "3") WarningsLibrary warnings) {
long count = 0;
for (Object item : items) {
count += warnings.countWarnings(item);
}
return count;
}

@ExportMessage
Warning[] getWarnings(Node location, @CachedLibrary(limit = "3") WarningsLibrary warnings)
throws UnsupportedMessageException {
Expand All @@ -210,8 +219,7 @@ Warning[] getWarnings(Node location, @CachedLibrary(limit = "3") WarningsLibrary
}

@ExportMessage
Array removeWarnings(@CachedLibrary(limit = "3") WarningsLibrary warnings)
throws UnsupportedMessageException {
Array removeWarnings(@CachedLibrary(limit = "3") WarningsLibrary warnings) {
Object[] items = new Object[this.items.length];
for (int i = 0; i < this.items.length; i++) {
if (warnings.hasWarnings(this.items[i])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,18 @@ boolean hasWarnings(@CachedLibrary(limit = "3") WarningsLibrary warnings) {
return warnings.hasWarnings(this.storage);
}

@ExportMessage
long countWarnings(@CachedLibrary(limit = "3") WarningsLibrary warnings) {
return warnings.countWarnings(this.storage);
}

@ExportMessage
Warning[] getWarnings(Node location, @CachedLibrary(limit = "3") WarningsLibrary warnings) throws UnsupportedMessageException {
return warnings.getWarnings(this.storage, location);
}

@ExportMessage
Object removeWarnings(@CachedLibrary(limit = "3") WarningsLibrary warnings) throws UnsupportedMessageException {
Object removeWarnings(@CachedLibrary(limit = "3") WarningsLibrary warnings) {
Object newStorage = warnings.removeWarnings(this.storage);
return new ArraySlice(newStorage, start, end);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,19 @@ boolean hasWarnings(@CachedLibrary(limit = "3") WarningsLibrary warnings) {
return warnings.hasWarnings(this.storage);
}

@ExportMessage
long countWarnings(@CachedLibrary(limit = "3") WarningsLibrary warnings) {
return warnings.countWarnings(this.storage);
}

@ExportMessage
Warning[] getWarnings(Node location, @CachedLibrary(limit = "3") WarningsLibrary warnings)
throws UnsupportedMessageException {
return warnings.getWarnings(this.storage, location);
}

@ExportMessage
Vector removeWarnings(@CachedLibrary(limit = "3") WarningsLibrary warnings)
throws UnsupportedMessageException {
Vector removeWarnings(@CachedLibrary(limit = "3") WarningsLibrary warnings) {
return new Vector(warnings.removeWarnings(this.storage));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ boolean hasWarnings() {

@ExportMessage
long countWarnings() {
return warnings.size();
return (long) warnings.size();
}

@ExportMessage
Expand All @@ -127,8 +127,7 @@ Warning[] getWarnings(
}

@ExportMessage
Object removeWarnings(@CachedLibrary(limit = "3") WarningsLibrary warnings)
throws UnsupportedMessageException {
Object removeWarnings(@CachedLibrary(limit = "3") WarningsLibrary warnings) {
if (warnings.hasWarnings(value)) {
return warnings.removeWarnings(value);
} else {
Expand Down

0 comments on commit fddb05c

Please sign in to comment.