gecko-dev/js2/tests/js/class.xml

82 lines
2.4 KiB
XML
Raw Normal View History

<class name="D">
<field name="f" type="Integer" />
<constructor name="D" static>
RETURN R0
</constructor>
<method name="bar" type="Void">
<parameter name="a" type="Integer"/> <!-- in R1 -->
<parameter name="b" type="Integer"/> <!-- in R2 -->
GENERIC_BINARY_OP R3, Add, R1, R2
SET_SLOT R0, 0, R3
RETURN_VOID
</method>
</class>
<class name="E" super="D">
<constructor name="E">
GET_STATIC R1, "D", 1
BIND_THIS R2, R0, R1
CALL R3, R2, () <!-- call to superclass constructor -->
RETURN R0
</constructor>
</class>
<function name="fn1" type="Void">
NEW_CLASS R2, "E"
GET_STATIC R3, "E", 1
BIND_THIS R4, R2, R3
CALL R1, R4, ()
LOAD_IMMEDIATE R2, 1
LOAD_IMMEDIATE R3, 4
GET_METHOD R4, R1, 0 <!-- virtual call to 'bar' in D -->
CALL R5, R4, (R2, R3)
GET_SLOT R2, R1, 0
LOAD_NAME R1, "print"
CALL R1, R1, (R2)
RETURN_VOID
</function>
<function name="anon_1" type="Integer">
<parameter name="b"/>
GET_CLOSURE R2, 0 <!-- acquire access to frame immediately below (statically) -->
GET_SLOT R3, R2, 1 <!-- closure slots referenced by index == register number -->
GENERIC_BINARY_OP R3, Add, R3, R1
RETURN R3
</function>
<function name="f" type="Integer">
<parameter name="a"/> <!-- R0 = this, R1 = a -->
NEW_CLOSURE R2, "anon_1" <!-- all functions are entered by name into the gloabl object, this is a bit hokey -->
LOAD_IMMEDIATE R3, 1
CALL R3, R2, (R3)
RETURN R3
</function>
<script>
LOAD_NAME R1, "f" <!-- demo'ing use of closures -->
LOAD_IMMEDIATE R2, 77
CALL R3, R1, (R2)
LOAD_NAME R1, "print"
CALL R1, R1, (R3)
LOAD_NAME R1, "fn1"
CALL R1, R1, ()
NEW_CLASS R2, "D"
GET_STATIC R3, "D", 1 <!-- 0'th static is __init__ -->
<!-- 1st static is D::D constructor -->
BIND_THIS R4, R2, R3
CALL R1, R4, ()
LOAD_IMMEDIATE R2, 1
LOAD_IMMEDIATE R3, 2
GET_METHOD R4, R1, 0 <!-- 0'th method is 'bar' above -->
CALL R5, R4, (R2, R3)
GET_SLOT R2, R1, 0
RETURN R2
</script>