<commit_before>#include "Kernel.h"
#include "lib/Runtime.h"
#include "lib/Global.h"
#include "lib/Function.h"
#include "ASTNode.h"
#include "parser/Driver.h"

#include <fstream>

namespace snow {
	void Kernel::init() {
		static bool initted = false;
		if (initted)
			return;
		
		// Set up runtime symbols needed for linking and compiling snow sources.
		SymbolTable& table = runtime_symbols();
		table["snow_eval_truth"] = (void*)snow::eval_truth;
		table["snow_call"] = (void*)snow::call;
		table["snow_get"] = (void*)snow::get;
		table["snow_set"] = (void*)snow::set;
		table["snow_enter_scope"] = (void*)snow::enter_scope;
		table["snow_leave_scope"] = (void*)snow::leave_scope;
		table["snow_set_parent_scope"] = (void*)snow::set_parent_scope;
		table["snow_get_local"] = (void*)snow::get_local;
		
		// Bind basic standard library stuff in global scope.
		Global::define_globals(global_scope());
		
		initted = true;
	}
	
	VALUE Kernel::require(const std::string& file) {
		std::ifstream f(file.c_str());
		RefPtr<ast::FunctionDefinition> scope = Driver::parse(f, file);
		f.close();
		
		if (!scope) {
			error("An unknown error occured while parsing `%s'", file.c_str());
			TRAP();
		}
		
		RefPtr<Codegen> codegen = Codegen::create(*scope);
		RefPtr<CompiledCode> cc = codegen->compile();
		
		cc->link(runtime_symbols());
		
		// TODO: Delay make_executable?
		cc->make_executable();
		
		Handle<Function> func = new Function(*cc);
		
		// TODO: We can't call with global scope because of the way locals work... Yet!
		//return func->call_in_scope(&global_scope());
		func->set_parent_scope(&global_scope());
		return func->call(nil(), 0);
	}
	
	SymbolTable& Kernel::runtime_symbols() {
		static SymbolTable s;
		return s;
	}
	
	Scope& Kernel::global_scope() {
		static Scope s;
		return s;
	}<commit_msg>Kernel: added disasm step for DEBUG<commit_after>#include "Kernel.h"
#include "lib/Runtime.h"
#include "lib/Global.h"
#include "lib/Function.h"
#include "ASTNode.h"
#include "parser/Driver.h"

#include "x86_64/Disassembler.h"

#include <fstream>

namespace snow {
	void Kernel::init() {
		static bool initted = false;
		if (initted)
			return;
		
		// Set up runtime symbols needed for linking and compiling snow sources.
		SymbolTable& table = runtime_symbols();
		table["snow_eval_truth"] = (void*)snow::eval_truth;
		table["snow_call"] = (void*)snow::call;
		table["snow_get"] = (void*)snow::get;
		table["snow_set"] = (void*)snow::set;
		table["snow_enter_scope"] = (void*)snow::enter_scope;
		table["snow_leave_scope"] = (void*)snow::leave_scope;
		table["snow_set_parent_scope"] = (void*)snow::set_parent_scope;
		table["snow_get_local"] = (void*)snow::get_local;
		
		// Bind basic standard library stuff in global scope.
		Global::define_globals(global_scope());
		
		initted = true;
	}
	
	VALUE Kernel::require(const std::string& file) {
		std::ifstream f(file.c_str());
		RefPtr<ast::FunctionDefinition> scope = Driver::parse(f, file);
		f.close();
		
		if (!scope) {
			error("An unknown error occured while parsing `%s'", file.c_str());
			TRAP();
		}
		
		RefPtr<Codegen> codegen = Codegen::create(*scope);
		RefPtr<CompiledCode> cc = codegen->compile();
		
		cc->link(runtime_symbols());
		
		#ifdef DEBUG
		std::ofstream disasmfile(std::string(file + ".s").c_str());
		disasmfile << x86_64::Disassembler::disassemble(*cc, runtime_symbols());
		disasmfile.close();
		#endif
		
		// TODO: Delay make_executable?
		cc->make_executable();
		
		Handle<Function> func = new Function(*cc);
		
		// TODO: We can't call with global scope because of the way locals work... Yet!
		//return func->call_in_scope(&global_scope());
		func->set_parent_scope(&global_scope());
		return func->call(nil(), 0);
	}
	
	SymbolTable& Kernel::runtime_symbols() {
		static SymbolTable s;
		return s;
	}
	
	Scope& Kernel::global_scope() {
		static Scope s;
		return s;
	}
{'fraction_non_alphanumeric': 0.16434468524251805, 'fraction_numerical': 0.0025799793601651187, 'mean_word_length': 4.7098674521354935, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 25, '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': '2828592', 'n_tokens_mistral': 1520, 'n_tokens_neox': 1350, 'n_words': 291}