-
Notifications
You must be signed in to change notification settings - Fork 326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
All Vector operations shall be applicable on java.util.ArrayList #6642
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e380e64
Run whole Vector_Spec with java.util.ArrayList
JaroslavTulach 415623d
Report missing build() method as a compiler error, not runtime exception
JaroslavTulach 9b1229f
Slicing node to handle Array as well as polyglot objects
JaroslavTulach f9ed686
One builtin method for slice is enough
JaroslavTulach f905a82
Alter the vector first and then filter it
JaroslavTulach 24749fd
Another round of Vector tests for Array_Proxy
JaroslavTulach File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could probably enhance the DSL to be able to generate
replaces
specializations. We already can dofallback
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason why I used own
Node
is: I wanted to use genericself
-Object
not anArray
. I haven't found a way to do that with a DSL. Moreover there isArrayXyzNode
#6299we want to be able to have nodes that operate on any array-like object. It is not very useful in case of
slice
- we don't use it fromengine
itself. However we will benefit from having real nodes that specialize in case oflength
andat
.