コード例 #1
0
ファイル: enumerator.c プロジェクト: takuto-h/ruby
/* :nodoc: */
static VALUE
generator_initialize(int argc, VALUE *argv, VALUE obj)
{
    VALUE proc;

    if (argc == 0) {
	rb_need_block();

	proc = rb_block_proc();
    }
    else {
	rb_scan_args(argc, argv, "1", &proc);

	if (!rb_obj_is_proc(proc))
	    rb_raise(rb_eTypeError,
		     "wrong argument type %s (expected Proc)",
		     rb_obj_classname(proc));

	if (rb_block_given_p()) {
	    rb_warn("given block not used");
	}
    }

    return generator_init(obj, proc);
}
コード例 #2
0
ファイル: enumerator.c プロジェクト: takuto-h/ruby
/*
 * call-seq:
 *   Enumerator.new(size = nil) { |yielder| ... }
 *   Enumerator.new(obj, method = :each, *args)
 *
 * Creates a new Enumerator object, which can be used as an
 * Enumerable.
 *
 * In the first form, iteration is defined by the given block, in
 * which a "yielder" object, given as block parameter, can be used to
 * yield a value by calling the +yield+ method (aliased as +<<+):
 *
 *   fib = Enumerator.new do |y|
 *     a = b = 1
 *     loop do
 *       y << a
 *       a, b = b, a + b
 *     end
 *   end
 *
 *   p fib.take(10) # => [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
 *
 * The optional parameter can be used to specify how to calculate the size
 * in a lazy fashion (see Enumerator#size). It can either be a value or
 * a callable object.
 *
 * In the second, deprecated, form, a generated Enumerator iterates over the
 * given object using the given method with the given arguments passed.
 *
 * Use of this form is discouraged.  Use Kernel#enum_for or Kernel#to_enum
 * instead.
 *
 *   e = Enumerator.new(ObjectSpace, :each_object)
 *       #-> ObjectSpace.enum_for(:each_object)
 *
 *   e.select { |obj| obj.is_a?(Class) }  #=> array of all classes
 *
 */
static VALUE
enumerator_initialize(int argc, VALUE *argv, VALUE obj)
{
    VALUE recv, meth = sym_each;
    VALUE size = Qnil;

    if (rb_block_given_p()) {
	rb_check_arity(argc, 0, 1);
	recv = generator_init(generator_allocate(rb_cGenerator), rb_block_proc());
	if (argc) {
            if (NIL_P(argv[0]) || rb_obj_is_proc(argv[0]) ||
                (RB_TYPE_P(argv[0], T_FLOAT) && RFLOAT_VALUE(argv[0]) == INFINITY)) {
                size = argv[0];
            }
            else {
                size = rb_to_int(argv[0]);
            }
            argc = 0;
        }
    }
    else {
	rb_check_arity(argc, 1, UNLIMITED_ARGUMENTS);
	rb_warn("Enumerator.new without a block is deprecated; use Object#to_enum");
	recv = *argv++;
	if (--argc) {
	    meth = *argv++;
	    --argc;
	}
    }

    return enumerator_init(obj, recv, meth, argc, argv, 0, size);
}
コード例 #3
0
ファイル: main.c プロジェクト: IlievskiV/DMA-Workshop
int main(void) {
	e_iap_status iap_status;

	/* Fill the flash with payload and hash data */
	iap_status = (e_iap_status) generator_init();
	if (iap_status != CMD_SUCCESS)
		while (1)
			;   // Error !!!

	Details d;

	initButton();
    initDMA();
	initDetails(&d, getNumberOfChunks(), getSizeOfChunk());

	while (buttonIterrupt) {
	}

	int res = mainFunction(&d, 32);

	if(res==0) {
		blinkLed(1000000);
	}
	else {
		blinkLed(100);
	}


	return 0;
}
コード例 #4
0
ファイル: main.c プロジェクト: svartalf/fizz
int main(int argc, char* argv[]) {

	int option, option_idx;
	int worker_id = 0;
	int datacenter_id = 0;
	int port = 7954;

	while ((option = getopt_long(argc, argv, "w:d:p:", options, &option_idx)) != -1) {
		switch (option) {
			case 'w':
				worker_id = atoi(optarg);
				break;
			case 'd':
				datacenter_id = atoi(optarg);
				break;
			case 'p':
				port = atoi(optarg);
				break;
			case 'h':
			case '?':
				printf(help);
				exit(EXIT_FAILURE);
				break;
		}
	}

	Context ctx = generator_init(worker_id, datacenter_id);

	server_serve(ctx, port);

	return 0;
}
コード例 #5
0
ファイル: rsecc.c プロジェクト: BtbN/btsync-qt
int RSECC_encode(int data_length, int ecc_length, const unsigned char *data, unsigned char *ecc)
{
	int i, j;
	unsigned char feedback;
	unsigned char *gen;

	if(!initialized) {
		RSECC_init();
	}

	if(ecc_length > max_length) return -1;

	memset(ecc, 0, ecc_length);
	if(!generatorInitialized[ecc_length - min_length]) generator_init(ecc_length);
	gen = generator[ecc_length - min_length];

	for(i = 0; i < data_length; i++) {
		feedback = aindex[data[i] ^ ecc[0]];
		if(feedback != symbols) {
			for(j = 1; j < ecc_length; j++) {
				ecc[j] ^= alpha[(feedback + gen[ecc_length - j]) % symbols];
			}
		}
		memmove(&ecc[0], &ecc[1], ecc_length - 1);
		if(feedback != symbols) {
			ecc[ecc_length - 1] = alpha[(feedback + gen[0]) % symbols];
		} else {
			ecc[ecc_length - 1] = 0;
		}
	}

	return 0;
}
コード例 #6
0
ファイル: generator_writer_c.c プロジェクト: TracyHu/TDR
void generator_writer_c_init(generator_writer_c_t *self, const symbols_t *symbols)
{
	generator_init(&self->super, symbols);

	self->super.on_document_begin = on_document_begin;
	self->super.on_document_end = on_document_end;
	self->super.on_definition = on_definition;
}
コード例 #7
0
ファイル: mvdistinct.c プロジェクト: adityavs/postgres
/*
 * statext_ndistinct_build
 *		Compute ndistinct coefficient for the combination of attributes.
 *
 * This computes the ndistinct estimate using the same estimator used
 * in analyze.c and then computes the coefficient.
 */
