-
-
Notifications
You must be signed in to change notification settings - Fork 52
Add a helper method to copy an array of numbers to a JS TypedArray #31
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
Changes from 2 commits
fe68a31
0cb3f65
3eca18c
bff8568
136315f
5b875b2
af57583
e71fc56
17d83f5
64342d2
ab974af
0928da8
a1f5b03
7971185
dde8cf2
74610c2
14ab088
b6602c8
561b8a6
b0ff949
7836ac2
e0ef55f
d64def7
fab45e1
f83a84c
2370a1f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,32 @@ enum JavaScriptValueKind { | |
Function = 6, | ||
} | ||
|
||
enum JavaScriptTypedArrayKind { | ||
Int8 = 0, | ||
Uint8 = 1, | ||
Int16 = 2, | ||
Uint16 = 3, | ||
Int32 = 4, | ||
Uint32 = 5, | ||
BigInt64 = 6, | ||
BigUint64 = 7, | ||
Float32 = 8, | ||
Float64 = 9, | ||
} | ||
|
||
type TypedArray = | ||
| Int8ArrayConstructor | ||
| Uint8ArrayConstructor | ||
| Int16ArrayConstructor | ||
| Uint16ArrayConstructor | ||
| Int32ArrayConstructor | ||
| Uint32ArrayConstructor | ||
// | BigInt64ArrayConstructor | ||
// | BigUint64ArrayConstructor | ||
| Float32ArrayConstructor | ||
| Float64ArrayConstructor | ||
|
||
|
||
type SwiftRuntimeHeapEntry = { | ||
id: number, | ||
rc: number, | ||
|
@@ -370,6 +396,16 @@ export class SwiftRuntime { | |
const constructor = this.heap.referenceHeap(constructor_ref) | ||
return obj instanceof constructor | ||
}, | ||
swjs_create_typed_array: ( | ||
kind: JavaScriptTypedArrayKind, | ||
elementsPtr: pointer, length: number, | ||
result_obj: pointer | ||
) => { | ||
const ArrayType: TypedArray = this.heap.referenceHeap(0)[JavaScriptTypedArrayKind[kind] + 'Array'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't abuse address There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I created a |
||
const array = new ArrayType(memory().buffer, elementsPtr, length); | ||
// Call `.slice()` to copy the memory | ||
writeUint32(result_obj, this.heap.allocHeap(array.slice())); | ||
j-f1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
swjs_destroy_ref: (ref: ref) => { | ||
this.heap.freeHeap(ref) | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.