mirror of
https://github.com/carp-lang/Carp.git
synced 2024-10-26 05:45:37 +03:00
all: various long fixes
This commit is contained in:
parent
c0ba8c723a
commit
30ed0ae8c3
@ -10,9 +10,9 @@ uint32_t Binary_to_MINUS_int32(uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4) {
|
|||||||
|
|
||||||
uint64_t Binary_to_MINUS_int64(uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4,
|
uint64_t Binary_to_MINUS_int64(uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4,
|
||||||
uint8_t b5, uint8_t b6, uint8_t b7, uint8_t b8) {
|
uint8_t b5, uint8_t b6, uint8_t b7, uint8_t b8) {
|
||||||
return (uint64_t)b1 | ((uint64_t)b2 << 8) | ((uint64_t)b3 << 16) | ((uint64_t)b4 << 24) |
|
return (uint64_t)b1 | ((uint64_t)b2 << 8) | ((uint64_t)b3 << 16) |
|
||||||
((uint64_t)b5 << 32) | ((uint64_t)b6 << 40) | ((uint64_t)b7 << 48) |
|
((uint64_t)b4 << 24) | ((uint64_t)b5 << 32) | ((uint64_t)b6 << 40) |
|
||||||
((uint64_t)b8 << 56);
|
((uint64_t)b7 << 48) | ((uint64_t)b8 << 56);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t Binary_int16_MINUS_to_MINUS_byte(uint16_t *x) {
|
uint8_t Binary_int16_MINUS_to_MINUS_byte(uint16_t *x) {
|
||||||
|
@ -10,17 +10,15 @@ Long Long__MUL_(Long x, Long y) {
|
|||||||
Long Long__DIV_(Long x, Long y) {
|
Long Long__DIV_(Long x, Long y) {
|
||||||
return x / y;
|
return x / y;
|
||||||
}
|
}
|
||||||
#ifndef _WIN32
|
|
||||||
bool Long_safe_MINUS_add(Long x, Long y, Long* res) {
|
bool Long_safe_MINUS_add(Long x, Long y, Long* res) {
|
||||||
return __builtin_saddll_overflow(x, y, res);
|
return __builtin_add_overflow(x, y, res);
|
||||||
}
|
}
|
||||||
bool Long_safe_MINUS_sub(Long x, Long y, Long* res) {
|
bool Long_safe_MINUS_sub(Long x, Long y, Long* res) {
|
||||||
return __builtin_ssubll_overflow(x, y, res);
|
return __builtin_sub_overflow(x, y, res);
|
||||||
}
|
}
|
||||||
bool Long_safe_MINUS_mul(Long x, Long y, Long* res) {
|
bool Long_safe_MINUS_mul(Long x, Long y, Long* res) {
|
||||||
return __builtin_smulll_overflow(x, y, res);
|
return __builtin_mul_overflow(x, y, res);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
bool Long__EQ_(Long x, Long y) {
|
bool Long__EQ_(Long x, Long y) {
|
||||||
return x == y;
|
return x == y;
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ bool log_memory_balance = false;
|
|||||||
void *logged_malloc(size_t size) {
|
void *logged_malloc(size_t size) {
|
||||||
void *ptr = malloc(size);
|
void *ptr = malloc(size);
|
||||||
if (log_memory_balance) {
|
if (log_memory_balance) {
|
||||||
printf("MALLOC: %p (%ld bytes)\n", ptr, size);
|
printf("MALLOC: %p (%zu bytes)\n", ptr, size);
|
||||||
}
|
}
|
||||||
malloc_balance_counter++;
|
malloc_balance_counter++;
|
||||||
return ptr;
|
return ptr;
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
bool Int_safe_MINUS_add(int x, int y, int* res) {
|
bool Int_safe_MINUS_add(int x, int y, int* res) {
|
||||||
return __builtin_sadd_overflow(x, y, res);
|
return __builtin_add_overflow(x, y, res);
|
||||||
}
|
}
|
||||||
bool Int_safe_MINUS_sub(int x, int y, int* res) {
|
bool Int_safe_MINUS_sub(int x, int y, int* res) {
|
||||||
return __builtin_ssub_overflow(x, y, res);
|
return __builtin_sub_overflow(x, y, res);
|
||||||
}
|
}
|
||||||
bool Int_safe_MINUS_mul(int x, int y, int* res) {
|
bool Int_safe_MINUS_mul(int x, int y, int* res) {
|
||||||
return __builtin_smul_overflow(x, y, res);
|
return __builtin_mul_overflow(x, y, res);
|
||||||
}
|
}
|
||||||
|
@ -52,10 +52,10 @@ String Uint8_str(Uint8 x) {
|
|||||||
snprintf(buffer, size, "Uint8(%" PRIu8 ")", x);
|
snprintf(buffer, size, "Uint8(%" PRIu8 ")", x);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
Uint8 Uint8_from_MINUS_long(long x) {
|
Uint8 Uint8_from_MINUS_long(Long x) {
|
||||||
return (Uint8)x;
|
return (Uint8)x;
|
||||||
}
|
}
|
||||||
long Uint8_to_MINUS_long(Uint8 x) {
|
Long Uint8_to_MINUS_long(Uint8 x) {
|
||||||
return (long)x;
|
return (long)x;
|
||||||
}
|
}
|
||||||
Uint8 Uint8_copy(Uint8* x) {
|
Uint8 Uint8_copy(Uint8* x) {
|
||||||
@ -119,10 +119,10 @@ String Uint16_str(Uint16 x) {
|
|||||||
snprintf(buffer, size, "Uint16(%" PRIu16 ")", x);
|
snprintf(buffer, size, "Uint16(%" PRIu16 ")", x);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
Uint16 Uint16_from_MINUS_long(long x) {
|
Uint16 Uint16_from_MINUS_long(Long x) {
|
||||||
return (Uint16)x;
|
return (Uint16)x;
|
||||||
}
|
}
|
||||||
long Uint16_to_MINUS_long(Uint16 x) {
|
Long Uint16_to_MINUS_long(Uint16 x) {
|
||||||
return (long)x;
|
return (long)x;
|
||||||
}
|
}
|
||||||
Uint16 Uint16_copy(Uint16* x) {
|
Uint16 Uint16_copy(Uint16* x) {
|
||||||
@ -186,10 +186,10 @@ String Uint32_str(Uint32 x) {
|
|||||||
snprintf(buffer, size, "Uint32(%" PRIu32 ")", x);
|
snprintf(buffer, size, "Uint32(%" PRIu32 ")", x);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
Uint32 Uint32_from_MINUS_long(long x) {
|
Uint32 Uint32_from_MINUS_long(Long x) {
|
||||||
return (Uint32)x;
|
return (Uint32)x;
|
||||||
}
|
}
|
||||||
long Uint32_to_MINUS_long(Uint32 x) {
|
Long Uint32_to_MINUS_long(Uint32 x) {
|
||||||
return (long)x;
|
return (long)x;
|
||||||
}
|
}
|
||||||
Uint32 Uint32_copy(Uint32* x) {
|
Uint32 Uint32_copy(Uint32* x) {
|
||||||
@ -253,10 +253,10 @@ String Uint64_str(Uint64 x) {
|
|||||||
snprintf(buffer, size, "Uint64(%" PRIu64 ")", x);
|
snprintf(buffer, size, "Uint64(%" PRIu64 ")", x);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
Uint64 Uint64_from_MINUS_long(long x) {
|
Uint64 Uint64_from_MINUS_long(Long x) {
|
||||||
return (Uint64)x;
|
return (Uint64)x;
|
||||||
}
|
}
|
||||||
long Uint64_to_MINUS_long(Uint64 x) {
|
Long Uint64_to_MINUS_long(Uint64 x) {
|
||||||
return (long)x;
|
return (long)x;
|
||||||
}
|
}
|
||||||
Uint64 Uint64_copy(Uint64* x) {
|
Uint64 Uint64_copy(Uint64* x) {
|
||||||
@ -320,10 +320,10 @@ String Int8_str(Int8 x) {
|
|||||||
snprintf(buffer, size, "Int8(%" PRId8 ")", x);
|
snprintf(buffer, size, "Int8(%" PRId8 ")", x);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
Int8 Int8_from_MINUS_long(long x) {
|
Int8 Int8_from_MINUS_long(Long x) {
|
||||||
return (Int8)x;
|
return (Int8)x;
|
||||||
}
|
}
|
||||||
long Int8_to_MINUS_long(Int8 x) {
|
Long Int8_to_MINUS_long(Int8 x) {
|
||||||
return (long)x;
|
return (long)x;
|
||||||
}
|
}
|
||||||
Int8 Int8_copy(Int8* x) {
|
Int8 Int8_copy(Int8* x) {
|
||||||
@ -387,10 +387,10 @@ String Int16_str(Int16 x) {
|
|||||||
snprintf(buffer, size, "Int16(%" PRId16 ")", x);
|
snprintf(buffer, size, "Int16(%" PRId16 ")", x);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
Int16 Int16_from_MINUS_long(long x) {
|
Int16 Int16_from_MINUS_long(Long x) {
|
||||||
return (Int16)x;
|
return (Int16)x;
|
||||||
}
|
}
|
||||||
long Int16_to_MINUS_long(Int16 x) {
|
Long Int16_to_MINUS_long(Int16 x) {
|
||||||
return (long)x;
|
return (long)x;
|
||||||
}
|
}
|
||||||
Int16 Int16_copy(Int16* x) {
|
Int16 Int16_copy(Int16* x) {
|
||||||
@ -454,10 +454,10 @@ String Int32_str(Int32 x) {
|
|||||||
snprintf(buffer, size, "Int32(%" PRId32 ")", x);
|
snprintf(buffer, size, "Int32(%" PRId32 ")", x);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
Int32 Int32_from_MINUS_long(long x) {
|
Int32 Int32_from_MINUS_long(Long x) {
|
||||||
return (Int32)x;
|
return (Int32)x;
|
||||||
}
|
}
|
||||||
long Int32_to_MINUS_long(Int32 x) {
|
Long Int32_to_MINUS_long(Int32 x) {
|
||||||
return (long)x;
|
return (long)x;
|
||||||
}
|
}
|
||||||
Int32 Int32_copy(Int32* x) {
|
Int32 Int32_copy(Int32* x) {
|
||||||
@ -521,11 +521,11 @@ String Int64_str(Int64 x) {
|
|||||||
snprintf(buffer, size, "Int64(%" PRId64 ")", x);
|
snprintf(buffer, size, "Int64(%" PRId64 ")", x);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
Int64 Int64_from_MINUS_long(long x) {
|
Int64 Int64_from_MINUS_long(Long x) {
|
||||||
return (Int64)x;
|
return (Int64)x;
|
||||||
}
|
}
|
||||||
long Int64_to_MINUS_long(Int64 x) {
|
Long Int64_to_MINUS_long(Int64 x) {
|
||||||
return (long)x;
|
return (Long)x;
|
||||||
}
|
}
|
||||||
Int64 Int64_copy(Int64* x) {
|
Int64 Int64_copy(Int64* x) {
|
||||||
return *x;
|
return *x;
|
||||||
|
@ -17,13 +17,7 @@ typedef int64_t Long;
|
|||||||
#define CHK_INDEX(i, n)
|
#define CHK_INDEX(i, n)
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#if defined(WIN32) || defined(_WIN32) || \
|
|
||||||
defined(__WIN32) && !defined(__CYGWIN__)
|
|
||||||
// The %zd format flag doesn't seem to work on Windows?
|
|
||||||
#define CHK_INDEX_FORMAT_STRING ":%u: bad index: %ld < %ld\n"
|
|
||||||
#else
|
|
||||||
#define CHK_INDEX_FORMAT_STRING ":%u: bad index: %zd < %zd\n"
|
#define CHK_INDEX_FORMAT_STRING ":%u: bad index: %zd < %zd\n"
|
||||||
#endif
|
|
||||||
|
|
||||||
#define CHK_INDEX(i, n) \
|
#define CHK_INDEX(i, n) \
|
||||||
do { \
|
do { \
|
||||||
|
@ -32,7 +32,6 @@ exitOnError { stack exec carp "--" ./examples/check_malloc.carp -b }
|
|||||||
|
|
||||||
# Generate docs
|
# Generate docs
|
||||||
exitOnError { stack exec carp "--" ./docs/core/generate_core_docs.carp }
|
exitOnError { stack exec carp "--" ./docs/core/generate_core_docs.carp }
|
||||||
exitOnError { stack exec carp "--" ./docs/sdl/generate_sdl_docs.carp }
|
|
||||||
|
|
||||||
echo "ALL TESTS DONE."
|
echo "ALL TESTS DONE."
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ templatePointerAdd = defineTemplate
|
|||||||
(SymPath ["Pointer"] "add")
|
(SymPath ["Pointer"] "add")
|
||||||
(FuncTy [PointerTy (VarTy "p"), LongTy] (PointerTy (VarTy "p")) StaticLifetimeTy)
|
(FuncTy [PointerTy (VarTy "p"), LongTy] (PointerTy (VarTy "p")) StaticLifetimeTy)
|
||||||
"adds a long integer value to a pointer."
|
"adds a long integer value to a pointer."
|
||||||
(toTemplate "$p* $NAME ($p *p, long x)")
|
(toTemplate "$p* $NAME ($p *p, Long x)")
|
||||||
(toTemplate $ unlines ["$DECL {"
|
(toTemplate $ unlines ["$DECL {"
|
||||||
," return p + x;"
|
," return p + x;"
|
||||||
,"}"])
|
,"}"])
|
||||||
@ -123,7 +123,7 @@ templatePointerSub = defineTemplate
|
|||||||
(SymPath ["Pointer"] "sub")
|
(SymPath ["Pointer"] "sub")
|
||||||
(FuncTy [PointerTy (VarTy "p"), LongTy] (PointerTy (VarTy "p")) StaticLifetimeTy)
|
(FuncTy [PointerTy (VarTy "p"), LongTy] (PointerTy (VarTy "p")) StaticLifetimeTy)
|
||||||
"subtracts a long integer value from a pointer."
|
"subtracts a long integer value from a pointer."
|
||||||
(toTemplate "$p* $NAME ($p *p, long x)")
|
(toTemplate "$p* $NAME ($p *p, Long x)")
|
||||||
(toTemplate $ unlines ["$DECL {"
|
(toTemplate $ unlines ["$DECL {"
|
||||||
," return p - x;"
|
," return p - x;"
|
||||||
,"}"])
|
,"}"])
|
||||||
@ -133,7 +133,7 @@ templatePointerWidth = defineTemplate
|
|||||||
(SymPath ["Pointer"] "width")
|
(SymPath ["Pointer"] "width")
|
||||||
(FuncTy [PointerTy (VarTy "p")] LongTy StaticLifetimeTy)
|
(FuncTy [PointerTy (VarTy "p")] LongTy StaticLifetimeTy)
|
||||||
"gets the byte size of a pointer."
|
"gets the byte size of a pointer."
|
||||||
(toTemplate "long $NAME ($p *p)")
|
(toTemplate "Long $NAME ($p *p)")
|
||||||
(toTemplate $ unlines ["$DECL {"
|
(toTemplate $ unlines ["$DECL {"
|
||||||
," return sizeof(*p);"
|
," return sizeof(*p);"
|
||||||
,"}"])
|
,"}"])
|
||||||
@ -143,9 +143,9 @@ templatePointerToLong = defineTemplate
|
|||||||
(SymPath ["Pointer"] "to-long")
|
(SymPath ["Pointer"] "to-long")
|
||||||
(FuncTy [PointerTy (VarTy "p")] LongTy StaticLifetimeTy)
|
(FuncTy [PointerTy (VarTy "p")] LongTy StaticLifetimeTy)
|
||||||
"converts a pointer to a long integer."
|
"converts a pointer to a long integer."
|
||||||
(toTemplate "long $NAME ($p *p)")
|
(toTemplate "Long $NAME ($p *p)")
|
||||||
(toTemplate $ unlines ["$DECL {"
|
(toTemplate $ unlines ["$DECL {"
|
||||||
," return (long)p;"
|
," return (Long)p;"
|
||||||
,"}"])
|
,"}"])
|
||||||
(const [])
|
(const [])
|
||||||
|
|
||||||
@ -153,7 +153,7 @@ templatePointerFromLong = defineTemplate
|
|||||||
(SymPath ["Pointer"] "from-long")
|
(SymPath ["Pointer"] "from-long")
|
||||||
(FuncTy [LongTy] (PointerTy (VarTy "p")) StaticLifetimeTy)
|
(FuncTy [LongTy] (PointerTy (VarTy "p")) StaticLifetimeTy)
|
||||||
"converts a long integer to a pointer."
|
"converts a long integer to a pointer."
|
||||||
(toTemplate "$p* $NAME (long p)")
|
(toTemplate "$p* $NAME (Long p)")
|
||||||
(toTemplate $ unlines ["$DECL {"
|
(toTemplate $ unlines ["$DECL {"
|
||||||
," return ($p*)p;"
|
," return ($p*)p;"
|
||||||
,"}"])
|
,"}"])
|
||||||
|
Loading…
Reference in New Issue
Block a user