diff options
author | Camil Staps | 2016-07-01 19:37:38 +0200 |
---|---|---|
committer | Camil Staps | 2016-07-01 19:37:38 +0200 |
commit | b3f1e3ff0404a5182b6eed2d88014b4b4fbd69c2 (patch) | |
tree | c2dbd5b0a43fffc6119510bdc2f5324aa3a0e3b5 /ABC/CStack.icl | |
parent | Assembler (diff) |
Moved to directory, added test program
Diffstat (limited to 'ABC/CStack.icl')
-rw-r--r-- | ABC/CStack.icl | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/ABC/CStack.icl b/ABC/CStack.icl new file mode 100644 index 0000000..74ca885 --- /dev/null +++ b/ABC/CStack.icl @@ -0,0 +1,26 @@ +implementation module ABC.CStack + +import StdEnv + +import ABC.Def +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] |