refactor: extract duplicate isLocalName into shared inline wrenIsLocalName in wren_vm.h
This commit is contained in:
Vendored
+1
-8
@@ -2201,13 +2201,6 @@ static void staticField(Compiler* compiler, bool canAssign)
|
|||||||
bareName(compiler, canAssign, variable);
|
bareName(compiler, canAssign, variable);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns `true` if [name] is a local variable name (starts with a lowercase
|
|
||||||
// letter).
|
|
||||||
static bool isLocalName(const char* name)
|
|
||||||
{
|
|
||||||
return name[0] >= 'a' && name[0] <= 'z';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Compiles a variable name or method call with an implicit receiver.
|
// Compiles a variable name or method call with an implicit receiver.
|
||||||
static void name(Compiler* compiler, bool canAssign)
|
static void name(Compiler* compiler, bool canAssign)
|
||||||
{
|
{
|
||||||
@@ -2231,7 +2224,7 @@ static void name(Compiler* compiler, bool canAssign)
|
|||||||
|
|
||||||
// If we're inside a method and the name is lowercase, treat it as a method
|
// If we're inside a method and the name is lowercase, treat it as a method
|
||||||
// on this.
|
// on this.
|
||||||
if (isLocalName(token->start) && getEnclosingClass(compiler) != NULL)
|
if (wrenIsLocalName(token->start) && getEnclosingClass(compiler) != NULL)
|
||||||
{
|
{
|
||||||
loadThis(compiler);
|
loadThis(compiler);
|
||||||
namedCall(compiler, canAssign, CODE_CALL_0);
|
namedCall(compiler, canAssign, CODE_CALL_0);
|
||||||
|
|||||||
Vendored
+1
-8
@@ -1498,13 +1498,6 @@ int wrenDeclareVariable(WrenVM* vm, ObjModule* module, const char* name,
|
|||||||
return wrenSymbolTableAdd(vm, &module->variableNames, name, length);
|
return wrenSymbolTableAdd(vm, &module->variableNames, name, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns `true` if [name] is a local variable name (starts with a lowercase
|
|
||||||
// letter).
|
|
||||||
static bool isLocalName(const char* name)
|
|
||||||
{
|
|
||||||
return name[0] >= 'a' && name[0] <= 'z';
|
|
||||||
}
|
|
||||||
|
|
||||||
int wrenDefineVariable(WrenVM* vm, ObjModule* module, const char* name,
|
int wrenDefineVariable(WrenVM* vm, ObjModule* module, const char* name,
|
||||||
size_t length, Value value, int* line)
|
size_t length, Value value, int* line)
|
||||||
{
|
{
|
||||||
@@ -1530,7 +1523,7 @@ int wrenDefineVariable(WrenVM* vm, ObjModule* module, const char* name,
|
|||||||
|
|
||||||
// If this was a localname we want to error if it was
|
// If this was a localname we want to error if it was
|
||||||
// referenced before this definition.
|
// referenced before this definition.
|
||||||
if (isLocalName(name)) symbol = -3;
|
if (wrenIsLocalName(name)) symbol = -3;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Vendored
+7
@@ -236,4 +236,11 @@ static inline ObjClass* wrenGetClassInline(WrenVM* vm, Value value)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns `true` if [name] is a local variable name (starts with a lowercase
|
||||||
|
// letter).
|
||||||
|
static inline bool wrenIsLocalName(const char* name)
|
||||||
|
{
|
||||||
|
return name[0] >= 'a' && name[0] <= 'z';
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user