Beispiel #1
0
static Editor
getCreateEditorView(View v, Size size)
{ Editor e;
  Int w, h;

  if ( notDefault(size) )
  { w = size->w;
    h = size->h;
  } else
    w = h = DEFAULT;

  if ( (e = newObject(ClassEditor, DEFAULT, w, h, EAV)) )
  { FontObj f;

    if ( (f = getClassVariableValueObject(v, NAME_font)) )
      send(e, NAME_font, f, EAV);

    answer(e);
  }

  fail;
}
Beispiel #2
0
static status
initialiseBlockv(Block b, int argc, Any *argv)
{ int n;

  initialiseCode((Code) b);
  assign(b, members, newObject(ClassChain, EAV));

  for(n=0; n<argc; n++)
  { if ( instanceOfObject(argv[n], ClassVar) )
    { if ( isNil(b->parameters) )
	assign(b, parameters, newObjectv(ClassCodeVector, 1, &argv[n]));
      else
	appendVector(b->parameters, 1, &argv[n]);
    } else
      break;
  }

  for( ; n < argc; n++ )
    appendChain(b->members, argv[n]);

  succeed;
}
Beispiel #3
0
Variable AVM::createNewObject(const Common::UString &name, std::vector<Variable> arguments) {
	Variable variable = getVariable(name);

	if (!variable.isFunction())
		throw Common::Exception("Object is not a function");

	if (!variable.asObject()->hasMember("prototype"))
		throw Common::Exception("Object has no prototype");

	ObjectPtr newObject(new Object(variable.asObject()->getMember("prototype").asObject().get()));
	Function *constructor = dynamic_cast<Function *>(variable.asObject().get());

	if (!constructor)
		throw Common::Exception("Constructor is not a function");

	byte counter = 1;
	if (constructor->getPreloadRootFlag()) {
		storeRegister(_variables["_root"], counter);
		counter += 1;
	}
	if (constructor->getPreloadThisFlag()) {
		storeRegister(Variable(newObject), counter);
		counter += 1;
	}
	if (constructor->getPreloadSuperFlag()) {
		storeRegister(Variable(newObject->getMember("constructor")), counter);
		counter += 1;
	}

	for (size_t i = 0; i < arguments.size(); ++i) {
		storeRegister(arguments[i], counter);
		counter += 1;
	}

	(*constructor)(*this);

	return Variable(newObject);
}
Beispiel #4
0
Something socketReadBytes(Thread *thread) {
    int connectionAddress = *(int *)stackGetThisObject(thread)->value;
    EmojicodeInteger n = unwrapInteger(stackGetVariable(0, thread));
    
    Object *bytesObject = newArray(n);
    
    size_t read = recv(connectionAddress, bytesObject->value, n, 0);
    
    if (read < 1) {
        return NOTHINGNESS;
    }
    
    stackPush(somethingObject(bytesObject), 0, 0, thread);
    
    Object *obj = newObject(CL_DATA);
    Data *data = obj->value;
    data->length = read;
    data->bytesObject = stackGetThisObject(thread);
    data->bytes = data->bytesObject->value;
    
    stackPop(thread);
    return somethingObject(obj);
}
Beispiel #5
0
std::shared_ptr<Hinge> Hinge::Spawn(std::string RigidBodyIDA, CML::Vec3 PivotPointA, CML::Vec3 AxesA,
									double BreakingThreshold,
									double Low,
									double High,
									double Softness,
									double BiasFactor,
									double RelaxationFactor,
									double MaxMotorImpulse)
{
	PhysicsManager& physicsManager = PhysicsManager::GetInstance();

	std::shared_ptr<Hinge> newObject(new Hinge());

	auto iter = Resource::RigidBodyList.find(RigidBodyIDA);
	if(iter != Resource::RigidBodyList.end())
	{
		newObject->Info.RigidBodyA = std::pair<std::string, std::weak_ptr<RigidBody>>(RigidBodyIDA, iter->second);
	}
	else
	{
		Logger::LogError("Error creating Hinge, the rigid body could not be found");
	}

	newObject->Info.PivotPointA = PivotPointA;
	newObject->Info.AxesA = AxesA;

	newObject->Info.BreakingThreshold = BreakingThreshold;
	newObject->Info.Low = Low;
	newObject->Info.High = High;
	newObject->Info.Softness = Softness;
	newObject->Info.BiasFactor = BiasFactor;
	newObject->Info.RelaxationFactor = RelaxationFactor;
	newObject->Info.MaxMotorImpulse = MaxMotorImpulse;
	newObject->Init();

	return newObject;
}
Beispiel #6
0
static void systemSystem(Thread *thread) {
    FILE *f = popen(stringToCString(thread->variable(0).object), "r");

    if (f == nullptr) {
        thread->returnNothingnessFromFunction();
        return;
    }

    size_t bufferUsedSize = 0;
    int bufferSize = 50;
    auto buffer = thread->retain(newArray(bufferSize));

    while (fgets(buffer->val<char>() + bufferUsedSize, bufferSize - (int)bufferUsedSize, f) != nullptr) {
        bufferUsedSize = strlen(buffer->val<char>());

        if (bufferSize - bufferUsedSize < 2) {
            bufferSize *= 2;
            buffer = resizeArray(buffer.unretainedPointer(), bufferSize, thread);
        }
    }

    bufferUsedSize = strlen(buffer->val<char>());

    EmojicodeInteger len = u8_strlen_l(buffer->val<char>(), bufferUsedSize);

    auto so = thread->retain(newObject(CL_STRING));
    auto *string = so->val<String>();
    string->length = len;

    Object *chars = newArray(len * sizeof(EmojicodeChar));
    string = so->val<String>();
    string->charactersObject = chars;

    u8_toucs(string->characters(), len, buffer->val<char>(), bufferUsedSize);
    thread->release(2);
    thread->returnFromFunction(so.unretainedPointer());
}
Beispiel #7
0
object_t* z_div(list_t* args) {
  object_t* a = z_nth(args,0);
  object_t* b = z_nth(args,1);
  object_t* result = newObject();
  if ((z_typeof(a) == Int && b->value->value.i == 0) || (z_typeof(a) == Float && b->value->value.f == 0)) {
    return z_exception("Division by zero.");
  }
  if(z_typeof(a) == z_typeof(b) && z_typeof(a) == Int) {
    result->value->value = (generic_value_t) (a->value->value.i / b->value->value.i);
    result->value->type = Int;
  } else if(z_typeof(a) == z_typeof(b) && z_typeof(a) == Float) {
    result->value->value = (generic_value_t) (a->value->value.f / b->value->value.f);
    result->value->type = Float;
  } else if(z_typeof(a) == Float && z_typeof(b) == Int) {
    result->value->value = (generic_value_t) (a->value->value.f / b->value->value.i);
    result->value->type = Float;
  } else if(z_typeof(a) == Int && z_typeof(b) == Float) {
    result->value->value = (generic_value_t) (a->value->value.i / b->value->value.f);
    result->value->type = Float;
  } else {
    exception("Type mismatch", a);
  }
  return result;
}
std::shared_ptr<BallSocket> BallSocket::Spawn(std::string RigidBodyIDA, CML::Vec3 PivotPointA,
											  std::string RigidBodyIDB, CML::Vec3 PivotPointB,
											  double BreakingThreshold)
{
	std::shared_ptr<BallSocket> newObject(new BallSocket());

	auto iter = Resource::RigidBodyList.find(RigidBodyIDA);
	if(iter != Resource::RigidBodyList.end())
	{
		newObject->Info.RigidBodyA = std::pair<std::string, std::weak_ptr<RigidBody>>(RigidBodyIDA, iter->second);
	}
	else
	{
		Logger::LogError("Error creating BallSocket, the rigid body could not be found");
	}

	newObject->Info.PivotPointA = PivotPointA;

	
	iter = Resource::RigidBodyList.find(RigidBodyIDB);
	if(iter != Resource::RigidBodyList.end())
	{
		newObject->Info.RigidBodyB = std::pair<std::string, std::weak_ptr<RigidBody>>(RigidBodyIDB, iter->second);
	}
	else
	{
		Logger::LogError("Error creating BallSocket, the rigid body could not be found");
	}
	newObject->Info.PivotPointB = PivotPointB;

	newObject->Info.BreakingThreshold = BreakingThreshold;

	newObject->Init();

	return newObject;
}
Beispiel #9
0
void nbObjectInit(NB_Stem *stem){
  nb_DisabledType=NbObjectType(stem,"disabled",NB_OBJECT_KIND_CONSTANT|NB_OBJECT_KIND_PERMANENT,TYPE_SPECIAL,disabledName,nbDisabledShow,NULL);
  nb_DisabledType->apicelltype=NB_TYPE_DISABLED;
  nb_Disabled=newObject(nb_DisabledType,NULL,sizeof(NB_Object));
  nb_Disabled->refcnt=(unsigned int)-1;   /* flag as perminent object */

  nb_TrueType=NbObjectType(stem,"true",NB_OBJECT_KIND_TRUE|NB_OBJECT_KIND_REAL|NB_OBJECT_KIND_CONSTANT|NB_OBJECT_KIND_PERMANENT,TYPE_SPECIAL,trueName,nbTrueShow,NULL);
  nb_TrueType->apicelltype=NB_TYPE_TRUE;
  nb_True=newObject(nb_TrueType,NULL,sizeof(NB_Real));
  nb_True->refcnt=(unsigned int)-1;    /* flag as perminent object */
  ((NB_Real *)nb_True)->value=1;

  nb_FalseType=NbObjectType(stem,"false",NB_OBJECT_KIND_FALSE|NB_OBJECT_KIND_REAL|NB_OBJECT_KIND_CONSTANT|NB_OBJECT_KIND_PERMANENT,TYPE_SPECIAL,falseName,nbFalseShow,NULL);
  nb_FalseType->apicelltype=NB_TYPE_FALSE;
  nb_False=newObject(nb_FalseType,NULL,sizeof(NB_Real));
  nb_False->refcnt=(unsigned int)-1;    /* flag as perminent object */
  ((NB_Real *)nb_False)->value=0;

  nb_UnknownType=NbObjectType(stem,"unknown",NB_OBJECT_KIND_UNKNOWN|NB_OBJECT_KIND_CONSTANT|NB_OBJECT_KIND_PERMANENT,TYPE_SPECIAL,unknownName,nbUnknownShow,NULL);
  nb_UnknownType->apicelltype=NB_TYPE_UNKNOWN;
  nb_Unknown=newObject(nb_UnknownType,NULL,sizeof(NB_Object));
  nb_Unknown->refcnt=(unsigned int)-1;    /* flag as perminent object */

  nb_UndefinedType=nbObjectType(stem,"undefined",NB_OBJECT_KIND_CONSTANT|NB_OBJECT_KIND_PERMANENT,TYPE_SPECIAL,nbUndefinedShow,NULL);
  nb_UndefinedType->apicelltype=NB_TYPE_UNDEFINED;
  nb_Undefined=newObject(nb_UndefinedType,NULL,sizeof(NB_Object));
  nb_Undefined->refcnt=(unsigned int)-1;    /* flag as perminent object */

  nb_PlaceholderType=nbObjectType(stem,"placeholder",NB_OBJECT_KIND_CONSTANT|NB_OBJECT_KIND_PERMANENT,TYPE_SPECIAL,nbPlaceholderShow,NULL);
  nb_PlaceholderType->apicelltype=NB_TYPE_PLACEHOLDER;
  nb_Placeholder=newObject(nb_PlaceholderType,NULL,sizeof(NB_Object));
  nb_Placeholder->refcnt=(unsigned int)-1;    /* flag as perminent object */

  nb_DisabledType->object.value=nb_Unknown;
  nb_UnknownType->object.value=nb_Unknown;
  nb_UndefinedType->object.value=nb_Unknown;
  nb_PlaceholderType->object.value=nb_Unknown;

  nb_TypeType=nbObjectType(stem,"type",NB_OBJECT_KIND_CONSTANT|NB_OBJECT_KIND_PERMANENT,TYPE_WELDED,nbTypeShow,NULL);
  }
