| 
									
										
										
										
											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"
 | 
					
						
							| 
									
										
										
										
											2013-06-18 01:36:18 +01:00
										 |  |  | #include "bytecode.h"
 | 
					
						
							| 
									
										
										
										
											2012-09-11 12:24:54 +01:00
										 |  |  | #include "locfile.h"
 | 
					
						
							| 
									
										
										
										
											2012-08-16 01:00:30 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | struct inst; | 
					
						
							|  |  |  | typedef struct inst inst; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef struct block { | 
					
						
							|  |  |  |   inst* first; | 
					
						
							|  |  |  |   inst* last; | 
					
						
							|  |  |  | } block; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-09 00:55:20 -04:00
										 |  |  | block gen_location(location, struct locfile*, block); | 
					
						
							| 
									
										
										
										
											2012-09-11 12:24:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-16 01:00:30 +01:00
										 |  |  | block gen_noop(); | 
					
						
							| 
									
										
										
										
											2014-07-27 17:33:22 -05:00
										 |  |  | int block_is_noop(block b); | 
					
						
							| 
									
										
										
										
											2012-08-16 01:00:30 +01:00
										 |  |  | block gen_op_simple(opcode op); | 
					
						
							| 
									
										
										
										
											2012-12-03 20:00:36 +00:00
										 |  |  | block gen_const(jv constant); | 
					
						
							| 
									
										
										
										
											2014-12-30 13:13:30 -06:00
										 |  |  | block gen_const_global(jv constant, const char *name); | 
					
						
							| 
									
										
										
										
											2014-07-27 17:33:22 -05:00
										 |  |  | int block_is_const(block b); | 
					
						
							| 
									
										
										
										
											2015-06-17 19:46:57 -05:00
										 |  |  | int block_is_const_inf(block b); | 
					
						
							| 
									
										
										
										
											2014-07-27 17:33:22 -05:00
										 |  |  | jv_kind block_const_kind(block b); | 
					
						
							|  |  |  | jv block_const(block b); | 
					
						
							| 
									
										
										
										
											2012-08-16 01:00:30 +01:00
										 |  |  | block gen_op_target(opcode op, block target); | 
					
						
							| 
									
										
										
										
											2013-06-18 01:07:18 +01:00
										 |  |  | block gen_op_unbound(opcode op, const char* name); | 
					
						
							|  |  |  | block gen_op_bound(opcode op, block binder); | 
					
						
							|  |  |  | block gen_op_var_fresh(opcode op, const char* name); | 
					
						
							| 
									
										
										
										
											2012-08-16 01:00:30 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 13:13:30 -06:00
										 |  |  | block gen_module(block metadata); | 
					
						
							| 
									
										
										
										
											2014-08-10 16:52:03 -05:00
										 |  |  | jv block_module_meta(block b); | 
					
						
							| 
									
										
										
										
											2014-12-30 13:13:30 -06:00
										 |  |  | block gen_import(const char* name, block metadata, const char *as, int is_data); | 
					
						
							| 
									
										
										
										
											2012-12-04 00:39:21 +00:00
										 |  |  | block gen_function(const char* name, block formals, block body); | 
					
						
							| 
									
										
										
										
											2014-08-08 18:00:47 -05:00
										 |  |  | block gen_param_regular(const char* name); | 
					
						
							| 
									
										
										
										
											2013-06-18 01:07:18 +01:00
										 |  |  | block gen_param(const char* name); | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							| 
									
										
										
										
											2014-08-09 20:47:03 -05:00
										 |  |  | block gen_const_object(block expr); | 
					
						
							| 
									
										
										
										
											2012-08-16 01:00:30 +01:00
										 |  |  | block gen_collect(block expr); | 
					
						
							| 
									
										
										
										
											2015-06-07 21:45:14 -07:00
										 |  |  | block gen_reduce(block source, block matcher, block init, block body); | 
					
						
							|  |  |  | block gen_foreach(block source, block matcher, block init, block update, block extract); | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-06 14:21:00 +01:00
										 |  |  | block gen_var_binding(block var, const char* name, block body); | 
					
						
							| 
									
										
										
										
											2015-06-07 21:45:14 -07:00
										 |  |  | block gen_array_matcher(block left, block curr); | 
					
						
							|  |  |  | block gen_object_matcher(block name, block curr); | 
					
						
							|  |  |  | block gen_destructure(block var, block matcher, block body); | 
					
						
							| 
									
										
										
										
											2013-05-06 14:21:00 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-04 15:34:34 +01:00
										 |  |  | block gen_cond(block cond, block iftrue, block iffalse); | 
					
						
							| 
									
										
										
										
											2014-12-28 00:32:06 -06:00
										 |  |  | block gen_try_handler(block handler); | 
					
						
							| 
									
										
										
										
											2014-07-05 20:54:42 -05:00
										 |  |  | block gen_try(block exp, block handler); | 
					
						
							| 
									
										
										
										
											2014-12-28 00:32:06 -06:00
										 |  |  | block gen_label(const char *label, block exp); | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							| 
									
										
										
										
											2014-07-09 00:55:20 -04:00
										 |  |  | int block_has_only_binders_and_imports(block, int bindflags); | 
					
						
							| 
									
										
										
										
											2012-09-18 10:17:38 +01:00
										 |  |  | int block_has_only_binders(block, int bindflags); | 
					
						
							| 
									
										
										
										
											2014-07-07 16:03:32 -05:00
										 |  |  | int block_has_main(block); | 
					
						
							|  |  |  | int block_is_funcdef(block b); | 
					
						
							| 
									
										
										
										
											2014-07-27 17:33:22 -05:00
										 |  |  | int block_is_single(block b); | 
					
						
							| 
									
										
										
										
											2012-08-21 18:14:13 +01:00
										 |  |  | block block_bind(block binder, block body, int bindflags); | 
					
						
							| 
									
										
										
										
											2014-07-09 00:55:20 -04:00
										 |  |  | block block_bind_library(block binder, block body, int bindflags, const char* libname); | 
					
						
							| 
									
										
										
										
											2013-05-15 01:37:15 +01:00
										 |  |  | block block_bind_referenced(block binder, block body, int bindflags); | 
					
						
							| 
									
										
										
										
											2014-07-09 00:55:20 -04:00
										 |  |  | block block_drop_unreferenced(block body); | 
					
						
							| 
									
										
										
										
											2012-08-16 01:00:30 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-09 00:55:20 -04:00
										 |  |  | jv block_take_imports(block* body); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int block_compile(block, 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)))
 | 
					
						
							| 
									
										
										
										
											2014-12-26 03:31:54 -06:00
										 |  |  | #define BLOCK_8(b1,b2,b3,b4,b5,b6,b7,b8) (block_join(BLOCK_7(b1,b2,b3,b4,b5,b6,b7),(b8)))
 | 
					
						
							| 
									
										
										
										
											2012-11-25 23:49:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-26 03:31:54 -06:00
										 |  |  | #define BLOCK_IDX(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
 | 
					
						
							| 
									
										
										
										
											2012-11-25 23:49:57 +00:00
										 |  |  | #define BLOCK(...) \
 | 
					
						
							| 
									
										
										
										
											2014-12-26 03:31:54 -06:00
										 |  |  |   BLOCK_IDX(__VA_ARGS__, BLOCK_8, BLOCK_7, BLOCK_6, BLOCK_5, BLOCK_4, BLOCK_3, BLOCK_2, BLOCK_1)(__VA_ARGS__) | 
					
						
							| 
									
										
										
										
											2012-11-25 23:49:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-16 17:08:56 +01:00
										 |  |  | #endif
 |