1. CoreWars compiler & parser

Hi everybody,

I've been outta the loop for awhile, so if this is a little late, my
apologies ;)

Rod, I thought your Core Wars program was a great start. Much farther
than
I got on mine ;) The reason I never finished mine was I couldn't write
warriors
very well, so I couldn't test it ;)  For anyone that's interested in
CoreWars,
http://www.koth.org/ is *THE* place to go.

Included at the end of the message is a UUencoded (I know, Juno doesn't
encode em automatically) zipfile that has my *very* beta parser and
compiler
for Rod's version of CoreScript. If anyone likes it (or doesn't),
feedback via
private mail is appreciated - budmeister1 at juno.com.

The parser can take source code and convert it either to
sequences of atoms (like Robert Pilkington's parser) or real atoms for
use by Rod's CoreWars program. It has support for comments (using ;),
all 3 addressing modes, and currently used instructions (more can be
easily added).

Rod, all you have to do to hook it up into your program is put code in to
actually read the files, then run them through the converter like this:

sequence code
code = read(file)
code = corescript_2_atom(code, 1)
-- the 1 tells it to convert to real atoms, not sequences of atoms
-- using 0 results in: {1,0,2,0,9,4,0,2,4,6,3}
-- using 1 results in: {10209402463} ...for each instruction

If I understand your code correctly, then this should work.

Otherwise...

The included CoreWars Compiler (CWC) can take a CoreScript program file
that doesn't have any get()able data, and convert it to raw data useable
by get(). Example:

Original program        Compiled program
-----------------       ------------------
; Hi! I'm a comment     {
PCT @5                  90200000005,
ADD #1, 4               20100010004,
JNZ 3, -2               61100039998,
MOV #-5, 2              10199950002,
JMP -4                  40100009996,
DAT #-5                 00000009995
                        }

It uses the same parser, so comments are supported, as well as all modes
& codes,
negative numbers, and instructions that have 0, 1, and 2 operands.
Comments are stripped out of the compiled program; if someone wants
I can move them down to the end of the file?

Btw, Rod, a friend of mine (Martin, you there?) used an idea a while back
about using routine_id(). He used constants for the instructions, then
assigned
the routine_id() of the routines to execute them. So to execute one,
there's no
endless if..then..else structures:

----------
procedure mov( atom arg1, atom arg2 )
...
end procedure

constant OPCODE = 1, ARG1 = 2, ARG2 = 3
constant MOV = routine_id("mov")

for i = 1 to blah blah blah
  call_proc(code[i][OPCODE], {code[i][ARG1], code[i][ARG2]})
end for
----------

I found it to be a clean way of executing instructions. What do you
think?


----->Buddy
budmeister1 at juno.com

------------------------------------ file follows ---------
_=_
_=_ Part 001 of 001 of file cwc.zip
_=_

new topic     » topic index » view message » categorize

2. CoreWars compiler & parser

Hi everybody,

I've been outta the loop for awhile, so if this is a little late, my
apologies ;)

Rod, I thought your Core Wars program was a great start. Much farther
than
I got on mine ;) The reason I never finished mine was I couldn't write
warriors
very well, so I couldn't test it ;)  For anyone that's interested in
CoreWars,
http://www.koth.org/ is *THE* place to go.

Included at the end of the message is a UUencoded (I know, Juno doesn't
encode em automatically) zipfile that has my *very* beta parser and
compiler
for Rod's version of CoreScript. If anyone likes it (or doesn't),
feedback via
private mail is appreciated - budmeister1 at juno.com.

The parser can take source code and convert it either to
sequences of atoms (like Robert Pilkington's parser) or real atoms for
use by Rod's CoreWars program. It has support for comments (using ;),
all 3 addressing modes, and currently used instructions (more can be
easily added).

Rod, all you have to do to hook it up into your program is put code in to
actually read the files, then run them through the converter like this:

sequence code
code = read(file)
code = corescript_2_atom(code, 1)
-- the 1 tells it to convert to real atoms, not sequences of atoms
-- using 0 results in: {1,0,2,0,9,4,0,2,4,6,3}
-- using 1 results in: {10209402463} ...for each instruction

If I understand your code correctly, then this should work.

Otherwise...

The included CoreWars Compiler (CWC) can take a CoreScript program file
that doesn't have any get()able data, and convert it to raw data useable
by get(). Example:

Original program        Compiled program
-----------------       ------------------
; Hi! I'm a comment     {
PCT @5                  90200000005,
ADD #1, 4               20100010004,
JNZ 3, -2               61100039998,
MOV #-5, 2              10199950002,
JMP -4                  40100009996,
DAT #-5                 00000009995
                        }

It uses the same parser, so comments are supported, as well as all modes
& codes,
negative numbers, and instructions that have 0, 1, and 2 operands.
Comments are stripped out of the compiled program; if someone wants
I can move them down to the end of the file?

Btw, Rod, a friend of mine (Martin, you there?) used an idea a while back
about using routine_id(). He used constants for the instructions, then
assigned
the routine_id() of the routines to execute them. So to execute one,
there's no
endless if..then..else structures:

----------
procedure mov( atom arg1, atom arg2 )
...
end procedure

constant OPCODE = 1, ARG1 = 2, ARG2 = 3
constant MOV = routine_id("mov")

for i = 1 to blah blah blah
  call_proc(code[i][OPCODE], {code[i][ARG1], code[i][ARG2]})
end for
----------

I found it to be a clean way of executing instructions. What do you
think?


----->Buddy
budmeister1 at juno.com

------------------------------------ file follows ---------

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu