Skip to content

Commit

Permalink
Replace BigInt object with {iu}128 (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
graydon authored Nov 20, 2022
1 parent 1a76201 commit 4a5b250
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 25 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ name: CI

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
# Triggers the workflow on push or pull request events for main, curr or next.
push:
branches: [ "main" ]
branches: [ "main", "curr", "next" ]
pull_request:
branches: [ "main" ]
branches: [ "main", "curr", "next" ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand Down
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 4a5b250

Please sign in to comment.