MVNDistinct *
statext_ndistinct_build(double totalrows, int numrows, HeapTuple *rows,
						Bitmapset *attrs, VacAttrStats **stats)
{
	MVNDistinct *result;
	int			k;
	int			itemcnt;
	int			numattrs = bms_num_members(attrs);
	int			numcombs = num_combinations(numattrs);

	result = palloc(offsetof(MVNDistinct, items) +
					numcombs * sizeof(MVNDistinctItem));
	result->magic = STATS_NDISTINCT_MAGIC;
	result->type = STATS_NDISTINCT_TYPE_BASIC;
	result->nitems = numcombs;

	itemcnt = 0;
	for (k = 2; k <= numattrs; k++)
	{
		int		   *combination;
		CombinationGenerator *generator;

		/* generate combinations of K out of N elements */
		generator = generator_init(numattrs, k);

		while ((combination = generator_next(generator)))
		{
			MVNDistinctItem *item = &result->items[itemcnt];
			int			j;

			item->attrs = NULL;
			for (j = 0; j < k; j++)
				item->attrs = bms_add_member(item->attrs,
											 stats[combination[j]]->attr->attnum);
			item->ndistinct =
				ndistinct_for_combination(totalrows, numrows, rows,
										  stats, k, combination);

			itemcnt++;
			Assert(itemcnt <= result->nitems);
		}

		generator_free(generator);
	}

	/* must consume exactly the whole output array */
	Assert(itemcnt == result->nitems);

	return result;
}
コード例 #8
0
ファイル: main.c プロジェクト: doniexun/jacc
int cmd_parse_expr(FILE *file, const char *filename, const char *cmd)
{
    log_set_unit(basename(filename));

    lexer_init(file);
    parser_init();
    generator_init();

    struct node* node = NULL;
    symtable_t symtable = NULL;
    code_t code = NULL;

    if (strcmp(cmd, "parse_expr") == 0) {
        parser_flags_set(0);
        node = parser_parse_expr();
        print_node(node, 0, 0);
    } else if (strcmp(cmd, "parse_stmt") == 0) {
        parser_flags_set(0);
        node = parser_parse_statement();
        print_node(node, 0, 0);
    } else if (strcmp(cmd, "parse") == 0) {
        parser_flags_set(PF_RESOLVE_NAMES);
        symtable = parser_parse();
        print_symtable(symtable, 0);
    } else if (strcmp(cmd, "compile") == 0) {
        symtable = parser_parse();
        if (symtable != NULL) {
            code = generator_process(symtable);
            optimizer_optimize(code);
            generator_print_code(code);
        } else {
            print_symtable(symtable, 0);
        }
    }

    parser_free_node(node);
    symtable_destroy(symtable, 1);
    generator_free_code(code);

    generator_destroy();
    parser_destroy();
    lexer_destroy();

    log_close();
    return EXIT_SUCCESS;
}
コード例 #9
0
/*
 *  call-seq:
 *    Enumerator.new(obj, method = :each, *args)
 *    Enumerator.new { |y| ... }
 *
 *  Creates a new Enumerator object, which is to be used as an
 *  Enumerable object iterating in a given way.
 *
 *  In the first form, a generated Enumerator iterates over the given
 *  object using the given method with the given arguments passed.
 *  Use of this form is discouraged.  Use Kernel#enum_for(), alias
 *  to_enum, instead.
 *
 *    e = Enumerator.new(ObjectSpace, :each_object)
 *        #-> ObjectSpace.enum_for(:each_object)
 *
 *    e.select { |obj| obj.is_a?(Class) }  #=> array of all classes
 *
 *  In the second form, iteration is defined by the given block, in
 *  which a "yielder" object given as block parameter can be used to
 *  yield a value by calling the +yield+ method, alias +<<+.
 *
 *    fib = Enumerator.new { |y|
 *      a = b = 1
 *      loop {
 *        y << a
 *        a, b = b, a + b
 *      }
 *    }
 *
 *    p fib.take(10) #=> [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
 */
