Jump to content

Photo

FastBasic - New Year Release

basic compiler interpreter

43 replies to this topic

#1 dmsc OFFLINE  

dmsc

    Moonsweeper

  • 444 posts
  • Location:Viņa del Mar, Chile

Posted Sat Dec 30, 2017 11:02 PM

Note: a new version is available over this post.

Hi all

As a new-year present, I released a new version of FastBasic.

It's only a minor bugfix release from last one:
- Fixes a bug with floating-point comparisons
- Adds more usage information to the cross-compiler.
- Fixes display corruption in the editor.
- Allows comments after any statement.

As always, the full source is over github, and you can download the release at https://github.com/d...basic/releases/full manual at https://github.com/d...aster/manual.md and sample programs are included in the ATR or in the source at https://github.com/d...ter/samples/int and https://github.com/d...ster/samples/fp

Over github I included the cross-compiler for Linux, Windows and macOS, but I only tested the Linux and Windows ones. For usage instructions of the cross-compiler, see at https://github.com/d...mpiler/USAGE.md

Attached Files


Edited by dmsc, Sun Feb 18, 2018 8:50 PM.


#2 bfollett OFFLINE  

bfollett

    Dragonstomper

  • 564 posts

Posted Sun Dec 31, 2017 12:31 PM

I was just looking at the manual on your website.  Just a quick note, I noticed #4 in the section "About the Syntax" had a small typo.  It says to use semicolons to between statements, but shows a colon:

 

"Multiple statements can be put on the same line by placing a semicolon : between statements."

 

 The programing language looks interesting, do you have a feel on how it compares speed wise to turbo basic/ turbo basic compiled?

 

Thanks,

 

Bob



#3 dmsc OFFLINE  

dmsc

    Moonsweeper

  • Topic Starter
  • 444 posts
  • Location:Viņa del Mar, Chile

Posted Sun Dec 31, 2017 1:27 PM

Hi!
 

I was just looking at the manual on your website.  Just a quick note, I noticed #4 in the section "About the Syntax" had a small typo.  It says to use semicolons to between statements, but shows a colon:
 
"Multiple statements can be put on the same line by placing a semicolon : between statements."
 
 The programing language looks interesting, do you have a feel on how it compares speed wise to turbo basic/ turbo basic compiled?
 
Thanks,
 
Bob


Thanks for the correction, updated over github.

With respect to speed, it depends on the program, but with the included SIEVE benchmark, the runtime in jiffies (1/60 of second, in NTSC, screen ON):
- Standard TurboBasic XL:                 7941 (100%) ( 28%)
- basicParser optimizaed TurboBasic XL:   7537 (105%) ( 29%)
- Compiled TurboBasic XL:                 2210 (360%) (100%)
- FastBasic IDE:                          1330 (597%) (166%)
- FastBasic cross-compiled:               1314 (604%) (168%)
So, FastBasic is 6 times faster than standard TurboBasic XL and 1.7 times faster than compiled TurboBasic XL. This is not a fair comparison, as FastBasic uses integers for the main operations, but TurboBasic XL uses floating point.

On the other hand, FastBasic is still an interpreter and a lot slower than compiled 6502 assembly. For example, MadPascal times the above benchmark at 98 jiffies, so it's 13 times faster than FastBasic.

Attached are the benchmark sources.

Attached Files


Edited by dmsc, Sun Dec 31, 2017 1:28 PM.


#4 bfollett OFFLINE  

bfollett

    Dragonstomper

  • 564 posts

Posted Sun Dec 31, 2017 1:39 PM

Wow, that's a pretty decent speed improvement.  I'm going to have to give it a try.

Bob


Edited by bfollett, Sun Dec 31, 2017 1:40 PM.


#5 Xuel OFFLINE  

Xuel

    Dragonstomper

  • 729 posts
  • Location:US

Posted Sun Dec 31, 2017 4:57 PM

What optimizations does the cross-compiler do that the IDE doesn't?



#6 dmsc OFFLINE  

dmsc

    Moonsweeper

  • Topic Starter
  • 444 posts
  • Location:Viņa del Mar, Chile

Posted Sun Dec 31, 2017 7:51 PM

Hi!
 

