From ceb0b74bd0b368124679378ebfb2cf316deb2e39 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Tue, 5 Jul 2016 17:25:10 +0200 Subject: Added Machine as module level --- ABC/Machine/CStack.icl | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 ABC/Machine/CStack.icl (limited to 'ABC/Machine/CStack.icl') diff --git a/ABC/Machine/CStack.icl b/ABC/Machine/CStack.icl new file mode 100644 index 0000000..51c1562 --- /dev/null +++ b/ABC/Machine/CStack.icl @@ -0,0 +1,26 @@ +implementation module ABC.Machine.CStack + +import StdEnv + +import ABC.Machine +import ABC.Misc + +:: CStack :== [InstrId] + +instance toString CStack where toString xs = "[" <++ (",", xs) <+ "]" + +cs_init :: CStack +cs_init = [] + +cs_get :: CSrc CStack -> InstrId +cs_get _ [] = abortn "cs_get: index too large" +cs_get 0 [i:_] = i +cs_get i [_:s] = cs_get (i-1) s + +cs_popn :: CSrc CStack -> CStack +cs_popn 0 s = s +cs_popn _ [] = abortn "cs_popn: popping too many elements" +cs_popn i [_:s] = cs_popn (i-1) s + +cs_push :: InstrId CStack -> CStack +cs_push i s = [i:s] -- cgit v1.2.3