Author: jquelin
Date: Fri Jan 9 02:22:33 2009
New Revision: 35267
Modified:
trunk/languages/befunge/befunge.pir
trunk/languages/befunge/flow.pir
Log:
instruction ` implemented (compare)
Modified: trunk/languages/befunge/befunge.pir
==============================================================================
--- trunk/languages/befunge/befunge.pir (original)
+++ trunk/languages/befunge/befunge.pir Fri Jan 9 02:22:33 2009
@@ -89,6 +89,7 @@
if char == '<' goto FLOW_GO_WEST
# flow control
+ if char == '`' goto FLOW_COMPARE
if char == '_' goto FLOW_IF_HORIZONTAL
if char == '|' goto FLOW_IF_VERTICAL
if char == '#' goto FLOW_BRIDGE
@@ -117,7 +118,7 @@
=pod
# Flow control.
- eq S0, "`", FLOW_COMPARE
+ #eq S0, "`", FLOW_COMPARE
#eq S0, "_", FLOW_EW_IF
#eq S0, "|", FLOW_NS_IF
#eq S0, "#", FLOW_BRIDGE
@@ -150,6 +151,9 @@
FLOW_BRIDGE:
flow__trampoline(1)
goto MOVE_PC
+ FLOW_COMPARE:
+ flow__compare()
+ goto MOVE_PC
FLOW_GO_EAST:
flow__go_east()
goto MOVE_PC
Modified: trunk/languages/befunge/flow.pir
==============================================================================
--- trunk/languages/befunge/flow.pir (original)
+++ trunk/languages/befunge/flow.pir Fri Jan 9 02:22:33 2009
@@ -48,6 +48,29 @@
# ** ifs & comparisons
#
+# flow__compare()
+#
+# greater than.
+# befunge stack:
+# before: ... a b
+# after: ... a>b
+# result is either 1 or 0.
+#
+.sub "flow__compare"
+ .local int a, b
+ b = stack__pop()
+ a = stack__pop()
+
+ if a < b goto FLOW__COMPARE__FALSE
+ stack__push(1)
+ .return()
+
+ FLOW__COMPARE__FALSE:
+ stack__push(0)
+.end
+
+
+#
# flow__if_horizontal()
#
# east/west if.
@@ -144,27 +167,6 @@
-# Greater than.
-# Befunge stack:
-# before: ... a b
-# after: ... a>b
-# Result is either 1 or 0.
-FLOW_COMPARE:
- set I10, P2
- unless I10, FLOW_COMPARE_POP_1
- pop I10, P2
-FLOW_COMPARE_POP_1:
- set I11, P2
- unless I11, FLOW_COMPARE_POP_2
- pop I11, P2
-FLOW_COMPARE_POP_2:
- set I12, 1
- gt I11, I10, FLOW_COMPARE_TRUE
- set I12, 0
-FLOW_COMPARE_TRUE:
- push P2, I12
- branch MOVE_PC
-
# Stop.