예제 #1
0
void symbolTable::add(symbolOop s) {
  assert(s->is_symbol(),
         "adding something that's not a symbol to the symbol table");
  assert(s->is_old(), "all symbols should be tenured");
  int hashValue = hash((char*) s->bytes(), s->length());
  basic_add(s, hashValue);
}
예제 #2
0
void stringTable::add(stringOop s) {
  assert(s->is_string(),
         "adding something that's not a string to the string table");
  assert(s->is_old(), "all strings should be tenured");
  int32 hashValue = hash(s->bytes(),  s->length());
  basic_add(s, hashValue);
}
예제 #3
0
 // NOT RT safe
 //
 // This function can NOT be called in parallell with other functions
 void append(Vector<T> &ts){
   LOCKASSERTER_EXCLUSIVE(&lockAsserter);
   
   R_ASSERT(next_elements == NULL);
   
   for (T t : ts)
     basic_add(t);
 }
예제 #4
0
stringOop stringTable::lookup(const char* name, int32 len, bool mustAllocate) {
  int32 hashValue = hash(name, len);
  stringTableEntry* bucket = bucketFor(hashValue);
  if (bucket->is_string()) {
    if (bucket->get_string()->equals(name, len)) return bucket->get_string();
    return basic_add(name, len, hashValue, mustAllocate);
  } else {
    if (!bucket->get_link())
      return basic_add(name, len, hashValue, mustAllocate);
    for (stringTableLink* l = bucket->get_link(); l; l = l->next) {
      if (l->string->equals(name, len)) {
        return l->string;
      }
    }    
  }
  return basic_add(name, len, hashValue, mustAllocate);
}
예제 #5
0
symbolOop symbolTable::lookup(char* name, int len) {
  int hashValue = hash(name, len);
  symbolTableEntry* bucket = bucketFor(hashValue);
  if (!bucket->is_empty()) {
    if (bucket->is_symbol()) {
      if (bucket->get_symbol()->equals(name, len)) return bucket->get_symbol();
    } else {
      for (symbolTableLink* l = bucket->get_link(); l; l = l->next)
	if (l->symbol->equals(name, len)) return l->symbol;
    }
  }
  return basic_add(name, len, hashValue);
}
예제 #6
0
  // Only RT safe if ensure_there_is_room_for_one_more_without_having_to_allocate_memory is called first.
  //
  // This function can NOT be called in parallell with other functions
  void add(T t){
    LOCKASSERTER_EXCLUSIVE(&lockAsserter);
    
    if (next_elements == NULL) {

      basic_add(t);
      
    } else {

      num_elements++;

      R_ASSERT(num_elements <= next_num_elements_max);
      
      free(elements);
      
      elements = next_elements;
      num_elements_max = next_num_elements_max;
      
      next_elements = NULL;
      next_num_elements_max = 0;

      elements[num_elements-1] = t;
    }
  }
예제 #7
0
symbolOop symbolTable::basic_add(char *name, int len, int hashValue) {
  symbolKlass* sk = (symbolKlass*) Universe::symbolKlassObj()->klass_part();
  symbolOop str =   sk->allocateSymbol(name, len);
  basic_add(str, hashValue);
  return str;
}
예제 #8
0
void symbolTable::add_symbol(symbolOop s) {
  basic_add(s, hash((char*) s->bytes(), s->length()));
}
예제 #9
0
stringOop stringTable::basic_add(const char *name, int32 len, int32 hashValue,
                                 bool mustAllocate) {
  stringOop str= make_string(name, len, mustAllocate);
  if (oop(str) != failedAllocationOop) basic_add(str, hashValue);
  return str; }
