musictheory / NilScript

Objective-C-style language superset of JavaScript with a tiny, simple runtime
Other
50 stars 5 forks source link

Add ojc.symbolicate API. #122

Closed iccir closed 7 years ago

iccir commented 7 years ago

Our build script uses copy-pasted code from oj to turn an oj symbol back into the human-readable version.

Instead, ojc.symbolicate() should convert a squeezed symbol such as $oj$abc123 or an unsqueezed symbol like $oj_f_stringWithString_ into the human-ruman representation.

iccir commented 7 years ago

As documented:

Symbolication is the process of transforming an internal identifier (either squeezed or unsqueezed) into a human-readable name. This is frequently used for stack traces in crash reports.

oj 2.x adds ojc.symbolicate(str, squeezeMap) as API. This function replaces all $oj_… identifiers in a string with the human-readable name. If the optional squeezeMap parameter is provided, squeezed $oj$… identifiers are also transformed:

let ojc = require("ojc");

let a = ojc.symbolicate("$oj_c_Foo, $oj_c_Bar");                 // "Foo, Bar"
let a = ojc.symbolicate("$oj_p_TheProtocol");                    // "TheProtocol"
let b = ojc.symbolicate("Exception in $oj_f_stringWithString_"); // "Exception in stringWithString:"
let c = ojc.symbolicate("$oj_i__anIvar");                        // "_anIvar"

// Normally, the 'squeeze' property on the compiler result object would be used for squeezeMap
let squeezeMap = { "$oj$a": "$oj_f_stringWithString_" };
let e = ojc.symbolicate("Exception in $oj$a", squeezeMap); // "Exception in stringWithString:"
iccir commented 7 years ago

--include-symbols has been removed. Instead, when --squeeze is used, a squeeze property is added to the compiler results.