Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
treefrogframework committed Apr 14, 2024
1 parent 066d774 commit 6829322
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
7 changes: 3 additions & 4 deletions build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

set PATH=C:\Qt\6.7.0\msvc2019_64\bin;%PATH%
set CWD=%~dp0

set VCVARSBAT=""
set VSVER=2022 2019 2017
set VSWHERE="%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"

where cl.exe >NUL 2>&1
if ERRORLEVEL 1 (
if exist %VSWHERE% (
for %%v in (%VSVER%) do (
for %%v in (%VSVER%) do (
for /f "usebackq tokens=*" %%i in (`%VSWHERE% -find **\vcvarsall.bat`) do (
echo %%i | find "%%v" >NUL
if not ERRORLEVEL 1 (
Expand All @@ -24,8 +23,8 @@ if ERRORLEVEL 1 (

:break
if exist %VCVARSBAT% (
echo Setting up environment for MSVC %VSVER% usage...
call %VCVARSBAT% amd64
echo Setting up environment for MSVC %VSVER% usage
call %VCVARSBAT% amd64 >NUL 2>&1
)
)

Expand Down
9 changes: 5 additions & 4 deletions cpi.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ set VCVARSBAT=""
set VSVER=2022 2019 2017
set VSWHERE="%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"

where cl.exe >NUL
where cl.exe >NUL 2>&1
if ERRORLEVEL 1 (
if exist %VSWHERE% (
for %%v in (%VSVER%) do (
for %%v in (%VSVER%) do (
for /f "usebackq tokens=*" %%i in (`%VSWHERE% -find **\vcvarsall.bat`) do (
echo %%i | find "%%v" >NUL
if not ERRORLEVEL 1 (
set VCVARSBAT="%%i"
set VSVER=%%v
goto :break
)
)
Expand All @@ -21,8 +22,8 @@ if ERRORLEVEL 1 (

:break
if exist %VCVARSBAT% (
echo Setting up environment for MSVC usage...
call %VCVARSBAT% amd64
echo Setting up environment for MSVC %VSVER% usage
call %VCVARSBAT% amd64 >NUL 2>&1
)
)

Expand Down
44 changes: 22 additions & 22 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,17 +225,15 @@ static bool waitForReadyStdInputRead(int msecs)
return false;
#else
bool ret = false;
auto ready = [&]() {
ret = true;
};

QSocketNotifier notifier(fileno(stdin), QSocketNotifier::Read);
QObject::connect(&notifier, &QSocketNotifier::activated, ready);
qApp->processEvents();
QObject::connect(&notifier, &QSocketNotifier::activated, [&](){ ret = true; });

while (timer.elapsed() < msecs && !ret) {
for (;;) {
qApp->processEvents(QEventLoop::AllEvents);
if (timer.elapsed() >= msecs || ret) {
break;
}
QThread::msleep(20);
qApp->processEvents();
}
return ret;
#endif
Expand Down Expand Up @@ -269,6 +267,19 @@ static void compile()
}
};


static QString readLine()
{
QString line;
std::string s;

if (std::getline(std::cin, s)) {
line = QString::fromStdString(s);
}
return line;
}


static int interpreter()
{
print() << "cpi " << CPI_VERSION_STR << endl;
Expand All @@ -291,23 +302,13 @@ static int interpreter()

bool end = false;
auto readCodeAndCompile = [&]() {
QString line;
std::string s;

if (std::getline(std::cin, s)) {
line = QString::fromStdString(s);
} else {
end = true;
return;
}
line = line.trimmed();
QString line = readLine();

if (line.isNull()) {
end = true;
return;
}

line = line.trimmed();
if (line == ".quit" || line == ".q") {
end = true;
return;
Expand Down Expand Up @@ -384,7 +385,7 @@ static int interpreter()
print() << "cpi> " << flush;

while (!end) {
bool ready = waitForReadyStdInputRead(40);
bool ready = waitForReadyStdInputRead(50);
if (ready) {
readCodeAndCompile();
}
Expand Down Expand Up @@ -444,8 +445,7 @@ int main(int argv, char *argc[])
QString src;
QTextStream tsstdin(stdin);
while (!tsstdin.atEnd()) {
src += tsstdin.readLine();
src += "\n";
src += tsstdin.readAll();
}

ret = compiler.compileAndExecute(src);
Expand Down

0 comments on commit 6829322

Please sign in to comment.