Beispiel #1
0
static int TrCompiler_compile_node_to_RK(VM, TrCompiler *c, TrBlock *b, TrNode *n, int reg) {
  int i;
  
  /* k value */
  if (NODE_TYPE(n) == NODE_VALUE) {
    return TrBlock_push_value(b, NODE_ARG(n, 0)) | 0x100;
    
  /* local */
  } else if (NODE_TYPE(n) == NODE_SEND && (i = TrBlock_find_local(b, NODE_ARG(NODE_ARG(n, 1), 0))) != -1) {
    return i;
  
  /* not a local, need to compile */
  } else {
    COMPILE_NODE(b, n, reg);
    return reg;
  }
  
}
Beispiel #2
0
NODE_IMPLEMENTATION(DynamicCast::node, Pointer)
{
    const Symbol* sym = NODE_THIS.argNode(0)->symbol();

    if (const Class* c0 = dynamic_cast<const Class*>(sym))
    {
	if (ClassInstance* o = NODE_ARG_OBJECT(1, ClassInstance))
	{
	    if (const Class* c1 = dynamic_cast<const Class*>(o->type()))
	    {
                if (ClassInstance* dobj = c1->dynamicCast(o, c0, true))
                {
                    NODE_RETURN(dobj);
                }
		//if (c1->isA(c0)) NODE_RETURN((Pointer)o);
	    }
	}
	else
	{
	    //
	    //	Let nil pass through
	    //

	    NODE_RETURN((Pointer)o);
	}
    }
    else if (const Interface* i = dynamic_cast<const Interface*>(sym))
    {
	if (Object* o = reinterpret_cast<Object*>(NODE_ARG(1, Pointer)))
	{
	    if (const Class* c1 = dynamic_cast<const Class*>(o->type()))
	    {
		if (c1->implementation(i))
		{
		    NODE_RETURN((Pointer)o);
		}
	    }
	}
	else
	{
	    //
	    //	Can't attempt to cast nil to an interface. Let it throw.
	    //

            //  ALLOWING --NEEDS FIXING

            NODE_RETURN(Pointer(0));
	}
    }

    throw BadDynamicCastException(NODE_THREAD);
}