Skip to content

Commit 7068a04

Browse files
committed
[[ LCB Machine ]] Add local variable names to module struct.
Variable names are now encoded in the handler definition - this allows better error reporting. Ideally this information would be present in a sideline 'debug info' section, so this is a stop-gap.
1 parent d871a23 commit 7068a04

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

libscript/src/script-builder.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1223,14 +1223,16 @@ void MCScriptAddVariableToHandlerInModule(MCScriptModuleBuilderRef self, MCNameR
12231223
MCScriptHandlerDefinition *t_handler;
12241224
t_handler = static_cast<MCScriptHandlerDefinition *>(self -> module . definitions[self -> current_handler]);
12251225

1226-
if (!MCMemoryResizeArray(t_handler -> local_type_count + 1, t_handler -> local_types, t_handler -> local_type_count))
1226+
if (!MCMemoryResizeArray(t_handler -> local_type_count + 1, t_handler -> local_types, t_handler -> local_type_count) ||
1227+
!MCMemoryResizeArray(t_handler -> local_name_count + 1, t_handler -> local_names, t_handler -> local_name_count))
12271228
{
12281229
r_index = 0;
12291230
self -> valid = false;
12301231
return;
12311232
}
12321233

12331234
t_handler -> local_types[t_handler -> local_type_count - 1] = p_type;
1235+
t_handler -> local_names[t_handler -> local_name_count - 1] = MCValueRetain(p_name);
12341236

12351237
r_index = self -> current_param_count + t_handler -> local_type_count - 1;
12361238
}

libscript/src/script-module.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ MC_PICKLE_END_RECORD()
129129
MC_PICKLE_BEGIN_RECORD(MCScriptHandlerDefinition)
130130
MC_PICKLE_UINDEX(type)
131131
MC_PICKLE_ARRAY_OF_UINDEX(local_types, local_type_count)
132+
MC_PICKLE_ARRAY_OF_NAMEREF(local_names, local_name_count)
132133
MC_PICKLE_UINDEX(start_address)
133134
MC_PICKLE_UINDEX(finish_address)
134135
MC_PICKLE_END_RECORD()
@@ -891,9 +892,13 @@ MCNameRef MCScriptGetNameOfLocalVariableInModule(MCScriptModuleRef self, MCScrip
891892
MCScriptHandlerDefinition *t_handler;
892893
t_handler = static_cast<MCScriptHandlerDefinition *>(p_definition);
893894

894-
// TODO - variable names
895+
MCScriptHandlerType *t_type;
896+
t_type = static_cast<MCScriptHandlerType *>(self -> types[t_handler -> type]);
895897

896-
return kMCEmptyName;
898+
if (p_index < t_type -> parameter_name_count)
899+
return t_type -> parameter_names[p_index];
900+
901+
return t_handler -> local_names[p_index - t_type -> parameter_name_count];
897902
}
898903

899904
MCNameRef MCScriptGetNameOfGlobalVariableInModule(MCScriptModuleRef self, uindex_t p_index)

libscript/src/script-private.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ struct MCScriptHandlerDefinition: public MCScriptCommonHandlerDefinition
260260
uindex_t *local_types;
261261
uindex_t local_type_count;
262262

263+
MCNameRef *local_names;
264+
uindex_t local_name_count;
265+
263266
uindex_t start_address;
264267
uindex_t finish_address;
265268

0 commit comments

Comments
 (0)