Re: more idle thinking: SiMPL



"BGB / cr88192" <cr88192@xxxxxxxxxxx> wrote in message
news:h9iv8m$h3s$1@xxxxxxxxxxxxxxxxxxxx

consider running C on something like the ActionScript VM.
the lack of a byte-centric memory model is likely to put a bit of a cramp
on
things...

int x;
int *pi;
...

pi=&x; //what, you mean I can't do this?...



Well, it might be possible to construct an artificial C style address
system. I'm not familiar with JavaScript or ActionScript. However, let's
start by me making some wild assumptions based on info from Wikipedia's
pages:

1) strings are available
2) arrays are available
3) memory for strings and arrays are dynamicly allocated, or actually hidden
behind some object action, like .push()
4) the memory allocated for each object, like strings and arrays, is
contiquous or sequentially allocated
5) strings and arrays are indexable/subscriptable...
6) the language is object-oriented, so an .length action should be available
for strings and arrays... (?)

So, to create an address system, you need to have a unique address for each
object and an index/offset/subscript where necessary. You also need the
size of objects. A hash function could generate unique "addresses" from an
object's name, e.g., to simulate the & address operator. A reverse hash
could return the object's name from the address, e.g., to simulate
dereferencing done by the * indirection operator. The strings and arrays
should be indexable or subscriptable with native language features. And,
the sizeof() the object could come from the .length action, or a "fake"
value table for int's since it should be fairly easy to determine sizes for
them. I think that should be about enough to comply with C, in theory...

Technically, the spec.'s don't mandate a memory model. However, yeah,
lots
of issues you have to solve if you're not on a "byte-centric" machine...


C -> JavaScript and C -> Scheme translation come to mind as problem
areas...


Obviously, the proper way is to rewrite the C without pointer usage, using
"arrays" or the subscript (or offset) operator, and then port it.

usually, this is done through keeping the syntax regular and
context-independent, but at the same time, this may cost some in terms of
"syntactic niceties", since these niceties are often special-case hacks in
the parser, and as such, adding them makes it more work to write a 3rd
party
parser (since they will also have to deal with all these little
special-case
hacks...).

Well, you could parse the language, and then add extra info where it's
needed to the source code. E.g., you could insert implicit int's, or add a
keyword to indicate typedef's, or convert "long long" to a single word.
That would make it easier for other parsers. If they don't what your extra
info, they just use a C pre-processor to #define it away.

You could also take the idea I'm using in my assembler and emit unique
characters infront of keywords, variables, hex integers, octal integers,
strings, characters, etc. so someone else's parser could be much simpler to
implement. E.g., if the parser sees ".while", it uses "." to indicate a
keyword immediately follows. Or, you might be able to emit and embed the
important info from the AST into the source code.


Rod Pemberton


.



Relevant Pages

  • Re: 32 or 64 bit processor info in C
    ... For a brief momenet we have the situation where int ... You could argue that all that memory won't be used for arrays. ... merely that the language isn't going to ...
    (comp.lang.c)
  • Re: beginners question on pointer arithmetic
    ... int *q; ... My uderstanding is that, only for arrays, ... q is now pointing to memory one int* beyond p; ... the code entirely; setting that to '0' terminates the string; while ...
    (comp.lang.c)
  • Re: 32 or 64 bit processor info in C
    ... For a brief momenet we have the situation where int ... and soon machines with 40 or 50 GB will be commonplace. ... You could argue that all that memory won't be used for arrays. ...
    (comp.lang.c)
  • Re: array of pointers
    ... All the three pointers point to literal strings, ... in memory that doesn't belong to you and that could be in read- ... If you want to change the memory the pointers are pointing ... > int size = strlen; ...
    (comp.lang.c)
  • Re: Compress int array, again
    ... the data has many many int[] arrays. ... So I choose to store the compressed ones in memory, ... > uncompress only to those necessary ones on the fly. ...
    (comp.lang.java.programmer)