1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-20 10:07:45 +03:00
mal/elm/Types.elm

108 lines
1.7 KiB
Elm
Raw Normal View History

module Types exposing (..)
2017-06-05 00:41:21 +03:00
import Array exposing (Array)
import Dict exposing (Dict)
import IO exposing (IO)
type Either a b
= Left a
| Right b
type Msg
= Input (Result String IO)
type alias Frame =
{ outerId : Maybe Int
2017-07-18 22:34:36 +03:00
, exitId : Maybe Int
, data : Dict String MalExpr
, refCnt : Int
}
type alias Env =
{ frames : Dict Int Frame
, nextFrameId : Int
, currentFrameId : Int
2017-06-14 16:49:27 +03:00
, atoms : Dict Int MalExpr
, nextAtomId : Int
, debug : Bool
, gcInterval : Int
, gcCounter : Int
2017-07-18 22:34:36 +03:00
, stack : List MalExpr
2017-07-22 22:44:25 +03:00
, keepFrames : List Int
}
2017-06-20 18:23:00 +03:00
type alias EvalCont a =
IO -> Eval a
2017-06-18 22:38:48 +03:00
type EvalResult res
2017-06-23 17:56:04 +03:00
= EvalErr MalExpr
| EvalOk res
2017-06-18 22:38:48 +03:00
| EvalIO (Cmd Msg) (EvalCont res)
type alias EvalContext res =
( Env, EvalResult res )
type alias Eval res =
Env -> EvalContext res
2017-06-14 16:49:27 +03:00
type alias MalFn =
List MalExpr -> Eval MalExpr
type MalFunction
= CoreFunc MalFn
2017-06-20 18:23:00 +03:00
| UserFunc
{ frameId : Int
, lazyFn : MalFn
, eagerFn : MalFn
, isMacro : Bool
2017-06-23 17:56:04 +03:00
, meta : Maybe MalExpr
2017-06-20 18:23:00 +03:00
}
2017-06-14 16:49:27 +03:00
type alias ApplyRec =
{ frameId : Int, bound : Bound, body : MalExpr }
2017-06-14 16:49:27 +03:00
type alias TcoFn =
() -> Eval MalExpr
type alias Bound =
List ( String, MalExpr )
2017-06-05 00:41:21 +03:00
type MalExpr
= MalNil
| MalBool Bool
| MalInt Int
| MalString String
| MalKeyword String
| MalSymbol String
| MalList (List MalExpr)
| MalVector (Array MalExpr)
| MalMap (Dict String MalExpr)
2017-06-14 16:49:27 +03:00
| MalFunction MalFunction
| MalApply ApplyRec
2017-06-14 16:49:27 +03:00
| MalAtom Int
2017-06-05 00:41:21 +03:00
{-| Keywords are prefixed by this char for usage in a MalMap.
Elm doesn't support user defined types as keys in a Dict.
The unicode char is: '\x029e'
-}
keywordPrefix : Char
keywordPrefix =
'ʞ'