Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit dfe5297

Browse files
committed
lcb: Integer type improvements
This patch reworks the sized integer types ensuring that all types which may be distinct are truly distinct. In doing so it unifies the naming of all types (S prefix for signed integers, U for unsigned integers), adds all the C integral types, and adds aliases from Int* to SInt*. A particular outcome of this patch is that foreign handlers which bind to Java methods *must* use the J* types and not the C* types as the C types are now considered distinct, and the Java binding code expects the J types (which are just aliases to the machine types since the JNI fixes that mapping).
1 parent 81822df commit dfe5297

File tree

13 files changed

+507
-325
lines changed

13 files changed

+507
-325
lines changed

docs/guides/LiveCode Builder Language Reference.md

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -436,39 +436,40 @@ foreign code.
436436
There are a number of types defined in the foreign module which map to
437437
the appropriate foreign type when used in foreign handler signatures.
438438

439+
There are the standard machine types:
440+
441+
- Bool maps to an 8-bit boolean
442+
- Int8/SInt8 and UInt8 map to 8-bit integers
443+
- Int16/SInt16 and UInt16 map to 16-bit integers
444+
- Int32/SInt32 and UInt32 map to 32-bit integers
445+
- Int64/SInt64 and UInt64 map to 64-bit integers
446+
- IntSize/SIntSize and UIntSize map to the integer size needed to hold a memory size
447+
- IntPtr/SIntPtr and UIntPtr map to the integer size needed to hold a pointer
448+
439449
There are the standard C primitive types:
440450

441451
- CBool maps to 'bool'
442-
- CChar and CUChar map to 'char' and 'unsigned char'
443-
- CShort and CUShort map to 'short' and 'unsigned short'
444-
- CInt and CUInt map to 'int' and 'unsigned int'
445-
- CLong and CULong map to 'long' and 'unsigned long'
446-
- CLongLong and CULongLong map to 'long long' and 'unsigned long long'
452+
- CChar, CSChar and CUChar map to 'char', 'signed char' and 'unsigned char'
453+
- CShort/CSShort and CUShort map to 'signed short' and 'unsigned short'
454+
- CInt/CSInt and CUInt map to 'signed int' and 'unsigned int'
455+
- CLong/CSLong and CULong map to 'signed long' and 'unsigned long'
456+
- CLongLong/CSLongLong and CULongLong map to 'signed long long' and 'unsigned long long'
447457
- CFloat maps to 'float'
448458
- CDouble maps to 'double'
449459

450-
There are the standard sized integer types:
451-
452-
- Int8 and UInt8 map to 8-bit integers
453-
- Int16 and UInt16 map to 16-bit integers
454-
- Int32 and UInt32 map to 32-bit integers
455-
- Int64 and UInt64 map to 64-bit integers
456-
- IntSize and UIntSize map to the integer size needed to hold a memory size
457-
- IntPtr and UIntPtr map to the integer size needed to hold a pointer
458-
459460
There are aliases for the Java primitive types:
460461

461-
- JBoolean maps to CBool
462+
- JBoolean maps to Bool
462463
- JByte maps to Int8
463464
- JShort maps to Int16
464465
- JInt maps to Int32
465466
- JLong maps to Int64
466467

467-
All the primitive types above will implicitly convert between corresponding
468+
All the primitive types above will implicitly bridge between corresponding
468469
high level types:
469470

470-
- CBool converts to and from Boolean
471-
- All integer and real types convert to and from Number
471+
- CBool and Bool bridge to and from Boolean
472+
- All integer and real types bridge to and from Number
472473

473474
Other LCB types pass as follows into foreign handlers:
474475

docs/lcb/notes/feature-sized_ints.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ version: 9.0.0-dp-7
44
# LiveCode Builder Standard Library
55
## Foreign function interface
66

7-
* The foreign sized integer types Int8, UInt8, Int16, UInt16,
8-
Int32, UInt32, Int64 and UInt64 have been added. These all map
9-
to their corresponding foreign counterparts.
7+
* The machine types Bool, SIntSize, UIntSize, SIntPtr, UIntPtr, SInt8, UInt8,
8+
SInt16, UInt16, SInt32, UInt32, SInt64 and UInt64 have been added. These all
9+
map to their corresponding foreign counterparts.
1010

11-
* The C integer types CChar, CUChar, CShort, CUShort, CInt,
12-
CUInt, CLong, CULong, CLongLong and CULongLong have been added.
11+
* The C types CBool, CChar, CSChar, CUChar, CSShort, CUShort, CSInt,
12+
CUInt, CSLong, CULong, CSLongLong and CULongLong have been added.
1313
These all map to their corresponding C counterparts.
1414

1515
* The Java integer primtive types JByte, JShort, JInt, JLong,

libfoundation/include/foundation.h

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,45 +1546,71 @@ MC_DLLEXPORT MCTypeInfoRef MCProperListTypeInfo(void) ATTRIBUTE_PURE;
15461546
MC_DLLEXPORT extern MCTypeInfoRef kMCBoolTypeInfo;
15471547
MC_DLLEXPORT MCTypeInfoRef MCForeignBoolTypeInfo(void) ATTRIBUTE_PURE;
15481548

