-
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.
All Vector operations shall be applicable on java.util.ArrayList (#6642)
Fixes #6609 by - e380e64 - running whole `Vector_Spec` on `java.util.ArrayList` - 9b1229f - introducing a node to handle interop values # Important Notes Contains additional DSL processor fix: - 415623d - to not crash the compiler, but to properly report compiler error
- Loading branch information
1 parent
866501f
commit 1302b69
Showing
7 changed files
with
144 additions
and
48 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
60 changes: 60 additions & 0 deletions
60
...ain/java/org/enso/interpreter/node/expression/builtin/immutable/SliceArrayVectorNode.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,60 @@ | ||
package org.enso.interpreter.node.expression.builtin.immutable; | ||
|
||
import org.enso.interpreter.dsl.BuiltinMethod; | ||
import org.enso.interpreter.runtime.EnsoContext; | ||
import org.enso.interpreter.runtime.data.Array; | ||
import org.enso.interpreter.runtime.data.Vector; | ||
import org.enso.interpreter.runtime.error.PanicException; | ||
|
||
import com.oracle.truffle.api.CompilerDirectives; | ||
import com.oracle.truffle.api.dsl.Specialization; | ||
import com.oracle.truffle.api.interop.InteropLibrary; | ||
import com.oracle.truffle.api.interop.UnsupportedMessageException; | ||
import com.oracle.truffle.api.library.CachedLibrary; | ||
import com.oracle.truffle.api.nodes.Node; | ||
|
||
@BuiltinMethod(type = "Vector", name = "slice", description = "Returns a slice of this Vector.") | ||
public abstract class SliceArrayVectorNode extends Node { | ||
SliceArrayVectorNode() {} | ||
|
||
public static SliceArrayVectorNode build() { | ||
return SliceArrayVectorNodeGen.create(); | ||
} | ||
|
||
abstract Object execute(Object self, long start, long end); | ||
|
||
@Specialization | ||
Object executeArray(Array self, long start, long end) { | ||
return Array.slice(self, start, end, self.length()); | ||
} | ||
|
||
@Specialization | ||
Object executeVector( | ||
Vector self, long start, long end, @CachedLibrary(limit = "3") InteropLibrary iop) { | ||
try { | ||
return Array.slice(self, start, end, self.length(iop)); | ||
} catch (UnsupportedMessageException ex) { | ||
CompilerDirectives.transferToInterpreter(); | ||
throw unsupportedMessageException(self); | ||
} | ||
} | ||
|
||
@Specialization(replaces = {"executeArray", "executeVector"}) | ||
Object executeArrayLike( | ||
Object self, long start, long end, @CachedLibrary(limit = "3") InteropLibrary iop) { | ||
try { | ||
long len = iop.getArraySize(self); | ||
return Array.slice(self, start, end, len); | ||
} catch (UnsupportedMessageException ex) { | ||
CompilerDirectives.transferToInterpreter(); | ||
throw unsupportedMessageException(self); | ||
} | ||
} | ||
|
||
private PanicException unsupportedMessageException(Object self) throws PanicException { | ||
var ctx = EnsoContext.get(this); | ||
var arrayType = ctx.getBuiltins().array(); | ||
throw new PanicException( | ||
ctx.getBuiltins().error().makeTypeError(arrayType, self, "self"), 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
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