Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add strict imports for writeArray and create a listToStrictJSArray

  • Loading branch information...
commit 743acb12060c09176eb7b0aff3cb70daf6b0c2f5 1 parent ac1368e
Jurriën Stutterheim norm2782 authored

Showing 1 changed file with 11 additions and 0 deletions. Show diff stats Hide diff stats

  1. +11 0 uhc-js/src/Language/UHC/JScript/ECMA/Array.hs
11 uhc-js/src/Language/UHC/JScript/ECMA/Array.hs
@@ -11,6 +11,9 @@ type JSArray x = BoxArray x
11 11
12 12 instance JS (JSArray a)
13 13
  14 +instance ToJS [a] (JSArray a) where
  15 + toJS = listToStrictJSArray
  16 +
14 17 foreign import js "%1.length"
15 18 lengthJSArray :: JSArray x -> Int
16 19
@@ -185,11 +188,19 @@ foreign import prim
185 188 foreign import prim "primWriteArray"
186 189 primWriteArray :: BoxArray x -> Int -> x -> ()
187 190
  191 +foreign import prim "primStrictWriteArray"
  192 + primStrictWriteArray :: BoxArray x -> Int -> x -> ()
  193 +
188 194 listToJSArray :: [a] -> JSArray a
189 195 listToJSArray [] = error "Cannot convert empty list"
190 196 listToJSArray xs = snd $ foldr f (0, primNewArray (B.length xs) (head xs)) xs
191 197 where f x (n, arr) = (n+1, seq (primWriteArray arr n x) arr)
192 198
  199 +listToStrictJSArray :: [a] -> JSArray a
  200 +listToStrictJSArray [] = error "Cannot convert empty list"
  201 +listToStrictJSArray xs = snd $ foldr f (0, primNewArray (B.length xs) (head xs)) xs
  202 + where f x (n, arr) = (n+1, seq (primStrictWriteArray arr n x) arr)
  203 +
193 204 indexJSArray :: JSArray x -> Int -> x
194 205 indexJSArray = indexArray
195 206

0 comments on commit 743acb1

Please sign in to comment.
Something went wrong with that request. Please try again.