Skip to content

Commit

Permalink
Use fixed width integer types in Compiler (#854)
Browse files Browse the repository at this point in the history
* Use fixed width integer types in Compiler

- Contributes to #535
- Contributes to #531
- Also address many code analysis issues from VS19 in-IDE parser
  - e.g. Use of enum class in preference to unscoped enums
- Define specific integer types (using enum class) for IPs and text positions to help identify
errors

* Post self code-review cleanup

* Wrong max radix
  • Loading branch information
blairmcg committed Dec 3, 2019
1 parent f3cce4e commit 1f60d3b
Show file tree
Hide file tree
Showing 26 changed files with 2,839 additions and 2,487 deletions.
4 changes: 2 additions & 2 deletions Core/DolphinVM/CompilePrims.cpp
Expand Up @@ -64,7 +64,7 @@ extern "C" Oop __stdcall PrimCompileForClass(Oop compilerOop, const char* szSour
if (piCompiler == NULL)
return Oop(GetVM()->NilPointer());

return (Oop)piCompiler->CompileForClass(GetVM(), compilerOop, szSource, (POTE)aClass, FLAGS(flags), notifier);
return (Oop)piCompiler->CompileForClass(GetVM(), compilerOop, szSource, (POTE)aClass, static_cast<FLAGS>(flags), notifier);
}

extern "C" Oop __stdcall PrimCompileForEval(Oop compilerOop, const char* szSource, Oop aClass, Oop aWorkspacePool, int flags, Oop notifier)
Expand All @@ -73,7 +73,7 @@ extern "C" Oop __stdcall PrimCompileForEval(Oop compilerOop, const char* szSourc
if (piCompiler == NULL)
return Oop(GetVM()->NilPointer());

return (Oop)piCompiler->CompileForEval(GetVM(), compilerOop, szSource, (POTE)aClass, (POTE)aWorkspacePool, FLAGS(flags), notifier);
return (Oop)piCompiler->CompileForEval(GetVM(), compilerOop, szSource, (POTE)aClass, (POTE)aWorkspacePool, static_cast<FLAGS>(flags), notifier);
}


Expand Down
5 changes: 4 additions & 1 deletion Core/DolphinVM/Compiler/Compiler.idl
Expand Up @@ -144,7 +144,10 @@ library CompilerLib
CInfoLast = CInfoHardBreakpoint
} FirstAndLastCodes;

typedef enum FLAGS {Default=0x00, SyntaxCheckOnly=0x02, NoOptimize=0x08, TextMap=0x10, TempsMap=0x20, DebugMethod=0x40, Boot=0x80, ScanOnly=0x100, Interactive=0x200, SendYourself=0x400} FLAGS;
cpp_quote("#define class_CompilerFlags class CompilerFlags")
typedef enum class_CompilerFlags
{Default=0x00, SyntaxCheckOnly=0x02, NoOptimize=0x08, TextMap=0x10, TempsMap=0x20, DebugMethod=0x40, Boot=0x80, ScanOnly=0x100, Interactive=0x200, SendYourself=0x400} FLAGS;
cpp_quote("#undef CompilerFlags")

[
object,
Expand Down
6 changes: 3 additions & 3 deletions Core/DolphinVM/Compiler/CompilerSupport.cpp
Expand Up @@ -14,15 +14,15 @@ be thrown away eventually, or perhaps compiled into a separate DLL.

#include "..\VMPointers.h"

POTE Compiler::NewCompiledMethod(POTE classPointer, unsigned numBytes, const STMethodHeader& hdr)
POTE Compiler::NewCompiledMethod(POTE classPointer, size_t numBytes, const STMethodHeader& hdr)
{
//_ASSERTE(ObjectMemory::inheritsFrom(classPointer, GetVMPointers().ClassCompiledMethod));
// Note we subtract
POTE methodPointer = m_piVM->NewObjectWithPointers(classPointer,
((sizeof(STCompiledMethod)
- sizeof(Oop) // Deduct dummy literal frame entry (arrays cannot be zero sized in IDL)
// -sizeof(ObjectHeader) // Deduct size of head which NewObjectWithPointers includes implicitly
) / sizeof(Oop)) + GetLiteralCount());
) / sizeof(Oop)) + LiteralCount);
STCompiledMethod* method = reinterpret_cast<STCompiledMethod*>(GetObj(methodPointer));
POTE bytes = m_piVM->NewByteArray(numBytes);
m_piVM->StorePointerWithValue((Oop*)&method->byteCodes, Oop(bytes));
Expand Down Expand Up @@ -86,7 +86,7 @@ bool Compiler::CanUnderstand(POTE oteBehavior, POTE oteSelector)
Oop Compiler::EvaluateExpression(LPUTF8 text, POTE oteMethod, Oop contextOop, POTE pools)
{
STCompiledMethod& exprMethod = *(STCompiledMethod*)GetObj(oteMethod);
BYTE primitive = exprMethod.header.primitiveIndex;
auto primitive = exprMethod.header.primitiveIndex;
Oop result;
// As an optimization avoid calling back into Smalltalk if we the expression is of simple form, e.g. a class ref
switch (primitive)
Expand Down

0 comments on commit 1f60d3b

Please sign in to comment.