Author Topic: MoBo Precompiler for 0.89x  (Read 2224 times)

0 Members and 1 Guest are viewing this topic.

Manitas

  • Grandmaster Knight
  • *
    • View Profile
  • Faction: Bandit
MoBo Precompiler for 0.89x
« on: December 05, 2006, 12:12:49 AM »

as far as I have tested, it works with 0.891, please let me know if there are any problems

V 0.04: Bugfix - fixed a bug with quoted identifiers in arithmetic expressions

V 0.03: Bugfix - fixed a bug in config file causing module_mission_templates not being processed



I find the official module scripting syntax somewhat puzzling in the long run, and not very  readable.
The tool introduces alternative syntax to use in your scripts, while maintaining full backward compatibility with traditional system.

Features:
- Compatible with all module system versions so far, expected to be compatible with all upcoming .8xx versions, probably will be compatible with upcoming major releases too
- Brand new programming-like syntax, symbolic arithmetic operations, no redundant parentheses and commas
- Customizable aliases for the most frequently used operations.
- Can be applied to mods being in progress already.

Installation:
1. Unzip contents of the archive into the module system directory, preserving directory structure (all 5 files must be present in the 'mobo' folder)
2. Run install_mobo.bat. This does the following:
- create backup[timestamp].zip archive in your official module directory containing all the module*.py files
- import all the module* files into the mobo directory, from now on you will edit these files instead those from official module.
3. After the install completes successfully, it's advised to delete install_mobo.bat and init_mobo.py.


Usage:

Just place your code between #mobo# tags like this:

Code: [Select]
("script_name",
[#mobo#
  :var = 12
  {agents    reg(5) begin end
         
      |!agent_is_alive    reg(5)
      agent_is_ally
      agent_get_position reg(10) :xxx
      $v2 = 5
      {
          $v1 == 3
          reg(2) += $var1
  reg3 = 2/2
      ?
          $varabool = reg(5) % 2
      }
  }
#mobo#
]),
The above translates to:
Code: [Select]
("script_name",
[
      (assign,':var',12),
      (try_for_agents,reg(5),begin,end),
        (this_or_next|neg|agent_is_alive,reg(5)),
        (agent_is_ally),
        (agent_get_position,reg(10),':xxx'),
        (assign,'$v2',5),
        (try_begin),
          (eq,'$v1',3),
          (val_add,reg(2),'$var1'),
          (store_div,reg3,2,2),
        (else_try),
          (assign,':mobo_tmp',reg(5)),
          (val_mod,':mobo_tmp',2),
          (assign,'$varabool',':mobo_tmp'),
        (try_end),
      (try_end),
]),
Note the last arithmetic operation. There's no corresponding operation in modsys, so it translates to three instead. You can customize the :mobo_temp temporary variable name in the config file.

To build a module: just run the mobo.bat. If precompile phase finishes without errors build_module.bat from official module system will be invoked automaticly.

Additional remarks:
- no need to enclose variables in quotes (identifiers should still be enclosed in quotes though)
- operation modifiers: "!" stands for neg|,   "|" - this_or_next|
- a += b works like a = a + b, other operators work analogicly: -=, *=, /=, %=




Ok, this is not gonna be very helpfull if you are going to write a three-liner, but if you try to deal with something more complex with lots of math, this might come in handy.

Please let me know if it will be of any use to anyone.

Manitas

  • Grandmaster Knight
  • *
    • View Profile
  • Faction: Bandit
Re: MoBo Script Project (0.8xx ready)
« Reply #1 on: December 08, 2006, 11:38:14 AM »
So, is anybody using this, anny comments?
I 'm planning to integrate it into the modsys directly, but if it's not needed I won't bother.

Scion

  • Master Knight
  • *
  • Just another tosser screaming at the tide
    • View Profile
  • Faction: Neutral
Re: MoBo Script Project (0.8xx ready)
« Reply #2 on: December 08, 2006, 11:41:43 AM »
I think this is the way to go to make stuff easier, and I will use it if I can use it everywhere (for all M&B operations), if I don't have to rewrite old code, and if it is stable. Except from that, I really think this is the way to go.

Edit: tested it now, looking good. If integrated, I would definately use this. A quick altering of build_module.bat would do the trick I guess.
« Last Edit: December 08, 2006, 01:33:03 PM by Scion »

Manitas

  • Grandmaster Knight
  • *
    • View Profile
  • Faction: Bandit
Re: MoBo Script Project (0.8xx ready)
« Reply #3 on: December 09, 2006, 01:21:21 PM »
Yes, the idea is to let the two systems coexist, so no rewriting old code. About the stability part, we'll see, it's a question of testing.

Manitas

  • Grandmaster Knight
  • *
    • View Profile
  • Faction: Bandit
Re: MoBo Script Precompiler (updated 10 Dec)
« Reply #4 on: December 10, 2006, 07:55:14 PM »
The first update.

Now instead compiling script by script and copy&pasting , you just type directly in module system files and let it go.
No original module system files were harmed or altered in the process.
more details in the title post.

Please, let me know if there are any bugs

Thorgrim

  • Cartographic Conquistador
  • Moderator
  • *
    • View Profile
Re: MoBo Script Precompiler (updated 10 Dec)
« Reply #5 on: December 11, 2006, 05:22:27 AM »
Great!

Nice work.  Now that you can write it right into the python scripts themselves it should be much more useable. 
At some stage I'd like to add support for it to MBDev if thats ok?

Manitas

  • Grandmaster Knight
  • *
    • View Profile
  • Faction: Bandit
Re: MoBo Script Precompiler (updated 10 Dec)
« Reply #6 on: December 13, 2006, 12:03:20 AM »
Sure it's ok,
It would surely benefit from syntax higlighting and auto completion.

Manitas

  • Grandmaster Knight
  • *
    • View Profile
  • Faction: Bandit
Re: MoBo Script Precompiler (updated 17 Dec)
« Reply #7 on: December 17, 2006, 02:22:22 PM »
A little bugfix:
The file module_mission_templates was not included in the config file, preventing it from being processed.

Fixed now.

Fujiwara

  • Sergeant at Arms
  • *
    • View Profile
  • Faction: Neutral
Re: MoBo Script Precompiler (updated 21 Dec)
« Reply #8 on: January 29, 2007, 07:40:53 PM »
Good looking stuff, Manitas! If you are interested, I would like to integrate this into the Pythonic Module Editor.
M&B: Onin no Ran - THE Japan Mod

Pythonic Module Editor

Johnny is a hacker's son
But Johnny is not 133t
What Johnny thought was ADD_AND_SHIFT
Instead was REG_DELETE


Manitas

  • Grandmaster Knight
  • *
    • View Profile
  • Faction: Bandit
Re: MoBo Precompiler for 0.89x
« Reply #10 on: September 26, 2007, 08:57:10 PM »
I have just done a quick check, and it seems it works with the .891 module system already (a benefit of not using hardcodes ;) )
Dont know if anybody's using this (besides me), but just in case.