static VALUE
enumerator_initialize(int argc, VALUE *argv, VALUE obj)
{
    VALUE recv, meth = sym_each;

    if (argc == 0) {
        if (!rb_block_given_p())
            rb_raise(rb_eArgError, "wrong number of argument (0 for 1+)");

        recv = generator_init(generator_allocate(rb_cGenerator), rb_block_proc());
    } else {
        recv = *argv++;
        if (--argc) {
            meth = *argv++;
            --argc;
        }
    }

    return enumerator_init(obj, recv, meth, argc, argv);
}
コード例 #10
0
/*
 * call-seq:
 *   Enumerator.new { |yielder| ... }
 *   Enumerator.new(obj, method = :each, *args)
 *
 * Creates a new Enumerator object, which can be used as an
 * Enumerable.
 *
 * In the first form, iteration is defined by the given block, in
 * which a "yielder" object, given as block parameter, can be used to
 * yield a value by calling the +yield+ method (aliased as +<<+):
 *
 *   fib = Enumerator.new do |y|
 *     a = b = 1
 *     loop do
 *       y << a
 *       a, b = b, a + b
 *     end
 *   end
 *
 *   p fib.take(10) # => [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
 *
 * The block form can be used to create a lazy enumeration that only processes
 * elements as-needed.  The generic pattern for this is:
 *
 *    Enumerator.new do |yielder|
 *      source.each do |source_item|
 *        # process source_item and append the yielder
 *      end
 *    end
 *
 * This can be used with infinite streams to support multiple chains:
 *
 *   class Fib
 *     def initialize(a = 1, b = 1)
 *       @a, @b = a, b
 *     end
 *
 *     def each
 *       a, b = @a, @b
 *       yield a
 *       while true
 *         yield b
 *         a, b = b, a+b
 *       end
 *     end
 *   end
 *
 *   def lazy_select enum
 *     Enumerator.new do |y|
 *       enum.each do |e|
 *         y << e if yield e
 *       end
 *     end
 *   end
 *
 *   def lazy_map enum
 *     Enumerator.new do |y|
 *       enum.each do |e|
 *         y << yield(e)
 *       end
 *     end
 *   end
 *
 *   even_fibs   = lazy_select(Fibs.new) { |x| x % 2 == 0 }
 *   string_fibs = lazy_map(even_fibs)   { |x| "<#{x}>" }
 *   string_fibs.each_with_index do |fib, i|
 *     puts "#{i}: #{fib}"
 *     break if i >= 3
 *   end
 *
 * This allows output even though the Fib produces an infinite sequence of
 * Fibonacci numbers:
 *
 *   0: <2>
 *   1: <8>
 *   2: <34>
 *   3: <144>
 *
 * In the second, deprecated, form, a generated Enumerator iterates over the
 * given object using the given method with the given arguments passed.
 *
 * Use of this form is discouraged.  Use Kernel#enum_for or Kernel#to_enum
 * instead.
 *
 *   e = Enumerator.new(ObjectSpace, :each_object)
 *       #-> ObjectSpace.enum_for(:each_object)
 *
 *   e.select { |obj| obj.is_a?(Class) }  #=> array of all classes
 *
 */
