gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/trunk r11178: Do slot reservation more cor


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r11178: Do slot reservation more correctly. Tests from all as3compile versions should
Date: Mon, 29 Jun 2009 12:31:21 +0200
User-agent: Bazaar (1.13.1)

------------------------------------------------------------
revno: 11178
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Mon 2009-06-29 12:31:21 +0200
message:
  Do slot reservation more correctly. Tests from all as3compile versions should
  now run properly.
modified:
  libcore/asClass.cpp
  libcore/asClass.h
  libcore/parser/abc_block.cpp
  libcore/parser/abc_block.h
    ------------------------------------------------------------
    revno: 11169.1.1
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Mon 2009-06-29 09:39:07 +0200
    message:
      Spaces.
    modified:
      libcore/asClass.cpp
    ------------------------------------------------------------
    revno: 11169.1.2
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Mon 2009-06-29 09:39:22 +0200
    message:
      Drop slot hack (now tests fail).
      
      Add more abc block initialization logging information.
    modified:
      libcore/parser/abc_block.cpp
    ------------------------------------------------------------
    revno: 11169.1.3
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Mon 2009-06-29 10:24:27 +0200
    message:
      Add output operator for Trait::Kind.
    modified:
      libcore/parser/abc_block.cpp
      libcore/parser/abc_block.h
    ------------------------------------------------------------
    revno: 11169.1.4
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Mon 2009-06-29 10:31:11 +0200
    message:
      Clean up logging.
    modified:
      libcore/parser/abc_block.cpp
    ------------------------------------------------------------
    revno: 11169.1.5
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Mon 2009-06-29 11:42:53 +0200
    message:
      Make sure Global is the prototype of the entry script. This produces the
      behaviour expected when the entry script is used, though the semantics of
      setting it as a 'prototype' needs thought.
      
      Use reserveSlot instead of init_member where we just want to reserve a 
slot.
      
      Register member classes with the global name, not the local one.
      
      as3compile tests should now all work.
    modified:
      libcore/asClass.cpp
      libcore/asClass.h
      libcore/parser/abc_block.cpp
