예제 #1
0
int	main(int	argc,
         char	**argv,
         char	**envp)
{
    t_env	*env;
    char	*line;

    env = get_env_list(envp);
    if (argc > 1)
        handle_options(argv, env);
    signal(SIGINT, &sig_handler);
    while (42)
    {
        prompt(env);
        line = get_next_line(0);
        if (line == NULL || line_isblank(line))
        {
            if (line == NULL)
                my_putchar('\n');
            continue;
        }
        else if (my_strcmp(line, "exit") == 0)
            break;
        else
            mysh_cmdparse(line, &env);
        free(line);
    }
    free_env(env);
    return (0);
}
예제 #2
0
void gc_orig(BOOLEAN force, BOOLEAN clear_black)
{
  static unsigned long count = 0;

  if(!can_do_gc)
    return;

  //no new objects were created since the
  //last GC cycle, so nothing to do.
  if(is_set_empty(WHITE))
    return;

  //do GC every GC_FREQUENCYth time called
  if((count % GC_FREQUENCY) != 0)
    return;

  //printf("Entering GC cycle... ");

  unsigned int dealloc_words = memory_deallocated();

  //assert(is_set_empty(GREY));

  build_grey_set();

  assert(!is_set_empty(GREY));

  while(!is_set_empty(GREY))
  {
    OBJECT_PTR obj = get_an_object_from_grey();

    assert(is_dynamic_memory_object(obj));

    //FUNCTION2 and MACRO2 objects are handled
    //by handling their undelying CONS objects
    if(!IS_FUNCTION2_OBJECT(obj) && !IS_MACRO2_OBJECT(obj))
      insert_node(BLACK, obj);

    remove_node(GREY, obj);

    if(IS_CONS_OBJECT(obj))
    {
      move_from_white_to_grey(car(obj));
      move_from_white_to_grey(cdr(obj));
    }
    else if(IS_CLOSURE_OBJECT(obj) || IS_MACRO_OBJECT(obj))
    {
      move_from_white_to_grey(get_env_list(obj));
      move_from_white_to_grey(get_params_object(obj));
      move_from_white_to_grey(get_body_object(obj));
      move_from_white_to_grey(get_source_object(obj));
    }
    else if(IS_ARRAY_OBJECT(obj))
    {
      uintptr_t ptr = extract_ptr(obj);

      //OBJECT_PTR length_obj = get_heap(ptr, 0);

      //move_from_white_to_grey(length_obj);

      //int len = get_int_value(length_obj);
      int len = *((OBJECT_PTR *)ptr);

      int i;

      for(i=1; i<=len; i++)
        move_from_white_to_grey(get_heap(ptr, i));
    }
    else if(IS_CONTINUATION_OBJECT(obj))
      move_from_white_to_grey(get_heap(extract_ptr(obj), 0));
    else if(IS_FUNCTION2_OBJECT(obj) || IS_MACRO2_OBJECT(obj))
    {
      OBJECT_PTR cons_equiv = cons_equivalent(obj);
      //move_from_white_to_grey(car(cons_equiv));
      //move_from_white_to_grey(cdr(cons_equiv));
      move_from_white_to_grey(cons_equiv);
    }
  } //end of while(!is_set_empty(GREY))

  free_white_set_objects();

  assert(is_set_empty(GREY));
  assert(is_set_empty(WHITE));

  assert(!is_set_empty(BLACK));

  /* if(clear_black) */
    /* recreate_black(); */

  /* if(clear_black) */
  /*   assert(is_set_empty(BLACK)); */

  //printf("%d words deallocated in current GC cycle\n", memory_deallocated() - dealloc_words);
}