Method: RCSimCinterface.rcsim_make_binary

Defined in:
ext/hruby_sim/hruby_rcsim_build.c

.rcsim_make_binary(type, operator, left, right) ⇒ Object

Creating a binary value C object.



771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 771

VALUE rcsim_make_binary(VALUE mod, VALUE type, VALUE operator, VALUE left, VALUE right) {
    // printf("rcsim_make_binary\n");
    /* Allocates the binary. */
    Binary binary = (Binary)malloc(sizeof(BinaryS));
    // printf("binary=%p\n",binary);
    /* Set it up. */
    binary->kind = BINARY;
    binary->owner = NULL;
    value_to_rcsim(TypeS,type,binary->type);
    switch(sym_to_char(operator)) {
        case (unsigned char)'+':         binary->oper = add_value; break;
        case (unsigned char)'-':         binary->oper = sub_value; break;
        case (unsigned char)'*':         binary->oper = mul_value; break;
        case (unsigned char)'/':         binary->oper = div_value; break;
        case (unsigned char)'%':         binary->oper = mod_value; break;
        case (unsigned char)'&':         binary->oper = and_value; break;
        case (unsigned char)'|':         binary->oper = or_value; break;
        case (unsigned char)'^':         binary->oper = xor_value; break;
        case (unsigned char)('<'+'<'*2): binary->oper = shift_left_value; break;
        case (unsigned char)('>'+'>'*2): binary->oper = shift_right_value; break;
        case (unsigned char)('='+'='*2): binary->oper = equal_value_c; break;
        case (unsigned char)('!'+'='*2): binary->oper = not_equal_value_c; break;
        case (unsigned char)'<':         binary->oper = lesser_value; break;
        case (unsigned char)('<'+'='*2): binary->oper = lesser_equal_value; break;
        case (unsigned char)'>':         binary->oper = greater_value; break;
        case (unsigned char)('>'+'='*2): binary->oper = greater_equal_value; break;
        default: perror("Invalid operator for binary.");
    }
    value_to_rcsim(ExpressionS,left,binary->left);
    value_to_rcsim(ExpressionS,right,binary->right);
    /* Returns the C binary embedded into a ruby VALUE. */
    VALUE res;
    rcsim_to_value(BinaryS,binary,res);
    return res;
}