Omnimaga

Calculator Community => Other Calc-Related Projects and Ideas => TI Z80 => Topic started by: Michael_Lee on December 20, 2011, 02:33:19 pm

Title: Axe Interpreter
Post by: Michael_Lee on December 20, 2011, 02:33:19 pm
Edit: Links to latest updates at bottom of post.

I was bored, so I tried making an implementation of Axe Parser in Python.  It currently only supports a very limited subset of Axe (only a few tokens, no pointers, strings, subroutines, HL madness, etc), but I thought this would be a good project to try this Christmas break.

It has both an interpreter mode, where you can type commands in on the fly, and a mode to execute from a text file.  It currently will not open 8xp files -- given the small number of tokens I support, it wouldn't even be useful at this point anyways.



This should be compatible with all major OSes, but was tested on Windows 7 and Linux Mint. 
No .exes, sorry -- you need Python 2.7 and Pygame.

To run the interpreter, type
Code: [Select]
$ python source/main.py --interpreter
To run a text file, type
Code: [Select]
$ python source/main.py myfile.txt
A full list of supported tokens and other miscellaneous details can be found in the readme.


Note: I'm not really fond of the name 'Axe Interpreter' -- can anybody think up a better one?



### EDIT -- Latest releases: ###

Title: Re: Axe Interpreter
Post by: Sorunome on December 20, 2011, 02:46:02 pm
Nice Idea, I like it!/me might try some time
Title: Re: Axe Interpreter
Post by: DJ Omnimaga on December 20, 2011, 02:51:32 pm
Hmm seems interesting. I hope it runs commands exactly like the calc counterparts, although in the future it would be cool if it was extended for computer usage too, such as higher resolution and stuff. :D

This project kinda reminds me of Basic++ by Miotatsu actually. He tried making a TI-83+ BASIC interpreter in C++, but he lost the entire source. :(
Title: Re: Axe Interpreter
Post by: Michael_Lee on December 20, 2011, 02:59:01 pm
Hmm seems interesting. I hope it runs commands exactly like the calc counterparts, although in the future it would be cool if it was extended for computer usage too, such as higher resolution and stuff. :D

This project kinda reminds me of Basic++ by Miotatsu actually. He tried making a TI-83+ BASIC interpreter in C++, but he lost the entire source. :(

Yeah, that's kind of what I want to turn this into.  Ideally, my version should be able to run Axe source code and make it look exactly as it does on the calculator, although I have a long ways to go before I hit that point :|

Changing the resolution -- that might actually be a neat idea.  I'll look into trying something like that.
Title: Re: Axe Interpreter
Post by: epic7 on December 20, 2011, 03:19:28 pm
Need two other programs in order to run?
Gosh, darnit! :P

Looks awesome, anyways :D
Title: Re: Axe Interpreter
Post by: Quigibo on December 20, 2011, 03:36:03 pm
Wow cool!  If you need any help about how I implement any complicated commands feel free to ask and I can explain :)
Title: Re: Axe Interpreter
Post by: TIfanx1999 on December 20, 2011, 08:22:06 pm
No .exes, sorry -- you need Python 2.7 and Pygame.

Wow, I know I've been on Omnimaga too long when I read the above sentence as:
Quote
No .exes, sorry -- you need Python 2.7 and Thegame.
Seriously, I think I need to have my head examined... x.x

Anyhow... This looks pretty sweet. At first glance I though it might be an on calc interpreter that ran Axe programs in a way similar to how Grammer works. I know a few people have mentioned attempting such a thing. Cool project though. :)
Title: Re: Axe Interpreter
Post by: epic7 on December 20, 2011, 08:25:49 pm
I have python but it wont open.
Title: Re: Axe Interpreter
Post by: saintrunner on December 20, 2011, 08:30:42 pm
What parts not opening? the GUI? Command Line?
Title: Re: Axe Interpreter
Post by: epic7 on December 20, 2011, 08:39:20 pm
Click on the compiled code, a black thing shows up, then dissapears.
Title: Re: Axe Interpreter
Post by: saintrunner on December 20, 2011, 08:43:14 pm
So a command line? What did you use to compile?
Title: Re: Axe Interpreter
Post by: Michael_Lee on December 20, 2011, 08:47:42 pm
Woah, what?  What compiled code?

