Skip to content
Richard L. Hudson edited this page Apr 3, 2014 · 2 revisions

Array.prototype.buildPar(iterationSpace, elementalFunction=undefined)

##Abstract routine

InitializePar(typeDescriptor, dimensions, buffer, offset, callbackfn, callbackthis = undefined, indices= [])

Where

typeDescriptor is a type descriptor

dimensions is an array of integers

buffer is an array buffer

offset is an integer

callbackfn is a function passed an array of indices indicating where in the result the value produced by this callbackfn will be placed and an cursor reflecting where in the resulting array the value can be placed.

indices is an array of indices indicating which element or array is being initialized.

  1. If dimensions is Cons(length, remainingDimensions):
    1. Let size be Size(typeDescriptor, remainingDimensions)
    2. In an arbitrary implementation dependent order for each i between 0 and length - 1:
      1. Set resultIndices to cons(indices, i)
      2. Call InitializePar(typeDescriptor, remainingDimensions, buffer, offset + i * size, resultIndices)
    3. Return
  2. Otherwise, if typeDescriptor is a ground type descriptor
    1. if IsCallable(callbackfn)
      1. let cursor be the result of calling makeCursor(typeDescriptor, buffer, offset) TBD define makeCursor
      2. let value be the result of calling callbackfn with an argument list of indices, and cursor and a this argument of callbackthis .
      3. If value is not undefined
        1. Call ConvertAndCopyTo(typeDescriptor, dimensions, buffer, offset, value)
    2. Otherwise let value be Default(typeDescriptor)
      1. Call ConvertAndCopyTo(typeDescriptor, dimensions, buffer, offset, value)
  3. Otherwise, structure must be a list of field records:
    1. if IsCallable(callbackfn)
      1. let cursor be the result of calling makeCursor(typeDescriptor, buffer, offset)
      2. let value be the result of calling callbackfn with a this argument of callbackthis an argument list of indices, and cursor.
      3. If value is defined
        1. Call ConvertAndCopyTo(typeDescriptor, dimensions, buffer, offset, value) //TBD am I dealing with dimensions correctly here?
    2. Otherwise
      1. For each field record {name, byteOffset, type} in structure:
      2. Let fieldOffset be offset + byteOffset
      3. Let fieldTypeDescriptor be type.[[TypeDescriptor]]
      4. Let fieldDimensions be type.[[ Dimensions]]
      5. Call Initialize (fieldTypeDescriptor, fieldDimensions, buffer, fieldOffset)
Clone this wiki locally