Harbs,

First, I can't believe you have time to code just after having another baby.

But anyway, is your goal to convert these structures to AS or to replicate the 
Restructure library in AS?  Seems like if you want lazy instantiation, you 
should be using Restructure in AS.

That said, in AS, we can use getters for lazy instantiation.

My 2 cents,
-Alex

On 5/2/18, 9:13 AM, "Harbs" <[email protected]> wrote:

    Here’s a fun one:
    
    var MinMax:Struct = new Struct({
        minCoord:           new Pointer(r.uint16, BaseCoord),  // May be NULL
        maxCoord:           new Pointer(r.uint16, BaseCoord),  // May be NULL
        featMinMaxCount:    r.uint16,                            // May be 0
        featMinMaxRecords:  new ArrayStruct(FeatMinMaxRecord, 
'featMinMaxCount') // In alphabetical order
    });
    
    This struct is then used in another and so on:
    
    var BaseLangSysRecord:Struct = new Struct({
        tag:    new StringStruct(4),  // 4-byte language system identification 
tag
        minMax: new Pointer(r.uint16, MinMax, {type: 'parent'})
    });
    
    I believe one of the primary features of these classes is that they support 
lazy initialization and the structures can be evaluated as needed.
    
    Harbs
    
    > On May 2, 2018, at 6:36 PM, Alex Harui <[email protected]> wrote:
    > 
    > What do some of the actual structs look like?  The Restructure 
library/language looks like an attempt to strongly-type data structures.  I've 
been told that type-inferencing is a key part to performance in JS in the 
browser.  But as we look into the future at other output types, statically 
knowing types looks like it will be really important.
    > 
    > Having a way to output bracket notation might be a bunch of work, and you 
might be surprised by the results.  Every time you use an Array, the accessor 
is returning an Object, not whatever type you know is in there.
    > 
    > HTH,
    > -Alex
    > 
    > On 5/2/18, 12:29 AM, "Harbs" <[email protected]> wrote:
    > 
    >    Nope. They are data structures that are constructed from binary data. 
They are also generally lazily initialized (which makes a huge difference in 
performance and memory footprint). Basically, there are tens of tables which 
might, or might not exist in any given font. The tables might or might not have 
different pieces of information to describe features and functionality.
    > 
    >    It took my a couple of weeks just to wrap my head around all this 
stuff… ;-)
    > 
    >    It’s using this set of classes (also migrated to AS3):
    >    
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fdevongovett%2Frestructure&data=02%7C01%7Caharui%40adobe.com%7C0dba99c3f32b410a1fd608d5affe6efd%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636608429687243487&sdata=%2Bn6rP8sRodUlqLqLlcia%2FWwQMAvBYpYDmlU%2BNE4YGDk%3D&reserved=0
 
<https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fdevongovett%2Frestructure&data=02%7C01%7Caharui%40adobe.com%7C0dba99c3f32b410a1fd608d5affe6efd%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636608429687243487&sdata=%2Bn6rP8sRodUlqLqLlcia%2FWwQMAvBYpYDmlU%2BNE4YGDk%3D&reserved=0>
    > 
    >    There are 148 instances of Struct alone. Almost every one has a 
different set of variables. That does not even include VersionedStruct, Array 
structs, Number structs, LazyArray, etc.
    > 
    >    Maybe there’s a way to infer types, but I don’t see how. Many of the 
variables can have different types depending on the context too. (Sometimes 
they can even be functions.)
    > 
    >    Harbs
    > 
    >> On May 2, 2018, at 10:16 AM, Alex Harui <[email protected]> wrote:
    >> 
    >> Are the objects JSON objects?  We have a utility that tries to convert 
JSON to AS3 ValueObjects by guessing the data types.
    >> 
    >> If the objects are externally instantiated, then you only really need 
typedefs and can avoid the memory overhead of the definitions.
    >> 
    >> -Alex
    >> 
    >> On 5/1/18, 11:40 PM, "Harbs" <[email protected]> wrote:
    >> 
    >>   Well, with font parsing there are SOOO MANY different data structures 
that it’s almost impossible to avoid using Object. Even if it was possible 
(which I’m not sure of), it’ll probably take me weeks or months and countless 
classes (with all the memory penalties of doing so) to cover all the types.
    >> 
    >>   I’m going to try and add a compiler option to output bracket notation 
for Object types to deal with the renaming issue of using Objects.
    >> 
    >>   Harbs
    >> 
    >>> On May 2, 2018, at 9:36 AM, Alex Harui <[email protected]> wrote:
    >>> 
    >>> Hmm.  That's what you get for using Object __
    >>> 
    >>> The code expects the expression for the initial value to resolve to a 
