develooper Front page | perl.perl6.internals | Postings from April 2002

Parrot BASIC version .02, now with GAMES!

From:
Clinton A. Pierce
Date:
April 1, 2002 15:04
Subject:
Parrot BASIC version .02, now with GAMES!
Message ID:
5.1.0.14.2.20020401172549.00a84cd0@www.geeksalad.org
I'm well aware of the date, but this is no April Fool's Joke.  (Well 
perhaps it is, but the joke would be on me.)  A new version of BASIC can be 
found at http://geeksalad.org/basic

This BASIC has a few interesting things over the last one.  I/O now works 
(INPUT, LOAD, etc...) as well as interactive mode (a nice friendly Ready 
prompt).  The expression parser is fully-functional now with functions, 
variable lookups, etc... There's a nice infix->postfix converter buried in 
there too.  The programs "sample2" and "sample3" show off some of the 
language features.

Best of all, if you can get it to load, Hunt the Wumpus in BASIC is now 
functional and playable.  To get started, compile up a recent version of 
Parrot, and run the script "basic.pl" (it's just assembling the necessary 
pieces, handing off to assemble.pl, and running the result):

	Ready
           LOAD wumpus         <-- type this

           Ready
           RUN                        <-- type this

And you should be back in 1975 again.  The only porting that had to be done 
for the code to work from David Ahl's original was to remove some DIM 
statements, change <> to !, and convert ON GOTO to a different structure.

In other words: I'm done.  :)

I may add features later, but essentially it works.  As Parrot gets better 
this will get more reliable.  Speed will improve when I figure out -- and 
they get written -- some of Parrot's more sophisticated data structures 
like arrays.


*** Notes for Parrot developers ***
There's still string/stack/GC bugs in Parrot somewhere.  In most cases, if 
the interpreter survives the LOAD process, then the BASIC program will run 
normally (and forever) without a hitch.  Once loaded, BASIC tends to use 
and re-use the same space over and over again (thus, not allocating new 
memory).

LOAD reads a file, splits the input buffer on \n, shoves lines onto the 
stack, and sorts the stack by line number.  Sometimes Parrot does not 
survive this.  The problem manifests itself as one of two errors:

    * LOAD triggers a SEGV
    * LOAD displays a spurious:
                    LOADING sampleb.bas...Cannot take substr outside string
      (The error is probably legit, but it's because the input buffer is 
now trashed.)

Curiously, re-arranging statements near the LOAD a bit causes the errors to 
go away and pop up elsewhere.   Bummer.




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