1549-
MC_DLLEXPORT extern MCTypeInfoRef kMCFloatTypeInfo;
1550-
MC_DLLEXPORT extern MCTypeInfoRef kMCDoubleTypeInfo;
1551-
MC_DLLEXPORT MCTypeInfoRef MCForeignFloatTypeInfo(void) ATTRIBUTE_PURE;
1552-
MC_DLLEXPORT MCTypeInfoRef MCForeignDoubleTypeInfo(void) ATTRIBUTE_PURE;
1553-
1554-
MC_DLLEXPORT extern MCTypeInfoRef kMCPointerTypeInfo;
1555-
MC_DLLEXPORT MCTypeInfoRef MCForeignPointerTypeInfo(void) ATTRIBUTE_PURE;
1556-
15571549
MC_DLLEXPORT extern MCTypeInfoRef kMCUInt8TypeInfo;
1558-
MC_DLLEXPORT extern MCTypeInfoRef kMCInt8TypeInfo;
1550+
MC_DLLEXPORT extern MCTypeInfoRef kMCSInt8TypeInfo;
15591551
MC_DLLEXPORT extern MCTypeInfoRef kMCUInt16TypeInfo;
1560-
MC_DLLEXPORT extern MCTypeInfoRef kMCInt16TypeInfo;
1552+
MC_DLLEXPORT extern MCTypeInfoRef kMCSInt16TypeInfo;
15611553
MC_DLLEXPORT extern MCTypeInfoRef kMCUInt32TypeInfo;
1562-
MC_DLLEXPORT extern MCTypeInfoRef kMCInt32TypeInfo;
1554+
MC_DLLEXPORT extern MCTypeInfoRef kMCSInt32TypeInfo;
15631555
MC_DLLEXPORT extern MCTypeInfoRef kMCUInt64TypeInfo;
1564-
MC_DLLEXPORT extern MCTypeInfoRef kMCInt64TypeInfo;
1556+
MC_DLLEXPORT extern MCTypeInfoRef kMCSInt64TypeInfo;
15651557
MC_DLLEXPORT MCTypeInfoRef MCForeignUInt8TypeInfo(void) ATTRIBUTE_PURE;
1566-
MC_DLLEXPORT MCTypeInfoRef MCForeignInt8TypeInfo(void) ATTRIBUTE_PURE;
1558+
MC_DLLEXPORT MCTypeInfoRef MCForeignSInt8TypeInfo(void) ATTRIBUTE_PURE;
15671559
MC_DLLEXPORT MCTypeInfoRef MCForeignUInt16TypeInfo(void) ATTRIBUTE_PURE;
1568-
MC_DLLEXPORT MCTypeInfoRef MCForeignInt16TypeInfo(void) ATTRIBUTE_PURE;
1560+
MC_DLLEXPORT MCTypeInfoRef MCForeignSInt16TypeInfo(void) ATTRIBUTE_PURE;
15691561
MC_DLLEXPORT MCTypeInfoRef MCForeignUInt32TypeInfo(void) ATTRIBUTE_PURE;
1570-
MC_DLLEXPORT MCTypeInfoRef MCForeignInt32TypeInfo(void) ATTRIBUTE_PURE;
1562+
MC_DLLEXPORT MCTypeInfoRef MCForeignSInt32TypeInfo(void) ATTRIBUTE_PURE;
15711563
MC_DLLEXPORT MCTypeInfoRef MCForeignUInt64TypeInfo(void) ATTRIBUTE_PURE;
1572-
MC_DLLEXPORT MCTypeInfoRef MCForeignInt64TypeInfo(void) ATTRIBUTE_PURE;
1564+
MC_DLLEXPORT MCTypeInfoRef MCForeignSInt64TypeInfo(void) ATTRIBUTE_PURE;
15731565

1574-
MC_DLLEXPORT extern MCTypeInfoRef kMCSizeTypeInfo;
1575-
MC_DLLEXPORT extern MCTypeInfoRef kMCSSizeTypeInfo;
1576-
MC_DLLEXPORT MCTypeInfoRef MCForeignSizeTypeInfo(void) ATTRIBUTE_PURE;
1577-
MC_DLLEXPORT MCTypeInfoRef MCForeignSSizeTypeInfo(void) ATTRIBUTE_PURE;
1566+
MC_DLLEXPORT extern MCTypeInfoRef kMCFloatTypeInfo;
1567+
MC_DLLEXPORT extern MCTypeInfoRef kMCDoubleTypeInfo;
1568+
MC_DLLEXPORT MCTypeInfoRef MCForeignFloatTypeInfo(void) ATTRIBUTE_PURE;
1569+
MC_DLLEXPORT MCTypeInfoRef MCForeignDoubleTypeInfo(void) ATTRIBUTE_PURE;
1570+
1571+
MC_DLLEXPORT extern MCTypeInfoRef kMCPointerTypeInfo;
1572+
MC_DLLEXPORT MCTypeInfoRef MCForeignPointerTypeInfo(void) ATTRIBUTE_PURE;
15781573