definition (so we know if we need to coerce it), but once you switch to Object, 
it won't resolve.  In this case,we don't know the type of "offsets".   The 
quick fix is to just accept that it might not resolve and just let the browser 
deal with it.  However, we don't know what the Google Closure optimizer will do 
with the "offsets" property.  It may or may not rename it.  I keep thinking we 
should be warning when folks use Object.  In Royale you are asking for 
optimizer trouble if you are not completely strongly-typed.
    >>> 
    >>> Thoughts?
    >>> -Alex
    >>> 
    >>> On 5/1/18, 11:19 PM, "Harbs" <[email protected]> wrote:
    >>> 
    >>>  FYI, I just tried reverting some changes, and it seems that not all 
the errors were due to void 0:
    >>>  This code:
    >>>                         var glyfPos:int = 
this._font.getTable('loca').offsets[this.id];
    >>>                         var nextPos:int = 
this._font.getTable('loca').offsets[this.id + 1];
    >>> 
    >>>  Causes this error:
    >>> 
    >>>       [java]    at 
org.apache.royale.compiler.internal.codegen.js.jx.VarDeclarationEmitter.emit(VarDeclarationEmitter.java:153)
    >>>       [java]    at 
org.apache.royale.compiler.internal.codegen.js.royale.JSRoyaleEmitter.emitVarDeclaration(JSRoyaleEmitter.java:699)
    >>>       [java]    at 
org.apache.royale.compiler.internal.codegen.as.ASBlockWalker.visitVariable(ASBlockWalker.java:278)
    >>>       [java]    at 
org.apache.royale.compiler.internal.visitor.as.ASNodeSwitch.handle(ASNodeSwitch.java:162)
    >>>       [java]    at 
org.apache.royale.compiler.internal.visitor.as.ASNodeHandler.handle(ASNodeHandler.java:85)
    >>>       [java]    at 
org.apache.royale.compiler.internal.visitor.as.BeforeAfterStrategy.handle(BeforeAfterStrategy.java:110)
    >>>       [java]    at 
org.apache.royale.compiler.internal.codegen.as.ASBlockWalker.walk(ASBlockWalker.java:159)
    >>>       [java]    at 
org.apache.royale.compiler.internal.codegen.js.jx.StatementEmitter.emit(StatementEmitter.java:40)
    >>>       [java]    at 
org.apache.royale.compiler.internal.codegen.js.jx.StatementEmitter.emit(StatementEmitter.java:29)
    >>>       [java]    at 
org.apache.royale.compiler.internal.codegen.js.JSEmitter.emitStatement(JSEmitter.java:323)
    >>>       [java]    at 
org.apache.royale.compiler.internal.codegen.js.royale.JSRoyaleEmitter.emitStatement(JSRoyaleEmitter.java:987)
    >>>       [java]    at 
org.apache.royale.compiler.internal.codegen.as.ASBlockWalker.visitBlock(ASBlockWalker.java:349)
    >>>       [java]    at 
org.apache.royale.compiler.internal.visitor.as.ASNodeSwitch.handle(ASNodeSwitch.java:278)
    >>>       [java]    at 
org.apache.royale.compiler.internal.visitor.as.ASNodeHandler.handle(ASNodeHandler.java:85)
    >>>       [java]    at 
org.apache.royale.compiler.internal.visitor.as.BeforeAfterStrategy.handle(BeforeAfterStrategy.java:110)
    >>>       [java]    at 
org.apache.royale.compiler.internal.codegen.as.ASBlockWalker.walk(ASBlockWalker.java:159)
    >>>       [java]    at 
org.apache.royale.compiler.internal.codegen.as.ASEmitter.emitMethodScope(ASEmitter.java:867)
    >>>       [java]    at 
org.apache.royale.compiler.internal.codegen.js.jx.MethodEmitter.emit(MethodEmitter.java:145)
    >>>       [java]    at 
org.apache.royale.compiler.internal.codegen.js.royale.JSRoyaleEmitter.emitMethod(JSRoyaleEmitter.java:723)
    >>>       [java]    at 
org.apache.royale.compiler.internal.codegen.js.jx.ClassEmitter.emit(ClassEmitter.java:176)
    >>>       [java]    at 
org.apache.royale.compiler.internal.codegen.js.royale.JSRoyaleEmitter.emitClass(JSRoyaleEmitter.java:681)
    >>>       [java]    at 
org.apache.royale.compiler.internal.codegen.as.ASBlockWalker.visitClass(ASBlockWalker.java:256)
    >>>       [java]    at 
