Exemplo n.º 1
0
List *expected_lists(int i){
    switch (i){
        case 0:
            return make_list(1, &LEFT_PAREN);
        case 1:
        case 2:
            return make_list(2, &LEFT_PAREN, integer_token(45, "45"));
        case 3:
            return make_list(2, double_token(34.6, "34.6"), &RIGHT_PAREN);
        case 4:
            return make_list(3, &LEFT_PAREN, identifier_token("fred", "fred"), &RIGHT_PAREN);
        case 5:
        case 6:
            return make_list(3, &LEFT_PAREN, identifier_token("x", "x"), &LEFT_PAREN);
        case 7:
            return make_list(1, string_token("fred"));
        case 8:
            return make_list(1, char_token('a'));
        case 9:
            return make_list(4, &LEFT_PAREN, char_token('x'), char_token('y'), &RIGHT_PAREN);
    }
}
Exemplo n.º 2
0
Arquivo: cpp.c Projeto: rui314/8cc-old
/*
 * #define
 * (C99 6.10.3 Macro replacement)
 */
static void read_define(CppContext *ctx) {
    Token *name = read_cpp_token(ctx);
    if (name->toktype != TOKTYPE_IDENT)
        error_cpp_ctx(ctx, "macro name must be an identifier, but got '%s'", token_to_string(name));

    bool is_space = is_next_space(ctx);
    Token *tok = read_cpp_token(ctx);

    if (!is_space && tok && is_punct(tok, '(')) {
        read_funclike_define(ctx, name->val.str);
        return;
    }

    List *body = make_list();
    while (tok && tok->toktype != TOKTYPE_NEWLINE) {
        list_push(body, tok);
        tok = read_cpp_token(ctx);
    }
    store_macro(ctx, name->val.str, make_obj_macro(body));
}
Exemplo n.º 3
0
static value make_array(cstlist csts, fncode fn)
{
  struct list *l;
  struct vector *v;
  uvalue size = 0, i;
  cstlist scan;
  
  for (scan = csts; scan; scan = scan->next) size++;

  /* This intermediate step is necessary as v is IMMUTABLE
     (so must be allocated after its contents) */
  l = make_list(NULL, csts, 0, FALSE, fn);
  GCPRO1(l);
  v = alloc_vector(size);
  SET_IMMUTABLE(v); SET_READONLY(v);
  GCPOP(1);

  for (i = 0; i < size; i++, l = l->cdr) v->data[i] = l->car;

  return v;
}
Exemplo n.º 4
0
value make_constant(constant c)
{
  struct obj *cst;

  switch (c->vclass)
    {
    case cst_string:
      cst = (value)alloc_string_length(c->u.string.str, c->u.string.len);
      cst->flags |= OBJ_READONLY | OBJ_IMMUTABLE;
      return cst;
    case cst_list: return make_list(c->u.constants);
    case cst_array: return make_array(c->u.constants);
    case cst_int: return makeint(c->u.integer);
    case cst_float: return (value)alloc_mudlle_float(c->u.mudlle_float);
    case cst_bigint: return make_bigint(c->u.bigint_str);
    case cst_table: return make_table(c->u.constants);
    case cst_symbol: return make_symbol(c->u.constpair);
    default:
      abort();
    }
}
Exemplo n.º 5
0
Arquivo: prim.c Projeto: mdbarr/vcsi
VCSI_OBJECT get_localtime_list(VCSI_CONTEXT vc,
			       VCSI_OBJECT x) {

  struct tm* lt;
  time_t tt;

  check_arg_type(vc,x,LNGNUM,"localtime->list");
  
  tt = LNGN(x);
  lt = localtime(&tt);
  
  return make_list(vc,9,make_long(vc,lt->tm_sec),
		   make_long(vc,lt->tm_min),
		   make_long(vc,lt->tm_hour),
		   make_long(vc,lt->tm_mday),
		   make_long(vc,lt->tm_mon),
		   make_long(vc,lt->tm_year+1900),
		   make_long(vc,lt->tm_wday),
		   make_long(vc,lt->tm_yday),
		   make_long(vc,lt->tm_isdst));
}
Exemplo n.º 6
0
value make_constant(constant c, bool save_location, fncode fn)
{
  struct obj *cst;

  switch (c->vclass)
    {
    case cst_string:
      cst = (value)alloc_string(c->u.string);
      SET_READONLY(cst); SET_IMMUTABLE(cst);
      return cst;
    case cst_gsymbol: return make_gsymbol(c->u.string, fn);
    case cst_quote: return make_quote(c, save_location, fn);
    case cst_list: return make_list(c, c->u.constants, 1, save_location, fn);
    case cst_array: return make_array(c->u.constants, fn);
    case cst_int: return makeint(c->u.integer);
    case cst_float: return alloc_mudlle_float(c->u.mudlle_float);
    case cst_table: return make_table(c->u.constants, fn);
    case cst_symbol: return make_symbol(c->u.constpair, fn);
    default:
      abort();
    }
}
Exemplo n.º 7
0
void * run_one_test(void * arg) {
  ln * x = make_list(1, LIST_LENGTH);
  int i;
  char *p = AO_malloc(LARGE_OBJ_SIZE);
  char *q;

  if (0 == p) {
    fprintf(stderr, "AO_malloc(%d) failed: This is normal without mmap\n",
            LARGE_OBJ_SIZE);
    AO_free(p);
  } else {
    p[0] = p[LARGE_OBJ_SIZE/2] = p[LARGE_OBJ_SIZE-1] = 'a';
    q = AO_malloc(LARGE_OBJ_SIZE);
    q[0] = q[LARGE_OBJ_SIZE/2] = q[LARGE_OBJ_SIZE-1] = 'b';
    if (p[0] != 'a' || p[LARGE_OBJ_SIZE/2] != 'a'
        || p[LARGE_OBJ_SIZE-1] != 'a') {
      fprintf(stderr, "First large allocation smashed\n");
      abort();
    }
    AO_free(p);
    if (q[0] != 'b' || q[LARGE_OBJ_SIZE/2] != 'b'
        || q[LARGE_OBJ_SIZE-1] != 'b') {
      fprintf(stderr, "Second large allocation smashed\n");
      abort();
    }
    AO_free(q);
  }
# ifdef DEBUG_RUN_ONE_TEST
    x = reverse(x, 0);
    print_list(x);
    x = reverse(x, 0);
    print_list(x);
# endif
  for (i = 0; i < N_REVERSALS; ++i) {
    x = reverse(x, 0);
  }
  check_list(x, 1, LIST_LENGTH);
  return 0;
}
Exemplo n.º 8
0
/* Matrix inverse */
SEXP R_PDGETRI(SEXP A, SEXP DESCA)
{
  R_INIT;
  int IJ = 1;
  
  SEXP RET, RET_NAMES, INFO, INV;
  
  newRvec(INFO, 1, "int");
  newRmat(INV, nrows(A), ncols(A), "dbl");
  
  
  // Compute inverse
  pdinv_(DBLP(A), &IJ, &IJ, INTP(DESCA), DBLP(INV), INTP(INFO));
  
  
  // Manage return
  RET_NAMES = make_list_names(2, "info", "A");
  RET = make_list(RET_NAMES, 2, INFO, INV);
  
  R_END;
  return RET;
}
Exemplo n.º 9
0
int main() {
  int i;
  int n, k;
  int v;
  int unique;
  List * list = NULL;
  Snode * head = NULL;
  Qnode * qnode = NULL;
  list = make_list(list);
  printf("Enter n, k: ");
  scanf("%d %d", &n, &k);
  for (i=0; i<k; i++) { // initializing
    scanf("%d", &v);
    list = push_back(make_Qnode(v), list);
    head = insert_value(v, head);
  }
  unique = search_unique_value(head);
  if (unique!=MAX_INT) {
    printf("%d\n", unique);
  } else {
    printf("Nothing\n");
  }
  for (i=0; i<n-k; i++) {
    scanf("%d", &v);
    list = push_back(make_Qnode(v), list);
    head = insert_value(v, head);
    qnode = pop_front(list);
    head = reduce_value(qnode->data, head);
    free(qnode);
    unique = search_unique_value(head);
    if (unique!=MAX_INT) {
      printf("%d\n", unique);
    } else {
      printf("Nothing\n");
    }
  }
  //print_list(list);
  return 0;
}
Exemplo n.º 10
0
/* Solving systems of linear equations */
SEXP R_PDGESV(SEXP N, SEXP NRHS, SEXP MXLDIMS, SEXP A, SEXP DESCA, SEXP B, SEXP DESCB)
{
  R_INIT;
  int IJ = 1;
  int * ipiv;
  double *A_cp;
  
  SEXP RET, RET_NAMES, INFO, B_OUT;
  newRvec(INFO, 1, "int");
  newRmat(B_OUT, nrows(B), ncols(B), "dbl");
  
  
  // Copy A and B since pdgesv writes in place
  A_cp = (double *) R_alloc(nrows(A)*ncols(A), sizeof(double));
  //FIXME check returns...
  memcpy(A_cp, DBLP(A), nrows(A)*ncols(A)*sizeof(double));
  memcpy(DBLP(B_OUT), DBLP(B), nrows(B)*ncols(B)*sizeof(double));
  
  
  // Call pdgesv
    ipiv = (int *) R_alloc(INT(MXLDIMS, 0) + INT(DESCA, 5), sizeof(int));
/*  ipiv = (int *) R_alloc(nrows(B) + INT(DESCA, 5), sizeof(int));*/
  
  
  INT(INFO, 0) = 0;
  
  pdgesv_(INTP(N), INTP(NRHS),
    A_cp, &IJ, &IJ, INTP(DESCA), ipiv,
    DBLP(B_OUT), &IJ, &IJ, INTP(DESCB), INTP(INFO));
  
  
  // Manage return
  RET_NAMES = make_list_names(2, "info", "B");
  RET = make_list(RET_NAMES, 2, INFO, B_OUT);
  
  R_END;
  return RET;
}
Exemplo n.º 11
0
ATerm lf_list_1 ( ATerm arg0 ) {
{
ATerm tmp [ 1 ] ;
FUNC_ENTRY ( lf_list_1sym , ATmakeAppl ( lf_list_1sym , arg0 ) ) ;
{
ATerm ltmp [ 1 ] ;
lbl_lf_list_1 : ltmp [ 0 ] = arg0 ;
( tmp [ 0 ] = ltmp [ 0 ] ) ;
{
ATerm atmp01110 ;
ATerm atmp0110 [ 2 ] ;
ATerm atmp010 ;
ATerm atmp00 [ 2 ] ;
( atmp00 [ 0 ] = tmp [ 0 ] ) ;
( atmp00 [ 1 ] = tmp [ 0 ] ) ;
while ( not_empty_list ( tmp [ 0 ] ) ) {
( atmp010 = list_head ( tmp [ 0 ] ) ) ;
( tmp [ 0 ] = list_tail ( tmp [ 0 ] ) ) ;
( atmp0110 [ 0 ] = tmp [ 0 ] ) ;
( atmp0110 [ 1 ] = tmp [ 0 ] ) ;
while ( not_empty_list ( tmp [ 0 ] ) ) {
( atmp01110 = list_head ( tmp [ 0 ] ) ) ;
( tmp [ 0 ] = list_tail ( tmp [ 0 ] ) ) ;
if ( term_equal ( atmp010 , atmp01110 ) ) {
( arg0 = cons ( slice ( atmp00 [ 0 ] , atmp00 [ 1 ] ) , cons ( make_list ( atmp010 ) , cons ( slice ( atmp0110 [ 0 ] , atmp0110 [ 1 ] ) , tmp [ 0 ] ) ) ) ) ;
goto lbl_lf_list_1 ;
}
( atmp0110 [ 1 ] = list_tail ( atmp0110 [ 1 ] ) ) ;
( tmp [ 0 ] = atmp0110 [ 1 ] ) ;
}
( atmp00 [ 1 ] = list_tail ( atmp00 [ 1 ] ) ) ;
( tmp [ 0 ] = atmp00 [ 1 ] ) ;
}
}
FUNC_EXIT ( make_nf1 ( lf_list_1sym , ltmp [ 0 ] ) ) ;
}
}
}
Exemplo n.º 12
0
Arquivo: tasks.c Projeto: bszcz/c
int main(int argc, char** argv) {
	const int seed = 1234;
	srand(seed);

	long list_size = 1000;
	int max_threads = omp_get_max_threads();
	int num_threads = 1;
	int nodes_to_print = 10;

	int opt;
	while ((opt = getopt(argc, argv, "p:s:t:")) != -1) {
		switch (opt) {
		case 'p':
			nodes_to_print = strtol(optarg, NULL, 10);
			break;
		case 's':
			list_size = strtol(optarg, NULL, 10);
			break;
		case 't':
			num_threads = strtol(optarg, NULL, 10);
			break;
		default:
			printf("usage: %s -p <nodes_to_print> -s <list_size> -t <num_threads>\n", argv[0]);
		}
	}

	omp_set_num_threads(num_threads);
	printf("// list_size = %ld, num_threads = %d, max_threads = %d\n",
	       list_size, num_threads, max_threads);

	struct node* first = make_list(list_size);
	print_list(first, nodes_to_print);
	printf("// processing...\n");
	process_list(first);
	print_list(first, nodes_to_print);

	exit(EXIT_SUCCESS);
}
Exemplo n.º 13
0
/* Cholesky */
SEXP R_PDPOTRF(SEXP N, SEXP A, SEXP DESCA, SEXP UPLO)
{
  R_INIT;
  int IJ = 1;
  SEXP RET, RET_NAMES, INFO, C;
  
  newRvec(INFO, 1, "int");
  newRmat(C, nrows(A), ncols(A), "dbl");
  
  // Compute chol
  memcpy(DBLP(C), DBLP(A), nrows(A)*ncols(A)*sizeof(double));
  
  INT(INFO, 0) = 0;
  
  pdpotrf_(STR(UPLO, 0), INTP(N), DBLP(C), &IJ, &IJ, INTP(DESCA), INTP(INFO));
  
  // Manage return
  RET_NAMES = make_list_names(2, "info", "A");
  RET = make_list(RET_NAMES, 2, INFO, C);
  
  R_END;
  return(RET);
}
Exemplo n.º 14
0
int main(int argc, char* argv[]) {
	thrd_t thrd1,thrd2,thrd3,thrd4;
	time_t tm;
	srand((unsigned int)time(&tm));
	curl_global_init(CURL_GLOBAL_WIN32/*CURL_GLOBAL_DEFAULT*/);// without ssl
	//initMqcdnMap(&map);
	//initOSMMap(&map);
	initBingMap(&map);
	//initYahooMap(&map);  //not work
	//initYndexMap(&map);

	glutInitWindowSize(veiwport[0], veiwport[1]);
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
	glutCreateWindow("glutplanet");
	glutMouseFunc(mouse);
	glutMotionFunc(mousemove);
	glutIdleFunc(idle);
	glutReshapeFunc(reshape);
	glutDisplayFunc(draw);

	tiles = make_list();
	tiles_get = make_synclist();
	thrd_create(&thrd1,worker_thread,0);
	thrd_create(&thrd2,worker_thread,0);
	thrd_create(&thrd3,worker_thread,0);
	thrd_create(&thrd4,worker_thread,0);
	crd_setz(&center,0.5,0.5,0);
	//double z = log2(veiwport[0]<veiwport[1]?veiwport[0]:veiwport[1] / 256.0);
	crd_zoomto(&center,log2(veiwport[0]<veiwport[1]?veiwport[0]:veiwport[1] / 256.0));
	make_tiles();

	atexit(do_exit);

	glutMainLoop();
	return 0;
}
Exemplo n.º 15
0
Arquivo: main.c Projeto: bcho/homework
int main()
{
    list_t l = make_list();

    char _[] = "deadbeef";
    char *msg = _;
    for (;*msg != '\0';msg++) {
        insert(*msg, header(l));
    }
    traversal(print_node, l);
    sep;
    printf("%c", find('a', l)->e);
    sep;
    insert('v', find('a', l));
    traversal(print_node, l);
    sep;
    traversal(print_node, pop('e', l));
    sep;
    destory(l);
    printf("%d %d", is_empty(l), is_last(header(l)));
    sep;

    return 0;
}
Exemplo n.º 16
0
/** Create a list of surfaces.
 */
