| 1723 | compiler * c ); |
| 1724 | |
| 1725 | static void var_parse_var_compile( VAR_PARSE_VAR const * parse, compiler * c ) |
| 1726 | { |
| 1727 | int expand_name = 0; |
| 1728 | int is_get_grist = 0; |
| 1729 | int has_modifiers = 0; |
| 1730 | /* Special case common modifiers */ |
| 1731 | if ( parse->modifiers->size == 1 ) |
| 1732 | { |
| 1733 | VAR_PARSE_GROUP * mod = dynamic_array_at( VAR_PARSE_GROUP *, parse->modifiers, 0 ); |
| 1734 | if ( mod->elems->size == 1 ) |
| 1735 | { |
| 1736 | VAR_PARSE * mod1 = dynamic_array_at( VAR_PARSE *, mod->elems, 0 ); |
| 1737 | if ( mod1->type == VAR_PARSE_TYPE_STRING ) |
| 1738 | { |
| 1739 | OBJECT * s = ( (VAR_PARSE_STRING *)mod1 )->s; |
| 1740 | if ( ! strcmp ( object_str( s ), "G" ) ) |
| 1741 | { |
| 1742 | is_get_grist = 1; |
| 1743 | } |
| 1744 | } |
| 1745 | } |
| 1746 | } |
| 1747 | /* If there are modifiers, emit them in reverse order. */ |
| 1748 | if ( parse->modifiers->size > 0 && !is_get_grist ) |
| 1749 | { |
| 1750 | int i; |
| 1751 | has_modifiers = 1; |
| 1752 | for ( i = 0; i < parse->modifiers->size; ++i ) |
| 1753 | var_parse_group_compile( dynamic_array_at( VAR_PARSE_GROUP *, |
| 1754 | parse->modifiers, parse->modifiers->size - i - 1 ), c ); |
| 1755 | } |
| 1756 | |
| 1757 | /* If there is a subscript, emit it. */ |
| 1758 | if ( parse->subscript ) |
| 1759 | var_parse_group_compile( parse->subscript, c ); |
| 1760 | |
| 1761 | /* If the variable name is empty, look it up. */ |
| 1762 | if ( parse->name->elems->size == 0 ) |
| 1763 | compile_emit( c, INSTR_PUSH_VAR, compile_emit_constant( c, |
| 1764 | constant_empty ) ); |
| 1765 | /* If the variable name does not need to be expanded, look it up. */ |
| 1766 | else if ( parse->name->elems->size == 1 && dynamic_array_at( VAR_PARSE *, |
| 1767 | parse->name->elems, 0 )->type == VAR_PARSE_TYPE_STRING ) |
| 1768 | { |
| 1769 | OBJECT * const name = ( (VAR_PARSE_STRING *)dynamic_array_at( |
| 1770 | VAR_PARSE *, parse->name->elems, 0 ) )->s; |
| 1771 | int const idx = get_argument_index( object_str( name ) ); |
| 1772 | if ( idx != -1 ) |
| 1773 | compile_emit( c, INSTR_PUSH_ARG, idx ); |
| 1774 | else |
| 1775 | compile_emit( c, INSTR_PUSH_VAR, compile_emit_constant( c, name ) ); |
| 1776 | } |
| 1777 | /* Otherwise, push the var names and use the group instruction. */ |
| 1778 | else |
| 1779 | { |
| 1780 | var_parse_group_compile( parse->name, c ); |
| 1781 | expand_name = 1; |
| 1782 | } |
no test coverage detected