aseba-community/aseba — pull request #296 by vaussard (2014-03-24 17:03:27+00:00)
Title: compiler: Fix emit statment when using a simple variable as argument

When using

emit foo bar

with bar being a 'simple' variable (i.e. we do not need to perform
temporary memory allocations), the current intermediate tree looks
like

EmitNode(foo)
|
--- MemoryVectorNode(bar)

which is wrong, as EmitNode's child nodes should only be used when
temporary memory allocation is necessary. As a result, the bytecode
for MemoryVectorNode will be emitted, resulting in a spurious LOAD
operation:

LOAD 35
EMIT foo addr 35 size 1

This spurious LOAD can potentially currupt Aseba's stack, which in turn
can have suprising effect when happening inside a subroutine call.

The fix is simple: add the MemoryVectorNode as a child of EmitNode only
if it is a temporary memory allocation. Only in such case, the emitted
bytecode will be correct, with balanced LOAD/STORE operations.