Skip to content

Commit

Permalink
Missed two spots where we use polyglot arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
hubertp committed Aug 23, 2022
1 parent 7e97b19 commit 5e34d39
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ polyglot java import org.enso.base.Text_Utils
all_character_sets : Vector.Vector Text
all_character_sets =
java_array = Charset.availableCharsets.keySet.toArray
Vector.Vector java_array
Vector.from_polyglot_array java_array

## Get all available Encodings.
all_encodings : Vector Encoding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ Text.from_utf_8 bytes on_problems=Report_Warning =

"Hello".char_vector
Text.char_vector : Vector.Vector Integer
Text.char_vector self = Vector.Vector (Text_Utils.get_chars self)
Text.char_vector self = Vector.from_polyglot_array (Text_Utils.get_chars self)

## Takes a vector of characters and returns the text that results from it.

Expand All @@ -840,7 +840,7 @@ Text.from_char_vector chars = Text_Utils.from_chars chars.to_array

"Hello".codepoints
Text.codepoints : Vector.Vector Integer
Text.codepoints self = Vector.Vector (Text_Utils.get_codepoints self)
Text.codepoints self = Vector.from_polyglot_array (Text_Utils.get_codepoints self)

## Takes an array of numbers and returns the text resulting from interpreting it
as a sequence of Unicode codepoints.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@ long doInteger(Object integer, @CachedLibrary(limit = "5") InteropLibrary number
}
}

@Specialization(guards = {"characters.isString(character)", "isChar(character)"})
long doChar(Object character, @CachedLibrary(limit = "5") InteropLibrary characters) {
try {
return characters.asString(character).charAt(0);
} catch (UnsupportedMessageException e) {
throw new IllegalStateException("Impossible, `character` is checked to be a long");
}
}

static boolean isChar(Object s) {
return s instanceof Character;
}

@Fallback
Object doNonPrimitive(Object value) {
return value;
Expand Down

0 comments on commit 5e34d39

Please sign in to comment.