list356_t* get_surfaces() {
    debug("get_surfaces()") ;


    // Spheres along the negative x, y, and z axes.
    list356_t* surfaces = make_list() ;
    surface_t* z_sphere ;
    for (float x=0.0; x>=-40.0; x-=3.0) {
        lst_add(surfaces, make_sphere(x, 0.0, 0.0f, 1.0f, &GREEN, 
                    &GREEN, &WHITE, 100.0f)) ;
        lst_add(surfaces, make_sphere(0.0f, x, 0.0f, .25, &PURPLE, 
                    &PURPLE, &WHITE, 100.0f)) ;
        lst_add(surfaces, (z_sphere = make_sphere(0.0f, 0.0f, x, .25, &PURPLE, 
                    &PURPLE, &WHITE, 100.0f))) ;
        z_sphere->refl_color = &LIGHT_GREY ;
    }

    // A rectangle in the y=-1 plane.
    surface_t* tri1 = make_triangle(
                (point3_t){-40, -1, 2},
                (point3_t){2, -1, 2},
                (point3_t){2, -1, -20},
                &LIGHT_GREY, &LIGHT_GREY, &BLACK, 10.0f) ;
    surface_t* tri2 = make_triangle(
                (point3_t){-40, -1, 2},
                (point3_t){2, -1, -20},
                (point3_t){-40, -1, -20},
                &LIGHT_GREY, &LIGHT_GREY, &BLACK, 10.0f) ;
    tri1->refl_color = &DARK_GREY ;
    tri2->refl_color = &DARK_GREY ;
    lst_add(surfaces, tri1) ;
    lst_add(surfaces, tri2) ;

    return surfaces ;

}
Exemplo n.º 17
0
static void make_list(int start_fac)
{
  int i;
  
  if (ng < ng_max) {
    if (n_list >= n_list_alloc) {
      n_list_alloc += 100;
      srenew(list,n_list_alloc);
    }
    list[n_list] = ng;
    n_list++;

    for(i=start_fac; i<facNR; i++) {
      /* allow any power of 2, 3, 5 and 7, but only one of 11 or 13 */
      if (i<4 || (decomp[4]+decomp[5]==0)) {
	ng*=factor[i];
	decomp[i]++;
	make_list(i);
	ng/=factor[i];
	decomp[i]--;
      }
    }
  }
}
Exemplo n.º 18
0
Arquivo: copy.c Projeto: Enouk/iErl14
/*
 *  Copy a structure to a heap.
 */
