catblocks: linguagem visual com plugins wasm
This commit is contained in:
commit
95d7e3f800
35 files changed
+2294
No files matched your search
@@ -0,0 +1,32 @@
|
||||
/* prova ponta-a-ponta: interpreta o IR, gera .wat e .c, compila o .c com gcc. */
|
||||
#include "catblocks/ir.h"
|
||||
#include "catblocks/programs.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
char *cb_interp_run(cb_node *root, int nvars, char **out, size_t *outlen);
|
||||
|
||||
int main(void) {
|
||||
cb_node *root = cb_program_sum();
|
||||
|
||||
/* 1) interpretar */
|
||||
char *out = NULL; size_t olen = 0;
|
||||
cb_interp_run(root, 4, &out, &olen);
|
||||
printf("== interpretado ==\n%s", out ? out : "(vazio)");
|
||||
int interp_ok = out && strstr(out, "5050") != NULL;
|
||||
|
||||
/* 2) gerar .wat e .c */
|
||||
cb_str wat, c;
|
||||
cb_str_init(&wat); cb_emit_wat(root, &wat);
|
||||
cb_str_init(&c); cb_emit_c(root, &c);
|
||||
FILE *f = fopen("build/test_out.wat", "w"); fputs(wat.buf, f); fclose(f);
|
||||
f = fopen("build/test_out.c", "w"); fputs(c.buf, f); fclose(f);
|
||||
printf("== wat (%zu bytes) e c (%zu bytes) escritos ==\n", wat.len, c.len);
|
||||
|
||||
cb_str_free(&wat); cb_str_free(&c);
|
||||
free(out);
|
||||
cb_node_free_all(NULL);
|
||||
printf(interp_ok ? "IR: OK\n" : "IR: FALHOU\n");
|
||||
return interp_ok ? 0 : 1;
|
||||
}
|
||||
Reference in new issue
Block a user