develooper Front page | perl.cvs.parrot | Postings from January 2009

[svn:parrot] r35166 - trunk/languages/befunge

From:
jquelin
Date:
January 7, 2009 10:39
Subject:
[svn:parrot] r35166 - trunk/languages/befunge
Message ID:
20090107183905.13403CB9F9@x12.develooper.com
Author: jquelin
Date: Wed Jan  7 10:39:04 2009
New Revision: 35166

Modified:
   trunk/languages/befunge/befunge.pir
   trunk/languages/befunge/maths.pir

Log:
instructions 0-9 implemented (push number)


Modified: trunk/languages/befunge/befunge.pir
==============================================================================
--- trunk/languages/befunge/befunge.pir	(original)
+++ trunk/languages/befunge/befunge.pir	Wed Jan  7 10:39:04 2009
@@ -71,10 +71,16 @@
     debug__check_breakpoint()
     
   TICK_NODEBUG:
+    # flags handling
     if char == '"' goto FLOW_TOGGLE_STRING_MODE
     if flag == 1   goto IO_PUSH_CHAR
+    if flag == 2   goto FLOW_TRAMPOLINE
+    if flag == 3   goto END
     
     # sole number
+    if char <  '0' goto NOT_NUM
+    if char <= '9' goto MATHS_PUSH_NUMBER
+  NOT_NUM:
     
     # direction changing
     if char == '>' goto FLOW_GO_EAST
@@ -88,16 +94,6 @@
 =pod
 
 
-        eq S0, "\"", FLOW_TOGGLE_STRING_MODE
-        eq I4, 1, IO_PUSH_CHAR
-        eq I4, 2, MAIN_TRAMPOLINE
-        eq I4, 3, MAIN_END
-
-        # Sole number.
-        lt S0, "0", NOT_NUM
-        le S0, "9", MATHS_PUSH_NUMBER
-NOT_NUM:
-
         # Direction changing.
         eq S0, "^", FLOW_GO_NORTH
         eq S0, ">", FLOW_GO_EAST
@@ -160,6 +156,12 @@
     io__push_char()
     goto MOVE_PC
 
+    # maths instructions
+  MATHS_PUSH_NUMBER:
+    maths__push_number()
+    goto MOVE_PC
+    
+    
     # instruction executed, now move the pc
     
   MOVE_PC:
@@ -198,7 +200,7 @@
     set_global "status", status
     goto TICK
 
-  MAIN_END:
+  END:
     end
 .end
 

Modified: trunk/languages/befunge/maths.pir
==============================================================================
--- trunk/languages/befunge/maths.pir	(original)
+++ trunk/languages/befunge/maths.pir	Wed Jan  7 10:39:04 2009
@@ -2,6 +2,24 @@
 
 .macro_const RANDMAX 65536.0
 
+
+#
+# push number on befunge's stack.
+# befunge stack:
+#   before:     ...
+#   after:      ... <number>
+.sub maths__push_number
+    $P0 = get_global "status"
+    $P1 = get_global "stack"
+
+    $S0 = $P0["char"]
+    $I0 = $S0
+    push $P1, $I0
+
+    set_global "stack", $P1
+.end
+
+
 =pod
 
 # Create a pseudo-random number.
@@ -23,14 +41,6 @@
     save I10
     ret
 
-# Push number on Befunge's stack.
-# Befunge Stack:
-#   before:     ...
-#   after:      ... <number>
-MATHS_PUSH_NUMBER:
-    set I10, S0
-    push P2, I10
-    branch MOVE_PC
 
 # Addition.
 # Befunge Stack:



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About