Go to the command line, navigate over to where the extracted axe-interpreter folder is, then type
Code: [Select]
python source/main.py --interpret
Hmm, on second thought, maybe it would be better to have double clicking open the interpreter without needed anything appended...
Title: Re: Axe Interpreter
Post by: epic7 on December 20, 2011, 08:50:14 pm
I have no idea what to do.
Title: Re: Axe Interpreter
Post by: Michael_Lee on December 20, 2011, 08:51:49 pm
If you wait about 10-20 minutes, I can make exes for both Linux and Windows.
Title: Re: Axe Interpreter
Post by: epic7 on December 20, 2011, 08:52:49 pm
Ok. It would take me more than 20 minutes to figure it out by my random button-smashing technique that I'm using now. :P
Title: Re: Axe Interpreter
Post by: saintrunner on December 20, 2011, 08:53:44 pm
HEY THAT'S MY TECHNIQUE!! lol :P
Title: Re: Axe Interpreter
Post by: Michael_Lee on December 20, 2011, 09:15:16 pm
Scratch that -- longer then 10 mins.  I thought I had pyInstaller or cx_freeze all set up and everything, but that doesn't seem to be the case :P.

Plus, parents are calling for dinner.
Title: Re: Axe Interpreter
Post by: alberthrocks on December 20, 2011, 11:20:55 pm
Well, I've tested it and it simply doesn't work, so....
But either way, I had a PyInstaller environment set up for Croquette building and testing, so I easily translated over my build script for this project! :)

Here's my script:
Code: [Select]
:: This is where PyInstaller is located on your computer. It should be the stable (1.5.x) version!
:: Do NOT use the trunk version; it will NOT work.
@set PYINSTALLER_PATH=C:\Users\arthur\Documents\pyinstaller-1.5.1
:: This is where you want the build files to be. You should set this to the source dir\build directory, but you're free
:: to choose any directory you wish - just make sure it exists.
@set BUILD_DIR=C:\SourceCode\axeinterpreter\build
:: File to compile (this should be the main one)
@set TO_COMPILE=C:\SourceCode\axeinterpreter\source\main.py
:: Basename of Python file that you're compiling - for example:
::    Compiling C:\bla\bla\bla\interesting.py
::    The basename for this file is "interesting"
::    (do not specify quotes)
@set BASENAME=main
:: Final base file name
@set FINALNAME=AxeInterpreterv0.0

:: Uncomment if you haven't used PyInstaller before
::C:\Python27\python %PYINSTALLER_PATH%\Configure.py
C:\Python27\python %PYINSTALLER_PATH%\MakeSpec.py --onefile --windowed -o %BUILD_DIR% %TO_COMPILE%
C:\Python27\python %PYINSTALLER_PATH%\Build.py %BUILD_DIR%\%BASENAME%.spec
move %BUILD_DIR%\dist\%BASENAME%.exe %BUILD_DIR%\dist\%FINALNAME%.exe
pause

Here's a Windows build for people to play with - again, the program seems to not work, but I release it anyway just in case someone does get it to work. ;)

Attached is a ZIP file - just decompress and enjoy! :) There are helper BAT files so that you will never have to open a console ever again :P
This should also work in Linux via WINE.

EDIT: Oops, forgot to include PyGame! :P It still doesn't work, but YMMV: http://dl.dropbox.com/u/1016340/AxeInterpreterv0.0_Windows_x86.zip (if link is not up immediately, it will be in a few minutes)
Title: Re: Axe Interpreter
Post by: Michael_Lee on December 21, 2011, 12:36:58 am
Because I don't want people to play with broken exes, here are working ones!

I made a few minor tweaks.  Double-clicking the exe now starts the interpreter, you can drag and drop a text file over the exe to try and run it, and the program will drop into the interpreter mode after a text file finishes running (so that you can do a postmortem, dissect variables, etc.)

For some inexplicable reason, you need to add a 'import pygame._views' while using pyinstaller in windows but exclude it for linux.

