Re: Compile-time text/string manipulation



randyhyde@xxxxxxxxxxxxx écrivait news:1121282066.852512.144300
@g43g2000cwa.googlegroups.com:

> For example, Rene ("Betov") has suggested using the
> operator "<s" to imply a signed less than comparison in
> a boolean expression. Though this is handled in a
> completely different way in HLA (using type coercion),
> if you're really dead-set on using this syntax, it's
> easy enough to use HLA's built-in text manipulation
> functions to do this for you. Consider the following
> macro:
>
> program main;
>
> #macro _if( _expr_ ):
> _x_,
> _leftOperand_,
> _rightOperand_,
> _pos_,
> _type_,
> _size_;
>
> ?_x_ := @string( _expr_ );
> ?_pos_ := @index( _x_, 0, "<s" );
> #if( _pos_ <> -1 )
>
> ?_leftOperand_ := @substr( _x_, 0, _pos_ - 1 );
> ?_rightOperand_ := @substr( _x_, _pos_ + 2, 10000 );
> ?_size_ := @size( @text( _leftOperand_ ));
> #if( _size_ = 1 )
>
> ?_type_ := "int8";
>
> #elseif( _size_ = 2 )
>
> ?_type_ := "int16";
>
> #elseif( _size_ = 4 )
>
> ?_type_ := "int32";
>
> #else
>
> #error( "<s only allows 8, 16, or 32-bit operands" )
> ?_type_ := "int8";
>
> #endif
> if( @text( "( type "+_type_+" "+_leftOperand_+") < " +
> _rightOperand_ ))
>
> // If you like, insert code to handle other other three signed
> // comparisons here.
>
> #else
>
> if( _expr_ )
>
> #endif
>
> #endmacro
>
>
> begin main;
>
> _if( eax <s ebx ) then
>
> neg( ecx );
>
> endif;
>
> _if( eax < ebx ) then
>
> neg( edx );
>
> endif;
>
> end main;


> HLA compiles this to the following MASM code:
>
>
> cmp eax, ebx
> jnl L7_false__hla_
> neg ecx
> L7_false__hla_:
> cmp eax, ebx
> jnb L8_false__hla_
> neg edx
> L8_false__hla_:

:))))))))))))))))))))))))))))))

Thanks for the good laugh time.

You are really a great clown.

:)

Betov.

< http://rosasm.org >



.