예제 #1
0
파일: icode.c 프로젝트: doniexun/zcc
/*===-------------------------------------------------------------------------
 * / % + - >> <<
-------------------------------------------------------------------------===*/
static symbol *arith_expr2ic(ast *root) {
	ast *t = root, *t1, *t2;
	symbol *s1, *s2, *val;
	type *dt;
	int ic;
	int set[] = {AST_MUL, AST_MOD, AST_DIV, AST_ADD, AST_SUB, AST_LS, AST_RS, 0};
	int mul_set[] = {AST_MUL, AST_MOD, AST_DIV, 0};

	if (!is_in_set(t->node, set))
		return cast2ic(t);
	// s1 = expr1
	t1 = t->left;
	if (is_in_set(t->node, mul_set))
		s1 = cast2ic(t1);
	else
		s1 = arith_expr2ic(t1);
	// more than one operator of equal precedence
	ic = eval_icode_node(t->node);
	dt = t->ty;
	t = t->right;
	while (is_in_set(t->node, set)) {
		t2 = t->left;
		if (is_in_set(t->node, mul_set))
			s2 = cast2ic(t2);
		else
			s2 = arith_expr2ic(t2);
		s1 = cast(s1, dt);
		val = cast(s2, dt);
		verify_ops(&s1, val);
		emit_ic(ic + gen_post(dt->cat, dt->cat), s1, val);
		///
		ic = eval_icode_node(t->node);
		dt = t->ty;
		t = t->right;
	}
	// last sub-expression or only has one operator(etc, a + b)
	if (is_in_set(t->node, mul_set))
		s2 = cast2ic(t);
	else
		s2 = arith_expr2ic(t);
	s1 = cast(s1, dt);
	s2 = cast(s2, dt);
	verify_ops(&s1, s2);
	emit_ic(ic + gen_post(dt->cat, dt->cat), s1, s2);

	return s1;
}
예제 #2
0
파일: map.c 프로젝트: spl/ivy
void explode(int var, int z)
{
    int i, last = cube.last_part[var];
    for(i=cube.first_part[var], z *= cube.part_size[var]; i<=last; i++, z++)
	if (is_in_set(Gcube, i))
	    if (var == 0)
		set_insert(Gminterm, z);
	    else
		explode(var-1, z);
}
예제 #3
0
BOOL parse_speed_command( char* mIncoming )
{
	char expression[] = "^motor speed:([vV]\\d+)? ?([wW]\\d+)? ?([xX]\\d+)? ?([yY]\\d+)? ?([zZ]\\d+)?";
	
	BOOL is_speed_command = strcmp(mIncoming, "motor speed");
	byte which = which_motors(mIncoming);
	float fraction=0.0;
	for (int b=0; b<NUM_MOTORS; b++)
	{
		if (is_in_set(which, b) )
			set_motor_duty( b, fraction );		
	}
	form_response("ACK: speed request");	
	return is_speed_command;
}
예제 #4
0
BOOL parse_position_command( char* mIncoming )
{
	char expression[] = "^motor position:([vV]\\d+)? ?([wW]\\d+)? ?([xX]\\d+)? ?([yY]\\d+)? ?([zZ]\\d+)?";
	
	BOOL is_position_command = strcmp(mIncoming, "motor position ");
	byte which = which_motors(mIncoming);
	uint32_t pos;
	for (int b=0; b<NUM_MOTORS; b++)
	{
		if (is_in_set(which, b) )
			set_motor_position( b, pos );		
	}	
	form_response("ACK: position request");		
	return is_position_command;
}
예제 #5
0
BOOL parse_home_command( char* mIncoming )
{
	char expression = "home ([vV])? ([wW])? ([xX])? ([yY])? ([zZ])?";
	int match = re_match( 2, Captures, expression, mIncoming );
		
	BOOL is_speed_command = strcmp(mIncoming, "HOME:");
	byte which = which_motors(mIncoming);
	for (int b=0; b<NUM_MOTORS; b++)
	{
		if (is_in_set(which, b) )
			set_motor_duty( b, HOMING_SPEED );		
	}
	form_response("ACK: homing...");
	return is_speed_command;
}
예제 #6
0
BOOL parse_zero_encoders( char* mIncoming )
{
	char expression = "zero (position|encoders) (v)?(w)?(x)?(y)?(z)?";
	int match = re_match( 7, Captures, expression, mIncoming );
		
	BOOL is_speed_command = strcmp(mIncoming, "zero position ");

	for (int b=0; b<NUM_MOTORS; b++)
	{
		if (is_in_set(which, b) )
			Encoders[b].Count=0;
	}
	form_response( "ACK zero positioned" );	
	return is_speed_command;
}
예제 #7
0
BOOL parse_limits_enable( char* mIncoming )
{
	char expression[] = "(enable|disable) limits";
	
	BOOL is_position_command = strcmp(mIncoming, "enable limits");
	is_position_command = strcmp(mIncoming, "disable limits");	
	byte which = which_motors(mIncoming);
	uint32_t pos;
	for (int b=0; b<NUM_MOTORS; b++)
	{
		if (is_in_set(which, b) )
			set_motor_position( b, pos );		
	}	
	form_response("ACK: limits enabled");
	return is_position_command;
}
예제 #8
0
BOOL parse_measure_travel( char* mIncoming )
{
	char expression = "measure travel";
	int match = re_match( 2, Captures, expression, mIncoming );
	
	BOOL is_speed_command = strcmp(mIncoming, "measure travel");
	byte which = which_motors(mIncoming);
	for (int b=0; b<NUM_MOTORS; b++)
	{
		if (is_in_set(which, b) )
			set_motor_duty( b, HOMING_SPEED );		
	}
	// Don't wait until further limit switches triggered, just ack the cmd:
	form_response( "ACK measuring travel..." );
	return is_speed_command;
}
예제 #9
0
파일: map.c 프로젝트: spl/ivy
void map(pset_family T)
{
    int j, k, l, other_input_offset, output_offset, outnum, ind;
    int largest_input_ind,  numout;
    char c;
    pset m;
    bool some_output;

    m = minterms(T);
    largest_input_ind = POWER2(cube.num_binary_vars);
    numout = cube.part_size[cube.num_vars-1];

    for(outnum = 0; outnum < numout; outnum++) {
	output_offset = outnum * largest_input_ind;
	printf("\n\nOutput space # %d\n", outnum);
	for(l = 0; l <= MAX(cube.num_binary_vars - 8, 0); l++) {
	    other_input_offset = l * 256;
	    for(k = 0; k < 16; k++) {
		some_output = FALSE;
		for(j = 0; j < 16; j++) {
		    ind = mapindex[k][j] + other_input_offset;
		    if (ind < largest_input_ind) {
			c = is_in_set(m, ind+output_offset) ? '1' : '.';
			putchar(c);
			some_output = TRUE;
		    }
		    if ((j+1)%4 == 0)
			putchar(' ');
		    if ((j+1)%8 == 0)
			printf("  ");
		}
		if (some_output)
		    putchar('\n');
		if ((k+1)%4 == 0) {
		    if (k != 15 && mapindex[k+1][0] >= largest_input_ind)
			break;
		    putchar('\n');
		}
		if ((k+1)%8 == 0)
		    putchar('\n');
	    }
	}
    }
    set_free(m);
}