static VALUE
enumerator_initialize(int argc, VALUE *argv, VALUE obj)
{
    VALUE recv, meth = sym_each;

    if (argc == 0) {
	if (!rb_block_given_p())
	    rb_check_arity(argc, 1, UNLIMITED_ARGUMENTS);

	recv = generator_init(generator_allocate(rb_cGenerator), rb_block_proc());
    }
    else {
	recv = *argv++;
	if (--argc) {
	    meth = *argv++;
	    --argc;
	}
    }

    return enumerator_init(obj, recv, meth, argc, argv);
}
コード例 #11
0
ファイル: config.c プロジェクト: enascimento/supercop
void init_all()
{
    // Field Initialisation:
    Kfield_init();

    // Curve Initialisation:
    curve_init();

    // Generator Initalisation:
    generator_init();

    // Order of the subgroup:
    mpz_init_set_str(p, "53919893334301279666889509884200806281039951735555151719046432375393",10);
    size_of_p = mpz_sizeinbase(p,2);

    // Initialisation of global dummys:
    int i;
    for(i = 0; i < NUMBER_OF_DUMMYELTS; i++)
    {
        Kinit(&(dummyelts[i]));
    }

}
コード例 #12
0
ファイル: enumerator.c プロジェクト: Sophrinix/MacRuby
/*
 *  call-seq:
 *    Enumerator.new(obj, method = :each, *args)
 *    Enumerator.new { |y| ... }
 *
 *  Creates a new Enumerator object, which is to be used as an
 *  Enumerable object iterating in a given way.
 *
 *  In the first form, a generated Enumerator iterates over the given
 *  object using the given method with the given arguments passed.
 *  Use of this form is discouraged.  Use Kernel#enum_for(), alias
 *  to_enum, instead.
 *
 *    e = Enumerator.new(ObjectSpace, :each_object)
 *        #-> ObjectSpace.enum_for(:each_object)
 *
 *    e.select { |obj| obj.is_a?(Class) }  #=> array of all classes
 *
 *  In the second form, iteration is defined by the given block, in
 *  which a "yielder" object given as block parameter can be used to
 *  yield a value by calling the +yield+ method, alias +<<+.
 *
 *    fib = Enumerator.new { |y|
 *      a = b = 1
 *      loop {
 *        y << a
 *        a, b = b, a + b
 *      }
 *    }
 *
 *    p fib.take(10) #=> [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
 */
