1{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
2{-# LANGUAGE BangPatterns, EmptyDataDecls, FlexibleInstances, MagicHash, UnboxedTuples #-}
25 , fromTypeVariableScheme
28 , int, float, bool, char, string
29 , maybe, result, list, array, dict, tuple, jsArray
30 , task, router, cmd, sub, platform, virtualDom
31 , shader, debug, debugger, bitwise, basics
32 , utils, negate, true, false, value
33 , node, program, _main, _Main, dollar, identity
34 , replModule, replValueToPrint
39import Prelude hiding (length, maybe, negate)
40import Control.Exception (assert)
41import qualified Data.Binary as Binary
42import qualified Data.ByteString.Builder.Internal as B
43import qualified Data.Coerce as Coerce
44import qualified Data.List as List
45import qualified Data.String as Chars
46import qualified Data.Utf8 as Utf8
53 , unsafeFreezeByteArray#
55import GHC.ST (ST(ST), runST)
57import GHC.Word (Word8(W8#))
59import qualified Elm.String as ES
77instance Chars.IsString (Utf8.Utf8 ELM_NAME) where
78 fromString = Utf8.fromChars
80instance Binary.Binary (Utf8.Utf8 ELM_NAME) where
81 get = Utf8.getUnder256
82 put = Utf8.putUnder256
89toChars :: Name -> [Char]
94toElmString :: Name -> ES.String
99{-# INLINE toBuilder #-}
100toBuilder :: Name -> B.Builder
109fromPtr :: Ptr Word8 -> Ptr Word8 -> Name
114fromChars :: [Char] -> Name
123hasDot :: Name -> Bool
125 Utf8.contains 0x2E {- . -} name
128splitDots :: Name -> [Name]
130 Utf8.split 0x2E {- . -} name
137getKernel :: Name -> Name
138getKernel name@(Utf8.Utf8 ba#) =
139 assert (isKernel name)
144 !size# = sizeofByteArray# ba# -# 11#
147 case newByteArray# size# s of
149 case copyByteArray# ba# 11# mba# 0# size# s of
151 case unsafeFreezeByteArray# mba# s of
152 (# s, ba# #) -> (# s, Utf8.Utf8 ba# #)
161isKernel :: Name -> Bool
162isKernel = Utf8.startsWith prefix_kernel
164isNumberType :: Name -> Bool
165isNumberType = Utf8.startsWith prefix_number
167isComparableType :: Name -> Bool
168isComparableType = Utf8.startsWith prefix_comparable
170isAppendableType :: Name -> Bool
171isAppendableType = Utf8.startsWith prefix_appendable
173isCompappendType :: Name -> Bool
174isCompappendType = Utf8.startsWith prefix_compappend
176{-# NOINLINE prefix_kernel #-}
178prefix_kernel = fromChars "Elm.Kernel."
180{-# NOINLINE prefix_number #-}
182prefix_number = fromChars "number"
184{-# NOINLINE prefix_comparable #-}
185prefix_comparable :: Name
186prefix_comparable = fromChars "comparable"
188{-# NOINLINE prefix_appendable #-}
189prefix_appendable :: Name
190prefix_appendable = fromChars "appendable"
192{-# NOINLINE prefix_compappend #-}
193prefix_compappend :: Name
194prefix_compappend = fromChars "compappend"
201fromVarIndex :: Int -> Name
205 do let !size = getIndexSize n
206 mba <- newByteArray size
207 writeWord8 mba 0 0x5F {- _ -}
208 writeWord8 mba 1 0x76 {- v -}
209 writeDigits mba (size - 1) n
214{-# INLINE getIndexSize #-}
215getIndexSize :: Int -> Int
219 | True = 2 + ceiling (logBase 10 (fromIntegral n + 1) :: Float)
223writeDigits :: MBA s -> Int -> Int -> ST s ()
224writeDigits !mba !offset !n =
225 do let (q,r) = quotRem n 10
226 writeWord8 mba offset (0x30 + fromIntegral r)
229 else writeDigits mba (offset-1) q
236fromTypeVariable :: Name -> Int -> Name
237fromTypeVariable name@(Utf8.Utf8 ba#) index =
242 len# = sizeofByteArray# ba#
243 end# = indexWord8Array# ba# (len# -# 1#)
245 if isTrue# (leWord# 0x30## end#) && isTrue# (leWord# end# 0x39##) then
248 do let !size = I# len# + 1 + getIndexSize index
249 mba <- newByteArray size
251 writeWord8 mba (I# len#) 0x5F {- _ -}
252 writeDigits mba (size - 1) index
258 do let !size = I# len# + getIndexSize index
259 mba <- newByteArray size
261 writeDigits mba (size - 1) index
267-- FROM TYPE VARIABLE SCHEME
270fromTypeVariableScheme :: Int -> Name
271fromTypeVariableScheme scheme =
275 do mba <- newByteArray 1
276 writeWord8 mba 0 (0x61 + fromIntegral scheme)
279 do let (extra, letter) = quotRem scheme 26
280 let !size = getIndexSize extra
281 mba <- newByteArray size
282 writeWord8 mba 0 (0x61 + fromIntegral letter)
283 writeDigits mba (size - 1) extra
292fromManyNames :: [Name] -> Name
295 !(I# size#) = sum (map (\(Utf8.Utf8 ba#) -> I# (sizeofByteArray# ba# +# 1#)) names)
300 case newByteArray# size# s of
302 case writeNames mba# 0# names s of
304 case unsafeFreezeByteArray# mba# s of
305 (# s, ba# #) -> (# s, Utf8.Utf8 ba# #)
309writeNames :: MutableByteArray# s -> Int# -> [Name] -> State# s -> State# s
310writeNames mba# !offset# names s =
315 (Utf8.Utf8 ba#) : names ->
316 case writeWord8Array# mba# offset# 0x24## {- $ -} s of
319 !offset1# = offset# +# 1#
320 !len# = sizeofByteArray# ba#
321 !newOffset# = offset1# +# len#
323 case copyByteArray# ba# 0# mba# offset1# len# s of
325 writeNames mba# newOffset# names s
332fromWords :: [Word8] -> Name
336 do mba <- newByteArray (List.length words)
337 writeWords mba 0 words
342writeWords :: MBA s -> Int -> [Word8] -> ST s ()
343writeWords !mba !i words =
349 do writeWord8 mba i w
350 writeWords mba (i+1) ws
357sepBy :: Word8 -> Name -> Name -> Name
358sepBy (W8# sep#) (Utf8.Utf8 ba1#) (Utf8.Utf8 ba2#) =
360 !len1# = sizeofByteArray# ba1#
361 !len2# = sizeofByteArray# ba2#
366 case newByteArray# (len1# +# len2# +# 1#) s of
368 case copyByteArray# ba1# 0# mba# 0# len1# s of
370 case writeWord8Array# mba# len1# sep# s of
372 case copyByteArray# ba2# 0# mba# (len1# +# 1#) len2# s of
374 case unsafeFreezeByteArray# mba# s of
375 (# s, ba# #) -> (# s, Utf8.Utf8 ba# #)
384 MBA# (MutableByteArray# s)
387{-# INLINE newByteArray #-}
388newByteArray :: Int -> ST s (MBA s)
389newByteArray (I# len#) =
391 case newByteArray# len# s of
392 (# s, mba# #) -> (# s, MBA# mba# #)
396freeze :: MBA s -> ST s Name
399 case unsafeFreezeByteArray# mba# s of
400 (# s, ba# #) -> (# s, Utf8.Utf8 ba# #)
403{-# INLINE writeWord8 #-}
404writeWord8 :: MBA s -> Int -> Word8 -> ST s ()
405writeWord8 (MBA# mba#) (I# offset#) (W8# w#) =
407 case writeWord8Array# mba# offset# w# s of
411{-# INLINE copyToMBA #-}
412copyToMBA :: Name -> MBA s -> ST s ()
413copyToMBA (Utf8.Utf8 ba#) (MBA# mba#) =
415 case copyByteArray# ba# 0# mba# 0# (sizeofByteArray# ba#) s of
428{-# NOINLINE float #-}
430float = fromChars "Float"
435bool = fromChars "Bool"
440char = fromChars "Char"
443{-# NOINLINE string #-}
445string = fromChars "String"
448{-# NOINLINE maybe #-}
450maybe = fromChars "Maybe"
453{-# NOINLINE result #-}
455result = fromChars "Result"
460list = fromChars "List"
463{-# NOINLINE array #-}
465array = fromChars "Array"
470dict = fromChars "Dict"
473{-# NOINLINE tuple #-}
475tuple = fromChars "Tuple"
478{-# NOINLINE jsArray #-}
480jsArray = fromChars "JsArray"
485task = fromChars "Task"
488{-# NOINLINE router #-}
490router = fromChars "Router"
503{-# NOINLINE platform #-}
505platform = fromChars "Platform"
508{-# NOINLINE virtualDom #-}
510virtualDom = fromChars "VirtualDom"
513{-# NOINLINE shader #-}
515shader = fromChars "Shader"
518{-# NOINLINE debug #-}
520debug = fromChars "Debug"
523{-# NOINLINE debugger #-}
525debugger = fromChars "Debugger"
528{-# NOINLINE bitwise #-}
530bitwise = fromChars "Bitwise"
533{-# NOINLINE basics #-}
535basics = fromChars "Basics"
538{-# NOINLINE utils #-}
540utils = fromChars "Utils"
543{-# NOINLINE negate #-}
545negate = fromChars "negate"
550true = fromChars "True"
553{-# NOINLINE false #-}
555false = fromChars "False"
558{-# NOINLINE value #-}
560value = fromChars "Value"
565node = fromChars "Node"
568{-# NOINLINE program #-}
570program = fromChars "Program"
573{-# NOINLINE _main #-}
575_main = fromChars "main"
578{-# NOINLINE _Main #-}
580_Main = fromChars "Main"
583{-# NOINLINE dollar #-}
585dollar = fromChars "$"
588{-# NOINLINE identity #-}
590identity = fromChars "identity"
593{-# NOINLINE replModule #-}
595replModule = fromChars "Elm_Repl"
598{-# NOINLINE replValueToPrint #-}
599replValueToPrint :: Name
600replValueToPrint = fromChars "repl_input_value_"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list