What optimizations does the cross-compiler do that the IDE doesn't?


The cross-compiler performs a simple peephole pass with some rules:

- Propagates constants operations (so, for example A=2+1 becomes A=3, A=1*B becomes A=B, etc.)
- Converts *2 and *4 (and A+A) to shift left
- Removes comparisons with 0 (so, "IF A=0" becomes "IF NOT A")
- Converts A=A+1 and A=A-1 to "INC A" and "DEC A"
- Converts ? #0, INPUT #0, GET #0, PUT #0 to the operations with the #0 implied.
- Converts the number 0 and 1 to tokens "TOK_0" and "TOK_1"
- Converts numbers from 2 to 255 to BYTES.

Also, it emits all PROCs at the end of the program instead of actual location in the source, this generates smaller code.

I plan to add more optimization pases in the future, converting the opcodes to a tree representation first and then lowering from there, as it's currently done in my TurboBasic XL parser.

#7 Xuel OFFLINE  

Xuel

    Dragonstomper

  • 729 posts
  • Location:US

Posted Sun Dec 31, 2017 8:56 PM

Very cool. Does the IDE do any optimizations?



#8 Philsan OFFLINE  

Philsan

    River Patroller

  • 3,742 posts
  • New Orleans Saints Super Bowl XLIV Champions
  • Location:Switzerland

Posted Mon Jan 1, 2018 10:05 AM

Instead of a single XEX, perhaps someone would need an ATR image to be created, with XEX file and other needed files (graphics, tunes...).

 

Based on FB's batch file by dmsc and Turban's batch file by Irgendwer, I made this batch file:

@echo off
set basfile=%1
set asmfile=%~d1%~p1%~n1.asm
set xexfile=autorun.sys
C:\cc65\fb\fastbasic-fp %basfile% %asmfile% || exit /b %errorlevel%
C:\cc65\bin\cl65 -t atari -C C:\cc65\fb\fastbasic.cfg %asmfile% -o %xexfile% C:\cc65\fb\fastbasic-fp.lib || exit /b %errorlevel%

set imagename=%~d1%~p1%~n1.atr
set diskdir=%~dp1\atr
copy %xexfile% %diskdir%
dir2atr -b Dos25 720 %imagename% "%diskdir%"
if %errorlevel% neq 0 exit /b %errorlevel%
Altirra.exe /pal /bootrw %imagename%

You need to put files in "fb/atr" folder.

 

The program will be compiled and an ATR will be created with all files.

The program will be started in Altirra (Altirra must be in PATH).



#9 Philsan OFFLINE  

Philsan

    River Patroller

  • 3,742 posts
  • New Orleans Saints Super Bowl XLIV Champions
  • Location:Switzerland

Posted Mon Jan 1, 2018 10:30 AM

Perhaps with FastBasic people without much experience would start programming.

 

Therefore I mode a simple guide for newbies.

 

Feel free to give me suggestions.

 

WINDOWS INSTALLATION

 

Download CC65 from here: http://cc65.github.i...ed.html#Windows

Unzip all folders in C

Make folder C:\cc65\fb

Download fastbasic-windows from here: https://github.com/d...basic/releases/

Unzip it in C:\cc65\fb

Download and install text editor Notepad++ from here: https://notepad-plus-plus.org/

In the menu select Language/V/VisualBasic

 

WINDOWS USE

 

Start Command Prompt

Type cd c:/cc65/fb

Write code on Notepad++ and save PROGRAMNAME.bas in C:\cc65\fb

In Command Prompt type fb PROGRAMNAME.bas

After a few second PROGRAMNAME.xex will be created in C:\cc65\fb

 

If you want the program started in emulator add "Altirra.exe %xexfile%" line in fb.bat and fb-int.bat.



#10 dmsc OFFLINE  

dmsc

    Moonsweeper

  • Topic Starter
  • 444 posts
  • Location:Viņa del Mar, Chile

Posted Mon Jan 1, 2018 11:12 AM

Hi!
 

Very cool. Does the IDE do any optimizations?


Not currently, the IDE directly transforms the code the tokens, following the set of rules in the syntax file.

I have tried to keep the IDE as smaller (and faster) as possible, and currently the speed gains for the optimization pass are not that great. I tried adding a constant-propagation pass using the syntax rules, but the parser became really slow, so I removed it.

