Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 16:59 11 Nov 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : An interesting DOS debug bonus.

Author Message
Paul_L
Guru

Joined: 03/03/2016
Location: United States
Posts: 769
Posted: 03:05am 17 Jul 2018
Copy link to clipboard 
Print this post

I've got this (so far) 1579 line 58KB program in the works. The first 80 lines or so are devoted to declaring variables and reading calibration values into variables.

Then the main loop begins.

I stuck a MEMORY then an END command just before the beginning of the main loop. I wanted to know how much memory this thing uses after the variables are declared and filled. So I ran it expecting it to just end before looping.

Guess what, the darned thing began crashing with errors triggered by typos, undeclared variables, wrong type variables passed to subs and functions and other assorted booboos. All of these crashes were triggered well after the END command, as far down as line 1523. It was finding my errors before it ran the code! It did this 14 times, each time finding one more of my screwups. I fixed them all and it terminated with the memory display just before the main loop began, the way I expected.

In other words, this thing does some sort of pre-interpretation of code as it is loaded but before it has the opportunity to run the code!!! I don't know how an interpreter does that!!

Geoff, you have to be some sort of mad genius, an interpreter that pre-compiles and doesn't tell anybody!!!! How did you do that, and when are you going to put a great big DONATE button on your website?????

Paul in NY
Edited by Paul_L 2018-07-18
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3308
Posted: 09:25am 17 Jul 2018
Copy link to clipboard 
Print this post

That is a large program that you have!

MMBasic does two levels of pre processing. The first is when the program is loaded into memory and a preprocessor turns command names, function names, operators and keywords into single byte tokens. This means that when the program is running the interpreter can use the value of the token to very quickly look up the C code to handle a command. You can get some errors from this process but they are rare.

When you type RUN, MMBasic then scans the entire program to find user defined subroutines and functions. As part of this it builds a table of these and their location in the program. That way when the interpreter hits a sub/fun in the BASIC program it can immediately jump to the direct spot without having to scan looking for it. In the Micromite this process also indexes CFunctions and fonts.

There are also other optimisations such as caching that is used in some critical areas.

Some time ago I built a special version of MMBasic which measured how much time was spend in various sections of the interpreter. After running a lot of test programs I had a good idea of where optimisation would give the best results.

It is all good fun and keeps me "off the streets". Much better than doing crosswords.

Geoff
Geoff Graham - http://geoffg.net
 
Paul_L
Guru

Joined: 03/03/2016
Location: United States
Posts: 769
Posted: 07:05pm 17 Jul 2018
Copy link to clipboard 
Print this post

Hi Geoff.

Nah it's only a tiny program. (Remember, I'm a old mainframer, you have to hit 25,000 lines before a program is a teenager.) If I can debug this thing under DOS I might just be able to get it running for real before I die.

I assumed that MMBasic went through the usual tokenization and jump table building, essentially building links to Cfunctions. The index of CFunctions and fonts is a nice touch which was dictated by the touch screen functions I guess.

But I still don't understand how this thing was catching undefined variables, errors in passing parameters, and other screwups after the END command. It never actually ran that code, it found the END command after the first 80 lines.

Like you, I am doing this to keep me from regressing into driving hot rods and chasing girls.

Where's the DONATE button, damn it!!!!

Paul in NY
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025