NebulousLabs/Sia — pull request #156 by lukechampine (2014-06-24 03:34:33+00:00)
Title: Bytecode translation

Added simple bytecode "translators." These aren't really compilers/decompilers; all they do is substitute opcodes for their corresponding bytes, and vis-versa. (Plus some convenient conversions from short values to 2 bytes, etc.)

This should make it a bit easier to read and write scripts, though I think I've become fairly proficient at writing in bytecode directly.

Future plans:
- build translators into the client
- add support for "annotations" (comments to the right of the script explaining each line, similar to what I've already been doing in scripts.go)
- better addressing: one problem with combining shorts into a single value is that it makes it tougher to know what byte offsets to use in instructions like `move` and `goto`. I'm not sure what the best way to approach this is. At any rate, it will become a non-issue when a real compiler is written.

The interpreter was also cleaned up a bit; its use of reflection was removed entirely by standardizing the opcode function signature. No more `reflect.ValueOf()` or `errInter.(error).Error()`! Opcode definitions suffered a bit though; their arguments are less readable.