musictheory / NilScript

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

3.0: Rethink prefixes #144

Closed iccir closed 5 years ago

iccir commented 6 years ago

The compiler currently uses $oj_c_… for classes, $oj_p_… for protocols, $oj_f_… for functions, and $oj_i_… for ivars.

This makes debugging complex, especially for ivars.

If we assume that release builds are always going to be squeezed, could we shorten/simplify the prefixes and renaming of functions for debug builds?

In any case, $oj_ should be some variant of $ns_

iccir commented 6 years ago

Here's a table showing the changes to prefixes and special variables. For most of these, $oj_ was changed to N$_.

oj NilScript Description
$oj_oj N$$_ nilscript root variable used by compiler
$oj_id N$_id Runtime global object counter
$oj_super N$_super Runtime function to obtain superclass
$oj_unused N$_unused Type checker: placeholder
$oj_$AtEachGetMember N$_atEachGetMember Codegen: @each
$oj_$AtEachTest N$_atEachTest Codegen: @each
$oj_rest N$_rest Codegen: rest parameter for TypeScript
$OJAnonymousEnum… N$_anonymousEnum… Prefix for anonymous @enum names
$oj_C_… N$_C_… Static class prefix (Typechecker only)
$oj_c_… N$_c_… Class prefix
$oj_e_… N$_e_… Enum prefix (Typechecker only)
$oj_f_… N$_f_… Method prefix
$oj_i_… N$_i_… Ivar prefix
$oj_m N$_m Instance method object passed into makeClass callback
$oj_P_… N$_P_… Static protocol prefix (Typechecker only)
$oj_p_… N$_p_… Protocol prefix
$oj_s N$_s Class method object passed into makeClass callback
$oj_t_… N$_t_… Prefix used for temporary variables
$oj_$Base N$_Base Typechecker
$oj_$Combined N$_Combined Typechecker
$oj_$Globals N$_Globals Typechecker
$oj_$id_intersection N$_IdIntersection Typechecker
$oj_$id_union N$_IdUnion Typechecker
$oj_$Runtime N$_Runtime Typechecker
$oj_$StaticBase N$_StaticBase Typechecker
$oj_$StaticCombined N$_StaticCombined Typechecker
$oj_SEL N$_Selector Typechecker

Squeezer prefixes will be defined as N$ followed by a non-_ and non-$ character. Hence, squeezer prefixes match the regexp N\$[A-Za-z0-9]+

The prefix N$$ is reserved for future use.

Regarding ivars: per #153, generated identifiers for ivars will no longer have the class name in them. This should help with debugging. We're going to add a new --simple-ivars option to further ease debugging (this will be in #153).

iccir commented 5 years ago

This is now in the 3.0 branch.