Ejemplo n.º 1
0
int
_cogl_blend_string_test (void)
{
  struct _TestString strings[] = {
        {"  A = MODULATE ( TEXTURE[RGB], PREVIOUS[A], PREVIOUS[A] )  ",
          COGL_BLEND_STRING_CONTEXT_TEXTURE_COMBINE },
        {"  RGB = MODULATE ( TEXTURE[RGB], PREVIOUS[A] )  ",
          COGL_BLEND_STRING_CONTEXT_TEXTURE_COMBINE },
        {"A=ADD(TEXTURE[A],PREVIOUS[RGB])",
          COGL_BLEND_STRING_CONTEXT_TEXTURE_COMBINE },
        {"A=ADD(TEXTURE[A],PREVIOUS[RGB])",
          COGL_BLEND_STRING_CONTEXT_TEXTURE_COMBINE },

        {"RGBA = ADD(SRC_COLOR*(SRC_COLOR[A]), DST_COLOR*(1-SRC_COLOR[A]))",
          COGL_BLEND_STRING_CONTEXT_BLENDING },
        {"RGB = ADD(SRC_COLOR, DST_COLOR*(0))",
          COGL_BLEND_STRING_CONTEXT_BLENDING },
        {"RGB = ADD(SRC_COLOR, 0)",
          COGL_BLEND_STRING_CONTEXT_BLENDING },
        {"RGB = ADD()",
          COGL_BLEND_STRING_CONTEXT_BLENDING },
        {"RGB = ADD(SRC_COLOR, 0, DST_COLOR)",
          COGL_BLEND_STRING_CONTEXT_BLENDING },
        {NULL}
  };
  int i;

  CoglError *error = NULL;
  for (i = 0; strings[i].string; i++)
    {
      CoglBlendStringStatement statements[2];
      int count = _cogl_blend_string_compile (strings[i].string,
                                              strings[i].context,
                                              statements,
                                              &error);
      if (!count)
        {
          g_print ("Failed to parse string:\n%s\n%s\n",
                   strings[i].string,
                   error->message);
          cogl_error_free (error);
          error = NULL;
          continue;
        }
      g_print ("Original:\n");
      g_print ("%s\n", strings[i].string);
      if (count > 0)
        print_statement (0, &statements[0]);
      if (count > 1)
        print_statement (1, &statements[1]);
    }

  return 0;
}
Ejemplo n.º 2
0
Archivo: ast.c Proyecto: MatzeB/fluffy
static void print_if_statement(const if_statement_t *statement)
{
	fprintf(out, "if ");
	print_expression(statement->condition);
	fprintf(out, ":\n");
	if (statement->true_statement != NULL)
		print_statement(statement->true_statement);

	if (statement->false_statement != NULL) {
		print_indent();
		fprintf(out, "else:\n");
		print_statement(statement->false_statement);
	}
}
Ejemplo n.º 3
0
Archivo: ast.c Proyecto: MatzeB/fluffy
static void print_concept_function_instance(
		concept_function_instance_t *function_instance)
{
	fprintf(out, "\tfunc ");

	const function_t *function = &function_instance->function;
	if (function_instance->concept_function != NULL) {
		concept_function_t *function = function_instance->concept_function;
		fprintf(out, "%s", function->base.symbol->string);
	} else {
		fprintf(out, "?%s", function_instance->symbol->string);
	}

	print_function_parameters(function->parameters, function->type);

	fprintf(out, " : ");
	print_type(function_instance->function.type->result_type);

	if (function->statement != NULL) {
		fprintf(out, ":\n");
		print_statement(function->statement);
	} else {
		fprintf(out, "\n");
	}
}
Ejemplo n.º 4
0
Archivo: ast.c Proyecto: MatzeB/fluffy
static void print_function(const function_entity_t *function_entity)
{
	const function_t *function = &function_entity->function;
	function_type_t  *type     = function->type;

	fprintf(out, "func ");

	if (function->is_extern) {
		fprintf(out, "extern ");
	}

	fprintf(out, " %s", function_entity->base.symbol->string);

	print_type_parameters(function->type_parameters);

	print_function_parameters(function->parameters, type);

	fprintf(out, " : ");
	print_type(type->result_type);

	if (function->statement != NULL) {
		fprintf(out, ":\n");
		print_statement(function->statement);
	} else {
		fprintf(out, "\n");
	}
}
Ejemplo n.º 5
0
Archivo: ast.c Proyecto: MatzeB/fluffy
static void print_block_statement(const block_statement_t *block)
{
	statement_t *statement = block->statements;
	for ( ; statement != NULL; statement = statement->base.next) {
		indent++;
		print_statement(statement);
		indent--;
	}
}
Ejemplo n.º 6
0
/*---------------------------------------------------------------------------*/
static void
statement(void)
{
  int token;

  token = tokenizer_token();

  switch(token) {
  case TOKENIZER_PRINT:
    print_statement();
    break;
  case TOKENIZER_IF:
    if_statement();
    break;
  case TOKENIZER_GOTO:
    goto_statement();
    break;
  case TOKENIZER_GOSUB:
    gosub_statement();
    break;
  case TOKENIZER_RETURN:
    return_statement();
    break;
  case TOKENIZER_FOR:
    for_statement();
    break;
  case TOKENIZER_PEEK:
    peek_statement();
    break;
  case TOKENIZER_POKE:
    poke_statement();
    break;
  case TOKENIZER_NEXT:
    next_statement();
    break;
  case TOKENIZER_END:
    end_statement();
    break;
  case TOKENIZER_LET:
    accept(TOKENIZER_LET);
    /* Fall through. */
  case TOKENIZER_VARIABLE:
    let_statement();
    break;
  default:
    DEBUG_PRINTF("ubasic.c: statement(): not implemented %d\n", token);
    exit(1);
  }
}
Ejemplo n.º 7
0
static void
emit_statement (statement_t *statement)
{
	const char *opcode = statement->opcode;
	def_t      *def_a, *def_b, *def_c;
	opcode_t   *op;
	dstatement_t *s;

	def_a = get_operand_def (statement->expr, statement->opa);
	use_tempop (statement->opa, statement->expr);
	def_b = get_operand_def (statement->expr, statement->opb);
	use_tempop (statement->opb, statement->expr);
	def_c = get_operand_def (statement->expr, statement->opc);
	use_tempop (statement->opc, statement->expr);
	op = opcode_find (opcode, statement->opa, statement->opb, statement->opc);

	if (!op) {
		print_expr (statement->expr);
		print_statement (statement);
		internal_error (statement->expr, "ice ice baby");
	}
	if (options.code.debug) {
		expr_t     *e = statement->expr;
		pr_uint_t   line = (e ? e->line : pr.source_line) - lineno_base;

		if (line != pr.linenos[pr.num_linenos - 1].line) {
			pr_lineno_t *lineno = new_lineno ();

			lineno->line = line;
			lineno->fa.addr = pr.code->size;
		}
	}
	s = codespace_newstatement (pr.code);
	s->op = op->opcode;
	s->a = def_a ? def_a->offset : 0;
	s->b = def_b ? def_b->offset : 0;
	s->c = def_c ? def_c->offset : 0;

	add_statement_def_ref (def_a, s, 0);
	add_statement_def_ref (def_b, s, 1);
	add_statement_def_ref (def_c, s, 2);

	add_statement_op_ref (statement->opa, s, 0);
	add_statement_op_ref (statement->opb, s, 1);
	add_statement_op_ref (statement->opc, s, 2);
}
Ejemplo n.º 8
0
static void statement (void)
{
  int token;
  char string[10];
  token = tokenizer_token();
  switch (token)
  {
    /* REM statement (comment). */
    case T_REM:
      tokenizer_next();
      accept(T_EOL);
      break;
    /* Print statement. */
    case T_PRINT:
      print_statement();
      break;
    /* If statement. */
    case T_IF:
      if_statement();
      break;
    /* Goto statement. */
    case T_GOTO:
      goto_statement();
      break;
    /* Let statement. */
    case T_LET:
      accept(T_LET);
    /* Fall through... */
    case T_LETTER:
      let_statement();
      break;
    default:
    /* Unrecognized statement! */
      to_string(string, sizeof string);
      dprintf("*vvtbi.c: statement(): "
        "not implemented near `%s'\n",
        E_ERROR,
        /* If empty, EOF! */
        ((strlen(string)) ? string : "EOF"));
      break;
  }
}
Ejemplo n.º 9
0
bool
_cg_blend_string_compile(cg_device_t *dev,
                         const char *string,
                         cg_blend_string_statement_t *statements,
                         cg_error_t **error)
{
    const char *p = string;
    const char *mark = NULL;
    const char *error_string;
    parser_state_t state = PARSER_STATE_EXPECT_DEST_CHANNELS;
    cg_blend_string_statement_t *statement = statements;
    int current_statement = 0;
    int current_arg = 0;
    int remaining_argc = 0;

#if 0
    CG_DEBUG_SET_FLAG (CG_DEBUG_BLEND_STRINGS);
#endif

    if (CG_DEBUG_ENABLED(CG_DEBUG_BLEND_STRINGS)) {
        CG_NOTE(BLEND_STRINGS,
                "Compiling blend string:\n%s\n",
                string);
    }

    do {
        if (c_ascii_isspace(*p))
            continue;

        if (*p == '\0') {
            switch (state) {
            case PARSER_STATE_EXPECT_DEST_CHANNELS:
                if (current_statement != 0)
                    goto finished;
                error_string = "Empty statement";
                goto error;
            case PARSER_STATE_SCRAPING_DEST_CHANNELS:
                error_string = "Expected an '=' following the destination "
                               "channel mask";
                goto error;
            case PARSER_STATE_EXPECT_FUNCTION_NAME:
                error_string = "Expected a function name";
                goto error;
            case PARSER_STATE_SCRAPING_FUNCTION_NAME:
                error_string = "Expected parenthesis after the function name";
                goto error;
            case PARSER_STATE_EXPECT_ARG_START:
                error_string = "Expected to find the start of an argument";
                goto error;
            case PARSER_STATE_EXPECT_STATEMENT_END:
                error_string = "Expected closing parenthesis for statement";
                goto error;
            }
        }

        switch (state) {
        case PARSER_STATE_EXPECT_DEST_CHANNELS:
            mark = p;
            state = PARSER_STATE_SCRAPING_DEST_CHANNELS;

        /* fall through */
        case PARSER_STATE_SCRAPING_DEST_CHANNELS:
            if (*p != '=')
                continue;
            if (strncmp(mark, "RGBA", 4) == 0)
                statement->mask = CG_BLEND_STRING_CHANNEL_MASK_RGBA;
            else if (strncmp(mark, "RGB", 3) == 0)
                statement->mask = CG_BLEND_STRING_CHANNEL_MASK_RGB;
            else if (strncmp(mark, "A", 1) == 0)
                statement->mask = CG_BLEND_STRING_CHANNEL_MASK_ALPHA;
            else {
                error_string = "Unknown destination channel mask; "
                               "expected RGBA=, RGB= or A=";
                goto error;
            }
            state = PARSER_STATE_EXPECT_FUNCTION_NAME;
            continue;

        case PARSER_STATE_EXPECT_FUNCTION_NAME:
            mark = p;
            state = PARSER_STATE_SCRAPING_FUNCTION_NAME;

        /* fall through */
        case PARSER_STATE_SCRAPING_FUNCTION_NAME:
            if (*p != '(') {
                if (!is_alphanum_char(*p)) {
                    error_string = "non alpha numeric character in function"
                                   "name";
                    goto error;
                }
                continue;
            }
            statement->function = get_function_info(mark, p);
            if (!statement->function) {
                error_string = "Unknown function name";
                goto error;
            }
            remaining_argc = statement->function->argc;
            current_arg = 0;
            state = PARSER_STATE_EXPECT_ARG_START;

        /* fall through */
        case PARSER_STATE_EXPECT_ARG_START:
            if (*p != '(' && *p != ',')
                continue;
            if (remaining_argc) {
                p++; /* parse_argument expects to see the first char of the arg
                      */
                if (!parse_argument(string,
                                    &p,
                                    statement,
                                    current_arg,
                                    &statement->args[current_arg],
                                    error))
                    return 0;
                current_arg++;
                remaining_argc--;
            }
            if (!remaining_argc)
                state = PARSER_STATE_EXPECT_STATEMENT_END;
            continue;

        case PARSER_STATE_EXPECT_STATEMENT_END:
            if (*p != ')') {
                error_string = "Expected end of statement";
                goto error;
            }
            state = PARSER_STATE_EXPECT_DEST_CHANNELS;
            if (current_statement++ == 1)
                goto finished;
            statement = &statements[current_statement];
        }
    } while (p++);

finished:

    if (CG_DEBUG_ENABLED(CG_DEBUG_BLEND_STRINGS)) {
        if (current_statement > 0)
            print_statement(0, &statements[0]);
        if (current_statement > 1)
            print_statement(1, &statements[1]);
    }

    if (!validate_statements(dev, statements, current_statement, error))
        return 0;

    return current_statement;

error: {
        int offset = p - string;
        _cg_set_error(error,
                      CG_BLEND_STRING_ERROR,
                      CG_BLEND_STRING_ERROR_PARSE_ERROR,
                      "Syntax error for string \"%s\" at offset %d: %s",
                      string,
                      offset,
                      error_string);

        if (CG_DEBUG_ENABLED(CG_DEBUG_BLEND_STRINGS)) {
            c_debug("Syntax error at offset %d: %s", offset, error_string);
        }
        return 0;
    }
}
Ejemplo n.º 10
0
void SyntaxAnalyzer::S()
{
	if ((cur->type == keyword)&&
		(strcmp(cur->lex, "end")!=0)) {
		if (strcmp(cur->lex, "if")==0) {
			next();
			if_statement();
			S();
		}
		else
		if (strcmp(cur->lex, "while")==0) {
			next();
			while_statement();
			S();
		}
		else
		if (strcmp(cur->lex, "goto")==0) {
			next();
			goto_statement();
			PolizOpGo* tmp = new PolizOpGo;
			add_poliz_list(tmp);
			S();
		}
		else
		if (strcmp(cur->lex, "print")==0) {
			next();
			print_statement();
			PolizPrint* tmp = new PolizPrint;
			add_poliz_list(tmp);
			S();
		}
		else
		if (strcmp(cur->lex, "then")!=0) {
			game_statement();
			S();
		}
		else
			throw Exeption("unexpected then", cur->num_str, cur->lex);
	}
	else
	if (cur->type == variable) {
		make_poliz_var();
		next();
		assignment_statement();
		PolizFunAssign* tmp = new PolizFunAssign;
		add_poliz_list(tmp);
		S();
	}
	else
	if (cur->type == label) {
		make_poliz_label();
		next();
		if (strcmp(cur->lex, ">")!=0)
			throw Exeption("'>' expected", cur->num_str, cur->lex);
		next();
		S();
	}
	else {
	if (strcmp(cur->lex, "end")!=0)
		throw Exeption("end expected", cur->num_str, cur->lex);
	else
		next();
	}
}
Ejemplo n.º 11
0
/*---------------------------------------------------------------------------*/
static uint8_t statement(void)
{
  int token;

  string_temp_free();

  token = current_token;
  /* LET may be omitted.. */
  if (token != TOKENIZER_INTVAR && token != TOKENIZER_STRINGVAR)
    accept_tok(token);

  switch(token) {
  case TOKENIZER_QUESTION:
  case TOKENIZER_PRINT:
    print_statement();
    break;
  case TOKENIZER_IF:
    if_statement();
    break;
  case TOKENIZER_GO:
    go_statement();
    return 0;
  case TOKENIZER_RETURN:
    return_statement();
    break;
  case TOKENIZER_FOR:
    for_statement();
    break;
  case TOKENIZER_POKE:
    poke_statement();
    break;
  case TOKENIZER_NEXT:
    next_statement();
    break;
  case TOKENIZER_STOP:
    stop_statement();
    break;
  case TOKENIZER_REM:
    rem_statement();
    break;
  case TOKENIZER_DATA:
    data_statement();
    break;
  case TOKENIZER_RANDOMIZE:
    randomize_statement();
    break;
  case TOKENIZER_OPTION:
    option_statement();
    break;
  case TOKENIZER_INPUT:
    input_statement();
    break;
  case TOKENIZER_RESTORE:
    restore_statement();
    break;
  case TOKENIZER_DIM:
    dim_statement();
    break;
  case TOKENIZER_CLS:
    cls_statement();
    break;
  case TOKENIZER_LET:
  case TOKENIZER_STRINGVAR:
  case TOKENIZER_INTVAR:
    let_statement();
    break;
  default:
    DEBUG_PRINTF("ubasic.c: statement(): not implemented %d\n", token);
    syntax_error();
  }
  return 1;
}
Ejemplo n.º 12
0
void   print_statement_list(statement_list_t * node, int spaces) {
	print_spaces(spaces);
	fprintf(stderr, "STATEMENT_LIST:\n");
	for(; node != NULL && node->statement != NULL; node = node->next)
		print_statement(node->statement, spaces + SP_INDENT);
}
Ejemplo n.º 13
0
//static void statement(void)
void statement(void)
{
	int token;
	token = tokenizer_token();

	switch(token) {
		case TOKENIZER_PRINT:
			print_statement();
			break;
		case TOKENIZER_IF:
			if_statement();
			break;
		case TOKENIZER_GOTO:
			goto_statement();
			break;
		case TOKENIZER_GOSUB:
			gosub_statement();
			break;
		case TOKENIZER_RETURN:
			return_statement();
			break;
		case TOKENIZER_FOR:
			for_statement();
			break;
		case TOKENIZER_NEXT:
			next_statement();
			break;
		case TOKENIZER_END:
			end_statement();
			break;
		case TOKENIZER_PSET:
			pset_statement();
			break;
		case TOKENIZER_CLS:
			cls_statement();
			break;
		case TOKENIZER_REFRESH:
			refresh_statement();
			break;
		case TOKENIZER_LIST:
			list_statement();
			break;
		case TOKENIZER_LOAD:
			load_statement();
			break;
		case TOKENIZER_SAVE:
			save_statement();
			break;
		case TOKENIZER_FILES:
			files_statement();
			break;
		case TOKENIZER_PEEK:
			peek_statement();
			break;
		case TOKENIZER_POKE:
			poke_statement();
			break;
		case TOKENIZER_WAIT:
			wait_statement();
			break;
		case TOKENIZER_INPUT:
			input_statement();
			break;
		case TOKENIZER_INP:
			inp_statement();
			break;
		case TOKENIZER_INR:
			inr_statement();
			break;
		case TOKENIZER_INA:
			ina_statement();
			break;
		case TOKENIZER_REM:
			rem_statement();
			break;
		case TOKENIZER_RUN:
			run_statement();
			break;
		case TOKENIZER_ERROR:
			tokenizer_error_print();
			ended = 1;
			glcd_DrawCursor();
			break;
		case TOKENIZER_LET:
			accept(TOKENIZER_LET);
			accept(TOKENIZER_VARIABLE);
			accept(TOKENIZER_CR);
			break;
			/* Fall through. */
		case TOKENIZER_VARIABLE:
			let_statement();
			break;
		default:
			exit(1);
	}
}