Skip to content

Instantly share code, notes, and snippets.

@SPY
Created May 7, 2018 04:53
Show Gist options
  • Save SPY/745a919d5bf7b5e9504f4ee23c808804 to your computer and use it in GitHub Desktop.
Save SPY/745a919d5bf7b5e9504f4ee23c808804 to your computer and use it in GitHub Desktop.
-- | Names are hierarchies of strings, describing scope (so no danger of
-- duplicate names, but need to be careful on lookup).
data Name = UN !T.Text -- ^ User-provided name
| NS !Name [T.Text] -- ^ Root, namespaces
| MN !Int !T.Text -- ^ Machine chosen names
| SN !SpecialName -- ^ Decorated function names
| SymRef Int -- ^ Reference to IBC file symbol table (used during serialisation)
instance Show Name where
show (UN n) = str n
show (NS n s) = showSep "." (map T.unpack (reverse s)) ++ "." ++ show n
show (MN _ u) | u == txt "underscore" = "_"
show (MN i s) = "{" ++ str s ++ "_" ++ show i ++ "}"
show (SN s) = show s
show (SymRef i) = "##symbol" ++ show i ++ "##"
data LVar = Loc Int | Glob Name
data Const
= I Int
| BI Integer
| Fl Double
| Ch Char
| Str String
| B8 Word8
| B16 Word16
| B32 Word32
| B64 Word64
| AType ArithTy
| StrType
| WorldType
| TheWorld
| VoidType
| Forgot
data NativeTy = IT8 | IT16 | IT32 | IT64
data IntTy = ITFixed NativeTy | ITNative | ITBig | ITChar
data ArithTy = ATInt IntTy | ATFloat
data PrimFn
= LPlus ArithTy | LMinus ArithTy | LTimes ArithTy
| LUDiv IntTy | LSDiv ArithTy | LURem IntTy | LSRem ArithTy
| LAnd IntTy | LOr IntTy | LXOr IntTy | LCompl IntTy
| LSHL IntTy | LLSHR IntTy | LASHR IntTy
| LEq ArithTy | LLt IntTy | LLe IntTy | LGt IntTy | LGe IntTy
| LSLt ArithTy | LSLe ArithTy | LSGt ArithTy | LSGe ArithTy
| LSExt IntTy IntTy | LZExt IntTy IntTy | LTrunc IntTy IntTy
| LStrConcat | LStrLt | LStrEq | LStrLen
| LIntFloat IntTy | LFloatInt IntTy | LIntStr IntTy | LStrInt IntTy
| LFloatStr | LStrFloat | LChInt IntTy | LIntCh IntTy
| LBitCast ArithTy ArithTy -- Only for values of equal width
| LFExp | LFLog | LFSin | LFCos | LFTan | LFASin | LFACos | LFATan
| LFATan2 | LFSqrt | LFFloor | LFCeil | LFNegate
| LStrHead | LStrTail | LStrCons | LStrIndex | LStrRev | LStrSubstr
| LReadStr | LWriteStr
-- system info
| LSystemInfo
| LFork
| LPar -- evaluate argument anywhere, possibly on another
-- core or another machine. 'id' is a valid implementation
| LExternal Name
| LCrash
| LNoOp
data SExp = SV LVar
| SApp Bool {- Tailcall -} Name [LVar] {- Argumetns -}
| SLet LVar {- Distination(only local) -} SExp {- Subexpr -} SExp {- Continuation -}
| SUpdate LVar {- Distination(only local) -} SExp
| SCon (Maybe LVar) {- location to reallocate, if available -} Int {- Con Tag -} Name [LVar]
| SCase CaseType {- Updatable | Shared -} LVar [SAlt]
| SChkCase LVar [SAlt] {- check if arg is constructor required -}
| SProj LVar Int {- get N argument of constructor -}
| SConst Const {- Define const -}
-- Keep DExps for describing foreign things, because they get
-- translated differently
| SForeign FDesc FDesc [(FDesc, LVar)]
| SOp PrimFn [LVar] {- execute primitive operation -}
| SNothing -- erased value, will never be inspected {- shouldn't be called -}
| SError String {- raise error -}
data SAlt
= SConCase Int {- constr addr -} Int {- tag -} Name [Name] SExp
| SConstCase Const SExp
| SDefaultCase SExp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment