[comp.lang.modula3] LOCATION

buschman@tubsibr.uucp (Andreas Buschmann) (04/15/91)

Hi!
> >       For my interpreter I created a procedureal operator LOCATION:
> >  
> >  	LOCATION (VAR x: Any) : REF Any
> >  
> >       How is this supposed to go in the new standard?
> 
> I don't understand.  Are you proposing that LOCATION be added to the
> language?  If so, you should post a full explanation of the proposal
> and its impact.  For instance, it appears to me that LOCATION would
> place great constraints on the possible allocator/collector implementations.
> Since I can use LOCATION to create a REF to an arbirary field in an
> arbitrary record, the collector cannot assume that type tags are near by?
> 
>   - Bill Kalsow

no, I am not sure about proposing this to be added to the language. At
this moment it is a local hack of mine, which doesn't interfere with
my heap storage implementation (I am using bitmaps to keep track of
which storage is still in use). What I want to know is: how do I get
the same effect, with legal actions defined in Modula3.

						Tschuess
							Andreas

A C example of what I want to do:

typedef struct node {
	struct node *next;
	int info;
} NODE;

#define NO_NODE ((NODE*) 0)


insert (NODE **list; NODE *new_node)
{
	NODE **ptr;

	for (ptr = list; 
	     *ptr != NO_NODE && (*ptr) -> info < new_node -> info; 
	     ptr = &((*ptr) -> next));

	new_node -> next = *ptr;
	*ptr = new_node;
}

in Algol68 this would be:

MODE NODE = STRUCT (
	REF NODE next;
	INT info
);

REF NODE no node = NIL;

PROC insert (REF REF NODE list; REF NODE new node) =
BEGIN
  REF REF NODE ptr;

  ptr := list;
  WHILE (ptr <> no node | info OF ptr < info OF new node | false)  DO
    ptr := next OF ptr
  OD;

  next OF new node := ptr;
  REF NODE ptr := new node
END

kalsow (Bill Kalsow) (04/15/91)

I don't think it's possible to simulate LOCATION in Modula-3.
It's possible to LOOPHOLE ADDRESSs to REFANYs in the unsafe
part of the langugage.   There's no guarantee that the result
is usable.

  - Bill Kalsow

hudson@yough.cs.umass.edu (Rick Hudson) (04/16/91)

buschman@tubsibr writes:
> Hi!
> > >       For my interpreter I created a procedural operator LOCATION:
> > >  
> > >  	LOCATION (VAR x: Any) : REF Any
> > >  
> > >       How is this supposed to go in the new standard?
> > 
> > I don't understand.  Are you proposing that LOCATION be added to the
> > language?  If so, you should post a full explanation of the proposal
> > and its impact.  For instance, it appears to me that LOCATION would
> > place great constraints on the possible allocator/collector implementations.
> > Since I can use LOCATION to create a REF to an arbitrary field in an
> > arbitrary record, the collector cannot assume that type tags are near by?
> > 
> >   - Bill Kalsow
> 
> no, I am not sure about proposing this to be added to the language. At
> this moment it is a local hack of mine, which doesn't interfere with
> my heap storage implementation (I am using bitmaps to keep track of
> which storage is still in use). What I want to know is: how do I get
> the same effect, with legal actions defined in Modula3.

Module-3 the language has outlawed such actions. Bill Kalsow has indicated a
one of the reasons. When I implement list manipulating routines I tend to do
it recursively. If I am concerned about efficiency, I restrict my recursion to
be tail recursion. Any reasonable compiler will optimize away the tail
recursion leaving me with readable and efficient code :-).

- Rick