• Please review our updated Terms and Rules here

QBasic - The Interpreted and Compiled Language.

Perhaps someone can answer this for me.

When the term "compiled BASIC' is used, exactly what is meant? For example, UCSD Pascal is compiled, but only to an intermediate code (P-code), not to native machine code. CBASIC does essentially the same thing, as does BASIC-M.

Then there's "compile to native machine code and optimize". Do any "compiled' BASICs do that (i.e. remove dead code, unroll loops, move code, remove invariant expressions from loops, perform register usage optimization, perform strength reduction, etc.)?
 
Perhaps someone can answer this for me.

When the term "compiled BASIC' is used, exactly what is meant? For example, UCSD Pascal is compiled, but only to an intermediate code (P-code), not to native machine code. CBASIC does essentially the same thing, as does BASIC-M.

I would describe those languages as 2-Pass Compilers where it takes your selected language and compiles to another, I'm not very familiar with the UCSD Pascal system/P-Code approach, so I don't know what happens with the P-Code, does another Language take that and convert into something fast for the machine like Forth?
I did a little CBASIC, but that was like 20 years ago when I made a little Starfield demo and then I had to Link a small Assembly subroutine which was done during the Linking phase (pass 2), to produce a timely moving starfield across all PCs, the CBASIC I made my main code from made an OBJ file that during the second pass generated the CMD file. Small-C is also 2 pass, but instead of generating an OBJ file it creates an Assembly file, which may also be a 2 step approach depending on the Assembler.

Compilers can either be 1-pass or 2-pass, a 2-pass compiler allows the end user to modify the code for optimization, the downside would be the time taken to improve, while a 1-pass simply compiles into a file ready for execution, optimization would be tricky if the compiler didn't perform that.

Then there's "compile to native machine code and optimize". Do any "compiled' BASICs do that (i.e. remove dead code, unroll loops, move code, remove invariant expressions from loops, perform register usage optimization, perform strength reduction, etc.)?

I'm not qualified to answer that, if there's a tone you're setting I would say No, though while reading earlier about QB64, it's goals are to produce C++ code and to use a C++ Compiler to produce the code, then maybe that's closer to producing optimized code?
 
Perhaps someone can answer this for me.

When the term "compiled BASIC' is used, exactly what is meant? For example, UCSD Pascal is compiled, but only to an intermediate code (P-code), not to native machine code. CBASIC does essentially the same thing, as does BASIC-M.

Then there's "compile to native machine code and optimize". Do any "compiled' BASICs do that (i.e. remove dead code, unroll loops, move code, remove invariant expressions from loops, perform register usage optimization, perform strength reduction, etc.)?

Some of the BASIC compilers did go all the way to native machine code. MS BASIC PDS, Borland TurboBASIC (now PowerBASIC), and FreeBASIC all could do it as an option. I think MS PDS also had the option of going to a form of P-Code instead. All three are supposed to optimize; FreeBASIC piggybacks off gcc optimizer. I haven't tested those optimizers at all. The last time I used PDS was back in 1990 when MS had put out the very poor optimizers in MS C 6 and I was reluctant to try any optimizing. No amount of clever optimizing was worth the risk of code that failed because of bugs in the optimizer.
 
Sorry--typo. BASIC-E. Predecessor of CBASIC; a Gordon Eubanks compiler.

Anent UCSD Pascal--the P-code is interpreted. Interestingly, on 8-bit hardware, P-code implementations are very often faster than compiling to native machine code. The reason is that most native machine code, particularly that involving floating point, essentially degenerates to a series of subroutine calls using a very limited register file, while a P-code instruction can be a single byte or two.

At one point, I posted some sample P-code generation from a BASIC compiler that I and my team wrote for 8085. I can probably dig it up if anyone's interested--our P-code isn't the same as UCSD's obviously. I recall that around 1982, a bunch of guys were roaming around at that year's NCC, benchmarking 8-bit BASICS. We absolutely clobbered Microsoft's compiled MBASIC.

As regards optimization, I do have some experience in automatic FORTRAN optimization on supercomputers. Some of the techniques can be pretty interesting.
 
Don't get me started on Microsoft's shady Compilers etc. from the '80s. That's where the phrase "Oh, that'll be fixed in the upcoming version" originated. I spend serious moolah to little real benefit in those days. Which is why I'm dismayed at their anti-competitive efforts in the past and their grip on the consumer market. An avaricious American company's attitude to business.
 
Back
Top