1574+
MC_DLLEXPORT extern MCTypeInfoRef kMCUIntSizeTypeInfo;
1575+
MC_DLLEXPORT extern MCTypeInfoRef kMCSIntSizeTypeInfo;
1576+
MC_DLLEXPORT MCTypeInfoRef MCForeignUIntSizeTypeInfo(void) ATTRIBUTE_PURE;
1577+
MC_DLLEXPORT MCTypeInfoRef MCForeignSIntSizeTypeInfo(void) ATTRIBUTE_PURE;
1578+
1579+
MC_DLLEXPORT extern MCTypeInfoRef kMCUIntPtrTypeInfo;
1580+
MC_DLLEXPORT extern MCTypeInfoRef kMCSIntPtrTypeInfo;
1581+
MC_DLLEXPORT MCTypeInfoRef MCForeignUIntPtrTypeInfo(void) ATTRIBUTE_PURE;
1582+
MC_DLLEXPORT MCTypeInfoRef MCForeignSIntPtrTypeInfo(void) ATTRIBUTE_PURE;
1583+
1584+
MC_DLLEXPORT extern MCTypeInfoRef kMCCBoolTypeInfo;
1585+
MC_DLLEXPORT MCTypeInfoRef MCForeignCBoolTypeInfo(void) ATTRIBUTE_PURE;
1586+
1587+
MC_DLLEXPORT extern MCTypeInfoRef kMCCCharTypeInfo;
1588+
MC_DLLEXPORT extern MCTypeInfoRef kMCCUCharTypeInfo;
1589+
MC_DLLEXPORT extern MCTypeInfoRef kMCCSCharTypeInfo;
1590+
MC_DLLEXPORT extern MCTypeInfoRef kMCCUShortTypeInfo;
1591+
MC_DLLEXPORT extern MCTypeInfoRef kMCCSShortTypeInfo;
1592+
MC_DLLEXPORT extern MCTypeInfoRef kMCCUIntTypeInfo;
1593+
MC_DLLEXPORT extern MCTypeInfoRef kMCCSIntTypeInfo;
15791594
MC_DLLEXPORT extern MCTypeInfoRef kMCCULongTypeInfo;
1580-
MC_DLLEXPORT extern MCTypeInfoRef kMCCLongTypeInfo;
1595+
MC_DLLEXPORT extern MCTypeInfoRef kMCCSLongTypeInfo;
1596+
MC_DLLEXPORT extern MCTypeInfoRef kMCCULongLongTypeInfo;
1597+
MC_DLLEXPORT extern MCTypeInfoRef kMCCSLongLongTypeInfo;
1598+
MC_DLLEXPORT MCTypeInfoRef MCForeignCCharTypeInfo(void) ATTRIBUTE_PURE;
1599+
MC_DLLEXPORT MCTypeInfoRef MCForeignCUCharTypeInfo(void) ATTRIBUTE_PURE;
1600+
MC_DLLEXPORT MCTypeInfoRef MCForeignCSCharTypeInfo(void) ATTRIBUTE_PURE;
1601+
MC_DLLEXPORT MCTypeInfoRef MCForeignCUShortTypeInfo(void) ATTRIBUTE_PURE;
1602+
MC_DLLEXPORT MCTypeInfoRef MCForeignCSShortTypeInfo(void) ATTRIBUTE_PURE;
1603+
MC_DLLEXPORT MCTypeInfoRef MCForeignCUIntTypeInfo(void) ATTRIBUTE_PURE;
1604+
MC_DLLEXPORT MCTypeInfoRef MCForeignCSIntTypeInfo(void) ATTRIBUTE_PURE;
15811605
MC_DLLEXPORT MCTypeInfoRef MCForeignCULongTypeInfo(void) ATTRIBUTE_PURE;
1582-
MC_DLLEXPORT MCTypeInfoRef MCForeignCLongTypeInfo(void) ATTRIBUTE_PURE;
1606+
MC_DLLEXPORT MCTypeInfoRef MCForeignCSLongTypeInfo(void) ATTRIBUTE_PURE;
1607+
MC_DLLEXPORT MCTypeInfoRef MCForeignCULongLongTypeInfo(void) ATTRIBUTE_PURE;
1608+
MC_DLLEXPORT MCTypeInfoRef MCForeignCSLongLongTypeInfo(void) ATTRIBUTE_PURE;
15831609

15841610
MC_DLLEXPORT extern MCTypeInfoRef kMCUIntTypeInfo;
1585-
MC_DLLEXPORT extern MCTypeInfoRef kMCIntTypeInfo;
1611+
MC_DLLEXPORT extern MCTypeInfoRef kMCSIntTypeInfo;
15861612
MC_DLLEXPORT MCTypeInfoRef MCForeignUIntTypeInfo(void) ATTRIBUTE_PURE;
1587-
MC_DLLEXPORT MCTypeInfoRef MCForeignIntTypeInfo(void) ATTRIBUTE_PURE;
1613+
MC_DLLEXPORT MCTypeInfoRef MCForeignSIntTypeInfo(void) ATTRIBUTE_PURE;
15881614

15891615
//////////
15901616

0 commit comments

Comments
 (0)