Ejemplo n.º 1
0
Archivo: bytecode.c Proyecto: 40a/jq
void bytecode_free(struct bytecode* bc) {
  if (!bc)
    return;
  jv_mem_free(bc->code);
  jv_free(bc->constants);
  for (int i=0; i<bc->nsubfunctions; i++)
    bytecode_free(bc->subfunctions[i]);
  if (!bc->parent)
    symbol_table_free(bc->globals);
  jv_mem_free(bc->subfunctions);
  jv_free(bc->debuginfo);
  jv_mem_free(bc);
}
Ejemplo n.º 2
0
Archivo: main.c Proyecto: tadeboro/hip
G_MODULE_EXPORT void
cb_compile (GtkToolButton *button,
	    AppData       *data)
{
  char *code;

  symbol_table_free (data->symtable);
  data->symtable = symbol_table_new ();
  g_object_get (data->text_buffer, "text", &code, NULL);
  compile (code, data->mem, data->symtable);
  g_free (code);
  update_mcode (data);
  update_symtable (data);
  update_data (data);
}
Ejemplo n.º 3
0
Archivo: main.c Proyecto: tadeboro/hip
static void
update_processor (AppData *data)
{
  if (data->mem)
    memory_free (data->mem);
  if (data->regs)
    registers_free (data->regs);
  if (data->symtable)
    symbol_table_free (data->symtable);

  /* Create empty symbol table (to be populated during parse) */
  data->symtable = symbol_table_new ();

  /* Create registers */
  data->regs = registers_new (g_key_file_get_integer (data->settings,
						      "processor",
						      "no_registers",
						      NULL));
  /* Create designated memory segments */
  data->mem = memory_new ();
  memory_add_data_segment (data->mem, MEM_SEG_DATA,
			   g_key_file_get_integer (data->settings,
						   "data segment",
						   "origin",
						   NULL),
			   g_key_file_get_integer (data->settings,
						   "data segment",
						   "size",
						   NULL));
  memory_add_data_segment (data->mem, MEM_SEG_CODE,
			   g_key_file_get_integer (data->settings,
						   "code segment",
						   "origin",
						   NULL),
			   g_key_file_get_integer (data->settings,
						   "code segment",
						   "size",
						   NULL));
  update_symtable (data);
  update_mcode (data);
  update_data (data);
  update_regs (data);
}
Ejemplo n.º 4
0
Archivo: main.c Proyecto: catseye/Bhuna
int
main(int argc, char **argv)
{
	char **real_argv = argv;
	struct scan_st *sc;
	struct symbol_table *stab;
	struct ast *a;
	char *source = NULL;
	int opt;
	int err_count = 0;
#ifdef DEBUG
	int run_program = 1;
	int dump_symbols = 0;
	int dump_program = 0;
	int dump_icode = 0;
#endif

#ifdef DEBUG
	setvbuf(stdout, NULL, _IOLBF, 0);
#endif

	/*
	 * Get command-line arguments.
	 */
	while ((opt = getopt(argc, argv, OPTS)) != -1) {
		switch(opt) {
#ifdef DEBUG
		case 'c':
			trace_scheduling++;
			break;
#ifdef POOL_VALUES
		case 'd':
			trace_pool++;
			break;
#endif
		case 'g':
			trace_gc++;
			break;
#endif
		case 'G':
			gc_trigger = atoi(optarg);
			break;
#ifdef DEBUG
		case 'i':
			dump_icode++;
			break;
		case 'l':
			trace_gen++;
			break;
		case 'm':
			trace_vm++;
			break;
		case 'n':
			run_program = 0;
			break;
		case 'o':
			trace_valloc++;
			break;
		case 'p':
			dump_program = 1;
			break;
		case 's':
			dump_symbols = 1;
			break;
		case 'v':
			trace_activations++;
			break;
		case 'y':
			trace_type_inference++;
			break;
#endif
		case '?':
		default:
			usage(argv);
		}
	}
	argc -= optind;
	argv += optind;

	if (*argv != NULL)
		source = *argv;
	else
		usage(real_argv);

#ifdef POOL_VALUES
	value_pool_new();
#endif

	gc_target = gc_trigger;
	if ((sc = scan_open(source)) != NULL) {
		stab = symbol_table_new(NULL, 0);
		global_ar = activation_new_on_heap(100, NULL, NULL);
		register_std_builtins(stab);
		report_start();
		a = parse_program(sc, stab);
		scan_close(sc);
#ifdef DEBUG
		if (dump_symbols)
			symbol_table_dump(stab, 1);
		if (dump_program) {
			ast_dump(a, 0);
		}
#endif
#ifndef DEBUG
		symbol_table_free(stab);
		types_free();
#endif
		err_count = report_finish();
		if (err_count == 0) {
			struct iprogram *ip;
			struct vm *vm;
			struct process *p;
			unsigned char *program;

			program = bhuna_malloc(16384);

			ip = ast_gen_iprogram(a);
			iprogram_eliminate_nops(ip);
			iprogram_eliminate_useless_jumps(ip);
			iprogram_optimize_tail_calls(ip);
			iprogram_optimize_push_small_ints(ip);
			iprogram_eliminate_dead_code(ip);
			iprogram_gen(&program, ip);
#ifdef DEBUG
			if (dump_icode > 0)
				iprogram_dump(ip, program);
#endif

			vm = vm_new(program, 16384);
			vm_set_pc(vm, program);
			vm->current_ar = global_ar;
			p = process_new(vm);
			/* ast_dump(a, 0); */
			if (RUN_PROGRAM) {
				process_scheduler();
			}
			vm_free(vm);
			bhuna_free(program);
			/*value_dump_global_table();*/
		}

		ast_free(a);	/* XXX move on up */
		/* gc(); */		/* actually do a full blow out at the end */
		/* activation_free_from_stack(global_ar); */
#ifdef DEBUG
		symbol_table_free(stab);
		types_free();
		if (trace_valloc > 0) {
			/*
			value_dump_global_table();
			*/
			printf("Created:  %8d\n", num_vars_created);
			printf("Cached:   %8d\n", num_vars_cached);
			printf("Freed:    %8d\n", num_vars_freed);
		}
		if (trace_activations > 0) {
			printf("AR's alloc'ed:  %8d\n", activations_allocated);
			printf("AR's freed:     %8d\n", activations_freed);
		}
#ifdef POOL_VALUES
		if (trace_pool > 0) {
			pool_report();
		}
#endif
#endif
		return(0);
	} else {
		fprintf(stderr, "Can't open `%s'\n", source);
		return(1);
	}
}