aboutsummaryrefslogtreecommitdiff
path: root/ABC
diff options
context:
space:
mode:
authorCamil Staps2017-07-18 20:50:08 +0000
committerCamil Staps2017-07-18 20:50:08 +0000
commit4d2c1f78e2cb61cdf0b087b6483cc15fbefa0ffa (patch)
tree8a2b5dc02bdcea37cd94d23311f3f938b6fd0ee7 /ABC
parentRaw instructions (diff)
Added divI
Diffstat (limited to 'ABC')
-rw-r--r--ABC/Assembler.dcl1
-rw-r--r--ABC/Assembler.icl1
-rw-r--r--ABC/Machine/BStack.dcl1
-rw-r--r--ABC/Machine/BStack.icl12
-rw-r--r--ABC/Machine/Instructions.dcl1
-rw-r--r--ABC/Machine/Instructions.icl4
6 files changed, 16 insertions, 4 deletions
diff --git a/ABC/Assembler.dcl b/ABC/Assembler.dcl
index acda095..cb83da9 100644
--- a/ABC/Assembler.dcl
+++ b/ABC/Assembler.dcl
@@ -80,6 +80,7 @@ from ABC.Machine.GraphStore import ::Desc
| Update_b BSrc BDst
| AddI
| DecI
+ | DivI
| GtI
| IncI
| LtI
diff --git a/ABC/Assembler.icl b/ABC/Assembler.icl
index 57ad36a..17104c4 100644
--- a/ABC/Assembler.icl
+++ b/ABC/Assembler.icl
@@ -194,6 +194,7 @@ where
trans (Update_b s d) _ _ = update_b s d
trans AddI _ _ = addI
trans DecI _ _ = decI
+ trans DivI _ _ = divI
trans GtI _ _ = gtI
trans IncI _ _ = incI
trans LtI _ _ = ltI
diff --git a/ABC/Machine/BStack.dcl b/ABC/Machine/BStack.dcl
index 488ed75..0af277b 100644
--- a/ABC/Machine/BStack.dcl
+++ b/ABC/Machine/BStack.dcl
@@ -27,6 +27,7 @@ bs_pushI :: Int BStack -> BStack
bs_update :: BDst Basic BStack -> BStack
bs_addI :: BStack -> BStack
bs_decI :: BStack -> BStack
+bs_divI :: BStack -> BStack
bs_incI :: BStack -> BStack
bs_eqB :: BStack -> BStack
bs_eqI :: BStack -> BStack
diff --git a/ABC/Machine/BStack.icl b/ABC/Machine/BStack.icl
index 624692e..70a1f1a 100644
--- a/ABC/Machine/BStack.icl
+++ b/ABC/Machine/BStack.icl
@@ -44,7 +44,7 @@ bs_init = []
bs_popn :: NrArgs BStack -> BStack
bs_popn 0 s = s
bs_popn _ [] = abortn "bs_popn: popping too many elements"
-bs_popn i [_:s] = bs_popn (i-1) s
+bs_popn i [_:s] = bs_popn (i - 1) s
bs_push :: Basic BStack -> BStack
bs_push d s = [d:s]
@@ -58,18 +58,22 @@ bs_pushI i s = [Int i:s]
bs_update :: BDst Basic BStack -> BStack
bs_update 0 d [_:s] = [d:s]
bs_update _ _ [] = abortn "bs_update: index too large"
-bs_update i d [e:s] = [e:bs_update (i-1) d s]
+bs_update i d [e:s] = [e:bs_update (i - 1) d s]
bs_addI :: BStack -> BStack
-bs_addI [Int m:Int n:s] = bs_pushI (m+n) s
+bs_addI [Int m:Int n:s] = bs_pushI (m + n) s
bs_addI _ = abortn "bs_addI: no integers"
bs_decI :: BStack -> BStack
bs_decI [Int n:s] = bs_pushI (n-1) s
bs_decI _ = abortn "bs_decI: no integer"
+bs_divI :: BStack -> BStack
+bs_divI [Int m:Int n:s] = bs_pushI (m / n) s
+bs_divI _ = abortn "bs_divI: no integers"
+
bs_incI :: BStack -> BStack
-bs_incI [Int n:s] = bs_pushI (n+1) s
+bs_incI [Int n:s] = bs_pushI (n + 1) s
bs_incI _ = abortn "bs_incI: no integer"
bs_eqB :: BStack -> BStack
diff --git a/ABC/Machine/Instructions.dcl b/ABC/Machine/Instructions.dcl
index 6c3c8b8..f0cc5b2 100644
--- a/ABC/Machine/Instructions.dcl
+++ b/ABC/Machine/Instructions.dcl
@@ -57,6 +57,7 @@ update_b :: BSrc BDst State -> State
addI :: State -> State
decI :: State -> State
+divI :: State -> State
gtI :: State -> State
incI :: State -> State
ltI :: State -> State
diff --git a/ABC/Machine/Instructions.icl b/ABC/Machine/Instructions.icl
index 911b999..3ca55af 100644
--- a/ABC/Machine/Instructions.icl
+++ b/ABC/Machine/Instructions.icl
@@ -365,6 +365,10 @@ decI :: State -> State
decI st=:{bstack}
= {st & bstack=bs_decI bstack}
+divI :: State -> State
+divI st=:{bstack}
+ = {st & bstack=bs_divI bstack}
+
gtI :: State -> State
gtI st=:{bstack}
= {st & bstack=bs_gtI bstack}