Skip to content

Commit

Permalink
fix: build failure
Browse files Browse the repository at this point in the history
  • Loading branch information
nullptr0x committed Jun 14, 2023
1 parent 7794d48 commit 013faa3
Show file tree
Hide file tree
Showing 4 changed files with 350 additions and 249 deletions.
4 changes: 2 additions & 2 deletions Swirl/include/pre-processor/pre-processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#include <string>
#include <sstream>

#include <tokenizer/Tokenizer.h>
//#include <tokenizer/Tokenizer.h>

#ifndef PRE_PROCESSOR_H_SWIRL
#define PRE_PROCESSOR_H_SWIRL
void preProcess(const std::string&, TokenStream&, std::string);
//void preProcess(const std::string&, TokenStream&, std::string);
#endif
50 changes: 25 additions & 25 deletions Swirl/src/pre-processor/pre-processor.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
#include <iostream>
#include <fstream>
#include <vector>
#include <filesystem>
#include <string>
#include <sstream>

#include <tokenizer/Tokenizer.h>

#ifndef _WIN32
#define TORNADO_PKGS_PATH "/.tornado/packages/"
#endif

void preProcess(const std::string& _source, TokenStream& _stream, std::string _buildPath) {
std::stringstream source_strm(_source);
std::vector<std::string> cimports{};

std::string cr_dir = "cd " + _buildPath.erase(_buildPath.size() - 16, _buildPath.size())
+ "&& mkdir __swirl_cache__";

if (!std::filesystem::exists(_buildPath + "__swirl_cache__"))
system(cr_dir.c_str());

std::ofstream cache_file(_buildPath + "__swirl_cache__" + PATH_SEP + "__main__.sw");
}
//#include <iostream>
//#include <fstream>
//#include <vector>
//#include <filesystem>
//#include <string>
//#include <sstream>
//
//#include <tokenizer/Tokenizer.h>
//
//#ifndef _WIN32
//#define TORNADO_PKGS_PATH "/.tornado/packages/"
//#endif
//
//void preProcess(const std::string& _source, TokenStream& _stream, std::string _buildPath) {
// std::stringstream source_strm(_source);
// std::vector<std::string> cimports{};
//
// std::string cr_dir = "cd " + _buildPath.erase(_buildPath.size() - 16, _buildPath.size())
// + "&& mkdir __swirl_cache__";
//
// if (!std::filesystem::exists(_buildPath + "__swirl_cache__"))
// system(cr_dir.c_str());
//
// std::ofstream cache_file(_buildPath + "__swirl_cache__" + PATH_SEP + "__main__.sw");
//}
106 changes: 95 additions & 11 deletions Swirl/src/swirl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <tokenizer/Tokenizer.h>
#include <transpiler/transpiler.h>
#include <parser/parser.h>
#include <include/SwirlConfig.h>
#include <SwirlConfig.h.in>

bool SW_DEBUG = false;
std::string SW_FED_FILE_PATH;
Expand Down Expand Up @@ -42,6 +42,90 @@ std::unordered_map<std::string, const char*> type_registry = {
{"function","global"}
};

std::unordered_map<std::string, uint8_t> non_assign_binary_ops = {
{"+", 0},
{"-", 1},
{"*", 2},
{"/", 3},
{"%", 4},
{"==", 5},
{"!=", 6},
{">", 7},
{"<", 8},
{">=", 9},
{"<=", 10},
{"&&", 11},
{"||", 12},
{"&", 13},
{"|", 14},
{"^", 15},
{"<<", 16},
{">>", 17},
};

std::unordered_map<std::string, uint8_t> keywords = {
{"func", 0},
{"return", 1},
{"if", 2},
{"else", 3},
{"for", 4},
{"while", 5},
{"is", 6},
{"in", 7},
{"or", 8},
{"and", 9},
{"class", 10},
{"public", 11},
{"private", 12},
{"const", 15},
{"static", 16},
{"break", 17},
{"continue", 18},
{"elif", 19},
{"global", 20},
{"importc", 21},
{"typedef", 22},
{"import", 23},
{"export", 24},
{"from", 25},
{"var", 26}
};

std::unordered_map<std::string, uint8_t> operators = {
{"+", 0},
{"-", 1},
{"*", 2},
{"/", 3},
{"%", 4},
{"==", 5},
{"!=", 6},
{">", 7},
{"<", 8},
{">=", 9},
{"<=", 10},
{"&&", 11},
{"||", 12},
{"&", 13},
{"|", 14},
{"^", 15},
{"<<", 16},
{">>", 17},
{"=", 18},
{"+=", 19},
{"-=", 20},
{"*=", 21},
{"/=", 22},
{"%=", 23},
{"===", 24},
{"!==", 25},
{"&=", 26},
{"|=", 27},
{"^=", 28},
{"<<=", 29},
{">>=", 30},
{"++", 31},
{"--", 32},
};

std::optional<std::unordered_map<std::string, std::string>> compile(
std::string& _source,
Expand All @@ -50,15 +134,15 @@ std::optional<std::unordered_map<std::string, std::string>> compile(

InputStream chrinp_stream(_source);
TokenStream tk(chrinp_stream);
preProcess(_source, tk, _cacheDir);
// preProcess(_source, tk, _cacheDir);
Parser parser(tk);
return Transpile(
parser.m_AST->chl,
_cacheDir,
compiled_source,
true,
symt
);
// return Transpile(
// {},
// _cacheDir,
// compiled_source,
// true,
// symt
// );
}

int main(int argc, const char** const argv) {
Expand Down Expand Up @@ -123,11 +207,11 @@ int main(int argc, const char** const argv) {
if ( !SW_FED_FILE_SOURCE.empty() ) {
InputStream is(SW_FED_FILE_SOURCE);
TokenStream tk(is, _debug);
preProcess(SW_FED_FILE_SOURCE, tk, cache_dir);
// preProcess(SW_FED_FILE_SOURCE, tk, cache_dir);

Parser parser(tk);
parser.dispatch();
Transpile(parser.m_AST->chl, cache_dir + SW_OUTPUT + ".cpp", compiled_source);
// Transpile(parser.m_AST->chl, cache_dir + SW_OUTPUT + ".cpp", compiled_source);
}

if (app.contains_flag("-r")) {
Expand Down
Loading

0 comments on commit 013faa3

Please sign in to comment.