www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Indirect jumps

reply Christian <chrisperx hotmail.com> writes:
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.
Jan 17 2008
next sibling parent reply Paul Findlay <r.lph50+d gmail.com> writes:
 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
Jan 17 2008
parent Christian <chrisperx hotmail.com> writes:
 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.
Jan 18 2008
prev sibling parent reply DQNOK <davidlqualls gmail.com> writes:
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
Jan 17 2008
parent reply Christian <chrisperx hotmail.com> writes:
 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.
Jan 18 2008
parent bearophile <bearophileHUGS lycos.com> writes:
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
Jan 18 2008