Fix #57 and #152 - clean ident in expressions

This commit is contained in:
Ganesh Viswanathan 2019-12-20 22:37:02 -06:00
commit 362b5498b1
3 changed files with 32 additions and 3 deletions

View file

@ -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

View file

@ -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 ")
])

23
tests/include/toast.h Normal file
View file

@ -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
};