Yazoo ---> Online Help Docs ---> Yazoo bytecode

Compiled expressions

This paragraph marks a turning point, where we step away from Yazoo scripting and venture into the more abstract world of compiled Yazoo bytecode. Down here, syntax is a bit less fluid and intuitive, the logical structure is simpler and we are palpably closer to Yazoo's internal motor. It may sound like just an intellectual adventure, but we have a very practical reason for taking it: we are seeking a fuller understanding of how our scripts work. Learning about bytecode is a means to this end, because bytecode is what the fundamental physics of Yazoo operates with.

In general, `bytecode' is a binary re-representation of a script -- a string of signed longs in Yazoo's case -- which encodes instructions to the machine more directly than a script does. Scripts are designed to be human-friendly, whereas Yazoo bytecode is Yazoo-friendly. As the two are somewhat at cross-purposes, Yazoo at some point has to translate (which is what the compile() function is for). The bytecode that Yazoo understands was nicknamed `Hobbish' in memory of his parents' answering machine (which was in turn named after his sister), and that nickname still sticks around in various odd places.

It must be emphasized that Yazoo bytecode is not machine code. There are some similarities: the bytecode directly encodes Yazoo instructions, just as machine code laboriously specifies processor instructions. However, a Yazoo instruction is not at all the same as a fundamental instruction for the chip. A major syntactic difference is that Yazoo's bytecode is a recursive language. Whereas machine code is a simple list of commands -- one instruction per line -- Yazoo bytecode is a list of sentences, most of which correspond to the sentences in the original script. Each sentence is composed of instructions called operators, and the operators themselves often take arguments which are other operators. Thus a given sentence can be composed of clauses and sub-clauses to a practically unlimited depth.

Because bytecode is a binary format, it makes for rather tedious reading in raw form. Back when Yazoo was still evolving, the author decided to write a `disassembler' to give a textual representation to the bytecode where runtime errors were being flagged. Error messages have improved drastically since those days, and disassembly is no longer the way to go for most day-to-day scripting errors. But the disassembly tool is still around, and in the rest of this chapter we will make heavy use of it. It resides in start.zoo, partly for that script's own private use, but the routine is made accessible to the command-line user as well. To `disassemble' a script, one makes the following call from the interactive command prompt:


    print( disassemble( my_code_string ) )
   

where both my_code and the return value of the disassembler are strings. The output will look something like:


    [print] ( def** ( sm -1 , scr { deq* ( sm -2 , cst "This is a sample script" ) } ) )
   


Prev: Functions, revisited   Next: Anatomy of a compiled sentence


Last update: July 28, 2013

Get Yazoo scripting language at SourceForge.net. Fast, secure and Free Open Source software downloads