Exemplo n.º 1
0
//--------------------------------------------------------
//static int8_t input0 (func_cb_ptr p, void *data, uint16_t length) {
static int8_t input0 (func_cb_ptr p, token_type_t *t) {
	update_background_state_t *s = (update_background_state_t *)sys_get_state();	

	// Get token from port.

	if (s->state == UPD_STATE_INIT) {	

		s->backMat = (CYCLOPS_Matrix *)capture_token_data(t, s->pid);
		if (s->backMat == NULL) return -ENOMEM;
		
		s->state = UPD_STATE_PROCESS;								
	} else {		
		CYCLOPS_Matrix *M = (CYCLOPS_Matrix *)get_token_data(t);
		//check that input matrix's depth is 1 byte
		if( (M->depth != CYCLOPS_1BYTE) || (s->backMat->depth != CYCLOPS_1BYTE) )
				return -EINVAL;
		token_type_t *my_token = create_token(s->backMat, sizeof(CYCLOPS_Matrix), s->pid);
		if (my_token == NULL) return -EINVAL;
		set_token_type(my_token, CYCLOPS_MATRIX);
		//SOS_CALL(s->put_token, put_token_func_t, s->output0, my_token);
		dispatch(s->output0, my_token);
		destroy_token(my_token);
	}
	return SOS_OK;
}
Exemplo n.º 2
0
TOKEN function_definition(SYMBOL s)
{
    TOKEN func_definition = NULL;
    //we didn't find a global var so assume we found a function
    //we already parsed the declaration specifiers and the declarator in the earlier parsing attempt
    //so just repurpose the information we collected instead of backtracking and re-parsing

    expect(DELIMITER_TOKEN, OPEN_PAREN, NO_ERROR_HANDLER);
    TOKEN params = parameter_type_list(); //we already found the return type and function name earlier, so we just pick up from there
    expect(DELIMITER_TOKEN, CLOSE_PAREN, NO_ERROR_HANDLER);
    SYMBOL return_type = s;
    insertfn(s->namestring, return_type, get_token_symbol_type(params)); //FIXME: extend this to more than just one parameter
    TOKEN func_body = compound_statement();

    //FIXME: this is a hack to retrieve the function name in TOKEN form
    //figure out a better way to deal with this
    TOKEN func_name = make_token();
    set_token_type(func_name, IDENTIFIER_TOKEN);
    set_token_string_value(func_name, s->namestring);
    set_token_symbol_table_entry(func_name, s);
    params = make_statement_list(params);
    func_definition = make_function_definition(func_name, params, func_body);
    return func_definition;
}