#11 XL Freak OFFLINE  

XL Freak

    Combat Commando

  • 3 posts
  • Location:stilwell, ok

Posted Sun Mar 11, 2018 9:27 PM

another optimization you could consider for the compiled code is expression pre-arrangement, so the included interpreter doesn't have to rearrange the expression on each pass, or at all. the compiler could arrange the expression, ie. A=4*((A+B)/Z), into A,B,+,Z,/,4,*A,= which the interpreter could execute quicker since it doesn't have to test the come-off and go-on stack values. it'd already be done.

 

this is an idea i have for an android project i may do at some point in the future. hope this helps...



#12 dmsc OFFLINE  

dmsc

    Moonsweeper

  • Topic Starter
  • 444 posts
  • Location:Viņa del Mar, Chile

Posted Mon Mar 12, 2018 12:45 PM

Hi!
 

another optimization you could consider for the compiled code is expression pre-arrangement, so the included interpreter doesn't have to rearrange the expression on each pass, or at all. the compiler could arrange the expression, ie. A=4*((A+B)/Z), into A,B,+,Z,/,4,*A,= which the interpreter could execute quicker since it doesn't have to test the come-off and go-on stack values. it'd already be done.
 
this is an idea i have for an android project i may do at some point in the future. hope this helps...


This is what the current compiler does, it transform the source to a stack-based byte-code. This is done in the IDE, at the same time the code is parsed.

In your example, the code is converted to:
        VAR_ADDR 'A'
        BYTE 4
        VAR_LOAD 'A'
        VAR_LOAD 'B'
        ADD
        VAR_LOAD 'Z'
        DIV
        MUL
        DPOKE
What the optimizer does is apply transformations to the above byte-code after the parsing is complete, replacing sequences with shorter/faster ones.

One of the novel ideas from the FastBasic IDE is that there is only one pass from source text to the byte-code, not separated tokenization plus parsing plus code-generation. This is done using a PEG like parser, that matches each source character with a list of rules described in a syntax file, and emits bytecode from the same syntax. The parser has some limitations, and as it does not support memoization it is slow for complex expressions, but it works well for a simple language like BASIC, and produces a complete parser in less than 3.5kB.

#13 XL Freak OFFLINE  

XL Freak

    Combat Commando

  • 3 posts
  • Location:stilwell, ok

Posted Mon Mar 12, 2018 1:03 PM

sounds great! can't wait to get my system up and running so i can try it

#14 Larry OFFLINE  

Larry

    River Patroller

  • 4,057 posts
  • Location:U.S. -- Midwest

Posted Sun Mar 18, 2018 3:32 PM

Is anyone successfully using FastBasic with an Atari Dos (2.0, MyDos, etc.)?

 

Or is it "hooked" to BEWE Dos?  BEWE Dos looks a lot like Sparta at a casual glance.

 

Thanks,

Larry



#15 dmsc OFFLINE  

dmsc

    Moonsweeper

  • Topic Starter
  • 444 posts
  • Location:Viņa del Mar, Chile

Posted Sun Mar 18, 2018 3:46 PM

Hi!
 

Is anyone successfully using FastBasic with an Atari Dos (2.0, MyDos, etc.)?
 
Or is it "hooked" to BEWE Dos?  BEWE Dos looks a lot like Sparta at a casual glance.
 
Thanks,
Larry


Should work with any DOS, only requirement is that MEMLO be less than $2000. As the IDE is self contained, you only need the "FB.COM" or "FBI.COM" programs in the disk, rest of files on disk are the manual and samples.

#16 Larry OFFLINE  

Larry

    River Patroller

  • 4,057 posts
  • Location:U.S. -- Midwest

Posted Tue Mar 20, 2018 1:00 PM

Hi dmsc-

 

I've found several Dos versions with MEMLO of less than $2000.  Thanks.

 

But if I try to do a binary load of FB.COM or FBI.COM with another Dos version,  then they launch OK, but immediately gives an ERROR 170.  What file is missing if the program is not launched by BEWE Dos?  Perhaps the HELP.TXT file is typically needed but will not load if using another Dos?  Not saying it crashes or anything, but it's interesting to start with an error message.

 

