aboutsummaryrefslogtreecommitdiff
path: root/src/prc1/display.c
blob: 70fac9359bb1e7a7993bf442d719be30ee605103 (plain) (blame)
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
#include "display.h"
#include "cgen.h"
#include "dbg.h"
#include "fn.h"
#include "parse.h"
#include "prv.h"
#include "stmt.h"
#include <stddef.h>
#include <stdlib.h>

int display_cgen(const struct print *pr, struct cgen *c)
{
    return print_cgen(pr, c, "stdout");
}

int display(const struct lex *l, struct prv *p)
{
    struct fn *fn = fn_cur(p);
    size_t n = fn->nstmts + 1;
    struct stmt *stmts = realloc(fn->stmts, n * sizeof *stmts);

    if (!stmts)
    {
        perror("realloc(3)");
        return -1;
    }

    dbg("\t\tadd display statement\n");
    stmts[fn->nstmts++] = (struct stmt){.type = DISPLAY, .u.print = {0}};
    fn->stmts = stmts;
    return print(l, p);
}