It has been my intention for the last month or so to move Robotic - the way the language is stored, the way we edit it, and the syntax/grammar/functional properties of the language itself - in a certain direction. I've broken up plans into several rough phases that I'll outline here.
Phase 1: Bytecode decoupling, general restructuring Status - Internal testing - Make Robotic code stored as textual source inside .mzx files, instead of assembled bytecode. - Code is never transformed, it always looks like how you wrote it. - Compiled when the robot is ran, when the board is loaded. - Save files save bytecode still, as do "save MZMs" - neither can be loaded in the editor. - Necessitated new MZM3 format which is versioned and contains textual robots. - MZM3s saved at runtime and loaded at "static" time have robots dummied out to customblocks. - save_world, save_bc, and save_robot are removed for the above reasons. - New parser and Robotic compiler: - Variables and other names (labels, robots, boards, etc) use backticks instead of quotes (double for command level, single for expressions) - Parser recognizes valid/invalid expressions and will visually show you when one is invalid and won't allow it to compile. - Expressions don't have enclosing quotes, don't require quotes around simple names - Commands can be split over lines arbitrarily, including inbetween expressions. - Optional words (like the "to" in "set x to y") now only work where they make sense. - The matching is loose and will fit user-defined names where the command doesn't call for something else. This allows more flexibility using names that are used for other things in Robotic. - There's a distinction between names and strings. - Modified expression and name evaluation runtime: - &, |, and ^ instead of a, o, and x respectively, allowing the latter to be normal characters in names. - ** instead of ^ (for exponentiation) to accommodate the above. - Interpolated strings are now done with < > instead of & & (the latter can't be used for counters anymore, use expressions). - Supports multiple strings in concatenation, ie < $str1 " and " $str2 > - &+...& and &#...& converted to special form (+...) and (#...) respectively, can only be used in strings/names, not standalone expressions. - New color coding engine, which supports more syntax (expressions, distinction between counter names, labels, strings, etc) - Converter which converts current MZX robots to this format and stores as source. - Currently, although it breaks convention, for compatibility purposes string literals used with user-defined strings look like names. - load_robot won't work as it's supposed to with legacy files (will be fixed later too) Phase 2: Program/robot separation Status - planning - The notion of "robot" and "program" will be separate. There will be lists of programs, and each robot will choose which program it has. - The benefits of this are threefold: less space will be needed for saving MZX worlds (and eventually, SAV files) and in memory for duplicates, less time will be needed for compiling programs that have already been compiled, and most importantly, it will make it much easier to reuse a program across many robots. - Eventually this will make it possible to "import" and/or "inherit" robots to allow for code reuse. - The editor GUI will make it easy to create a new program along with a new robot, or choose an existing one. - Current MZX worlds will have programs checksummed and entered into lists such that duplicates are removed and unique names are generated when collisions arise from using the robot's name. Phase 3: Language cleanup, more syntax provisions Status - planning - Expressions will be parsed into compound elements with color coding per expression token instead of the whole token. This will make it easier to compile them more efficiently as well. - Code blocks will be recognized as another compound parse element, and will be useful later. - Builtin counters will be converted into builtin functions that look like this: function(arg1, arg2), ie: set "vch&x&,&y&" 1 -> set vlayer_char(x, y) 1 Note that this is unambiguous from a normal counter name with an expression, because that must be in backticks. - It will be possible to "set" a builtin-function, which is like passing the set value as the last argument. - There will be a compatibility break for any games that used strings to indirectly refer to builtin counters. This will probably be rare and will be fairly easy to fix. - Some builtin counters will be changed to new commands instead. - String conventions will be changed to builtin-functions as well. - See this in-progress list for details: http://exophase.devzero.co.uk/counter_convert.txt - Several "special" versions of current commands will be changed to new commands. - Like with counters, if these were determined at runtime there will be compatibility problems. Again, should be rare. - See this in-progress list for details: http://exophase.devzero.co.uk/command_convert.txt Phase 4: Macros Status - planning - Will allow for essentially "custom commands" which take parameters and expand to one or more commands/macros that use those parameters. - More on syntax to come - I have a good idea in mind but I don't want to go indepth yet. - Not quite determined where/how they will be stored - macros defined in programs will probably be local to those programs, and macros defined in some global context (global programs, or dedicated global macro lists) will be usable by all. - Because macro parameters will fit combinations of valid command parameters and because the macro blocks will be parsed like command blocks under special context, all invocations of macros will be guaranteed to generate correct code. - However, any editors of global macros will not allow you to change the parameters of a macro that existing programs use. This is to keep with MZX's model of never letting you exit an editor while any code may be invalid. - You will be allowed to overload macro names, just like commands are now. This will also be a good way to get around the above problem when necessary. Phase 5: New bytecode and VM Status - planning - Robotic bytecode will be stored in a more compact and efficient manner that makes it easier to quickly execute programs and takes out some of the bulk. - The bytecode format will be designed such that often used instructions are executed most quickly, allowing for specialized/non-portable implementations of faster VMs (even compilers to native code) without having to carry with it all the legacy compatibility that Robotic entails. - Commands in general will typically consist of "pushing" arguments onto an argument stack using whatever push command is appropriate for the argument type, then running a command that's an argument-less instruction. - This will allow for a variety of argument types and optimizations. - Expressions will be compiled, such that they also use the argument stack and arithmetic/logical commands to evaluate sub-expressions. - This will allow for optimization to be performed on expressions, not burdening the programmer with this. - Now "simple" names that don't contain expressions will have pointers linked directly to the whereever the entity is, allowing for much faster counter lookup, gotos, etc for most cases. - Interpolation (for both names and strings) will be broken down and compiled in the same sense expressions are. - The core sections of the VM will be largely rewritten with performance in mind. Phase 6: User-defined functions Status - planning - Syntactic definitions similar to macros, but will allow for code to be easily reused without expanding new versions of that code. Like subroutines now, but will allow parameters and returns. I'll cover this more indepth later.
This doesn't really cover everything that I want, but it's a good idea of what I'm most intent on adding.
I'll keep things updated here as it moves along. I hope that at each stage things will basically be good enough that if
I stopped right there it'd still be a worthwhile, usable result. So none of the stages should outright rely on future
stages, although currently I'd have to add a couple things to phase 1 to comply with this.
(one of the admins can feel free to tidy up the line breaks and formatting on this ;P)