예제 #10
0
void test_cwrapper() {
    char* s;
    basic x, y, z;
    basic_init(x);
    basic_init(y);
    basic_init(z);
    symbol_set(x, "x");
    symbol_set(y, "y");
    symbol_set(z, "z");

    s = basic_str(x);
    printf("Symbol : %s\n", s);
    basic_str_free(s);
    basic e;
    basic_init(e);

    integer_set_ui(e, 123);
    s = basic_str(e);
    printf("Integer : %s\n", s);
    basic_str_free(s);

    integer_set_ui(e, 456);
    basic_add(e, e, x);
    basic_mul(e, e, y);
    basic_div(e, e, z);
    s = basic_str(e);
    printf("Basic : %s\n", s);
    basic_str_free(s);

    basic_diff(e, e, z);
    s = basic_str(e);
    printf("Basic : %s\n", s);
    basic_str_free(s);

    rational_set_ui(e, 100, 47);
    s = basic_str(e);

    printf("Rational : %s\n", s);
    printf("Is_a_Symbol %s: %d\n", s, is_a_Symbol(e));
    printf("Is_a_Rational %s: %d\n", s, is_a_Rational(e));
    printf("Is_a_Integer %s: %d\n", s, is_a_Integer(e));

    integer_set_ui(e, 123);
    printf("integer_get_ui 123: %lu\n", integer_get_ui(e));

    integer_set_si(e, -123);
    printf("integer_get_si -123: %ld\n", integer_get_si(e));

    mpz_t test;
    mpz_init(test);

    integer_get_mpz(test, e);
    printf("integer_get_mpz(e): %ld\n", mpz_get_ui(test));

    mpz_clear(test);
    basic_free(e);
    basic_free(x);
    basic_free(y);
    basic_free(z);
    basic_str_free(s);
}
예제 #11
0
VALUE check_sympify(VALUE operand2, basic_struct *cbasic_operand2)
{

    basic_struct *temp;
    VALUE a, b;
    double f;

    switch (TYPE(operand2)) {
        case T_FIXNUM:
        case T_BIGNUM:
            get_symintfromval(operand2, cbasic_operand2);
            break;

        case T_FLOAT:
            f = RFLOAT_VALUE(operand2);
            real_double_set_d(cbasic_operand2, f);
            break;

        case T_RATIONAL:
            a = rb_funcall(operand2, rb_intern("numerator"), 0, NULL);
            b = rb_funcall(operand2, rb_intern("denominator"), 0, NULL);

            basic num_basic, den_basic;
            basic_new_stack(num_basic);
            basic_new_stack(den_basic);

            get_symintfromval(a, num_basic);
            get_symintfromval(b, den_basic);

            rational_set(cbasic_operand2, num_basic, den_basic);

            basic_free_stack(num_basic);
            basic_free_stack(den_basic);
            break;

        case T_COMPLEX:
            a = rb_funcall(operand2, rb_intern("real"), 0, NULL);
            b = rb_funcall(operand2, rb_intern("imaginary"), 0, NULL);

            basic real_basic;
            basic imag_basic;

            basic_new_stack(real_basic);
            basic_new_stack(imag_basic);

            sympify(a, real_basic);
            sympify(b, imag_basic);

            basic_const_I(cbasic_operand2);
            basic_mul(cbasic_operand2, cbasic_operand2, imag_basic);
            basic_add(cbasic_operand2, cbasic_operand2, real_basic);

            basic_free_stack(real_basic);
            basic_free_stack(imag_basic);

            break;

        case T_DATA:
            if (rb_obj_is_kind_of(operand2, c_basic)) {
                Data_Get_Struct(operand2, basic_struct, temp);
                basic_assign(cbasic_operand2, temp);
                break;
            }
#ifdef HAVE_SYMENGINE_MPFR
            if (strcmp(rb_obj_classname(operand2), "BigDecimal") == 0) {
                const char *c;
                c = RSTRING_PTR(rb_funcall(operand2, rb_intern("to_s"), 1,
                                           rb_str_new2("F")));
                real_mpfr_set_str(cbasic_operand2, c, 200);
                break;
            }
#endif // HAVE_SYMENGINE_MPFR
        default:
            return Qfalse;
    }
    return Qtrue;
}