Ejemplo n.º 1
0
  SExpr* SPrimScope::tryTypeCheck() {
    // for inlined prims, try to see if primitive will always fail
    if (!InlinePrimitives) return NULL;
    
    bool fail = false;
    switch (pd->type()) {
     case NotReallyAPrimitive:
     case InternalPrimitive:
      fatal("cannot call an internal primitive from Self code");
      return NULL;
     case IntComparisonPrimitive:
     case IntArithmeticPrimitive:
      // must have two smis
      fail = CHECK_INT(receiver) || CHECK_INT(args->last());
      break;

     case FloatArithmeticPrimitive:
     case FloatComparisonPrimitive:
      // must have two floats
      fail = CHECK_FLOAT(receiver) || CHECK_FLOAT(args->last());
      break;
      
     case AtPrimitive:
     case AtPutPrimitive:
      // must have array rcvr and smi arg
      fail = TYPECHECK(receiver, is_objVector()) || CHECK_INT(args->last());
      break;
     case SizePrimitive:
      // must have array rcvr
      fail = TYPECHECK(receiver, is_objVector());
      break;

     case ByteAtPutPrimitive:
      // stored value must be 0..255; for now, test only for integer
      fail = CHECK_INT(args->nth(0));
      // fall through
     case ByteAtPrimitive:
      // must have array rcvr and smi arg
      fail |= TYPECHECK(receiver, is_byteVector()) || CHECK_INT(args->last());
      break;
     case ByteSizePrimitive:
      // must have array rcvr
      fail = TYPECHECK(receiver, is_byteVector());
      break;

     default:
      return NULL;          
    }
    
    if (fail) {
      // primitive will always fail
      ConstPReg* error = new_ConstPReg(_sender, VMString[BADTYPEERROR]);
      Node* dummy;
      MergeNode* mdummy = NULL;
      return genPrimFailure(NULL, error, dummy, mdummy, resultPR, false);
    } else {
      return NULL;
    }
  }
Ejemplo n.º 2
0
void get_print_string(oop_t x, char* s, int size) {
  // toto unimplemented incomplete -- dmu 1/06
  switch (tag(x)) {
    default: fatal("???");
    case float_tag:  sprintf(s, "a float 0x%x", x);                return;
    case   smi_tag:  sprintf(s, "a smi %d", value_of_smiOop(x));   return;
    case  mark_tag:  sprintf(s, "a markOop 0x%x", x);              return;
    case   mem_tag:  break;
  }
  if (size < length_of_C_string(s))  fatal("string overflow");
  size -= length_of_C_string(s);
  if (is_byteVector(x)) {
    ByteVectorObj::from(x)->copy_to_C_string(s, size);
  }
  else if (is_method(x)) {
   printf_and_flush("object vector printing not implemented\n");
//  }else if (is_blockMethod(x)) {
//   printf_and_flush("block method printing not implemented\n");
  } else if (is_block(x)) {
   printf_and_flush("block printing not implemented\n");
  } else if (is_objVector(x)) {
    smi id =  Object_Table::index_for_oop(x);
    ObjVectorObj* x_ov = ObjVectorObj::from(x);
    printf_and_flush("object vector [ID: %d, size: %d], contents:\n", id , x_ov->indexableSize());
    //x_ov->print();
    printf_and_flush("done contents [ID: %d].\n", id);
  } else {
    printf_and_flush("printing not implemented for ??? object type\n");
  }
   
  
  if (size < length_of_C_string(s))  fatal("string overflow");
}
Ejemplo n.º 3
0
oop_t string_canonicalize_prim (oop_t rcvr, oop_t* argsp, oop_t current_activation, oop_t* new_actp) {
    if (!is_byteVector(rcvr))
        return primitive_fail_string(BADTYPEERROR);

    ByteVectorObj* bv = ByteVectorObj::from(rcvr);
    return StringObj::intern(bv->bytes(), bv->indexableSize());
}
Ejemplo n.º 4
0
oop_t string_print_prim (oop_t rcvr, oop_t* argsp, oop_t current_activation, oop_t* new_actp) {
    if (!is_byteVector(rcvr))
        return primitive_fail_string(BADTYPEERROR);

    ByteVectorObj::from(rcvr)->string_print();
    return rcvr;
}
Ejemplo n.º 5
0
oop_t MemObj::clone(MemObj** addrp) {
  if (is_byteVector()) {
    untested("calling regular clone() on a byte vector");
    ByteVectorObj* this_bv = (ByteVectorObj*) this;
    return this_bv->clone_and_resize(this_bv->indexableSize(), 0, (ByteVectorObj**)addrp);
  }
  
  return clone_oops_and_allocate_bytes(total_size_in_oops(), NO_BYTES_PART, addrp);
}
Ejemplo n.º 6
0
fint MemObj::total_size_in_oops() {
  if (is_activation()) {
    return ((ActivationObj*)this)->total_size_in_oops();
  } else if (is_byteVector()) {
    return ((ByteVectorObj*)this)->total_size_in_oops();
  } else {
    oop_t* start = (oop_t*)this;
    oop_t*   end = start;
    while ( !is_mark(*++end) ) {}
    return end - start;
  }
}
Ejemplo n.º 7
0
fint Lookup::argCountForLookupError(oop_t selector, fint perform_arg_count, LookupType lookupType) {
  fint argc;

  if (isPerformLookupType(lookupType)) {
    assert(perform_arg_count >= 0); // should have a static selector or a perform arg count
    argc = perform_arg_count;
  } else {
    assert(is_byteVector(selector)); // should be a string if static
    argc = ByteVectorObj::from(selector)->arg_count();
  }
  assert(argc >= 0 && argc < MAX_ARGS);
  return argc;
}