Beispiel #10
0
Object::Object(QScriptEnginePrivate *eng, QScriptClassInfo *classInfo):
    Core(eng, classInfo)
{
    newObject(&publicPrototype, eng->nullValue());
}
Beispiel #11
0
ixPo newInteger(integer ix)
{
  return (ixPo)newObject(ixClass,ix);
}
Beispiel #12
0
void vm_push_obj(object *obj){
    Object* o = newObject(global_vm, OBJ_POINTER);
    o->pvalue = obj;
    o->free=delete_obj;
    push(global_vm, o);
}
Beispiel #13
0
	END_IT
	
	IT("Parses date and time strings")
		str1 = newString(strDup("3/24/1988 5:42am"));
		SHOULD_EQUAL(newDate(str1), 575185320)
		freeStr(str1);
		str2 = newString(strDup("10/11/2000   15:12:34"));
		SHOULD_EQUAL(newDate(str2), 971277154)
		freeStr(str2);
	END_IT
END_DESCRIBE

DESCRIBE(newObject, "tap_obj* newObject (datatype type, property* props)")
	IT("Creates a new object with the given type and properties")
		expression* expr = newExpressionInt(5);
		tap_obj* obj = newObject(TYPE_OBJ, newProperty("x", newTypelist(TYPE_INT), PROP_PRIVACY_PUBLIC, PROP_RANGE_LOCAL, expr));
		SHOULD_EQUAL(obj->type, TYPE_OBJ)
		SHOULD_EQUAL(strcmp(obj->props->name, "x"), 0)
		freeExpr(expr);
		freeObj(obj);
	END_IT
