Example #1
0
File: stmt.c Project: matsuu/konoha
void knh_Stmt_add(Ctx *ctx, Stmt *o, Term *tm)
{
    KNH_ASSERT(IS_Term(tm));
    KNH_ASSERT(SP(o)->stt != STT_DONE);
    if(!(DP(o)->size < DP(o)->capacity)) {
        knh_Stmt_terms_expand(ctx, o);
    }
    KNH_SETv(ctx, DP(o)->terms[DP(o)->size], tm);
    DP(o)->size++;
    if(IS_Stmt(tm)) {
        Stmt *stmt = (Stmt*)tm;
        DP(o)->line_end = SP(stmt)->line;
        if(SP(o)->line == 0) {
            SP(o)->line = DP(stmt)->line_end;
            SP(o)->uri = SP(stmt)->uri;
        }
        if(SP(stmt)->stt == STT_ERR) {
            knh_Stmt_toERR(ctx, o, tm);
        }
    }
    else {
        Token *tk = (Token*)tm;
        DP(o)->line_end = SP(tk)->line;
        if(SP(o)->line == 0) {
            SP(o)->line = DP(o)->line_end;
            SP(o)->uri = SP(tk)->uri;
        }
        if(SP(tk)->tt == TT_ERR) {
            knh_Stmt_toERR(ctx, o, tm);
        }
    }
}
Example #2
0
static void JumpStmt_asm(KonohaContext *kctx, kStmt *stmt, int shift, int espidx)
{
	SugarSyntax *syn = stmt->syn;
	kStmt *jump = (kStmt*)kStmt_getObject(kctx, stmt, syn->keyword, NULL);
	DBG_ASSERT(jump != NULL);
	DBG_ASSERT(IS_Stmt(jump));
	kBasicBlock* lbJUMP = (kBasicBlock*)KLIB kObject_getObject(kctx, jump, syn->keyword, NULL);
	DBG_ASSERT(lbJUMP != NULL);
	DBG_ASSERT(IS_BasicBlock(lbJUMP));
	ASM_JMP(kctx, lbJUMP);
}
Example #3
0
File: stmt.c Project: matsuu/konoha
void knh_Stmt_toERR(Ctx *ctx, Stmt *stmt, Term *tm)
{
    if(SP(stmt)->stt == STT_ERR) return;
    SP(stmt)->stt = STT_ERR;
    knh_uri_t uri = 0;
    int line = 0;
    if(IS_Token(tm)) {
        uri =  SP((Token*)tm)->uri;
        line =  SP((Token*)tm)->line;
    }
    else if(IS_Stmt(tm)) {
        uri =  SP((Stmt*)tm)->uri;
        line =  SP((Stmt*)tm)->line;
    }
    {
        char buf[256];
        knh_snprintf(buf, sizeof(buf), "Script!!: running errors at %s:%d", URIDN(SP(stmt)->uri), SP(stmt)->line);
        KNH_SETv(ctx, DP(stmt)->errMsg, new_String(ctx, B(buf), NULL));
        KNH_SETv(ctx, DP(stmt)->next, KNH_NULL);
    }
}
Example #4
0
File: stmt.c Project: matsuu/konoha
void knh_Stmt__s(Ctx *ctx, Stmt *o, OutputStream *w, String *m)
{
    knh_intptr_t i;
    knh_putc(ctx, w, '(');
    if(SP(o)->stt != STT_OP && SP(o)->stt != STT_NEW && SP(o)->stt != STT_CALL ) {
        knh_write_char(ctx, w, knh_stmt_tochar(SP(o)->stt));
        if(DP(o)->size > 0) {
            knh_putc(ctx, w, ' ');
        }
    }
    for(i = 0; i < DP(o)->size; i++) {
        if(i > 0) knh_putc(ctx, w, ' ');
        if(IS_Token(DP(o)->terms[i])) {
            knh_Token__s(ctx, DP(o)->tokens[i], w, m);
        } else {
            KNH_ASSERT(IS_Stmt(DP(o)->terms[i]));
            knh_Stmt__s(ctx, DP(o)->stmts[i], w, m);
            if(IS_NOTNULL(DP(DP(o)->stmts[i])->next)) {
                knh_write_dots(ctx, w);
            }
        }
    }
    knh_putc(ctx, w, ')');
}