|
 |
CS 3723
Programming Languages
|
Tiny® Extensions |
Overview:
This page shows several of ways that the Tiny®
project might be extended. The main message is that
modest extensions can be surprisingly easy.
All calculations in floating point:
It is very easy to fix up the compiler so that it outputs
MIPS floating point instructions instead of integer ones. I used only
the double format (64-bit), and not float
(32-bit). See
Tiny® with Doubles.
Declarations of Basic Types:
Suppose we want to add declarations of variables of either
int or double type. We would have to decide on
a syntax for declarations: for now just assume that
- I i, j, k ; means that
i, j, and k are int type, and
- D x, y, z ; means that
x, y, and z are double type.
The natural and convenient way to handle this is to maintain
a Symbol Table, that is, a table of all identifiers in
the program. The entry for a given identifier would include
information about that identifier, in this case
- the address to
use for the identifier as a variable, and
- whether the variable was
to be an int or a double.
When declared the information would
be stuck in. When the identifier is used later, the type
could be retrieved by the compiler. If an identifier is used
without declaration, the compiler could assume a default declaration,
or it could require a declaration and issue an error message.
Assuming the declarations above, in a statement such
as y = x + i ; the compiler would look up the types of
x and i, and decide that i needed
conversion to a double.
The compiler could issue extra code to do this.
Implementing Arrays:
Here again, we need a syntax for arrays. Suppose
that we use "[8]" along with the declarations above
for an array of ints or doubles of size 8,
and suppose that
means that i is declared as an array of 20 ints.
(Notice that I'm also sneaking in multi-digit constants.)
Then this information would be stored in the symbol table.
Knowing the type of the array, we know how much storage to
allocate, and we can do the address calculation to get
the offset of, say i[8] from the start of i,
namely 8*4 = 32 bytes.
Revision date: 2013-02-21.
(Please use ISO
8601, the International Standard.)
|