static VALUE
enumerator_initialize(VALUE obj, SEL sel, int argc, VALUE *argv)
{
    VALUE recv, meth = sym_each;

    if (argc == 0) {
	if (!rb_block_given_p())
	    rb_raise(rb_eArgError, "wrong number of argument (0 for 1+)");

	recv = generator_init(generator_allocate(rb_cGenerator, 0), rb_block_proc());
    }
    else {
	recv = *argv++;
	if (--argc) {
	    meth = *argv++;
	    --argc;
	}
    }

    ID meth_id = rb_to_id(meth);
    SEL meth_sel = rb_vm_id_to_sel(meth_id, argc);
    return enumerator_init(obj, recv, meth_sel, argc, argv);
}
コード例 #13
0
ファイル: main.c プロジェクト: shadowlamer/sixties
int main(void)
{

	uint32_t x = 0;
	uint32_t y = 0;

	RCC_DeInit();
	RCC_HSEConfig(RCC_HSE_ON);
	if(RCC_WaitForHSEStartUp() == SUCCESS)
	{
		RCC_HCLKConfig(RCC_SYSCLK_Div1);
		RCC_PCLKConfig(RCC_HCLK_Div1);
		RCC_PLLConfig(RCC_PLLSource_PREDIV1, RCC_PLLMul_8);
		RCC_PLLCmd(ENABLE);
		while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);
		RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
		while(RCC_GetSYSCLKSource() != 0x08);
	}
	generator_init();
	generator_start();
	delay_init();
	lcd_init();

	lcd_clear();
	lcd_dma_start();


	for (x=0;x<50;x++) {
		while (lcd_is_busy());
		lcd_noise();
		lcd_dma_start();
	}


	while (lcd_is_busy());

	for (x=0;x<patternWidthPages*patternHeightPixels;x++)
		lcd_buf[x] = patternBitmaps[x];

	print(1,0,"PLEASE",6);
	print(0,7,"STAND_BY",8);

	while (lcd_is_busy());
	lcd_dma_start();

	delay_ms(20000);


	for (x=0;x<patternWidthPages*patternHeightPixels;x++)
		lcd_buf[x] = patternBitmaps[x];

	for (x=9;x>0;x--) {
		putchar_big(3,3,'0'+x);
		while (lcd_is_busy());
		lcd_dma_start();
		delay_ms(3000);
	}

	lcd_clear();
	print(1,1,"URGENT",6);
	print(0,6,"MESSAGE!",8);
	while (lcd_is_busy());
	lcd_dma_start();
	delay_ms(3000);

	scroll_text(MESSAGE);

	delay_ms(3000);
	lcd_clear();
	print(1,1,"THAT'S",6);
	print(3,3,"ALL",3);
	print(1,5,"FOLKS!",6);
	while (lcd_is_busy());
	lcd_dma_start();

	delay_ms(100000);

	for (x=0;x<10000;x++) {
		while (lcd_is_busy());
		lcd_noise();
		lcd_dma_start();
	}

	lcd_clear();
	while (lcd_is_busy());
	lcd_dma_start();

	scroll_text(SECRET_MESSAGE);

	while(1) //Infinite loop!
	{
		while (lcd_is_busy());
		lcd_noise();
		lcd_dma_start();
	}
}
コード例 #14
0
int main (void){
    cli();

    // debug
    DDRB |= (1<<DEBUG_LED_PIN);
    debug_init();
    // push button
    DDRD |= (1<<BUTTON_PWR_PIN); PORTD |= (1<<BUTTON_PWR_PIN);
    DDRD &= ~(1<<BUTTON_PIN); PORTD |= (1<<BUTTON_PIN);
    uint8_t button_press_counter;

    // init
    sequence_init();
    generator_init();
    sequence_update(0);
    sequence_runmode = SEQ_RUNMODE_SEQUENTIAL;
    generator_update();
    uint16_t frame_counter;
    uint8_t seed=0;
    _delay_ms(10);

    // Global interrupt enable.
    sei();

    while(1)
    {
        srand(seed++);

        // the refresh rate depends on the driver rate
        if(pwm_packet_counter>20){
            pwm_packet_counter = 0;
            generator_run();
            DEBUG_LED_PIN_TOGGLE();

            if((frame_counter++ > 0x3FF)&&(sequence_runmode==SEQ_RUNMODE_TOGGLE)){
                sequence_skip();
                generator_update();
                frame_counter = 0;
            }
        }
        // serial cmd received
        if(debug_char != 0xFF){
            sequence_update(debug_char);
            generator_update();
            debug_char = 0xFF;
        }
        // push button
        if((PIND&(1<<BUTTON_PIN)) == 0){
            button_press_counter = 0;
            // measure the button press duration
            while((PIND&(1<<BUTTON_PIN)) == 0){
                _delay_ms(100);
                button_press_counter++;
            }
            // short press => next sequence
            if (button_press_counter < 10){
                frame_counter = 0;
                sequence_skip();
                generator_update();
                // debug_putc('d'); // skip sequence
            }
            // long press => switch between normal and sequential mode
            else{
                frame_counter = 0;
                sequence_runmode ^= SEQ_RUNMODE_TOGGLE;
                // debug_putc('c'); // switch normal(current sequence)<->sequential
            }
        }
    }
}