Download Windows version: http://dl.dropbox.com/u/10645749/axe-interpreter-windows.zip (http://dl.dropbox.com/u/10645749/axe-interpreter-windows.zip)
Download Linux version: http://dl.dropbox.com/u/10645749/axe-interpreter-linux.zip (http://dl.dropbox.com/u/10645749/axe-interpreter-linux.zip)
Title: Re: Axe Interpreter
Post by: Nick on December 21, 2011, 03:31:07 am
is it possible that you need other files than the exe? it searches for a file in a directory on your pc xp
Title: Re: Axe Interpreter
Post by: Michael_Lee on December 21, 2011, 03:39:33 am
Really?  What do you mean?
Title: Re: Axe Interpreter
Post by: Nick on December 21, 2011, 03:45:02 am
uh, wow wait, i tried it again and now it all works fine :) but the first time it gave like 1 minute long an error message in the commandline (but so fast you couldn't read it) and than it stopped saying something like c:\users\michael\dropbox\python files not found or so (i already closed it os it's not exact..ending with ,] that's all i can remember), but now it is ok
Title: Re: Axe Interpreter
Post by: AngelFish on December 21, 2011, 04:08:24 am
Nice project. One bug I noticed is that even if you don't use DispGraph, entering anything in the interactive mode will cause the display to update.

As for the name, what about AXE (Axe eXecutable Environment) or AXiE (Axe eXecuting interactive Environment)?
Title: Re: Axe Interpreter
Post by: TIfanx1999 on December 21, 2011, 05:51:23 am
AXIS?
Axe
Interpreting
System

:D
Title: Re: Axe Interpreter
Post by: FinaleTI on December 21, 2011, 06:14:06 am
Or what about Axecutor?
Title: Re: Axe Interpreter
Post by: TIfanx1999 on December 21, 2011, 06:24:40 am
Oooh, I like! ;D
Title: Re: Axe Interpreter
Post by: alberthrocks on December 21, 2011, 10:08:22 am
Because I don't want people to play with broken exes, here are working ones!

I made a few minor tweaks.  Double-clicking the exe now starts the interpreter, you can drag and drop a text file over the exe to try and run it, and the program will drop into the interpreter mode after a text file finishes running (so that you can do a postmortem, dissect variables, etc.)

For some inexplicable reason, you need to add a 'import pygame._views' while using pyinstaller in windows but exclude it for linux.
Good tweaks indeed. :)
Also, that bug you mention about has been fixed rather recently... O_O http://www.pyinstaller.org/ticket/406
There's a "hook" that had to be implemented for it to work. (pygame._view is considered as a "hidden" import.)

