Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

FYI: A script may compile differently under Mac vs Windows

RJ Source
Green Sky Labs
Join date: 10 Jan 2007
Posts: 272
07-19-2007 11:05
FYI, I have a script that compiles fine on the Mac client, but gives a Syntax error on the windows client.

I've sent it in as a bug report. I've taken all the other stuff out as much as possible from this script while still maintaining the error condition. Posted below (the script itself now does pretty much nothing: its just to show the compilation error).

This is more an fyi than anything else. I had a larger script I was delivering to a client, who was unable to change the value of a global without getting errors. After quite a lot of debugging, it turned out it was because it would not compile when logged in with the windows SL client, but did compile with mac.

CODE

// This compiles on the mac client, but Syntax errors on the Windows client
//
// 20070716 RJ Source Initial Coding

string g_Config = "test";
string g_Comment = "test";
key g_QueryID;

string g_MenuCmd = "0";
string g_ButtonCmd = "0";
string g_GiveCmd = "0";
string g_AutoCmd = "0";
string g_IdleCmd = "0";
string g_LoopOpt = "0";
string g_SoundOpt = "0";
string g_AnimOpt = "0";
string g_SitCmd = "0";
string g_InvCmd = "0";
string g_MoveCmd = "0";
string g_HelpCmd = "0";
string g_UpCmd = "0";

list g_Tools = [];
string g_AutoAnim = "0";
string g_IdleAnim = "0";


string g_Sittext = "0";
integer g_Invisible = TRUE;
vector g_pos = <0.0,0,0.0>;
rotation g_rot = <0,0,0,1>;
vector g_newpos;

string g_Mute = "0";
string g_TopMenu = "0";
string g_Idle = "0";
list g_RepeatButtons = [g_Idle, g_Mute];
float g_Timer = 3.0;
float g_MoveInc = 0.0;
string g_HelpCard = "";

string AnimControl = "0";
string AnimStart = "0";
string AnimStop = "0";

float g_Volume = 0.0;

list g_Menus = [];
list g_MenuTexts = [];
list g_MenuStartptr = [];
list g_MenuEndptr = [];
integer g_Bptr1;
integer g_Bptr2;
integer g_Menuptr;
list g_MenuStack;

list g_Buttons = [];
integer g_ButtonCount = 0;

list g_Anims = [];
string g_Anim = "";

list g_Sounds = [];
list g_Sloops = [];
string g_Sound = "";

list g_Texts = [];

integer g_x;
key g_Agent = NULL_KEY;
integer g_Channel;
integer g_ListenID;
list g_TempMenu;
list g_TempRepeat;
string g_MenuText;

float g_Alpha1;

integer g_Worn = FALSE;
integer g_Sit = FALSE;

string g_PageCmd = "Page ";
integer g_Page = 1;
integer g_Marked = -1;
string g_Marker = "*";

string UnComment(string text1, string text2)
{
return "";
}

AddMenu(string menu, string text)
{
}

AddButton(string menu, string button, string text, string anim, string sound, integer loop)
{
}

// ParseCommand
// Parse the given command
//
ParseCommand(string command)
{
list tokens = llParseString2List(command, [","], []);

string cmd;
string opt1;
integer ptr;
string opt2;
string opt3;
string opt4;
string text;

cmd = llToUpper(llStringTrim(llList2String(tokens, 0), STRING_TRIM));
if (cmd == "") return;

opt1 = llStringTrim(llList2String(tokens, 1), STRING_TRIM);

if (cmd == g_GiveCmd) g_Tools = (g_Tools = []) + g_Tools + opt1;
else if (cmd == g_HelpCmd) g_HelpCard = opt1;
else if (cmd == g_SitCmd) g_Sittext = opt1;
else if (cmd == g_InvCmd) // Turn seat invisible
{
opt1 == llToUpper(opt1);
if (opt1 == "YES") g_Invisible = TRUE;
else g_Invisible = FALSE;
}
else if (cmd == g_AutoCmd) g_AutoAnim = opt1;
else if (cmd == g_IdleCmd) g_IdleAnim = opt1;
else if (cmd == g_MoveCmd) g_MoveInc = (float)opt1;
else if (cmd == g_MenuCmd) // Menu command
{
AddMenu(opt1, opt1);
opt2 = llToUpper(llList2String(tokens, 2)); // Sub command
opt3 = llList2String(tokens, 3);
opt4 = llList2String(tokens, 4);
if (opt2 == g_MenuCmd)
{
AddButton(opt1, opt3, opt4, "", "", 0);
AddMenu(opt3, opt4);
}
else if (opt2 == g_ButtonCmd)
{
AddButton(opt1, opt3, llList2String(tokens, 7), opt4, llList2String(tokens, 5), llList2Integer(tokens, 6));
}
}
else llSay(0, "Unknown Command: " + command);
}

