Parse.c DEF_RULE macro - How does it works?

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
festfire
Posts: 1
Joined: Wed Nov 05, 2014 1:41 pm

Parse.c DEF_RULE macro - How does it works?

Post by festfire » Wed Nov 05, 2014 2:11 pm

Hello. I am currently working on porting micropython to IAR Workbench environment.
Naturally I encountered numerous errors, though I can't resolve all of them without help. For now I have a trouble understanding how parse.c and grammar.h works - DEF_RULE macro just blows my newbie mind.
The error is "too many initializer values" in https://github.com/micropython/micropyt ... mmar.h#L40 and so on.
CC's preprocessor gives me this:

Code: Select all

static const rule_t rule_single_input = { RULE_single_input, or(3), { tok(NEWLINE), rule(simple_stmt), rule(compound_stmt) } };
IAR doesn't compile that :roll:

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Parse.c DEF_RULE macro - How does it works?

Post by dhylands » Wed Nov 05, 2014 4:23 pm

festfire wrote:Hello. I am currently working on porting micropython to IAR Workbench environment.
Naturally I encountered numerous errors, though I can't resolve all of them without help. For now I have a trouble understanding how parse.c and grammar.h works - DEF_RULE macro just blows my newbie mind.
The error is "too many initializer values" in https://github.com/micropython/micropyt ... mmar.h#L40 and so on.
CC's preprocessor gives me this:

Code: Select all

static const rule_t rule_single_input = { RULE_single_input, or(3), { tok(NEWLINE), rule(simple_stmt), rule(compound_stmt) } };
IAR doesn't compile that :roll:
That looks incomplete. The or, tok, and rule macros don't seem to be expanded.

I ran:

Code: Select all

make build-PYBV10/py/parse.pp
and I get the following line for rule_single_input from the build-PYBV10/py/parse.pp file:

Code: Select all

static const rule_t rule_single_input = { RULE_single_input, ((0x10) | 3), { ((0x1000) | MP_TOKEN_NEWLINE), ((0x2000) | RULE_simple_stmt), ((0x2000) | RULE_compound_stmt) } };

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: Parse.c DEF_RULE macro - How does it works?

Post by pfalcon » Wed Nov 05, 2014 4:40 pm

dhylands wrote: I ran:

Code: Select all

make build-PYBV10/py/parse.pp
I missed such rule being present, but shouldn't it be build-PYBV10/py/parse.i ?
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Parse.c DEF_RULE macro - How does it works?

Post by dhylands » Wed Nov 05, 2014 5:59 pm

pfalcon wrote:
dhylands wrote: I ran:

Code: Select all

make build-PYBV10/py/parse.pp
I missed such rule being present, but shouldn't it be build-PYBV10/py/parse.i ?
It seems many build systems don't bother with it. I find it just useful enough to put it in. The rule is here:
https://github.com/micropython/micropyt ... mk#L48-L50

As to .i versus .pp, I think its really just personal preference. Since I was the one creating the initial mkrules.mk file, my personal preference was to use .pp (short for preprocess), because .i doesn't have any meaning (some intermediate).

make doesn't have any builtin rules for either one.

Post Reply