Crazy stuffI had a crazy idea I just had to try to implement. I got it when working on my nanobots. It's a way to cheat codesize.jar and fit more advanced code into the bot than would otherwise be possible. Because only bytecode counts and strings in the class file are free I though that it must be possible to put the actual code into strings and then execute them using an interpreter. I have implemented an interpreter for a custom "bytecode". The interpreter is just over 700 bytes of bytecode so it fits in a microbot. I think java put a limit of 64Kb on strings so thats the limit of how advanced the bot can be. Well, the interpreted language puts a lot of constraints on what can be done. Here are some of the features: * Fixed size stack of doubles * Fixed size static heap of doubles * Basic stack operations: push, dup, drop, swap, pick, etc. * Aritmethic operations: subtraction, multiplication and less-than-zero * Heap operations: load and store. * Branching: conditional and unconditional jump, subroutine call and return. * Java interface: Ability to call getters and setters on the robot and on the event. The custom bytecode looks a bit like [funge]. It is hard to write, harder to read and probably impossible to debug, so don't expect any killer bot comming out of this. =) When I have cleaned up the code a bit I'll post it if someone is interested. Have anybody tried something like this before? |
| Interpreter | MicroBot | Executes code stored in strings |
Way cool that interpreter of yours. When will you release it? I'd like to try build a bot using it. Since I used to code in PostScript? some years ago I might have a head start with it. -- PEZ |