Skip to content

Commit

Permalink
Nift (aka nsm) v2.4.7 - see release notes
Browse files Browse the repository at this point in the history
  • Loading branch information
n-ham committed Mar 30, 2021
1 parent 76e7f40 commit a464a9f
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 108 deletions.
2 changes: 1 addition & 1 deletion Consts.h
Expand Up @@ -4,7 +4,7 @@
#include <cstdio>
#include <iostream>

const std::string NSM_VERSION = "2.4.6";
const std::string NSM_VERSION = "2.4.7";

const int HASH_RS = -2011;
const int HASH_JS = -2012;
Expand Down
115 changes: 76 additions & 39 deletions Parser.cpp
Expand Up @@ -508,25 +508,25 @@ int Parser::refresh_completions()
return 0;
}

int Parser::shell(std::string& lang, std::ostream& eos)
int Parser::shell(std::string& langStr, char& langCh, std::ostream& eos)
{
mode = MODE_SHELL;
return interactive(lang, eos);
return interactive(langStr, langCh, eos);
}

int Parser::interpreter(std::string& lang, std::ostream& eos)
int Parser::interpreter(std::string& langStr, char& langCh, std::ostream& eos)
{
mode = MODE_INTERP;
return interactive(lang, eos);
return interactive(langStr, langCh, eos);
}