//
default
{
state_entry()
{
llOwnerSay("Testing.");
}
}

Destiny Niles
Registered User
Join date: 23 Aug 2006
Posts: 949
07-19-2007 13:02
Which line did you receive the error on? What was the compile error? (incase I run across it)
RJ Source
Green Sky Labs
Join date: 10 Jan 2007
Posts: 272
07-19-2007 15:24
It was just a Syntax error. It actually moved around, depending on how I played around with the code. It usually pointed to this line:

AddButton(opt1, opt3, llList2String(tokens, 7), opt4, llList2String(tokens, 5), llList2Integer(tokens, 6));

To the first llList2String. But again, it could move if I did things like just delete one of the global defs, not even being used now, at the top.

My best guess was maybe that the Windows client compiler was having an issue with the statement evaluation depth, because to get around it without deleting stuff from the original code, i moved that else if to the first if.
Darien Caldwell
Registered User
Join date: 12 Oct 2006
Posts: 3,127
07-19-2007 15:37
I believe this, because I recently had a similar issue on a PC client. I have a XYText script that has a long list of IF ELSE IF statements. I compiled it sometime before the 1.18 client release, and it compiled and worked fine. But just a few days ago I went back and changed one string, it would no longer compile. giving a 'moving error' as you describe. It took me awhile to figure out that i could have one less ELSE IF statement under 1.18 than I could previously. I just chalked it up to the Lindens once again trying to nerf LSL.

I have no MAC client to see if the extra ELSE IF still works.
_____________________
Milambus Oh
Registered User
Join date: 6 Apr 2007
Posts: 224
07-19-2007 16:13
I wonder if it might be an endline character issue. Since Windows uses a carriage return and new line character at the end of lines, while Macs just use end line.
ed44 Gupte
Explorer (Retired)
Join date: 7 Oct 2005
Posts: 638
07-20-2007 06:35
I ran this through lslint on their web site at http://w-hat.com/lslint/ and got:

From: someone

