Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Hey /prog/

Name: Anonymous 2012-03-07 3:41

improve my virtual machine

git clone https://code.google.com/p/gpvm/

Forgive my lack of documentation. This will be remidied shortly. Also, some instructions remain unimplemented, as I haven't found a use for them yet.

Also, note the absolute lack of references (int &a = b). Haskell has created the idea in my head they are not needed, but I can see them being useful and I will almost undoubtedly implement them at some point.

I look forward to sorting through your abuse to see if anyone says anything constructive.

Name: 6 2012-03-08 4:13

>>17,29
#define NEXT(t) \
  if (++t->ip < t->code_size) { \
    return cycle(t); /* tail-call */ \
  } else { \
    return 0; \
  }

typedef int(*ins_f)(vm_thread_t*);

int cycle(vm_thread_t* t);

int ins_tsun(vm_thread_t* t)
{
  puts("tsun");
  NEXT(t)
}

int ins_dere(vm_thread_t* t)
{
  puts("dere");
  NEXT(t)
}

int ins_hlt(vm_thread_t* t)
{
  return 0;
}

/* inlined */
int cycle(vm_thread_t* t)
{
  static const ins_f ins[4] = {
    ins_tsun, ins_dere, ins_hlt, ins_hlt
  };
  /* tail-call and bounds checking through optimized modulo */
  return ins[t->code[t->ip] & 0x3](t);
}


This is a minimal, not executable and untested example and it's very dependent on compiler optimization but it should be the most efficient instruction dispatching design, at least on GCC for x86, mainly because it makes the loop implicit. You might want to directly write assembly in order to avoid overflowing the stack with inferior compilers.

By the way, >>1, your code doesn't react well to malformed instructions.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List