|
Author
|
Comment
|
Kevin Kofler 
Admin
Posts: 4614
(12/4/04 6:14 am)
Reply
|
TI-BASIC as a scripting language
I have just completed a demo showing how to use TI-BASIC as an embedded scripting language for your ASM programs. This project was inspired by Lua89: its author talks about using Lua as a scripting language, however, the Lua language and API takes around 90 KB! By reusing the already-existing scripting language TI-BASIC, you can save lots of memory. My demo program takes about 1 KB, so it is almost 100 times smaller!
The way this works is that my demo "parasites" (hooks) the TIHOME application to install a few TI-BASIC extensions. These TI-BASIC extensions correspond to the API offered by your program. They work just like FlashApp TI-BASIC extensions, but they are part of your RAM program, and they are installed only temporarily for the duration of your program and get uninstalled before exiting. (Don't try to keep them installed when exiting, it won't work, because your program can move in memory at any time!) I also added a progrun function, which is an improved version of the one in the TIGCC FAQ (I guess I should update the FAQ as well...).
Please tell me if you are interested in using this in your own application. I might make a few adjustments before I release this "officially".
members.chello.at/gerhard.kofler/kevin/ti89prog/tibasext.zip
|
MastaZog
Registered User
Posts: 430
(12/4/04 12:23 pm)
Reply
|
Re: TI-BASIC as a scripting language
That's pretty cool. I don't have a use for it right now, but it's still a neat idea.
|
Kevin Kofler 
Admin
Posts: 4616
(12/4/04 4:05 pm)
Reply
|
Re: TI-BASIC as a scripting language
I fixed a missing TRY...FINALLY around the program execution, to make sure the hook really is uninstalled when exiting, even in case of an error. What's cool is that you get to edit the TI-BASIC when an error occurs, despite it being rethrown across 3 TRY blocks (the one in progrun, the one in _main, and the one added by ENABLE_ERROR_RETURN).
I also added a few optimization flags I didn't think about last night, so we're still at 1 KB.
|
Kevin Kofler 
Admin
Posts: 4618
(12/4/04 4:46 pm)
Reply
|
Re: TI-BASIC as a scripting language
Here is a sample script:
test()
:Prgm
:Local i
:dummy()
:For i,1,3
:If hellow.hellow() Then
:Text "true"
:Else
:Text "false"
:EndIf
:EndFor
:EndPrgm
As you can see, the hellow. qualifier is optional. This script will show "Hello world" and then "false", and repeat this 2 more times.
|
|
|
jackiechan
Registered User
Posts: 227
(12/4/04 7:40 pm)
Reply
|
Re
That's a good idea, great work Kevin (as usual ) !
|
Kevin Kofler 
Admin
Posts: 4621
(12/5/04 1:30 am)
Reply
|
Re: Re
One more update:
* progrun optimized to be 4 bytes smaller,
* now released under the MIT X11 Open Source license, which means the header and the sample code can be used with almost no restrictions,
* removed unused definitions (low-level ACB stuff that is not needed because we're hooking the existing TIHOME ACB instead of creating a new one) from the header file,
* binaries of the demo program are now included.
Edited by: Kevin Kofler at: 12/5/04 1:36 am
|
Kevin Kofler 
Admin
Posts: 4651
(12/9/04 12:09 am)
Reply
|
Re: Re
One thing that should be mentioned: as said on page 50 of the TIFS documentation:
Quote: The extensions table has an entry for each extension function or program. [...] The entries in this table must be alphabetized by the function name.
|
Kevin Kofler 
Admin
Posts: 4718
(12/19/04 1:20 am)
Reply
|
Re: Re
I've just completed a tech demo showing the power of this technology: a scriptable spread sheet program in 14 KB, written in 2 evenings. members.chello.at/gerhard.kofler/kevin/ti89prog/spread89.zip
Important notes:
* This is a preliminary version and may be unstable for various reasons. Use at your own risk.
* The program is compatible with all TI-89, TI-92+, V200 or TI-89 Titanium calculators running AMS 2.04 or higher. (You can recompile it without F-Line ROM_CALLs or with an F-Line emulator if you really want to use it on AMS 2.00-2.03. AMS 1 is not supported at all.)
* The entire spread sheet relies on TI-BASIC Extensions. The way to refer to other cells is that you use the cells( function: cells("A1") or cells("A2:B4"). Cell ranges are handled as matrices. For your convenience, the msum, mprod and mmean functions are equivalent to sum°mat>list, prod°mat>list and mean°mat>list, respectively.
* Supported table sizes: 26, 52 or 78 columns (A-Z, A-AZ or A-BZ), 1 to 360 rows, subject to available memory limits.
* A possible improvement would be an expression parser based on AutoClBr to automatically convert e.g. A1 to cells("A1") (case-sensitively), and to auto-close parentheses.
* In case of errors in scripts, you can choose if you prefer to stay in the spreadsheet application (press ESC) or quit and debug the script (press ENTER). Warning: The data is not saved if you press ENTER.
* The scripts run using F4 get a reduced expression stack (14 KB), the rest is used to store the expressions used in the spreadsheet itself. (This hack worked reliably when I tried it, I hope it won't crash on you...) TI-BASIC functions used for cell evaluation use the same expression stack as the spread sheet, but they aren't allowed to use functions/procedures like openfile which push cell contents to the expression stack.
* This spreadsheet program is not a performance wonder: Each cell is refreshed whenever it is drawn or whenever its value is needed in another cell. There is no cache. You have been warned.
|
Kevin Kofler 
Admin
Posts: 4721
(12/19/04 6:01 am)
Reply
|
Re: Re
Another neat thing I should mention: Spread89 is almost entirely event driven. All the keyboard handling happens in the event loop, not through polling. This means event hooks work (though AutoClBr doesn't because it doesn't detect the text area, it can only detect HOME and Y=), and APD and the low power mode are supported without additional efforts. But most importantly, this shows how features like event-driven programming and TI-BASIC extensions are not limited to FlashApps, they can be used successfully in RAM programs as well.
|
Kevin Kofler 
Admin
Posts: 4725
(12/19/04 10:57 pm)
Reply
|
Re: Re
I have uploaded a new version of Spreas89 with 2 stack-overflow-related bugfixes:
* Running scripts was writing way beyond the expression stack, because I didn't make sure it has at least 50000 bytes available before using bottom_estack+50000. This is fixed now (check_estack_size(bottom_estack+50000-top_estack); does the trick).
* Writing cells(1,1) into A1 was crashing the calculator because the CPU stack overflowed. I added a NeedStack(600); to the cells( TI-BASIC extension to fix this.
|