Browse Source

Record of added instructions in new.masm and parser/templates for

making builtins.c
dynamic
Raphael Roberts 5 years ago
parent
commit
fc4b2e0904
  1. 1
      .gitignore
  2. 94
      new.masm
  3. 32
      parser.py
  4. 3
      skeleton.j2

1
.gitignore

@ -5,3 +5,4 @@
__pycache__
compile_flags.txt
.dir-locals.el
*.egg-info

94
new.masm

@ -1,73 +1,27 @@
# template
#+begin_src masm
control shootp obj unit shoot 0 0
control configure obj configure 0 0 0
control color obj r g b 0
#+end_src
# manual
#+begin_src masm
draw image x y image size rotation 0
control shootp obj unit shoot 0 0
control configure obj configure 0 0 0
control color obj r g b 0
ubind type
#+end_src
# template
# toggles/set
#+begin_src masm
ucontrol boost enable 0 0 0 0
ucontrol flag value 0 0 0 0
#+end_src
# direct commands
#+begin_src masm
ucontrol idle 0 0 0 0 0
ucontrol stop 0 0 0 0 0
ucontrol pathfind 0 0 0 0 0
ucontrol payDrop 0 0 0 0 0
#+end_src
# direct with bool
#+begin_src masm
ucontrol payTake takeUnits 0 0 0 0
#+end_src
# xy-direct
#+begin_src masm
ucontrol move x y 0 0 0
ucontrol mine x y 0 0 0
#+end_src
# xy-param-set
#+begin_src masm
ucontrol approach x y r 0 0
control target x y shoot 0 0
#+end_src
# xy-param-get
#+begin_src masm
ucontrol within x y raduis result 0
ucontrol getBlock x y type building 0
#+end_src
# other
#+begin_src masm
ucontrol targetp unit shoot 0 0 0
ucontrol itemDrop to amount 0 0 0
ucontrol itemTake from item amount 0 0
ucontrol build x y block rotation config
#+end_src
# subclass from radar, no 'from' param
#+begin_src masm
uradar boss boss player armor 0 order result
#+end_src
# manual/subclass
#+begin_src masm
ulocate ore core enemy @copper outx outy found building
ucontrol idle x y 0 0 0
ucontrol stop 0 0 0 0 0
ucontrol approach x y radius 0 0
ucontrol boost enable y radius 0 0
ucontrol pathfind enable y radius 0 0
ucontrol target x y shoot 0 0
ucontrol targetp unit shoot shoot 0 0
ucontrol itemDrop obj amount shoot 0 0
ucontrol itemTake obj item amount 0 0
ucontrol payDrop obj item amount 0 0
ucontrol payTake takeUnits item amount 0 0
ucontrol mine x y amount 0 0
ucontrol flag value y amount 0 0
ucontrol build x y block rotation configure
ucontrol getBlock x y type building configure
ucontrol within x y radius result configure
uradar any any any distance 0 order result
ulocate building core enemy @copper outx outy found building
ulocate spawn core enemy @copper outx outy found building
ulocate damaged core enemy @copper outx outy found building
#+end_src
ulocate ore core enemy ore outx outy found building
ulocate spawn core enemy ore outx outy found building
ulocate damaged core enemy ore outx outy found building

32
parser.py

@ -0,0 +1,32 @@
import re
COMMAND_RE = re.compile(r'(?P<command>\w+) (?P<subcommand>\w+) ?(?P<params>.*)')
PARAM_RE = re.compile(r'[\w@]+')
def parse_params(param_text):
important_params = []
params = []
for match in PARAM_RE.finditer(param_text):
important = True
s = match.group(0)
params.append(s)
if s == '0' or "@" in s:
important = False
important_params.append(important)
return params, important_params
def parse_command(command_text):
match = COMMAND_RE.match(command_text)
info = match.groupdict()
if info['params'] != '':
parsed_params, important = parse_params(info['params'])
info['params'] = parsed_params
info['important'] = important
else:
info['params'] = []
info['important'] = []
return info
if __name__ == "__main__":
with open('./new.masm') as command_file:
command_text = command_file.read()
l = list(map(parse_command, filter(bool, command_text.split('\n'))))

3
skeleton.j2

@ -0,0 +1,3 @@
{{ subcommand }}({% for param in params %}{% if important[loop.index0] %}void* {{ param }}{% if not loop.last %}, {% endif %}{% endif %}{% endfor %}){% raw %}{{% endraw %}
asm("{{ command }} {{ subcommand }} {% for param in params %}{% if important[loop.index0] %}{% raw %}{{% endraw %}{{ param }}{% raw %}}{% endraw %}{% else %}{{ param }}{% endif %}{% if not loop.last %} {% endif %}{% endfor %}");
{% raw %}}{% endraw %}
Loading…
Cancel
Save