<commit_before>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

#include <sys/stat.h>

#include "stb_ds.h"

#include "info.h"
#include "ints.h"
#include "ast.h"
#include "parse.c"
#include "symbol_resolution.c"
#include "typecheck.c"
#include "bytecodegen.c"
#include "unsafevm.c"
#include "init.c"

int main()
{
	char *srcbuf;
	init();
	{	/* read source */
		struct stat st;
		stat("test.soal", &st);
		srcbuf = malloc(sizeof(char) * st.st_size + 1);
		FILE* testfile = fopen("test.soal", "r");
		size_t readcount = fread(srcbuf, 1, st.st_size, testfile);
		if(readcount != st.st_size) {
			fprintf(stderr, "failed to read input file\n");
			fclose(testfile); /* :( */
			exit(EXIT_FAILURE);
		}
		srcbuf[readcount] = '\0';
		fclose(testfile);
	}
	struct toplevelnode n = parse(srcbuf, "test.soal");
	/*struct sym_table *stbl = collect_module_syms(&n);*/
	resolve_toplevel_symbols(&n);
	struct genstate gs = emit_bytecode(&n);
	run_program(&gs);
}


#define STB_DS_IMPLEMENTATION
#include "stb_ds.h"<commit_msg>factor out read entire file since it will be used elsewhere<commit_after>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

#include <sys/stat.h>

#include "stb_ds.h"

#include "info.h"
#include "ints.h"
#include "ast.h"
#include "parse.c"
#include "symbol_resolution.c"
#include "typecheck.c"
#include "bytecodegen.c"
#include "unsafevm.c"
#include "init.c"

char *read_entire_file(char *path)
{
	char *buf;
	struct stat st;

	stat(path, &st);
	buf = malloc(sizeof(char) * st.st_size + 1);

	FILE* f = fopen(path, "r");
	size_t readcount = fread(buf, 1, st.st_size, f);
	if(readcount != st.st_size) {
		fprintf(stderr, "failed to read input file %s\n", path);
		fclose(f); /* :( */
		exit(EXIT_FAILURE);
	}
	buf[readcount] = '\0';
	fclose(f);
	return buf;
}

int main()
{
	init();

	char *srcbuf = read_entire_file("test.soal");
	struct toplevelnode n = parse(srcbuf, "test.soal");
	/*struct sym_table *stbl = collect_module_syms(&n);*/
	resolve_toplevel_symbols(&n);
	struct genstate gs = emit_bytecode(&n);
	run_program(&gs);
}


#define STB_DS_IMPLEMENTATION
#include "stb_ds.h"
{'fraction_non_alphanumeric': 0.176109537299339, 'fraction_numerical': 0.0028328611898017, 'mean_word_length': 4.8054794520547945, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2927817', 'n_tokens_mistral': 912, 'n_tokens_neox': 878, 'n_words': 191}