void ReflectiveScriptClass::setProperty( QScriptValue& object, const QScriptString & name, uint id, const QScriptValue& value) { // std::cout << __FUNCTION__ << " " << // name.toString().toStdString() << std::endl; Node_ptr node = qscriptvalue_cast< Node_ptr >(object.data()); if (node) { // Ensure it is initialized node->check_for_initialized(); ::gsim::core::descriptor_type type = node->descriptor->get_type(); if (type == ::gsim::core::TYPE_STRUCT) { // because I am sure it is initialized if (id < node->children.size()) { fromScriptValue(value, node->children[id]); } } else if (node->descriptor->is_repeated()) { if (id < node->children.size()) { fromScriptValue(value, node->children[id]); } else if (node->descriptor->is_variable_length() && QString(name) == "length") { // length property unsigned int length = value.toUInt32(); node->descriptor->set_length(node->holder, length); // re-initialized in next access node->reset(); } } } }
void Array<T>::eval() { if (isReady()) return; this->setId(getActiveDeviceId()); data = std::shared_ptr<T>(memAlloc<T>(elements()), memFree<T>); T *ptr = data.get(); dim4 ostrs = strides(); dim4 odims = dims(); for (int w = 0; w < (int)odims[3]; w++) { dim_t offw = w * ostrs[3]; for (int z = 0; z < (int)odims[2]; z++) { dim_t offz = z * ostrs[2] + offw; for (int y = 0; y < (int)odims[1]; y++) { dim_t offy = y * ostrs[1] + offz; for (int x = 0; x < (int)odims[0]; x++) { dim_t id = x + offy; ptr[id] = *(T *)node->calc(x, y, z, w); } } } } ready = true; Node_ptr prev = node; prev->reset(); // FIXME: Replace the current node in any JIT possible trees with the new BufferNode node.reset(); }
// this finds consequetive sequences of instructions. void Node::CreateList(Instruction_list& instructions, Node_list& nodes)/*{{{*/ { Instruction_list::iterator cur = instructions.begin(); if (instructions.end() == cur) return; Instruction_list::iterator begin = cur++; while (cur != instructions.end()) { Node_ptr node; Instruction_ptr instruction = *cur; // message("%p\n", instruction->Address()); switch (instruction->Type()) { case Instruction::CONDITIONAL_JUMP: cur++; node = ConditionalJumpNode::CreateFrom(instruction, instructions.end() == cur ? INVALID_ADDR : (**cur).Address(), begin, cur); begin = cur; break; case Instruction::JUMP: cur++; node = JumpNode::CreateFrom(instruction, begin, cur); begin = cur; break; case Instruction::LABEL: case Instruction::CASE: if (begin != cur) { node.reset( new FallThroughNode(instruction->Address(), begin, cur) ); begin = cur; } cur++; // yes, increase after node creation, not before break; case Instruction::RETURN: cur++; node.reset( new ReturnNode(begin, cur) ); begin = cur; break; /* * TODO: currently call's are in the instruction list as: * AssignmentInstruction(CallExpression()) case Instruction::CALL: cur++; node.reset( new CallNode(instruction->Address(), instruction->.., begin, cur) ); begin = cur; break; */ /* case Instruction::SWITCH: cur++; node.reset( new N_WayNode(GetSwitchExpression(), begin, cur) ); begin = cur; break; */ default: cur++; break; } if (node.get()) { nodes.push_back(node); } } ConnectSuccessors(nodes); }/*}}}*/
void reset() { resetCommonFlags(); m_child->reset(); }
void reset(bool reset_off=true) { m_lhs->reset(reset_off); m_rhs->reset(reset_off); m_is_eval = false; }
void ReflectiveScriptClass::fromScriptValue( const QScriptValue& value, Node_ptr node) { // std::cout << __FUNCTION__ << std::endl; using namespace gsim::core; const descriptor_type type = node->descriptor->get_type(); node->check_for_initialized(); holder& hold = node->holder; descriptor_base const * descriptor = node->descriptor; switch(type) { case TYPE_STRUCT: { if (value.isObject()) { unsigned int count = node->descriptor->get_children_count(); // Search by name for (unsigned int i = 0; i < count; i++) { const char *childName = descriptor->get_child_name(i); QScriptValue childValue = value.property(childName); if (childValue.isValid()) fromScriptValue(childValue, node->children[i]); } } else { std::cerr << "Must be an object!" << std::endl; } } break; case TYPE_ARRAY: if (descriptor->get_slice()->get_type() == TYPE_CHAR) { const std::string str(value.toString().toStdString()); descriptor->from_string(hold, str); break; } case TYPE_SEQUENCE: { unsigned int length = descriptor->get_length(hold); unsigned int newLength = value.property("length").toUInt32(); if (descriptor->is_variable_length() && length != newLength) { descriptor->set_length(hold, newLength); node->reset(); node->check_for_initialized(); } for (unsigned int i = 0; i < newLength && i < length; i++) { fromScriptValue(value.property(i), node->children[i]); } } break; case TYPE_BOOL: hold.to_value< bool >() = value.toBool(); break; case TYPE_OCTET: hold.to_value< unsigned char >() = value.toInteger(); break; case TYPE_CHAR: hold.to_value< char >() = value.toInteger(); break; case TYPE_SHORT: hold.to_value< short >() = value.toInteger(); break; case TYPE_USHORT: hold.to_value< unsigned short >() = value.toUInt16(); break; case TYPE_LONG: hold.to_value< int32_t >() = value.toInteger(); break; case TYPE_ULONG: hold.to_value< uint32_t >() = value.toUInt32(); break; case TYPE_LONGLONG: hold.to_value< int64_t >() = value.toInteger(); break; case TYPE_ULONGLONG: hold.to_value< uint64_t >() = value.toInteger(); break; case TYPE_STRING: case TYPE_WSTRING: { const std::string str(value.toString().toStdString()); descriptor->from_string(hold, str); } break; case TYPE_ENUM: { const unsigned int count = descriptor->get_children_count(); const QString str (value.toString()); unsigned int idx = descriptor->get_child_index( str.toStdString().c_str()); if (idx < count) { core::holder tmp( descriptor->get_child_value(hold, idx)); descriptor->copy(tmp, hold); } // TODO debería devolverse excepción si se introdujo // un literal no válido. } break; case TYPE_DOUBLE: hold.to_value< double >() = value.toNumber(); break; case TYPE_FLOAT: hold.to_value< float >() = value.toNumber(); default: break; } }