-
Notifications
You must be signed in to change notification settings - Fork 21
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
Replace ScObject with ScOption. Unify everything under ScVal. #64
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,11 +33,7 @@ namespace stellar | |
* Up here in XDR we have variable-length tagged disjoint unions but no | ||
* bit-level packing, so we can be more explicit in their structure, at the | ||
* cost of spending more than 64 bits to encode many cases, and also having | ||
* to convert. It's a little non-obvious at the XDR level why there's a | ||
* split between SCVal and SCObject given that they are both immutable types | ||
* with value semantics; but the split reflects the split that happens in | ||
* the implementation, and marks a place where different implementations of | ||
* immutability (CoW, structural sharing, etc.) will likely occur. | ||
* to convert. | ||
*/ | ||
|
||
// A symbol is up to 10 chars drawn from [a-zA-Z0-9_], which can be packed | ||
|
@@ -48,17 +44,28 @@ typedef string SCSymbol<10>; | |
|
||
enum SCValType | ||
{ | ||
SCV_U63 = 0, | ||
SCV_U32 = 1, | ||
SCV_I32 = 2, | ||
SCV_STATIC = 3, | ||
SCV_OBJECT = 4, | ||
SCV_SYMBOL = 5, | ||
SCV_BITSET = 6, | ||
SCV_STATUS = 7 | ||
}; | ||
// Numbers | ||
SCV_U32 = 0, | ||
SCV_I32 = 1, | ||
SCV_U64 = 2, | ||
SCV_I64 = 3, | ||
SCV_U128 = 4, | ||
SCV_I128 = 5, | ||
|
||
// Other Primitives | ||
SCV_STATIC = 100, | ||
SCV_SYMBOL = 101, | ||
SCV_BITSET = 102, | ||
SCV_STATUS = 103, | ||
SCV_BYTES = 104, | ||
SCV_ACCOUNT_ID = 105, | ||
|
||
% struct SCObject; | ||
// Containers | ||
SCV_VEC = 1000, | ||
SCV_MAP = 1001, | ||
SCV_OPTION = 1002, | ||
SCV_CONTRACT_CODE = 1003 | ||
}; | ||
|
||
enum SCStatic | ||
{ | ||
|
@@ -186,40 +193,38 @@ case SST_CONTRACT_ERROR: | |
|
||
union SCVal switch (SCValType type) | ||
{ | ||
case SCV_U63: | ||
int64 u63; | ||
case SCV_U32: | ||
uint32 u32; | ||
case SCV_I32: | ||
int32 i32; | ||
case SCV_U64: | ||
uint64 u64; | ||
case SCV_I64: | ||
int64 i64; | ||
case SCV_U128: | ||
Int128Parts u128; | ||
case SCV_I128: | ||
Int128Parts i128; | ||
case SCV_STATIC: | ||
SCStatic ic; | ||
case SCV_OBJECT: | ||
SCObject* obj; | ||
case SCV_SYMBOL: | ||
SCSymbol sym; | ||
case SCV_BITSET: | ||
uint64 bits; | ||
case SCV_STATUS: | ||
SCStatus status; | ||
}; | ||
|
||
enum SCObjectType | ||
{ | ||
// We have a few objects that represent non-stellar-specific concepts | ||
// like general-purpose maps, vectors, numbers, blobs. | ||
|
||
SCO_VEC = 0, | ||
SCO_MAP = 1, | ||
SCO_U64 = 2, | ||
SCO_I64 = 3, | ||
SCO_U128 = 4, | ||
SCO_I128 = 5, | ||
SCO_BYTES = 6, | ||
SCO_CONTRACT_CODE = 7, | ||
SCO_ACCOUNT_ID = 8 | ||
|
||
// TODO: add more | ||
case SCV_BYTES: | ||
opaque bin<SCVAL_LIMIT>; | ||
case SCV_ACCOUNT_ID: | ||
AccountID accountID; | ||
case SCV_VEC: | ||
SCVec vec; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SCVec and SCMap being recursive types here have to be SCVec* amd SCMap* |
||
case SCV_MAP: | ||
SCMap map; | ||
case SCV_OPTION: | ||
SCOption obj; | ||
case SCV_CONTRACT_CODE: | ||
SCContractCode contractCode; | ||
}; | ||
|
||
struct SCMapEntry | ||
|
@@ -232,6 +237,7 @@ const SCVAL_LIMIT = 256000; | |
|
||
typedef SCVal SCVec<SCVAL_LIMIT>; | ||
typedef SCMapEntry SCMap<SCVAL_LIMIT>; | ||
typedef *SCVal SCOption; | ||
|
||
enum SCContractCodeType | ||
{ | ||
|
@@ -254,26 +260,3 @@ struct Int128Parts { | |
uint64 lo; | ||
uint64 hi; | ||
}; | ||
|
||
union SCObject switch (SCObjectType type) | ||
{ | ||
case SCO_VEC: | ||
SCVec vec; | ||
case SCO_MAP: | ||
SCMap map; | ||
case SCO_U64: | ||
uint64 u64; | ||
case SCO_I64: | ||
int64 i64; | ||
case SCO_U128: | ||
Int128Parts u128; | ||
case SCO_I128: | ||
Int128Parts i128; | ||
case SCO_BYTES: | ||
opaque bin<SCVAL_LIMIT>; | ||
case SCO_CONTRACT_CODE: | ||
SCContractCode contractCode; | ||
case SCO_ACCOUNT_ID: | ||
AccountID accountID; | ||
}; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spacing out numbers like this isn't ideal. We reuse these numbers as object code tags which means they get encoded into the instruction stream as literals. Bigger numbers => larger codesize.