Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add multiplication to forth #1

Open
wants to merge 2 commits into from

2 participants

@bubaflub

Just a simple function to handle multiplication. I added it so I could run the first example from http://en.wikipedia.org/wiki/Forth_(programming_language):

25 10 * 50 + . cr

@leto
Owner

Can you add a test for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 10, 2011
  1. @bubaflub

    add multiplication operation

    bubaflub authored
  2. @bubaflub
This page is out of date. Refresh to see the latest.
Showing with 33 additions and 1 deletion.
  1. +25 −0 forth/words.pir
  2. +8 −1 t/math.t
View
25 forth/words.pir
@@ -463,6 +463,31 @@ END_PIR
.return()
.end
+# multiplication
+.sub '*'
+ .param pmc code
+ .param pmc stream
+ .param pmc stack
+
+ .local string a, b
+ b = pop stack
+ a = pop stack
+ $P0 = get_root_global ['parrot';'PGE';'Util'], 'unique'
+ $S0 = $P0('$P')
+ $S1 = $P0('$P')
+ $S2 = $P0('$P')
+
+ code.'append_format'(<<'END_PIR', b, a, $S0, $S1, $S2)
+ %2 = %0
+ %3 = %1
+ %4 = new 'Float'
+ %4 = %3 * %2
+END_PIR
+ push stack, $S2
+
+ .return()
+.end
+
# Local Variables:
# mode: pir
# fill-column: 100
View
9 t/math.t
@@ -8,6 +8,13 @@
3 + 5 +
15
-# <0>
+# <0>
5 -
10
+
+# multiplication
+5 *
+50
+
+2 *
+100
Something went wrong with that request. Please try again.