Skip to content
This repository
tree: 0c03d1f769
Fetching contributors…

Cannot retrieve contributors at this time

file 132 lines (115 sloc) 1.963 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
# Copyright (C) 2002-2009, Parrot Foundation.

#
# push number on befunge's stack.
# befunge stack:
# before: ...
# after: ... <number>
# no return value.
#
.sub maths__push_number
    $P0 = get_global "status"
    $S0 = $P0["char"]
    $I0 = $S0
    stack__push($I0)
.end


# ** math operations

#
# maths__add()
#
# addition.
# befunge stack:
# before: ... a b
# after: ... a+b
# no return value.
#
.sub "maths__add"
    $I1 = stack__pop()
    $I0 = stack__pop()
    $I2 = $I0 + $I1
    stack__push($I2)
.end


#
# maths__div()
#
# division.
# befunge stack:
# before: ... a b
# after: ... a/b
# no return value.
#
.sub "maths__div"
    $I1 = stack__pop()
    $I0 = stack__pop()
    if $I1 == 0 goto MATHS__DIV__BY_ZERO
    $I2 = $I0 / $I1
    stack__push($I2)
    .return()

  MATHS__DIV__BY_ZERO:
    stack__push(0)
.end


#
# maths__mod()
#
# modulus.
# befunge stack:
# before: ... a b
# after: ... a%b
# no return value.
#
.sub "maths__mod"
    $I1 = stack__pop()
    $I0 = stack__pop()
    $I2 = mod $I0, $I1
    stack__push($I2)
.end


#
# maths__mul()
#
# multiplication.
# befunge stack:
# before: ... a b
# after: ... a*b
# no return value.
# no return value.
#
.sub "maths__mul"
    $I1 = stack__pop()
    $I0 = stack__pop()
    $I2 = $I0 * $I1
    stack__push($I2)
.end


#
# maths__not()
#
# logical not.
# befunge stack:
# before: ... a
# after: ... not(a)
# no return value.
#
.sub "maths__not"
    $I0 = stack__pop()
    $I0 = not $I0
    stack__push($I0)
.end


#
# maths__sub()
#
# subtraction.
# befunge stack:
# before: ... a b
# after: ... a-b
# no return value.
#
.sub "maths__sub"
    $I1 = stack__pop()
    $I0 = stack__pop()
    $I2 = $I0 - $I1
    stack__push($I2)
.end


########################################################################
# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir:
Something went wrong with that request. Please try again.