Permalink
Please sign in to comment.
Showing
with
104 additions
and 3 deletions.
- +42 −0 lib/builtins.py
- +35 −0 src/Hython/BuiltinTypes/List.hs
- +9 −3 src/Hython/Builtins.hs
- +1 −0 src/Hython/InterpreterState.hs
- +17 −0 test/builtins/list.py
| @@ -0,0 +1,35 @@ | ||
| module Hython.BuiltinTypes.List | ||
| where | ||
| import Control.Monad.State | ||
| import Data.IORef | ||
| import Hython.InterpreterState | ||
| import Hython.Object | ||
| listNew :: PrimitiveFn | ||
| listNew _ = do | ||
| items <- liftIO $ newIORef [] | ||
| return $ List items | ||
| listAppend :: PrimitiveFn | ||
| listAppend [l@(List ref), obj] = do | ||
| liftIO $ modifyIORef' ref (\l -> l ++ [obj]) | ||
| return l | ||
| listConcat :: PrimitiveFn | ||
| listConcat [l@(List lRef), List rRef] = do | ||
| items <- liftIO $ readIORef rRef | ||
| liftIO $ modifyIORef' lRef (++ items) | ||
| return l | ||
| listClear :: PrimitiveFn | ||
| listClear [l@(List ref)] = do | ||
| liftIO $ modifyIORef' ref (const []) | ||
| return l | ||
| listLength :: PrimitiveFn | ||
| listLength [List ref] = do | ||
| items <- liftIO $ readIORef ref | ||
| return $ Int (fromIntegral (length items)) | ||
0 comments on commit
fb7ec19