Eterm
copy_struct(Eterm obj, Uint sz, Eterm** hpp, ErlOffHeap* off_heap)
{
    char* hstart;
    Uint hsize;
    Eterm* htop;
    Eterm* hbot;
    Eterm* hp;
    Eterm* objp;
    Eterm* tp;
    Eterm  res;
    Eterm  elem;
    Eterm* tailp;
    Eterm* argp;
    Eterm* const_tuple;
    Eterm hdr;
    int i;
#ifdef DEBUG
    Eterm org_obj = obj;
    Uint org_sz = sz;
#endif

    if (IS_CONST(obj))
	return obj;

    hp = htop = *hpp;
    hbot   = htop + sz;
    hstart = (char *)htop;
    hsize = (char*) hbot - hstart;
    const_tuple = 0;

    /* Copy the object onto the heap */
    switch (primary_tag(obj)) {
    case TAG_PRIMARY_LIST: argp = &res; goto L_copy_list;
    case TAG_PRIMARY_BOXED: argp = &res; goto L_copy_boxed;
    default:
	erl_exit(ERTS_ABORT_EXIT,
		 "%s, line %d: Internal error in copy_struct: 0x%08x\n",
		 __FILE__, __LINE__,obj);
    }

 L_copy:
    while (hp != htop) {
	obj = *hp;

	switch (primary_tag(obj)) {
	case TAG_PRIMARY_IMMED1:
	    hp++;
	    break;
	case TAG_PRIMARY_LIST:
	    objp = list_val(obj);
	    if (in_area(objp,hstart,hsize)) {
		hp++;
		break;
	    }
	    argp = hp++;
	    /* Fall through */

	L_copy_list:
	    tailp = argp;
	    while (is_list(obj)) {
		objp = list_val(obj);
		tp = tailp;
		elem = *objp;
		if (IS_CONST(elem)) {
		    *(hbot-2) = elem;
		    tailp = hbot-1;
		    hbot -= 2;
		}
		else {
		    *htop = elem;
		    tailp = htop+1;
		    htop += 2;
		}
		*tp = make_list(tailp - 1);
		obj = *(objp+1);
	    }
	    switch (primary_tag(obj)) {
	    case TAG_PRIMARY_IMMED1: *tailp = obj; goto L_copy;
	    case TAG_PRIMARY_BOXED: argp = tailp; goto L_copy_boxed;
	    default:
		erl_exit(ERTS_ABORT_EXIT,
			 "%s, line %d: Internal error in copy_struct: 0x%08x\n",
			 __FILE__, __LINE__,obj);
	    }
	    
	case TAG_PRIMARY_BOXED:
	    if (in_area(boxed_val(obj),hstart,hsize)) {
		hp++;
		break;
	    }
	    argp = hp++;

	L_copy_boxed:
	    objp = boxed_val(obj);
	    hdr = *objp;
	    switch (hdr & _TAG_HEADER_MASK) {
	    case ARITYVAL_SUBTAG:
		{
		    int const_flag = 1; /* assume constant tuple */
		    i = arityval(hdr);
		    *argp = make_tuple(htop);
		    tp = htop;	/* tp is pointer to new arity value */
		    *htop++ = *objp++; /* copy arity value */
		    while (i--) {
			elem = *objp++;
			if (!IS_CONST(elem)) {
			    const_flag = 0;
			}
			*htop++ = elem;
		    }
		    if (const_flag) {
			const_tuple = tp; /* this is the latest const_tuple */
		    }
		}
		break;
	    case REFC_BINARY_SUBTAG:
		{
		    ProcBin* pb;

		    pb = (ProcBin *) objp;
		    if (pb->flags) {
			erts_emasculate_writable_binary(pb);
		    }
		    i = thing_arityval(*objp) + 1;
		    hbot -= i;
		    tp = hbot;
		    while (i--)  {
			*tp++ = *objp++;
		    }
		    *argp = make_binary(hbot);
		    pb = (ProcBin*) hbot;
		    erts_refc_inc(&pb->val->refc, 2);
		    pb->next = off_heap->mso;
		    pb->flags = 0;
		    off_heap->mso = pb;
		    off_heap->overhead += pb->size / sizeof(Eterm);
		}
		break;
	    case SUB_BINARY_SUBTAG:
		{
		    ErlSubBin* sb = (ErlSubBin *) objp;
		    Eterm real_bin = sb->orig;
		    Uint bit_offset = sb->bitoffs;
		    Uint bit_size = sb -> bitsize;
		    Uint offset = sb->offs;
		    size_t size = sb->size;
		    Uint extra_bytes;
		    Uint real_size;
		    if ((bit_size + bit_offset) > 8) {
			extra_bytes = 2;
		    } else if ((bit_size + bit_offset) > 0) {
			extra_bytes = 1;
		    } else {
			extra_bytes = 0;
		    } 
		    real_size = size+extra_bytes;
		    objp = binary_val(real_bin);
		    if (thing_subtag(*objp) == HEAP_BINARY_SUBTAG) {
			ErlHeapBin* from = (ErlHeapBin *) objp;
			ErlHeapBin* to;
			i = heap_bin_size(real_size);
			hbot -= i;
			to = (ErlHeapBin *) hbot;
			to->thing_word = header_heap_bin(real_size);
			to->size = real_size;
			sys_memcpy(to->data, ((byte *)from->data)+offset, real_size);
		    } else {
			ProcBin* from = (ProcBin *) objp;
			ProcBin* to;
			
			ASSERT(thing_subtag(*objp) == REFC_BINARY_SUBTAG);
			if (from->flags) {
			    erts_emasculate_writable_binary(from);
			}
			hbot -= PROC_BIN_SIZE;
			to = (ProcBin *) hbot;
			to->thing_word = HEADER_PROC_BIN;
			to->size = real_size;
			to->val = from->val;
			erts_refc_inc(&to->val->refc, 2);
			to->bytes = from->bytes + offset;
			to->next = off_heap->mso;
			to->flags = 0;
			off_heap->mso = to;
			off_heap->overhead += to->size / sizeof(Eterm);
		    }
		    *argp = make_binary(hbot);
		    if (extra_bytes != 0) {
			ErlSubBin* res;
			hbot -= ERL_SUB_BIN_SIZE;
			res = (ErlSubBin *) hbot;
			res->thing_word = HEADER_SUB_BIN;
			res->size = size;
			res->bitsize = bit_size;
			res->bitoffs = bit_offset;
			res->offs = 0;
			res->is_writable = 0;
			res->orig = *argp;
			*argp = make_binary(hbot);
		    }
		    break;
		}
		break;
	    case FUN_SUBTAG:
		{
		    ErlFunThing* funp = (ErlFunThing *) objp;

		    i =  thing_arityval(hdr) + 2 + funp->num_free;
		    tp = htop;
		    while (i--)  {
			*htop++ = *objp++;
		    }
#ifndef HYBRID /* FIND ME! */
		    funp = (ErlFunThing *) tp;
		    funp->next = off_heap->funs;
		    off_heap->funs = funp;
		    erts_refc_inc(&funp->fe->refc, 2);
#endif
		    *argp = make_fun(tp);
		}
		break;
	    case EXTERNAL_PID_SUBTAG:
	    case EXTERNAL_PORT_SUBTAG:
	    case EXTERNAL_REF_SUBTAG:
		{
		  ExternalThing *etp = (ExternalThing *) htop;

		  i =  thing_arityval(hdr) + 1;
		  tp = htop;

		  while (i--)  {
		    *htop++ = *objp++;
		  }

		  etp->next = off_heap->externals;
		  off_heap->externals = etp;
		  erts_refc_inc(&etp->node->refc, 2);

		  *argp = make_external(tp);
		}
		break;
	    case BIN_MATCHSTATE_SUBTAG:
		erl_exit(ERTS_ABORT_EXIT,
			 "copy_struct: matchstate term not allowed");
	    default:
		i = thing_arityval(hdr)+1;
		hbot -= i;
		tp = hbot;
		*argp = make_boxed(hbot);
		while (i--) {
		    *tp++ = *objp++;
		}
	    }
	    break;
	case TAG_PRIMARY_HEADER:
	    if (header_is_thing(obj) || hp == const_tuple) {
		hp += header_arity(obj) + 1;
	    } else {
		hp++;
	    }
	    break;
	}
    }

#ifdef DEBUG
    if (htop != hbot)
	erl_exit(ERTS_ABORT_EXIT,
		 "Internal error in copy_struct() when copying %T:"
		 " htop=%p != hbot=%p (sz=%bpu)\n",
		 org_obj, htop, hbot, org_sz); 
#else
    if (htop > hbot) {
	erl_exit(ERTS_ABORT_EXIT,
		 "Internal error in copy_struct(): htop, hbot overrun\n");
    }
#endif
    *hpp = (Eterm *) (hstart+hsize);
    return res;
}
Exemplo n.º 19
0
int get_user( UnwrapParams *uwp )
{
   static char *text[] = {
      "Draws polygons in the 2D coordinate system of the selected texture layer.",
      NULL
   };
   static char *fgopt[] = {
      "Use Color",
      "Invert Background",
      "Brighten",
      "Darken",
      NULL
   };
   static char *bgopt[] = {
      "Use Color",
      "Copy Image Map",
      NULL
   };

   LWPanControlDesc desc;
   LWValue
      ival    = { LWT_INTEGER },
      sval    = { LWT_STRING },
      ivecval = { LWT_VINT };
   LWPanelID panel;
   LWControl *ctl[ 10 ], *bdr[ 2 ];
   Node *root;
   int i, x, y, w, ph, ok;


   root = make_list( panf->globalFun );
   if ( !root ) return 0;

   if( !( panel = PAN_CREATE( panf, "Unwrap" ))) {
      free_tree( root, 1 );
      return 0;
   }

   if ( !uwp->filename[ 0 ] ) {
      strcpy( uwp->filename, "unwrapped" );
      filename_ext( uwp->saver, uwp->filename );
      uwp->bgcolor[ 0 ] = uwp->bgcolor[ 1 ] = uwp->bgcolor[ 2 ] = 255;
   }

   TEXT_CTL( panf, panel, "", text );

   ctl[ 0 ] = TREE_CTL( panf, panel, "Texture Layer", 200, 200, tree_info,
      tree_count, tree_child );

   ph = PAN_GETH( panf, panel );
   ph -= CON_X( ctl[ 0 ] );
   ph -= CON_H( ctl[ 0 ] );

   ctl[ 1 ] = SAVE_CTL( panf, panel, "Save As", 40 );
   ctl[ 2 ] = CUSTPOPUP_CTL( panf, panel, "", 150, sname, scount );
   ctl[ 3 ] = INT_CTL( panf, panel, "Width" );
   ctl[ 4 ] = INT_CTL( panf, panel, "Height" );
   ctl[ 5 ] = BUTTON_CTL( panf, panel, "From Image Map" );
   ctl[ 6 ] = WPOPUP_CTL( panf, panel, "Edges", fgopt, 150 );
   ctl[ 7 ] = MINIRGB_CTL( panf, panel, "" );
   ctl[ 8 ] = WPOPUP_CTL( panf, panel, "Background", bgopt, 150 );
   ctl[ 9 ] = MINIRGB_CTL( panf, panel, "" );

   w = CON_W( ctl[ 1 ] );
   w -= CON_LW( ctl[ 1 ] );

   bdr[ 0 ] = BORDER_CTL( panf, panel, "", w, 2 );
   bdr[ 1 ] = BORDER_CTL( panf, panel, "", w, 2 );

   x = CON_X( ctl[ 0 ] );
   x += CON_W( ctl[ 0 ] );
   x += CON_LW( ctl[ 8 ] ) + 8;
   y = CON_Y( ctl[ 0 ] );

   w = CON_LW( ctl[ 1 ] );
   MOVE_CON( ctl[ 1 ], x - w, y );

   w = CON_LW( ctl[ 2 ] );
   y += CON_HOTH( ctl[ 1 ] ) + 4;
   MOVE_CON( ctl[ 2 ], x - w, y );

   y += CON_HOTH( ctl[ 2 ] ) + 6;
   MOVE_CON( bdr[ 0 ], x, y );

   w = CON_LW( ctl[ 3 ] );
   y += 6;
   MOVE_CON( ctl[ 3 ], x - w, y );

   w = CON_X( ctl[ 3 ] );
   w += CON_W( ctl[ 3 ] );
   MOVE_CON( ctl[ 5 ], w + 16, y );

   w = CON_LW( ctl[ 4 ] );
   y += CON_HOTH( ctl[ 3 ] ) + 4;
   MOVE_CON( ctl[ 4 ], x - w, y );

   y += CON_HOTH( ctl[ 2 ] ) + 6;
   MOVE_CON( bdr[ 1 ], x, y );

   y += 6;
   for ( i = 6; i <= 9; i++ ) {
      w = CON_LW( ctl[ i ] );
      MOVE_CON( ctl[ i ], x - w, y );
      y += CON_HOTH( ctl[ i ] ) + 4;
   }

   y = CON_Y( ctl[ 9 ] );
   y += CON_H( ctl[ 9 ] );
   PAN_SETH( panf, panel, y + ph );

   SET_STR( ctl[ 1 ], uwp->filename, sizeof( uwp->filename ));
   SET_INT( ctl[ 2 ], uwp->saver );
   SET_INT( ctl[ 3 ], uwp->width );
   SET_INT( ctl[ 4 ], uwp->height );
   SET_INT( ctl[ 6 ], uwp->fgoptions );
   SET_INT( ctl[ 8 ], uwp->bgoptions );
   SETV_IVEC( ctl[ 7 ], uwp->fgcolor );
   SETV_IVEC( ctl[ 9 ], uwp->bgcolor );

   CON_SETEVENT( ctl[ 0 ], tree_event, root );
   CON_SETEVENT( ctl[ 2 ], saver_event, ctl[ 1 ] );
   CON_SETEVENT( ctl[ 5 ], sizebtn_event, ctl );

   ok = panf->open( panel, PANF_BLOCKING | PANF_CANCEL );

   if ( ok ) {
      GET_STR( ctl[ 1 ], uwp->filename, sizeof( uwp->filename ));
      GET_INT( ctl[ 2 ], uwp->saver );
      GET_INT( ctl[ 3 ], uwp->width );
      GET_INT( ctl[ 4 ], uwp->height );
      GET_INT( ctl[ 6 ], uwp->fgoptions );
      GET_INT( ctl[ 8 ], uwp->bgoptions );
      GETV_IVEC( ctl[ 7 ], uwp->fgcolor );
      GETV_IVEC( ctl[ 9 ], uwp->bgcolor );

      ctl[ 0 ]->get( ctl[ 0 ], CTL_VALUE, &ival );
      if ( !getsel_tree( uwp, ( Node * ) ival.ptr.ptr )) {
         msgf->error( "No texture layer selected", NULL );
         ok = 0;
      }
   }

   PAN_KILL( panf, panel );

   free_tree( root, 1 );
   return ok;
}
Exemplo n.º 20
0
Arquivo: list.c Projeto: irori/8cc
List *list_copy(List *list) {
    List *r = make_list();
    for (Iter *i = list_iter(list); !iter_end(i);)
        list_push(r, iter_next(i));
    return r;
}
Exemplo n.º 21
0
Arquivo: list.c Projeto: irori/8cc
List *make_list1(void *e) {
    List *r = make_list();
    list_push(r, e);
    return r;
}
Exemplo n.º 22
0
Arquivo: list.c Projeto: irori/8cc
List *list_reverse(List *list) {
    List *r = make_list();
    for (Iter *i = list_iter(list); !iter_end(i);)
        list_unshift(r, iter_next(i));
    return r;
}
Exemplo n.º 23
0
Arquivo: sp6.c Projeto: dtzWill/SVF
void main() {
    list l = make_list(10);
    free_list(l);
}
Exemplo n.º 24
0
/** Create a list of surfaces.
 */
