Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Null PMC access while parsing javascript

10 views
Skip to first unread message

Mehmet Yavuz Selim Soyturk

unread,
Oct 9, 2006, 10:14:54 PM10/9/06
to perl6-i...@perl.org
js.pg in languages/ecmascript/src compiles just fine with pgc. But it
gives a "Null PMC access" error while using the compiled pir file. Is
it a pge bug?

$ cd languages/ecmascript/src

$ cat main.pir
.include 'errors.pasm'

.sub _main :main
.param pmc args

.local string source_code, rule_to_match
source_code = args[1]
rule_to_match = args[2]

errorson .PARROT_ERRORS_PARAM_COUNT_FLAG

load_bytecode 'PGE.pbc'
load_bytecode 'dumper.pbc'
load_bytecode 'PGE/Dumper.pbc'
load_bytecode 'PGE/Text.pbc'
load_bytecode 'Getopt/Obj.pbc'
load_bytecode 'js.pir'

.local pmc start_rule
start_rule = get_global ['JS'], rule_to_match
if null start_rule goto e_global_not_found

.local pmc match
match = start_rule(source_code)

_dumper(match)
branch end

e_global_not_found:
say "global not found"
end:
.end

$ pgc js.pg >js.pir

$ parrot main.pir 'x' 'identifier'
Null PMC access in invoke()
current instr.: 'parrot;JS;identifier' pc 9096 (js.pir:3766)
called from Sub '_main' pc 38 (main.pir:24)

$ tail -n +3766 js.pir | line
captob = $P0(captob)

$ parrot main.pir '[1]' 'array_literal'
Null PMC access in invoke()
current instr.: 'parrot;JS;array_literal' pc 11560 (js.pir:4711)
called from Sub '_main' pc 38 (main.pir:24)

$ tail -n +4711 js.pir | line
captob = $P0(captob)

$ parrot main.pir '"test"' 'string_literal'
Null PMC access in invoke()
current instr.: 'parrot;JS;string_literal' pc 7460 (js.pir:3094)
called from Sub '_main' pc 38 (main.pir:24)

$ tail -n +3094 js.pir | line
captob = $P0(captob, "\"")

$ parrot main.pir '/* test */' 'multilinecomment'
Null PMC access in invoke()
current instr.: 'parrot;JS;multilinecomment' pc 816 (js.pir:349)
called from Sub '_main' pc 38 (main.pir:24)

$ tail -n +349 js.pir | line
captob = $P0(captob, "/* */")


--
Mehmet

Kay-Uwe Hull

unread,
Oct 10, 2006, 6:52:58 AM10/10/06
to perl6-i...@perl.org, mehmet.ya...@gmail.com
Hi Mehmet,

you might have run into a Garbage-Collector bug. Try

parrot --no-gc main.pir 'x' 'identifier'

I had similar problems using PGE::P6Regex. '--no-gc' helped.

Regards,

Kiwi

Mehmet Yavuz Selim Soyturk

unread,
Oct 10, 2006, 8:07:39 AM10/10/06
to perl6-i...@perl.org
The same problem.

I think that I now know the problem: the grammar is not complete. I
was thinking that pgc would refuse compiling in that case, but it
doesn't. It's probably to allow you define your own rules at runtime, but
some warnings would be handy.

--
Mehmet

Patrick R. Michaud

unread,
Oct 11, 2006, 5:34:20 PM10/11/06
to Mehmet Yavuz Selim Soyturk, perl6-i...@perl.org
On Wed, Oct 11, 2006 at 10:56:39PM +0200, Mehmet Yavuz Selim Soyturk wrote:
> I have rewritten the grammar. There are some problems though.
>
> - I don't know how to express thinks like: an identifier is
> <[a..zA..Z_$]>*, but not a <keyword>. Something like: rule identifier
> {<!keyword><[a..zA..Z_$]>*} seems not to allow identifiers that have
> keywords as prefix.

For now, try adding a \b at the ends of the <keyword> rule:

token keyword { \b [ if | else | for | while | ... ] \b }

Then <keyword> will match only the exact keyword.

However, the "\b" metacharacter is disappearing soon, to be replaced
by <?wb> and <!wb>. In its place will be "<<" and ">>", making
the above:

token keyword { << [ if | else | for | while | ... ] >> }

I'll get << and >> added into PGE today/tomorrow.

> - I couldn't make comments work.
> - I don't know how to handle unicode,
> - How to accomplish semicolon insertion?

I'll have to look at the grammar a bit and see what I can come up
with here.

Pm

Patrick R. Michaud

unread,
Oct 12, 2006, 11:13:19 AM10/12/06
to Mehmet Yavuz Selim Soyturk, perl6-i...@perl.org
On Wed, Oct 11, 2006 at 04:34:17PM -0500, Patrick R. Michaud wrote:
> On Wed, Oct 11, 2006 at 10:56:39PM +0200, Mehmet Yavuz Selim Soyturk wrote:
> > I have rewritten the grammar. There are some problems though.
> >
> > - I don't know how to express thinks like: an identifier is
> > <[a..zA..Z_$]>*, but not a <keyword>. Something like: rule identifier
> > {<!keyword><[a..zA..Z_$]>*} seems not to allow identifiers that have
> > keywords as prefix.
> [...]

> However, the "\b" metacharacter is disappearing soon, to be replaced
> by <?wb> and <!wb>. In its place will be "<<" and ">>", making
> the above:
>
> token keyword { << [ if | else | for | while | ... ] >> }
>
> I'll get << and >> added into PGE today/tomorrow.

OOPS! I just looked at PGE, and apparently << and >>
(and their Unicode equivalents) have been been implemented
since late July. So, go ahead and use the above definition
for keyword. :-)

> > - I couldn't make comments work.
> > - I don't know how to handle unicode,
> > - How to accomplish semicolon insertion?
>
> I'll have to look at the grammar a bit and see what I can come up
> with here.

I'm still working on this one.

Pm

0 new messages