js2lua icon indicating copy to clipboard operation
js2lua copied to clipboard

compile time errors with ammo.js (bullet built with emscripten)

Open CapsAdmin opened this issue 10 years ago • 4 comments

using: latest luajit 2.1 from git translating: https://github.com/kripken/ammo.js/blob/master/builds/ammo.js

I realize running bullet like this this is silly and all but I was curious to see how it would perform. I also thought maybe you would be interested in fixing these errors (there's probably gonna be more) since you already have a gigantic test suite for js to make sure there are no errors there.

I'll try to fix the errors manually and report whats wrong:

I had to change LJ_MAX_LOCVAR from 200 to 2000 and LJ_MAX_SLOTS from 250 to 2000.

After doing this I got this error:

ammo.lua:4528: <goto __Continue200> jumps into the scope of local 'convertCode'

after manually fixing this error by moving the local convert code (which is just 5 lines below) above the function i get this syntax error:

ammo.lua:4840: '<name>' expected near '{'

this section of the code is supposed to be commented but fails to do so because the generated comment "-- [[" needs to be be "--[[" (without the space in-between) To fix this I replaced "-- [[" with "--[[" everywhere in the code.

I now get another syntax error that looks like this foo(a, b, c, --[[hello world]], d, e) so when I remove the comment it becomes (a, b, c,, d, e) where the error is the 2 commas

To fix this I replaced ",--[[ EmitCall" with "--[[ EmitCall"

Now there is this another syntax error on line 10317

currArg =--[[WTF Call { type: 'CallExpression', callee: { type: 'ConditionalExpression', test: { type: 'Identifier', name: 'signed' }, consequent: { type: 'Identifier', name: 'reSign' }, alternate: { type: 'Identifier', name: 'unSign' } }, arguments: [ { type: 'BinaryExpression', operator: '&', left: [Object], right: [Object] }, { type: 'BinaryExpression', operator: '*', left: [Object], right: [Object] } ] } --]]bit32.band (currArg ,limit ) ,(argSize *8 ) )

which when simplified becomes currArg = foo(), (bar) ) where the syntax error is an extra ")"

Now I get "undefined label '__Continue539' " because the code is structured like this

`if foo then
goto __Continue539 end

::__Switch541_2:: do ::__Continue539:: end`

there's a lot of these and I don't really know how to fix them. I just commented the goto line out.

After this there's a bunch of "break" statements so you get the error "no loop to break". I also commented these out

Finally there's this

while __ToBoolean(__CmpGreater (Module ["preInit" ] .length ,0 ) ) do --[[WTF Call { type: 'CallExpression', callee: { type: 'CallExpression', callee: { type: 'MemberExpression', computed: false, object: [Object], property: [Object] }, arguments: [] }, arguments: [] } --]]) end

Where the syntax error is the extra ")" at the end of the comment. This seems to be all the compile time errors.

Now I get your custom "unhandled exception" error. I commented out os.exit() because of issues it would cause in the environment.

`> open ammo Unhandled Exception:table::"150" "stack traceback: lua/ammo.lua:57: in function <lua/ammo.lua:52> [C]: in function 'error' lua/ammo.lua:388: in function '__RefCheck' lua/ammo.lua:3439: in function '__CallMember' lua/ammo.lua:3196: in function <lua/ammo.lua:3195> [C]: in function 'xpcall' lua/ammo.lua:3195: in main chunk [C]: in function 'xpcall' .../goluwa/.base/lua/libraries/filesystem/lua_utilities.lua:165: in function 'include' ...gle Drive/goluwa/.base/lua/autorun//console_commands.lua:363: in function <...gle Drive/goluwa/.base/lua/autorun//console_commands.lua:353> [C]: in function 'xpcall' ... lua/libraries/event.lua:417: in function 'UpdateTimers' lua/main_loop.lua:30: in function <lua/main_loop.lua:29> [C]: in function 'pcall' lua/main_loop.lua:54: in function 'update' lua/main_loop.lua:94: in function 'main' lua/main_loop.lua:101: in main chunk [C]: in function 'xpcall' .../goluwa/.base/lua/libraries/filesystem/lua_utilities.lua:165: in function 'include' ../../lua/init.lua:313: in main chunk [C]: at 0x7ff6a2c51ed0"

stack traceback: lua/ammo.lua:69: in function '__LastXpCall' lua/ammo.lua:181202: in function '__TryHandler148' lua/ammo.lua:181208: in main chunk [C]: in function 'xpcall' .../goluwa/.base/lua/libraries/filesystem/lua_utilities.lua:165: in function 'include' ...gle Drive/goluwa/.base/lua/autorun//console_commands.lua:363: in function <...gle Drive/goluwa/.base/lua/autorun//console_commands.lua:353> [C]: in function 'xpcall' lua/libraries/console.lua:111: in function 'call' lua/libraries/console.lua:126: in function 'RunString' lua/libraries/extensions/console_curses.lua:675: in function 'HandleKey' lua/libraries/extensions/console_curses.lua:136: in function <lua/libraries/extensions/console_curses.lua:101> [C]: in function 'Call' lua/libraries/event.lua:417: in function 'UpdateTimers' lua/main_loop.lua:30: in function <lua/main_loop.lua:29> [C]: in function 'pcall' lua/main_loop.lua:54: in function 'update' lua/main_loop.lua:94: in function 'main' lua/main_loop.lua:101: in main chunk [C]: in function 'xpcall' .../goluwa/.base/lua/libraries/filesystem/lua_utilities.lua:165: in function 'include' ../../lua/init.lua:313: in main chunk [C]: at 0x7ff6a2c51ed0 `

CapsAdmin avatar Feb 06 '15 01:02 CapsAdmin

Everywhere the --[[ gets emitted it means the codegen for that JS construct is not ready yet, sorry :)

wizzard0 avatar Feb 06 '15 02:02 wizzard0

meanwhile, running bullet is no more ridiculous than this project in itself, but there are still things needing to be fixed. I need to do a proper CFG-based codegen to translate code like that.

wizzard0 avatar Feb 06 '15 02:02 wizzard0

Ah that makes sense. I hope you find the time to do it. :)

here's the manually fixed lua file if you want to diff it https://dl.dropboxusercontent.com/u/244444/ammo.lua

CapsAdmin avatar Feb 06 '15 03:02 CapsAdmin

@CapsAdmin Rotten link 🤐

InDieTasten avatar Feb 26 '17 02:02 InDieTasten