Skip to content

Commit

Permalink
Update to Concert 9.3
Browse files Browse the repository at this point in the history
* Update to Concert 9.3.
* Add hardware_concurrency function in thread standard library.
* Fix memory leaks with file handles after closing.
* Add sleep function in thread standard library.
  • Loading branch information
puckowski committed Jul 13, 2024
1 parent fa55eed commit e66b7bd
Show file tree
Hide file tree
Showing 25 changed files with 119 additions and 50 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Concert/.vs/Lang3/v17/.suo
Binary file not shown.
Binary file modified Concert/.vs/Lang3/v17/Browse.VC.db
Binary file not shown.
25 changes: 24 additions & 1 deletion Concert/Lang3/HandleStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ void ConcertHandleEnvironment::HandleStore::openFile(const std::wstring& name, i
{
it->second->close();
mHandleMap.erase(it->first);
delete it->second;
}

mHandleMap.insert({ name, fileStream });
Expand Down Expand Up @@ -146,6 +147,7 @@ void ConcertHandleEnvironment::HandleStore::openByteFile(const std::wstring& nam
{
it->second->close();
mByteHandleMap.erase(it->first);
delete it->second;
}

mByteHandleMap.insert({ name, fileStream });
Expand All @@ -165,6 +167,7 @@ void ConcertHandleEnvironment::HandleStore::closeFile(const std::wstring &name)

byteFileStream->close();
mByteHandleMap.erase(name);
delete byteFileStream;
}
}
else
Expand All @@ -173,6 +176,7 @@ void ConcertHandleEnvironment::HandleStore::closeFile(const std::wstring &name)

fileStream->close();
mHandleMap.erase(name);
delete fileStream;
}
}