Or perhaps there is a built-in hook to the STARTUP.BAT file?

 

-Larry



#17 flashjazzcat OFFLINE  

flashjazzcat

    Quadrunner

  • 14,043 posts
  • Location:United Kingdom

Posted Tue Mar 20, 2018 1:57 PM

Loads under DOS 2.5 and finds HELP.TXT OK, so there don't appear to be any dependencies on a particular DOS. I do think the file not found error could be suppressed regarding HELP.TXT, though, since once you get the hang of things it's not needed and it would be preferable to simply start with an empty editor (and no error message).

#18 dmsc OFFLINE  

dmsc

    Moonsweeper

  • Topic Starter
  • 444 posts
  • Location:Viņa del Mar, Chile

Posted Tue Mar 20, 2018 7:21 PM

Hi!
 

Hi dmsc-
 
I've found several Dos versions with MEMLO of less than $2000.  Thanks.
 
But if I try to do a binary load of FB.COM or FBI.COM with another Dos version,  then they launch OK, but immediately gives an ERROR 170.  What file is missing if the program is not launched by BEWE Dos?  Perhaps the HELP.TXT file is typically needed but will not load if using another Dos?  Not saying it crashes or anything, but it's interesting to start with an error message.
 
Or perhaps there is a built-in hook to the STARTUP.BAT file?
 
-Larry


Yes, the editor loads 'D:HELP.TXT' at start to show a simple help screen, if not found an error is shown but the IDE continues working ok. If you don't like the error, simply copy the file, or write a new one with whatever you want to show at start.
 

Loads under DOS 2.5 and finds HELP.TXT OK, so there don't appear to be any dependencies on a particular DOS. I do think the file not found error could be suppressed regarding HELP.TXT, though, since once you get the hang of things it's not needed and it would be preferable to simply start with an empty editor (and no error message).

 
Suppressing the error would make the IDE bigger (because the editor simply calls "LoadFile" with the filename set to 'D:HELP.TXT'), to make the error disappear it is easier to simply write an empty HELP.TXT file.

I'm now finalizing a new version, there are one major bug in the STR$ function in the 3.3 version that is fixed in current github sources, I will release the 3.4 version before Friday, so it's available for the ten-liners competition :)

#19 Larry OFFLINE  

Larry

    River Patroller

  • 4,057 posts
  • Location:U.S. -- Midwest

Posted Wed Mar 21, 2018 4:00 AM

I see what happens... 

 

In my case, I've been loading FB.COM from D4:. D1: is a hard drive, and FB isn't there, yet.  But FB is expecting the HELP.TXT file to be there on D1: (not on D4:), hence the ERROR 170.  

 

Mystery solved!  And FB seems quite happy with MyDos 4.5x!

 

-Larry



#20 flashjazzcat OFFLINE  

flashjazzcat

    Quadrunner

  • 14,043 posts
  • Location:United Kingdom

Posted Wed Mar 21, 2018 5:00 AM

Suppressing the error would make the IDE bigger (because the editor simply calls "LoadFile" with the filename set to 'D:HELP.TXT'), to make the error disappear it is easier to simply write an empty HELP.TXT file.


Good point. Assuming there was no free ZP address for a flag, suppressing errors could take eleven bytes (3 bytes to set flag to known value of 0 of $FF, 3 to INC or DEC flag once initialisation phase is done, 3 to test bit 7 of flag in load procedure, and 2 bytes to branch accordingly). Worse yet, it's possible to receive errors that relate to a help file which was located but couldn't be loaded owing to IO errors, etc, so you end up filtering conditions in order to do things properly. Your suggested method is fine.

#21 gozar OFFLINE  

gozar

    Dragonstomper

  • 925 posts
  • Location:Ohio

Posted Fri Mar 30, 2018 8:05 AM

Suppressing the error would make the IDE bigger (because the editor simply calls "LoadFile" with the filename set to 'D:HELP.TXT'), to make the error disappear it is easier to simply write an empty HELP.TXT file.

 

Does the help.txt need to be loaded? Eliminating the loading process would free up space.



#22 dmsc OFFLINE  

dmsc

    Moonsweeper

  • Topic Starter
  • 444 posts
  • Location:Viņa del Mar, Chile

