| Copyright | (c) Murdoch J. Gabbay 2020 |
|---|---|
| License | GPL-3 |
| Maintainer | murdoch.gabbay@gmail.com |
| Stability | experimental |
| Portability | POSIX |
| Safe Haskell | None |
| Language | Haskell2010 |
Language.Nominal.Examples.Assembly2
Description
Based on an example in the Bound package. This is interesting for the binding behaviour of Add and the swapping behaviour of Swp.
Add adds two numbers and binds the result to a fresh register with scope over subsequent instructions.
Swp swaps the contents of two registers with scope over subsequent instructions.
Documentation
An operand is an integer literal or a variable
Instances
| Eq Operand Source # | |
| Show Operand Source # | |
| Generic Operand Source # | |
| Swappable Operand Source # | |
| KSub V Operand Prog Source # | Substitution on |
| KSub V Operand Operand Source # | Substitution as standard on |
| type Rep Operand Source # | |
Defined in Language.Nominal.Examples.Assembly2 type Rep Operand = D1 (MetaData "Operand" "Language.Nominal.Examples.Assembly2" "nom-0.1.0.2-Cei0dwnsIrWHLKrPA11A4S" False) (C1 (MetaCons "Lit" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Int)) :+: C1 (MetaCons "Var" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 V))) | |
Terms of our assembly language
Constructors
| Ret Operand | Return a value |
| Swp Operand Operand Prog | Swap the contents of two variables |
| Add Operand Operand (KAbs V Prog) | Add two operands and store the value in a fresh variable which is local to subsequent computation (the third argument) |
Instances
evalOperand :: Operand -> Int Source #
Evaluate an operand.
- A literal maps to its corresponding integer.
- If asked to evaluate a free variable, complain.
normaliseProg :: Prog -> Prog Source #
Normalise a program by executing any embedded Swp commands.
example1eval :: Int Source #
3