summaryrefslogtreecommitdiffstats
path: root/src/engine.c
blob: 646d46e4728e38e58d867ed91615e53e340b968d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <stdio.h>
#include <string.h>

#include "librcc.h"

int rccEngineInit(rcc_engine_context *engine_ctx, rcc_context *ctx) {
    if ((!ctx)||(!engine_ctx)) return -1;
    
    engine_ctx->ctx = ctx;
    engine_ctx->free_func = NULL;
    engine_ctx->func = NULL;
    return 0;
}

void rccFreeEngine(rcc_engine_context *engine_ctx) {
    if (!engine_ctx) return;
    
    if (engine_ctx->free_func) {
	engine_ctx->free_func(engine_ctx);
	engine_ctx->free_func = NULL;
    }

    engine_ctx->func = NULL;
    engine_ctx->internal = NULL;
}

int rccEngineConfigure(rcc_engine_context *ctx) {
    rcc_language_id language_id;
    rcc_engine_id engine_id;
    rcc_engine *engine;

    if ((!ctx)||(!ctx->ctx)) return -1;

    rccEngineFree(&ctx);
    
    language_id = rccGetCurrentLanguage(ctx->ctx);
    if (language_id<0) return -1;

    engine_id = rccGetCurrentEngine(ctx->ctx);
    if (engine_id<0) return -1;
    
    engine = ctx->ctx->languages[language_id]->engines[engine_id];
    
    ctx->free_func = engine->free_func;
    ctx->func = engine->func;
    ctx->language = ctx->languages[language_id];

    ctx->internal = engine->init_func(ctx);
    return 0;
}

rcc_engine_internal rccEngineGetInternal(rcc_engine_context *ctx) {
    if (!ctx) return NULL;

    return ctx->internal;
}