ERROR:: (145,104): Parser stack depth exceeded; SL will throw a syntax error here.
WARN:: ( 5, 1): variable `g_Config' declared but never used.
WARN:: ( 6, 1): variable `g_Comment' declared but never used.
WARN:: ( 7, 1): variable `g_QueryID' declared but never used.
WARN:: ( 14, 1): variable `g_LoopOpt' declared but never used.
WARN:: ( 15, 1): variable `g_SoundOpt' declared but never used.
WARN:: ( 16, 1): variable `g_AnimOpt' declared but never used.
WARN:: ( 21, 1): variable `g_UpCmd' declared but never used.
WARN:: ( 30, 1): variable `g_pos' declared but never used.
WARN:: ( 31, 1): variable `g_rot' declared but never used.
WARN:: ( 32, 1): variable `g_newpos' declared but never used.
WARN:: ( 34, 1): variable `g_Mute' declared but never used.
WARN:: ( 35, 1): variable `g_TopMenu' declared but never used.
WARN:: ( 36, 1): variable `g_Idle' declared but never used.
WARN:: ( 37, 1): variable `g_RepeatButtons' declared but never used.
WARN:: ( 38, 1): variable `g_Timer' declared but never used.
WARN:: ( 42, 1): variable `AnimControl' declared but never used.
WARN:: ( 43, 1): variable `AnimStart' declared but never used.
WARN:: ( 44, 1): variable `AnimStop' declared but never used.
WARN:: ( 46, 1): variable `g_Volume' declared but never used.
WARN:: ( 48, 1): variable `g_Menus' declared but never used.
WARN:: ( 49, 1): variable `g_MenuTexts' declared but never used.
WARN:: ( 50, 1): variable `g_MenuStartptr' declared but never used.
WARN:: ( 51, 1): variable `g_MenuEndptr' declared but never used.
WARN:: ( 52, 1): variable `g_Bptr1' declared but never used.
WARN:: ( 53, 1): variable `g_Bptr2' declared but never used.
WARN:: ( 54, 1): variable `g_Menuptr' declared but never used.
WARN:: ( 55, 1): variable `g_MenuStack' declared but never used.
WARN:: ( 57, 1): variable `g_Buttons' declared but never used.
WARN:: ( 58, 1): variable `g_ButtonCount' declared but never used.
WARN:: ( 60, 1): variable `g_Anims' declared but never used.
WARN:: ( 61, 1): variable `g_Anim' declared but never used.
WARN:: ( 63, 1): variable `g_Sounds' declared but never used.
WARN:: ( 64, 1): variable `g_Sloops' declared but never used.
WARN:: ( 65, 1): variable `g_Sound' declared but never used.
WARN:: ( 67, 1): variable `g_Texts' declared but never used.
WARN:: ( 69, 1): variable `g_x' declared but never used.
WARN:: ( 70, 1): variable `g_Agent' declared but never used.
WARN:: ( 71, 1): variable `g_Channel' declared but never used.
WARN:: ( 72, 1): variable `g_ListenID' declared but never used.
WARN:: ( 73, 1): variable `g_TempMenu' declared but never used.
WARN:: ( 74, 1): variable `g_TempRepeat' declared but never used.
WARN:: ( 75, 1): variable `g_MenuText' declared but never used.
WARN:: ( 77, 1): variable `g_Alpha1' declared but never used.
WARN:: ( 79, 1): variable `g_Worn' declared but never used.
WARN:: ( 80, 1): variable `g_Sit' declared but never used.
WARN:: ( 82, 1): variable `g_PageCmd' declared but never used.
WARN:: ( 83, 1): variable `g_Page' declared but never used.
WARN:: ( 84, 1): variable `g_Marked' declared but never used.
WARN:: ( 85, 1): variable `g_Marker' declared but never used.
WARN:: ( 87, 1): function `UnComment' declared but never used.
WARN:: ( 87, 25): variable `text1' declared but never used.
WARN:: ( 87, 39): variable `text2' declared but never used.
WARN:: ( 92, 16): variable `menu' declared but never used.
WARN:: ( 92, 29): variable `text' declared but never used.
WARN:: ( 96, 18): variable `menu' declared but never used.
WARN:: ( 96, 31): variable `button' declared but never used.
WARN:: ( 96, 46): variable `text' declared but never used.
WARN:: ( 96, 59): variable `anim' declared but never used.
WARN:: ( 96, 72): variable `sound' declared but never used.
WARN:: ( 96, 87): variable `loop' declared but never used.
WARN:: (103, 1): function `ParseCommand' declared but never used.
WARN:: (109, 1): variable `ptr' declared but never used.
WARN:: (113, 1): variable `text' declared but never used.
TOTAL:: Errors: 1 Warnings: 63


You have too many nested if elses. The compiler keeps a stack of where it is in the if/else tree and runs out of space. You could return from each if statement if only to reduce stack use.


This menu program will not pass Programming 101, but it overcomes some of the stack overflow problems with our lsl compiler (before it is even run!). Hopefully mono will let us revert to a better way to get the most out of each 16 K Byte script space.

CODE

list MENU = [ "A" , "0" , "1" , "2" , "3" , "4" , "5" ];

listen(integer channel, string name, key id, string message)
{
integer index = llListFindList(MENU, [message]);
if(index != -1) // verify dialog choice
{
if (0 == index) {DoMenuA(); return; }
if (1 == index) { DoMenu0(); return; }
if (2 == index) { DoMenu1(); return; }
if (3 == index) { DoMenu2(); return; }
if (4 == index) { DoMenu3(); return; }
if (5 == index) { DoMenu4(); return; }
if (6 == index) { DoMenu5(); return; }
}
llOwnerSay ("Could not decode " + (string) message);
}


The matrix of if statements and very simple sub calls also would not pass Programming 101 but it makes it easier to spot mistakes in the copying and pasting most programmers use to produce this kind of code.
RJ Source
Green Sky Labs
Join date: 10 Jan 2007
Posts: 272
07-20-2007 06:41
Interesting. Yeah the depth of the evals seemed to have been the consensus (mostly the if/elses in this case). But the really curious thing from the beginning is that it does compile and execute fine on the mac client.
Masakazu Kojima
ケロ
Join date: 23 Apr 2004
Posts: 232
07-21-2007 07:45
My guess is they just use a different version of bison with different defaults to compile the Mac viewer.

See this post for another case: http://forums.secondlife.com/showthread.php?t=87017&page=6&pp=15#post1317875

And this for an explanation of the error:
http://forums.secondlife.com/showthread.php?t=163711