list356_t* get_surfaces() {

    list356_t* surfaces = make_list() ;

    // Table.
    point3_t vertices[8] = {
        {0, 0, 1}, {8, 0, 1}, {0, 8, 1}, {8, 8, 1},
        {0, 0, -1}, {8, 0, -1}, {0, 8, -1}, {8, 8, -1},
    } ;

    int indices[] = {
        0, 1, 3,    0, 3, 2,        // top
        0, 2, 6,    0, 6, 4,        // left
        4, 6, 7,    4, 7, 5,        // bottom
        1, 5, 7,    1, 7, 3,        // right
        2, 3, 7,    2, 7, 6,        // back
        0, 4, 5,    0, 5, 1         // front
    } ;
    int top_offset = 6 ;
    int offset = 36 ;

    list356_t* table_surfaces = make_list() ;
    for (int i=0; i<top_offset/3; ++i) {
        lst_add(table_surfaces, make_triangle(
                    vertices[indices[3*i]],
                    vertices[indices[3*i+1]],
                    vertices[indices[3*i+2]],
                    &RED, &RED, &WHITE, 10.0f)) ;
    }
    for (int i=top_offset/3; i<offset/3; ++i) {
        lst_add(table_surfaces, make_triangle(
                    vertices[indices[3*i]],
                    vertices[indices[3*i+1]],
                    vertices[indices[3*i+2]],
                    &GREEN, &GREEN, &WHITE, 10.0f)) ;
    }

    // Two purple spheres.
    lst_add(table_surfaces, 
            make_sphere(6, 6, 1.75+.01, .75, 
                &PURPLE, &PURPLE, &WHITE, 100.0f)) ;
    lst_add(table_surfaces, 
            make_sphere(5, 2, 1.75+.01, .75, 
                &PURPLE, &PURPLE, &WHITE, 100.0f)) ;

    // Transparent cube.
    point3_t cube_vertices[] = {
            {4, 0, 3}, {5, 0, 3}, {4, 1, 3}, {5, 1, 3},
            {4, 0, 1.01}, {5, 0, 1.01}, {4, 1, 1.01}, {5, 1, 1.01},
    } ;
    for (int i=0; i<offset/3; ++i) {
        surface_t* t = make_triangle(
                    cube_vertices[indices[3*i]],
                    cube_vertices[indices[3*i+1]],
                    cube_vertices[indices[3*i+2]],
                    &BLACK, &BLACK, &WHITE, 10.0f) ;
        t->refr_index = 1.1f ;
        t->atten = &GREENISH ;
        lst_add(surfaces, t) ;
    }

    list356_itr_t* itr = lst_iterator(table_surfaces) ;
    while (lst_has_next(itr)) lst_add(surfaces, lst_next(itr)) ;
    lst_free(table_surfaces) ;

    // Plane at z=-1.
    surface_t* plane = make_plane(
                (point3_t){0, 0, -1},
                (point3_t){1, 0, -1},
                (point3_t){1, 1, -1},
                &LIGHT_GREY, &LIGHT_GREY, &BLACK, 10.0f) ;
    plane->refl_color = &LIGHT_GREY ;
    lst_add(surfaces, plane) ;

    return surfaces ;

}
constexpr list<T, sizeof...(U) + 1> make_list(T head, U... args)
{
 return {head, make_list(args...)};
}
   // ----------------------------------------------------------------------
      // ----------------------------------------------------------------------
   std::string 
      WisemlScenarioCollector::generate_timestamp_xml(double timestamp) 
      const
   {
      std::stringstream wml;
      std::map<string, NodeTemplate*> nodes;
      std::map<string, pair<LinkInfo*, bool> > links;
      std::multimap<double, std::string>::const_iterator ts_begin = 
         items_.lower_bound(timestamp);
      std::multimap<double, std::string>::const_iterator ts_end = 
         items_.upper_bound(timestamp);

      for(std::multimap<double, std::string>::const_iterator it = ts_begin;
         it != ts_end; ++it)
      {
         std::list<std::string> data(make_list(it->second));
         list<string>::iterator dit = data.begin();
         std::string datatype = dit->c_str();
         
         if(datatype == "en")
         {
            ++dit;
            std::string label = dit->c_str();
            wml << "\t\t<enablenode id=\"" << label << "\"/>" << std::endl;
         }
         else if(datatype == "dn")
         {
            ++dit;
            std::string label = dit->c_str();
            wml << "\t\t<disablenode id=\"" << label << "\"/>" << std::endl;
         }
         else if(datatype == "el")
         {
            ++dit; std::string source = dit->c_str();
            ++dit; std::string target = dit->c_str();
            wml << "\t\t<enablelink source=\"" << source << "\"/>" << 
               "target=\"" << target << "\"/>" << std::endl;
         }
         else if(datatype == "dl")
         {
            ++dit; std::string source = dit->c_str();
            ++dit; std::string target = dit->c_str();
            wml << "\t\t<disablelink source=\"" << source << "\"/>" << 
               "target=\"" << target << "\"/>" << std::endl;
         }
         else if(datatype == "np")
         {
            ++dit;
            std::string label = dit->c_str();

            NodeTemplate *tmp;
            if(nodes.find(label) != nodes.end())
            {
               tmp = nodes.find(label)->second;
            }
            else
            {
               tmp = new NodeTemplate();
               nodes.insert(pair<string, NodeTemplate*>(label, tmp));
            }
            tmp->label = label;
            ++dit;
            tmp->posx = atof(dit->c_str());
            ++dit;
            tmp->posy= atof(dit->c_str());
            ++dit;
            tmp->posz = atof(dit->c_str());
            Capability dummy;
            dummy.name = "positioned";
            tmp->capabilities.push_front(dummy);
         }
         else if(datatype == "nc")
         {
            ++dit;
            std::string label = dit->c_str();

            NodeTemplate *tmp;
            if(nodes.find(label) != nodes.end())
            {
               tmp = nodes.find(label)->second;
            }
            else
            {
               tmp = new NodeTemplate();
               nodes.insert(pair<string, NodeTemplate*>(label, tmp));
            }
            tmp->label = label;
            Capability cap;
            ++dit;
            cap.name = dit->c_str();
            ++dit;
            cap.def_value = dit->c_str();
            tmp->capabilities.push_back(cap);
         }
         /// Item syntax: lrssi;source_node;target_node;rssi_value
         else if(datatype == "lrssi")
         {
            ++dit;
            std::string src = dit->c_str();
            ++dit;
            std::string dst = dit->c_str();
            ++dit;
            std::string value = dit->c_str();
            LinkInfo *info;
            if(links.find(src + dst) != links.end())
            {
               info = links.find(src + dst)->second.first;
               links.find(src + dst)->second.second = true;
            }
            else
            {
               info = new LinkInfo();
               links.insert(pair<string, pair<LinkInfo*, bool> >(src+dst,
                  pair<LinkInfo*, bool>(info, true)));
            }
            info->source = src;
            info->target = dst;
            info->rssi = value;

         }
         /// Item syntax: 
         /// lc;source_node;target_node;capability_name;capability_value
         else if(datatype == "lc")
         {
            ++dit;
            std::string src = dit->c_str();
            ++dit;
            std::string dst = dit->c_str();
            LinkInfo *info;
            if(links.find(src + dst) != links.end())
            {
               info = links.find(src + dst)->second.first;
            }
            else
            {
               info = new LinkInfo();
               links.insert(pair<string, pair<LinkInfo*, bool> >(src+dst,
                  pair<LinkInfo*, bool>(info, false)));
            }
            info->source = src;
            info->target = dst;
            Capability cap;
            ++dit;
            cap.name = dit->c_str();;
            ++dit;
            cap.def_value = dit->c_str();
            info->capabilities.push_back(cap);
         }

         
      }

      for(map<string, NodeTemplate*>::iterator it = nodes.begin();
         it != nodes.end(); ++it)
      {
         wml << "\t\t<node id=\"" << it->second->label << "\">" << std::endl;
         if(it->second->capabilities.front().name == "positioned")
         {
            wml << "\t\t\t<position>" << std::endl;
            wml << "\t\t\t\t<x>" << it->second->posx << "</x>" << std::endl;
            wml << "\t\t\t\t<y>" << it->second->posy << "</y>" << std::endl;
            wml << "\t\t\t\t<z>" << it->second->posz << "</z>" << std::endl;
            wml << "\t\t\t</position>" << std::endl;
         }

         for(CapList::iterator cit = it->second->capabilities.begin();
            cit != it->second->capabilities.end(); ++cit)
         {
            if(cit->name != "positioned")
               wml << "\t\t\t<data key=\"" << cit->name << "\">" << 
                  cit->def_value << "</data>" << std::endl;
         }
         wml << "\t\t</node>" << std::endl;
      }

      for(map<string, pair<LinkInfo*,bool> >::iterator it = links.begin();
         it != links.end(); ++it)
      {
         wml << "\t\t<link source=\"" << it->second.first->source << "\" "
            << "target=\"" << it->second.first->target << "\">"
            << std::endl;
         if(it->second.second)
         {
            wml << "\t\t\t<rssi>" << it->second.first->rssi << "</rssi>"
               << std::endl;
         }

         for(CapList::iterator cit = it->second.first->capabilities.begin();
            cit != it->second.first->capabilities.end(); ++cit)
         {
            wml << "\t\t\t<data key=\"" << cit->name << "\">" << 
               cit->def_value << "</data>" << std::endl;
         }
         wml << "\t\t</link>" << std::endl;
      }
      
      return wml.str();
   }
