X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=mTaskInterpret.icl;h=eaded85f03b0bfc7a531eb64592072994bd475f9;hb=48dfd7ad2f104321657a3ea44d33340761c95c2e;hp=80286f2b41a4f5d8d088eef79ef87b3bd7654eca;hpb=aa90c851099c0f6e5993b8cf83ef6605b3835346;p=mTask.git diff --git a/mTaskInterpret.icl b/mTaskInterpret.icl index 80286f2..eaded85 100644 --- a/mTaskInterpret.icl +++ b/mTaskInterpret.icl @@ -5,17 +5,17 @@ import gdynamic, gCons, GenEq, StdMisc, StdArray import GenPrint import mTask +import StdFile +import StdString + from StdFunc import o import StdTuple import Data.Tuple -import Data.Functor import StdList -import Control.Applicative -import Control.Monad -import Data.Monoid -import Control.Monad.State -import Control.Monad.Identity from Data.Func import $ +from Text import class Text(join), instance Text String + + toByteVal :: BC -> String @@ -46,13 +46,15 @@ instance boolExpr ByteCode where instance If ByteCode Stmt Stmt Stmt where If b t e = BCIfStmt b t e instance If ByteCode Stmt e Stmt where If b t e = BCIfStmt b t e -instance If ByteCode Stmt Stmt e where If b t e = BCIfStmt b t e -instance If ByteCode Stmt x y where If b t e = BCIfStmt b t e +//instance If ByteCode Stmt Stmt e where If b t e = BCIfStmt b t e +//instance If ByteCode Stmt x y where If b t e = BCIfStmt b t e instance IF ByteCode where IF b t e = BCIfStmt b t e (?) b t = BCIfStmt b t $ BC [] BCIfStmt b t e = b <+-> [BCJmpF $ length <$> t + 1] <++> t <+-> [BCJmp $ length <$> e] <++> e +instance noOp ByteCode where noOp = BC [] + (<++>) infixl 7 (<++>) (BC x) (BC y) = BC $ x ++ y @@ -74,11 +76,20 @@ instance serial ByteCode where instance zero BCState where zero = {a=()} -//runByteCode :: (ByteCode Int Expr) BCState -> [BC] -//runByteCode (BC f) s = evalState f s -//runByteCode (BC f) s = fst (f Rd s) - -//Start :: Main (ByteCode Int Expr) -//Start :: [BC] -Start :: ByteCode Int Expr -Start = (lit 36 +. lit 42) +. lit 84 +//Start :: ByteCode Int Expr +//Start = (lit 36 +. lit 42) +. lit 84 +// +derive consIndex BC +derive consName BC + +Start w +# (io, w) = stdio w +# io = io <<< "#ifndef MTASK_H\n#define MTASK_H\n" +# io = io <<< join "\n" ["#define " +++ consName{|*|} x +++ " " +++ toString (consIndex{|*|} x)\\x<-allBC] +# (ok, w) = fclose (io <<< "\n#endif\n") w +| not ok = abort "Couldn't close stdio" += w + where + allBC = [BCNop, BCPush "", BCPop, BCNeg, BCNot, BCAdd, BCSub, BCMul, + BCDiv, BCAnd, BCOr, BCEq, BCNeq, BCLes, BCGre, BCLeq, BCGeq, + BCJmp 0, BCJmpT 0, BCJmpF 0]