discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

StepTalk patch: argument bytecode sign bug fix, optimization literals, s


From: Mateu Batle
Subject: StepTalk patch: argument bytecode sign bug fix, optimization literals, stack overflow fix
Date: Wed, 26 May 2004 16:01:23 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6) Gecko/20040113

Hi everybody !

I have submitted a patch to savannah web, which fixes following bugs:

- Fixed bug with signed/unsigned bytecode, which made StepTalk to crash if has more than 127 literals in the array.

- Possible problem of stack overflow, returned object are never pop from stack if nobody uses them. Please check this fix.

- Optimization: literal array usage, don't create a new entry if already exists

Some comments also:

- bytecodes seem to be 1 byte long for each, operation and two arguments (max 3 bytes). I think it may fall short in some cases, for example for the literals table index. This is the reason of the optimization submitted in the patch, before all literals where always appended
to the array without checking if they could be reused.

- In STBytecode bytecode code and arguments are defined as short, but they are always 1 byte.
It does not matter that much, but it can be confusing.

cheers !
 Mateu Batle
Index: STCompiler.m
===================================================================
--- STCompiler.m        (revision 147)
+++ STCompiler.m        (working copy)
@@ -470,8 +470,12 @@
 
 - (unsigned)addLiteral:literal
 {
-    [literals addObject:literal];
-    return [literals count] - 1;
+    unsigned index = [literals indexOfObject: literal];
+    if (index == NSNotFound) {
+        [literals addObject:literal];
+        index = [literals count] - 1;
+    }
+    return index;
 }
 
 - (unsigned)externalVariableIndex:(NSString *)varName
@@ -596,10 +600,17 @@
     
     if(array)
     {
+        BOOL first = YES;
         enumerator = [array objectEnumerator];
         while((expr = [enumerator nextObject]))
         {
-            [self compileExpression:expr];
+            // mateu.batle: ignore returned value on the stack ? please check 
this !!!
+            if (!first) {
+                [self emitPopStack];
+            } else {
+                first = NO;
+            }
+            [self compileExpression:expr];            
         }
     }
 
Index: STBytecodes.m
===================================================================
--- STBytecodes.m       (revision 147)
+++ STBytecodes.m       (working copy)
@@ -206,7 +206,7 @@
 - (STBytecode)fetchNextBytecodeAtPointer:(unsigned *)pointer
 {
     STBytecode  bytecode;
-    const char *bytesPtr = (const char *)[bytes bytes];
+    const unsigned char *bytesPtr = (const unsigned char *)[bytes bytes];
     unsigned    length = [self length];
     
     if(*pointer < length)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]