void Parser::VarDecl() { wchar_t* name; int type; Type(type); Ident(name); tab->NewObj(name, var, type); while (la->kind == 30) { Get(); Ident(name); tab->NewObj(name, var, type); } Expect(18); }
Ident Pool::alloc() { ID_TYPE id; _mutex.lock(); if (_last > _max) { id = -1; for (ID_TYPE i=_first; i<_max; i++) { ListOfID::const_iterator it=std::find_if( _ids.begin(), _ids.end(), IDFinder( i ) ); if (it == _ids.end()) { id = i; break; } } if (id == -1) { _mutex.unlock(); throw std::runtime_error("Cannot allocate identifier, no more identifiers available"); } } else { id = _last; _last++; } _ids.push_back( id ); _mutex.unlock(); LDEBUG("id::Pool", "Pool(%s), Alloc id: id=%ld", _name.c_str(), id); return Ident( new IdentType( (Pool *)this, id ) ); }
void Parser::ProcDecl() { wchar_t* name; Obj *obj; int adr; Expect(9); Ident(name); obj = tab->NewObj(name, proc, undef); obj->adr = gen->pc; if (coco_string_equal(name, L"Main")) gen->progStart = gen->pc; tab->OpenScope(); Expect(10); Expect(11); Expect(12); gen->Emit(ENTER, 0); adr = gen->pc - 2; while (StartOf(1)) { if (la->kind == 28 || la->kind == 29) { VarDecl(); } else { Stat(); } } Expect(13); gen->Emit(LEAVE); gen->Emit(RET); gen->Patch(adr, tab->topScope->nextAdr); tab->CloseScope(); }
CAMLprim value caml_thread_new(value clos) { caml_thread_t th; value vthread = Val_unit; value descr; DWORD th_id; Begin_roots2 (clos, vthread) /* Create a finalized value to hold thread handle */ vthread = alloc_final(sizeof(struct caml_thread_handle) / sizeof(value), caml_thread_finalize, 1, 1000); ((struct caml_thread_handle *)vthread)->handle = NULL; /* Create a descriptor for the new thread */ descr = alloc_tuple(sizeof(struct caml_thread_descr) / sizeof(value)); Ident(descr) = Val_long(thread_next_ident); Start_closure(descr) = clos; Threadhandle(descr) = (struct caml_thread_handle *) vthread; thread_next_ident++; /* Create an info block for the current thread */ th = (caml_thread_t) stat_alloc(sizeof(struct caml_thread_struct)); th->descr = descr; #ifdef NATIVE_CODE th->bottom_of_stack = NULL; th->exception_pointer = NULL; th->local_roots = NULL; #else /* Allocate the stacks */ th->stack_low = (value *) stat_alloc(Thread_stack_size); th->stack_high = th->stack_low + Thread_stack_size / sizeof(value); th->stack_threshold = th->stack_low + Stack_threshold / sizeof(value); th->sp = th->stack_high; th->trapsp = th->stack_high; th->local_roots = NULL; th->external_raise = NULL; th->backtrace_pos = 0; th->backtrace_buffer = NULL; th->backtrace_last_exn = Val_unit; #endif /* Add thread info block to the list of threads */ th->next = curr_thread->next; th->prev = curr_thread; curr_thread->next->prev = th; curr_thread->next = th; /* Fork the new thread */ th->wthread = CreateThread(NULL, 0, caml_thread_start, (void *) th, 0, &th_id); if (th->wthread == NULL) { /* Fork failed, remove thread info block from list of threads */ th->next->prev = curr_thread; curr_thread->next = th->next; #ifndef NATIVE_CODE stat_free(th->stack_low); #endif stat_free(th); caml_wthread_error("Thread.create"); } ((struct caml_thread_handle *)vthread)->handle = th->wthread; End_roots(); return descr; }
inline void fillBoundingVolumesUsingNodesFromFile( MPI_Comm comm, const std::string& sphereFilename, FlaotBoxVector &spheres) { const int spatialDim = 3; stk::mesh::MetaData meta(spatialDim); stk::mesh::BulkData bulk(meta, comm); stk::io::fill_mesh(sphereFilename, bulk); stk::mesh::EntityVector nodes; stk::mesh::get_selected_entities(meta.locally_owned_part(), bulk.buckets(stk::topology::NODE_RANK), nodes); spheres.clear(); spheres.resize(nodes.size()); stk::mesh::FieldBase const * coords = meta.coordinate_field(); for (size_t i=0;i<nodes.size();i++) { stk::mesh::Entity node = nodes[i]; double *data = static_cast<double*>(stk::mesh::field_data(*coords, node)); double x=data[0]; double y=data[1]; double z=data[2]; double radius=1e-5; unsigned id = bulk.identifier(node); FloatBox box(x-radius, y-radius, z-radius, x+radius, y+radius, z+radius); spheres[i] = std::make_pair(box, Ident(id, bulk.parallel_rank())); } }
CAMLprim value caml_thread_initialize(value unit) { value vthread = Val_unit; value descr; HANDLE tick_thread; DWORD th_id; /* Protect against repeated initialization (PR#1325) */ if (curr_thread != NULL) return Val_unit; Begin_root (vthread); /* Initialize the main mutex and acquire it */ caml_mutex = CreateMutex(NULL, TRUE, NULL); if (caml_mutex == NULL) caml_wthread_error("Thread.init"); /* Initialize the TLS keys */ thread_descriptor_key = TlsAlloc(); last_channel_locked_key = TlsAlloc(); /* Create a finalized value to hold thread handle */ vthread = alloc_final(sizeof(struct caml_thread_handle) / sizeof(value), caml_thread_finalize, 1, 1000); ((struct caml_thread_handle *)vthread)->handle = NULL; /* Create a descriptor for the current thread */ descr = alloc_tuple(sizeof(struct caml_thread_descr) / sizeof(value)); Ident(descr) = Val_long(thread_next_ident); Start_closure(descr) = Val_unit; Threadhandle(descr) = (struct caml_thread_handle *) vthread; thread_next_ident++; /* Create an info block for the current thread */ curr_thread = (caml_thread_t) stat_alloc(sizeof(struct caml_thread_struct)); DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &(curr_thread->wthread), 0, FALSE, DUPLICATE_SAME_ACCESS); if (curr_thread->wthread == NULL) caml_wthread_error("Thread.init"); ((struct caml_thread_handle *)vthread)->handle = curr_thread->wthread; curr_thread->descr = descr; curr_thread->next = curr_thread; curr_thread->prev = curr_thread; /* The stack-related fields will be filled in at the next enter_blocking_section */ /* Associate the thread descriptor with the thread */ TlsSetValue(thread_descriptor_key, (void *) curr_thread); /* Set up the hooks */ prev_scan_roots_hook = scan_roots_hook; scan_roots_hook = caml_thread_scan_roots; enter_blocking_section_hook = caml_thread_enter_blocking_section; leave_blocking_section_hook = caml_thread_leave_blocking_section; try_leave_blocking_section_hook = caml_thread_try_leave_blocking_section; caml_channel_mutex_free = caml_io_mutex_free; caml_channel_mutex_lock = caml_io_mutex_lock; caml_channel_mutex_unlock = caml_io_mutex_unlock; caml_channel_mutex_unlock_exn = caml_io_mutex_unlock_exn; /* Fork the tick thread */ tick_thread = CreateThread(NULL, 0, caml_thread_tick, NULL, 0, &th_id); if (tick_thread == NULL) caml_wthread_error("Thread.init"); CloseHandle(tick_thread); End_roots(); return Val_unit; }
CAMLprim value caml_thread_uncaught_exception(value exn) /* ML */ { char * msg = format_caml_exception(exn); fprintf(stderr, "Thread %d killed on uncaught exception %s\n", Int_val(Ident(curr_thread->descr)), msg); free(msg); if (caml_backtrace_active) print_exception_backtrace(); fflush(stderr); return Val_unit; }
void Factor() { if (Look == '(') { Match('('); Expression(); Match(')'); } else if (IsAlpha(Look)) { Ident(); } else { sprintf(tmp, "movl $%d, %%eax", GetNum()); EmitLn(tmp); } }
void Parser::Calc() { int p; char *name; while (la->kind == 1) { Ident(name); Expect(3); Expr(p); Expect(4); map<string, int>::iterator it = tab->find(string(name)); if(it != tab->end()){ tab->erase(string(name)); } tab->insert(pair<string, int>(name, p)); } while (la->kind == 5) { Get(); Expr(p); Ident(name); if (la->kind == 4 || la->kind == 6 || la->kind == 7) { if (la->kind == 6) { Get(); printf("%s = 0x%x\n",name, p); } else if (la->kind == 7) { Get(); printf("%s = 0o%o\n",name, p); } else { Get(); printf("%s = %d\n",name, p); } } } if (la->kind == 8) { Get(); exit(0); } }
void Parser::Taste() { wchar_t* name; InitDeclarations(); Expect(27); Ident(name); tab->OpenScope(); Expect(12); while (la->kind == 28 || la->kind == 29) { VarDecl(); } while (la->kind == 9) { ProcDecl(); } Expect(13); tab->CloseScope(); }
static value caml_thread_new_descriptor(value clos) { value mu = Val_unit; value descr; Begin_roots2 (clos, mu) /* Create and initialize the termination semaphore */ mu = caml_threadstatus_new(); /* Create a descriptor for the new thread */ descr = alloc_small(3, 0); Ident(descr) = Val_long(thread_next_ident); Start_closure(descr) = clos; Terminated(descr) = mu; thread_next_ident++; End_roots(); return descr; }
void Parser::Factor(int &type) { int n; Obj *obj; wchar_t* name; type = undef; if (la->kind == 1) { Ident(name); obj = tab->Find(name); type = obj->type; if (obj->kind == var) { if (obj->level == 0) gen->Emit(LOADG, obj->adr); else gen->Emit(LOAD, obj->adr); } else Err(L"variable expected"); } else if (la->kind == 2) { Get(); swscanf(t->val, L"%d", &n); //n = Convert.ToInt32(t->val); gen->Emit(CONST, n); type = integer; } else if (la->kind == 4) { Get(); Factor(type); if (type != integer) { Err(L"integer type expected"); type = integer; } gen->Emit(NEG); } else if (la->kind == 5) { Get(); gen->Emit(CONST, 1); type = boolean; } else if (la->kind == 6) { Get(); gen->Emit(CONST, 0); type = boolean; } else SynErr(34); }
void Parser::Stat() { int type; wchar_t* name; Obj *obj; int adr, adr2, loopstart; switch (la->kind) { case 1: { Ident(name); obj = tab->Find(name); if (la->kind == 17) { Get(); if (obj->kind != var) Err(L"cannot assign to procedure"); Expr(type); Expect(18); if (type != obj->type) Err(L"incompatible types"); if (obj->level == 0) gen->Emit(STOG, obj->adr); else gen->Emit(STO, obj->adr); } else if (la->kind == 10) { Get(); Expect(11); Expect(18); if (obj->kind != proc) Err(L"object is not a procedure"); gen->Emit(CALL, obj->adr); } else SynErr(36); break; } case 1: { Ident(name); obj = tab->Find(name); Expect(17); Expr(type); Expect(19); Expr(type2); Expect(20); Expr(type3); Expect(18); break; } case 21: { Get(); Expect(10); Expr(type); Expect(11); if (type != boolean) Err(L"boolean type expected"); gen->Emit(FJMP, 0); adr = gen->pc - 2; Stat(); if (la->kind == 22) { Get(); gen->Emit(JMP, 0); adr2 = gen->pc - 2; gen->Patch(adr, gen->pc); adr = adr2; Stat(); } gen->Patch(adr, gen->pc); break; } case 23: { Get(); loopstart = gen->pc; Expect(10); Expr(type); Expect(11); if (type != boolean) Err(L"boolean type expected"); gen->Emit(FJMP, 0); adr = gen->pc - 2; Stat(); gen->Emit(JMP, loopstart); gen->Patch(adr, gen->pc); break; } case 24: { Get(); loopstart = gen->pc; Expect(10); Expr(ty); Expect(18); Expr(type); Expect(18); Expr(ty); Expect(11); if (type != boolean) Err(L"boolean type expected"); gen->Emit(FJMP, 0); adr = gen->pc - 2; Stat(); break; } case 25: { Get(); Ident(name); Expect(18); obj = tab->Find(name); if (obj->type != integer) Err(L"integer type expected"); gen->Emit(READ); if (obj->level == 0) gen->Emit(STOG, obj->adr); else gen->Emit(STO, obj->adr); break; } case 26: { Get(); Expr(type); Expect(18); if (type != integer) Err(L"integer type expected"); gen->Emit(WRITE); break; } case 12: { Get(); while (StartOf(1)) { if (StartOf(2)) { Stat(); } else { VarDecl(); } } Expect(13); break; } default: SynErr(37); break; } }
CAMLprim value caml_thread_id(value th) { return Ident(th); }
ArbolSA* Lista_Prototipos_Reservados() { ArbolSA* actual, *actual_tipo, *actual_nombre, *actual_parametros, *actual_declaracion; if (Prototipos_Reservados==NULL) { Prototipos_Reservados=Lista_Prototipos_Vacia(); /* void WriteI(integer e); */ actual_tipo = Tipo_Nulo(); actual_nombre = Ident(); Ident_Info_Lex(actual_nombre) = String2Lex("WriteI"); actual_declaracion = Declaracion(Crear_Tipo(_TIPO_ENTERO),Ident(),Expr_Nula()); Ident_Info_Lex(Declaracion_nombre(actual_declaracion)) = String2Lex("e"); actual_parametros = Lista_Parametros(Lista_Parametros_Vacia(),Parametro(Solo_Lectura(),actual_declaracion)); actual = Prototipo(actual_tipo, actual_nombre, actual_parametros); Prototipos_Reservados=Lista_Prototipos(Prototipos_Reservados,actual); /* void WriteR(real r); */ actual_tipo = Tipo_Nulo(); actual_nombre = Ident(); Ident_Info_Lex(actual_nombre) = String2Lex("WriteR"); actual_declaracion = Declaracion(Crear_Tipo(_TIPO_REAL),Ident(),Expr_Nula()); Ident_Info_Lex(Declaracion_nombre(actual_declaracion)) = String2Lex("r"); actual_parametros = Lista_Parametros(Lista_Parametros_Vacia(),Parametro(Solo_Lectura(),actual_declaracion)); actual = Prototipo(actual_tipo, actual_nombre, actual_parametros); Prototipos_Reservados=Lista_Prototipos(Prototipos_Reservados,actual); /* void WriteC(character c); */ actual_tipo = Tipo_Nulo(); actual_nombre = Ident(); Ident_Info_Lex(actual_nombre) = String2Lex("WriteC"); actual_declaracion = Declaracion(Crear_Tipo(_TIPO_CARACTER),Ident(),Expr_Nula()); Ident_Info_Lex(Declaracion_nombre(actual_declaracion)) = String2Lex("c"); actual_parametros = Lista_Parametros(Lista_Parametros_Vacia(),Parametro(Solo_Lectura(),actual_declaracion)); actual = Prototipo(actual_tipo, actual_nombre, actual_parametros); Prototipos_Reservados=Lista_Prototipos(Prototipos_Reservados,actual); /* void WriteS(string s); */ actual_tipo = Tipo_Nulo(); actual_nombre = Ident(); Ident_Info_Lex(actual_nombre) = String2Lex("WriteS"); actual_declaracion = Declaracion(Crear_Tipo(_TIPO_CADENA),Ident(),Expr_Nula()); Ident_Info_Lex(Declaracion_nombre(actual_declaracion)) = String2Lex("s"); actual_parametros = Lista_Parametros(Lista_Parametros_Vacia(),Parametro(Solo_Lectura(),actual_declaracion)); actual = Prototipo(actual_tipo, actual_nombre, actual_parametros); Prototipos_Reservados=Lista_Prototipos(Prototipos_Reservados,actual); /* void WriteL(boolean l); */ actual_tipo = Tipo_Nulo(); actual_nombre = Ident(); Ident_Info_Lex(actual_nombre) = String2Lex("WriteL"); actual_declaracion = Declaracion(Crear_Tipo(_TIPO_LOGICO),Ident(),Expr_Nula()); Ident_Info_Lex(Declaracion_nombre(actual_declaracion)) = String2Lex("l"); actual_parametros = Lista_Parametros(Lista_Parametros_Vacia(),Parametro(Solo_Lectura(),actual_declaracion)); actual = Prototipo(actual_tipo, actual_nombre, actual_parametros); Prototipos_Reservados=Lista_Prototipos(Prototipos_Reservados,actual); /* integer ReadI(); */ actual_tipo = Crear_Tipo(_TIPO_ENTERO); actual_nombre = Ident(); Ident_Info_Lex(actual_nombre) = String2Lex("ReadI"); actual_parametros = Lista_Parametros_Vacia(); actual = Prototipo(actual_tipo, actual_nombre, actual_parametros); Prototipos_Reservados=Lista_Prototipos(Prototipos_Reservados,actual); /* real ReadR(); */ actual_tipo = Crear_Tipo(_TIPO_REAL); actual_nombre = Ident(); Ident_Info_Lex(actual_nombre) = String2Lex("ReadR"); actual_parametros = Lista_Parametros_Vacia(); actual = Prototipo(actual_tipo, actual_nombre, actual_parametros); Prototipos_Reservados=Lista_Prototipos(Prototipos_Reservados,actual); /* character ReadC(); */ actual_tipo = Crear_Tipo(_TIPO_CARACTER); actual_nombre = Ident(); Ident_Info_Lex(actual_nombre) = String2Lex("ReadC"); actual_parametros = Lista_Parametros_Vacia(); actual = Prototipo(actual_tipo, actual_nombre, actual_parametros); Prototipos_Reservados=Lista_Prototipos(Prototipos_Reservados,actual); /* string ReadS(); */ actual_tipo = Crear_Tipo(_TIPO_CADENA); actual_nombre = Ident(); Ident_Info_Lex(actual_nombre) = String2Lex("ReadS"); actual_parametros = Lista_Parametros_Vacia(); actual = Prototipo(actual_tipo, actual_nombre, actual_parametros); Prototipos_Reservados=Lista_Prototipos(Prototipos_Reservados,actual); /* boolean ReadL(); */ actual_tipo = Crear_Tipo(_TIPO_LOGICO); actual_nombre = Ident(); Ident_Info_Lex(actual_nombre) = String2Lex("ReadB"); actual_parametros = Lista_Parametros_Vacia(); actual = Prototipo(actual_tipo, actual_nombre, actual_parametros); Prototipos_Reservados=Lista_Prototipos(Prototipos_Reservados,actual); }; return Prototipos_Reservados; };
/** Construct a Householder transformation around v * v the unit column vector defining a hyperplane * returns a Householder matrix which reflects vectors across * the hyperplane defined by v */ Matrix Matrix::Householder(const Matrix& v){ assert(v.cols == 1); double n = v.frobeniusNorm(); Matrix hh = Ident(v.rows) - v*v.T()*(2.0/(n*n)); return hh; }