Skip to content

Commit

Permalink
remaining bscript, started plib
Browse files Browse the repository at this point in the history
  • Loading branch information
turleypol committed Jan 3, 2024
1 parent e99d526 commit 591f873
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 30 deletions.
14 changes: 2 additions & 12 deletions pol-core/bscript/compiler/file/SourceFileCache.cpp
@@ -1,10 +1,10 @@
#include "SourceFileCache.h"

#include "clib/logfacility.h"
#include "clib/timer.h"
#include "bscript/compiler/Profile.h"
#include "bscript/compiler/file/SourceFile.h"
#include "bscript/compiler/file/SourceFileIdentifier.h"
#include "clib/logfacility.h"
#include "clib/timer.h"

namespace Pol::Bscript::Compiler
{
Expand All @@ -26,15 +26,13 @@ std::shared_ptr<SourceFile> SourceFileCache::load( const SourceFileIdentifier& i
auto itr = files.find( pathname );
if ( itr != files.end() )
{
// INFO_PRINT << "Cache hit: " << pathname << "\n";
profile.cache_hits++;

// We do not propagate errors here. This happens when the compilation unit
// or module is obtained, so that the errors occur at the same "time"
// whether the file was just loaded, or was cached.
return ( *itr ).second;
}
// INFO_PRINT << "Cache miss: " << pathname << "\n";
profile.cache_misses++;
}

Expand Down Expand Up @@ -83,18 +81,10 @@ void SourceFileCache::keep_some()
for ( auto itr = pathname_frequencies.begin(), end = itr + remove; itr != end; ++itr )
{
const std::string& pathname = *( ( *itr ).second );
// INFO_PRINT << "Remove from cache: " << *( *itr ).second
// << "(" << ( *itr ).first << ")\n";
( *itr ).second = nullptr;
files.erase( pathname );
}
profile.prune_cache_delete_micros += delete_timer.ellapsed().count();

// INFO_PRINT << "Cache kept:\n";
// for( auto& kv : files )
// {
// INFO_PRINT << " - " << kv.first << " (" << frequency[kv.first] << ")\n";
// }
}

} // namespace Pol::Bscript::Compiler
6 changes: 2 additions & 4 deletions pol-core/bscript/expression.cpp
Expand Up @@ -705,13 +705,11 @@ void Expression::remove_non_emitting_tokens()

void Expression::dump_tokens() const
{
INFO_PRINT << "Expression with " << tokens.size() << " tokens:\n";
INFO_PRINT2( "Expression with {} tokens:", tokens.size() );
for ( unsigned i = 0; i < tokens.size(); ++i )
{
Token* tk = tokens[i];
INFO_PRINT << fmt::pad( i, 4, ' ' )
<< " (" << fmt::pad( get_num_tokens( i ), 2, ' ' ) << ")"
<< ": " << *tk << "\n";
INFO_PRINT2( "{:>4} ({:>2}): {}", i, get_num_tokens( i ), *tk );
}
}

Expand Down
7 changes: 4 additions & 3 deletions pol-core/plib/RawMap.cpp
Expand Up @@ -104,7 +104,8 @@ unsigned int RawMap::load_full_map( FILE* mapfile, FILE* mapdif_file )
// TODO: cleanup the code
unsigned int RawMap::load_full_map( int uo_mapid, std::istream& ifs )
{
auto maphash = []( int mapid, size_t chunkidx ) {
auto maphash = []( int mapid, size_t chunkidx )
{
char mapstring[1024];
snprintf( mapstring, sizeof mapstring, "build/map%dlegacymul/%08i.dat", mapid, (int)chunkidx );
return HashLittle2( mapstring );
Expand Down Expand Up @@ -145,8 +146,8 @@ unsigned int RawMap::load_full_map( int uo_mapid, std::istream& ifs )
} while ( currentblock != nullptr && filemap.size() < uopfile.header()->nfiles() );

if ( uopfile.header()->nfiles() != filemap.size() )
INFO_PRINT << "Warning: not all chunks read (" << filemap.size() << "/"
<< uopfile.header()->nfiles() << ")\n";
INFO_PRINT2( "Warning: not all chunks read ({}/{})", filemap.size(),
uopfile.header()->nfiles() );

// Sanity checking and pre-allocate mapinfo vector
passert_r(
Expand Down
20 changes: 9 additions & 11 deletions pol-core/plib/fsa.h
Expand Up @@ -89,7 +89,7 @@ class FixedSizeAllocator
~FixedSizeAllocator()
{
// Free up the memory
delete[]( char* ) m_pMemory;
delete[] (char*)m_pMemory;
}

// Allocate a new USER_TYPE and return a pointer to it
Expand Down Expand Up @@ -178,28 +178,26 @@ class FixedSizeAllocator
// For debugging this displays both lists (using the prev/next list pointers)
void Debug()
{
INFO_PRINT << "free list";
INFO_PRINT2( "free list" );
FSA_ELEMENT* p = m_pFirstFree;
fmt::Writer _tmp;
std::string tmp;
while ( p )
{
_tmp << fmt::hex( p->pPrev ) << "!" << fmt::hex( p->pNext ) << " ";
tmp += fmt::format( "{:#x}!{:#x} ", p->pPrev, p->pNext );
p = p->pNext;
}
_tmp << "\n";
INFO_PRINT << _tmp.str();
INFO_PRINT2( tmp );

INFO_PRINT << "used list\n";
_tmp.Clear();
INFO_PRINT2( "used list" );
tmp.clear();

p = m_pFirstUsed;
while ( p )
{
_tmp << fmt::hex( p->pPrev ) << "!" << fmt::hex( p->pNext ) << " ";
tmp += fmt::format( "{:#x}!{:#x} ", p->pPrev, p->pNext );
p = p->pNext;
}
_tmp << "\n";
INFO_PRINT << _tmp.str();
INFO_PRINT2( tmp );
}

// Iterators
Expand Down

0 comments on commit 591f873

Please sign in to comment.