|
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
|
01-10-2007 00:37
I'm looking at the most efficient way to implement constant folding in the open source LSL compiler. The memory allocator they're using is a bit ad-hoc, has anyone else looked at the code to see what the best approach is? The absolute minimum I want to get working is to implement constant folding for negative numbers, rather than parsing negative numbers as a single token. I guess the simplest hack would be to do something like: simple_assignable_no_list //... | '-' constant { $$ = new LLScriptConstantInteger(gLine, gColumn, -$2); gAllocationManager->addAllocation($$); }
|
|
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
|
01-10-2007 02:16
I haven't looked into those yet, i've been reading through the implementation of the LSO and writing notes for it. There are a bunch of OpCodes that LSL does not use. There are DUP opcodes for example. I am working on a compiler in C# to which I will be adding embedded assembly support to LSL like that of C. Checkout: http://www.libsecondlife.org/wiki/LSO
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river. - Cyril Connolly
Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence. - James Nachtwey
|
|
Lex Neva
wears dorky glasses
Join date: 27 Nov 2004
Posts: 1,361
|
01-10-2007 11:08
From: Argent Stonecutter I'm looking at the most efficient way to implement constant folding in the open source LSL compiler. <3
|
|
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
|
01-10-2007 11:51
OK, after sleeping on it (it really sucks trying to understand this code when you have the flu), I think what I'm going to do is restrict my changes to the lex and yacc as much as possible. The class structure in the tree files is just so insane... why they have everything defined as a zillion argument parameter on *:recurse instead of having different methods for each pass I can't fathom, and it's just too complex. The thing that might be a problem for this would be LSCP_PRETTY_PRINT... is this actually used for anything in the client? I'd hate to have a client that changed the text of the scripts when you edited it. It only seems to be passed in inside "#ifdef EMERGENCY_DEBUG_PRINTOUTS", so that's OK. So here's the approach I'm looking at: Change this: constant : INTEGER_CONSTANT { $$ = new LLScriptConstantInteger(gLine, gColumn, $1); gAllocationManager->addAllocation($$); } //...
To this: constant : integer_constant_expression { $$ = new LLScriptConstantInteger(gLine, gColumn, $1); gAllocationManager->addAllocation($$); } //...
And then integer_constant_expression : INTEGER_CONSTANT { $$ = $1; } : '-' integer_constant { $$ = -$1; } : integer_constant '-' integer_constant { $$ = $1 + $3; } : integer_constant '+' integer_constant { $$ = $1 + $3; } //...
|