void BasePacket::parse(PTP::ByteStream &stream) { const PARAM_NAME* ary = param_list(); for(int i = 0; ary[i]!=pnEND; i++) { Parameter* p = &(*this)[ary[i]]; p->parse(stream); } }
/* EBNF: params -> param-list | void */ static TreeNode * params (void) { TreeNode * t = NULL; while (token == COMMENT) unexpectedTokenHandling(); if (token == VOID) { t = newStmtNode (ParamK); t->type = Void; match (VOID); } else t = param_list(); return t; }
static void params() { if(token == TOK_VOID){ match(TOK_VOID); } else if( token == TOK_INT || token == TOK_CHAR || token == TOK_PINT || token == TOK_PCHAR || token == TOK_VOID || token == TOK_PVOID){ param_list(); }else{ if(token != TOK_RPAREN) fprintf(stderr, "line %d: function params error\n", save_line); } }
inline void kernel_radix(backend::source_generator &o, pow radix, bool invert) { o << in_place_dft(radix.value, invert); // kernel. o.begin_kernel("radix"); o.begin_kernel_parameters(); o.template parameter< global_ptr<const T2> >("x"); o.template parameter< global_ptr< T2> >("y"); o.template parameter< cl_uint >("p"); o.template parameter< cl_uint >("threads"); o.end_kernel_parameters(); o.new_line() << "const size_t i = " << o.global_id(0) << ";"; o.new_line() << "if(i >= threads) return;"; // index in input sequence, in 0..P-1 o.new_line() << "const size_t k = i % p;"; o.new_line() << "const size_t batch_offset = " << o.global_id(1) << " * threads * " << radix.value << ";"; // read o.new_line() << "x += i + batch_offset;"; for(size_t i = 0; i < radix.value; ++i) o.new_line() << type_name<T2>() << " v" << i << " = x[" << i << " * threads];"; // twiddle o.new_line() << "if(p != 1)"; o.open("{"); for(size_t i = 1; i < radix.value; ++i) { const T alpha = -boost::math::constants::two_pi<T>() * i / radix.value; o.new_line() << "v" << i << " = mul(v" << i << ", twiddle(" << "(" << type_name<T>() << ")" << std::setprecision(16) << alpha << " * k / p));"; } o.close("}"); // inplace DFT o.new_line() << "dft" << radix.value; param_list(o, "&", 0, radix.value); o << ";"; // write back o.new_line() << "const size_t j = k + (i - k) * " << radix.value << ";"; o.new_line() << "y += j + batch_offset;"; for(size_t i = 0; i < radix.value; i++) o.new_line() << "y[" << i << " * p] = v" << i << ";"; o.end_kernel(); }
void BasePacket::to_packet(vector<string>& ret) const { ret.assign(1, ""); const PARAM_NAME* ary = param_list(); size_t len = 0; for(int i = 0; ary[i]!=pnEND; i++) { string t; (*this)[ary[i]].to_packet(t); len += t.size(); ret.push_back(t); } string h; PTP::String::to_s((uint32_t)(8+len), h); string i; PTP::String::to_s((uint32_t)id(), i); h.append(i); ret.at(0).assign(h); }
int32_t SkUEBlueprintInterface::add_event_entry(UClass * ue_class_p, SkMethodBase * sk_method_p) { // Check if this binding already exists, and if so, just update it int32_t binding_index; if (try_update_binding_entry(ue_class_p, sk_method_p, &binding_index)) { return binding_index; } if (binding_index >= 0) { delete_binding_entry(binding_index); } // Parameters of the method we are creating const SkParameters & params = sk_method_p->get_params(); const tSkParamList & param_list = params.get_param_list(); uint32_t num_params = param_list.get_length(); // Create new UFunction ParamInfo * param_info_array_p = a_stack_allocate(num_params + 1, ParamInfo); UFunction * ue_function_p = build_ue_function(ue_class_p, sk_method_p, BindingType_Event, param_info_array_p); if (!ue_function_p) return -1; // Bind Sk method sk_method_p->set_user_data(binding_index); bind_event_method(sk_method_p); // Allocate binding entry EventEntry * event_entry_p = new(AMemory::malloc(sizeof(EventEntry) + num_params * sizeof(K2ParamEntry), "EventEntry")) EventEntry(sk_method_p, ue_function_p, num_params); // Initialize parameters for (uint32_t i = 0; i < num_params; ++i) { const SkParameterBase * input_param = param_list(i); const ParamInfo & param_info = param_info_array_p[i]; new (&event_entry_p->get_param_entry_array()[i]) K2ParamEntry(input_param->get_name(), input_param->get_expected_type(), param_info.m_sk_value_getter_p, static_cast<UProperty *>(param_info.m_ue_param_p)->GetOffset_ForUFunction()); } // Store binding entry in array return store_binding_entry(event_entry_p, binding_index); }
int32_t SkUEBlueprintInterface::add_function_entry(UClass * ue_class_p, SkInvokableBase * sk_invokable_p) { // Check if this binding already exists, and if so, just update it int32_t binding_index; if (try_update_binding_entry(ue_class_p, sk_invokable_p, &binding_index)) { return binding_index; } if (binding_index >= 0) { delete_binding_entry(binding_index); } // Parameters of the method we are creating const SkParameters & params = sk_invokable_p->get_params(); const tSkParamList & param_list = params.get_param_list(); uint32_t num_params = param_list.get_length(); // Create new UFunction ParamInfo * param_info_array_p = a_stack_allocate(num_params + 1, ParamInfo); UFunction * ue_function_p = build_ue_function(ue_class_p, sk_invokable_p, BindingType_Function, param_info_array_p); if (!ue_function_p) return -1; // Allocate binding entry FunctionEntry * function_entry_p = new(AMemory::malloc(sizeof(FunctionEntry) + num_params * sizeof(SkParamEntry), "FunctionEntry")) FunctionEntry(sk_invokable_p, ue_function_p, num_params, params.get_result_class(), param_info_array_p[num_params].m_sk_value_getter_p); // Initialize parameters for (uint32_t i = 0; i < num_params; ++i) { const SkParameterBase * input_param = param_list(i); new (&function_entry_p->get_param_entry_array()[i]) SkParamEntry(input_param->get_name(), input_param->get_expected_type(), param_info_array_p[i].m_k2_param_fetcher_p); } // Store binding entry in array binding_index = store_binding_entry(function_entry_p, binding_index); ue_function_p->RepOffset = uint16(binding_index); // Remember array index of method to call return binding_index; }
inline void kernel_radix(std::ostringstream &o, pow radix, bool invert) { o << in_place_dft(radix.value, invert); // kernel. o << "__kernel void radix(__global const real2_t *x, __global real2_t *y, uint p, uint threads) {\n" << " const size_t i = get_global_id(0);\n" << " if(i >= threads) return;\n" // index in input sequence, in 0..P-1 << " const size_t k = i % p;\n" << " const size_t batch_offset = get_global_id(1) * threads * " << radix.value << ";\n"; // read o << " x += i + batch_offset;\n"; for(size_t i = 0 ; i < radix.value ; i++) o << " real2_t v" << i << " = x[" << i << " * threads];\n"; // twiddle o << " if(p != 1) {\n"; for(size_t i = 1 ; i < radix.value ; i++) { const T alpha = -boost::math::constants::two_pi<T>() * i / radix.value; o << " v" << i << " = mul(v" << i << ", twiddle(" << "(real_t)" << alpha << " * k / p));\n"; } o << " }\n"; // inplace DFT o << " dft" << radix.value; param_list(o, "&", 0, radix.value); o << ";\n"; // write back o << " const size_t j = k + (i - k) * " << radix.value << ";\n"; o << " y += j + batch_offset;\n"; for(size_t i = 0 ; i < radix.value ; i++) o << " y[" << i << " * p] = v" << i << ";\n"; o << "}\n"; }
//--------------------------------------------------------------------------------------- // Params: // out_param_info_array_p: Storage for info on each parameter, return value is stored behind the input parameters, and is zeroed if there is no return value UFunction * SkUEBlueprintInterface::build_ue_function(UClass * ue_class_p, SkInvokableBase * sk_invokable_p, eBindingType binding_type, ParamInfo * out_param_info_array_p) { // Build name of method including scope const char * invokable_name_p = sk_invokable_p->get_name_cstr(); const char * class_name_p = sk_invokable_p->get_scope()->get_name_cstr(); AString qualified_invokable_name; qualified_invokable_name.ensure_size_buffer(uint32_t(::strlen(invokable_name_p) + ::strlen(class_name_p) + 3u)); qualified_invokable_name.append(class_name_p); qualified_invokable_name.append(" @ ", 3u); qualified_invokable_name.append(invokable_name_p); // Make UFunction object UFunction * ue_function_p = NewObject<UFunction>(ue_class_p, qualified_invokable_name.as_cstr(), RF_Public | RF_RootSet); ue_function_p->FunctionFlags |= FUNC_Public; if (sk_invokable_p->is_class_member()) { ue_function_p->FunctionFlags |= FUNC_Static; } if (binding_type == BindingType_Function) { ue_function_p->FunctionFlags |= FUNC_BlueprintCallable | FUNC_Native; ue_function_p->SetNativeFunc(sk_invokable_p->get_invoke_type() == SkInvokable_coroutine ? (Native)&SkUEBlueprintInterface::exec_coroutine : (sk_invokable_p->is_class_member() ? (Native)&SkUEBlueprintInterface::exec_class_method : (Native)&SkUEBlueprintInterface::exec_instance_method)); #if WITH_EDITOR ue_function_p->SetMetaData(TEXT("Tooltip"), *FString::Printf(TEXT("%S\n%S@%S()"), sk_invokable_p->get_invoke_type() == SkInvokable_coroutine ? "Kick off SkookumScript coroutine" : "Call to SkookumScript method", sk_invokable_p->get_scope()->get_name_cstr(), sk_invokable_p->get_name_cstr())); #endif } else // binding_type == BindingType_Event { ue_function_p->FunctionFlags |= FUNC_BlueprintEvent | FUNC_Event; ue_function_p->Bind(); // Bind to default Blueprint event mechanism #if WITH_EDITOR ue_function_p->SetMetaData(TEXT("Tooltip"), *FString::Printf(TEXT("Triggered by SkookumScript method\n%S@%S()"), sk_invokable_p->get_scope()->get_name_cstr(), sk_invokable_p->get_name_cstr())); #endif ue_function_p->RepOffset = EventMagicRepOffset; // So we can tell later this is an Sk event } #if WITH_EDITOR ue_function_p->SetMetaData(TEXT("Category"), TEXT("SkookumScript")); #endif // Parameters of the method we are creating const SkParameters & params = sk_invokable_p->get_params(); const tSkParamList & param_list = params.get_param_list(); uint32_t num_params = param_list.get_length(); // Handle return value if any if (params.get_result_class() && params.get_result_class() != SkObject::ms_class_p) { UProperty * result_param_p = build_ue_param(ue_function_p, params.get_result_class(), "result", out_param_info_array_p ? out_param_info_array_p + num_params : nullptr); if (!result_param_p) { // If any parameters can not be mapped, skip building this entire function ue_function_p->ConditionalBeginDestroy(); return nullptr; } result_param_p->PropertyFlags |= CPF_ReturnParm; // Flag as return value } else if (out_param_info_array_p) { // If there is no return value, indicate that by zeroing that entry in the param info array memset(out_param_info_array_p + num_params, 0, sizeof(*out_param_info_array_p)); } // Handle input parameters (in reverse order so they get linked into the list in proper order) for (int32_t i = num_params - 1; i >= 0; --i) { const SkParameterBase * input_param = param_list(i); if (!build_ue_param(ue_function_p, input_param->get_expected_type(), input_param->get_name_cstr(), out_param_info_array_p ? out_param_info_array_p + i : nullptr)) { // If any parameters can not be mapped, skip building this entire function ue_function_p->ConditionalBeginDestroy(); return nullptr; } } // Make method known to its class ue_class_p->LinkChild(ue_function_p); ue_class_p->AddFunctionToFunctionMap(ue_function_p); // Make sure parameter list is properly linked and offsets are set ue_function_p->StaticLink(true); return ue_function_p; }
void dec(int level) { int expType; int this_line = line_cnt; findType(this_line); id_num_check(ID, this_line); if(strcmp(tokenPos->textOfLine,";") == 0) { push(SEMI, this_line); pTreeType[this_line][0] = DEC_VAR; pTreeType[this_line][1] = level; } else if(strcmp(tokenPos->textOfLine,"[") == 0) { //교제에 있는 C-언어의 정의에서 전역변수로 배열을 정의할때 //ID [NUM]이 되기 때문에 다른 하위 Terminal로 넘어가지 않고 바로 종결. NUM만 있으면 되니. push(LSGWAL, this_line); id_num_check(NUM,this_line); if(strcmp(tokenPos->textOfLine,"]") != 0) { print_err(tokenPos->lineNum,tokenPos->textOfLine,"DEC","]",tokenPos->tokenType); } else { push(RSGWAL, this_line); } semi_check(this_line); pTreeType[this_line][0] = DEC_VAR; pTreeType[this_line][1] = level; } else if(strcmp(tokenPos->textOfLine,"(") == 0)//declare Function. { push(LGWAL, this_line); list<line>::iterator temp = tokenPos; temp++; if(strcmp(tokenPos->textOfLine,"void") == 0 && strcmp((temp)->textOfLine,")") == 0) { findType(this_line); push(RGWAL, this_line); } else { push_child(this_line,PARAM); param_list(level+1); if(strcmp(tokenPos->textOfLine,")") == 0 ) { push(RGWAL, this_line); } else { print_err(tokenPos->lineNum,tokenPos->textOfLine,"DEC",")",tokenPos->tokenType); } } pTreeType[this_line][0] = DEC_FUN; pTreeType[this_line][1] = level; push_child(this_line,COM_STMT); compound_stmt(level+1); //semi_check(this_line); } else { print_err(tokenPos->lineNum,tokenPos->textOfLine,"DEC", "( or [",tokenPos->tokenType); } }