cvsuser     02/11/24 13:17:34

  Modified:    languages/Befunge-93 Changes README flow.pasm io.pasm
                        maths.pasm stack.pasm
  Log:
  befunge now supports the push and
  pop instructions builtin in PerlArray PMC, and I can get rid of my own
  crafted version of push and pop in Parrot Assembly.
  Fear, cause now I'll be able to find even more bugs! :-)
  
  Courtesy of Jerome Quelin <[EMAIL PROTECTED]>
  
  (Committed with the appropriate amount of fear... :)
  
  Revision  Changes    Path
  1.2       +5 -0      parrot/languages/Befunge-93/Changes
  
  Index: Changes
  ===================================================================
  RCS file: /cvs/public/parrot/languages/Befunge-93/Changes,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -w -r1.1 -r1.2
  --- Changes   14 Sep 2002 13:56:44 -0000      1.1
  +++ Changes   24 Nov 2002 21:17:34 -0000      1.2
  @@ -1,5 +1,10 @@
   Revision history for Befunge-93 interpreter written for Parrot.
   
  +0.04  Sat Nov 23 10:22:51 CET 2002
  +        - now using the push and pop instructions of the PerlArray
  +          PMC, and thanks go to Steve Fink for his hack to pop an
  +          empty PerlArray.
  +
   0.03  Mon Sep  9 21:26:11 CEST 2002
           - taking advantage of Parrot's 'chr' instruction, getting rid
             of Clinton Pierce's hack.
  
  
  
  1.4       +4 -5      parrot/languages/Befunge-93/README
  
  Index: README
  ===================================================================
  RCS file: /cvs/public/parrot/languages/Befunge-93/README,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -w -r1.3 -r1.4
  --- README    14 Sep 2002 13:56:44 -0000      1.3
  +++ README    24 Nov 2002 21:17:34 -0000      1.4
  @@ -1,13 +1,13 @@
   DESCRIPTION
   -----------
  -This is a Befunge interpreter written in Parrot assembler, version 0.03
  +This is a Befunge interpreter written in Parrot assembler, version 0.04
   
   This interpreter should be Befunge-93 compliant. This means the
   playfield is limited to 80x25 and can hold *only bytes*. This means
   that you can't fetch/store numbers greater than 255 or less than 0 in
   the torus (even if I do not check for over/underflow - for now).
   
  -You should compile the files with:
  +You should compile and test the files with:
   
        $ make test
   
  @@ -26,8 +26,7 @@
           flow.pasm       handles the flow-control instructions
           io.pasm         handles the io related instructions
           maths.pasm      handles all the maths instructions
  -        stack.pasm      handles the stack operations as well as stack
  -                        instructions
  +        stack.pasm      handles the stack instructions
           Makefile        a tiny, little Makefile to help (me) during
                           developement
           test.bef        a befunge script that test almost all the
  
  
  
  1.2       +17 -10    parrot/languages/Befunge-93/flow.pasm
  
  Index: flow.pasm
  ===================================================================
  RCS file: /cvs/public/parrot/languages/Befunge-93/flow.pasm,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -w -r1.1 -r1.2
  --- flow.pasm 17 Aug 2002 00:18:34 -0000      1.1
  +++ flow.pasm 24 Nov 2002 21:17:34 -0000      1.2
  @@ -43,8 +43,10 @@
   #   after:      ...
   # delta <- if (b) (-1,0) else (1,0)
   FLOW_EW_IF:
  -        bsr POP
  -        restore I10
  +        set I10, P2
  +        unless I10, FLOW_EW_IF_POP_1
  +        pop I10, P2
  +FLOW_EW_IF_POP_1:       
           eq I10, 0, FLOW_GO_EAST
           branch FLOW_GO_WEST
   
  @@ -54,8 +56,10 @@
   #   after:      ...
   # delta <- if (b) (0,-1) else (0,1)
   FLOW_NS_IF:
  -        bsr POP
  -        restore I10
  +        set I10, P2
  +        unless I10, FLOW_NS_IF_POP_1
  +        pop I10, P2
  +FLOW_NS_IF_POP_1:       
           eq I10, 0, FLOW_GO_SOUTH
           branch FLOW_GO_NORTH
   
  @@ -67,16 +71,19 @@
   # Result is either 1 or 0.
   FLOW_COMPARE:
           pushi
  -        bsr POP
  -        restore I10
  -        bsr POP
  -        restore I11
  +        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:
  -        save I12
  -        bsr PUSH
  +        push P2, I12
           popi
           branch MOVE_PC
           
  
  
  
  1.3       +32 -22    parrot/languages/Befunge-93/io.pasm
  
  Index: io.pasm
  ===================================================================
  RCS file: /cvs/public/parrot/languages/Befunge-93/io.pasm,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -w -r1.2 -r1.3
  --- io.pasm   14 Sep 2002 13:56:44 -0000      1.2
  +++ io.pasm   24 Nov 2002 21:17:34 -0000      1.3
  @@ -6,8 +6,7 @@
   IO_PUSH_CHAR:
           pushi
           ord I10, S0
  -        save I10
  -        bsr PUSH
  +        push P2, I10
           popi
           branch MOVE_PC
   
  @@ -39,8 +38,7 @@
           set I11, 0
   IO_INPUT_INT_NAN:
           substr S2, S2, I11, I10
  -        save I10
  -        bsr PUSH
  +        push P2, I10
           pops
           popi
           branch MOVE_PC
  @@ -63,8 +61,7 @@
           length I10, S2
           substr S2, S2, 1, I10
           ord I10, S10
  -        save I10
  -        bsr PUSH
  +        push P2, I10
           save S2
           pops
           restore S2
  @@ -78,8 +75,10 @@
   # writeint(i)
   IO_OUTPUT_INT:
           pushi
  -        bsr POP
  -        restore I10
  +        set I10, P2
  +        unless I10, IO_OUTPUT_INT_POP_1
  +        pop I10, P2
  +IO_OUTPUT_INT_POP_1:    
           print I10
           popi
           branch MOVE_PC
  @@ -92,8 +91,10 @@
   IO_OUTPUT_CHAR:
           pushi
           pushs
  -        bsr POP
  -        restore I10
  +        set I10, P2
  +        unless I10, IO_OUTPUT_CHAR_POP_1
  +        pop I10, P2
  +IO_OUTPUT_CHAR_POP_1:   
           chr S10, I10
           print S10
           popi
  @@ -108,14 +109,17 @@
   IO_GET_VALUE:
           pushi
           pushs
  -        bsr POP
  -        restore I11
  -        bsr POP
  -        restore I10
  +        set I11, P2
  +        unless I11, IO_GET_VALUE_POP_1
  +        pop I11, P2
  +IO_GET_VALUE_POP_1:
  +        set I10, P2
  +        unless I10, IO_GET_VALUE_POP_2
  +        pop I10, P2
  +IO_GET_VALUE_POP_2:     
           set S10, P1[I11]
           ord I12, S10, I10
  -        save I12
  -        bsr PUSH
  +        push P2, I12
           pops
           popi
           branch MOVE_PC
  @@ -128,13 +132,19 @@
   IO_PUT_VALUE:
           pushi
           pushs
  -        bsr POP
  -        restore I11
  +        set I11, P2
  +        unless I11, IO_PUT_VALUE_POP_1
  +        pop I11, P2
  +IO_PUT_VALUE_POP_1:     
           set S10, P1[I11]        # original line
  -        bsr POP
  -        restore I10             # offset
  -        bsr POP
  -        restore I20
  +        set I10, P2             # offset
  +        unless I10, IO_PUT_VALUE_POP_2
  +        pop I10, P2
  +IO_PUT_VALUE_POP_2:
  +        set I20, P2
  +        unless I20, IO_PUT_VALUE_POP_3
  +        pop I20, P2
  +IO_PUT_VALUE_POP_3:     
           chr S11, I20            # char to store
        length I12, S10
        set S13, ""             # First part
  
  
  
  1.2       +51 -36    parrot/languages/Befunge-93/maths.pasm
  
  Index: maths.pasm
  ===================================================================
  RCS file: /cvs/public/parrot/languages/Befunge-93/maths.pasm,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -w -r1.1 -r1.2
  --- maths.pasm        17 Aug 2002 00:18:34 -0000      1.1
  +++ maths.pasm        24 Nov 2002 21:17:34 -0000      1.2
  @@ -29,8 +29,7 @@
   MATHS_PUSH_NUMBER:
           pushi
           set I10, S0
  -        save I10
  -        bsr PUSH
  +        push P2, I10
           popi
           branch MOVE_PC
   
  @@ -40,13 +39,16 @@
   #   after:      ... a+b
   MATHS_ADD:
           pushi
  -        bsr POP
  -        restore I11
  -        bsr POP
  -        restore I10
  +        set I11, P2
  +        unless I11, MATHS_ADD_POP_1
  +        pop I11, P2
  +MATHS_ADD_POP_1:
  +        set I10, P2
  +        unless I10, MATHS_ADD_POP_2
  +        pop I10, P2
  +MATHS_ADD_POP_2:        
           add I12, I10, I11
  -        save I12
  -        bsr PUSH
  +        push P2, I12
           popi
           branch MOVE_PC
           
  @@ -56,13 +58,16 @@
   #   after:      ... a-b
   MATHS_SUB:
           pushi
  -        bsr POP
  -        restore I11
  -        bsr POP
  -        restore I10
  +        set I11, P2
  +        unless I11, MATHS_SUB_POP_1
  +        pop I11, P2
  +MATHS_SUB_POP_1:
  +        set I10, P2
  +        unless I10, MATHS_SUB_POP_2
  +        pop I10, P2
  +MATHS_SUB_POP_2:        
           sub I12, I10, I11
  -        save I12
  -        bsr PUSH
  +        push P2, I12
           popi
           branch MOVE_PC
   
  @@ -72,13 +77,16 @@
   #   after:      ... a*b
   MATHS_MUL:
           pushi
  -        bsr POP
  -        restore I11
  -        bsr POP
  -        restore I10
  +        set I11, P2
  +        unless I11, MATHS_MUL_POP_1
  +        pop I11, P2
  +MATHS_MUL_POP_1:
  +        set I10, P2
  +        unless I10, MATHS_MUL_POP_2
  +        pop I10, P2
  +MATHS_MUL_POP_2:        
           mul I12, I10, I11
  -        save I12
  -        bsr PUSH
  +        push P2, I12
           popi
           branch MOVE_PC
   
  @@ -88,13 +96,16 @@
   #   after:      ... a/b
   MATHS_DIV:
           pushi
  -        bsr POP
  -        restore I11
  -        bsr POP
  -        restore I10
  +        set I11, P2
  +        unless I11, MATHS_DIV_POP_1
  +        pop I11, P2
  +MATHS_DIV_POP_1:
  +        set I10, P2
  +        unless I10, MATHS_DIV_POP_2
  +        pop I10, P2
  +MATHS_DIV_POP_2:        
           div I12, I10, I11
  -        save I12
  -        bsr PUSH
  +        push P2, I12
           popi
           branch MOVE_PC
   
  @@ -104,13 +115,16 @@
   #   after:      ... a mod b
   MATHS_MOD:
           pushi
  -        bsr POP
  -        restore I11
  -        bsr POP
  -        restore I10
  +        set I11, P2
  +        unless I11, MATHS_MOD_POP_1
  +        pop I11, P2
  +MATHS_MOD_POP_1:
  +        set I10, P2
  +        unless I10, MATHS_MOD_POP_2
  +        pop I10, P2
  +MATHS_MOD_POP_2:        
           mod I12, I10, I11
  -        save I12
  -        bsr PUSH
  +        push P2, I12
           popi
           branch MOVE_PC
   
  @@ -120,10 +134,11 @@
   #   after:      ... not(a)
   MATHS_NOT:
           pushi
  -        bsr POP
  -        restore I10
  +        set I10, P2
  +        unless I10, MATHS_NOT_POP_1
  +        pop I10, P2
  +MATHS_NOT_POP_1:        
           not I10, I10
  -        save I10
  -        bsr PUSH
  +        push P2, I10
           popi
           branch MOVE_PC
  
  
  
  1.2       +20 -47    parrot/languages/Befunge-93/stack.pasm
  
  Index: stack.pasm
  ===================================================================
  RCS file: /cvs/public/parrot/languages/Befunge-93/stack.pasm,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -w -r1.1 -r1.2
  --- stack.pasm        17 Aug 2002 00:18:34 -0000      1.1
  +++ stack.pasm        24 Nov 2002 21:17:34 -0000      1.2
  @@ -1,46 +1,15 @@
  -# Push an integer in Befunge's stack.
  -# The integer is popped from Parrot's stack.
  -# Generic method.
  -PUSH:
  -        pushi
  -        restore I6
  -        set I7, P2
  -        set P2[I7], I6
  -        popi
  -        ret
  -
  -# Pop an integer from Befunge's stack.
  -# the integer is pushed on Parrot's stack.
  -# Generic method.
  -POP:
  -        pushi
  -        set I7, P2
  -        eq I7, 0, POP_EMPTY
  -        dec I7
  -        set I6, P2[I7]
  -        save I6
  -        set P2, I7
  -        popi
  -        ret
  -
  -POP_EMPTY:      
  -        set I10, 0
  -        save I10
  -        popi
  -        ret
  -
   # Duplicate.
   # Befunge stack:        
   #   before:     ... v
   #   after:      ... v 
   STACK_DUP:
           pushi
  -        bsr POP
  -        restore I10
  -        save I10
  -        bsr PUSH
  -        save I10
  -        bsr PUSH
  +        set I10, P2
  +        unless I10, STACK_DUP_POP_1
  +        pop I10, P2
  +STACK_DUP_POP_1:        
  +        push P2, I10
  +        push P2, I10
           popi
           branch MOVE_PC
   
  @@ -51,8 +20,10 @@
   # Element is just discarded.
   STACK_POP:
           pushi
  -        bsr POP
  -        restore I10
  +        set I10, P2
  +        unless I10, STACK_POP_POP_1
  +        pop I10, P2
  +STACK_POP_POP_1:
           popi
           branch MOVE_PC
           
  @@ -62,13 +33,15 @@
   #   after:      ... b a
   STACK_SWAP:
           pushi
  -        bsr POP
  -        restore I10
  -        bsr POP
  -        restore I11
  -        save I10
  -        bsr PUSH
  -        save I11
  -        bsr PUSH
  +        set I10, P2
  +        unless I10, STACK_SWAP_POP_1
  +        pop I10, P2
  +STACK_SWAP_POP_1:
  +        set I11, P2
  +        unless I11, STACK_SWAP_POP_2
  +        pop I11, P2
  +STACK_SWAP_POP_2:       
  +        push P2, I10
  +        push P2, I11
           popi
           branch MOVE_PC
  
  
  


Reply via email to