From aa90c851099c0f6e5993b8cf83ef6605b3835346 Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Wed, 9 Nov 2016 18:01:39 +0100 Subject: [PATCH] Initial try, maybe I'll need a state --- Makefile | 2 +- mTaskInterpret.dcl | 17 +++++++++++++- mTaskInterpret.icl | 58 +++++++++++++++++++++++++++++++++++++--------- 3 files changed, 64 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index a4cf3b1..104f190 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ CLEAN_HOME?=/opt/clean CLM:=clm -CLMFLAGS+=-dynamics -l -no-pie -h 200M -t -nt +CLMFLAGS+=-dynamics -l -no-pie -h 200M -t -nt -lat CLMLIBS:=\ -I $(CLEAN_HOME)/lib/iTasks-SDK/Patches/Dynamics\ -I $(CLEAN_HOME)/lib/iTasks-SDK/Patches/Generics\ diff --git a/mTaskInterpret.dcl b/mTaskInterpret.dcl index 32e7b9b..5a80189 100644 --- a/mTaskInterpret.dcl +++ b/mTaskInterpret.dcl @@ -16,8 +16,23 @@ import mTask | BCSub | BCMul | BCDiv + //Binary Bool ops + | BCAnd + | BCOr + | BCEq + | BCNeq + | BCLes + | BCGre + | BCLeq + | BCGeq + //Conditionals and jumping + | BCJmp Int + | BCJmpT Int + | BCJmpF Int -:: ByteCode a p = BC ((ReadWrite (ByteCode a Expr)) BCState -> ([BC], BCState)) +//:: ByteCode a p = BC (BCState -> ([BC], BCState)) +:: ByteCode a p = BC [BC] +//:: ByteCode a p = BC ((ReadWrite (ByteCode a Expr)) BCState -> ([BC], BCState)) :: BCState = { a::() } diff --git a/mTaskInterpret.icl b/mTaskInterpret.icl index 52d7fd4..80286f2 100644 --- a/mTaskInterpret.icl +++ b/mTaskInterpret.icl @@ -8,8 +8,13 @@ import mTask 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 $ @@ -21,13 +26,43 @@ derive gPrint BC toReadableByteVal :: BC -> String toReadableByteVal a = printToString a -//:: ByteCode a p = BC (BCState -> ([BC], BCState)) instance arith ByteCode where - lit a = BC \_ s->([BCPush $ toCode a], s) - (+.) _ _ = undef - (-.) _ _ = undef - (*.) _ _ = undef - (/.) _ _ = undef + lit x = BC [BCPush $ toCode x] + (+.) x y = x <++> y <+-> [BCAdd] + (-.) x y = x <++> y <+-> [BCSub] + (*.) x y = x <++> y <+-> [BCMul] + (/.) x y = x <++> y <+-> [BCDiv] + +instance boolExpr ByteCode where + (&.) x y = x <++> y <+-> [BCAnd] + (|.) x y = x <++> y <+-> [BCOr] + Not x = x <+-> [BCNot] + (==.) x y = x <++> y <+-> [BCEq] + (!=.) x y = x <++> y <+-> [BCNeq] + (<.) x y = x <++> y <+-> [ BCLes] + (>.) x y = x <++> y <+-> [BCGre] + (<=.) x y = x <++> y <+-> [BCLeq] + (>=.) x y = x <++> y <+-> [BCGeq] + +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 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 + + +(<++>) infixl 7 +(<++>) (BC x) (BC y) = BC $ x ++ y +(<+->) infixl 7 +(<+->) (BC x) y = BC $ x ++ y +(<-+>) infixl 7 +(<-+>) x (BC y) = BC $ x ++ y + +(<$>) infixl 9 +(<$>) f (BC x) = f x instance serial ByteCode where serialAvailable = undef @@ -39,10 +74,11 @@ instance serial ByteCode where instance zero BCState where zero = {a=()} -runByteCode :: (ByteCode Int Expr) BCState -> [BC] -runByteCode (BC f) s = fst (f Rd s) +//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 = runByteCode (lit 36) zero +//Start :: [BC] +Start :: ByteCode Int Expr +Start = (lit 36 +. lit 42) +. lit 84 -- 2.20.1