Skip to content

Commit

Permalink
Replace BigInt object with {iu}128
Browse files Browse the repository at this point in the history
  • Loading branch information
graydon committed Nov 20, 2022
1 parent 1a76201 commit 2a76ef8
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions Stellar-contract.x
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,11 @@ enum SCObjectType
SCO_MAP = 1,
SCO_U64 = 2,
SCO_I64 = 3,
SCO_BYTES = 4,
SCO_BIG_INT = 5,
SCO_CONTRACT_CODE = 6,
SCO_ACCOUNT_ID = 7
SCO_U128 = 4,
SCO_I128 = 5,
SCO_BYTES = 6,
SCO_CONTRACT_CODE = 7,
SCO_ACCOUNT_ID = 8

// TODO: add more
};
Expand All @@ -232,22 +233,6 @@ const SCVAL_LIMIT = 256000;
typedef SCVal SCVec<SCVAL_LIMIT>;
typedef SCMapEntry SCMap<SCVAL_LIMIT>;

enum SCNumSign
{
NEGATIVE = -1,
ZERO = 0,
POSITIVE = 1
};

union SCBigInt switch (SCNumSign sign)
{
case ZERO:
void;
case POSITIVE:
case NEGATIVE:
opaque magnitude<256000>;
};

enum SCContractCodeType
{
SCCONTRACT_CODE_WASM_REF = 0,
Expand All @@ -262,6 +247,14 @@ case SCCONTRACT_CODE_TOKEN:
void;
};

struct Int128Parts {
// Both signed and unsigned 128-bit ints
// are transported in a pair of uint64s
// to reduce the risk of sign-extension.
uint64 lo;
uint64 hi;
};

union SCObject switch (SCObjectType type)
{
case SCO_VEC:
Expand All @@ -272,10 +265,12 @@ 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_BIG_INT:
SCBigInt bigInt;
case SCO_CONTRACT_CODE:
SCContractCode contractCode;
case SCO_ACCOUNT_ID:
Expand Down

0 comments on commit 2a76ef8

Please sign in to comment.