entrypoint : () -> (){ debugwritestring(lexicalcast(string, pi()))}pi : () -> (real){ real(retval, 0.0) real(denominator, 1.0) boolean(isplus, true) do { real(div, 0.0) assign(div, divide(4.0, denominator)) if(equal(isplus, true)) { assign(retval, add(retval, div)) assign(isplus, false) } else { assign(retval, subtract(retval, div)) assign(isplus, true) } assign(denominator, add(denominator, 2.0)) } while(less(denominator, 10000.0)) add(retval, 0.0)}
Execution time averaged 31ms on my machine. Not bad for a hacked up VM with no optimization support [smile]
Unfortunately, this turned up a couple of bugs in the built-in arithmetic operators. Specifically, in some cases the operands will be accidentally reversed, so instead of, say, 5 - foo, you get foo - 5. This is obviously a problem.
Eventually I'll hunt back through the code for the arithmetic operators and make sure everything is correct, but for now my brain is thoroughly fried.
You may also notice a couple of weird things in the above code, such as the trailing add(retval, 0.0) operation, or the fact that the div variable is somewhat superfluous. This just reflects areas of the language that aren't fully implemented; I still have to finish up a few various permutations of passing things around. Everything is a step forwards, though, and so far I haven't encountered any significant issues that would force me to redo parts of the VM.
I think the next step will be to tackle structures... that seems like a sufficiently big and scary thing to warrant another release once it's done [smile]