Expand Down Expand Up @@ -264,7 +268,26 @@ bool ConcertHandleEnvironment::HandleStore::isAtEndOfFile(const std::wstring &na
int ConcertHandleEnvironment::HandleStore::removeFile(const std::wstring &name)
{
int result = std::remove(wstring_to_utf8(name).c_str());
mHandleMap.erase(name);

auto handle = getHandle(name);

if (handle != nullptr)
{
handle->close();
mHandleMap.erase(name);
delete handle;
}
else
{
auto byteHandle = getByteHandle(name);

if (byteHandle != nullptr)
{
byteHandle->close();
mByteHandleMap.erase(name);
delete byteHandle;
}
}

return result;
}
Expand Down
Binary file modified Concert/Lang3/Release/HandleStore.obj
Binary file not shown.
Binary file modified Concert/Lang3/Release/Lang3.iobj
Binary file not shown.
Binary file modified Concert/Lang3/Release/Lang3.ipdb
Binary file not shown.
13 changes: 7 additions & 6 deletions Concert/Lang3/Release/Lang3.log
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
 main.cpp
C:\Users\fooba\Downloads\Concert Programming Language (0.0.8.4.1)\Lang3 - Copy\Lang3 - Copy\Lang3\sourceFunctions.h(894,70): warning C4459: declaration of 'codeStore' hides global declaration
C:\Users\fooba\Downloads\Concert Programming Language (0.0.8.4.1)\Lang3 - Copy\Lang3 - Copy\Lang3\sourceFunctions.h(859,70): warning C4459: declaration of 'codeStore' hides global declaration
C:\Users\fooba\Downloads\Concert Programming Language (0.0.8.4.1)\Lang3 - Copy\Lang3 - Copy\Lang3\header.h(33,32): message : see declaration of 'codeStore'
C:\Users\fooba\Downloads\Concert Programming Language (0.0.8.4.1)\Lang3 - Copy\Lang3 - Copy\Lang3\sourceFunctions.h(894,70): warning C4100: 'codeStore': unreferenced formal parameter
C:\Users\fooba\Downloads\Concert Programming Language (0.0.8.4.1)\Lang3 - Copy\Lang3 - Copy\Lang3\sourceFunctions.h(913,42): warning C4459: declaration of 'currentLine' hides global declaration
C:\Users\fooba\Downloads\Concert Programming Language (0.0.8.4.1)\Lang3 - Copy\Lang3 - Copy\Lang3\sourceFunctions.h(859,70): warning C4100: 'codeStore': unreferenced formal parameter
C:\Users\fooba\Downloads\Concert Programming Language (0.0.8.4.1)\Lang3 - Copy\Lang3 - Copy\Lang3\sourceFunctions.h(878,42): warning C4459: declaration of 'currentLine' hides global declaration
C:\Users\fooba\Downloads\Concert Programming Language (0.0.8.4.1)\Lang3 - Copy\Lang3 - Copy\Lang3\header.h(44,25): message : see declaration of 'currentLine'
C:\Users\fooba\Downloads\Concert Programming Language (0.0.8.4.1)\Lang3 - Copy\Lang3 - Copy\Lang3\sourceFunctions.h(913,96): warning C4459: declaration of 'codeStore' hides global declaration
C:\Users\fooba\Downloads\Concert Programming Language (0.0.8.4.1)\Lang3 - Copy\Lang3 - Copy\Lang3\sourceFunctions.h(878,96): warning C4459: declaration of 'codeStore' hides global declaration
C:\Users\fooba\Downloads\Concert Programming Language (0.0.8.4.1)\Lang3 - Copy\Lang3 - Copy\Lang3\header.h(33,32): message : see declaration of 'codeStore'
C:\Users\fooba\Downloads\Concert Programming Language (0.0.8.4.1)\Lang3 - Copy\Lang3 - Copy\Lang3\operatorFunctions.h(172,29): warning C4018: '<': signed/unsigned mismatch
C:\Users\fooba\Downloads\Concert Programming Language (0.0.8.4.1)\Lang3 - Copy\Lang3 - Copy\Lang3\operatorFunctions.h(289,35): warning C4100: 'tokensSize': unreferenced formal parameter
Expand Down Expand Up @@ -115,8 +115,9 @@ C:\Users\fooba\Downloads\Concert Programming Language (0.0.8.4.1)\Lang3 - Copy\L
C:\Users\fooba\Downloads\Concert Programming Language (0.0.8.4.1)\Lang3 - Copy\Lang3 - Copy\Lang3\regexLibrary.h(65,7): warning C4459: declaration of 'returnVar' hides global declaration
C:\Users\fooba\Downloads\Concert Programming Language (0.0.8.4.1)\Lang3 - Copy\Lang3 - Copy\Lang3\header.h(36,26): message : see declaration of 'returnVar'
C:\Users\fooba\Downloads\Concert Programming Language (0.0.8.4.1)\Lang3 - Copy\Lang3 - Copy\Lang3\regexLibrary.h(86,74): warning C4100: 'argumentsSize': unreferenced formal parameter
C:\Users\fooba\Downloads\Concert Programming Language (0.0.8.4.1)\Lang3 - Copy\Lang3 - Copy\Lang3\threadLibrary.h(14,7): warning C4459: declaration of 'returnVar' hides global declaration
C:\Users\fooba\Downloads\Concert Programming Language (0.0.8.4.1)\Lang3 - Copy\Lang3 - Copy\Lang3\threadLibrary.h(15,7): warning C4459: declaration of 'returnVar' hides global declaration
C:\Users\fooba\Downloads\Concert Programming Language (0.0.8.4.1)\Lang3 - Copy\Lang3 - Copy\Lang3\header.h(36,26): message : see declaration of 'returnVar'
C:\Users\fooba\Downloads\Concert Programming Language (0.0.8.4.1)\Lang3 - Copy\Lang3 - Copy\Lang3\threadLibrary.h(34,74): warning C4100: 'argumentsSize': unreferenced formal parameter
C:\Users\fooba\Downloads\Concert Programming Language (0.0.8.4.1)\Lang3 - Copy\Lang3 - Copy\Lang3\keywordBreak.h(10,31): warning C4459: declaration of 'currentLine' hides global declaration
C:\Users\fooba\Downloads\Concert Programming Language (0.0.8.4.1)\Lang3 - Copy\Lang3 - Copy\Lang3\header.h(44,25): message : see declaration of 'currentLine'
C:\Users\fooba\Downloads\Concert Programming Language (0.0.8.4.1)\Lang3 - Copy\Lang3 - Copy\Lang3\keywordTry.h(14,29): warning C4459: declaration of 'currentLine' hides global declaration
Expand Down Expand Up @@ -162,7 +163,7 @@ C:\Users\fooba\Downloads\Concert Programming Language (0.0.8.4.1)\Lang3 - Copy\L
_Fn=int (__cdecl *)(int)
]
Generating code
97 of 4419 functions ( 2.2%) were compiled, the rest were copied from previous compilation.
97 of 4458 functions ( 2.2%) were compiled, the rest were copied from previous compilation.
0 functions were new in current compilation
9 functions had inline decision re-evaluated but remain unchanged
Finished generating code
Expand Down
Binary file modified Concert/Lang3/Release/Lang3.tlog/CL.command.1.tlog
Binary file not shown.
Binary file modified Concert/Lang3/Release/Lang3.tlog/CL.read.1.tlog
Binary file not shown.
Binary file modified Concert/Lang3/Release/Lang3.tlog/CL.write.1.tlog
Binary file not shown.
Binary file modified Concert/Lang3/Release/main.obj
Binary file not shown.
Binary file modified Concert/Lang3/Release/vc143.pdb
Binary file not shown.
4 changes: 2 additions & 2 deletions Concert/Lang3/header.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class WorkspaceStore;
class ObjectStore;

