Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add chunk properties to values.

  • Loading branch information...
commit 3efbe5a5277eab27710cafb6868069534cc95d1e 1 parent d76eae2
Uli Kusterer authored
105 common/LEOInstructions.c
View
@@ -606,14 +606,113 @@ void LEOPushChunkInstruction( LEOContext* inContext )
return;
char str[1024] = { 0 };
- LEOGetValueAsString( chunkTarget, str, sizeof(str), inContext );
+ char* completeStr = LEOGetValueAsString( chunkTarget, str, sizeof(str), inContext );
LEOCleanUpStackToPtr( inContext, inContext->stackEndPtr -2 );
size_t startDelOffs = 0, endDelOffs = 0;
- LEOGetChunkRanges( str, inContext->currentInstruction->param2, chunkStartOffs, chunkEndOffs, &chunkStartOffs, &chunkEndOffs, &startDelOffs, &endDelOffs, inContext->itemDelimiter );
+ LEOGetChunkRanges( completeStr, inContext->currentInstruction->param2, chunkStartOffs, chunkEndOffs, &chunkStartOffs, &chunkEndOffs, &startDelOffs, &endDelOffs, inContext->itemDelimiter );
LEOCleanUpValue( inContext->stackEndPtr -1, kLEOInvalidateReferences, inContext );
- LEOInitStringValue( inContext->stackEndPtr -1, str +chunkStartOffs, chunkEndOffs -chunkStartOffs, kLEOInvalidateReferences, inContext );
+ LEOInitStringValue( inContext->stackEndPtr -1, completeStr +chunkStartOffs, chunkEndOffs -chunkStartOffs, kLEOInvalidateReferences, inContext );
+
+ inContext->currentInstruction++;
+}
+
+
+/*!
+ Change a property of a sub-range of an object. (SET_CHUNK_PROPERTY_INSTR)
+
+ The property name, value, chunk end and chunk start are popped off the back of the stack (in that order).
+
+ param1 - The basePtr-relative offset of the value to be referenced. If this is BACK_OF_STACK it will get the value from the stack, and expects it to have been pushed as the very first parameter.
+
+ param2 - The LEOChunkType of this chunk expression.
+
+ @seealso //leo_ref/c/func/LEOGetChunkRanges LEOGetChunkRanges
+*/
+
+void LEOSetChunkPropertyInstruction( LEOContext* inContext )
+{
+ LEOValuePtr chunkTarget = NULL;
+ bool onStack = (inContext->currentInstruction->param1 == BACK_OF_STACK);
+ if( onStack )
+ chunkTarget = inContext->stackEndPtr -3;
+ else
+ chunkTarget = (inContext->stackBasePtr +(*(int16_t*)&inContext->currentInstruction->param1));
+ LEOValuePtr propName = inContext->stackEndPtr -1;
+ LEOValuePtr propValue = inContext->stackEndPtr -2;
+ LEOValuePtr chunkEnd = inContext->stackEndPtr -3;
+ LEOValuePtr chunkStart = inContext->stackEndPtr -4;
+
+ size_t chunkStartOffs = LEOGetValueAsInteger(chunkStart,inContext) -1;
+ if( !inContext->keepRunning )
+ return;
+
+ size_t chunkEndOffs = LEOGetValueAsInteger(chunkEnd,inContext) -1;
+ if( !inContext->keepRunning )
+ return;
+
+ char propNameStr[1024] = { 0 };
+ char* completePropNameStr = LEOGetValueAsString( propName, propNameStr, sizeof(propNameStr), inContext );
+
+ char str[1024] = { 0 };
+ char* completeStr = LEOGetValueAsString( chunkTarget, str, sizeof(str), inContext );
+
+ size_t startDelOffs = 0, endDelOffs = 0;
+ LEOGetChunkRanges( completeStr, inContext->currentInstruction->param2, chunkStartOffs, chunkEndOffs, &chunkStartOffs, &chunkEndOffs, &startDelOffs, &endDelOffs, inContext->itemDelimiter );
+ LEOSetValueForKeyOfRange( chunkTarget, completePropNameStr, propValue, chunkStartOffs, chunkEndOffs, inContext );
+
+ LEOCleanUpStackToPtr( inContext, inContext->stackEndPtr -1 );
+
+ inContext->currentInstruction++;
+}
+
+
+/*!
+ Push the value of a property of a chunk out of a larger value onto the stack as a string value. (PUSH_CHUNK_PROPERTY_INSTR)
+
+ The name, chunk end and chunk start are popped off the back of the stack (in that order).
+
+ param1 - The basePtr-relative offset of the value to be referenced. If this is BACK_OF_STACK it will get the value from the stack, and expects it to have been pushed as the very first parameter.
+
+ param2 - The LEOChunkType of this chunk expression.
+
+ @seealso //leo_ref/c/func/LEOGetChunkRanges LEOGetChunkRanges
+*/
+
+void LEOPushChunkPropertyInstruction( LEOContext* inContext )
+{
+ LEOValuePtr chunkTarget = NULL;
+ bool onStack = (inContext->currentInstruction->param1 == BACK_OF_STACK);
+ if( onStack )
+ chunkTarget = inContext->stackEndPtr -3;
+ else
+ chunkTarget = (inContext->stackBasePtr +(*(int16_t*)&inContext->currentInstruction->param1));
+ LEOValuePtr propName = inContext->stackEndPtr -1;
+ LEOValuePtr chunkEnd = inContext->stackEndPtr -2;
+ LEOValuePtr chunkStart = inContext->stackEndPtr -3;
+
+ size_t chunkStartOffs = LEOGetValueAsInteger(chunkStart,inContext) -1;
+ if( !inContext->keepRunning )
+ return;
+
+ size_t chunkEndOffs = LEOGetValueAsInteger(chunkEnd,inContext) -1;
+ if( !inContext->keepRunning )
+ return;
+
+ char propNameStr[1024] = { 0 };
+ char* completePropNameStr = LEOGetValueAsString( propName, propNameStr, sizeof(propNameStr), inContext );
+
+ char str[1024] = { 0 };
+ char* completeStr = LEOGetValueAsString( chunkTarget, str, sizeof(str), inContext );
+
+ LEOCleanUpStackToPtr( inContext, inContext->stackEndPtr -2 );
+
+ size_t startDelOffs = 0, endDelOffs = 0;
+ LEOGetChunkRanges( completeStr, inContext->currentInstruction->param2, chunkStartOffs, chunkEndOffs, &chunkStartOffs, &chunkEndOffs, &startDelOffs, &endDelOffs, inContext->itemDelimiter );
+ LEOCleanUpValue( inContext->stackEndPtr -2, kLEOInvalidateReferences, inContext );
+
+ LEOGetValueForKeyOfRange( chunkTarget, completePropNameStr, chunkStartOffs, chunkEndOffs, chunkTarget, inContext );
inContext->currentInstruction++;
}
2  common/LEOInstructions.h
View
@@ -89,6 +89,8 @@ enum
CHAR_TO_NUM_INSTR,
NUM_TO_HEX_INSTR,
HEX_TO_NUM_INSTR,
+ SET_CHUNK_PROPERTY_INSTR,
+ PUSH_CHUNK_PROPERTY_INSTR,
LEO_NUMBER_OF_INSTRUCTIONS // MUST BE LAST.
};
96 common/LEOValue.c
View
@@ -75,7 +75,10 @@ struct LEOValueType kLeoValueTypeNumber =
LEOCantGetValueForKey,
LEOCantSetValueForKey,
LEOCantSetValueAsArray,
- LEOCantGetKeyCount
+ LEOCantGetKeyCount,
+
+ LEOCantGetValueForKeyOfRange,
+ LEOCantSetValueForKeyOfRange
};
@@ -110,7 +113,10 @@ struct LEOValueType kLeoValueTypeInteger =
LEOCantGetValueForKey,
LEOCantSetValueForKey,
LEOCantSetValueAsArray,
- LEOCantGetKeyCount
+ LEOCantGetKeyCount,
+
+ LEOCantGetValueForKeyOfRange,
+ LEOCantSetValueForKeyOfRange
};
@@ -145,7 +151,10 @@ struct LEOValueType kLeoValueTypeString =
LEOCantGetValueForKey,
LEOSetStringLikeValueForKey,
LEOSetStringLikeValueAsArray,
- LEOCantGetKeyCount
+ LEOCantGetKeyCount,
+
+ LEOCantGetValueForKeyOfRange,
+ LEOCantSetValueForKeyOfRange
};
@@ -180,7 +189,10 @@ struct LEOValueType kLeoValueTypeStringConstant =
LEOCantGetValueForKey,
LEOCantSetValueForKey,
LEOSetStringLikeValueAsArray,
- LEOCantGetKeyCount
+ LEOCantGetKeyCount,
+
+ LEOCantGetValueForKeyOfRange,
+ LEOCantSetValueForKeyOfRange
};
@@ -217,7 +229,10 @@ struct LEOValueType kLeoValueTypeBoolean =
LEOCantGetValueForKey,
LEOCantSetValueForKey,
LEOCantSetValueAsArray,
- LEOCantGetKeyCount
+ LEOCantGetKeyCount,
+
+ LEOCantGetValueForKeyOfRange,
+ LEOCantSetValueForKeyOfRange
};
@@ -252,7 +267,10 @@ struct LEOValueType kLeoValueTypeReference =
LEOGetReferenceValueValueForKey,
LEOSetReferenceValueValueForKey,
LEOSetReferenceValueAsArray,
- LEOGetReferenceValueKeyCount
+ LEOGetReferenceValueKeyCount,
+
+ LEOGetReferenceValueForKeyOfRange,
+ LEOSetReferenceValueForKeyOfRange
};
@@ -287,7 +305,10 @@ struct LEOValueType kLeoValueTypeNumberVariant =
LEOCantGetValueForKey,
LEOCantSetValueForKey,
LEOSetVariantValueAsArray,
- LEOCantGetKeyCount
+ LEOCantGetKeyCount,
+
+ LEOCantGetValueForKeyOfRange,
+ LEOCantSetValueForKeyOfRange
};
@@ -322,7 +343,10 @@ struct LEOValueType kLeoValueTypeIntegerVariant =
LEOCantGetValueForKey,
LEOCantSetValueForKey,
LEOSetVariantValueAsArray,
- LEOCantGetKeyCount
+ LEOCantGetKeyCount,
+
+ LEOCantGetValueForKeyOfRange,
+ LEOCantSetValueForKeyOfRange
};
@@ -357,7 +381,10 @@ struct LEOValueType kLeoValueTypeStringVariant =
LEOCantGetValueForKey,
LEOSetStringVariantValueValueForKey,
LEOSetVariantValueAsArray,
- LEOCantGetKeyCount
+ LEOCantGetKeyCount,
+
+ LEOCantGetValueForKeyOfRange,
+ LEOCantSetValueForKeyOfRange
};
@@ -392,7 +419,10 @@ struct LEOValueType kLeoValueTypeBooleanVariant =
LEOCantGetValueForKey,
LEOCantSetValueForKey,
LEOSetVariantValueAsArray,
- LEOCantGetKeyCount
+ LEOCantGetKeyCount,
+
+ LEOCantGetValueForKeyOfRange,
+ LEOCantSetValueForKeyOfRange
};
@@ -427,7 +457,10 @@ struct LEOValueType kLeoValueTypeArray =
LEOGetArrayValueValueForKey,
LEOSetArrayValueValueForKey,
LEOSetArrayValueAsArray,
- LEOGetArrayValueKeyCount
+ LEOGetArrayValueKeyCount,
+
+ LEOCantGetValueForKeyOfRange,
+ LEOCantSetValueForKeyOfRange
};
@@ -462,7 +495,10 @@ struct LEOValueType kLeoValueTypeArrayVariant =
LEOGetArrayValueValueForKey,
LEOSetArrayValueValueForKey,
LEOSetArrayValueAsArray,
- LEOGetArrayValueKeyCount
+ LEOGetArrayValueKeyCount,
+
+ LEOCantGetValueForKeyOfRange,
+ LEOCantSetValueForKeyOfRange
};
@@ -721,6 +757,18 @@ void LEOSetStringLikeValueAsArray( LEOValuePtr self, struct LEOArrayEntry *inArr
}
+void LEOCantGetValueForKeyOfRange( LEOValuePtr self, const char* keyName, size_t startOffset, size_t endOffset, LEOValuePtr outValue, struct LEOContext* inContext )
+{
+ LEOContextStopWithError( inContext, "Can't get properties of ranges of a %s", self->base.isa->displayTypeName );
+}
+
+
+void LEOCantSetValueForKeyOfRange( LEOValuePtr self, const char* keyName, LEOValuePtr inValue, size_t startOffset, size_t endOffset, struct LEOContext* inContext )
+{
+ LEOContextStopWithError( inContext, "Ranges of a %s can't have properties", self->base.isa->displayTypeName );
+}
+
+
#pragma mark -
#pragma mark Number
@@ -2034,6 +2082,30 @@ size_t LEOGetReferenceValueKeyCount( LEOValuePtr self, struct LEOContext * inCo
}
+void LEOGetReferenceValueForKeyOfRange( LEOValuePtr self, const char* keyName, size_t startOffset, size_t endOffset, LEOValuePtr outValue, struct LEOContext* inContext )
+{
+ LEOValuePtr theValue = LEOContextGroupGetPointerForObjectIDAndSeed( inContext->group, self->reference.objectID, self->reference.objectSeed );
+ if( theValue == NULL )
+ {
+ LEOContextStopWithError( inContext, "The referenced value doesn't exist anymore." );
+ }
+ else
+ LEOGetValueForKeyOfRange( theValue, keyName, startOffset, endOffset, outValue, inContext );
+}
+
+
+void LEOSetReferenceValueForKeyOfRange( LEOValuePtr self, const char* keyName, LEOValuePtr inValue, size_t startOffset, size_t endOffset, struct LEOContext* inContext )
+{
+ LEOValuePtr theValue = LEOContextGroupGetPointerForObjectIDAndSeed( inContext->group, self->reference.objectID, self->reference.objectSeed );
+ if( theValue == NULL )
+ {
+ LEOContextStopWithError( inContext, "The referenced value doesn't exist anymore." );
+ }
+ else
+ LEOSetValueForKeyOfRange( theValue, keyName, inValue, startOffset, endOffset, inContext );
+}
+
+
LEOValuePtr LEOReferenceValueFollowReferencesAndReturnValueOfType( LEOValuePtr self, LEOValueTypePtr inType, struct LEOContext* inContext )
{
LEOValuePtr theValue = LEOContextGroupGetPointerForObjectIDAndSeed( inContext->group, self->reference.objectID, self->reference.objectSeed );
41 common/LEOValue.h
View
@@ -117,6 +117,9 @@ struct LEOValueType
void (*SetValueAsArray)( LEOValuePtr self, struct LEOArrayEntry* inArray, struct LEOContext* inContext );
size_t (*GetKeyCount)( LEOValuePtr self, struct LEOContext* inContext );
+
+ void (*GetValueForKeyOfRange)( LEOValuePtr self, const char* keyName, size_t startOffset, size_t endOffset, LEOValuePtr outValue, struct LEOContext* inContext );
+ void (*SetValueForKeyOfRange)( LEOValuePtr self, const char* keyName, LEOValuePtr inValue, size_t startOffset, size_t endOffset, struct LEOContext* inContext );
};
@@ -747,7 +750,6 @@ void LEOInitBooleanVariantValue( LEOValuePtr self, bool inBoolean, LEOKeepRefer
@param s The source value to copy into the array.
@param c The context in which your script is currently running and in
which errors will be stored.
- @result A LEOValuePtr pointing to the actual value in the array.
*/
#define LEOSetValueForKey(v,k,s,c) ((LEOValuePtr)(v))->base.isa->SetValueForKey(((LEOValuePtr)(v)),(k),(s),(c))
@@ -764,6 +766,36 @@ void LEOInitBooleanVariantValue( LEOValuePtr self, bool inBoolean, LEOKeepRefer
/*!
+ @function LEOGetValueForKeyOfRange
+ Fetches the value with the given key from the array in the specified value.
+ Returns NULL if there is no value under that key yet.
+ @param v The value you wish to examine.
+ @param k The key of the array item to fetch.
+ @param so The start offset of the byte range.
+ @param eo The end offset of the byte range.
+ @param ov This value will be set to a copy of value of the key of that range.
+ @param c The context in which your script is currently running and in
+ which errors will be stored.
+*/
+#define LEOGetValueForKeyOfRange(v,k,so,eo,ov,c) ((LEOValuePtr)(v))->base.isa->GetValueForKeyOfRange(((LEOValuePtr)(v)),(k),(so),(eo),(ov),(c))
+
+
+/*!
+ @function LEOSetValueForKeyOfRange
+ Stores a value under the given key in the array in the specified value.
+
+ @param v The value you wish to examine.
+ @param k The key of the array item to fetch.
+ @param s The source value to copy into the array.
+ @param so The start offset of the byte range.
+ @param eo The end offset of the byte range.
+ @param c The context in which your script is currently running and in
+ which errors will be stored.
+*/
+#define LEOSetValueForKeyOfRange(v,k,s,so,eo,c) ((LEOValuePtr)(v))->base.isa->SetValueForKeyOfRange(((LEOValuePtr)(v)),(k),(s),(so),(eo),(c))
+
+
+/*!
@function LEOCleanUpValue
Dispose of any additional storage the value has allocated to hold its data.
If there are references to this value, this will cause the references to fail
@@ -838,7 +870,9 @@ size_t LEOCantGetKeyCount( LEOValuePtr self, struct LEOContext* inContext );
LEOValuePtr LEOCantFollowReferencesAndReturnValueOfType( LEOValuePtr self, LEOValueTypePtr inType, struct LEOContext* inContext );
void LEOCantSetValueAsArray( LEOValuePtr self, struct LEOArrayEntry *inArray, struct LEOContext* inContext );
void LEOSetStringLikeValueAsArray( LEOValuePtr self, struct LEOArrayEntry *inArray, struct LEOContext* inContext );
-void LEOSetStringLikeValueForKey( LEOValuePtr self, const char* keyName, LEOValuePtr inValue, struct LEOContext* inContext );
+void LEOSetStringLikeValueForKey( LEOValuePtr self, const char* keyName, LEOValuePtr inValue, struct LEOContext* inContext );
+void LEOCantGetValueForKeyOfRange( LEOValuePtr self, const char* keyName, size_t startOffset, size_t endOffset, LEOValuePtr outValue, struct LEOContext* inContext );
+void LEOCantSetValueForKeyOfRange( LEOValuePtr self, const char* keyName, LEOValuePtr inValue, size_t startOffset, size_t endOffset, struct LEOContext* inContext );
// Other methods reusable across several types:
void LEOGetAnyValueAsRangeOfString( LEOValuePtr self, LEOChunkType inType,
@@ -956,6 +990,9 @@ void LEOSetReferenceValueValueForKey( LEOValuePtr self, const char* inKey, LEOV
void LEOSetReferenceValueAsArray( LEOValuePtr self, struct LEOArrayEntry * inArray, struct LEOContext * inContext );
size_t LEOGetReferenceValueKeyCount( LEOValuePtr self, struct LEOContext * inContext );
+void LEOGetReferenceValueForKeyOfRange( LEOValuePtr self, const char* keyName, size_t startOffset, size_t endOffset, LEOValuePtr outValue, struct LEOContext* inContext );
+void LEOSetReferenceValueForKeyOfRange( LEOValuePtr self, const char* keyName, LEOValuePtr inValue, size_t startOffset, size_t endOffset, struct LEOContext* inContext );
+
// Variant-specific replacements for certain instance methods:
void LEOSetVariantValueAsNumber( LEOValuePtr self, LEONumber inNumber, struct LEOContext* inContext );
Please sign in to comment.
Something went wrong with that request. Please try again.