Some further suggestions...
1) I suggest you look into threading (you'll be seeing that very soon in Croquette!) for Pygame event pumping. If you don't "process" the events sent to the Pygame window, Windows will think it died and ask to terminate it. :P The Pygame portion MUST remain in the main thread (unfortunately), but the CLI interpreter can be handled in the thread, making things work out nicely. :) (Even if it's odd to do graphics processing first :P)
2) Add an option to hide/show the window? (As you've demoed, some commands do not need the screen shown.)
3) CLI commands - like when I do Output(1,1,"Hello world!"), it shows it in the console instead. A flag must be toggled for this to work, of course. If you want to implement this, you need to use a mix of the ncurses module and the Windows Console module (http://effbot.org/zone/console-index.htm).

Otherwise, it's pretty nice :D
Title: Re: Axe Interpreter
Post by: Michael_Lee on December 21, 2011, 11:39:55 am
Nice project. One bug I noticed is that even if you don't use DispGraph, entering anything in the interactive mode will cause the display to update.

Oh, that's intentional.  To turn that off, type '@DRAW 0' and to turn it back on, type '@DRAW 1'.  I thought that constantly having to type 'DispGraph' was a bit annoying.

Some further suggestions...
1) I suggest you look into threading (you'll be seeing that very soon in Croquette!) for Pygame event pumping. If you don't "process" the events sent to the Pygame window, Windows will think it died and ask to terminate it. :P The Pygame portion MUST remain in the main thread (unfortunately), but the CLI interpreter can be handled in the thread, making things work out nicely. :) (Even if it's odd to do graphics processing first :P)
2) Add an option to hide/show the window? (As you've demoed, some commands do not need the screen shown.)
3) CLI commands - like when I do Output(1,1,"Hello world!"), it shows it in the console instead. A flag must be toggled for this to work, of course. If you want to implement this, you need to use a mix of the ncurses module and the Windows Console module (http://effbot.org/zone/console-index.htm).

Otherwise, it's pretty nice :D

Thanks for the suggestions!  I ended up using multiple processes instead of threads, but the final effect was the same.  Never mind.  Should have tested on Windows.  Got threads working now.

I'll look into the other suggestions, thanks.
Title: Re: Axe Interpreter
Post by: DJ Omnimaga on December 21, 2011, 02:32:23 pm
Or what about Axecutor?
That sounds like a Pokémon :P

Nice idea though lol

Also nice to see this worked on more :D
Title: Re: Axe Interpreter
Post by: epic7 on December 21, 2011, 03:50:05 pm
Exe file yet?
Title: Re: Axe Interpreter
Post by: Michael_Lee on December 21, 2011, 06:26:34 pm
Because I don't want people to play with broken exes, here are working ones!

I made a few minor tweaks.  Double-clicking the exe now starts the interpreter, you can drag and drop a text file over the exe to try and run it, and the program will drop into the interpreter mode after a text file finishes running (so that you can do a postmortem, dissect variables, etc.)

For some inexplicable reason, you need to add a 'import pygame._views' while using pyinstaller in windows but exclude it for linux.

Download Windows version: http://dl.dropbox.com/u/10645749/axe-interpreter-windows.zip (http://dl.dropbox.com/u/10645749/axe-interpreter-windows.zip)
Download Linux version: http://dl.dropbox.com/u/10645749/axe-interpreter-linux.zip (http://dl.dropbox.com/u/10645749/axe-interpreter-linux.zip)
^ That.

Note: Later today, I'll upload another version.  GetKey has been implemented, along with pointers, so you can have legit lists.
I'm having some trouble integrating the screen with manipulating memory, so writing to L3 or L6 won't currently effect the screen.

Does anybody know how you can use a bytearray or a list (in python) to manipulate or create a pygame Surface?
Title: Re: Axe Interpreter
Post by: epic7 on December 21, 2011, 06:34:54 pm
How will getKey work with computer keys? :P
Title: Re: Axe Interpreter
Post by: Michael_Lee on December 21, 2011, 06:41:05 pm
You have a config file, and you assign whatever computer key you want the appropriate computer key.  So to make GetKey(15) equal the backspace key, you would edit the config file so the appropriate line reads

Code: [Select]
K_BACKSPACE    :   15
Title: Re: Axe Interpreter
Post by: alberthrocks on December 21, 2011, 07:32:41 pm
Does anybody know how you can use a bytearray or a list (in python) to manipulate or create a pygame Surface?
Take a look at these two classes (is that the right term?):
http://pygame.org/docs/ref/pixelarray.html
http://pygame.org/docs/ref/surfarray.html

It should do what you want it to do. :) Note that surfarray requires numpy/numeric, so keep that in mind when you're using it. (It's standard, but it may or may not increase built exec size.)
Title: Re: Axe Interpreter
Post by: Michael_Lee on December 23, 2011, 02:55:59 am
Another release!

getKeys, scrolling, a few more pxl-commands, rudimentary pointers and constants (using L1-L6 for lists, mostly), a bunch of math commands, and a few more control structures were added.

Download here: http://dl.dropbox.com/u/10645749/axe-interpreter_v0.2.zip (http://dl.dropbox.com/u/10645749/axe-interpreter_v0.2.zip)
Executables for Linux and Windows along with source code should be included.  (Tested on Windows 7 (64 bit) and Linux Mint 11 (32 bit))

I then whipped up a quick tunnel game below, which you can watch below ;D



