diff options
| author | Ganesh Viswanathan <dev@genotrance.com> | 2019-12-20 22:37:02 -0600 |
|---|---|---|
| committer | Ganesh Viswanathan <dev@genotrance.com> | 2019-12-20 22:37:02 -0600 |
| commit | 362b5498b1794aefc91e1d660b8bdb8401f1189f (patch) | |
| tree | 19c1da64e0ebeba8077ec04893983d8aa836e58e | |
| parent | a06081f807e6cbb6922fa022a1a0340b263d7357 (diff) | |
| download | nimterop-issue57.tar.gz nimterop-issue57.zip | |
Fix #57 and #152 - clean ident in expressionsissue57
| -rw-r--r-- | nimterop.nimble | 1 | ||||
| -rw-r--r-- | nimterop/getters.nim | 11 | ||||
| -rw-r--r-- | tests/include/toast.h | 23 |
3 files changed, 32 insertions, 3 deletions
diff --git a/nimterop.nimble b/nimterop.nimble index 6ada463..8802d1b 100644 --- a/nimterop.nimble +++ b/nimterop.nimble @@ -38,6 +38,7 @@ task test, "Test": execTest "tests/tnimterop_c.nim" execCmd "nim cpp -f -r tests/tnimterop_cpp.nim" + execCmd "./nimterop/toast -pnk -E=_ tests/include/toast.h" execTest "tests/tpcre.nim" # Platform specific tests diff --git a/nimterop/getters.nim b/nimterop/getters.nim index 1c5f8aa..af3dfa2 100644 --- a/nimterop/getters.nim +++ b/nimterop/getters.nim @@ -382,24 +382,27 @@ proc getNimExpression*(nimState: NimState, expr: string): string = for i in 0 .. clean.len: if i != clean.len: - if clean[i] == '_' and ident.Bl: - gen = $clean[i] - elif clean[i] in IdentChars: + if clean[i] in IdentChars: if clean[i] in Digits and ident.Bl: + # Identifiers cannot start with digits gen = $clean[i] elif clean[i] in HexDigits and hex == true: + # Part of a hex number gen = $clean[i] elif i > 0 and i < clean.len-1 and clean[i] in ['x', 'X'] and clean[i-1] == '0' and clean[i+1] in HexDigits: + # Found a hex number gen = $clean[i] hex = true else: + # Part of an identifier ident &= clean[i] hex = false else: gen = (block: if (i == 0 or clean[i-1] != '\'') or (i == clean.len - 1 or clean[i+1] != '\''): + # If unquoted, convert logical ops to Nim case clean[i] of '^': " xor " of '&': " and " @@ -412,6 +415,7 @@ proc getNimExpression*(nimState: NimState, expr: string): string = hex = false if i == clean.len or gen.nBl: + # Process identifier if ident.nBl: ident = nimState.getIdentifier(ident, nskConst) result &= ident @@ -419,6 +423,7 @@ proc getNimExpression*(nimState: NimState, expr: string): string = result &= gen gen = "" + # Convert shift ops to Nim result = result.multiReplace([ ("<<", " shl "), (">>", " shr ") ]) diff --git a/tests/include/toast.h b/tests/include/toast.h new file mode 100644 index 0000000..b6b11a8 --- /dev/null +++ b/tests/include/toast.h @@ -0,0 +1,23 @@ +// #57 +enum { + _SG_STRING_SIZE = 16, + _SG_SLOT_SHIFT = 16, + _SG_SLOT_MASK = (1<<_SG_SLOT_SHIFT)-1, + _SG_MAX_POOL_SIZE = (1<<_SG_SLOT_SHIFT), + _SG_DEFAULT_BUFFER_POOL_SIZE = 128, + _SG_DEFAULT_IMAGE_POOL_SIZE = 128, + _SG_DEFAULT_SHADER_POOL_SIZE = 32, + _SG_DEFAULT_PIPELINE_POOL_SIZE = 64, + _SG_DEFAULT_PASS_POOL_SIZE = 16, + _SG_DEFAULT_CONTEXT_POOL_SIZE = 16, + _SG_MTL_DEFAULT_UB_SIZE = 4 * 1024 * 1024, + _SG_MTL_DEFAULT_SAMPLER_CACHE_CAPACITY = 64, +}; + +// #152 +enum { + _ONE, + _TWO, + _MAX = _TWO, + _MORE +}; |
