2017-11-21 02:39:44 +00:00
|
|
|
#include "unit.h"
|
|
|
|
#include <dst/dst.h>
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
DstParseResult pres;
|
|
|
|
DstAssembleOptions opts;
|
|
|
|
DstAssembleResult ares;
|
|
|
|
DstFunction *func;
|
|
|
|
|
2017-12-17 04:11:51 +00:00
|
|
|
FILE *f = fopen("./dsttest/minimal.dsts", "rb");
|
2017-11-21 02:39:44 +00:00
|
|
|
fseek(f, 0, SEEK_END);
|
|
|
|
long fsize = ftell(f);
|
|
|
|
fseek(f, 0, SEEK_SET); //same as rewind(f);
|
|
|
|
|
|
|
|
char *string = malloc(fsize + 1);
|
|
|
|
fread(string, fsize, 1, f);
|
|
|
|
fclose(f);
|
|
|
|
|
|
|
|
string[fsize] = 0;
|
|
|
|
|
|
|
|
dst_init();
|
|
|
|
|
|
|
|
pres = dst_parsec(string);
|
|
|
|
free(string);
|
|
|
|
|
|
|
|
if (pres.status == DST_PARSE_ERROR) {
|
2017-12-17 04:11:51 +00:00
|
|
|
dst_puts(dst_formatc("parse error at %d: %S\n", pres.bytes_read, pres.error));
|
2017-11-21 02:39:44 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
assert(pres.status == DST_PARSE_OK);
|
2017-12-17 04:11:51 +00:00
|
|
|
dst_puts(dst_formatc("\nparse result: %v\n\n", pres.value));
|
2017-11-21 02:39:44 +00:00
|
|
|
|
|
|
|
opts.flags = 0;
|
2017-12-17 04:11:51 +00:00
|
|
|
opts.source = pres.value;
|
2017-12-08 20:57:02 +00:00
|
|
|
opts.sourcemap = pres.map;
|
2017-11-21 02:39:44 +00:00
|
|
|
|
|
|
|
ares = dst_asm(opts);
|
|
|
|
if (ares.status == DST_ASSEMBLE_ERROR) {
|
2017-12-17 04:11:51 +00:00
|
|
|
dst_puts(dst_formatc("assembly error: %S\n", ares.error));
|
2017-12-08 20:57:02 +00:00
|
|
|
dst_puts(dst_formatc("error location: %d, %d\n", ares.error_start, ares.error_end));
|
2017-11-21 02:39:44 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
assert(ares.status == DST_ASSEMBLE_OK);
|
|
|
|
|
|
|
|
func = dst_asm_func(ares);
|
2017-12-17 04:11:51 +00:00
|
|
|
|
|
|
|
dst_puts(dst_formatc("\nfuncdef: %v\n\n", dst_disasm(ares.funcdef)));
|
2017-11-21 02:39:44 +00:00
|
|
|
|
|
|
|
dst_run(dst_wrap_function(func));
|
|
|
|
dst_puts(dst_formatc("result: %v\n", dst_vm_fiber->ret));
|
2017-11-29 20:17:56 +00:00
|
|
|
|
|
|
|
dst_deinit();
|
2017-11-21 02:39:44 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|