Thread overview
Indirect jumps
Jan 17, 2008
Christian
Jan 17, 2008
Paul Findlay
Jan 18, 2008
Christian
Jan 17, 2008
DQNOK
Jan 18, 2008
Christian
Jan 18, 2008
bearophile
January 17, 2008
Hi,

I would like to implement a direct threaded interpreter and I need support for indirect jumps. I know how to make this in gcc using label references (operator &&):

void interp() {
  void *labelref = &&mylabel;

  goto *labelref;

mylabel:
  ...
}

does dmd or gdc support this ?

I can't use delegates or function pointers since i need the best performance possible (without using assembler).

Thanks in advance,
Christian.
January 17, 2008
> I would like to implement a direct threaded interpreter and I need support for indirect jumps

> does dmd or gdc support this ?
Unfortunately no. Past conversation: http://www.digitalmars.com/d/archives/digitalmars/D/Feature_request_First_class_labels_53208.html

 - Paul
January 17, 2008
And nested functions won't do the trick?  I kind of thought that is what nested functions were for: the ability to access local variables without the overhead of pushing pointers to all of them onto the stack.

david
January 18, 2008
> And nested functions won't do the trick?  I kind of thought that is what nested functions were for: the ability to access local variables without the overhead of pushing pointers to all of them onto the stack.

I will study this possibility. But I think that it is not possible, because the functions are called through indirection. The pointer to the function would be saved to memory and then would be called using this pointer, then how know the compiler that this call is for a nested function?.

Christian.
January 18, 2008
> Unfortunately no. Past conversation: http://www.digitalmars.com/d/archives/digitalmars/D/Feature_request_First_class_labels_53208.html

Thanks, I have read this conversation.

I don't understand how a modern language like D don't support first class labels or something like this that permits make portable interpreters or dynamic recompilation using inlined direct threading.

Christian.
January 18, 2008
Christian Wrote>I think that it is not possible, because the functions are called through indirection. The pointer to the function would be saved to memory and then would be called using this pointer, then how know the compiler that this call is for a nested function?<

I think D delegates may help. And true closures of D 2.x may solve other problems left.

Bye,
bearophile