#ifndef __COMPILE
#define __COMPILE
-//m_bool check_filename(struct Gwion_* vm, const m_str filename);
-m_bool check_string(struct Gwion_* vm, const m_str filename, const m_str data);
-//m_bool check_file(struct Gwion_* vm, const m_str filename, FILE* file);
m_uint compile_filename(struct Gwion_* vm, const m_str filename);
m_uint compile_string(struct Gwion_* vm, const m_str filename, const m_str data);
-//m_uint compile_file(struct Gwion_* vm, const m_str filename, FILE* file);
+m_uint compile_file(struct Gwion_* vm, const m_str filename, FILE* file);
#endif
static void compiler_clean(MemPool p, const struct Compiler* c) {
if(c->name)
xfree(c->name);
- if(c->file)
+ if(c->type == COMPILE_MSTR && c->file)
fclose(c->file);
if(c->ast)
free_ast(p, c->ast);
m_str name = c->name;
c->name = realpath(name, NULL);
xfree(name);
- return c->name ? !!(c->file = fopen(c->name, "r")) : -1;
- } else if(c->type == COMPILE_MSTR)
- return (c->file = fmemopen(c->data, strlen(c->data) + 1, "r")) ? 1 : - 1;
+ return c->name ? !!(c->file = fopen(c->name, "r")) : GW_ERROR;
+ } else if(c->type == COMPILE_MSTR) {
+ c->file = fmemopen(c->data, strlen(c->data), "r");
+ return c->file ? GW_OK : GW_ERROR;
+ }
return GW_OK;
}
return compile(vm, &c);
}
-/*
m_uint compile_file(struct Gwion_* vm, const m_str filename, FILE* file) {
- struct Compiler c = { .base=filename, .type=COMPILE_MSTR, .file=file };
+ struct Compiler c = { .base=filename, .type=COMPILE_FILE, .file=file };
return compile(vm, &c);
}
-*/
--- /dev/null
+#include "gwion_util.h"
+#include "gwion_ast.h"
+#include "oo.h"
+#include "vm.h"
+#include "env.h"
+#include "type.h"
+#include "object.h"
+#include "instr.h"
+#include "gwion.h"
+#include "value.h"
+#include "operator.h"
+#include "import.h"
+#include "gwi.h"
+#include "compile.h"
+
+#define _XOPEN_SOURCE 500
+#include <string.h>
+GWION_IMPORT(compile_string) {
+ DECL_OB(FILE *,file, = fopen("rm_me.gw", "w+"))
+ fprintf(file, "1;");
+ rewind(file);
+ const m_bool ret = compile_file(gwi->gwion, __FILE__, file) ?
+ GW_OK : GW_ERROR;
+ fclose(file);
+ return ret;
+}
--- /dev/null
+#include "gwion_util.h"
+#include "gwion_ast.h"
+#include "oo.h"
+#include "vm.h"
+#include "env.h"
+#include "type.h"
+#include "object.h"
+#include "instr.h"
+#include "gwion.h"
+#include "value.h"
+#include "operator.h"
+#include "import.h"
+#include "gwi.h"
+#include "compile.h"
+
+#define _XOPEN_SOURCE 500
+#include <string.h>
+GWION_IMPORT(compile_string) {
+ return compile_string(gwi->gwion, __FILE__, "1;") ?
+ GW_OK : GW_ERROR;
+}
--- /dev/null
+#include <stdlib.h>
+#include <unistd.h>
+#include "gwion_util.h"
+#include "gwion_ast.h"
+#include "oo.h"
+#include "env.h"
+#include "vm.h"
+#include "type.h"
+#include "value.h"
+#include "object.h"
+#include "driver.h"
+#include "gwion.h"
+#include "instr.h"
+#include "operator.h"
+#include "import.h"
+#include "gwi.h"
+#include "plug.h"
+
+GWMODSTR(dummy_module);
+
+GWMODINI(dummy_module) {
+ puts(__func__);
+ return NULL;
+}
+GWMODEND(dummy_module) {
+ puts(__func__);
+}
+
+GWION_IMPORT(dummy_module) {
+ GWI_OB(get_module(gwi->gwion, "dummy"))
+ get_module(gwi->gwion, "non_existant_module");
+ return GW_OK;
+}
--- /dev/null
+1;
\ No newline at end of file