Posted Fri Mar 30, 2018 9:08 AM

Hi!

Does the help.txt need to be loaded? Eliminating the loading process would free up space.


Yes, loading the help.txt is not needed and removing it currently frees 24 bytes, but I like the program to be "discoverable", as the key combinations are not universal.

#23 funkheld OFFLINE  

funkheld

    Moonsweeper

  • 370 posts

Posted Sun Sep 9, 2018 3:39 AM

Can the code start from $ 2000 to $ 3000. I want to make a graphics screen from $ 2000 to $ 3000 with dli.
 
Thank you.
Greeting

Edited by funkheld, Sun Sep 9, 2018 8:19 AM.


#24 funkheld OFFLINE  

funkheld

    Moonsweeper

  • 370 posts

Posted Sun Sep 9, 2018 8:18 AM

how can you divide these values of the data line into several lines?
It is an asm program.
 

data ml() byte =  $68,$68, $A2, $00, $A9, $00, $9D, $40, $BC, $9D, $40, $BD, 
                  $9D, $40, $BE, $9D, $40, $BF, $E8, $D0, $F1, $A9, 
                  $2D, $A2, $0C, $60
  
? i, usr(adr(ml),i)
 
repeat
until Key()
 
asm-source clearscreen :

  ldx #0
  lda #0
loop 
  sta $bc40,x
  sta $bd40,x
  sta $be40,x
  sta $bf40,x
  inx
  bne loop
  lda #45
  ldx #12
  rts

Edited by funkheld, Sun Sep 9, 2018 8:18 AM.


#25 dmsc OFFLINE  

dmsc

    Moonsweeper

  • Topic Starter
  • 444 posts
  • Location:Viņa del Mar, Chile

Posted Sun Sep 9, 2018 10:50 AM

Hi funkheld!,
 

Can the code start from $ 2000 to $ 3000. I want to make a graphics screen from $ 2000 to $ 3000 with dli.

If you are using the cross-compiler, it is easy, just pass "--start-addr 0x3000" to the CL65 command line:




cl65 -tatari -C fastbasic.cfg -g --start-addr 0x3000 miprog.asm -o myprog.xex -Ln myprog.lbl fastbasic-fp.lib
Sadly, the current compiler script does not support passing options to the CL65 command line directly, you have to manually invoke the commands.

The other, not recommended option, is to modify the file "fastbasic.cfg", the default STARTADDR values is at line 23.

If you are using the native compiler. This it not as easy, as the native compiler don't do a linker phase, the only option is to reassemble the whole IDE with a lower start address. It is basically the same as the above, but you have to recompile and modify the Makefile with the added option.

Here you can also modify the file "fastbasic.cfg" and recompile, this will change the default value for the IDE and the cross-compiler.
 

how can you divide these values of the data line into several lines?
It is an asm program.
 
 

data ml() byte =  $68,$68, $A2, $00, $A9, $00, $9D, $40, $BC, $9D, $40, $BD, 
                  $9D, $40, $BE, $9D, $40, $BF, $E8, $D0, $F1, $A9, 
                  $2D, $A2, $0C, $60
  
? i, usr(adr(ml),i)
 
repeat
until Key()


You need to repeat the "data byte" line:
data ml() byte =  $68,$68, $A2, $00, $A9, $00, $9D, $40, $BC, $9D, $40, $BD, 
data byte = $9D, $40, $BE, $9D, $40, $BF, $E8, $D0, $F1, $A9, 
data byte =     $2D, $A2, $0C, $60  
This is a quirk of the parser that allows it to parse one line at a time without context, this makes the native parser use a lot less memory.
 

? i, usr(adr(ml),i)
 
repeat
until Key()
asm-source clearscreen :

  ldx #0
  lda #0
loop 
  sta $bc40,x
  sta $bd40,x
  sta $be40,x
  sta $bf40,x
  inx
  bne loop
  lda #45
  ldx #12
  rts

That don't work: you are calling the USR function with one parameter "i", but you are not removing the parameter from the stack. Simply call it without the second parameter: "? usr(adr(ml))".

Hope it helps!





Also tagged with one or more of these keywords: basic, compiler, interpreter

0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users