(Hmm, the embedded youtube video is a bit too small.  Is there a way to make them bigger?)
(Edit: Weird, you can't see the mouse.)

Additional notes:
By default, a few keys are mapped to getKey -- for example, pressing backspace maps to 'getKey(15)', for example.  Included in the folder should be a file named 'keybindings.config' which can be edited to change which keys maps to which getkey.  That file has to be in the same folder as the exe.

You can use the '{ }' brackets and L1-L6 for lists and pointer stuff, but currently changing L6 or L3 doesn't change the buffers yet.

Using @OPEN "filename" (you have to include the quotation marks) can open files directly inside the interpreter.  If you use those commands inside files, I guess that would work as a sort of substitute for imports/subroutines, at least until I have legitimate imports, subroutines, labels, etc. working.
Title: Re: Axe Interpreter
Post by: Nick on December 23, 2011, 03:03:27 am
wow, great.. looks like this is going to have full axe support.. wonderful

i'm going to map some keys right now :)
Title: Re: Axe Interpreter
Post by: Sorunome on December 23, 2011, 12:36:05 pm
This just looks sooooooooooooo cool! :)
Title: Re: Axe Interpreter
Post by: C0deH4cker on December 23, 2011, 01:45:54 pm
Maybe one of the included keymap config files could be just like Wabbit's default. It's alright, but could be better IMHO.
Title: Re: Axe Interpreter
Post by: Michael_Lee on December 23, 2011, 04:04:25 pm
Maybe one of the included keymap config files could be just like Wabbit's default. It's alright, but could be better IMHO.

Do you know where I can find an official copy of what Wabbitemu uses for key mappings?  This should be pretty trivial to change. 
Title: Re: Axe Interpreter
Post by: alberthrocks on December 24, 2011, 09:26:44 am
Maybe one of the included keymap config files could be just like Wabbit's default. It's alright, but could be better IMHO.

Do you know where I can find an official copy of what Wabbitemu uses for key mappings?  This should be pretty trivial to change. 
There are two ways:
1) Look in hardware/keys.c and look for the corresponding key bindings set up (all in C);
2) Look at http://wikiti.brandonw.net/index.php?title=Emulators:Wabbitemu (all in plain English) ;)

Note that the keys used in hardware/keys.c don't match up with the SDL keys, so don't use it verbatim!

EDIT: Also, I don't think a "keymap config file" exists for Wabbitemu.... unless you're talking about those keymap images, which isn't exactly something you would want to play with unless you wish to implement ports. (Some possible outdated (if at all possible) skins here (file *keymap): http://code.google.com/p/wxwabbitemu/source/browse/#svn%2Ftrunk%2Fsrc%2Fgui%2Fskins)
Title: Re: Axe Interpreter
Post by: aeTIos on December 24, 2011, 10:55:42 am
So what does this actually do? is this meant to test axe programs on pc without a lot emulator hassles?
Title: Re: Axe Interpreter
Post by: Spyro543 on December 24, 2011, 11:02:05 am
So what does this actually do? is this meant to test axe programs on pc without a lot emulator hassles?
Looks like a port of Axe to computer to me. If it is, maybe color commands should be added.
Title: Re: Axe Interpreter
Post by: epic7 on December 24, 2011, 11:31:04 am
Should this be working?

