-
Notifications
You must be signed in to change notification settings - Fork 2
/
Mrifk_code.hs
75 lines (59 loc) · 2.32 KB
/
Mrifk_code.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
{-
Mrifk, a decompiler for Glulx story files.
Copyright 2004 Ben Rudiak-Gould.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You can read the GNU General Public License at this URL:
http://www.gnu.org/copyleft/gpl.html
-}
module Mrifk_code (
Statement(..), LabelType(..), Expr(..), Opcode(..), BinaryOp (..),
binopEQ, binopNE, binopLT, binopGT, binopLE, binopGE,
binopHas, binopOr, binopAnd,
binopName, binopPrec
) where
data Statement =
Push Expr | Eval String Expr |
Print String Expr | NewLine |
IfThenElse Expr [Statement] [Statement] |
Label Int LabelType | JCond Expr Int | Jump Int |
Give Expr Bool Int |
GInstr (String,Int,Int,Int,Opcode) [Expr]
deriving (Show,Eq)
data LabelType = Single | Multi | Phantom deriving (Show,Eq)
data Expr =
SP | Imm Int | ImmString Int | Mem Int | Local Int |
Unary String Int Expr | PostIncDec Expr String |
Binary Expr BinaryOp Expr |
Assign Expr Expr | Call Expr [Expr] |
SpecialName String
deriving (Show,Eq)
data Opcode =
OCopy | OJCond BinaryOp | OJump | OCall | OCallI | OReturn |
OALoadBit | OAStore | OAStoreB | OAStoreBit |
OStreamChar | OStreamNum | OStreamStr |
OBinary BinaryOp | OGlk | OStkSwap | OSpecial
deriving (Show,Eq)
data BinaryOp =
NormalOp String Int | PredicateOp String String | LogicalOp String String deriving (Show,Eq)
binopEQ = PredicateOp " == " " ~= "
binopNE = PredicateOp " ~= " " == "
binopLT = PredicateOp " < " " >= "
binopGT = PredicateOp " > " " <= "
binopLE = PredicateOp " <= " " > "
binopGE = PredicateOp " >= " " < "
binopHas = PredicateOp " has " " hasnt "
binopOr = LogicalOp " || " " && "
binopAnd = LogicalOp " && " " || "
binopName (PredicateOp s _) = s
binopName (LogicalOp s _) = s
binopName (NormalOp s _) = s
binopPrec (PredicateOp _ _) = 3
binopPrec (LogicalOp _ _) = 2
binopPrec (NormalOp _ p) = p