Lavalamp Posted December 12, 2017 Share Posted December 12, 2017 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. Quote Link to comment https://forums.atariage.com/topic/273047-atari-basic-xl-ver-c/ Share on other sites More sharing options...
baktra Posted December 12, 2017 Share Posted December 12, 2017 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. Quote Link to comment https://forums.atariage.com/topic/273047-atari-basic-xl-ver-c/#findComment-3910073 Share on other sites More sharing options...
JamesD Posted December 12, 2017 Share Posted December 12, 2017 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. Quote Link to comment https://forums.atariage.com/topic/273047-atari-basic-xl-ver-c/#findComment-3910204 Share on other sites More sharing options...
Lavalamp Posted December 12, 2017 Author Share Posted December 12, 2017 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. Quote Link to comment https://forums.atariage.com/topic/273047-atari-basic-xl-ver-c/#findComment-3910263 Share on other sites More sharing options...
dmsc Posted December 12, 2017 Share Posted December 12, 2017 (edited) 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 December 12, 2017 by dmsc 2 Quote Link to comment https://forums.atariage.com/topic/273047-atari-basic-xl-ver-c/#findComment-3910511 Share on other sites More sharing options...
Lavalamp Posted December 13, 2017 Author Share Posted December 13, 2017 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? Quote Link to comment https://forums.atariage.com/topic/273047-atari-basic-xl-ver-c/#findComment-3910705 Share on other sites More sharing options...
thorfdbg Posted December 14, 2017 Share Posted December 14, 2017 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. Quote Link to comment https://forums.atariage.com/topic/273047-atari-basic-xl-ver-c/#findComment-3911738 Share on other sites More sharing options...
dmsc Posted December 14, 2017 Share Posted December 14, 2017 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. 2 Quote Link to comment https://forums.atariage.com/topic/273047-atari-basic-xl-ver-c/#findComment-3911953 Share on other sites More sharing options...
dmsc Posted December 14, 2017 Share Posted December 14, 2017 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 Quote Link to comment https://forums.atariage.com/topic/273047-atari-basic-xl-ver-c/#findComment-3911960 Share on other sites More sharing options...
Recommended Posts
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.