Dynamic Objects

version 8/140515 by Jesse McGrew

  • Home page
  • Beginning
  • Previous
  • Next



  • Section 1 - 'a new object cloned from'
    To decide which object is a new object cloned from (prev - an object), preserving relations: (- DO_CloneObject({prev}, {phrase options}) -).
    First before cloning a new object from (this is the dynamic objects setting activity variables rule): initialize cloning activity variables.
    To initialize cloning activity variables: (- (+preserving relations+) = do_temp_array-->0; -).
    Include (-
    Constant OBJECT_STRUCT_SIZE = NUM_ATTR_BYTES + 25;
    [ DO_CloneObject src opts rv props i;
        ! need to have something to copy from
        if ((src == 0) || (src->0 ~= $70)) rfalse;
        do_temp_array-->0 = (opts ~= 0); ! will be copied to "preserving relations"
        BeginActivity((+ cloning a new object from activity +), src);
        if (ForActivity((+ cloning a new object from activity +), src) == false) {
            ! copy property table (this also allocates the fixed-size object structure at the beginning)
            rv = DO_CloneProperties(src);
            if (~~rv) { AbandonActivity((+ cloning a new object from activity +), src); rfalse; }
            props = rv + OBJECT_STRUCT_SIZE;
            ! initialize object
            rv->0 = $70; ! type ID
            for ( i=1: i<=NUM_ATTR_BYTES: i++ ) rv->i = src->i; ! attributes
            i = (1 + NUM_ATTR_BYTES) / 4;
            rv-->i = 0; ! next object link
            rv-->(i+1) = src-->(i+1); ! hardware name
            rv-->(i+2) = props; ! property table
            rv-->(i+3) = 0; ! parent
            rv-->(i+4) = 0; ! sibling
            rv-->(i+5) = 0; ! child
            ! insert object into Inform's linked lists
            DO_LinkObject(src, rv);
            ! update relation structures and maintain invariants for symmetric relations
            DO_FixRelations(src, rv, opts);
        }
        
        ! we can't refer to the activity variable "new object" from here, so we rely on knowing that it's the first variable in this activity (see above)
        MStack-->MstVO(10000 + (+ cloning a new object from activity +), 0) = rv;
        
        EndActivity((+ cloning a new object from activity +), src);
        return rv;
    ];
    -).
    First after cloning a new object from a thing (this is the dynamic objects belt loosening rule):
        let NT be the number of things;
        if the number of rows in the Table of Locale Priorities is less than NT, change the Table of Locale Priorities to have NT + 4 rows.