aboutsummaryrefslogtreecommitdiff
path: root/src/program.c
blob: aa39a4ca64979322ee12d255d5b10222a7c994f5 (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
#include "../include/program.h"
#include <stdio.h>
#include <errno.h>

void amal_program_init(amal_program *self) {
    ignore_result_int(buffer_init(&self->data, NULL));
}

void amal_program_deinit(amal_program *self) {
    buffer_deinit(&self->data);
}

int amal_program_append_bytecode(amal_program *self, Bytecode *bytecode) {
    return buffer_append(&self->data, bytecode->data.data, bytecode->data.size);
}

int amal_program_run(amal_program *self) {
    /* TODO: Implement */
    (void)self;
    return 0;
}

int amal_program_save(amal_program *self, const char *filepath) {
    FILE *file;
    file = fopen(filepath, "wb");
    if(!file) {
        int err;
        err = errno;
        perror(filepath);
        return -err;
    }
    if(fwrite(self->data.data, 1, self->data.size, file) != self->data.size) {
        int err;
        err = errno;
        perror(filepath);
        return -err;
    }
    fclose(file);
    return 0;
}