2012-09-16 17:08:56 +01:00
|
|
|
#ifndef COMPILE_H
|
|
|
|
#define COMPILE_H
|
2012-08-16 01:00:30 +01:00
|
|
|
#include <stdint.h>
|
2012-12-02 21:25:54 +00:00
|
|
|
#include "jv.h"
|
2012-08-16 01:00:30 +01:00
|
|
|
#include "opcode.h"
|
2012-09-11 12:24:54 +01:00
|
|
|
#include "locfile.h"
|
2012-08-16 01:00:30 +01:00
|
|
|
|
2012-12-02 21:25:54 +00:00
|
|
|
struct bytecode;
|
|
|
|
struct symbol_table;
|
2013-05-05 22:37:46 +01:00
|
|
|
struct cfunction;
|
2012-12-02 21:25:54 +00:00
|
|
|
|
2012-08-16 01:00:30 +01:00
|
|
|
struct inst;
|
|
|
|
typedef struct inst inst;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct block {
|
|
|
|
inst* first;
|
|
|
|
inst* last;
|
|
|
|
} block;
|
|
|
|
|
2012-09-11 12:24:54 +01:00
|
|
|
block gen_location(location, block);
|
|
|
|
|
2012-08-16 01:00:30 +01:00
|
|
|
block gen_noop();
|
|
|
|
block gen_op_simple(opcode op);
|
2012-12-03 20:00:36 +00:00
|
|
|
block gen_const(jv constant);
|
2012-08-16 01:00:30 +01:00
|
|
|
block gen_op_target(opcode op, block target);
|
|
|
|
block gen_op_var_unbound(opcode op, const char* name);
|
|
|
|
block gen_op_var_bound(opcode op, block binder);
|
2012-08-21 18:14:13 +01:00
|
|
|
block gen_op_block_unbound(opcode op, const char* name);
|
2012-08-16 01:00:30 +01:00
|
|
|
|
2012-12-04 00:39:21 +00:00
|
|
|
block gen_function(const char* name, block formals, block body);
|
2012-11-26 01:36:55 +00:00
|
|
|
block gen_lambda(block body);
|
|
|
|
block gen_call(const char* name, block body);
|
2012-08-16 01:00:30 +01:00
|
|
|
block gen_subexp(block a);
|
|
|
|
block gen_both(block a, block b);
|
|
|
|
block gen_collect(block expr);
|
2012-12-28 15:04:16 +00:00
|
|
|
block gen_fold(const char* varname, block init, block body);
|
2012-09-04 15:34:34 +01:00
|
|
|
block gen_definedor(block a, block b);
|
2012-09-17 21:08:43 +01:00
|
|
|
block gen_condbranch(block iftrue, block iffalse);
|
2012-09-04 20:38:59 +01:00
|
|
|
block gen_and(block a, block b);
|
|
|
|
block gen_or(block a, block b);
|
2012-09-04 15:34:34 +01:00
|
|
|
|
|
|
|
block gen_cond(block cond, block iftrue, block iffalse);
|
2012-08-16 01:00:30 +01:00
|
|
|
|
2013-05-05 22:37:46 +01:00
|
|
|
block gen_cbinding(const struct cfunction* functions, int nfunctions, block b);
|
2012-08-16 01:00:30 +01:00
|
|
|
|
|
|
|
void block_append(block* b, block b2);
|
|
|
|
block block_join(block a, block b);
|
2012-09-18 10:17:38 +01:00
|
|
|
int block_has_only_binders(block, int bindflags);
|
2012-08-21 18:14:13 +01:00
|
|
|
block block_bind(block binder, block body, int bindflags);
|
2012-08-16 01:00:30 +01:00
|
|
|
|
2012-09-11 12:24:54 +01:00
|
|
|
int block_compile(block, struct locfile*, struct bytecode**);
|
2012-08-16 01:00:30 +01:00
|
|
|
|
|
|
|
void block_free(block);
|
2012-08-27 11:19:42 +01:00
|
|
|
|
|
|
|
|
2012-09-16 17:08:56 +01:00
|
|
|
|
2012-11-25 23:49:57 +00:00
|
|
|
// Here's some horrible preprocessor gunk so that code
|
|
|
|
// sequences can be contructed as BLOCK(block1, block2, block3)
|
|
|
|
|
|
|
|
#define BLOCK_1(b1) (b1)
|
|
|
|
#define BLOCK_2(b1,b2) (block_join((b1),(b2)))
|
|
|
|
#define BLOCK_3(b1,b2,b3) (block_join(BLOCK_2(b1,b2),(b3)))
|
|
|
|
#define BLOCK_4(b1,b2,b3,b4) (block_join(BLOCK_3(b1,b2,b3),(b4)))
|
|
|
|
#define BLOCK_5(b1,b2,b3,b4,b5) (block_join(BLOCK_4(b1,b2,b3,b4),(b5)))
|
|
|
|
#define BLOCK_6(b1,b2,b3,b4,b5,b6) (block_join(BLOCK_5(b1,b2,b3,b4,b5),(b6)))
|
|
|
|
#define BLOCK_7(b1,b2,b3,b4,b5,b6,b7) (block_join(BLOCK_6(b1,b2,b3,b4,b5,b6),(b7)))
|
|
|
|
|
|
|
|
#define BLOCK_IDX(_1,_2,_3,_4,_5,_6,_7,NAME,...) NAME
|
|
|
|
#define BLOCK(...) \
|
|
|
|
BLOCK_IDX(__VA_ARGS__, BLOCK_7, BLOCK_6, BLOCK_5, BLOCK_4, BLOCK_3, BLOCK_2, BLOCK_1)(__VA_ARGS__)
|
|
|
|
|
|
|
|
|
2012-09-16 17:08:56 +01:00
|
|
|
#endif
|