From 34dfa724f02cd36ff31057ab71ba53ad57fabcb5 Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Fri, 4 Nov 2016 20:32:07 +0100 Subject: [PATCH] started with interpret and bytecode classes --- .gitignore | 1 + Makefile | 8 ++- mTask.dcl | 2 +- mTaskCode.dcl | 3 +- mTaskInterpret.dcl | 157 +++++++++++++++++++++++++++++++++++++++++++++ mTaskInterpret.icl | 32 +++++++++ 6 files changed, 197 insertions(+), 6 deletions(-) create mode 100644 mTaskInterpret.dcl create mode 100644 mTaskInterpret.icl diff --git a/.gitignore b/.gitignore index 73b32ae..c43012d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ mTask mTaskExamples sapl mTask-data +mTaskInterpret diff --git a/Makefile b/Makefile index b8ba871..a4cf3b1 100644 --- a/Makefile +++ b/Makefile @@ -23,10 +23,12 @@ CLMLIBS:=\ -I $(CLEAN_HOME)/lib/TCPIP\ -I ./CleanSerial -all: mTaskExamples +BINARIES:= mTaskExamples mTaskInterpret -%: %.icl +all: $(BINARIES) + +%: %.icl $(wildcard *.dcl) $(CLM) $(CLMLIBS) $(CLMFLAGS) $(basename $<) -o $@ clean: - $(RM) -r mTaskExamples Clean\ System\ Files + $(RM) -r $(BINARIES) Clean\ System\ Files diff --git a/mTask.dcl b/mTask.dcl index d341ff7..6613e2a 100644 --- a/mTask.dcl +++ b/mTask.dcl @@ -21,7 +21,7 @@ import StdClass from iTasks.API.Core.Types import :: Display import gdynamic, gCons, GenEq, StdMisc, StdArray -import mTaskCode, mTaskSimulation +import mTaskCode, mTaskSimulation, mTaskInterpret import mTaskSerial, mTaskLCD // =================== mTask =================== diff --git a/mTaskCode.dcl b/mTaskCode.dcl index 8e5f0f5..068de00 100644 --- a/mTaskCode.dcl +++ b/mTaskCode.dcl @@ -2,12 +2,11 @@ definition module mTaskCode import mTask +class toCode a :: a -> String instance toCode Pin instance toCode MTask instance toCode () instance toCode Long - -class toCode a :: a -> String instance toCode Bool instance toCode Int instance toCode Real diff --git a/mTaskInterpret.dcl b/mTaskInterpret.dcl new file mode 100644 index 0000000..557225f --- /dev/null +++ b/mTaskInterpret.dcl @@ -0,0 +1,157 @@ +definition module mTaskInterpret + +import mTask + +:: BC + = BCNop + | BCPush Int + | BCPop + //Unary ops + | BCNeg + | BCNot + //Binary Int ops + | BCAdd + | BCSub + | BCMul + | BCDiv + +:: ByteCode a p = BC ((ReadWrite a) BCState -> ([BC], BCState)) +:: BCState = { + a::() + } + +toByteVal :: BC -> String +toReadableByteVal :: BC -> String + +//instance toCode Pin +//instance toCode MTask +//instance toCode () +//instance toCode Long +// +//class toCode a :: a -> String +//instance toCode Bool +//instance toCode Int +//instance toCode Real +//instance toCode Char +//instance toCode String +//instance toCode DigitalPin +//instance toCode AnalogPin +// +//argType :: (((Code a p)->Code b q)->In ((Code a p)->Code b q) (Code c s)) -> a | type a +// +//class argTypes t :: ((t->Code b Expr)->In (t->Code b2 q) (Main (Code c s))) -> t +//instance argTypes (Code a p) | showType a +//instance argTypes (Code a p, Code b q) | showType a & showType b +//instance argTypes (Code a p, Code b q, Code c r) | showType a & showType b & showType c +// +//instance toCode (SV t) +// +//instance arith Code +//instance boolExpr Code +//instance If Code Stmt Stmt Stmt +//instance If Code e Stmt Stmt +//instance If Code Stmt e Stmt +//instance If Code x y Expr +//instance IF Code +//instance sds Code +// +//defCode :: ((Code t p) -> In t (Main (Code u q))) -> Main (Code u r) | type t +// +//var :: String (ReadWrite (Code v q)) CODE -> CODE +// +//instance assign Code +//instance seq Code +//instance step` Code +//codeSteps :: [Step Code t] -> Code u p +//optBreak :: Mode -> Code u p +// +//instance setDelay Code +//instance mtask Code a | taskImp2 a & types a +//instance mtasks Code a b | taskImp2 a & types a & taskImp2 b & types b +// +//loopCode :: Int (Code a b) -> Code c d +// +//class taskImp2 a :: Int a -> ((Code Long p) a->Code MTask Expr, a) | /*long Code delay &*/ isExpr p +//instance taskImp2 () +//instance taskImp2 (Code t p) +//instance taskImp2 (Code a p, Code b q) +//instance taskImp2 (Code a p, Code b q, Code c r) +//instance taskImp2 (Code a p, Code b q, Code c r, Code d s) +// +//class taskImp a :: Int a -> (Int a->Code MTask Expr, a) +//instance taskImp () +//instance taskImp (Code t p) +//instance taskImp (Code a p, Code b q) +//instance taskImp (Code a p, Code b q, Code c r) +//instance taskImp (Code a p, Code b q, Code c r, Code d s) +// +//tasksMain :: Int Int ((a->Code MTask Expr,b->Code MTask Expr) -> In (a->Code c d,b->Code e f) (Main (Code g h))) -> Main (Code i j) | taskImp a & types a & taskImp b & types b +//class types a :: a +//instance types () +//instance types (Code a p) | typeSelector a & isExpr p +//instance types (Code a p, Code b q) | typeSelector a & isExpr p & typeSelector b & isExpr q +//instance types (Code a p, Code b q, Code c r) | typeSelector a & isExpr p & typeSelector b & isExpr q & typeSelector c & isExpr r +//instance types (Code a p, Code b q, Code c r, Code d s) | typeSelector a & isExpr p & typeSelector b & isExpr q & typeSelector c & isExpr r & typeSelector d & isExpr s +// +//codeMTaskBody :: (Code v w) (Code c d) -> Code e f +//instance fun Code () +//instance fun Code (Code t p) | type, showType t & isExpr p +//instance fun Code (Code a p, Code b q) | showType a & showType b +//instance fun Code (Code a p, Code b q, Code c r) | showType a & showType b & showType c +//instance output Code +//instance pinMode Code +//instance digitalIO Code +//instance dIO Code +//instance aIO Code +//instance analogIO Code +//instance noOp Code +// +//:: Code a p = C ((ReadWrite (Code a Expr)) CODE -> CODE) +//:: CODE = +// { fresh :: Int +// , freshMTask :: Int +// , funs :: [String] +// , ifuns :: Int +// , vars :: [String] +// , ivars :: Int +// , setup :: [String] +// , isetup :: Int +// , loop :: [String] +// , iloop :: Int +// , includes :: [String] +// , def :: Def +// , mode :: Mode +// , binds :: [String] +// } +// +//unC :: (Code a p) -> ((ReadWrite (Code a Expr)) CODE -> CODE) +// +//:: Def = Var | Fun | Setup | Loop +//:: Mode = /*MainMode |*/ NoReturn | Return String | SubExp | Assign String +// +//setMode :: Mode -> Code a p +//getMode :: (Mode -> Code a p) -> Code a p +//embed :: (Code a p) -> Code a p +//(+.+) infixl 5 :: (Code a p) (Code b q) -> Code c r +//fresh :: (Int -> (Code a p)) -> (Code a p) +//freshMTask :: (Int -> (Code a p)) -> (Code a p) +//setCode :: Def -> (Code a p) +//getCode :: (Def -> Code a p) -> (Code a p) +//brac :: (Code a p) -> Code b q +//funBody :: (Code a p) -> Code b q +//codeOp2 :: (Code a p) String (Code b q) -> Code c r +//include :: String -> Code a b +//argList :: [a] -> String | toCode a +//c :: a -> Code b p | toCode a +//indent :: Code a p +//unindent :: Code a p +//nl :: Code a p +//setBinds :: [String] -> Code a p +//addBinds :: String -> Code a p +//getBinds :: ([String] -> Code a p) -> (Code a p) +// +//// ----- driver ----- // +// +//compile :: (Main (Code a p)) -> [String] +//mkset :: [a] -> [a] | Eq a +//newCode :: CODE diff --git a/mTaskInterpret.icl b/mTaskInterpret.icl new file mode 100644 index 0000000..eecea1d --- /dev/null +++ b/mTaskInterpret.icl @@ -0,0 +1,32 @@ +implementation module mTaskInterpret + +import iTasks +import gdynamic, gCons, GenEq, StdMisc, StdArray +import GenPrint +import mTask + + +toByteVal :: BC -> String +toByteVal a = undef + +derive gPrint BC + +toReadableByteVal :: BC -> String +toReadableByteVal a = printToString a + +instance arith ByteCode where + lit _ = undef + (+.) _ _ = undef + (-.) _ _ = undef + (*.) _ _ = undef + (/.) _ _ = undef + +instance serial ByteCode where + serialAvailable = undef + serialPrint _ = undef + serialPrintln _ = undef + serialRead = undef + serialParseInt = undef + +Start :: Main (ByteCode Int Expr) +Start = {main=serialPrint (lit 36)} -- 2.20.1