Re: ideas for a BASIC compiler



Frank Buss wrote:

I've started a BASIC compiler, first for PICs, but later I plan to use this
for ARM platforms, too. This is an example source code:

http://www.frank-buss.de/tmp/test.bas.txt

this is the generated assembler code:

http://www.frank-buss.de/tmp/main.asm.txt

and this is the compiler:

http://www.frank-buss.de/tmp/compiler.lisp.txt

A lot of things are missing, like a full expression evaluator and a some
more BASIC keywords, like if-endif, but at least it works.

It is inspired by BASIC stamp and PIC Basic, but I'm not sure about how to
handle register access (or memory access on ARM). PEEK and POKE looks too
cumbersome to write each time I need it, because in embedded systems it is
needed a lot. My idea is to use some default rules: If you write

timerValue = TMR0

this means, the register TMR0 is read and the result is saved in the
register timerValue. But if you write:

foo = 42

this means, the value 42 is saved to register foo. So in general, if you
use symbols, the values of the symbols are read or written, but if you use
numbers, the numbers themselfs are used. I think this is the most common
usage.

If you really want to read the register 42, I think a C-like syntax would
be good:

foo = *42

Same if you want to get the register address, instead of the register
value:

foo = &TMR0

You can write the full form every time you want. This is the same:

timerValue = TMR0
*timerValue = *TMR0

Do you think this is easy to understand for programmer beginners?

If you are gettng that close to C, you are going to confuse beginners.
clearer is more Pascal like :
foo = ADDRESS(TMR0)

Should I implement arrays, structs and strings, too?

Without those, it will be very limited.

The goal is that it can be used
by beginners without problems, but it should be powerful enough to use all
features of the platform where it runs.

Another question is how to use functions. On a PIC there is no data stack,
so parameter passing has to be done with implicit defined variables, which
makes the compiler more complex. And I'm not sure, if it makes sense for
small PICs like the 12F508, which has a call stack of 2 levels, only.

But on ARM CPUs the BASIC programs could become really large, so structured
programming with functions would be nice. Do you think it is better to
develop two different BASIC implementations, a small one for small PICs and
a large one, with functions, arrays, interrupts, mutithreading etc., for
bigger PICs and other bigger CPUs? This would make it more difficult to
share source code between the systems, e.g. a general program for a sigma
delta converter.

That's a big jump, from a vanilla PIC, to ARM.

You need to think about Debug, and simulation, and if possible, allow
syntax that allows a PC version of the compiler to compile code (possible with different header files) - OR make it work really well
with a vendors low cost ICE, so simullation uses silicon.

What are the PIC In_circuit_debug solution priced at ?

-jg







.



Relevant Pages

  • ideas for a BASIC compiler
    ... I've started a BASIC compiler, first for PICs, but later I plan to use this ... handle register access (or memory access on ARM). ... share source code between the systems, e.g. a general program for a sigma ...
    (comp.arch.embedded)
  • Re: Function seems to re-initialize arguments
    ... If that is actually how myFunc looks, that is it doesn't ever use foo, ... bar and slug, then it is quite possible that an optimising compiler is ... the compiler decides that foo is ... stored in register 1 and bar is stored in register 2, ...
    (comp.lang.c)
  • Re: switch statement, was compiler, status...
    ... Primary Register, Secondary Register, ... Stack, and abit of storage does it. ... This version of Small-C is copyrighted as a revision to Ron Cain's ... Croatia) is "Calculator Compiler" by Senko Rasik. ...
    (alt.lang.asm)
  • Re: Bad performance on alpha? (make buildworld)
    ... It's been a few years since I'd written a compiler, ... it is 4-way superscalar but the different execution ... instruction decode stages rather than just the integer pipeline), ... > architecture and relying on the L1 cache to handle the register spills ...
    (freebsd-performance)
  • Re: Can someone spot the error here?
    ... at the bottom of a function, or as nearly at the bottom as possible. ... in a register, or even in a flag. ... the need for the programmer to be studied in compiler construction. ... the optimizer will recognize this ...
    (comp.lang.pascal.misc)