Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion stack language for Parrot
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Michel Pelletier  
View profile  
 More options Jun 30 2004, 12:45 am
Newsgroups: perl.perl6.internals
From: mic...@dialnetwork.com (Michel Pelletier)
Date: Tue, 29 Jun 2004 21:45:12 -0700
Local: Wed, Jun 30 2004 12:45 am
Subject: stack language for Parrot

I've been lurking on this list for a while and playing with Parrot.  I
have created a little stack language not entirely unlike Forth I've come
to calling Parakeet.  Consider the most trivial example:

0> 2 2 + println
4
0>

Two integers are pushed on the stack, the word "+" adds them leaving the
result on the stack which the word "println" prints on its own line.

New words can be defined with 'def ... end':

0> def square dup * end
0> 16 square println
256
0>

This defines the word "square" whose body is composed of "dup *". New
words are compiled directly to PIR.  You can see the PIR code of defined
words with "see":

0> see square
.include "languages/parakeet/macros.imc"
.sub _square
.POP
.PUSH
.PUSH
.POP2
.TOS = .NOS * .TOS
.PUSH
ret
.end
0>

(Obviously this is not the most optimal code, but could easily be
optimized to cache the top two stack elements in registers at all
times).

There is some primitive support for pmc objects with "findtype" and
"new":

0> "PerlInt" findtype new println
0
0>

The string "PerlInt" is pushed on the stack, the word "findtype" finds
the type code and pushes it on the stack, which is instantiated with
"new".  These words map to their Parrot opcode equivalents.  Simple
variables can be created with the word "var"

0> 4 var x
0> x println
4
0>

Parakeet is a stack language like Forth but is very machine specific to
Parrot.  There are no "cells" or access to "memory", the stack is
heterogeneous and can hold any PMC.  There is no return stack, since
Parrot handles that with 'jsr ... ret'.

Flow control currently consists of 'if/then' and 'do/loop':

0> def decide if 5 then end
0> 1 decide println
5
0> 0 decide
0>

The word "decide" pushes the integer 5 onto the stack if the top of the
stack is true, it does nothing otherwise.  Here is its PIR:

0> see decide
.include "languages/parakeet/macros.imc"
.sub _decide
.POP
unless .TOS, endif2
.TOS = new .PerlInt
.TOS = 1
.PUSH
endif2:
ret
.end

Parakeet is incomplete, but I'd like to keep working on it if the Parrot
team is interested in another language.  I have run up against some
problems, however, that I have been unable to solve or find solutions
for in the docs.  For example:

0> def shoot do "bang" println loop end
0> see shoot
.include "languages/parakeet/macros.imc"
.sub _shoot
.POP2
push .CSTACK, .NOS
push .CSTACK, .TOS
do2:
.TOS = new .PerlString
.TOS = "bang"
.PUSH
.POP
print .TOS
print "\n"
pop .TOS, .CSTACK
pop .NOS, .CSTACK
inc .TOS
push .CSTACK, .NOS
push .CSTACK, .TOS
ne .TOS, .NOS,  do2
pop .TOS, .CSTACK
pop .NOS, .CSTACK
ret
.end
0>

The word "shoot" should print the string "bang" inside a loop whose
limit and start are on the data stack (in the above code, the CSTACK is
the control stack to hold the current loop values, not the data stack):

0> 4 0 shoot
pop .NOS, .CSTACK
findtypepop .NOS, .CSTACK
findtypepop .NOS, .CSTACK
findtypepop .NOS, .CSTACK
findtype0>

It does print four things, but not the four things I was expecting!  I
have having some other problems with resolving variables names:

0> def bob var x end
0> see bob
.include "languages/parakeet/macros.imc"
.sub _bob
.POP
.VARS["x"] = .TOS
ret
.end

Now when I try to run it:

0> 4 bob
Key not a string!
[michel@parrot]$

I suspect maybe these two problems are related.  Anyone spot it?  Cuz
I'm stumped.

If you are interested in playing with it and seeing what it is all about
I have attached the two .imc files that you need to run it.  Just put
the two files in languages/parakeet and point Parrot to parakeet.imc and
you will get the interpreter prompt.

In my analysis I've found the Parrot VM to be very cool and quite fast.
I've had a lot of experience with the Python VM and it's "C loop"
interpreter design.

I have no idea how the two currently compare (but soon we'll find out
which way the pie flies ;) but it looks to me that Parrot's JIT
compiling VM with lots of on-processor register space is going to
present some clear competition to Python's stack-based VM implemented in
a C loop.  No matter who wins at OSCON the Python VM will have to
embrace these optimizations to remain viable.  We'll see.

-Michel

  macros.imc
1K Download

  parakeet.imc
10K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.