(http://img.removedfromgame.com/imgs/wat.png)

Edit: I got the file to open by moving it to the Windows folder.
Also how do you make .axe files?
Title: Re: Axe Interpreter
Post by: Michael_Lee on December 24, 2011, 07:11:28 pm
Currently, strings aren't supported.

A .axe  file is the same as a .txt file.  You can use either -- the extension doesn't matter.

So what does this actually do? is this meant to test axe programs on pc without a lot emulator hassles?

^ That.  It could also eventually let you port your Axe games to be playable on the computer.
Title: Re: Axe Interpreter
Post by: DJ Omnimaga on December 25, 2011, 11:52:01 pm
Is the syntax exactly the same? If so, then I guess once complete we will be able to play Axe games without any modifications, right? If so, then it would be nice if we could actually import 8xp files (source) or even launch them with the interpreter to play them directly there.
Title: Re: Axe Interpreter
Post by: calc84maniac on December 25, 2011, 11:56:19 pm
As far as I know, it won't be able to use Axioms or Asm(), since there's no z80 emulation (and some Axioms and Asm() statements might rely on TI-OS, which isn't there either)
Title: Re: Axe Interpreter
Post by: DJ Omnimaga on December 25, 2011, 11:59:17 pm
Ah right I forgot about Axioms. Hopefully it can run games like Axe Tunnel, though, or even some of the large projects (assuming all sub-programs are in the same folder)
Title: Re: Axe Interpreter
Post by: calc84maniac on December 26, 2011, 12:02:07 am
And I guess GetCalc() would directly access .8x* files in the same folder... that would be cool :D
Title: Re: Axe Interpreter
Post by: DJ Omnimaga on December 26, 2011, 12:05:15 am
Indeed that's what I thought, and of course sub-programs/routines
Title: Re: Axe Interpreter
Post by: Michael_Lee on January 05, 2012, 12:13:08 am
Progress report:

So, I essentially have to rewrite a chunk of my program.  Basically, the story is, I'm first converting text into a sort of tree -- lists containing lists containing lists.  Unfortunately, that format won't allow me to easily code in goto statements -- there are ways to hack out a solution, but they're all slow and brittle. 

So I'm rewriting my code to first create a tree then convert it into a single flattened list so I can easily jump to a line number.  Which is a pity, since I thought my whole recursive scheme for running the tree was cool (I like recursion). 

I'm also angsting over whether or not I should turn my tree into objects containing objects or just keep them as nested lists.

You know, gotos are generally seen as evil, but I never realized they were diabolical to implement too D:
Title: Re: Axe Interpreter
Post by: willrandship on January 05, 2012, 01:16:35 am
For the name......how about Halberd?
Title: Re: Axe Interpreter
Post by: DJ Omnimaga on January 12, 2012, 02:00:45 am
I'm glad this is still progressing. Hopefully you can finish this. :)
Title: Re: Axe Interpreter
Post by: Michael_Lee on January 18, 2012, 03:48:47 am
I revamped how I handle memory and graphics.

Full pointer madness is working, along with graphics (including grayscale and sprites).  I still have to implement all the different sprite variations (which should be easy), and redo scrolling (Horizontal/Vertical +/-).

On the lexing/parser side, I've been procrastinating and still haven't rewritten it to compensate for those blasted gotos :P

Does anybody know where I can get the font used for the TI-84?  (both the small one and the homescreen one?)
Title: Re: Axe Interpreter
Post by: TIfanx1999 on January 18, 2012, 09:30:50 pm
Ti's website used to have a font available, you could check there. I'm unsure if it was accurate or just looked similar to what was on the calc. I'm pretty sure it was only one size as well.
Title: Re: Axe Interpreter
Post by: Michael_Lee on May 13, 2012, 01:50:41 am
Necropost!

Here's a shiny new youtube video:

(it comes out a bit small, so try going to the actual video?)

...and the download link:
http://dl.dropbox.com/u/10645749/axe-interpreter_v0.3.zip (http://dl.dropbox.com/u/10645749/axe-interpreter_v0.3.zip)

So, here are a list of changes since the last official version!

...and the things I need to work on:

The list of all supported tokens can be found here:
static.michael0x2a.com/commands.html (http://static.michael0x2a.com/commands.html)
Title: Re: Axe Interpreter
Post by: shmibs on May 13, 2012, 12:51:00 pm
so grey just displays in fixed colour until the next update?

this looks pretty snazzy indeed =)

EDIT: there wasn't a linux executable included, so i tried running the version in .src. it worked, but i kept getting unrecognised token errors, and it froze up at the end of the program
Title: Re: Axe Interpreter
Post by: Michael_Lee on May 13, 2012, 01:14:22 pm
so grey just displays in fixed colour until the next update?

Erm, could you clarify what you mean by 'fixed color'?

If you're referring to how grayscale usually has a flickering/diagonal effect in real calculators, I'm probably not going to in the near future because I'm not really sure how to code something like that. 
Title: Re: Axe Interpreter
Post by: shmibs on May 13, 2012, 01:22:25 pm
yes, that's what i was referring to. i don't think there will be any reason for you to change it. it would be a lot of work, and most programs would look better like this anyways.
Title: Re: Axe Interpreter
Post by: Michael_Lee on May 13, 2012, 01:42:57 pm
Huh, that's a really weird tokenizing error.  I confirmed on my linux box: I'll go ahead and take a look at it (although it may take a week or so before I have time push the fix out).