aboutsummaryrefslogtreecommitdiff
path: root/src/program.c
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-07-17 19:23:16 +0200
committerdec05eba <dec05eba@protonmail.com>2020-07-25 14:36:46 +0200
commit84e65c63e7482590d535e86f7660a00ae8a0cecb (patch)
treec79de87b7136e96b977003db85d43e5e676bbfc1 /src/program.c
parent85c654a102701958d3748e82ecac9c1bc4dbbcba (diff)
Start on amal program
Fix mutex issue in lhs expr which can cause a deadlock when a file has an error and throws and doesn't close the mutex and another thread waits for that mutex. The mutex can instead be removed and ignore race conditions which are uncommon. This should improve memory usage and performance.
Diffstat (limited to 'src/program.c')
-rw-r--r--src/program.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/program.c b/src/program.c
new file mode 100644
index 0000000..aa39a4c
--- /dev/null
+++ b/src/program.c
@@ -0,0 +1,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;
+}
+