const std::wstring SOFTWARE_NAME = L"Concert";
const std::wstring SOFTWARE_VERSION_STRING = L"0.0.9.2";
const std::wstring SOFTWARE_VERSION_CODE = L"1405";
const std::wstring SOFTWARE_VERSION_STRING = L"0.0.9.3";
const std::wstring SOFTWARE_VERSION_CODE = L"1410";
const std::wstring SOFTWARE_AUTHOR = L"Daniel Puckowski";

extern std::unordered_map<std::wstring, std::wstring> varLockMap;
Expand Down
12 changes: 12 additions & 0 deletions Concert/Lang3/keywordCall.h
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,18 @@ void executeKeywordCall(const int &tokensSize, std::vector<std::wstring> &tokens

break;
}
case THREAD_HARDWARE_CONCURRENCY:
{
libraryThreadHardwareConcurrency(tokens, tokensSize);

break;
}
case THREAD_SLEEP:
{
libraryThreadSleep(tokens, tokensSize);

break;
}
}
}

Expand Down
35 changes: 0 additions & 35 deletions Concert/Lang3/sourceFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -856,41 +856,6 @@ void readStatementsFromFile(const std::wstring& filename)
addExitTokenVectorIfNeeded();
}

bool readStatementsFromConsole()
{
std::vector<std::wstring> lines;
std::wstring line;
/*
do
{
std::cout << "> ";
std::getline(std::cin, line);
if (line.empty() == true)
{
break;
}
else if (line == L"exit")
{
return false;
}
else
{
lines.push_back(line);
}
} while (true);
for (std::vector<std::wstring>::iterator it = lines.begin(); it != lines.end(); ++it)
{
line = *it;
std::vector<std::wstring> tokens;
tokenizeStatement3(line, tokens);
}*/

return true;
}

void readStatementsFromFile(const std::wstring &filename, CodeStore* codeStore)
{
std::ifstream file(filename);
Expand Down
10 changes: 7 additions & 3 deletions Concert/Lang3/standardLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ enum LibraryFunction
MATH_TAN = 60,
MATH_GET_PI = 61,
MATH_SET_PRECISION = 62,
MATH_EXP = 63
MATH_EXP = 63,
THREAD_HARDWARE_CONCURRENCY = 64,
THREAD_SLEEP = 65
};

