Skip to content

Commit

Permalink
Merge pull request #7 from gmoromisato/master
Browse files Browse the repository at this point in the history
1.2 RC 1
  • Loading branch information
gmoromisato committed Oct 21, 2013
2 parents e151832 + c8708e9 commit a99674f
Show file tree
Hide file tree
Showing 96 changed files with 4,084 additions and 914 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ Transcendence/Worklist.txt
Transcendence/Worklist (Completed).txt
Transcendence/Debug/*
Transcendence/Documents/*
Transcendence/Game/*.bat
Transcendence/Game/*.tdb
Transcendence/Game/*.txt
Transcendence/Game/Cache/*
Transcendence/Game/Collection/*
Transcendence/Game/compileBotA.bat
Transcendence/Game/DebugExtensions/*
Expand Down
13 changes: 13 additions & 0 deletions Alchemy/CodeChain/CCLambda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,21 @@ ICCItem *CCLambda::Execute (CEvalContext *pCtx, ICCItem *pArgs)
if (bNoEval || *(pVar->GetStringValue().GetASCIIZPointer()) == '%')
pResult = pArg->Reference();
else
{
pResult = pCC->Eval(pCtx, pArg);

// HACK: If we get back an error and it is "Function name expected"
// then we need to exit. We can't just exit with any error because
// we might want to pass an error into a function.

if (pResult->IsError()
&& strStartsWith(pResult->GetStringValue(), CONSTLIT("Function name expected")))
{
pLocalSymbols->Discard(pCC);
return pResult;
}
}

pItem = pLocalSymbols->AddEntry(pCC, pVar, pResult);
pResult->Discard(pCC);
}
Expand Down
73 changes: 49 additions & 24 deletions Alchemy/CodeChain/CCSymbolTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,6 @@ void CCSymbolTable::AddByOffset (CCodeChain *pCC, int iOffset, ICCItem *pEntry)
((ICCItem *)pOldEntry)->Discard(pCC);
}

void CCSymbolTable::DeleteEntry (CCodeChain *pCC, ICCItem *pKey)

// DeleteEntry
//
// Deletes the entry

{
CObject *pOldEntry;

if (m_Symbols.RemoveEntry(pKey->GetStringValue(), &pOldEntry) != NOERROR)
{
// We get an error is the key was not found. This is OK.
return;
}

// If we have a previous entry, decrement its refcount since we're
// throwing it away

ICCItem *pPrevEntry = (ICCItem *)pOldEntry;
pPrevEntry->Discard(pCC);

SetModified();
}

ICCItem *CCSymbolTable::AddEntry (CCodeChain *pCC, ICCItem *pKey, ICCItem *pEntry, bool bForceLocalAdd)

// AddEntry
Expand Down Expand Up @@ -179,6 +155,55 @@ ICCItem *CCSymbolTable::Clone (CCodeChain *pCC)
return pNewTable;
}

void CCSymbolTable::DeleteAll (CCodeChain *pCC, bool bLambdaOnly)

// DeleteAll
//
// Delete all entries

{
int i;

for (i = 0; i < m_Symbols.GetCount(); i++)
{
CObject *pEntry = m_Symbols.GetValue(i);
ICCItem *pItem = (ICCItem *)pEntry;
if (bLambdaOnly && pItem->IsPrimitive())
continue;

#ifdef DEBUG
::kernelDebugLogMessage(m_Symbols.GetKey(i).GetASCIIZPointer());
#endif
pItem->Discard(pCC);
m_Symbols.RemoveEntry(i);
i--;
}
}

void CCSymbolTable::DeleteEntry (CCodeChain *pCC, ICCItem *pKey)

// DeleteEntry
//
// Deletes the entry

{
CObject *pOldEntry;

if (m_Symbols.RemoveEntry(pKey->GetStringValue(), &pOldEntry) != NOERROR)
{
// We get an error is the key was not found. This is OK.
return;
}

// If we have a previous entry, decrement its refcount since we're
// throwing it away

ICCItem *pPrevEntry = (ICCItem *)pOldEntry;
pPrevEntry->Discard(pCC);

SetModified();
}

void CCSymbolTable::DestroyItem (CCodeChain *pCC)

// DestroyItem
Expand Down
12 changes: 11 additions & 1 deletion Alchemy/CodeChain/CodeChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,17 @@ ALERROR CCodeChain::DefineGlobalString (const CString &sVar, const CString &sVal
return error;
}

void CCodeChain::DiscardAllGlobals (void)

// DiscardAllGlobals
//
// Discard all globals.

{
if (m_pGlobalSymbols)
m_pGlobalSymbols->DeleteAll(this, true);
}

ICCItem *CCodeChain::Eval (CEvalContext *pEvalCtx, ICCItem *pItem)

// Eval
Expand Down Expand Up @@ -556,7 +567,6 @@ ICCItem *CCodeChain::Eval (CEvalContext *pEvalCtx, ICCItem *pItem)

else
return pItem->Reference();

}

ICCItem *CCodeChain::EvalLiteralStruct (CEvalContext *pCtx, ICCItem *pItem)
Expand Down
7 changes: 7 additions & 0 deletions Alchemy/CodeChain/Link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ ICCItem *CCodeChain::Link (const CString &sString, int iOffset, int *retiLinked,
&& *pPos != SYMBOL_OPENBRACE
&& *pPos != SYMBOL_CLOSEBRACE
&& *pPos != SYMBOL_COLON
&& *pPos != SYMBOL_QUOTE
&& *pPos != ';')
pPos++;

Expand All @@ -379,6 +380,12 @@ ICCItem *CCodeChain::Link (const CString &sString, int iOffset, int *retiLinked,
if (pStartString == pPos)
pResult = CreateParseError(iCurLine, strPatternSubst(CONSTLIT("Unexpected character: %s"), CString(pPos, 1)));

// If we ended in a quote then that's a bug

else if (*pPos == SYMBOL_QUOTE)
pResult = CreateParseError(iCurLine, strPatternSubst(CONSTLIT("Identifiers must not use single quote characters: %s"),
strSubString(sString, iOffset + (pStartString - pStart), (pPos + 1 - pStartString))));

// Otherwise, get the identifier

else
Expand Down
4 changes: 2 additions & 2 deletions Alchemy/Kernel/CDataFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ ALERROR CDataFile::Create (const CString &sFilename,

hFile = CreateFile(sFilename.GetASCIIZPointer(),
GENERIC_READ | GENERIC_WRITE,
0,
FILE_SHARE_READ,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
Expand Down Expand Up @@ -683,7 +683,7 @@ ALERROR CDataFile::Open (const CString &sFilename, DWORD dwFlags)
else
{
dwAccess = GENERIC_READ | GENERIC_WRITE;
dwShare = 0;
dwShare = FILE_SHARE_READ;
m_fReadOnly = false;
}

Expand Down
27 changes: 27 additions & 0 deletions Alchemy/Kernel/CDictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,33 @@ ALERROR CDictionary::RemoveEntry (int iKey, int *retiOldValue)
return NOERROR;
}

ALERROR CDictionary::RemoveEntryByOrdinal (int iEntry, int *retiOldValue)

// RemoveEntryByOrdinal
//
// Removes the given entry

{
ALERROR error;
int iOldValue;

// Get the old value

iOldValue = m_Array.GetElement(iEntry + 1);

// Remove the entry

if (error = m_Array.RemoveRange(iEntry, iEntry + 1))
return error;

// Done

if (retiOldValue)
*retiOldValue = iOldValue;

return NOERROR;
}

ALERROR CDictionary::ReplaceEntry (int iKey, int iValue, BOOL bAdd, BOOL *retbAdded, int *retiOldValue)

// ReplaceEntry
Expand Down
4 changes: 2 additions & 2 deletions Alchemy/Kernel/CFileWriteStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ ALERROR CFileWriteStream::Create (void)

m_hFile = CreateFile(m_sFilename.GetASCIIZPointer(),
GENERIC_WRITE,
0,
FILE_SHARE_READ,
NULL,
(m_bUnique ? CREATE_NEW : CREATE_ALWAYS),
FILE_ATTRIBUTE_NORMAL,
Expand All @@ -94,7 +94,7 @@ ALERROR CFileWriteStream::Open (void)

m_hFile = CreateFile(m_sFilename.GetASCIIZPointer(),
GENERIC_WRITE,
0,
FILE_SHARE_READ,
NULL,
OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
Expand Down
45 changes: 20 additions & 25 deletions Alchemy/Kernel/CHTTPClientSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

#include "Internets.h"

const int ONE_SECOND = 1000;
#define PROTOCOL_HTTP CONSTLIT("http")

const int ONE_SECOND = 1000;

CHTTPClientSession::CHTTPClientSession (void) :
m_iLastError(inetsOK),
Expand Down Expand Up @@ -285,7 +287,7 @@ bool CHTTPClientSession::ReadBuffer (void *pBuffer, DWORD dwLen, DWORD *retdwRea
return true;
}

EInetsErrors CHTTPClientSession::Send (const CHTTPMessage &Request, CHTTPMessage *retResponse)
EInetsErrors CHTTPClientSession::Send (const CHTTPMessage &Request, CHTTPMessage *retResponse, IHTTPClientSessionEvents *pEvents)

// Send
//
Expand Down Expand Up @@ -327,55 +329,48 @@ EInetsErrors CHTTPClientSession::Send (const CHTTPMessage &Request, CHTTPMessage
return m_iLastError;
}

// Now read the response. We build up a buffer to hold it.
// As we read the buffer we parse into the response

CMemoryWriteStream ResponseBuff;
int iResponseBuffSize = 0;
if (ResponseBuff.Create() != NOERROR)
if (retResponse->InitFromBufferReset() != NOERROR)
{
::kernelDebugLogMessage("Out of memory: Unable to create response buffer.");
m_iLastError = inetsOutOfMemory;
return m_iLastError;
}

// As we read the buffer we parse into the response

retResponse->InitFromBuffer(CString(ResponseBuff.GetPointer(), iResponseBuffSize, true));

// Keep reading until we've got enough (or until the connection drops)

int iTotalRead = 0;
while (!retResponse->IsMessageComplete())
{
// Grow the buffer so that we can read into it

int iReadSize = 4096;
if (ResponseBuff.Write(NULL, iReadSize - (ResponseBuff.GetLength() - iResponseBuffSize)) != NOERROR)
{
::kernelDebugLogMessage("Out of memory: Unable to write to response buffer.");
m_iLastError = inetsOutOfMemory;
return m_iLastError;
}
CString sBuffer;
const int iReadSize = 4096;
char *pBuffer = sBuffer.GetWritePointer(iReadSize);

// Read

DWORD dwBytesRead;
if (!ReadBuffer(ResponseBuff.GetPointer() + iResponseBuffSize, iReadSize, &dwBytesRead))
bool bOK = ReadBuffer(pBuffer, iReadSize, &dwBytesRead);
sBuffer.Truncate(dwBytesRead);
iTotalRead += dwBytesRead;
if (!bOK)
{
::kernelDebugLogMessage("Unable to read from server. Reponse:\r\n%s", CString(ResponseBuff.GetPointer(), iResponseBuffSize, true));
::kernelDebugLogMessage("Unable to read from server. Reponse:\r\n%s", sBuffer);
Disconnect();
m_iLastError = inetsUnableToRead;
if (m_iInternetStatus != internetChecking)
m_iInternetStatus = internetUnknown;
return m_iLastError;
}

// Increment our read position
// Parse some more

iResponseBuffSize += dwBytesRead;
retResponse->InitFromBuffer(sBuffer);

// Parse some more
// Send notification, if necessary

retResponse->InitFromBuffer(CString(ResponseBuff.GetPointer(), iResponseBuffSize, true));
if (pEvents)
pEvents->OnReceiveData(iTotalRead, -1);
}

// Done
Expand Down
Loading

0 comments on commit a99674f

Please sign in to comment.