END_DESCRIBE

DESCRIBE(copyObject, "tap_obj* copyObject (tap_obj* obj)")
	IT("Copies the given object, copying its type and properties")
		expression* expr = newExpressionFlo(-9.8);
		tap_obj* obj1 = newObject(TYPE_OBJ, newProperty("y", newTypelist(TYPE_FLO), PROP_PRIVACY_PRIVATE, PROP_RANGE_GLOBAL, expr));
		tap_obj* obj2 = copyObject(obj1);
		SHOULD_NOT_EQUAL(obj1, obj2)
		SHOULD_EQUAL(obj1->type, obj2->type)
		SHOULD_NOT_EQUAL(obj1->props, obj2->props)
Beispiel #14
0
inline Object *hashMapObject(HashMap *hm, const MemTag memTag) {
  return newObject(hm, HashMapTag, memTag);
}
Beispiel #15
0
inline Object *doubleObject(const double d) {
  double *dMem = (double *)malloc(sizeof(*dMem));
  *dMem = d;
  return newObject(dMem, DoubleTag, Heapd);
}
Beispiel #16
0
inline Object *kvObject(Object *key, Object *value) {
  KeyValue *kv = kvStruct(key, value);
  return newObject(kv, KeyValueTag, Heapd);
}
Beispiel #17
0
object_t* z_println(list_t* args) {
  z_print(args);
  printf("\n");
  return newObject();
}
QScriptValue QDeclarativeContextScriptClass::newUrlContext(const QString &url)
{
    QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);

    return newObject(scriptEngine, this, new UrlContextData(url));
}
Beispiel #19
0
static Graphical
getDefaultArrowJoint(Joint jt)
{ answer(newObject(ClassArrow, EAV));
}
Beispiel #20
0
void pushInt(VM* vm, int intValue) {
	Object* object = newObject(vm, OBJ_INT);
	object->value = intValue;
	push(vm, object);
}
Beispiel #21
0
listPo cons(objectPo head, listPo tail) {
  return O_LIST(newObject(listClass, head, tail));
}
Beispiel #22
0
object_t* z_cond_placeholder(list_t* args) {
  return newObject();
}
Beispiel #23
0
QScriptValue QDeclarativeObjectMethodScriptClass::newMethod(QObject *object, const QDeclarativePropertyCache::Data *method)
{
    QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);

    return newObject(scriptEngine, this, new MethodData(object, *method));
}
Beispiel #24
0
inline Object *intObject(const uint64 u) {
  uint32 *uMem = (uint32 *)malloc(sizeof(*uMem));
  *uMem = u;
  return newObject(uMem, LIntTag, Heapd);
}
Beispiel #25
0
retCode connectRemote(char *where, int port,
                      ioEncoding encoding, logical waitForMe,
                      ioPo *inC, ioPo *outC) {
  int sock;
  struct sockaddr_in serv_addr;
  char *host = getHostname(where);
  struct in_addr *addr = host != NULL ? getHostIP(host, 0) : NULL;

  if (addr != NULL) {
    /* Attempt to establish links to the server */
    memset((char *) &serv_addr, 0, sizeof(serv_addr));
    serv_addr.sin_family = AF_INET;
    serv_addr.sin_addr = *addr;
    serv_addr.sin_port = htons((u_short) port);

    /* Create the socket ... */
    if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) {
      return Error;
    } else {
      ioPo conn = O_IO(newObject(sockClass, host, sock, encoding, ioREAD | ioWRITE));

      configureIo(O_FILE(conn), (waitForMe ? turnOnBlocking : turnOffBlocking));

      while (connect(sock, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) != 0) {
        switch (errno) {    //  Unix version
          case EACCES:
          case EADDRNOTAVAIL:
            outMsg(logFile, "Address %U not available", host);
            markHostUnavail(host);
            closeFile(O_IO(conn));
            return Error;
          case ECONNREFUSED:
            outMsg(logFile, "Connection to %U refused", host);
            markHostUnavail(host);
            closeFile(O_IO(conn));
            return Error;
          case ETIMEDOUT:
            outMsg(logFile, "Connection to %U timed out", host);
            markHostUnavail(host);
            closeFile(O_IO(conn));
            return Error;
          case ENETUNREACH:
            outMsg(logFile, "Network down or %U unreachable", host);
            markHostUnavail(host);
            closeFile(O_IO(conn));
            return Error;
          case EALREADY:
          case EINTR:
          case EWOULDBLOCK:
          case EINPROGRESS:
            closeFile(O_IO(conn));
            return Fail;
          default:
            outMsg(logFile, "Connection to %U refused", host);
            markHostUnavail(host);
            closeFile(O_IO(conn));
            return Error;
        }
      }

      *inC = conn;
      *outC = conn;
      return Ok;
    }
  } else {
    outMsg(logFile, "cant resolve host %U", where);
    return Error;
  }
}
Beispiel #26
0
object_t* z_print(list_t* args) {
  object_t* obj = newObject();
  object_t* o = z_first(args);
  struct atom *atom;
  if(o == NULL) {
    printf("undefined");
    return obj;
  }

  switch(o->value->type) {
    case Int:
      printf("%d", o->value->value.i);
      return obj;
    case Float:
      printf("%f", o->value->value.f);
      return obj;
    case Char:
      printf("%c", o->value->value.c);
      return obj;
    case String:
      printf("%s",o->value->value.s);
      return obj;
    case Bool:
      if(o->value->value.b) {
        printf("True");
      } else {
        printf("False");
      }
      return obj;
    case List:
      atom = o->value->value.l->head;
      printf("( ");
      while (atom != NULL) {
        object_t *l = z_list();
        z_conj(l->value->value.l, atom->value);
        z_print(l->value->value.l);
        printf(" ");
        atom = atom->next;
      }
      printf(")");
      return obj;
    case Exception:
      printf("<Exception Object>");
      return obj;
    case Function:
      if (o->value->value.function->body != NULL) {
        printf("<Function Object> ( %s ", o->value->value.function->name);
        atom = o->value->value.function->args->head;
        printf("( ");
        while (atom != NULL) {
          object_t *l = z_list();
          z_conj(l->value->value.l, atom->value);
          z_print(l->value->value.l);
          printf(" ");
          atom = atom->next;
        }
        printf(") ");
        atom = o->value->value.function->body->head;
        printf("( ");
        while (atom != NULL) {
          object_t *l = z_list();
          z_conj(l->value->value.l, atom->value);
          z_print(l->value->value.l);
          printf(" ");
          atom = atom->next;
        }
        printf(") )");
      } else {
        printf("<Native Function Object>");
      }
      return obj;
    case FunctionReference:
      printf("%s",o->value->value.s);
      return obj;
    case Symbol:
      printf("%s", o->value->value.s);
      return obj;
  }
  printf("<object> @ %d", o->id);
}
QScriptValue QDeclarativeContextScriptClass::newContext(QDeclarativeContextData *context, QObject *scopeObject)
{
    QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);

    return newObject(scriptEngine, this, new ContextData(context, scopeObject));
}
    void SerializerBase::invokeRead(Archive &ar)
    {
        Node node( "", "", 0, false );
        Node * pNode = NULL;

        if (ar.isFlagSet(Archive::NODE_ALREADY_READ))
        {
            LocalStorage & localStorage = ar.getIstream()->getLocalStorage();
            pNode = reinterpret_cast<Node *>(localStorage.getNode());
        }
        else
        {
            if ( ! ar.getIstream()->begin(node) )
                return;
            pNode = &node;
        }

        // Detect polymorphism, either through pointers or through references
        if (!ar.isFlagSet(Archive::POLYMORPHIC))
        {
            if (    ar.isFlagSet(Archive::POINTER) 
                ||  (!ar.isFlagSet(Archive::PARENT) && isDerived()))
            {
                if (pNode->type.length() > 0)
                {
                    ar.setFlag(Archive::POLYMORPHIC, true );
                    std::string derivedTypeName = pNode->type.cpp_str();
                    getSerializerPolymorphic(derivedTypeName);
                    ar.getIstream()->getLocalStorage().setNode(pNode);
                    ar.setFlag(Archive::NODE_ALREADY_READ);
                    invokeSerializerPolymorphic(ar);
                    return;
                }
            }
        }

        // May now assume that the object is not polymorphic
        UInt32 nid = pNode->id;
        bool bId = pNode->id ? true : false;
        bool bNode = pNode->ref ? false : true;
        bool bPointer = ar.isFlagSet(Archive::POINTER);
        ar.clearState();

        if (bId && bNode && bPointer)
        {
            newObject(ar);
            addToInputContext(ar.getIstream(), nid);
            serializeContents(ar);
        }
        else if ( !bId && bNode && bPointer )
        {
            newObject(ar);
            serializeContents(ar);
        }
        else if (bId && !bNode && bPointer)
        {
            queryInputContext(ar.getIstream(), nid);
            setFromId();
        }
        else if (bId && bNode && !bPointer)
        {
            addToInputContext(ar.getIstream(), nid);
            serializeContents(ar);
        }
        else if (!bId && bNode && !bPointer )
        {
            serializeContents(ar);
        }
        else if (!bId && !bNode && bPointer)
        {
            setToNull();
        }
        else if (!bId && !bNode && !bPointer)
        {
            RCF::Exception e(RCF::_RcfError_DeserializationNullPointer());
            RCF_THROW(e);
        }
        else if (bId && !bNode && !bPointer)
        {
            RCF::Exception e(RCF::_SfError_RefMismatch());
            RCF_THROW(e);
        }

        ar.getIstream()->end();
    }
QScriptValue QDeclarativeContextScriptClass::newSharedContext()
{
    QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);

    return newObject(scriptEngine, this, new ContextData());
}
Beispiel #30
0
Datei: vm.c Projekt: vangroan/gc
void pushInt(VM* vm, int value) {
    Object* obj = newObject(vm, ObjInt);
    obj->value = value;
    pushStack(vm, obj);
}