1 implementation module mTaskInterpret
4 import gdynamic, gCons, GenEq, StdMisc, StdArray
13 import Control.Applicative
16 import Control.Monad.State
17 import Control.Monad.Identity
18 from Data.Func import $
21 toByteVal :: BC -> String
26 toReadableByteVal :: BC -> String
27 toReadableByteVal a = printToString a
29 instance arith ByteCode where
30 lit x = BC [BCPush $ toCode x]
31 (+.) x y = x <++> y <+-> [BCAdd]
32 (-.) x y = x <++> y <+-> [BCSub]
33 (*.) x y = x <++> y <+-> [BCMul]
34 (/.) x y = x <++> y <+-> [BCDiv]
36 instance boolExpr ByteCode where
37 (&.) x y = x <++> y <+-> [BCAnd]
38 (|.) x y = x <++> y <+-> [BCOr]
39 Not x = x <+-> [BCNot]
40 (==.) x y = x <++> y <+-> [BCEq]
41 (!=.) x y = x <++> y <+-> [BCNeq]
42 (<.) x y = x <++> y <+-> [ BCLes]
43 (>.) x y = x <++> y <+-> [BCGre]
44 (<=.) x y = x <++> y <+-> [BCLeq]
45 (>=.) x y = x <++> y <+-> [BCGeq]
47 instance If ByteCode Stmt Stmt Stmt where If b t e = BCIfStmt b t e
48 instance If ByteCode Stmt e Stmt where If b t e = BCIfStmt b t e
49 instance If ByteCode Stmt Stmt e where If b t e = BCIfStmt b t e
50 instance If ByteCode Stmt x y where If b t e = BCIfStmt b t e
51 instance IF ByteCode where
52 IF b t e = BCIfStmt b t e
53 (?) b t = BCIfStmt b t $ BC []
54 BCIfStmt b t e = b <+-> [BCJmpF $ length <$> t + 1] <++> t <+-> [BCJmp $ length <$> e] <++> e
58 (<++>) (BC x) (BC y) = BC $ x ++ y
60 (<+->) (BC x) y = BC $ x ++ y
62 (<-+>) x (BC y) = BC $ x ++ y
67 instance serial ByteCode where
68 serialAvailable = undef
70 serialPrintln _ = undef
72 serialParseInt = undef
74 instance zero BCState where
77 //runByteCode :: (ByteCode Int Expr) BCState -> [BC]
78 //runByteCode (BC f) s = evalState f s
79 //runByteCode (BC f) s = fst (f Rd s)
81 //Start :: Main (ByteCode Int Expr)
83 Start :: ByteCode Int Expr
84 Start = (lit 36 +. lit 42) +. lit 84