Jump to content
IGNORED

Atari Basic XL ver C


Recommended Posts

I had a question from a work colleague that I couldn't answer, he wanted to know how the BASIC interpreter compiles and executes the code, ie is it just in time or compiles it then executes. As theres no perceivable delay on RUN, I wasnt sure, i thought it tokenized it as you entered each line. Given memory and CPU limitations compiling separate code on RUN seemed wrong, but i have no idea.

Link to comment
Share on other sites

I had a question from a work colleague that I couldn't answer, he wanted to know how the BASIC interpreter compiles and executes the code, ie is it just in time or compiles it then executes. As theres no perceivable delay on RUN, I wasnt sure, i thought it tokenized it as you entered each line. Given memory and CPU limitations compiling separate code on RUN seemed wrong, but i have no idea.

 

baktra is correct, keywords are tokenized on entry and then the code is interpreted when you type RUN.

 

If the BASIC code were compiled to machine code, you'd definitely know it.

Programs would run incredibly fast. 8 bits are slow, but they aren't that slow.

On the other hand, they aren't fast enough for just in time compilation from BASIC to machine code.

BASIC compilers could take over a minute to compile even a small program. Large programs might require a coffee break.

The compilers themselves often require a minimum of 32K of RAM just for the compiler, and the program being compiled usually has to reside on disk.

 

Just in time compilation might have been possible for some of the byte code interpreters once there was enough RAM, but that's after a compiler has done the heavy lifting to generate the byte codes in the first place. This would be similar to just in time compilation of Java byte codes on modern machines.

Given a few more years of development, you might have seen something like that with the UCSD P-Machine.

It supported UCSD Pascal, BASIC, Fortran, and other compilers. But 16 & 32 bit CPUs were taking over by then.

 

Link to comment
Share on other sites

Hi!

 

Thanks guys that confirms what I deduced. On a side quest I was looking at compilers for Atari BASIC or Turbo Basic XL, I came across a forum stating there was a compiler (TurboBasicXL.arc) that forms a stand alone .EXE for Turbo Basic, as supposed to using the .OBJ runtime.

You can look also to my FastBasic https://github.com/dmsc/fastbasic/blob/master/README.md, this is a complete editor+compiler (to an optimized byte-code) fast enough to just compile after each edit. You can download the ATR from https://github.com/dmsc/fastbasic/releases/download/v1/fastbasic-v1.atr

 

The IDE can also compile to disk, writing a standard atari executable.

Edited by dmsc
  • Like 2
Link to comment
Share on other sites

Hi!

 

 

You can look also to my FastBasic https://github.com/dmsc/fastbasic/blob/master/README.md, this is a complete editor+compiler (to an optimized byte-code) fast enough to just compile after each edit. You can download the ATR from https://github.com/dmsc/fastbasic/releases/download/v1/fastbasic-v1.atr

 

The IDE can also compile to disk, writing a standard atari executable.

 

 

Wow, will certainly check this out. Can I open Atari or Turbo Basic in it?

Link to comment
Share on other sites

Atari BASIC tokenizes the code as you enter each line.

After entering RUN, Atari BASIC interprets the tokenized code (using a kind of pushdown store-based interpreter). There is no compilation to machine code involved.

 

Correct, though straight compilation does not add that much of an advantage, unless the compiler is also able to optimize the machine code. Just to give you an idea: If math is used a lot in a BASIC program, the limiting factor is not the basic interpretation itself, but the math code. Another limiting factor is the rather "simple" method by which Atari Basic looks for line numbers on GOTO, GOSUB, FOR and IF.

 

If you "compile" your program with the ABC "Compiler" (just to mention a popular compiler), the result is not machine code either. It is a pseudo-code, that is also interpreted at run time, though the interpretation is faster, the mathematics is all-integer, and the line-number search is a binary bisection on a fixed table that is much faster than the original linear search Atari Basic performs.

 

I do not know what FastBasic does, i.e. wether the output is machine code or just a pseudo-code.

Link to comment
Share on other sites

Hi!

 

Correct, though straight compilation does not add that much of an advantage, unless the compiler is also able to optimize the machine code. Just to give you an idea: If math is used a lot in a BASIC program, the limiting factor is not the basic interpretation itself, but the math code. Another limiting factor is the rather "simple" method by which Atari Basic looks for line numbers on GOTO, GOSUB, FOR and IF.

 

If you "compile" your program with the ABC "Compiler" (just to mention a popular compiler), the result is not machine code either. It is a pseudo-code, that is also interpreted at run time, though the interpretation is faster, the mathematics is all-integer, and the line-number search is a binary bisection on a fixed table that is much faster than the original linear search Atari Basic performs.

 

I do not know what FastBasic does, i.e. wether the output is machine code or just a pseudo-code.

The output is pseudo-code, just a simple stack-based byte-code run with a fast interpreter. The parser converts basic text to this byte-code at run-time, replacing simple statements like "COLOR 2" with "POKE COLOR, 2" and "POSITION X, Y" with "DPOKE COLCRS, X : POKE ROWCRS, Y". This keeps the byte-code under less than 128 codes (101 opcodes currently), allowing a simply indexing for jumping to the next instruction.

 

The cross-compiler also optimizes the byte-code via a peephole, this makes the compiled program smaller and a little faster.

  • Like 2
Link to comment
Share on other sites

Hi!

 

Wow, will certainly check this out. Can I open Atari or Turbo Basic in it?

No, as the IDE does not support tokenized formats and the language does not support line numbers.

 

You can list a BASIC program (via LIST "D:MYPROG.LST") and open the resulting list in FastBasic, edit to remove line numbers and rework the program. Simple programs should be easy to convert, main difference will be with integer variables. See the manual at https://github.com/dmsc/fastbasic/blob/master/manual.md

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...