Re: Language design/VM design (Stephan Houben)
1 Apr 2000 14:05:48 -0500

          From comp.compilers

Related articles
[2 earlier articles]
Re: Language design/VM design (Jeremy Boden) (2000-03-06)
Re: Language design/VM design (Floris 'Tamama' van Gog) (2000-03-11)
Re: Language design/VM design (Jeremy Boden) (2000-03-23)
Re: Language design/VM design (Alan Fargusson) (2000-03-23)
Re: Language design/VM design (Joachim Durchholz) (2000-03-23)
Re: Language design/VM design (Floris 'Tamama' van Gog) (2000-03-28)
Re: Language design/VM design (2000-04-01)
| List of all articles for this month |

From: (Stephan Houben)
Newsgroups: comp.compilers
Date: 1 Apr 2000 14:05:48 -0500
Organization: Eindhoven University of Technology, The Netherlands
References: 00-02-138 00-03-102 00-03-147
Keywords: design, interpreter

Floris 'Tamama' van Gog <> wrote:
>Now it would be kinda bad if the VM would execute a script that then
>crashes the host-program. For this I need this pointer safety (static
>arrays are bound-checked at compile time if possible). But while
>thinking I came up with the idea not to check if the access is within
>VM space, but whether or not that access is within it's array it's
>supposed to be in as well.

I.e. you want to have boundary-checked arrays.

This is commonly implemented by adding to every array a header
that contains the number of elements. Your array (pointed to by p)
now looks like this:

p -> +------+
          |size |
          |item 0|
          |item 1|
          |item 2|

The disadvantage is that you have to add some constant offset to
p before referencing into the array. A trick to avoid this is to
have p pointed to the first item:

          |size |
p -> +------+
          |item 0|
          |item 1|
          |item 2|

But now you have to subtract a constant offset from p to get the size.
However, whenever your compiler can do compile-time boundary checking,
this can be avoided, and then array indexing is as fast as in C.

Having pointers that point into the middle of an array is more
problematic. One way is to represent such pointers as a pair
(array base, offset). Then do boundary checking when dereferencing
the pointer.

On a language design point of view: I think that C's way of
confusing arrays and pointers is difficult to understand and difficult
to implement. So perhaps you shouldn't try to reproduce it.


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.