Exemplo n.º 1
0
static void *make_stack_copy_rec(intptr_t size)
{
  CopiedStack *cs, **lk;

  cs = MALLOC_ONE(CopiedStack);
  cs->size = size;
  lk = MALLOC_LINK();
  cs->next = lk;
  lk = MALLOC_LINK();
  cs->prev = lk;


  /* double linked list push */
  *cs->next = *first_copied_stack;
  if (*first_copied_stack)
    *(*first_copied_stack)->prev = cs;
  *cs->prev = NULL;
  *first_copied_stack = cs;

  GC_register_finalizer(cs, remove_cs, NULL, NULL, NULL);

  scheme_num_copied_stacks++;

  return (void *)cs;
}
Exemplo n.º 2
0
cfg_t *cfg_alloc() {
	cfg_t *ret = MALLOC_ONE(cfg_t);
	int capacity = 5;
	ret->non_terminals = list_alloc(capacity, sizeof(token_t));
	ret->terminals = list_alloc(capacity, sizeof(token_t));
	ret->start_symbols = list_alloc(capacity, sizeof(token_t));
	ret->rule_list = list_alloc(capacity, sizeof(cfg_rule_t));
	return ret;
}
Exemplo n.º 3
0
/** 分配一个可用的结点 */
static LinkedListNode *LinkedList_AllocNode( LinkedList *list )
{
        if( !list->usable_head_node ) {
		list->usable_head_node = MALLOC_ONE(LinkedListNode);
		list->usable_head_node->next = NULL;
		list->usable_head_node->prev = NULL;
		list->usable_head_node->data = NULL;
		++list->usable_node_num;
        }

        ++list->used_node_num;
	--list->usable_node_num;

	if( !list->used_head_node ) {
		list->used_head_node = list->usable_head_node;
		list->usable_head_node = list->usable_head_node->next;
		if( list->usable_head_node ) {
			list->usable_head_node->prev = NULL;
		}
		list->used_head_node->next = NULL;
		list->used_tail_node = list->used_head_node;
		DEBUG_MSG("list->used_tail_node = %p\n", list->used_tail_node);
		list->current_node = list->used_head_node;
		list->current_node_pos = 0;
		return list->used_head_node;
	}
	
	DEBUG_MSG("list->used_tail_node = %p\n", list->used_tail_node);
	list->used_tail_node->next = list->usable_head_node;
	list->used_tail_node->next->prev = list->used_tail_node;
	list->usable_head_node = list->usable_head_node->next;
	if( list->usable_head_node ) {
		list->usable_head_node->prev = NULL;
	}
	list->used_tail_node = list->used_tail_node->next;
	DEBUG_MSG("list->used_tail_node = %p\n", list->used_tail_node);
	list->used_tail_node->next = NULL;
        return list->used_tail_node;
}
Exemplo n.º 4
0
Scheme_Object *scheme_place(int argc, Scheme_Object *args[]) {
  Scheme_Place          *place;
  Place_Start_Data      *place_data;
  mz_proc_thread        *proc_thread;
  Scheme_Object         *collection_paths;
  mzrt_sema             *ready;

  /* create place object */
  place = MALLOC_ONE_TAGGED(Scheme_Place);
  place->so.type = scheme_place_type;

  mzrt_sema_create(&ready, 0);

  /* pass critical info to new place */
  place_data = MALLOC_ONE(Place_Start_Data);
  place_data->ready    = ready;

  if (argc == 2) {
    Scheme_Object *so;

    if (!scheme_is_module_path(args[0]) && !SCHEME_PATHP(args[0])) {
      scheme_wrong_type("place", "module-path or path", 0, argc, args);
    }
    if (!SCHEME_SYMBOLP(args[1])) {
      scheme_wrong_type("place", "symbol", 1, argc, args);
    }

    so = scheme_places_deep_copy_to_master(args[0]);
    place_data->module   = so;
    so = scheme_places_deep_copy_to_master(args[1]);
    place_data->function = so;
    place_data->ready    = ready;
    
    /* create channel */
    {
      Scheme_Place_Bi_Channel *channel;
      channel = scheme_place_bi_channel_create();
      place->channel = (Scheme_Object *) channel;
      channel = scheme_place_bi_peer_channel_create(channel);
      place_data->channel = (Scheme_Object *) channel;
    }
  }
  else {
    scheme_wrong_count_m("place", 2, 2, argc, args, 0);
  }

  collection_paths = scheme_current_library_collection_paths(0, NULL);
  collection_paths = scheme_places_deep_copy_to_master(collection_paths);
  place_data->current_library_collection_paths = collection_paths;

  /* create new place */
  proc_thread = mz_proc_thread_create(place_start_proc, place_data);

  /* wait until the place has started and grabbed the value
     from `place_data'; it's important that a GC doesn't happen
     here until the other place is far enough. */
  mzrt_sema_wait(ready);
  mzrt_sema_destroy(ready);
  
  place->proc_thread = proc_thread;

  return (Scheme_Object*) place;
}
Exemplo n.º 5
0
cfg_rule_t *cfg_rule_alloc() {
	cfg_rule_t *ret = MALLOC_ONE(cfg_rule_t);
	ret->match_data = list_alloc(5, sizeof(match_list_t));
	ret->start_symbol = MALLOC_ONE(token_t);
	return ret;
}