Skip to content

Commit 8fb991d

Browse files
committed
[[ LCB Builder ]] Explain arg count variants of Fetch, Store and Return opcodes.
1 parent 3799ae5 commit 8fb991d

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

libscript/src/script-builder.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,6 +1326,8 @@ void MCScriptEmitReturnUndefinedInModule(MCScriptModuleBuilderRef self)
13261326
if (self == nil || !self -> valid)
13271327
return;
13281328

1329+
// If the zero argument form of Return is used, then the return value is
1330+
// taken to be undefined.
13291331
__emit_instruction(self, kMCScriptBytecodeOpReturn, 0);
13301332
}
13311333

@@ -1370,21 +1372,27 @@ void MCScriptEmitFetchInModule(MCScriptModuleBuilderRef self, uindex_t p_dst_reg
13701372
if (self == nil || !self -> valid)
13711373
return;
13721374

1375+
// To Fetch from level 0, the 2 argument variant must be used.
1376+
// To Fetch from level n > 0, the 3 argument variant must be used with the third
1377+
// argument level - 1.
13731378
if (p_level == 0)
13741379
__emit_instruction(self, kMCScriptBytecodeOpFetch, 2, p_dst_reg, p_index);
13751380
else
1376-
__emit_instruction(self, kMCScriptBytecodeOpFetch, 3, p_dst_reg, p_index, p_level);
1381+
__emit_instruction(self, kMCScriptBytecodeOpFetch, 3, p_dst_reg, p_index, p_level - 1);
13771382
}
13781383

13791384
void MCScriptEmitStoreInModule(MCScriptModuleBuilderRef self, uindex_t p_src_reg, uindex_t p_index, uindex_t p_level)
13801385
{
13811386
if (self == nil || !self -> valid)
13821387
return;
13831388

1389+
// To Store from level 0, the 2 argument variant must be used.
1390+
// To Store from level n > 0, the 3 argument variant must be used with the third
1391+
// argument level - 1.
13841392
if (p_level == 0)
13851393
__emit_instruction(self, kMCScriptBytecodeOpStore, 2, p_src_reg, p_index);
13861394
else
1387-
__emit_instruction(self, kMCScriptBytecodeOpStore, 3, p_src_reg, p_index, p_level);
1395+
__emit_instruction(self, kMCScriptBytecodeOpStore, 3, p_src_reg, p_index, p_level - 1);
13881396
}
13891397

13901398
void MCScriptEmitPositionInModule(MCScriptModuleBuilderRef self, MCNameRef p_file, uindex_t p_line)

0 commit comments

Comments
 (0)