<?xml version="1.0"?>
<swf version="6" compressed="0">

<!--

 Test file for https://savannah.gnu.org/bugs/?33521

 Shows that functions keep a reference on the constant
 pool in place at time of their definition, even if
 the pool in the action buffer is overridden at time
 of function call.

 This file uses anonymous function, see func_dict.xml 
 for a named function.

-->

  <Header framerate="12" frames="1">
    <size>
      <Rectangle left="0" right="12800" top="0" bottom="9600"/>
    </size>
    <tags>
      <DoAction>
        <actions>

	<!-- Dictionary at time of function definition -->
          <Dictionary>
            <strings>
              <String value="a"/>
            </strings>
          </Dictionary>

	<!-- Name we'll assign to the function -->
          <PushData>
            <items>
              <StackString value="f"/>
            </items>
          </PushData>

	<!-- Function code -->
          <DeclareFunction name="" argc="0" length="15">
            <args/>
          </DeclareFunction>
          <PushData>
            <items>
              <StackString value="r"/>
            </items>
          </PushData>
          <Duplicate/>
          <GetVariable/>
          <PushData>
            <items>
              <StackDictionaryLookup index="0"/>
            </items>
          </PushData>
          <AddTyped/>
          <SetVariable/>

	<!-- Assigning the anonymous function to the variable `f' -->
          <SetVariable/>

	<!-- Dictionary after function definition -->
          <Dictionary>
            <strings>
              <String value="b"/>
            </strings>
          </Dictionary>


	<!-- Main code -->

	  // Append dict[0] to `r'
          <PushData>
            <items>
              <StackString value="r"/>
            </items>
          </PushData>
          <Duplicate/>
          <GetVariable/>
          <PushData>
            <items>
              <StackDictionaryLookup index="0"/>
            </items>
          </PushData>
          <AddTyped/>
          <SetVariable/>

	  // Call the function appending dict[0] to `r'
          <PushData>
            <items>
              <StackInteger value="0"/>
              <StackString value="f"/>
            </items>
          </PushData>
          <CallFunction/>
          <Pop/>

	  // Verify `r' equals 'ba'
          <PushData>
            <items>
              <StackString value="ba"/>
              <StackString value="r"/>
            </items>
          </PushData>
          <GetVariable/>
	  <EqualTyped/>

	  // If true, jump to PASSED tracing
	  <BranchIfTrue byteOffset="51"/>

	  // Else, trace XFAILED
          <PushData>
            <items>
              <StackString value="FAILED: func used overridden dictionary "/>
            </items>
          </PushData>
          <Trace/>
          <BranchAlways byteOffset="44"/> // get to end 

	  // PASSED tracing
          <PushData>
            <items>
              <StackString value="PASSED: func used original dictionary "/>
            </items>
          </PushData>
          <Trace/>

	  // END OF TEST tag
          <PushData>
            <items>
              <StackString value="END OF TEST"/>
            </items>
          </PushData>
          <Trace/>

          <EndAction/>
        </actions>
      </DoAction>
      <ShowFrame/>
      <End/>
    </tags>
  </Header>
</swf>