int Parser::interactive(std::string& lang, std::ostream& eos)
int Parser::interactive(std::string& langStr, char& langCh, std::ostream& eos)
{
bool addPath;
vars.precision = 6;
vars.fixedPrecision = vars.scientificPrecision = 0;

if(lang.find_first_of("eEfFlLnN"))
/*if(langStr.find_first_of("eEfFlLnN"))
{
if(!consoleLocked)
os_mtx->lock();
Expand All @@ -536,7 +536,7 @@ int Parser::interactive(std::string& lang, std::ostream& eos)
start_err(eos) << "sh: unknown language " << c_light_blue << lang << c_white << std::endl;
os_mtx->unlock();
return 1;
}
}*/

depFiles.clear();
includedFiles.clear();
Expand All @@ -553,7 +553,7 @@ int Parser::interactive(std::string& lang, std::ostream& eos)
symbol_table.add_package(vectorops_package);

exprtk_nsm_lang<double> exprtk_nsm_lang_fn;
exprtk_nsm_lang_fn.setLangPtr(&lang);
exprtk_nsm_lang_fn.setLangPtr(&langStr);
symbol_table.add_function("nsm_lang", exprtk_nsm_lang_fn);
exprtk_nsm_mode<double> exprtk_nsm_mode_fn;
exprtk_nsm_mode_fn.setModePtr(&mode);
Expand All @@ -564,7 +564,7 @@ int Parser::interactive(std::string& lang, std::ostream& eos)
lua.init();
lua_addnsmfns();

lua_pushlightuserdata(lua.L, &lang);
lua_pushlightuserdata(lua.L, &langStr);
lua_setglobal(lua.L, "nsm_lang__");
lua_register(lua.L, "nsm_lang", lua_nsm_lang);
lua_register(lua.L, "nsm_mode", lua_nsm_mode);
Expand All @@ -591,7 +591,7 @@ int Parser::interactive(std::string& lang, std::ostream& eos)
int netBrackets = 0;
try
{
result = getline(lang, addPath, promptChar, lolcatActive, inLine, 1, tabCompletionStrs);
result = getline(langStr, addPath, promptChar, lolcatActive, inLine, 1, tabCompletionStrs);
}
catch(...)
{
Expand Down Expand Up @@ -628,7 +628,7 @@ int Parser::interactive(std::string& lang, std::ostream& eos)
toProcess += inLine + "\n";

inLine = "";
result = getline(lang, addPath, ">", lolcatActive, inLine, 1, tabCompletionStrs);
result = getline(langStr, addPath, ">", lolcatActive, inLine, 1, tabCompletionStrs);
for(size_t i=0; i<inLine.size(); ++i)
{
if(inLine[i] == '(' || inLine[i] == '{' || inLine[i] == '[' || inLine[i] == '<')
Expand All @@ -645,13 +645,13 @@ int Parser::interactive(std::string& lang, std::ostream& eos)

try
{
if(lang[0] == 'n')
if(langCh == 'n')
result = n_read_and_process_fast(1, 0, toProcess, 0, emptyPath, antiDepsOfReadPath, parsedText, eos);
else if(lang[0] == 'f')
else if(langCh == 'f')
result = f_read_and_process_fast(0, toProcess, 0, emptyPath, antiDepsOfReadPath, parsedText, eos);
else if(toProcess == "exit" || toProcess == "quit")
result = NSM_QUIT;
else if(lang[0] == 'e')
else if(langCh == 'x')
{
if(!expr.compile(toProcess))
{
Expand All @@ -666,7 +666,7 @@ int Parser::interactive(std::string& lang, std::ostream& eos)
else
result = expr.evaluate();
}
else if(lang[0] == 'l')
else if(langCh == 'l')
{
result = luaL_dostring(lua.L, toProcess.c_str());

Expand Down Expand Up @@ -699,13 +699,25 @@ int Parser::interactive(std::string& lang, std::ostream& eos)
else if(result == NSM_QUIT || result == NSM_EXIT)
break;
else if(result == LANG_NPP)
lang = "n++";
{
langStr = "n++";
langCh = 'n';
}
else if(result == LANG_FPP)
lang = "f++";
{
langStr = "f++";
langCh = 'f';
}
else if(result == LANG_LUA)
lang = "lua";
{
langStr = "lua";
langCh = 'l';
}
else if(result == LANG_EXPRTK)
lang = "exprtk";
{
langStr = "exprtk";
langCh = 'x';
}
else if(result == MODE_SHELL)
{
mode = MODE_SHELL;
Expand Down Expand Up @@ -773,15 +785,15 @@ int Parser::run(const Path& path, char lang, std::ostream& eos)
int pos = path.file.find_first_of('.');
std::string ext = path.file.substr(pos, path.file.size()-pos);

if(ext.find_first_of('f') != std::string::npos)
if(ext.find_first_of("fF") != std::string::npos)
lang = 'f';
else if(ext.find_first_of('n') != std::string::npos)
else if(ext.find_first_of("nNtT") != std::string::npos)
lang = 'n';
if(ext.find_first_of('l') != std::string::npos)
if(ext.find_first_of("lL") != std::string::npos)
lang = 'l';
else if(ext.find_first_of('x') != std::string::npos)
else if(ext.find_first_of("eExX") != std::string::npos)
lang = 'x';
else //if(ext.find_first_of('f') != std::string::npos)
else
lang = 'f';
/*else
{
Expand Down Expand Up @@ -875,7 +887,7 @@ int Parser::run(const Path& path, char lang, std::ostream& eos)
os_mtx->unlock();
}
}
else if(lang == 'x')
else if(lang == 'e')
{
std::string strippedScriptStr = scriptStr;
strip_surrounding_whitespace_multiline(strippedScriptStr);
Expand Down Expand Up @@ -1544,13 +1556,28 @@ int Parser::n_read_and_process_fast(const bool& indent,
}
else if(inStr[linePos] == '@') //checks for function calls
{
linePos++;
int ret_val = read_and_process_fn(indent, baseIndentAmount, 'n', addOutput, inStr, lineNo, linePos, readPath, antiDepsOfReadPath, outStr, eos);
try
{
linePos++;
int ret_val = read_and_process_fn(indent, baseIndentAmount, 'n', addOutput, inStr, lineNo, linePos, readPath, antiDepsOfReadPath, outStr, eos);

if(ret_val == NSM_CONT)
return 0;
else if(ret_val)
return ret_val;
//skips over 'end of statement' semicolons
while(linePos < inStr.size() && inStr[linePos] == ';')
++linePos;

if(ret_val == NSM_CONT)
return 0;
else if(ret_val)
return ret_val;
}
catch(...)
{
if(!consoleLocked)
os_mtx->lock();
start_err(eos, readPath, lineNo) << "caught an unknown error" << std::endl;
os_mtx->unlock();
return 1;
}
}
else if(inStr[linePos] == '$' && (inStr[linePos+1] == '{' || inStr[linePos+1] == '[' || inStr[linePos+1] == '`'))
{
Expand Down Expand Up @@ -1706,9 +1733,12 @@ int Parser::f_read_and_process_fast(const bool& addOutput,

continue;
}
else if(inStr[linePos] == '@') //ignores @ for function calls
else if(inStr[linePos] == '@')
{
outStr += "@";
/*if(linePos && (inStr[linePos] == ' ' ||
inStr[linePos] == '\t' ||
inStr[linePos] == '\n'))*/
//outStr += "@";
++linePos;
}
else if(inStr[linePos] == '<')
Expand Down Expand Up @@ -1745,7 +1775,7 @@ int Parser::f_read_and_process_fast(const bool& addOutput,
return 1;
}
}
/*else if(isdigit(inStr[linePos]))
/*]else if(isdigit(inStr[linePos]))
{
do
{
Expand All @@ -1765,6 +1795,10 @@ int Parser::f_read_and_process_fast(const bool& addOutput,
{
int ret_val = read_and_process_fn(0, "", 'f', addOutput, inStr, lineNo, linePos, readPath, antiDepsOfReadPath, outStr, eos);

//skips over 'end of statement' semicolons
while(linePos < inStr.size() && inStr[linePos] == ';')
++linePos;

if(ret_val == NSM_CONT)
return 0;
else if(ret_val)
Expand All @@ -1774,7 +1808,7 @@ int Parser::f_read_and_process_fast(const bool& addOutput,
{
if(!consoleLocked)
os_mtx->lock();
start_err(eos, readPath, lineNo) << "an unknown error occurred" << std::endl;
start_err(eos, readPath, lineNo) << "caught an unknown error" << std::endl;
os_mtx->unlock();
return 1;
}
Expand Down Expand Up @@ -14297,14 +14331,14 @@ int Parser::read_and_process_fn(const bool& indent,
}
else
{
std::string trash, toParse = "sys(" + funcName;
//std::string trash, toParse = "sys(" + funcName;

if(options.size())
/*if(options.size())
{
for(size_t o=0; o<options.size(); ++o)
#if defined _WIN32 || defined _WIN64
toParse += " /" + options[o];
#else //*nix
#else // *nix
toParse += " -" + options[o];
#endif
}
Expand All @@ -14322,7 +14356,10 @@ int Parser::read_and_process_fn(const bool& indent,
toParse += inStr[linePos];
}
}
toParse += ")";
toParse += ")";*/

std::string trash,
toParse = "sys{!p}(" + inStr.substr(sLinePos, (linePos = inStr.find_first_of("\n", sLinePos)) - sLinePos) + ")";

if(f_read_and_process(0, toParse, sLineNo-1, readPath, antiDepsOfReadPath, trash, eos))
{
Expand Down
6 changes: 3 additions & 3 deletions Parser.h
Expand Up @@ -104,9 +104,9 @@ struct Parser
const bool& outputWhatDoing);

int refresh_completions();
int shell(std::string& lang, std::ostream& eos);
int interpreter(std::string& lang, std::ostream& eos);
int interactive(std::string& lang, std::ostream& eos);
int shell(std::string& langStr, char& langCh, std::ostream& eos);
int interpreter(std::string& langStr, char& langCh, std::ostream& eos);
int interactive(std::string& langStr, char& langCh, std::ostream& eos);
int run(const Path& path, char lang, std::ostream& eos);
int build(const TrackedInfo& ToBuild,
std::atomic<double>& estNoPagesFinished,
Expand Down
5 changes: 5 additions & 0 deletions ProjectInfo.cpp
Expand Up @@ -548,6 +548,11 @@ Path ProjectInfo::execrc_path(const std::string& exec, const std::string& execrc
return Path(app_dir() + "/.nift/", exec + "rc." + execrc_ext);
}

Path ProjectInfo::execrc_path(const std::string& exec, const char& execrc_ext)
{
return Path(app_dir() + "/.nift/", exec + "rc." + execrc_ext);
}

int ProjectInfo::save_config(const std::string& configPathStr, const bool& global)
{
std::ofstream ofs(configPathStr);
Expand Down
1 change: 1 addition & 0 deletions ProjectInfo.h
Expand Up @@ -62,6 +62,7 @@ struct ProjectInfo
int open_tracking(const bool& addMsg);

Path execrc_path(const std::string& exec, const std::string& execrc_ext);
Path execrc_path(const std::string& exec, const char& execrc_ext);

int save_config(const std::string& configPathStr, const bool& global);
int save_global_config();
Expand Down
9 changes: 9 additions & 0 deletions ReleaseNotes.md
Expand Up @@ -2,6 +2,15 @@
Nift Release Notes
------------------

Version 2.4.7 of Nift
* Reverted to handling @fns with f++, too ingrained in the codebase
* Reverted to calling sys call on whole line for zero param functions
* Reverted to breaking at non-escaped @'s when reading function names
* Fixed up allowing for ';' at end of statements (hopefully no bugs/undesirable
features), though any potential system call will be called on whole line for
possibly multiple statements, use a new line if needed
* cleaned up (hopefully) language choce with interactive REPL's (both interp and sh) and run

Version 2.4.6 of Nift
* Initialised all bLineNo's to zero (started getting warnings on OSX)
* Fixed up "run commands" in-built scripts from last version to handle language names as well as chars for script extensions
Expand Down

0 comments on commit a464a9f

Please sign in to comment.