=== modified file 'libcore/asClass.cpp'
--- a/libcore/asClass.cpp       2009-06-23 13:44:26 +0000
+++ b/libcore/asClass.cpp       2009-06-29 09:42:53 +0000
@@ -82,17 +82,14 @@
 asClass::addSlot(string_table::key name, asNamespace* ns,
         boost::uint32_t slotId, asClass* /*type*/, bool /*isstatic*/)
 {
-       string_table::key nsname = ns ? ns->getURI() : string_table::key(0);
-//     int flags = as_prop_flags::dontDelete;
-//     if (isstatic)
-//             flags |= as_prop_flags::staticProp;
-//     log_debug("Before init_member.");
+       string_table::key nsname = ns ? ns->getURI() : 0;
+
        //TODO: Set flags.
-       if(slotId == 0){
-               _prototype->init_member(name,as_value(), 0, nsname);
+       if(slotId == 0) {
+               _prototype->init_member(name, as_value(), 0, nsname);
        }
-       else{
-               _prototype->init_member(name, as_value(), 0, nsname, slotId);
+       else {
+               _prototype->reserveSlot(name, nsname, slotId);
        }
        return true;
 }

=== modified file 'libcore/asClass.h'
--- a/libcore/asClass.h 2009-05-19 15:55:16 +0000
+++ b/libcore/asClass.h 2009-06-29 09:42:53 +0000
@@ -169,7 +169,13 @@
 
        string_table::key getName() const { return _name; }
 
-       void initPrototype(){ _prototype = new as_object();}
+    void setPrototype(as_object* prototype) {
+        _prototype = prototype;
+    }
+
+       void initPrototype() {
+        _prototype =  new as_object();
+    }
 
        /// What is the type of our parent class?
        asClass* getSuper() const { return _super; }

=== modified file 'libcore/parser/abc_block.cpp'
--- a/libcore/parser/abc_block.cpp      2009-06-26 05:53:09 +0000
+++ b/libcore/parser/abc_block.cpp      2009-06-29 09:42:53 +0000
@@ -37,8 +37,9 @@
 bool
 Trait::finalize(abc_block *pBlock, asClass *pClass, bool do_static)
 {
-       log_abc("In finalize class name=%s trait kind=0x%X", 
-            pBlock->_stringPool[pClass->getName()], _kind | 0x0);
+       log_abc("Finalize class %s (%s), trait kind: %s", 
+            pBlock->_stringPool[pClass->getName()], pClass, _kind);
+
        switch (_kind)
        {
        case KIND_SLOT:
@@ -47,7 +48,7 @@
                // Validate the type.
                asClass *pType;
                if (_typeIndex) {
-                       log_abc("Trait type is %s", 
+                       log_abc("Trait type: %s", 
                 pBlock->_stringPool[
                     pBlock->_multinamePool[_typeIndex].getABCName()]);
                        pType = 
pBlock->locateClass(pBlock->_multinamePool[_typeIndex]);
@@ -92,7 +93,10 @@
        }
        case KIND_CLASS:
        {
-               pClass->addMemberClass(_name, _namespace, _slotID, 
+               log_abc("Adding class %s, value %s, slot=%u",
+                pBlock->_stringPool[_name], _value, _slotID);
+
+               pClass->addMemberClass(_globalName, _namespace, _slotID, 
                        pBlock->_classes[_classInfoIndex], do_static);
                break;
        }
@@ -206,8 +210,8 @@
        boost::uint8_t kind = in->read_u8();
        _kind = static_cast<Kind>(kind & 0x0F);
 
-       log_abc("Trait name: %s, Trait kind: 0x%X",
-            pBlock->_stringPool[multiname.getABCName()], kind | 0x0);
+       log_abc("Trait name: %s, Trait kind: %s",
+            pBlock->_stringPool[multiname.getABCName()], _kind);
 
     switch (_kind)
        {
@@ -291,6 +295,29 @@
        return true;
 }
 
+std::ostream&
+operator<<(std::ostream& o, const Trait::Kind k)
+{
+    switch (k) {
+        case abc::Trait::KIND_SLOT:
+            return o << "slot";
+        case abc::Trait::KIND_CONST:
+            return o << "const";
+        case abc::Trait::KIND_METHOD:
+            return o << "method";
+        case abc::Trait::KIND_GETTER:
+            return o << "getter";
+        case abc::Trait::KIND_SETTER:
+            return o << "setter";
+        case abc::Trait::KIND_CLASS:
+            return o << "class";
+        case abc::Trait::KIND_FUNCTION:
+            return o << "function";
+        default:
+            return o << "Unknown kind " << static_cast<int>(k);
+    }
+}
+
 } // abc
 
 using namespace abc;
@@ -308,11 +335,22 @@
 void
 abc_block::prepare(Machine* mach)
 {
+    
     std::for_each(_classes.begin(), _classes.end(),
             std::mem_fun(&asClass::initPrototype));
 
-    std::for_each(_scripts.begin(), _scripts.end(),
-            std::mem_fun(&asClass::initPrototype));
+    // The first (entry) script has Global as its prototype.
+    // This can be deduced because the global classes are initialized with a
+    // slot on script 0 (entry script). OpNewClass then attempts to set the
+    // corresponding slot once the class has been constructed. At this point,
+    // global should verifiably be on the stack, so the slots are expected
+    // to be set on the global object.
+    if (!_scripts.empty()) {
+        _scripts.front()->setPrototype(mach->global());
+
+        std::for_each(_scripts.begin() + 1, _scripts.end(),
+                std::mem_fun(&asClass::initPrototype));
+    }
  
     std::for_each(_methods.begin(), _methods.end(),
             boost::bind(&asMethod::initPrototype, _1, mach));
@@ -320,17 +358,6 @@
     std::for_each(_traits.begin(), _traits.end(),
             boost::bind(&Trait::finalize, _1, this));
 
-    // If the following is enabled, it reserves slots for all namespaces
-    // in the global object. This means that ABC_ACTION_SETSLOT does not
-    // fail as often, but doesn't really seem quite correct.
-#if 1
-    as_object* global = mach->global();
-        assert(global);
-    for (std::vector<asNamespace*>::iterator i = _namespacePool.begin(), 
-            e = _namespacePool.end(); i != e; ++i) {
-        global->reserveSlot((*i)->getURI(), 0, i - _namespacePool.begin());
-    }
-#endif
     _traits.clear();
 
 }
@@ -532,7 +559,8 @@
        {
                boost::uint8_t kind = _stream->read_u8();
                boost::uint32_t nameIndex = _stream->read_V32();
-               log_abc("Namespace %u kind=0x%X index=%u name=%s", i, kind | 
0x0, nameIndex, _stringPool[nameIndex]);
+               log_abc("Namespace %u: kind %s, index %u, name %s", i,
+                static_cast<int>(kind), nameIndex, _stringPool[nameIndex]);
 
                if (nameIndex >= _stringPool.size())
                {
@@ -552,6 +580,7 @@
                        _namespacePool[i] = n;
                }
                if (kind == PROTECTED_NS) _namespacePool[i]->setProtected();
+               if (kind == PACKAGE_NS) _namespacePool[i]->setPackage();
                setNamespaceURI(_namespacePool[i], nameIndex);
        }
        return true;
@@ -605,7 +634,7 @@
                boost::uint32_t name = 0;
                boost::uint32_t nsset = 0;
 
-               log_abc("Multiname %u has kind=0x%X", i, kind | 0x0);
+               log_abc("Multiname %u has kind %s", i, static_cast<int>(kind));
 
                // Read, but don't upper validate until after the switch.
                switch (kind)
@@ -963,7 +992,10 @@
                }
 
                boost::uint8_t flags = _stream->read_u8();
-               log_abc("Instance %u multiname index=%u name=%s super index=%u 
flags=%X", i, index, _stringPool[_multinamePool[index].getABCName()], 
super_index, flags | 0x0);
+               log_abc("Instance %u(%s) multiname index=%u name=%s super 
index=%u "
+                "flags=%X", i, pClass, index, 
+                _stringPool[_multinamePool[index].getABCName()],
+                super_index, flags | 0x0);
 
                if (flags & INSTANCE_SEALED)
                        pClass->setSealed();
@@ -1053,9 +1085,9 @@
        log_abc("There are %u classes.", count);
        for (unsigned int i = 0; i < count; ++i)
        {
-               asClass *pClass = _classes[i];
+               asClass* pClass = _classes[i];
                boost::uint32_t offset = _stream->read_V32();
-               log_abc("Class %u static constructor index=%u", i, offset);
+               log_abc("Class %u(%s) static constructor index=%u", i, pClass, 
offset);
                if (offset >= _methods.size())
                {
                        log_error(_("ABC: Out of bound static constructor for 
class."));
@@ -1093,11 +1125,12 @@
        _scripts.resize(count);
        for (unsigned int i = 0; i < count; ++i)
        {
-               asClass *pScript = mCH->newClass();
+               asClass* pScript = mCH->newClass();
                _scripts[i] = pScript;
 
                boost::uint32_t offset = _stream->read_V32();
-               log_abc("Reading script %u initializer method index=%u", i, 
offset);
+               log_abc("Reading script %u(%s) initializer method index=%u", i,
+                pScript, offset);
                if (offset >= _methods.size())
                {
                        log_error(_("ABC: Out of bounds method for script."));
@@ -1122,7 +1155,7 @@
                        if (!(aTrait.read(_stream, this))) {
                                return false;
             }
-                       log_abc("Trait: %u name: %s(%u) kind: %u value: %s ", 
j, 
+                       log_abc("Trait: %u name: %s(%u) kind: %s value: %s ", 
j, 
                     _stringPool[aTrait._name], aTrait._name, aTrait._kind,
                     aTrait._value.to_string());
 
@@ -1241,7 +1274,7 @@
                 // TODO: 'method body activation traits'
                                return false;
             }
-                       log_abc("Trait: %u name: %s kind: %u value: %s ", j, 
+                       log_abc("Trait: %u name: %s kind: %s value: %s ", j, 
                     _stringPool[aTrait._name], aTrait._kind, 
                     aTrait._value.to_string());
                }

=== modified file 'libcore/parser/abc_block.h'
--- a/libcore/parser/abc_block.h        2009-06-26 05:52:12 +0000
+++ b/libcore/parser/abc_block.h        2009-06-29 08:24:27 +0000
@@ -119,6 +119,9 @@
        }
 };
 
+/// Output stream operator for abc::Trait::Kind
+std::ostream& operator<<(std::ostream& o, const Trait::Kind k);
+
 } // namespace abc
 
 namespace {
@@ -205,35 +208,8 @@
     void prepare(Machine* mach);
 
 private:
-
-    friend class abc::Trait;
-
-       bool read_version();
-       bool read_integer_constants();
-       bool read_unsigned_integer_constants();
-       bool read_double_constants();
-       bool read_string_constants();
-       bool read_namespaces();
-       bool read_namespace_sets();
-       bool read_multinames();
-       bool read_method_infos();
-       bool skip_metadata();
-       bool read_instances();
-       bool read_classes();
-       bool read_scripts();
-       bool read_method_bodies();
-
-       void check_multiname_name(boost::uint32_t name);
-
-       void check_multiname_namespace(boost::uint32_t ns);
-
-       void check_multiname_namespaceset(boost::uint32_t nsset);
-
-       void setMultinameNames(asName *n,string_table::key ABCName);
-
-       void setNamespaceURI(asNamespace *ns,string_table::key ABCName);
-
-       enum Constants
+       
+    enum Constant
        {
                PRIVATE_NS = 0x05,
                PACKAGE_NS = 0x16,
@@ -262,6 +238,33 @@
                POOL_NULL = 0x0C
        };
 
+    friend class abc::Trait;
+
+       bool read_version();
+       bool read_integer_constants();
+       bool read_unsigned_integer_constants();
+       bool read_double_constants();
+       bool read_string_constants();
+       bool read_namespaces();
+       bool read_namespace_sets();
+       bool read_multinames();
+       bool read_method_infos();
+       bool skip_metadata();
+       bool read_instances();
+       bool read_classes();
+       bool read_scripts();
+       bool read_method_bodies();
+
+       void check_multiname_name(boost::uint32_t name);
+
+       void check_multiname_namespace(boost::uint32_t ns);
+
+       void check_multiname_namespaceset(boost::uint32_t nsset);
+
+       void setMultinameNames(asName *n,string_table::key ABCName);
+
+       void setNamespaceURI(asNamespace *ns,string_table::key ABCName);
+
        std::vector<boost::int32_t> _integerPool;
        std::vector<boost::uint32_t> _uIntegerPool;
        std::vector<double> _doublePool;
@@ -286,7 +289,9 @@
 
 };
 
+
 } 
 
+
 #endif /* GNASH_ABC_BLOCK_H */
 


reply via email to

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