コード例 #1
0
ファイル: lang_constexpr.c プロジェクト: dkoby/stm8mu
static void _not_opd(struct symbols_t *sl, struct token_t *token)
{
    char *tname;
    
    PRINTF("%s" NL, __FUNCTION__);
    if ((tname = token_get(token, TOKEN_TYPE_NUMBER, TOKEN_NEXT)))
    {
        int64_t value;

        PRINTF("NUM %s" NL, tname);

        if (lang_util_str2num(tname, &value) < 0)
        {
            token_print_rollback(token);
            app_close(APP_EXITCODE_ERROR);
        }

        _exprstack_push(value);
    } else if ((tname = token_get(token, TOKEN_TYPE_SYMBOL, TOKEN_NEXT))) {
        struct symbol_t *s;
        int64_t value;

        s = symbol_get_const(sl, tname, &value);
        if (!s)
        {
            debug_emsgf("Symbol not found", "%s" NL, tname);
            token_print_rollback(token);
            app_close(APP_EXITCODE_ERROR);
        }
        _exprstack_push(value);
    } else if (token_get(token, TOKEN_TYPE_ROUND_OPEN, TOKEN_NEXT)) {
        _expr(sl, token);
        if (!token_get(token, TOKEN_TYPE_ROUND_CLOSE, TOKEN_NEXT))
        {
            debug_emsg("Missing \")\" in expr");
            token_print_rollback(token);
            app_close(APP_EXITCODE_ERROR);
        }
    } else {
        debug_emsg("Empty expression");
        token_print_rollback(token);
        app_close(APP_EXITCODE_ERROR);
    }
}
コード例 #2
0
ファイル: lang_constexpr.c プロジェクト: dkoby/stm8mu
static void _exprstack_push(int64_t value)
{
    if (exprstack.depth > EXPR_STACK_SIZE)
    {
        debug_emsg("Expression stack overflow");
        app_close(APP_EXITCODE_ERROR);
    }
    PRINTF("push %llu" NL, value);
    exprstack.stack[exprstack.depth++] = value;
}
コード例 #3
0
ファイル: lang_constexpr.c プロジェクト: dkoby/stm8mu
static int64_t _exprstack_pop()
{
    if (exprstack.depth <= 0)
    {
        debug_emsg("Expression stack underflow");
        app_close(APP_EXITCODE_ERROR);
    }

    PRINTF("pop  %llu" NL, exprstack.stack[exprstack.depth - 1]);
    return exprstack.stack[--exprstack.depth];
}
コード例 #4
0
ファイル: lang_constexpr.c プロジェクト: dkoby/stm8mu
int lang_constexpr(struct symbols_t *sl, struct token_t *token, int64_t *value)
{
    if (!token_get(token, TOKEN_TYPE_CURLY_OPEN, TOKEN_NEXT))
        return -1;

    /*
     * Expression syntax.
     *
     *     EXPR      = EXPR, "|", OR_OPD | OR_OPD
     *     OR_OPD    = OR_OPD, "^", XOR_OPD | XOR_OPD
     *     XOR_OPD   = XOR_OPD, "&", AND_OPD | AND_OPD
     *     AND_OPD   = AND_OPD, "<<", SHIFT_OPD | AND_OPD, ">>", SHIFT_OPD | SHIFT_OPD
     *     SHIFT_OPD = SHIFT_OPD, "+", ADD_OPD | SHIFT_OPD, "-", ADD_OPD | ADD_OPD
     *     ADD_OPD   = ADD_OPD, "*", MUL_OPD | ADD_OPD, "/", MUL_OPD | ADD_OPD, "%", MUL_OPD | MUL_OPD
     *     MUL_OPD   = "~", MUL_OPD | NOT_OPD
     *     NOT_OPD   = NUMBER | SYMBOL | "(", EXPR, ")"
     *
     * Eliminate of left recursion.
     *
     *     EXPR       = OR_OPD, EXPRR
     *     EXPRR      = "|", OR_OPD, EXPRR | 0
     *     OR_OPD     = XOR_OPD, OR_OPDR
     *     OR_OPDR    = "^", XOR_OPD, OR_OPDR | 0
     *     XOR_OPD    = AND_OPD, XOR_OPDR
     *     XOR_OPDR   = "&", AND_OPD, XOR_OPDR | 0
     *     AND_OPD    = SHIFT_OPD, AND_OPDR
     *     AND_OPDR   = "<<", SHIFT_OPD, AND_OPDR | ">>", SHIFT_OPD, AND_OPDR | 0
     *     SHIFT_OPD  = ADD_OPD, SHIFT_OPDR
     *     SHIFT_OPDR = "+", ADD_OPD, SHIFT_OPDR | "-", ADD_OPD, SHIFT_OPDR | 0
     *     ADD_OPD    = MUL_OPD, ADD_OPDR
     *     ADD_OPDR   = "*", MUL_OPD, ADD_OPDR | "/", MUL_OPD, ADD_OPDR |"%", MUL_OPD, ADD_OPDR | 0
     *     MUL_OPD    = "!", NOT_OPD | NOT_OPD
     *     NOT_OPD    = NUMBER | SYMBOL | "(", EXPR, ")"
     */

    _exprstack_flush();

    _expr(sl, token);

    *value = _exprstack_pop();

    if (!token_get(token, TOKEN_TYPE_CURLY_CLOSE, TOKEN_NEXT))
    {
        debug_emsg("Missing \"}\" in expr");
        token_print_rollback(token);
        app_close(APP_EXITCODE_ERROR);
    }

    token_drop(token);

    return 0;
}
コード例 #5
0
ファイル: app.c プロジェクト: YEXINGZHE54/pebble
int module_global_init(void){
    ngx_pool_t *pool;
	ngx_log_t *log;
    pool = ngx_create_pool(4096, log);
    if (pool == NULL){
		app_close(1);
        printf("Error while creating pool buffer!");
        return -1;
    }
    globals_r.pool = pool;
    globals_r.log  = log;
    return 0;
}
コード例 #6
0
int main(int argc, char **argv)
{
	int retval = 0;
	if (app_init(argc, argv)) {
		retval = -1;
		goto out;
	}

	/*if (matrix_cmd(MATRIX_MODE_GRAYSCALE)) {
		retval = -1;
		goto out;
	}*/

	picture_t *pic = picture_alloc();

	int i;

	int timeval;

	const unsigned int start = 100000;
	
	for(i = 0 ; i < 176 ; i++)
	{
	  if(i<60)
            timeval = (double)start - (double)(start/1000)*pow(i,1.6);
	  else
            timeval = (double)start - (double)(start/1000)*pow(60,1.6) - (double)(start/1000)*pow(i-60,1.2);

    	  picture_full(pic);
  	  matrix_update(pic);
  	  usleep(timeval);
  	  picture_clear(pic);
  	  matrix_update(pic);
          usleep(timeval);
	}

	picture_free(pic);

 out:
	app_close();

	return retval;
}
コード例 #7
0
ファイル: assembler.c プロジェクト: dkoby/stm8mu
void assembler_init()
{
    struct asm_context_t *ctx;

    app.asmcontext = malloc(sizeof(struct asm_context_t));
    if (!app.asmcontext)
    {
        debug_emsg("Can not allocate memory");
        app_close(APP_EXITCODE_ERROR);
    }

    ctx = app.asmcontext;

    ctx->pass     = 0;
    ctx->dbendian = DB_ENDIAN_BIG;

    tokens_init(&ctx->tokens);
    symbols_init(&ctx->symbols);
    sections_init(&ctx->sections);
    relocations_init(&ctx->relocations);

    ctx->section = section_select(&ctx->sections, "text");
}
コード例 #8
0
ファイル: relocation.c プロジェクト: dkoby/stm8mu
void relocations_add(struct relocations_t *rl,
                     char *section, char *symbol, uint32_t offset, uint32_t length, int32_t adjust, enum relocation_type_t type)
{
    struct llist_t *head;
    struct relocation_t *r;

    r = malloc(sizeof(struct relocation_t));
    if (!r)
        goto error;

    r->section = malloc(strlen(section) + 1);
    if (!r->section)
        goto error;
    strcpy(r->section, section);
    r->symbol = malloc(strlen(symbol) + 1);
    if (!r->symbol)
        goto error;
    strcpy(r->symbol, symbol);

    r->type   = type;
    r->offset = offset;
    r->length = length;
    r->adjust = adjust;

    head = llist_add(rl->first, r, _relocation_destroy, r);
    if (!head)
        goto error;
    rl->first = head;

    return;
error:
    debug_emsg("Can not add relocation");
    if (r)
        _relocation_destroy(r);
    app_close(APP_EXITCODE_ERROR);
}