void setup0001() { if (root == NULL) { root = new_component(0, 0, 0, TEXT_DEFAULT, COLOR_ORIGINAL, BGCOLOR_ORIGINAL, MAP_0001); sea1 = new_component(0, 7, 12, TEXT_DEFAULT, COLOR_WHITE, BGCOLOR_LIGHTBLUE, MAP_0001_SEA1); root->child = sea1; sea2 = new_component(0, 7, 12, TEXT_DEFAULT, COLOR_WHITE, BGCOLOR_LIGHTBLUE, MAP_0001_SEA2); sea1->next = sea2; } }
ComponentInstance& HomeServantBase::incarnate_component ( Components::ExecutorLocator_ptr executor_locator , CCMContext* ccm_context , const Components::ConfigValues& config) { DEBUG_OUT ("HomeServantBase: incarnate_component() (with ConfigValues) called"); ccm_context->container (this->container_); // create object reference CORBA::Object_var component_ref = this->create_primary_object_reference (this->comp_repository_id_); // create object id PortableServer::ObjectId_var object_id = this->reference_to_oid (component_ref); // create component instance and register it ComponentInstance new_component (object_id, component_ref, executor_locator, ccm_context, this); new_component.configure( config ); QedoLock lock (component_instances_mutex_); component_instances_.push_back (new_component); return component_instances_.back (); }
ComponentInstance& HomeServantBase::incarnate_component (const char* rep_id, Components::ExecutorLocator_ptr executor_locator, ExecutorContext* ccm_context) { CORBA::Object_var component_ref = this->create_primary_object_reference (rep_id); // Now do all the other stuff PortableServer::ObjectId* object_id = new PortableServer::ObjectId(); *object_id = *(this->reference_to_oid (component_ref)); ComponentInstance new_component (*object_id, component_ref, executor_locator, ccm_context, this); component_instances_.push_back (new_component); std::vector <ComponentInstance>::iterator components_iter; for (components_iter = component_instances_.begin(); components_iter != component_instances_.end(); components_iter++) { if (Qedo::compare_object_ids ((*components_iter).object_id_, *object_id)) { break; } } if (components_iter == component_instances_.end()) { NORMAL_ERR ("HomeServantBase: Fatal internal error in incarnate component(): Instance list corrupted"); assert (0); } return *components_iter; }
void compile_init(void) { compile_block = new_block(); /* Note: These definitions actually depend on those in types.h and runtime.c */ component_undefined = new_component(compile_block, c_constant, new_constant(compile_block, cst_int, 42)); component_true = new_component(compile_block, c_constant, new_constant(compile_block, cst_int, TRUE)); component_false = new_component(compile_block, c_constant, new_constant(compile_block, cst_int, FALSE)); builtin_ops[b_eq] = OPmeq; builtin_ops[b_ne] = OPmne; builtin_ops[b_lt] = OPmlt; builtin_ops[b_le] = OPmle; builtin_ops[b_gt] = OPmgt; builtin_ops[b_ge] = OPmge; builtin_ops[b_bitor] = OPmbitor; builtin_ops[b_bitxor] = OPmbitxor; builtin_ops[b_bitand] = OPmbitand; builtin_ops[b_shift_left] = OPmshiftleft; builtin_ops[b_shift_right] = OPmshiftright; builtin_ops[b_add] = OPmadd; builtin_ops[b_subtract] = OPmsub; builtin_ops[b_multiply] = OPmmultiply; builtin_ops[b_divide] = OPmdivide; builtin_ops[b_remainder] = OPmremainder; builtin_ops[b_negate] = OPmnegate; builtin_ops[b_not] = OPmnot; builtin_ops[b_bitnot] = OPmbitnot; builtin_ops[b_ref] = OPmref; builtin_ops[b_set] = OPmset; builtin_functions[b_cons] = "cons"; staticpro((value *)&last_filename); last_filename = alloc_string(""); last_c_filename = xstrdup(""); }
/******************************************************* * ARP-COLOUR-CONTROL *******************************************************/ ArpColourControl::ArpColourControl( BRect frame, const char* name, const BString16* label, float div) : inherited(frame, name, 0, 0, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_FRAME_EVENTS), mR(0), mG(0), mB(0), mA(0), mChangingMsg(0), mChangedMsg(0) { BRect f(0, 0, 0, frame.Height()); f.right = 0; if (label || div > 0) { if (div <= 0) div = StringWidth(label) + 2; f.right = div; BStringView* sv = new BStringView(f, "label", label); if (sv) AddChild(sv); // f.left = f.right + 1; } float iw = StringWidth("255") + 5; if ((mR = new_component(f, iw, "r", _R_MSG)) != 0) AddChild(mR); if ((mG = new_component(f, iw, "g", _G_MSG)) != 0) AddChild(mG); if ((mB = new_component(f, iw, "b", _B_MSG)) != 0) AddChild(mB); if ((mA = new_component(f, iw, "a", _A_MSG)) != 0) AddChild(mA); }
LOCAL COMP_TYPE *clone_elliptical_comp_type( ELLIPSOID *ellip, COMP_TYPE *ct, Front *front, INIT_PHYSICS *ip) { _ELLIPTICAL *el, *nel; COMP_TYPE *nct; INTERFACE *intfc = front->interf; int i, dim; nct = comp_type(new_component(NEW_COMP)); set_elliptical_comp_type(nct,ip); nel = Elliptical(nct); nel->ellipsoid = ellip; switch (ct->type) { case ELLIPTICAL: dim = intfc->dim; el = Elliptical(ct); nel->rstate = copy_random_state_structure(el->rstate,intfc); ft_assign(nel->state,el->state,front->sizest); ft_assign(nel->wkstate[0],el->wkstate[0],front->sizest); ft_assign(nel->wkstate[1],el->wkstate[1],front->sizest); for (i = 0; i < dim; ++i) nel->weight[i] = el->weight[i]; nel->r0 = el->r0; nel->rw1d = el->rw1d; nel->stratification_type = el->stratification_type; break; case AMBIENT: nel->rstate = NULL; set_state(nel->state,TGAS_STATE,Ambient(ct)); break; default: screen("ERROR in copy_elliptical_comp_type(), " "comp_type %s not supported\n",comp_type_name(ct->type)); clean_up(ERROR); break; } return nct; } /*end clone_elliptical_comp_type*/
/** * Code adapted from component.cpp, dataitems are unpacked in the same * order as the Component::unpack( void* ) method to maintain consistency. */ struct component * unpack_component( void *buffer ) { struct component *ret = NULL; u32 size = 0, netOrder; char *packed = (char*)buffer; char * next; struct list *item; struct dataitem *data; if( !buffer ) return ret; ret = new_component( 0 ); if( !ret ) return ret; memcpy( &netOrder, packed, sizeof( u32 ) ); size = ntohl( netOrder ); next = packed + sizeof( u32 ); ret->id = unpack_dataitem( next ); if( !ret->id ) goto unpackerr; next += calc_packed_length_dataitem( ret->id ); ret->deviceTreeNode = unpack_dataitem( next ); if( !ret->deviceTreeNode ) goto unpackerr; next += calc_packed_length_dataitem( ret->deviceTreeNode ); ret->sysFsNode = unpack_dataitem( next ); if( !ret->sysFsNode ) goto unpackerr; next += calc_packed_length_dataitem( ret->sysFsNode ); ret->sysFsLinkTarget = unpack_dataitem( next ); if( !ret->sysFsLinkTarget ) goto unpackerr; next += calc_packed_length_dataitem( ret->sysFsLinkTarget ); ret->halUDI = unpack_dataitem( next ); if( !ret->halUDI ) goto unpackerr; next += calc_packed_length_dataitem( ret->halUDI ); ret->netAddr = unpack_dataitem( next ); if( !ret->netAddr ) goto unpackerr; next += calc_packed_length_dataitem( ret->netAddr ); ret->devClass = unpack_dataitem( next ); if( !ret->devClass ) goto unpackerr; next += calc_packed_length_dataitem( ret->devClass ); ret->description = unpack_dataitem( next ); if( !ret->description ) goto unpackerr; next += calc_packed_length_dataitem( ret->description ); ret->cdField = unpack_dataitem( next ); if( !ret->cdField ) goto unpackerr; next += calc_packed_length_dataitem( ret->cdField ); ret->serialNumber = unpack_dataitem( next ); if( !ret->serialNumber ) goto unpackerr; next += calc_packed_length_dataitem( ret->serialNumber ); ret->partNumber = unpack_dataitem( next ); if( !ret->partNumber ) goto unpackerr; next += calc_packed_length_dataitem( ret->partNumber ); ret->firmwareLevel = unpack_dataitem( next ); if( !ret->firmwareLevel ) goto unpackerr; next += calc_packed_length_dataitem( ret->firmwareLevel ); ret->firmwareVersion = unpack_dataitem( next ); if( !ret->firmwareVersion ) goto unpackerr; next += calc_packed_length_dataitem( ret->firmwareVersion ); ret->fru = unpack_dataitem( next ); if( !ret->fru ) goto unpackerr; next += calc_packed_length_dataitem( ret->fru ); ret->manufacturer = unpack_dataitem( next ); if( !ret->manufacturer ) goto unpackerr; next += calc_packed_length_dataitem( ret->manufacturer ); ret->model = unpack_dataitem( next ); if( !ret->model ) goto unpackerr; next += calc_packed_length_dataitem( ret->model ); ret->manufacturerID = unpack_dataitem( next ); if( !ret->manufacturerID ) goto unpackerr; next += calc_packed_length_dataitem( ret->manufacturerID ); ret->engChangeLevel = unpack_dataitem( next ); if( !ret->engChangeLevel ) goto unpackerr; next += calc_packed_length_dataitem( ret->engChangeLevel ); ret->parent = unpack_dataitem( next ); if( !ret->parent ) goto unpackerr; next += calc_packed_length_dataitem( ret->parent ); ret->devSubSystem = unpack_dataitem( next ); if( !ret->devSubSystem ) goto unpackerr; next += calc_packed_length_dataitem( ret->devSubSystem ); ret->devDriver = unpack_dataitem( next ); if( !ret->devDriver ) goto unpackerr; next += calc_packed_length_dataitem( ret->devDriver ); ret->devKernel = unpack_dataitem( next ); if( !ret->devKernel ) goto unpackerr; next += calc_packed_length_dataitem( ret->devKernel ); ret->devKernelNumber = unpack_dataitem( next ); if( !ret->devKernelNumber ) goto unpackerr; next += calc_packed_length_dataitem( ret->devKernelNumber ); ret->devSysName = unpack_dataitem( next ); if( !ret->devSysName ) goto unpackerr; next += calc_packed_length_dataitem( ret->devSysName ); ret->devDevTreeName = unpack_dataitem( next ); if( !ret->devDevTreeName ) goto unpackerr; next += calc_packed_length_dataitem( ret->devDevTreeName ); ret->devBus = unpack_dataitem( next ); if( !ret->devBus ) goto unpackerr; next += calc_packed_length_dataitem( ret->devBus ); ret->devBusAddr = unpack_dataitem( next ); if( !ret->devBusAddr ) goto unpackerr; next += calc_packed_length_dataitem( ret->devBusAddr ); ret->recordType = unpack_dataitem( next ); if( !ret->recordType ) goto unpackerr; next += calc_packed_length_dataitem( ret->recordType ); ret->scsiDetail = unpack_dataitem( next ); if( !ret->scsiDetail ) goto unpackerr; next += calc_packed_length_dataitem( ret->scsiDetail ); ret->plantMfg = unpack_dataitem( next ); if( !ret->plantMfg ) goto unpackerr; next += calc_packed_length_dataitem( ret->plantMfg ); ret->featureCode = unpack_dataitem( next ); if( !ret->featureCode ) goto unpackerr; next += calc_packed_length_dataitem( ret->featureCode ); ret->keywordVersion = unpack_dataitem( next ); if( !ret->keywordVersion ) goto unpackerr; next += calc_packed_length_dataitem( ret->keywordVersion ); ret->microCodeImage = unpack_dataitem( next ); if( !ret->microCodeImage ) goto unpackerr; next += calc_packed_length_dataitem( ret->microCodeImage ); ret->secondLocation = unpack_dataitem( next ); if( !ret->secondLocation ) goto unpackerr; next += calc_packed_length_dataitem( ret->secondLocation ); ret->physicalLocation = unpack_dataitem( next ); if( !ret->physicalLocation ) goto unpackerr; next += calc_packed_length_dataitem( ret->physicalLocation ); while( 0 == strncmp( next, CHILD_START, strlen( CHILD_START ) ) ) { next++; if( next > packed + size ) goto unpackerr; } if( strncmp( next, CHILD_START, strlen( CHILD_START ) ) == 0 ) { next += strlen( CHILD_START ) + 1; if( next > packed + size ) goto unpackerr; while( strncmp( next, CHILD_END, strlen( CHILD_END ) ) != 0 ) { item = new_list( ); if( !next ) goto unpackerr; item->data = strdup( next ); if (item->data == NULL) goto unpackerr; next += strlen( (char*)item->data ) + 1; if( !ret->childrenIDs ) ret->childrenIDs = item; else concat_list( ret->childrenIDs, item ); if( next > packed + size ) goto unpackerr; } next += strlen( CHILD_END ) + 1; } if( strncmp( next, DEVICE_START, strlen( DEVICE_START ) ) == 0 ) { next += strlen( DEVICE_START ) + 1; if( next > packed + size ) goto unpackerr; while( strncmp( next, DEVICE_END, strlen( DEVICE_END ) ) != 0 ) { data = unpack_dataitem( next ); if( !data ) goto unpackerr; next += calc_packed_length_dataitem( data ); if( !ret->deviceSpecific ) ret->deviceSpecific = data; else add_dataitem( ret->deviceSpecific, data ); if( next > packed + size ) goto unpackerr; } next += strlen( DEVICE_END ) + 1; } if( strncmp( next, USER_START, strlen( USER_START ) ) == 0 ) { next += strlen( USER_START ) + 1; if( next > packed + size ) goto unpackerr; while( strncmp( next, USER_END, strlen( USER_END ) ) != 0 ) { data = unpack_dataitem( next ); if( !data ) goto unpackerr; next += calc_packed_length_dataitem( data ); if( !ret->userData ) ret->userData = data; else add_dataitem( ret->userData, data ); if( next > packed + size ) goto unpackerr; } next += strlen( USER_END ) + 1; } if( strncmp( next, AX_START, strlen( AX_START ) ) == 0 ) { next += strlen( AX_START ) + 1; if( next > packed + size ) goto unpackerr; while( strncmp( next, AX_END, strlen( AX_END ) ) != 0 ) { data = unpack_dataitem( next ); if( !data ) goto unpackerr; next += calc_packed_length_dataitem( data ); if( !ret->aixNames ) ret->aixNames = data; else add_dataitem( ret->aixNames, data ); if( next > packed + size ) goto unpackerr; } } return ret; unpackerr: free_component( ret ); return NULL; }
/* * This example shows how to use the C "client" API. * It essentially wraps a subset of the JSON API, * relevant for a SHERPA mission. * * For communication zyre is used. * Please make ensure a correct zyre configuration file * is passed. */ int main(int argc, char *argv[]) { char agent_name[] = "fw0"; // or wasp1, operator0, ... donkey0, sherpa_box0. Please use the same as SWM_AGENT_NAME environment variable. /* Load configuration file for communication setup */ char config_folder[255] = { SWM_ZYRE_CONFIG_DIR }; char config_name[] = "swm_zyre_config.json"; char config_file[512] = {0}; snprintf(config_file, sizeof(config_file), "%s/%s", config_folder, config_name); if (argc == 2) { // override default config snprintf(config_file, sizeof(config_file), "%s", argv[1]); } json_t * config = load_config_file(config_file);//"swm_zyre_config.json"); if (config == NULL) { return -1; } /* Spawn new communication component */ component_t *self = new_component(config); if (self == NULL) { return -1; } printf("[%s] component initialized!\n", self->name); char *msg; /* Input variables */ double x = 979875; double y = 48704; double z = 405; double utcTimeInMiliSec = 0.0; int i; struct timeval tp; printf("###################### CONNECTIVITY #########################\n"); char *root_id = 0; /* Get the root node ID of the local SHWRPA World Model. * This can be used the check connectivity to the SMW. * Typically false means the local SWM cannot be reached. Is it actually started? */ assert(get_root_node_id(self, &root_id)); free(root_id); printf("###################### AGENT #########################\n"); /* column-major layout: * 0 4 8 12 * 1 5 9 13 * 2 6 10 14 * 3 7 11 15 * * <=> * * r11 r12 r13 x * r21 r22 r23 y * r31 r32 r33 z * 3 7 11 15 */ double matrix[16] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; // y,x,z,1 remember this is column-major! matrix[12] = x; matrix[13] = y; matrix[14] = z; assert(add_agent(self, matrix, utcTimeInMiliSec, agent_name)); assert(add_agent(self, matrix, utcTimeInMiliSec, agent_name)); // twice is not a problem, sine it checks for existance /* * Add new observations for potential victims */ for (i = 0; i < 2; ++i) { printf("###################### VICTIM #########################\n"); gettimeofday(&tp, NULL); utcTimeInMiliSec = tp.tv_sec * 1000 + tp.tv_usec / 1000; //get current timestamp in milliseconds double matrix[16] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; // y,x,z,1 remember this is column-major! matrix[12] = x; matrix[13] = y; matrix[14] = z; assert(add_victim(self, matrix, utcTimeInMiliSec, agent_name)); } /* * Add new image observations */ for (i = 0; i < 2; ++i) { printf("###################### IMAGE #########################\n"); gettimeofday(&tp, NULL); utcTimeInMiliSec = tp.tv_sec * 1000 + tp.tv_usec / 1000; //get current timestamp in milliseconds double matrix[16] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; // y,x,z,1 remember this is column-major! matrix[12] = x; matrix[13] = y; matrix[14] = z; assert(add_image(self, matrix, utcTimeInMiliSec, agent_name, "/tmp/image001.jpg")); } /* * Add new ARTVA observations (Only relevant for the WASPS) */ for (i = 0; i < 2; ++i) { printf("###################### ARTVA #########################\n"); gettimeofday(&tp, NULL); utcTimeInMiliSec = tp.tv_sec * 1000 + tp.tv_usec / 1000; //get current timestamp in milliseconds double matrix[16] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; // y,x,z,1 remember this is column-major! matrix[12] = x; matrix[13] = y; matrix[14] = z; assert(add_artva(self, matrix, 77, 12, 0, 0, utcTimeInMiliSec, agent_name)); } /* * Add new battery values. In fact it is stored in a single battery node and * get updated after first creation. */ for (i = 0; i < 2; ++i) { printf("###################### BATTERY #########################\n"); double voltage = 20 + i; assert(add_battery(self, voltage, "HIGH", utcTimeInMiliSec, agent_name)); } /* * Update pose of this agent */ for (i = 0; i < 30; ++i) { printf("###################### POSE #########################\n"); gettimeofday(&tp, NULL); utcTimeInMiliSec = tp.tv_sec * 1000 + tp.tv_usec / 1000; //get current timestamp in milliseconds double matrix[16] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; // y,x,z,1 remember this is column-major! matrix[12] = x; matrix[13] = y; matrix[14] = z+i; update_pose(self, matrix, utcTimeInMiliSec+i, agent_name); usleep(100/*[ms]*/ * 1000); } /* * Get current position */ printf("###################### GET POSITION #########################\n"); x = 0; y = 0; z = 0; gettimeofday(&tp, NULL); utcTimeInMiliSec = tp.tv_sec * 1000 + tp.tv_usec / 1000; //get current timestamp in milliseconds get_position(self, &x, &y, &z, utcTimeInMiliSec, agent_name); printf ("Latest position of agent = (%f,%f,%f)\n", x,y,z); /* * Get ID of mediator */ printf("###################### GET MEDIATOR ID #########################\n"); char* mediator_id = NULL; assert(get_mediator_id(self, &mediator_id)); printf ("ID of mediator = %s\n", mediator_id); free(mediator_id); printf("###################### DONE #########################\n"); /* Clean up */ destroy_component(&self); printf ("SHUTDOWN\n"); return 0; }
constant new_constant(block_t heap, enum constant_class vclass, ...) { va_list args; constant newp = allocate(heap, sizeof *newp); newp->vclass = vclass; va_start(args, vclass); switch (vclass) { case cst_int: newp->u.integer = va_arg(args, int); break; case cst_string: newp->u.string = va_arg(args, str_and_len_t); break; case cst_list: { cstlist clhead = newp->u.constants = va_arg(args, cstlist); cstlist *clp = &newp->u.constants; while (*clp && ((*clp)->cst == NULL || (*clp)->cst->vclass != cst_expression)) clp = &(*clp)->next; cstlist cltail = *clp; if (cltail == NULL) break; if (clp == &newp->u.constants) { /* the first expression is the list tail */ newp = clhead->cst; cltail = cltail->next; } else if (clp == &newp->u.constants->next) { /* the first expression is the last element before the tail */ if (newp->u.constants->cst) newp = newp->u.constants->cst; else newp->u.constants = NULL; } else { /* the first expression is here, so truncate the tail */ *clp = NULL; } build_heap = heap; component l = new_component(heap, -1, c_constant, newp); for (; cltail; cltail = cltail->next) { component c = new_component(heap, -1, c_constant, cltail->cst); l = build_exec(build_recall(GEP "pcons"), 2, c, l); } newp = allocate(heap, sizeof *newp); newp->vclass = cst_expression; newp->u.expression = l; break; } case cst_array: case cst_table: { newp->u.constants = va_arg(args, cstlist); bool dynamic = false; for (cstlist cl = newp->u.constants; cl; cl = cl->next) if (cl->cst->vclass == cst_expression) { dynamic = true; break; } if (!dynamic) break; build_heap = heap; clist cargs = NULL; for (cstlist cl = newp->u.constants; cl; cl = cl->next) cargs = new_clist(heap, new_component(heap, -1, c_constant, cl->cst), cargs); cargs = new_clist(heap, build_recall(GEP "sequence"), cargs); component c = new_component(heap, 0, c_execute, cargs); if (vclass == cst_table) c = build_exec(build_recall(GEP "vector_to_ptable"), 1, c); newp->vclass = cst_expression; newp->u.expression = c; break; } case cst_float: newp->u.mudlle_float = va_arg(args, double); break; case cst_bigint: newp->u.bigint_str = va_arg(args, const char *); break; case cst_symbol: { newp->u.constpair = va_arg(args, cstpair); if (newp->u.constpair->cst1->vclass != cst_expression && newp->u.constpair->cst2->vclass != cst_expression) break; build_heap = heap; component c = build_exec(build_recall(GEP "make_psymbol"), 2, new_component(heap, -1, c_constant, newp->u.constpair->cst1), new_component(heap, -1, c_constant, newp->u.constpair->cst2)); newp->vclass = cst_expression; newp->u.expression = c; break; } case cst_expression: newp->u.expression = va_arg(args, component); break; default: abort(); } va_end(args); return newp; }
/*ARGSUSED*/ EXPORT void set_up_riemann_problem_region( int layer_label, int region_label, int surf_label, int ellip_label, float *coords, float *nor, SIDE ahead_side, Locstate ahead_st, Locstate st, LAYER_SYS *layer_sys, INIT_PHYSICS *ip, INIT_DATA *init) { COMP_TYPE *ct; _RAREFACTION_WAVE_1D *rw1d; LAYER *lyr, *llyr, *ulyr; Front *front = layer_sys->front; INTERFACE *intfc = front->interf; ELLIPSOID *ellip; LAYER_SURF *lsurf; Locstate sl, sr; Locstate left, right; Locstate sml, smr; float vl, vr; float pjump; float pml, pmr, uml, umr, ml, mr; float cl, cr, cml, cmr, Wl, Wr; float W, V; float dt, dh; RIEMANN_SOLVER_WAVE_TYPE l_wave, r_wave; int i, dim = front->rect_grid->dim; int w_type; size_t sizest = front->sizest; debug_print("layer","Entered set_up_riemann_problem_region()\n"); alloc_state(intfc,&left,max(sizeof(VGas),sizest)); alloc_state(intfc,&right,max(sizeof(VGas),sizest)); alloc_state(intfc,&sml,sizest); alloc_state(intfc,&smr,sizest); if (ahead_side == POSITIVE_SIDE) { sl = st; sr = ahead_st; } else { sl = ahead_st; sr = st; } set_state(right,TGAS_STATE,sr); set_state(left,TGAS_STATE,sl); lyr = layer_sys->layer[layer_label]; if (ellip_label > 0) { if (ellip_label <= lyr->num_ellips) ellip = lyr->ellip[ellip_label]; else { screen("ERROR in set_up_riemann_problem_region(), " "invalid ellip_label %d > num_ellips %d\n", ellip_label,lyr->num_ellips); clean_up(ERROR); } lsurf = NULL; } else { ellip = NULL; if (surf_label == layer_label) { lsurf = lyr->upper_surf; llyr = lyr; ulyr = layer_sys->layer[layer_label+1]; } else if (surf_label == layer_label-1) { lsurf = lyr->lower_surf; ulyr = lyr; llyr = layer_sys->layer[layer_label-1]; } else { screen("ERROR in set_up_riemann_problem_region(), " "invalid surf_label %d layer_label %d\n", surf_label,layer_label); clean_up(ERROR); } } if (ellip != NULL) { vr = Vel(right)[0]; vl = Vel(left)[0]; pjump = -ellip->surf_tension/ distance_between_positions(coords,ellip->cen,dim); } else { vr = scalar_product(Vel(right),nor,dim); vl = scalar_product(Vel(left),nor,dim); pjump = 0.0; } zero_state_velocity(right,dim); Vel(right)[0] = vr; zero_state_velocity(left,dim); Vel(right)[0] = vl; set_state_for_find_mid_state(right,right); set_state_for_find_mid_state(left,left); if (find_mid_state(left,right,pjump,&pml,&pmr,¨,&umr,&ml,&mr, &l_wave,&r_wave) != FUNCTION_SUCCEEDED) { screen("ERROR in set_up_riemann_problem_region(), " "find_mid_state() did not converge\n"); verbose_print_state("left",left); verbose_print_state("right",right); (void) printf("pjump = %g\n" "pml = %g, pmr = %g\n" "uml = %g, umr = %g\n" "ml = %g, mr = %g\n", pjump,pml,pmr,uml,umr,ml,mr); (void) printf("l_wave = %s, r_wave = %s\n", rsoln_wave_name(l_wave),rsoln_wave_name(r_wave)); clean_up(ERROR); } w_type = (l_wave == RAREFACTION) ? BACKWARD_SOUND_WAVE_TE : BACKWARD_SHOCK_WAVE; state_behind_sound_wave(left,sml,&cml,&Wl,0.0,ml,uml,pml,TGAS_STATE, w_type,l_wave,LEFT_FAMILY); w_type = (r_wave == RAREFACTION) ? FORWARD_SOUND_WAVE_TE : FORWARD_SHOCK_WAVE; state_behind_sound_wave(right,smr,&cmr,&Wr,0.0,mr,umr,pmr,TGAS_STATE, w_type,r_wave,RIGHT_FAMILY); cl = sound_speed(left); cr = sound_speed(right); W = max(fabs(Wl),fabs(Wr)); V = fabs(vl) + cl; W = max(W,V); V = fabs(vr) + cr; W = max(W,V); V = fabs(uml) + cml; W = max(W,V); V = fabs(umr) + cmr; W = max(W,V); for (dh = HUGE_VAL, i = 0; i < dim; ++i) dh = min(dh,front->rect_grid->h[i]); dt = 0.1*dh/W;/*TOLERANCE*/ layer_sys->dt = min(layer_sys->dt,dt); if (debugging("layer")) { (void) printf("States from Riemann solution\n"); verbose_print_state("left state",left); verbose_print_state("left mid state",sml); verbose_print_state("right mid state",smr); verbose_print_state("right state",right); (void) printf("l_wave = %s, r_wave = %s\n", rsoln_wave_name(l_wave),rsoln_wave_name(r_wave)); (void) printf("Wave speeds\n"); if (l_wave == RAREFACTION) { (void) printf("Left rarefaction leading edge speed = %g\n", vl-cl); (void) printf("Left rarefaction trailing edge speed = %g\n", uml-cml); } else if (l_wave == SHOCK) (void) printf("Left shock speed = %g\n",Wl); (void) printf("Contact speed = %g (uml = %g, umr = %g)\n", 0.5*(uml+umr),uml,umr); if (r_wave == RAREFACTION) { (void) printf("Right rarefaction trailing edge speed = %g\n", umr+cmr); (void) printf("Right rarefaction leading edge speed = %g\n", vr+cr); } else if (r_wave == SHOCK) (void) printf("Right shock speed = %g\n",Wr); } if (ellip == NULL) { LAYER *rlyr, *mlyr; LAYER_SURF *rlyr_le, *rlyr_te, *shock; float *nor = lsurf->nor; float vml, vmr; vml = Vel(sml)[0]; vmr = Vel(smr)[0]; for (i = 0; i < dim; ++i) { Vel(sml)[i] = vel(i,sl) + (vml-vl)*nor[i]; Vel(smr)[i] = vel(i,sr) + (vmr-vr)*nor[i]; } if (l_wave == RAREFACTION) { rlyr = add_new_layer(layer_sys,new_component(NEW_COMP)); rlyr->lower_surf = alloc_layer_surf(); rlyr->upper_surf = alloc_layer_surf(); *rlyr->upper_surf = *lsurf; *rlyr->lower_surf = *lsurf; rlyr->lower_surf->reset_position = YES; rlyr->upper_surf->reset_position = YES; rlyr->lower_surf->surf_ten = 0.0; rlyr->upper_surf->surf_ten = 0.0; ct = comp_type(rlyr->comp); set_rarefaction_wave_1d_comp_type(ct,front); rw1d = Rarefaction_wave_1d(ct); rw1d->l_or_r = LEFT_FAMILY; rw1d->zbar = lsurf->pbar[dim-1]; rw1d->tbar = -HUGE_VAL; /*To be set later */ rw1d->el_lead = rw1d->el_trail = NULL; set_state(rw1d->stl,TGAS_STATE,sl); set_state(rw1d->stt,TGAS_STATE,sml); rw1d->spl = vl-cl; rw1d->spt = vml-cml; mlyr = add_new_layer(layer_sys,new_component(NEW_COMP)); if (nor[dim-1] < 0.0) { rlyr_le = rlyr->upper_surf; rlyr_te = rlyr->lower_surf; mlyr->upper_surf = rlyr_te; mlyr->lower_surf = lsurf; rw1d->zt = rw1d->zmin = -HUGE_VAL;/*To be set later*/ rw1d->stmin = rw1d->stt; rw1d->zl = rw1d->zmax = HUGE_VAL;/*To be set later*/ rw1d->stmax = rw1d->stl; ulyr->lower_surf = rlyr_le; } else { rlyr_le = rlyr->lower_surf; rlyr_te = rlyr->upper_surf; mlyr->lower_surf = rlyr_te; mlyr->upper_surf = lsurf; rw1d->zl = rw1d->zmin = -HUGE_VAL;/*To be set later*/ rw1d->stmin = rw1d->stl; rw1d->zt = rw1d->zmax = HUGE_VAL;/*To be set later*/ rw1d->stmax = rw1d->stt; llyr->upper_surf = rlyr_le; } rw1d->lead = rlyr_le; rw1d->trail = rlyr_te; rlyr_le->l_comp = lsurf->l_comp; rlyr_le->r_comp = rlyr_te->l_comp = rlyr->comp; rlyr_le->wv_type = BACKWARD_SOUND_WAVE_LE; rlyr_te->wv_type = BACKWARD_SOUND_WAVE_TE; rlyr_te->r_comp = lsurf->l_comp = mlyr->comp; for (i = 0; i < dim; ++i) { rlyr_le->velocity[i] = rw1d->spl*nor[i]; rlyr_te->velocity[i] = rw1d->spt*nor[i]; } } else { mlyr = add_new_layer(layer_sys,new_component(NEW_COMP)); shock = alloc_layer_surf(); *shock = *lsurf; if (nor[dim-1] < 0.0) { mlyr->upper_surf = shock; mlyr->lower_surf = lsurf; ulyr->lower_surf = shock; } else { mlyr->lower_surf = shock; mlyr->upper_surf = lsurf; llyr->upper_surf = shock; } shock->l_comp = lsurf->l_comp; shock->wv_type = BACKWARD_SHOCK_WAVE; shock->r_comp = lsurf->l_comp = mlyr->comp; shock->reset_position = YES; for (i = 0; i < dim; ++i) shock->velocity[i] = Wl*nor[i]; } ct = comp_type(mlyr->comp); set_ambient_comp_type(ct,front); set_state(Ambient(ct),GAS_STATE,sml); if (r_wave == RAREFACTION) { rlyr = add_new_layer(layer_sys,new_component(NEW_COMP)); rlyr->lower_surf = alloc_layer_surf(); rlyr->upper_surf = alloc_layer_surf(); *rlyr->upper_surf = *lsurf; *rlyr->lower_surf = *lsurf; rlyr->lower_surf->reset_position = YES; rlyr->upper_surf->reset_position = YES; rlyr->lower_surf->surf_ten = 0.0; rlyr->upper_surf->surf_ten = 0.0; ct = comp_type(rlyr->comp); set_rarefaction_wave_1d_comp_type(ct,front); rw1d = Rarefaction_wave_1d(ct); rw1d->l_or_r = RIGHT_FAMILY; rw1d->zbar = lsurf->pbar[dim-1]; rw1d->tbar = -HUGE_VAL; /*To be set later */ rw1d->el_lead = rw1d->el_trail = NULL; set_state(rw1d->stl,TGAS_STATE,sr); set_state(rw1d->stt,TGAS_STATE,smr); rw1d->spl = vr+cr; rw1d->spt = vmr+cmr; rw1d->lead = rlyr_le; rw1d->trail = rlyr_te; mlyr = add_new_layer(layer_sys,new_component(NEW_COMP)); if (nor[dim-1] < 0.0) { rlyr_le = rlyr->lower_surf; rlyr_te = rlyr->upper_surf; mlyr->lower_surf = rlyr_te; mlyr->upper_surf = lsurf; rw1d->zl = rw1d->zmin = -HUGE_VAL;/*To be set later*/ rw1d->stmin = rw1d->stl; rw1d->zt = rw1d->zmax = HUGE_VAL;/*To be set later*/ rw1d->stmax = rw1d->stt; llyr->upper_surf = rlyr_le; } else { rlyr_le = rlyr->upper_surf; rlyr_te = rlyr->lower_surf; mlyr->upper_surf = rlyr_te; mlyr->lower_surf = lsurf; rw1d->zt = rw1d->zmin = -HUGE_VAL;/*To be set later*/ rw1d->stmin = rw1d->stt; rw1d->zl = rw1d->zmax = HUGE_VAL;/*To be set later*/ rw1d->stmax = rw1d->stl; ulyr->lower_surf = rlyr_le; } rlyr_le->r_comp = lsurf->r_comp; rlyr_le->l_comp = rlyr_te->r_comp = rlyr->comp; rlyr_le->wv_type = FORWARD_SOUND_WAVE_LE; rlyr_te->wv_type = FORWARD_SOUND_WAVE_TE; rlyr_te->l_comp = lsurf->r_comp = mlyr->comp; for (i = 0; i < dim; ++i) { rlyr_le->velocity[i] = rw1d->spl*nor[i]; rlyr_te->velocity[i] = rw1d->spt*nor[i]; } } else { mlyr = add_new_layer(layer_sys,new_component(NEW_COMP)); shock = alloc_layer_surf(); *shock = *lsurf; if (nor[dim-1] < 0.0) { mlyr->lower_surf = shock; mlyr->upper_surf = lsurf; llyr->upper_surf = shock; } else { mlyr->upper_surf = shock; mlyr->lower_surf = lsurf; ulyr->lower_surf = shock; } shock->r_comp = lsurf->r_comp; shock->wv_type = FORWARD_SHOCK_WAVE; shock->l_comp = lsurf->r_comp = mlyr->comp; shock->reset_position = YES; for (i = 0; i < dim; ++i) shock->velocity[i] = Wr*nor[i]; } ct = comp_type(mlyr->comp); set_ambient_comp_type(ct,front); set_state(Ambient(ct),GAS_STATE,smr); lsurf->wv_type = CONTACT; lsurf->reset_position = YES; for (i = 0; i < dim; ++i) lsurf->velocity[i] = 0.5*(vml+vmr)*nor[i]; } else { set_riemann_problem_ellipsoid(front,lyr,ellip,l_wave,r_wave, Wl,Wr,sl,sml,smr,sr,ip); } free_these(4,left,right,sml,smr); debug_print("layer","Left set_up_riemann_problem_region()\n"); } /*end set_up_riemann_problem_region*/
static void generate_component(component comp, fncode fn) { clist args; set_lineno(comp->lineno, fn); switch (comp->vclass) { case c_assign: { ulong offset; bool is_static; variable_class vclass = env_lookup(comp->u.assign.symbol, &offset, false, true, &is_static); component val = comp->u.assign.value; if (val->vclass == c_closure) { /* Defining a function, give it a name */ if (vclass == global_var) val->u.closure->varname = comp->u.assign.symbol; else { char *varname = allocate(fnmemory(fn), strlen(comp->u.assign.symbol) + 7); sprintf(varname, "local-%s", comp->u.assign.symbol); val->u.closure->varname = varname; } } if (is_static) { ins1(op_recall + vclass, offset, fn); generate_component(comp->u.assign.value, fn); mexecute(g_symbol_set, NULL, 2, fn); break; } generate_component(comp->u.assign.value, fn); set_lineno(comp->lineno, fn); if (vclass == global_var) massign(offset, comp->u.assign.symbol, fn); else ins1(op_assign + vclass, offset, fn); /* Note: varname becomes a dangling pointer when fnmemory(fn) is deallocated, but it is never used again so this does not cause a problem. */ break; } case c_vref: case c_recall: { bool is_vref = comp->vclass == c_vref; ulong offset; bool is_static; variable_class vclass = env_lookup(comp->u.recall, &offset, true, is_vref, &is_static); if (is_static) { assert(vclass != global_var); ins1(op_recall + vclass, offset, fn); ulong gidx = is_vref ? g_make_symbol_ref : g_symbol_get; mexecute(gidx, NULL, 1, fn); break; } if (vclass != global_var) ins1((is_vref ? op_vref : op_recall) + vclass, offset, fn); else if (is_vref) { if (!mwritable(offset, comp->u.recall)) return; ins_constant(makeint(offset), fn); } else mrecall(offset, comp->u.recall, fn); if (is_vref) mexecute(g_make_variable_ref, "make_variable_ref", 1, fn); break; } case c_constant: ins_constant(make_constant(comp->u.cst), fn); break; case c_closure: { uword idx; idx = add_constant(generate_function(comp->u.closure, false, fn), fn); if (idx < ARG1_MAX) ins1(op_closure_code1, idx, fn); else ins2(op_closure_code2, idx, fn); break; } case c_block: generate_block(comp->u.blk, fn); break; case c_labeled: start_block(comp->u.labeled.name, fn); generate_component(comp->u.labeled.expression, fn); end_block(fn); break; case c_exit: generate_component(comp->u.labeled.expression, fn); if (!exit_block(comp->u.labeled.name, fn)) { if (!comp->u.labeled.name) log_error("no loop to exit from"); else log_error("no block labeled %s", comp->u.labeled.name); } break; case c_execute: { uword count; generate_args(comp->u.execute->next, fn, &count); set_lineno(comp->lineno, fn); generate_execute(comp->u.execute->c, count, fn); break; } case c_builtin: args = comp->u.builtin.args; switch (comp->u.builtin.fn) { case b_if: { block cb = new_codeblock(fnmemory(fn), NULL, new_clist(fnmemory(fn), args->next->c, new_clist(fnmemory(fn), component_undefined, NULL)), NULL, NULL, -1); generate_if(args->c, new_component(fnmemory(fn), args->next->c->lineno, c_block, cb), component_undefined, fn); break; } case b_ifelse: generate_if(args->c, args->next->c, args->next->next->c, fn); break; case b_sc_and: case b_sc_or: generate_if(comp, component_true, component_false, fn); break; case b_while: generate_while(args->c, args->next->c, fn); break; case b_loop: { label loop = new_label(fn); env_start_loop(); set_label(loop, fn); start_block(NULL, fn); generate_component(args->c, fn); branch(op_loop1, loop, fn); end_block(fn); env_end_loop(); adjust_depth(1, fn); break; } case b_add: case b_subtract: case b_ref: case b_set: case b_bitor: case b_bitand: case b_not: case b_eq: case b_ne: case b_lt: case b_le: case b_ge: case b_gt: { uword count; assert(comp->u.builtin.fn < last_builtin); generate_args(args, fn, &count); set_lineno(comp->lineno, fn); ins0(builtin_ops[comp->u.builtin.fn], fn); break; } default: { uword count; assert(comp->u.builtin.fn < last_builtin); generate_args(args, fn, &count); set_lineno(comp->lineno, fn); mexecute(builtin_functions[comp->u.builtin.fn], NULL, count, fn); break; } } break; default: abort(); } }
str_and_len_t sl = { .len = 0, .str = NULL }; const char *filename = (f->body->filename ? f->body->filename : ""); const char *nicename = (f->body->nicename ? f->body->nicename : ""); compile_level = seclev; erred = false; env_reset(); fncode top = new_fncode(true); env_push(NULL, top); /* Environment must not be totally empty */ block body = new_toplevel_codeblock(fnmemory(top), f->statics, f->body); function func = new_function(fnmemory(top), TYPESET_ANY, sl, NULL, new_component(fnmemory(top), 0, c_block, body), body->lineno, filename, nicename); func->varname = "top-level"; struct icode *cc = generate_function(func, true, top); GCPRO1(cc); generate_fncode(top, NULL, NULL, NULL, NULL, 0, NULL, TYPESET_ANY, seclev); uword dummy; env_pop(&dummy); delete_fncode(top); UNGCPRO(); if (erred) return NULL; return alloc_closure0(&cc->code);