Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vireo EggShell Refactor for Supporting More Types #471

Merged
merged 70 commits into from
Jul 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
167e818
Add the findValueRef API function
rajsite Jun 18, 2018
c4fbfd7
Update readDouble for ValueRef api
rajsite Jun 19, 2018
493d545
Add the shared createValueRef function
rajsite Jun 19, 2018
7fa3d60
Fix usage of createValueRef
rajsite Jun 19, 2018
ce1727c
Test unsupported types for readDouble
rajsite Jun 19, 2018
e69710c
Merged changes for readDouble
Jun 19, 2018
20c171c
Exported more Is* functions from TypeCommon
Jun 19, 2018
56d5567
Merged isType functions
Jun 19, 2018
f303d55
Added tests for `reflectOnValueRef` and fixed some issues.
Jun 20, 2018
d58340d
Fixed whitespace in EmMakeFile and removed cwrap for TopAQSize.
Jun 20, 2018
b7c830f
Moved all type related functions to its own module.
Jun 21, 2018
6db6834
Fixed linting issues
Jun 21, 2018
5f812dc
Modified TypeRef_Name to take a TypeManagerRef as other similar funct…
Jun 21, 2018
cfd90b0
Removed string allocations for errors
Jun 21, 2018
9d732e7
Moved v_root and v_userShell
Jun 21, 2018
440a175
Added findSubValueRef
Jun 21, 2018
caa3ca8
Added tests for FindSubValueRef
Jun 22, 2018
3c6658e
Moved readDouble function in eggShell
Jun 22, 2018
7ec6613
Added a little more validation to FindSubValue
Jun 22, 2018
6e61e37
Added InvalidTypeRef as an EggShellResult
Jun 25, 2018
89b024b
Changed top-level test description
Jun 25, 2018
285aafa
First pass at string read
rajsite Jun 21, 2018
c95bfdd
Enable all tests
rajsite Jun 21, 2018
357a758
Move type functions to new module
rajsite Jun 21, 2018
9978769
Expand types for readTypedArray
rajsite Jun 22, 2018
a500383
Fix cpplint error
rajsite Jun 22, 2018
deefc47
Change Data_GetArrayBegin to return pointer
rajsite Jun 22, 2018
3b526c1
Add boolean array support for readTypedArray
rajsite Jun 23, 2018
8c3eee6
Fix GetNumericArray test for new variable name
rajsite Jun 23, 2018
e200e3e
Use readTypedArray for HttpPost buffer
rajsite Jun 23, 2018
289aad2
Fix Makefile whitespace
rajsite Jun 25, 2018
38f6b95
Cover unsupported cases for readString and getArrayDimensions
rajsite Jun 25, 2018
4327ab0
Merged typeRank and elementName
Jun 26, 2018
7563590
Initial implementation of readValueRefObject with tests
Jun 25, 2018
93713db
Added some more validation for accepted types of readValueRefObject.
Jun 26, 2018
e365f83
Updated error for readValueRefObject
Jun 26, 2018
800ca42
Added note on typeHandlers order.
Jun 26, 2018
129c512
Added a few more comments to explain order of typeHandlers
Jun 26, 2018
17bffae
Added tests for NIPath
Jun 26, 2018
9524c9d
Resize array initial implementation
rajsite Jun 25, 2018
c761212
Move Rank validation to Cpp layer
rajsite Jun 26, 2018
d9755cc
Move valid array type check to cpp
rajsite Jun 26, 2018
070a00c
Fix cpp lint error
rajsite Jun 26, 2018
6ccce6e
Updated EggShell_ReadValueString to use type and data pointers.
Jun 26, 2018
f816bcb
Deleted HelloNode.js
Jun 26, 2018
4282813
Added UnableToParseData to eggShellResultEnum
Jun 27, 2018
b324a8d
Fixed tests for new writeJSON API.
Jun 27, 2018
44724a8
Fixed remaining broken tests
Jun 27, 2018
a905e11
First pass of writeString
rajsite Jun 27, 2018
cc225b8
Update comment for jsStringToSizedUTF8Array
rajsite Jun 27, 2018
d59084d
Expand readString and writeString tests
rajsite Jun 28, 2018
b14bda8
First pass writeDouble api
rajsite Jun 28, 2018
5eb6d59
Expand writeDouble tests and use EggShellResult
rajsite Jun 28, 2018
4f8a8e2
Aded visitEnum[8|16|32] to visitor reflection API
Jun 28, 2018
0e9519d
Changed name of visitor functions for enums
Jun 28, 2018
e9e9b21
Mark deprecated functions in eggShell api
rajsite Jun 29, 2018
7004589
Standardized on call for dispatchers and fixed loop condition.
Jul 2, 2018
72050a1
Added tests for context and arguments of visitor functions.
Jul 9, 2018
f391fd4
Merge pull request #2 from gleonoliva/typehelpers-fixes
rajsite Jul 9, 2018
ae135ca
Renamed TypeWaveform tests to be included in the test suite.
Jul 3, 2018
9db209f
Fixed tests in TypeWaveform.
Jul 3, 2018
e79f1e3
Fixing FindSubValueRef
Jul 3, 2018
c01c7e2
Fixed linting errors
Jul 9, 2018
558ff6f
Renamed tests
Jul 9, 2018
32b5f73
Reverted writeJSStringToStack and added a free memory on writeJSON.
Jul 9, 2018
48562fd
Merge pull request #3 from gleonoliva/read-write-json-tests
rajsite Jul 9, 2018
1eef26c
Type support feedback (#4)
Jul 9, 2018
7754218
Type support feedback5 (#5)
Jul 10, 2018
8498742
Use decoded field names in readValueRefObject
rajsite Jul 11, 2018
80c9e0f
Merge pull request #6 from rajsite/valuerefobject-decoded-names
rajsite Jul 11, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion make-it/EmMakefile
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ EM_EXPORTS = -s EXPORTED_FUNCTIONS="[\
'_EggShell_REPL',\
'_EggShell_ExecuteSlices',\
'_EggShell_Delete',\
'_EggShell_FindValue',\
'_EggShell_FindSubValue',\
'_EggShell_ReadDouble',\
'_EggShell_WriteDouble',\
'_EggShell_ReadValueString',\
Expand Down Expand Up @@ -140,11 +142,32 @@ EM_EXPORTS = -s EXPORTED_FUNCTIONS="[\
'_Data_WriteDouble',\
'_Data_WriteJavaScriptRefNum',\
'_Data_GetArrayMetadata',\
'_Data_GetArrayBegin',\
'_Data_GetArrayDimensions',\
'_Data_GetArrayLength',\
'_Data_GetArrayDimLength',\
'_Data_ResizeArray',\
'_TypeRef_TopAQSize',\
'_TypeRef_Name',\
'_TypeRef_ElementName',\
'_TypeRef_SubElementCount',\
'_TypeRef_GetSubElementByIndex',\
'_TypeRef_IsCluster',\
'_TypeRef_IsArray',\
'_TypeRef_IsBoolean',\
'_TypeRef_IsInteger',\
'_TypeRef_IsSigned',\
'_TypeRef_IsEnum',\
'_TypeRef_IsFloat',\
'_TypeRef_IsString',\
'_TypeRef_IsPath',\
'_TypeRef_IsTimestamp',\
'_TypeRef_IsComplex',\
'_TypeRef_IsAnalogWaveform',\
'_JavaScriptInvoke_GetParameterType',\
'_JavaScriptInvoke_GetParameterPointer',\
'_JavaScriptInvoke_GetArrayElementType'\
'_JavaScriptInvoke_GetArrayElementType',\
'_TypeRef_Rank'\
]"

EM_RUNTIME_EXPORTS = -s EXTRA_EXPORTED_RUNTIME_METHODS="[\
Expand Down
270 changes: 218 additions & 52 deletions source/core/CEntryPoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,67 +118,93 @@ VIREO_EXPORT Int32 EggShell_PokeMemory(TypeManagerRef tm,
}
}
//------------------------------------------------------------
//! Write a numeric value to a symbol. Value will be coerced as needed.
VIREO_EXPORT void EggShell_WriteDouble(TypeManagerRef tm, const char* viName, const char* eltName, Double d)
//! Get a reference to the type pointer and data for a symbol.
VIREO_EXPORT EggShellResult EggShell_FindValue(TypeManagerRef tm, const char* viName, const char* eltName, TypeRef* typeRefLocation, void** dataRefLocation)
{
void *pData = nullptr;

TypeManagerScope scope(tm);
SubString objectName(viName);
SubString path(eltName);
TypeRef actualType = tm->GetObjectElementAddressFromPath(&objectName, &path, &pData, true);
if (actualType == nullptr)
return;
*typeRefLocation = tm->GetObjectElementAddressFromPath(&objectName, &path, dataRefLocation, true);
if (*typeRefLocation == nullptr)
return kEggShellResult_ObjectNotFoundAtPath;

WriteDoubleToMemory(actualType, pData, d);
return kEggShellResult_Success;
}
//------------------------------------------------------------
//! Read a numeric value from a symbol. Value will be coerced as needed.
VIREO_EXPORT Double EggShell_ReadDouble(TypeManagerRef tm, const char* viName, const char* eltName)
//! Get a reference to the type pointer and data for a sub element
VIREO_EXPORT EggShellResult EggShell_FindSubValue(TypeManagerRef tm,
const TypeRef typeRef, void * pData, const char* eltName, TypeRef* typeRefLocation, void** dataRefLocation)
{
void *pData = nullptr;
SubString objectName(viName);
if (typeRef == nullptr || !typeRef->IsValid())
return kEggShellResult_InvalidTypeRef;

TypeManagerScope scope(tm);
SubString path(eltName);
TypeRef actualType = tm->GetObjectElementAddressFromPath(&objectName, &path, &pData, true);
if (actualType == nullptr)
return -1;
*typeRefLocation = typeRef->GetSubElementAddressFromPath(&path, pData, dataRefLocation, true);
if (*typeRefLocation == nullptr)
return kEggShellResult_ObjectNotFoundAtPath;

return ReadDoubleFromMemory(actualType, pData);
return kEggShellResult_Success;
}
//------------------------------------------------------------
// Write a string value to a symbol. Value will be parsed according to format designated.
VIREO_EXPORT void EggShell_WriteValueString(TypeManagerRef tm,
const char* viName, const char* eltName, const char* format, const char* value)
//! Write a numeric value to a symbol. Value will be coerced as needed.
VIREO_EXPORT EggShellResult EggShell_WriteDouble(TypeManagerRef tm, const TypeRef typeRef, void* pData, Double value)
{
TypeManagerScope scope(tm);
if (typeRef == nullptr || !typeRef->IsValid())
return kEggShellResult_InvalidTypeRef;

void *pData = nullptr;
NIError error = WriteDoubleToMemory(typeRef, pData, value);
if (error)
return kEggShellResult_UnexpectedObjectType;
return kEggShellResult_Success;
}
//------------------------------------------------------------
//! Read a numeric value from a symbol. Value will be coerced as needed.
VIREO_EXPORT EggShellResult EggShell_ReadDouble(TypeManagerRef tm, const TypeRef typeRef, const void* pData, Double* result)
{
TypeManagerScope scope(tm);
if (typeRef == nullptr || !typeRef->IsValid())
return kEggShellResult_InvalidTypeRef;

if (result == nullptr)
return kEggShellResult_InvalidResultPointer;

NIError error = kNIError_Success;
*result = ReadDoubleFromMemory(typeRef, pData, &error);
if (error)
return kEggShellResult_UnexpectedObjectType;
return kEggShellResult_Success;
}
//------------------------------------------------------------
// Write a string value to a symbol. Value will be parsed according to format designated.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"to designated format" instead of "to format designated"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll change it

VIREO_EXPORT EggShellResult EggShell_WriteValueString(TypeManagerRef tm, const TypeRef typeRef, void* pData, const char* format, const char* value)
{
TypeManagerScope scope(tm);

SubString objectName(viName);
SubString path(eltName);
SubString valueString(value);

TypeRef actualType = tm->GetObjectElementAddressFromPath(&objectName, &path, &pData, true);
if (actualType == nullptr)
return;
if (typeRef == nullptr || !typeRef->IsValid())
return kEggShellResult_InvalidTypeRef;

EventLog log(EventLog::DevNull);
SubString formatss(format);
TDViaParser parser(tm, &valueString, &log, 1, &formatss, true, true, true);
parser.ParseData(actualType, pData);
Int32 error = parser.ParseData(typeRef, pData);
if (error) {
return kEggShellResult_UnableToParseData;
}

return kEggShellResult_Success;
}
//------------------------------------------------------------
//! Read a symbol's value as a string. Value will be formatted according to the format designated.
VIREO_EXPORT const char* EggShell_ReadValueString(TypeManagerRef tm,
const char* viName, const char* eltName, const char* format)
//! Read a symbol's value as a string. Value will be formatted according to designated format.
VIREO_EXPORT EggShellResult EggShell_ReadValueString(TypeManagerRef tm, const TypeRef typeRef, void* pData, const char* format, UInt8** valueString)
{
TypeManagerScope scope(tm);
void *pData = nullptr;

SubString objectName(viName);
SubString path(eltName);
TypeRef actualType = tm->GetObjectElementAddressFromPath(&objectName, &path, &pData, true);
if (actualType == nullptr)
return nullptr;
if (typeRef == nullptr || !typeRef->IsValid())
return kEggShellResult_InvalidTypeRef;

static StringRef returnBuffer = nullptr;
if (returnBuffer == nullptr) {
Expand All @@ -193,12 +219,14 @@ VIREO_EXPORT const char* EggShell_ReadValueString(TypeManagerRef tm,
if (returnBuffer) {
SubString formatss(format);
TDViaFormatter formatter(returnBuffer, true, 0, &formatss, kJSONEncodingEggShell);
formatter.FormatData(actualType, pData);
// Add an explicit nullptr terminator so it looks like a C string.
formatter.FormatData(typeRef, pData);
// Add an explicit null terminator so it looks like a C string.
returnBuffer->Append((Utf8Char)'\0');
return (const char*) returnBuffer->Begin();
*valueString = returnBuffer->Begin();
return kEggShellResult_Success;
}
return "";

return kEggShellResult_UnableToCreateReturnBuffer;
}
void CopyArrayTypeNameStringToBuffer(StringRef arrayTypeNameBuffer, SubString arrayTypeName)
{
Expand Down Expand Up @@ -257,20 +285,26 @@ VIREO_EXPORT Int32 EggShell_GetArrayDimLength(TypeManagerRef tm, const char* viN
}
//------------------------------------------------------------
//! Resizes a variable size Array symbol to have new dimension lengths specified by newLengths, it also initializes cells for non-flat data.
//! Returns -1 if the symbols is not found, -2 if was not possible to resize the array and 0 if resizing was successful.
VIREO_EXPORT Int32 EggShell_ResizeArray(TypeManagerRef tm, const char* viName, const char* eltName, Int32 rank, Int32* newLengths)
VIREO_EXPORT EggShellResult EggShell_ResizeArray(TypeManagerRef tm, const TypeRef typeRef, const void* pData,
Int32 rank, Int32 dimensionLengths[])
{
SubString objectName(viName);
SubString path(eltName);
void *pData = nullptr;
TypeManagerScope scope(tm);
if (typeRef == nullptr || !typeRef->IsValid())
return kEggShellResult_InvalidTypeRef;

TypeRef actualType = tm->GetObjectElementAddressFromPath(&objectName, &path, &pData, true);
if (actualType == nullptr || !actualType->IsArray()) {
return kLVError_ArgError;
}
if (!typeRef->IsArray())
return kEggShellResult_UnexpectedObjectType;

TypedArrayCoreRef actualArray = *(TypedArrayCoreRef*)pData;
return Data_ResizeArray(tm, actualArray, rank, newLengths);
if (typeRef->Rank() != rank)
return kEggShellResult_MismatchedArrayRank;

TypedArrayCoreRef arrayObject = *(TypedArrayCoreRef*)pData;
VIREO_ASSERT(TypedArrayCore::ValidateHandle(arrayObject));

if (!arrayObject->ResizeDimensions(rank, dimensionLengths, true, false)) {
return kEggShellResult_UnableToCreateReturnBuffer;
}
return kEggShellResult_Success;
}
//------------------------------------------------------------
VIREO_EXPORT void* Data_GetStringBegin(StringRef stringObject)
Expand Down Expand Up @@ -329,6 +363,34 @@ VIREO_EXPORT EggShellResult Data_GetArrayMetadata(TypeManagerRef tm,
return kEggShellResult_Success;
}
//------------------------------------------------------------
//! Get the starting location of the first element of an Array / String type in memory
// This function returns the start address of where elements would appear in memory (returns address even if length zero)
VIREO_EXPORT void* Data_GetArrayBegin(const void* pData)
{
TypedArrayCoreRef arrayObject = *(TypedArrayCoreRef*)pData;
VIREO_ASSERT(TypedArrayCore::ValidateHandle(arrayObject));
return arrayObject->BeginAt(0);
}
//------------------------------------------------------------
//! Get the values for dimensions of the array. Assumes dimensions target is of length equal to rank
//! Caller is expected to allocate an array dimensions of size array rank for the duration of function invocation.
VIREO_EXPORT void Data_GetArrayDimensions(const void* pData, IntIndex dimensionsLengths[])
{
TypedArrayCoreRef arrayObject = *(TypedArrayCoreRef*)pData;
VIREO_ASSERT(TypedArrayCore::ValidateHandle(arrayObject));
for (int i = 0; i < arrayObject->Rank(); i++) {
dimensionsLengths[i] = arrayObject->GetLength(i);
}
}
//------------------------------------------------------------
//! Get the total length for an array
VIREO_EXPORT Int32 Data_GetArrayLength(const void* pData)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name ArrayLength is good 👍

{
TypedArrayCoreRef arrayObject = *(TypedArrayCoreRef*)pData;
VIREO_ASSERT(TypedArrayCore::ValidateHandle(arrayObject));
return arrayObject->Length();
}
//------------------------------------------------------------
//! Get the Length of a dimension in an Array Symbol. Returns -1 if the Symbol is not found or not
//! an Array or dimension requested is out of the bounds of the rank.
VIREO_EXPORT Int32 Data_GetArrayDimLength(TypeManagerRef tm, TypedArrayCoreRef arrayObject, Int32 dim)
Expand Down Expand Up @@ -505,10 +567,54 @@ VIREO_EXPORT Int32 TypeRef_Alignment(TypeRef typeRef)
return typeRef->AQAlignment();
}
//------------------------------------------------------------
VIREO_EXPORT void TypeRef_Name(TypeRef typeRef, Int32* bufferSize, char* buffer)
VIREO_EXPORT const char* TypeRef_Name(TypeManagerRef tm, TypeRef typeRef)
{
TypeManagerScope scope(tm);
SubString name = typeRef->Name();
*bufferSize = name.CopyToBoundedBuffer(*bufferSize, reinterpret_cast<Utf8Char*>(buffer));

static StringRef returnBuffer = nullptr;
if (returnBuffer == nullptr) {
// Allocate a string the first time it is used.
// After that it will be resized as needed.
STACK_VAR(String, tempReturn);
returnBuffer = tempReturn.DetachValue();
} else {
returnBuffer->Resize1D(name.Length() + 1);
}

if (returnBuffer) {
returnBuffer->CopyFromSubString(&name);
// Add an explicit null terminator so it looks like a C string.
returnBuffer->Append((Utf8Char)'\0');
return (const char*) returnBuffer->Begin();
}

return "";
}
//------------------------------------------------------------
VIREO_EXPORT const char* TypeRef_ElementName(TypeManagerRef tm, TypeRef typeRef)
{
TypeManagerScope scope(tm);
SubString name = typeRef->ElementName();

static StringRef returnBuffer = nullptr;
if (returnBuffer == nullptr) {
// Allocate a string the first time it is used.
// After that it will be resized as needed.
STACK_VAR(String, tempReturn);
returnBuffer = tempReturn.DetachValue();
} else {
returnBuffer->Resize1D(name.Length() + 1);
}

if (returnBuffer) {
returnBuffer->CopyFromSubString(&name);
// Add an explicit null terminator so it looks like a C string.
returnBuffer->Append((Utf8Char)'\0');
return (const char*) returnBuffer->Begin();
}

return "";
}
//------------------------------------------------------------
VIREO_EXPORT Int32 TypeRef_ElementOffset(TypeRef typeRef)
Expand Down Expand Up @@ -546,6 +652,66 @@ VIREO_EXPORT TypeRef TypeRef_GetSubElementByIndex(TypeRef typeRef, Int32 index)
return typeRef->GetSubElement(index);
}
//------------------------------------------------------------
VIREO_EXPORT Boolean TypeRef_IsCluster(TypeRef typeRef)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have the prefix of EggShell for all the new APIs that start with TypeRef as well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are not exposing these functions to eggShell, I don't think they should be prefixed as eggshell. That's why we added the typeHelpers module.

{
return typeRef->IsCluster();
}
//------------------------------------------------------------
VIREO_EXPORT Boolean TypeRef_IsArray(TypeRef typeRef)
{
return typeRef->IsArray();
}
//------------------------------------------------------------
VIREO_EXPORT Boolean TypeRef_IsBoolean(TypeRef typeRef)
{
return typeRef->IsBoolean();
}
//------------------------------------------------------------
VIREO_EXPORT Boolean TypeRef_IsInteger(TypeRef typeRef)
{
return typeRef->IsInteger();
}
//------------------------------------------------------------
VIREO_EXPORT Boolean TypeRef_IsSigned(TypeRef typeRef)
{
return typeRef->IsSignedInteger();
}
//------------------------------------------------------------
VIREO_EXPORT Boolean TypeRef_IsEnum(TypeRef typeRef)
{
return typeRef->IsEnum();
}
//------------------------------------------------------------
VIREO_EXPORT Boolean TypeRef_IsFloat(TypeRef typeRef)
{
return typeRef->IsFloat();
}
//------------------------------------------------------------
VIREO_EXPORT Boolean TypeRef_IsString(TypeRef typeRef)
{
return typeRef->IsString();
}
//------------------------------------------------------------
VIREO_EXPORT Boolean TypeRef_IsPath(TypeRef typeRef)
{
return typeRef->IsPath();
}
//------------------------------------------------------------
VIREO_EXPORT Boolean TypeRef_IsTimestamp(TypeRef typeRef)
{
return typeRef->IsTimestamp();
}
//------------------------------------------------------------
VIREO_EXPORT Boolean TypeRef_IsComplex(TypeRef typeRef)
{
return typeRef->IsComplex();
}
//------------------------------------------------------------
VIREO_EXPORT Boolean TypeRef_IsAnalogWaveform(TypeRef typeRef)
{
return typeRef->IsAnalogWaveform();
}
//------------------------------------------------------------
//------------------------------------------------------------
VIREO_EXPORT Int32 Data_RawBlockSize(TypedBlock* object)
{
Expand Down
2 changes: 1 addition & 1 deletion source/core/StringUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ void SubString::TrimQuotedString(TokenTraits tt)
}
}
//------------------------------------------------------------
IntIndex SubString::FindFirstMatch(SubString* searchString, IntIndex offset, Boolean ignoreCase)
IntIndex SubString::FindFirstMatch(const SubString* searchString, IntIndex offset, Boolean ignoreCase)
{
IntIndex searchStringLength = searchString->Length();
if (Length() == 0 || searchStringLength > Length())
Expand Down
Loading