Hi Paul,
I got a 2x speedup by making two changes.
1) adding some type declarations to the vm and insn tuples:
TUPLE: peg-vm { str string } { insns vector } { pc fixnum } { pos
fixnum } { stack vector } { cap vector } ;
TUPLE: insn { type fixnum } { off fixnum } aux ;
To get the latter to
2009/1/28 Slava Pestov sl...@factorcode.org:
That's a pretty decent speedup.
On my machine, I'm now getting run times of 0.39 seconds, vs 0.14 for
C - that's under 3x C's speed, which is pretty incredible for
high-level code like this!
Thanks for all the hints.
Paul.
One thing I noticed about your code is that you're using stack
shufflers in a few places where you could use combinators. For
example, stuff like
dup pc over instructions nth
should be
dup [ pc ] [ instructions bi nth
Also, generally words should not leave their inputs on the stack, with
only
2009/1/28 Slava Pestov sl...@factorcode.org:
One thing I noticed about your code is that you're using stack
shufflers in a few places where you could use combinators.
[...]
Also, generally words should not leave their inputs on the stack, with
only a few exceptions (like tuple setters that are
2009/1/21 Slava Pestov sl...@factorcode.org:
One other thing to try: declare any words which operate on your VM
tuple 'inline', then supposing the exec word has effect ( vm insn --
vm ), put hints on it:
HINTS: exec vm instruction ;
I'm slightly confused between this and the documentation,
2009/1/21 Slava Pestov sl...@factorcode.org:
Hi Paul,
If you're looking to make instruction dispatch fast in your VM, one
thing worth trying is to use a 'case' indexed by enum elements.
Hmm, that's actually very slightly *slower* than a generic-based
approach. (Generics are 1.2s, case-based
2009/1/21 Slava Pestov sl...@factorcode.org:
Have you seen C-ENUM: in alien.syntax?
No, I hadn't. Thanks for the pointer. It's nice to see that it's quite
similar to mine :-)
This word is in alien.syntax
because we generally only use it when interfacing with C libraries. If
you just need
Hi Paul,
If you're looking to make instruction dispatch fast in your VM, one
thing worth trying is to use a 'case' indexed by enum elements.
You'll need to cook up some parsing words, first.
IN: lpeg
...
SYMBOL: instructions
H{ } clone instructions set-global
! INSN: word body ;
: INSN:
I couldn't find any way in Factor to define an enumeration, as in C -
a series of symbolic names for consecutive numbers. I may well have
missed one, but after a bit of digging in the documentation, I decided
it was probably easy enough to define my own. So I did :-)
If this is of any use to