Embedded Basic Requirements (was Prop II: Too little, too late ???)
David Betz
Posts: 14,516
(I've started this new thread to avoid hijacking the Propeller 2 thread)
Please define "complete BASIC Compiler". I'm working on a version of basic for the Propeller and I'd be interested to know what you think is needed for it to be complete.
Thanks,
David
davidsaunders wrote: »Leon:
No it is not, though neither is this old school thing (VB) that you keep mentioning. Unfortunately I am not aware of any complete BASIC compilers that are good for embedded development. Perhaps PropBASIC could become one if the effort is put into it to make it a complete BASIC Compiler.
Please define "complete BASIC Compiler". I'm working on a version of basic for the Propeller and I'd be interested to know what you think is needed for it to be complete.
Thanks,
David
Comments
In that case I'm sure PropBasic already qualifies! :-)
Seriously, I'd like this thing that I'm building to be useful. Can you suggest what features it needs to have beyond the normal variables, assignment statements, if/then/else, loops, functions with parameters, etc? Obviously, it will need some equivilent to waitcnt, waitpne, waitpeq to be useful on the Propeller and also access to the COG registers like dira, ina, outa, etc. What else?
A complete BASIC by modern standards (to the way I understand) would be as fallows:
1) Generation 2 Structured BASIC structure and syntax.
2) Includes all the ANSI BASIC keywords.
3) Has minimally the types:
3.A) LONG
3.B) SHORT
3.C) BYTE
3.D) STRING
3.E) UNSIGNED (modifier)
3.F) INTEGER
3.G) FLOAT (some use REAL instead).
3.H) User types (Array, TYPE...END TYPE, etc).
3.G) Pointer types, for all types (including FUNCTION/SUB, and ANY PTR).
4) Typed, all variables must be declared.
5) Scope declaration for all variables and pointers.
6) Dynamic memory allocation.
7) Compiled language.
Some would say that the OO features are needed, I disagree, BASIC does not have to be OO.
The above list represents what appears to be standard for modern BASICs, as far as I am aware.
We are not talking about a early generation BASIC here.
Leon:
I think that all BASICs are Turing complete.
1) No BASIC bashing
2) No arguments over Open Source, Eclipse, Microsoft...
that said...
It should support different memory models, at least the following:
PASM Only, code fits in a cog, all native PASM
LMM
XMM
The ability to have inline PASM,LMM,XMM code would be nice.
Defines: #ifdef, etc.
I'm sure there is more.
C.W.
Ideally (not required), it should be self compiling.
ctwardell:
Thank You.
Okay, this is getting at what I'm looking for. In particular, do people think that dynamic strings are necessary in an embedded Basic? While it isn't that hard to implement a heap manager, it complicates the runtime significantly for possibly litte benefit (other than being able to run startrek.bas!). I tried this in an earlier version of my compiler but later realized that adding functions with parameters makes having dynamically allocated objects much harder. You have to be able to locate all "live" objects when the garbage collector is called and that requires that you know the type of every item on the stack. Maybe there is a simple way to handle this but I couldn't think of anything other than having a type tag associated with every stack entry or some sort of arguments/locals type map associated with every function.
So my question is, are dynamic strings really necessary? If so, does someone have a good idea of how to handle them in an embedded runtime environment?
STRING(80) line_buff, args
and I'd probably just use plain null-terminated strings
This would allow string overruns, however we are talking about a small microcontroller with limited resources - trying to shoehorn some big system features is contra-indicated if the plain 32K hub model is to be well supported.
Though Dynamic memory with ALLOCATE, FREE keywords is needed. Also there is no reason to track every type (except in the case of using Dynamic Strings [not needed]).
I think you mean:
DIM MyStr AS STRING 80
Is this correct? Remember this is BASIC.
Happy Birthday Leon and davidsaunders!
Thank You.
Happy Birthday Leon and David Saunders!
I was thinking early generation basic, as that is a closer fit to the size of a Prop board... you are entirely correct with regards to the syntax of more modern basic's declaration of fixed length strings :-)
http://www.freebasic.net/wiki/wikka.php?wakka=DocToc
Ray
Explicit memory allocation isn't a problem. It's automatic garbage collection that is difficult. You have to know the type of every value.
Not to mention that you would probably want to be able to compile somethings to fit entirely in cog memory, for time critical applications. Though for stuff that must fit entirely in a COG I would omit the dynamic allocation functions.
Heap management is not that difficult. Just tag the length of the block of memory so that when the block is explicitly freed you know how much is freed, also keep it as a linked list (with all this in the 3 WORDS right before the block).
Thanks!
I'm 69, BTW.
I suspect what you describe is perfectly possible. It's just that it would take far more effort than I'm able to put into it at the moment. I'll wait for your implementation! :-)