2002-08-22 20:50:39 PDT
> I'm not familiar with ruby, but from your description the
> once method doesn't actually need to change the code
> segment. It wraps the function call in an if-statement,
> testing a static boolean that is set after the call and
> returning the already-computed value if it triggers.
Yes, it /could/ do it that way, but that would be inefficient, so it doesn't. The 'once' method actually rewrites the method so that the method returns the value computed after the first run. There is no 'if' branch involved. Branches are relatively expensive operations -- if I remember correctly, they're the most expensive single operations in an instruction set, more so because they tend to defeat pipelining look-ahead. So it is more efficient, and more elegant, to self-modify the code. Put another way: if you know in advance that the result is static after the first run, then isn't it a waste to execute a test-branch every time the method is called?
WRT bytecodes, you may be correct; I don't know. I thought I had read that the compilation process went Crush source -> Bytecode -> Native code, and that the second translation wasn't done 'on the fly'. As it appears that you and I are the only active members of this list (or the only ones interested in this topic), I guess we'll never know. I'm certainly not going to wade through a bunch of pseudo-Scheme code to find out ;-).
I can't see any obvious limitations for interpreted languages. I also can't see any obvious limitations on compilers for arbitrary languages that produce BRiX bytecode; I'm guessing that all of the security checking occurs during the second compile, where it would be most obvious. The one hitch would be the possible case that the BRiX bytecode doesn't support certain features that some languages, especially highly dynamic languages, require. Runtime linking, in particular, is a very useful construction. Loosely typed languages are very useful for a large number of applications. I've already mentioned the need for self-modifying applications.
Anyway, the architectural goals of BRiX are excellent. It seems that Brand has gotten all of the right buzzwords from a variety of other experimental OSes.