org.apache.royale.compiler.internal.visitor.as.ASNodeSwitch.handle(ASNodeSwitch.java:136)
    >>>       [java]    at 
org.apache.royale.compiler.internal.visitor.as.ASNodeHandler.handle(ASNodeHandler.java:85)
    >>>       [java]    at 
org.apache.royale.compiler.internal.visitor.as.BeforeAfterStrategy.handle(BeforeAfterStrategy.java:110)
    >>>       [java]    at 
org.apache.royale.compiler.internal.codegen.as.ASBlockWalker.walk(ASBlockWalker.java:159)
    >>>       [java]    at 
org.apache.royale.compiler.internal.codegen.js.goog.JSGoogEmitter.emitPackageContents(JSGoogEmitter.java:182)
    >>>       [java]    at 
org.apache.royale.compiler.internal.codegen.as.ASBlockWalker.visitPackage(ASBlockWalker.java:244)
    >>>       [java]    at 
org.apache.royale.compiler.internal.visitor.as.ASNodeSwitch.handle(ASNodeSwitch.java:132)
    >>>       [java]    at 
org.apache.royale.compiler.internal.visitor.as.ASNodeHandler.handle(ASNodeHandler.java:85)
    >>>       [java]    at 
org.apache.royale.compiler.internal.visitor.as.BeforeAfterStrategy.handle(BeforeAfterStrategy.java:110)
    >>>       [java]    at 
org.apache.royale.compiler.internal.codegen.as.ASBlockWalker.walk(ASBlockWalker.java:159)
    >>>       [java]    at 
org.apache.royale.compiler.internal.codegen.as.ASBlockWalker.visitFile(ASBlockWalker.java:223)
    >>>       [java]    at 
org.apache.royale.compiler.internal.visitor.as.ASNodeSwitch.handle(ASNodeSwitch.java:128)
    >>>       [java]    at 
org.apache.royale.compiler.internal.visitor.as.ASNodeHandler.handle(ASNodeHandler.java:85)
    >>>       [java]    at 
org.apache.royale.compiler.internal.visitor.as.BeforeAfterStrategy.handle(BeforeAfterStrategy.java:110)
    >>>       [java]    at 
org.apache.royale.compiler.internal.codegen.as.ASBlockWalker.walk(ASBlockWalker.java:159)
    >>>       [java]    at 
org.apache.royale.compiler.internal.codegen.as.ASBlockWalker.visitCompilationUnit(ASBlockWalker.java:188)
    >>>       [java]    at 
org.apache.royale.compiler.internal.codegen.js.JSWriter.writeTo(JSWriter.java:98)
    >>>       [java]    at 
org.apache.royale.compiler.internal.codegen.js.JSWriter.writeTo(JSWriter.java:82)
    >>>       [java]    at 
org.apache.royale.compiler.clients.COMPJSCRoyale.compile(COMPJSCRoyale.java:308)
    >>>       [java]    at 
org.apache.royale.compiler.clients.MXMLJSCRoyale._mainNoExit(MXMLJSCRoyale.java:240)
    >>>       [java]    at 
org.apache.royale.compiler.clients.MXMLJSCRoyale.mainNoExit(MXMLJSCRoyale.java:197)
    >>>       [java]    at 
org.apache.royale.compiler.clients.COMPJSC._mainNoExit(COMPJSC.java:210)
    >>>       [java]    at 
org.apache.royale.compiler.clients.COMPJSC.mainNoExit(COMPJSC.java:140)
    >>>       [java]    at 
org.apache.royale.compiler.clients.COMPJSC.staticMainNoExit(COMPJSC.java:125)
    >>>       [java]    at 
org.apache.royale.compiler.clients.COMPJSC.main(COMPJSC.java:108)
    >>> 
    >>>  this._font is typed to a class instance
    >>>  getTable() returns an Object type.
    >>> 
    >>>  Changing the code to the following makes the error go away:
    >>> 
    >>>                         var glyfPos:int = 
(this._font.getTable('loca').offsets[this.id] as int);
    >>>                         var nextPos:int = 
(this._font.getTable('loca').offsets[this.id + 1] as int);
    >>> 
    >>>  Harbs
    >>> 
    >>>> On May 1, 2018, at 7:35 PM, Harbs <[email protected]> wrote:
    >>>> 
    >>>> I just finished resolving all my errors. It was hard to trace them 
down, but I just discovered that there were uses of "void 0" in the code. I 
replaced all those cases with “undefined" and poof! All my errors went away! :-)
    >>> 
    >>> 
    >>> 
    >> 
    >> 
    >> 
    > 
    > 
    > 
    
    

Reply via email to