|
@@ -17,66 +17,58 @@ var RTL$ = {
|
|
|
result[i] = this.makeArray.apply(this, forward);
|
|
|
return result;
|
|
|
},
|
|
|
- copyArrayOfRecords: function (from, to){
|
|
|
- to.splice(0, to.length);
|
|
|
- var length = from.length;
|
|
|
- if (!length)
|
|
|
+ copy: function (from, to, type){
|
|
|
+ var r = type.record;
|
|
|
+ if (r){
|
|
|
+ for(var f in r){
|
|
|
+ var fieldType = r[f];
|
|
|
+ if (fieldType){
|
|
|
+ // temporary support for mangled fields
|
|
|
+ var mangled = "$" + f;
|
|
|
+ if (!from.hasOwnProperty(mangled))
|
|
|
+ mangled = f;
|
|
|
+ this.copy(from[mangled], to[mangled], fieldType);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ to[f] = from[f];
|
|
|
+ }
|
|
|
return;
|
|
|
-
|
|
|
- var method = from[0] instanceof Array
|
|
|
- ? this.cloneArrayOfRecords // this is array of arrays, go deeper
|
|
|
- : this.cloneRecord;
|
|
|
- for(var i = 0; i < length; ++i)
|
|
|
- to.push(method.call(this, from[i]));
|
|
|
- },
|
|
|
- cloneArrayOfRecords: function (from){
|
|
|
- var length = from.length;
|
|
|
- var result = new Array(length);
|
|
|
- if (length){
|
|
|
- var method = from[0] instanceof Array
|
|
|
- ? this.cloneArrayOfRecords // this is array of arrays, go deeper
|
|
|
- : this.cloneRecord;
|
|
|
- for(var i = 0; i < result.length; ++i)
|
|
|
- result[i] = method.call(this, from[i]);
|
|
|
}
|
|
|
- return result;
|
|
|
- },
|
|
|
- cloneRecord: function (from){
|
|
|
- var Ctr = from.constructor;
|
|
|
- var result = new Ctr();
|
|
|
- this.copyRecord(from, result);
|
|
|
- return result;
|
|
|
- },
|
|
|
- copyRecord: function (from, to){
|
|
|
- for(var prop in to){
|
|
|
- if (to.hasOwnProperty(prop)){
|
|
|
- var v = from[prop];
|
|
|
- var isScalar = prop[0] != "$";
|
|
|
- if (isScalar)
|
|
|
- to[prop] = v;
|
|
|
- else
|
|
|
- to[prop] = v instanceof Array ? this.cloneArrayOfRecords(v)
|
|
|
- : this.cloneRecord(v);
|
|
|
+ var a = type.array;
|
|
|
+ if (a !== undefined ){
|
|
|
+ if (a === null)
|
|
|
+ // shallow copy
|
|
|
+ Array.prototype.splice.apply(to, [0, to.length].concat(from));
|
|
|
+ else {
|
|
|
+ // deep copy
|
|
|
+ to.splice(0, to.length);
|
|
|
+ for(var i = 0; i < from.length; ++i)
|
|
|
+ to.push(this.clone(from[i], a));
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
- copyArrayOfScalars: function (from, to){
|
|
|
- to.splice(0, to.length);
|
|
|
- for(var i = 0; i < from.length; ++i)
|
|
|
- to.push(this.cloneArrayOfScalars(from[i]));
|
|
|
- },
|
|
|
- cloneArrayOfScalars: function (from){
|
|
|
- var length = from.length;
|
|
|
- if (!length)
|
|
|
- return [];
|
|
|
- if (!(from[0] instanceof Array))
|
|
|
- return from.slice();
|
|
|
+ clone: function (from, type){
|
|
|
+ var result;
|
|
|
+ var r = type.record;
|
|
|
+ if (r){
|
|
|
+ var Ctr = from.constructor;
|
|
|
+ result = new Ctr();
|
|
|
+ this.copy(from, result, type);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ var a = type.array;
|
|
|
+ if (a !== undefined ){
|
|
|
+ if (a === null)
|
|
|
+ // shallow clone
|
|
|
+ return from.slice();
|
|
|
|
|
|
- // this is array of arrays, go deeper
|
|
|
- var result = new Array(length);
|
|
|
- for(var i = 0; i < length; ++i)
|
|
|
- result[i] = this.cloneArrayOfScalars(from[i]);
|
|
|
- return result;
|
|
|
+ // deep clone
|
|
|
+ var length = from.length;
|
|
|
+ result = new Array(length);
|
|
|
+ for(var i = 0; i < length; ++i)
|
|
|
+ result[i] = this.clone(from[i], a);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
},
|
|
|
assert: function (condition){
|
|
|
if (!condition)
|
|
@@ -119,12 +111,12 @@ function passArrayBeRef(a/*VAR ARRAY * OF INTEGER*/){
|
|
|
|
|
|
function passArrayOfRecordsByRef(a/*VAR ARRAY * OF T*/){
|
|
|
var result = [];
|
|
|
- RTL$.copyArrayOfRecords(result, a);
|
|
|
+ RTL$.copy(result, a, {array: {record: {a: {array: null}}}});
|
|
|
}
|
|
|
|
|
|
function passArrayOfArraysByRef(a/*VAR ARRAY *, 3 OF INTEGER*/){
|
|
|
var result = [];
|
|
|
- RTL$.copyArrayOfScalars(result, a);
|
|
|
+ RTL$.copy(result, a, {array: {array: null}});
|
|
|
}
|
|
|
dynamicInt.push(3);
|
|
|
dynamicInt.push(i);
|
|
@@ -135,7 +127,7 @@ dynamicString.push(s);
|
|
|
dynamicChar.push(34);
|
|
|
dynamicByte.push(byte);
|
|
|
dynamicByte.push(i & 0xFF);
|
|
|
-dynamicRecord.push(RTL$.cloneRecord(r));
|
|
|
+dynamicRecord.push(RTL$.clone(r, {record: {a: {array: null}}}));
|
|
|
dynamicArrayOfStaticArrayInt.push(a.slice());
|
|
|
RTL$.assert(dynamicInt.indexOf(i) != -1);
|
|
|
RTL$.assert(dynamicChar.indexOf(34) != -1);
|