1%if false 2 Copyright (c) 2009 ETH Zurich. 3 All rights reserved. 4 5 This file is distributed under the terms in the attached LICENSE file. 6 If you do not find this file, copies can be found by writing to: 7 ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group. 8%endif 9 10%include polycode.fmt 11 12%if false 13 14> module Constructs.Typedef where 15 16> import Semantics 17> import Constructs 18> import PureExpressions 19> import {-# SOURCE #-} Expressions 20 21> import IL.FoF.FoF 22> import IL.FoF.Compile 23 24%endif 25 26\section{Type Definition} 27 28The |Typedef| construct provides a similar service than the C 29@typedef@. 30 31\subsection{Smart Constructors} 32 33In particular, |Typedef| offers two combinators. The first one, 34|alias| allows you to locally define a type alias. 35 36> alias :: TypeExpr -> FoFCode PureExpr 37> alias typedef = inject (Typedef typedef (return void)) 38 39The other one, |aliasE| allows you to mention an aliasing declared in 40an external library, such as @<stdbool.h>@ that declares a @bool@ as 41an integer. 42 43> aliasE :: String -> 44> TypeExpr -> 45> FoFCode PureExpr 46> aliasE incl typedef = inject (TypedefE incl typedef (return void)) 47 48\subsection{Compile Instantiation} 49 50The compilation to FoF is straightforward: 51 52> compileTypedef (Typedef (TTypedef typ aliasName) r) binding = 53> let (cont, binding1) = r binding in 54> (FStatement (FTypedef typ aliasName) cont, 55> binding1) 56> 57> compileTypedef (TypedefE inclDirective typeDef@(TTypedef typ aliasName) r) binding = 58> let (cont, binding1) = r binding in 59> (FStatement (FTypedefE inclDirective typeDef) cont, 60> binding1) 61 62 63\subsection{Run Instantiation} 64 65These operations occurring at the type-level, the interpreter doesn't 66pay any attention to them: 67 68> runTypedef (Typedef _ r) heap = r heap 69> runTypedef (TypedefE _ _ r) heap = r heap 70 71