Closed cm1776 closed 3 years ago
In the context of the classDeclaration()
function, classCompiler
and currentClass
are the same thing (currentClass is just a pointer to classCompiler
:
ClassCompiler classCompiler;
classCompiler.name = parser.previous;
classCompiler.enclosing = currentClass;
currentClass = &classCompiler;
So it's fine to use both, but my guess is that classCompiler is used because it's one less indirection, which might bring a tiny performance improvement. Although probably the compiler is smart enough to not make any difference.
No real reason that I recall. Some choices are just arbitrary. :)
The variable
currentClass
tracks the class declaration currently being compiled.In the
classDeclaration()
function, aclassCompiler
variable is initialized and its address is assigned to thecurrentClass
variable. Several lines of code later, we come across the following:classCompiler.hasSuperclass = true;
andif (classCompiler.hasSuperclass) { endScope(); }
Is there a specific reason for using
classCompiler
in the 2 lines of code above rather than thecurrentClass
variable? I expected the use of the later i.e.currentClass.hasSuperclass = true;
andif (currentClass.hasSuperclass) { endScope() }
Granted, in this particular case, the results seem to be the same.