[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Basic compiler



Knut Roll-Lund wrote:
Michael J. Mahon wrote:

Knut Roll-Lund wrote:

I'm surprised, on the TRS-80 which also has Microsoft basic, though a bit differently looking, does integer operations on integers (and it is an important point to use integers for speed). This is so except for division where the actual division is done in single precision. Even constants are done as integers as long as they fit.



In Applesoft, constants are represented in ASCII in the program
text and converted on each use.  This is why assigning a frequently
used constant to a variable speeds up a program.


Yes A=1:B=A is faster than A=1:B=1 this is similar, constants are stored as ascii also on a TRS-80, but when converted they start out as integers and will convert to single or double precision as needed.

I believe this approach is common to all interpreted Microsoft BASICs.

Whether integer arithmetic or floating point arithmetic is used in
evaluating constants is an implementation decision, regardless of
the final number format desired, assuming that sufficient precision
is retained (32-bit integers, for example).

I'd have to look at the disassembly to see exactly what Applesoft
does.  (If I were doing it, I'd accumulate the integer in the FAC
mantissa, keeping note of where/if I saw a decimal point and/or
exponent.  Then I'd scale in floating point if required, and then
return either the integer or the FP result, as required.)

Of course, having to convert ASCII to binary on each use is painful
with integer operations (multiply by 10 and add for each digit),
but excruciating with FP ops (same thing, but much slower).  ;-)

Line numbers after THEN, ELSE, GOTO or GOSUB are also stored as ASCII but the line numbers themselves (at the beginning of a line) is stored digitally 16 bit.

Right.  The only case I can think of that is kept in binary--and it's a
good thing, since branches (but not FOR loops) require searching the
line list each time!

I have a basic compiler for the TRS-80 that does a strange hybrid thing; ACCEL2. I bought it back in the old days. It will put assembly into comments within the basic program and there is a small runtime library too. It will compile only what is advantageous. The output is smaller and a lot faster.

An interesting approach...so it must "patch" the BASIC program so that
it gets control to the machine code?

I remember looking into a scheme to pre-compute branch targets in
Applesoft programs to eliminate the need to search the program
repeatedly.  I finally got an accelerator and just let it go.  ;-)

The Microsoft basic came with the TRS-80 (Model I) Level II that came in August 1978. The original TRS-80 Microcomputer (Model I Level I) from August 1977 had a basic that was made by Tandy famous for its error messages: 3 in all WHAT?, HOW? and SORRY (means syntaxerr, outofrange and outofmemory respectively). :-)

In the tradition of the JOSS language for the Johnniac computer at
RAND, which had exactly one error message:  Eh?

So it is not unique :-)

The idea was that JOSS statements were pretty simple, so if you
called the scientist's attention to a statement with an error, it
would be "obvious".  ;-)

I write software and identifying and then explaining to the user and/or log what went wrong is so much tedious work. But of course I benefit from it too getting less phone calls from frustrated users, or can at least identify what is wrong so I can help them.

Back in the "bad old days" we just told them to RTFM--if they couldn't
either figure it out or document a bug, they weren't smart enough to
use the computer.  ;-)

-michael

NadaNet networking for Apple II computers!
Home page:  http://members.aol.com/MJMahon/

"The wastebasket is our most important design
tool--and it's seriously underused."