NestedVM can take any program that GCC can compile and run it in a Java VM. It does this by compiling the program to a MIPS executable and then translating the MIPS machine code to Java bytecode. Now, there isn't any high-level type information in a MIPS binary, so there isn't any in the bytecode. Instead each instruction is translated to something that bangs on some large
int
arrays that represent virtual memory. (Thesbrk
system call is implemented usingnew int[]
.)The paper has sentences like, “The NestedVM runtime fills the role typically assumed by an OS kernel.” :)
I think the point of this, aside from being cool, is to make C++ code run anywhere Java does. I don't know how many platforms have JVMs but not gcc back-ends, though. (GCC actually has a back end for Java, but it can't handle C++.)
So if you know C, you know that
&&
has short-circuit behavior: if the left-hand side is false, the right-hand side doesn't get evaluated. This week I learned that if the right-hand side of&&
is simple enough and has no side effects, as inx > 0 && x < N
, a good compiler emits code that evaluates it anyway, essentially treating the&&
as&
. A conditional branch is slower than a few redundant instructions.Objective C exceptions on Mac are implemented using
setjmp
/longjmp
. They don't cooperate with C++; if you throw an Objective C exception across a frame containing C++ objects, the destructors don't get called. This triggered some bugs in Mozilla, which apparently has Cocoa GUI code or something. (Sorry, I don't pay much atttention to that stuff.:)
)If you compile with
gcc -g3
, thengdb
canprint
expressions that use macros! I knew Jim Blandy had implemented this but I never actually went and dug up the magic to make it work. This will make my life a lot easier, at least for a year or two.The
gcc
compiler itself uses a garbage collector. I'm told the GC is autogenerated from the source; so thegcc
source distribution actually includes a bunch of autogenerated code.gcc -S
prints Intel assembly code with the operands reversed. I don't remember if I ever knew this or not. What a pain.And some more about GCC internals, from here.
25 January 2008
This week I learned...
18 January 2008
This week I learned...
The Phaistos Disc is a mysterious clay disc, about 3400-3850 years old, discovered in the basement of a Minoan palace. It is imprinted with hieroglyphic symbols. It is the earliest known instance of movable-type printing, which would not be seen again until woodblock printing appeared in China some 1600+ years later.
Poseidon was believed to have created the horse. (I didn't even know that Pandora was a Greek legend. In my brain she was curiously detached from any specific culture.)
For some reason, Wikipedia's pages on Greek mythology are very often vandalized.
And I learned more about SpiderMonkey split objects than any human being should know. But I still don't understand them very well, as that page (which I wrote) indicates.
I've been learning (and documenting) a lot about SpiderMonkey and its API, which may be why the pickings are so slim otherwise.
07 January 2008
This week I learned...
Before desktop computers were widely used in China, telegraph operators there had to memorize every Chinese character's GB 2312 character code.
Moleskin is made from cotton, not moles. (In other news, guacamole is made from avacados.)
Garbage collection in Erlang is per-process. This seems weird—are messages copied from process to process?—but as that article explains, there are advantages, too.
The Haskell standard library contains over 100 operators— that is, functions whose names consist of ASCII symbols, like
.|
and|.
and@?=
and@=?
. Someone must stop these madmen.I learned a few very basic odds and ends of category theory.
The book I'm reading (by Benjamin Pierce) offers “injective functions are monic in Set; surjective functions are epic” as a mnemonic, you know, to help you remember monic and epic. This has to be the worst mnemonic of all time. I just don't see anything helpful about it. Sur- means “under”. Epi- mean “on top of”. I can never remember the difference between injective and surjective to begin with.
04 January 2008
This week I learned...
There are lots of ways to tile a regular dodecagon with sides of length s using only rhombi with sides of length s. My favorite so far:
I speculate all such tilings use exactly this many rhombi of each shape—six skinny diamonds, six fat ones, and three squares. It would be really cool if I were wrong. Calculate the area of each shape to see why I think this.
(Pictured: Melissa & Doug pattern blocks. Great toy.)
Basic stuff about the Erlang programming language. If you set aside the concurrency features for a second, Erlang looks like ML without static typing or refs. In a word, yuck.
Haskell has concurrency libraries that I should look at (while I'm learning about language-level approaches to concurrent programming).
Incidentally, if you're a Haskell programmer, see if you can spot the unintentional self-parody in that blog post. Hint: it's in the sentence “So let's do something useful with this, how about a little program that computes primes and fibonacci numbers?”
This week I started looking for elementary school curriculum materials. My son is four years old. We will probably homeschool him, and I want a head start on this one. Not a lot of luck searching so far. There are a lot of individual lesson plans; for example, PBS has some science lessons. On the other end of the spectrum, I found the What your nth-grader needs to know books and ordered one. We'll see. I really want a variety of textbooks and workbooks.