franko / luajit-lang-toolkit

A Lua bytecode compiler written in Lua itself for didactic purposes or for new language implementations
Other
655 stars 91 forks source link

Wrong runtime debug information #5

Closed q66 closed 9 years ago

q66 commented 10 years ago

I believe the place "if node.line then self.ctx:line(node.line) end" is done is wrong. It should be done before the rule is called so that the line information is up to date by the time things are emitted. Right now it displays bad line info.

Also, such statements should be placed before every rule call, not only in "emit". That's because if you do stuff like


print(

    "foo" + 5)

The error about arithmetic on string value should be on the line the string literal is placed, not on the line "print" is placed. (i.e. without any fix at all, the error will be on line 1; with partial fix, it'll be on line 3; but it should be on line 7)

The solution here is:

1) move the statement in "emit" before the rule call. 2) add the same line before every rule call elsewhere, i.e. into test_emit, expr_toreg, expr_tomultireg and lhs_expr_emit.

franko commented 10 years ago

Agree with you in principle but the whole line information stuff is quite broken and I'm planning to address all the issues all together. I just need to get the motivation :-)

Something that retained me from implementing straight away all the line number stuff was that I don't like the idea to "pollute" every AST node with line information and to have to pass everywhere the line number as an argument for every function call. Yet I didn't have any better solution for the moment so basically I kept what Richard did at the beginning for Nyanga and didn't modify anything.

Otherwise if you have some clear idea about how things should be done you may contribute some improvements. If you are using the lang toolkit for another project it could make sense to "invest" a little bit of your time in the language toolkit itself.

q66 commented 10 years ago

I'll let you know if I come up with a decent solution. I'm not using the lang-toolkit as-is (i.e. i have my own lexer, my own parser, my own AST, and generator is heavily modified, bytecode.lua generally remains the same), but yes, I can contribute pieces here and there when they're relevant to both projects. Right now I'm only reporting because i'm still familiarizing myself with the codebase.