Skip to content

Commit

Permalink
Ensure non-breaking state clear
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kus committed Dec 5, 2019
1 parent 9d9f1a3 commit 844382e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/xfunc/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace xfift {
if (name == "main") {
has_main = true;
force_return(code);
code->print(std::cout, 15);
//code->print(std::cout, 15);
}

code->simplify_var_types();
Expand Down
23 changes: 17 additions & 6 deletions src/xfunc/preproc.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
#include <fstream>
#include <streambuf>
#include <iostream>
using namespace std;

#include "xfunc.hpp"

namespace xfift {

const std::vector<std::string> not_a_func = {
"asm", "if", "ifnot", "then", "else", "elseif", "elseifnot"
const std::vector<std::string> skip_list = {
"int", "cell", "slice", "builder", "cont", "tuple",
"return", "var", "repeat", "do", "while", "until", "if", "ifnot", "then", "else", "elseif", "elseifnot",
"extern", "asm", "impure", "inline", "inline_ref", "method_id", "operator", "infix", "infixl", "infixr",
"divmod", "moddiv", "muldivr", "muldiv", "muldivmod", "null?", "throw", "throw_if", "throw_unless",
"load_int", "load_uint", "preload_int", "preload_uint", "store_int", "store_uint", "load_bits",
"preload_bits", "int_at", "cell_at", "slice_at", "tuple_at", "at", "touch", "touch2", "dump",
"run_method0", "run_method1", "run_method2", "run_method3", "~divmod", "~moddiv", "~store_int",
"~store_uint", "~touch", "~touch2"
};

void resolve_includes(std::string& expr, const std::vector<std::string>& func_path) {
std::regex include_re("^#include\\s\"([^\"]+)\"");
std::regex include_re(R"(#include\s\"([^\"]+)\")");
std::smatch match;
std::stringstream ss;
bool resolved = false;
Expand Down Expand Up @@ -45,18 +54,20 @@ namespace xfift {
}

void parse_functions(const std::string& expr, std::vector<std::string>& func_names) {
std::regex func_name_re("^[^;]*\\s(~?[_\\w:#]+[?=]?) *\\([_,\\w\\s]*\\) *(?:[a-z]|\\{)");
std::regex func_name_re(R"(\s(~?[_\w:#]+[?=]?) *\([_,\w\s]*\) *(?:[a-z]|\{))");

for (std::sregex_iterator it = std::sregex_iterator(expr.begin(), expr.end(), func_name_re);
it != std::sregex_iterator();
++it)
{
{
std::smatch match = *it;
assert(match.size() == 2);
if (std::find(not_a_func.begin(), not_a_func.end(), match.str(1)) == not_a_func.end()) {
if (std::find(skip_list.begin(), skip_list.end(), match.str(1)) == skip_list.end()) {
func_names.push_back(match.str(1));
}
}

std::clog << "Found " << func_names.size() << " function declarations\n";
}

void force_main(std::string& expr, std::vector<std::string>& func_names) {
Expand Down
8 changes: 6 additions & 2 deletions src/xfunc/symguard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ namespace xfift {
for (int i = 0; i < sym::symbols.hprime; i++) {
clear_sym_def(sym::sym_def, i);
clear_sym_def(sym::global_sym_def, i);
auto symbol = sym::symbols[i];
if (symbol) {
symbol->str = "";
symbol->idx = 0;
}
}

sym::symbols = sym::SymTable<100003>{};

std::clog << "Global state is clear\n";
}

Expand Down

0 comments on commit 844382e

Please sign in to comment.