Exemplo n.º 27
0
void rg(list356_t* surfaces, point3_t* eye, point3_t* look_at) {
    //update eye and look_at positions
    point3_t eye_position = {4.0f, -4.0f, 8.0f} ;
    point3_t look_at_point = {4.0f, 4.0f, 1.0f} ;
    *eye = eye_position;
    *look_at = look_at_point;

    // Chess board.
    list356_t* board_surfaces = make_list() ;

    // All the vertices.
    point3_t vertices[85] ;
    for (int x=0; x<9; ++x) {
        for (int y=0; y<9; ++y) {
            vertices[9*y+x] = (point3_t){x, y, 1} ;
        }
    }
    vertices[81] = (point3_t){0, 0, -1} ;
    vertices[82] = (point3_t){8, 0, -1} ;
    vertices[83] = (point3_t){0, 8, -1} ;
    vertices[84] = (point3_t){8, 8, -1} ;

    int indices[138*3] ;
    int offset = 0 ;

    // Top of chess board.
    for (int x=0; x<8; ++x) {
        for (int y=0; y<8; ++y) {
            indices[offset++] = 9*y+x ;
            indices[offset++] = 9*y+x+1 ;
            indices[offset++] = 9*(y+1)+x+1 ;
            indices[offset++] = 9*y+x ;
            indices[offset++] = 9*(y+1)+x+1 ;
            indices[offset++] = 9*(y+1)+x ;
        }
    }
    int top_offset = offset ;

    // Sides and bottom.
    indices[offset++] = 81 ; indices[offset++] = 82; indices[offset++] = 8 ;
    indices[offset++] = 81 ; indices[offset++] = 8; indices[offset++] = 0 ;

    indices[offset++] = 8 ; indices[offset++] = 82 ; indices[offset++] = 84 ;
    indices[offset++] = 8 ; indices[offset++] = 84 ; indices[offset++] = 80 ;

    indices[offset++] = 72 ; indices[offset++] = 80 ; indices[offset++] = 84 ;
    indices[offset++] = 72 ; indices[offset++ ] = 84 ; indices[offset++] = 83 ;

    indices[offset++] = 0 ; indices[offset++] = 72 ; indices[offset++] = 83 ;
    indices[offset++] = 0 ; indices[offset++] = 83 ; indices[offset++] = 81 ;

    indices[offset++] = 81 ; indices[offset++] = 83 ; indices[offset++] =84 ;
    indices[offset++] = 81 ; indices[offset++] = 84 ; indices[offset++] = 82 ;
    debug("get_surfaces():  final offset = %d", offset) ;

    // Top as triangles.
    for (int i=0; i<top_offset/3; ++i) {
        int c = (i/2)%8 ;
        int r = (i/2)/8 ;
        int j = r+c ;
        color_t* color = j%2 == 0 ? &RED : &BLACK ;
        lst_add(board_surfaces, make_triangle(
                    vertices[indices[3*i]],
                    vertices[indices[3*i+1]],
                    vertices[indices[3*i+2]],
                    color, color, &WHITE, 10.0f)) ;
    }
    // Sides and bottom at triangles.
    for (int i=top_offset/3; i<offset/3; ++i) {
        lst_add(board_surfaces, make_triangle(
                    vertices[indices[3*i]],
                    vertices[indices[3*i+1]],
                    vertices[indices[3*i+2]],
                    &LIGHT_GREY, &LIGHT_GREY, &WHITE, 10.0f)) ;
    }

    //// "Pieces"
    //for (int c=0; c<8; ++c) {
    //    for (int r=0; r<2; ++r) {
    //        surface_t* s = make_sphere(c+.5, r+.5, 1.375+.01, .375,
    //                &BLACK, &BLACK, &WHITE, 100.0f) ;
    //        lst_add(board_surfaces, s) ;
    //    }
    //    //for (int r=6; r<8; ++r) {
    //    //    lst_add(board_surfaces, make_sphere(c+.5, r+.5, 1.25, .25,
    //    //                &WHITE, &WHITE, &WHITE, 100.0f)) ;
    //    //}
    //}

    // Draw R manually
    // Define squares to place spheres on

    void add_sphere(c,r) {
        lst_add(board_surfaces, make_sphere(c+.5, r+.5, 1.75, .50,
                    &GREEN, &GREEN, &BLACK, 150.0f)) ;
    }
Exemplo n.º 28
0
Arquivo: copy.c Projeto: Enouk/iErl14
/* Copy a message to the message area. */
Eterm copy_struct_lazy(Process *from, Eterm orig, Uint offs)
{
    Eterm obj;
    Eterm dest;
#ifdef INCREMENTAL
    int alloc_old = 0;
#else
    int total_need = 0;
#endif

    VERBOSE(DEBUG_MESSAGES,
            ("COPY START; %T is sending a message @ 0x%016x\n%T\n",
             from->id, orig, orig));

#ifndef INCREMENTAL
 copy_start:
#endif
    MA_STACK_PUSH(src,orig);
    MA_STACK_PUSH(dst,&dest);
    MA_STACK_PUSH(offset,offs);

    while (ma_src_top > 0) {
        obj = MA_STACK_POP(src);

        /* copy_struct_lazy should never be called with something that
         * do not need to be copied. Within the loop, nothing that do
         * not need copying should be placed in the src-stack.
         */
        ASSERT(!NO_COPY(obj));

        switch (primary_tag(obj)) {
        case TAG_PRIMARY_LIST: {
            Eterm *hp;
            Eterm *objp;

            GlobalAlloc(from,2,hp);
            objp = list_val(obj);

            MA_STACK_UPDATE(dst,MA_STACK_POP(offset),make_list(hp));
            MA_STACK_POP(dst);

            /* TODO: Byt ordningen nedan så att CDR pushas först. */

            if (NO_COPY(*objp)) {
                hp[0] = *objp;
#ifdef INCREMENTAL
                if (ptr_within(ptr_val(*objp),inc_fromspc,inc_fromend))
                    INC_STORE(gray,hp,2);
#endif
            } else {
                MA_STACK_PUSH(src,*objp);
                MA_STACK_PUSH(dst,hp);
                MA_STACK_PUSH(offset,0);
            }

            objp++;

            if (NO_COPY(*objp)) {
                hp[1] = *objp;
#ifdef INCREMENTAL
                if (ptr_within(ptr_val(*objp),inc_fromspc,inc_fromend))
                    INC_STORE(gray,hp,2);
#endif
            }
            else {
                MA_STACK_PUSH(src,*objp);
                MA_STACK_PUSH(dst,hp);
                MA_STACK_PUSH(offset,1);
            }
            continue;
        }

        case TAG_PRIMARY_BOXED: {
            Eterm *objp = boxed_val(obj);

            switch (*objp & _TAG_HEADER_MASK) {
            case ARITYVAL_SUBTAG: {
                Uint ari = arityval(*objp);
                Uint i;
                Eterm *hp;
                GlobalAlloc(from,ari + 1,hp);
                /* A GC above might invalidate the value of objp */
                objp = boxed_val(obj);
                MA_STACK_UPDATE(dst,MA_STACK_POP(offset),make_tuple(hp));
                MA_STACK_POP(dst);
                *hp = *objp++;
                for (i = 1; i <= ari; i++) {
                    switch (primary_tag(*objp)) {
                    case TAG_PRIMARY_LIST:
                    case TAG_PRIMARY_BOXED:
                        if (NO_COPY(*objp)) {
                            hp[i] = *objp;
#ifdef INCREMENTAL
                            if (ptr_within(ptr_val(*objp),
                                           inc_fromspc,inc_fromend))
                                INC_STORE(gray,hp,BOXED_NEED(hp,*hp));
#endif
                            objp++;
                        } else {
                            MA_STACK_PUSH(src,*objp++);
                            MA_STACK_PUSH(dst,hp);
                            MA_STACK_PUSH(offset,i);
                        }
                        break;
                    default:
                        hp[i] = *objp++;
                    }
                }
                continue;
            }

            case REFC_BINARY_SUBTAG: {
                ProcBin *pb;
                Uint i = thing_arityval(*objp) + 1;
                Eterm *hp;
                GlobalAlloc(from,i,hp);
                /* A GC above might invalidate the value of objp */
                objp = boxed_val(obj);
                MA_STACK_UPDATE(dst,MA_STACK_POP(offset),make_binary(hp));
                MA_STACK_POP(dst);
                pb = (ProcBin*) hp;
                while (i--) {
                    *hp++ = *objp++;
                }
                erts_refc_inc(&pb->val->refc, 2);
                pb->next = erts_global_offheap.mso;
                erts_global_offheap.mso = pb;
                erts_global_offheap.overhead += pb->size / sizeof(Eterm);
                continue;
            }

            case FUN_SUBTAG: {
                ErlFunThing *funp = (ErlFunThing*) objp;
                Uint i = thing_arityval(*objp) + 1;
                Uint j = i + 1 + funp->num_free;
                Uint k = i;
                Eterm *hp, *hp_start;
                GlobalAlloc(from,j,hp);
                /* A GC above might invalidate the value of objp */
                objp = boxed_val(obj);
                hp_start = hp;
                MA_STACK_UPDATE(dst,MA_STACK_POP(offset),make_fun(hp));
                MA_STACK_POP(dst);
                funp = (ErlFunThing*) hp;
                while (i--) {
                    *hp++ = *objp++;
                }
#ifndef HYBRID // FIND ME!
                funp->next = erts_global_offheap.funs;
                erts_global_offheap.funs = funp;
                erts_refc_inc(&funp->fe->refc, 2);
#endif
                for (i = k; i < j; i++) {
                    switch (primary_tag(*objp)) {
                    case TAG_PRIMARY_LIST:
                    case TAG_PRIMARY_BOXED:
                        if (NO_COPY(*objp)) {
#ifdef INCREMENTAL
                            if (ptr_within(ptr_val(*objp),
                                           inc_fromspc,inc_fromend))
                                INC_STORE(gray,hp,BOXED_NEED(hp,*hp));
#endif
                            *hp++ = *objp++;
                        } else {
                            MA_STACK_PUSH(src,*objp++);
                            MA_STACK_PUSH(dst,hp_start);
                            MA_STACK_PUSH(offset,i);
                            hp++;
                        }
                        break;
                    default:
                        *hp++ = *objp++;
                    }
                }
                continue;
            }

            case EXTERNAL_PID_SUBTAG:
            case EXTERNAL_PORT_SUBTAG:
            case EXTERNAL_REF_SUBTAG: {
                ExternalThing *etp;
                Uint i =  thing_arityval(*objp) + 1;
                Eterm *hp;
                GlobalAlloc(from,i,hp);
                /* A GC above might invalidate the value of objp */
                objp = boxed_val(obj);
                MA_STACK_UPDATE(dst,MA_STACK_POP(offset),make_external(hp));
                MA_STACK_POP(dst);
                etp = (ExternalThing*) hp;
                while (i--)  {
                    *hp++ = *objp++;
                }

                etp->next = erts_global_offheap.externals;
                erts_global_offheap.externals = etp;
		erts_refc_inc(&etp->node->refc, 2);
                continue;
            }

            case SUB_BINARY_SUBTAG: {
                ErlSubBin *sb = (ErlSubBin *) objp;
		Eterm *hp;
		Eterm res_binary;
                Eterm real_bin = sb->orig;
                Uint bit_offset = sb->bitoffs;
		Uint bit_size = sb -> bitsize;
		Uint sub_offset = sb->offs;
                size_t size = sb->size;
		Uint extra_bytes;
		Uint real_size;
		Uint sub_binary_heapneed;
		if ((bit_size + bit_offset) > 8) {
		    extra_bytes = 2;
		    sub_binary_heapneed = ERL_SUB_BIN_SIZE;
		} else if ((bit_size + bit_offset) > 0) {
		    extra_bytes = 1;
		    sub_binary_heapneed = ERL_SUB_BIN_SIZE;
		} else {
		    extra_bytes = 0;
		    sub_binary_heapneed = 0;
		}
		
		real_size = size+extra_bytes;
                objp = binary_val(real_bin);
                if (thing_subtag(*objp) == HEAP_BINARY_SUBTAG) {
                    ErlHeapBin *from_bin;
                    ErlHeapBin *to_bin;
                    Uint i = heap_bin_size(real_size);
                    GlobalAlloc(from,i+sub_binary_heapneed,hp);
                    from_bin = (ErlHeapBin *) objp;
                    to_bin = (ErlHeapBin *) hp;
                    to_bin->thing_word = header_heap_bin(real_size);
                    to_bin->size = real_size;
                    sys_memcpy(to_bin->data, ((byte *)from_bin->data) +
                               sub_offset, real_size);
		    res_binary = make_binary(to_bin);
		    hp += i;
                } else {
                    ProcBin *from_bin;
                    ProcBin *to_bin;
                    
                    ASSERT(thing_subtag(*objp) == REFC_BINARY_SUBTAG);
		    from_bin = (ProcBin *) objp;
		    erts_refc_inc(&from_bin->val->refc, 2);
                    GlobalAlloc(from,PROC_BIN_SIZE+sub_binary_heapneed,hp);
                    to_bin = (ProcBin *) hp;
                    to_bin->thing_word = HEADER_PROC_BIN;
                    to_bin->size = real_size;
                    to_bin->val = from_bin->val;
                    to_bin->bytes = from_bin->bytes + sub_offset;
                    to_bin->next = erts_global_offheap.mso;
                    erts_global_offheap.mso = to_bin;
                    erts_global_offheap.overhead += to_bin->size / sizeof(Eterm);
		    res_binary=make_binary(to_bin);
		    hp += PROC_BIN_SIZE;
                }
		if (extra_bytes != 0) {
		    ErlSubBin* res;
		    res = (ErlSubBin *) hp;
		    res->thing_word = HEADER_SUB_BIN;
		    res->size = size;
		    res->bitsize = bit_size;
		    res->bitoffs = bit_offset;
		    res->offs = 0;
		    res->is_writable = 0;
		    res->orig = res_binary;
		    res_binary = make_binary(hp);
		}
		MA_STACK_UPDATE(dst,MA_STACK_POP(offset),res_binary);
		MA_STACK_POP(dst);
                continue;
            }

	    case BIN_MATCHSTATE_SUBTAG:
		erl_exit(ERTS_ABORT_EXIT,
			 "copy_struct_lazy: matchstate term not allowed");

            default: {
                Uint size = thing_arityval(*objp) + 1;
                Eterm *hp;
                GlobalAlloc(from,size,hp);
                /* A GC above might invalidate the value of objp */
                objp = boxed_val(obj);
                MA_STACK_UPDATE(dst,MA_STACK_POP(offset),make_boxed(hp));
                MA_STACK_POP(dst);
                while (size--) {
                    *hp++ = *objp++;
                }
                continue;
            }
            }
            continue;
        }

        case TAG_PRIMARY_HEADER:
        ASSERT((obj & _TAG_HEADER_MASK) == ARITYVAL_SUBTAG);
        {
            Eterm *objp = &obj;
            Uint ari = arityval(obj);
            Uint i;
            Eterm *hp;
            GlobalAlloc(from,ari + 1,hp);
            MA_STACK_UPDATE(dst,MA_STACK_POP(offset),make_tuple(hp));
            MA_STACK_POP(dst);
            *hp = *objp++;
            for (i = 1; i <= ari; i++) {
                switch (primary_tag(*objp)) {
                case TAG_PRIMARY_LIST:
                case TAG_PRIMARY_BOXED:
                    if (NO_COPY(*objp)) {
#ifdef INCREMENTAL
                        if (ptr_within(ptr_val(*objp),inc_fromspc,inc_fromend))
                            INC_STORE(gray,hp,ari + 1);
#endif
                        hp[i] = *objp++;
                    } else {
                        MA_STACK_PUSH(src,*objp++);
                        MA_STACK_PUSH(dst,hp);
                        MA_STACK_PUSH(offset,i);
                    }
                    break;
                default:
                    hp[i] = *objp++;
                }
            }
            continue;
        }

        default:
            erl_exit(ERTS_ABORT_EXIT,
		     "%s, line %d: Internal error in copy_struct_lazy: 0x%08x\n",
                     __FILE__, __LINE__,obj);
        }
    }

    VERBOSE(DEBUG_MESSAGES,
            ("Copy allocated @ 0x%08lx:\n%T\n",
             (unsigned long)ptr_val(dest),dest));

    ma_gc_flags &= ~GC_CYCLE_START;

    ASSERT(eq(orig, dest));
    ASSERT(ma_src_top == 0);
    ASSERT(ma_dst_top == 0);
    ASSERT(ma_offset_top == 0);
    return dest;
}
Exemplo n.º 29
0
/** Build the maze by removing walls according to Prim's algorithm.
 *
 *  @param maze a maze with all walls present.
 */
static void build_prim(maze_t* maze) {
    // MST edges and cells.  If (a, b) in mst_edges, then (b, a) not in
    // mst_edges.  (a, b) in mst_edges iff a, b both in mst_cells.
    list356_t* mst_edges = make_list() ;
    list356_t* mst_cells = make_list() ;

    // The frontier.  This is the collection of edges between cells in the MST
    // and cells not in the MST.  If (a, b) in frontier, then a in mst_cells
    // and b not in mst_cells.
    list356_t* frontier = make_list() ;

    // Choose two adjacent cells at random to put into the MST, then
    // populate the frontier accordinately.  For simplicitly, choose a
    // cell in the interior of the maze, then randomly choose a direction
    // for the other cell.
    cell_t* start = 
        get_cell(maze, random_limit(1, maze->nrows-1), 
                random_limit(1, maze->ncols-1));
    unsigned char direction = 1 << random_limit(0, 4) ;

    cell_t* next = get_neighbor(maze, start, direction) ;
    /*
    debug("Removing (%d, %d) - (%d, %d).\n",
            start->r, start->c, next->r, next->c) ;
    */
    remove_wall(maze, start, direction) ;

    edge_t init_edge = (edge_t){start, next} ;
    lst_add(mst_edges, &init_edge) ;
    lst_add(mst_cells, start) ;
    lst_add(mst_cells, next) ;

    for (int d=0; d<4; ++d) {
        if (directions[d] != direction && is_cell(maze, start, directions[d])) {
            cell_t* c = get_neighbor(maze, start, directions[d]) ;
            edge_t* e = malloc(sizeof(edge_t)) ;
            e->a = start ; e->b = c ;
            lst_add(frontier, e) ;
        }
    }

    for (int d=0; d<4; ++d) {
        if (directions[d] != opposite(direction) 
                && is_cell(maze, next, directions[d])) {
            cell_t* c = get_neighbor(maze, next, directions[d]) ;
            edge_t* e = malloc(sizeof(edge_t)) ;
            e->a = next ; e->b = c ;
            lst_add(frontier, e) ;
        }
    }

    // As long as we don't have all the cells in the MST, choose an
    // edge in the frontier at random.  Put the edge in the MST
    // and compute the new edges to add to the frontier.
    while (lst_size(mst_cells) < (maze->nrows)*(maze->ncols)) {
        int p = random_limit(0, lst_size(frontier)) ;
        edge_t* edge = lst_get(frontier, p) ;
        cell_t* old_cell = edge->a ;
        cell_t* new_cell = edge->b ;
        /*
        debug("Removing (%d, %d) - (%d, %d).\n",
                old_cell->r, old_cell->c, new_cell->r, new_cell->c) ;
        */
        remove_wall(maze, old_cell, get_direction(old_cell, new_cell)) ;

        lst_add(mst_edges, edge) ;
        lst_add(mst_cells, new_cell) ;

        for (int d=0; d<4; ++d) {
            unsigned char dir = directions[d] ;
            if (is_cell(maze, new_cell, dir)) {
                cell_t* adj_cell = get_neighbor(maze, new_cell, dir) ;
                edge_t* edge2 = malloc(sizeof(edge_t)) ;
                edge2->a = new_cell ; edge2->b = adj_cell ;
                if (lst_contains(mst_cells, adj_cell, cell_cmp)) {
                    lst_remove(frontier, edge2, edge_cmp) ;
                    if (adj_cell != old_cell) free(edge2) ;
                }
                else {
                    lst_add(frontier, edge2) ;
                }
            }
        }
    }


}
Exemplo n.º 30
0
void main() {
  // Test construction of a pair
  
  // Test car
  pair *a = cons(42, NULL);
  printf("\nExpected: 42 ==> %d\n", car(a));
  
  // Test cdr
  pair *b = cons(42, cons(43, NULL));
  pair *c = cdr(b);
  printf("\nExpected: 43 ==> %d\n", car(c));
  
  // Test empty
  pair *d = NULL;
  printf("\nExpected: 1 ==> %d\n", emptyp(d));
  
  // Test length
  pair *e = cons(42, cons(43, cons(44, NULL)));
  printf("\nExpected: 3 ==> %d\n", length(e));
  
  // Test list
  printf("\nExpected: (1 2 3) ==> ");
  print_list(list(1, 2, 3, NULL));
  
  // Test make_list
  printf("\nExpected: (42 42 42) ==> ");
  print_list(make_list(3, 42));
  
  // Test iota
  printf("\nExpected: (0 1 2) ==> ");
  print_list(iota(3));
  
  // Test reverse
  pair * g = list(1, 2, 3, 4, 5, NULL);
  printf("\nExpected: (1 2 3 4 5) ==> ");
  print_list(g);
  printf("\nExpected: (5 4 3 2 1) ==> ");
  print_list(reverse(g));

  // Test print_list
  printf("\nExpected: (1 2 3) ==> ");
  print_list(list(1, 2, 3, NULL));

  // Test drop
  printf("\nExpected: (4 5) ==> ");
  print_list(drop(g, 3));
  
  // Test take
  printf("\nExpected: (1 2 3) ==> ");
  print_list(take(g, 3));
  
  // Test list_ref
  printf("\nExpected: 4 ==> %d\n", list_ref(g, 3));

  // Test map
  pair *h = map(g, dub);
  printf("\nExpected: (2 4 6 8 10) ==> ");
  print_list(h);

  // Test filter
  pair *i = filter(g, even);
  printf("\nExpected: (2 4) ==> ");
  print_list(i);
  
  // Test member
  printf("\nExpected: (3 4 5) ==> ");
  print_list(member(g, 3));
  
  
}