std::vector<std::wstring>* stringLibraryFunctions = new std::vector<std::wstring>{ L"substring" , L"find", L"contains", L"length", L"to_int", L"to_double", L"char_at", L"wchar_at", L"char_to_string", L"wchar_to_string",
Expand All @@ -76,7 +78,7 @@ std::vector<std::wstring>* fileLibraryFunctions = new std::vector<std::wstring>{
std::vector<std::wstring>* mathLibraryFunctions = new std::vector<std::wstring>{ L"seed_random", L"get_random", L"int_to_double", L"double_to_int", L"int_to_long", L"long_to_int",
L"long_to_double", L"double_to_long", L"absolute_value", L"sqrt", L"log10", L"round", L"floor", L"ceil", L"sin", L"cos", L"tan", L"get_pi", L"set_precision", L"exp" };
std::vector<std::wstring>* regexLibraryFunctions = new std::vector<std::wstring>{ L"regex_search", L"regex_match", L"regex_replace" };
std::vector<std::wstring>* threadLibraryFunctions = new std::vector<std::wstring>{ L"get_thread_id" };
std::vector<std::wstring>* threadLibraryFunctions = new std::vector<std::wstring>{ L"get_thread_id", L"hardware_concurrency", L"sleep" };

thread_local const std::map<const std::wstring, std::vector<std::wstring>*> LIBRARY_IMPORT_MAP =
{
Expand Down Expand Up @@ -146,7 +148,9 @@ const std::map<const std::wstring, const LibraryFunction> LIBRARY_FUNCTION_MAP =
{ L"tan", MATH_TAN },
{ L"get_pi", MATH_GET_PI },
{ L"set_precision", MATH_SET_PRECISION },
{ L"exp", MATH_EXP }
{ L"exp", MATH_EXP },
{ L"hardware_concurrency", THREAD_HARDWARE_CONCURRENCY },
{ L"sleep", THREAD_SLEEP }
};
const std::_Tree_const_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const std::wstring, const LibraryFunction>>>> LIBRARY_FUNCTION_MAP_END = LIBRARY_FUNCTION_MAP.end();

Expand Down
7 changes: 7 additions & 0 deletions Concert/Lang3/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -516,3 +516,10 @@ println pi_val;
double toexp = 1.6;
call exp : toexp -> toexp;
println toexp;

println "Sleeping...";
call sleep : 555;

int hwc = 0;
call hardware_concurrency -> hwc;
println "Hardware thread count check: ", hwc;
40 changes: 40 additions & 0 deletions Concert/Lang3/threadLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <vector>
#include <string>
#include <chrono>

#include "header.h"
#include "Var.h"
Expand All @@ -21,4 +22,43 @@ void libraryThreadGetId(std::vector<std::wstring>& arguments, const int& argumen
returnData[returnVarInt] = idstr;
}

void libraryThreadHardwareConcurrency(std::vector<std::wstring>& arguments, const int& argumentsSize)
{
Var* v = getVar(arguments[argumentsSize - 1], returnVarInt, createdRetVar);

int* returnData = static_cast<int*>(v->data);

returnData[returnVarInt] = std::thread::hardware_concurrency();
}

void libraryThreadSleep(std::vector<std::wstring>& arguments, const int& argumentsSize)
{
int r1;
bool createdInt;
Var* intVar = getVar(arguments[2], r1, createdInt);

switch (intVar->type)
{
case TYPE_INT:
{
int* pstr = static_cast<int*>(intVar->data);

std::this_thread::sleep_for(std::chrono::milliseconds(pstr[r1]));

break;
}
case TYPE_LONG:
{
long long int* pstr = static_cast<long long int*>(intVar->data);

std::this_thread::sleep_for(std::chrono::milliseconds(pstr[r1]));

break;
}
}

if (createdInt)
delete intVar;
}

#endif
Binary file modified Concert/Release/Lang3.exe
Binary file not shown.
Binary file modified Concert/Release/Lang3.pdb
Binary file not shown.
23 changes: 20 additions & 3 deletions standard_library/thread_library.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ import thread;

## Functions

| Name | Description |
|:---------------|:---------------------------------------------------|
| get_thread_id | Get the current thread's ID. |
| Name | Description |
|:---------------------|:-------------------------------------------------------|
| get_thread_id | Get the current thread's ID. |
| hardware_concurrency | Try to get system hardware thread count. May report 0. |
| sleep | Sleep for argument milliseconds. |

## Examples

Expand All @@ -29,3 +31,18 @@ string data;

call get_thread_id -> data;
```

### hardware_concurrency

```cpp
int threadCount = 0;
call hardware_concurrency -> threadCount;
```

### sleep

```cpp
int millis = 500;
println "Sleeping for ", millis, " millis";
call sleep : millis;
```

0 comments on commit e66b7bd

Please sign in to comment.