mirror of
https://github.com/carp-lang/Carp.git
synced 2024-10-05 17:47:30 +03:00
Long type to ensure longs are actually 64 bits.
This commit is contained in:
parent
ad1539a4dd
commit
a6055eec5f
@ -38,8 +38,8 @@ double Double_from_MINUS_int(int x) {
|
||||
return (double)x;
|
||||
}
|
||||
|
||||
long Double_to_MINUS_bytes(double x) {
|
||||
long y;
|
||||
Long Double_to_MINUS_bytes(double x) {
|
||||
Long y;
|
||||
memcpy(&y, &x, sizeof(double));
|
||||
return y;
|
||||
}
|
||||
@ -52,11 +52,11 @@ double Double_from_MINUS_float(float x) {
|
||||
return (double)x;
|
||||
}
|
||||
|
||||
long Double_to_MINUS_long(double x) {
|
||||
return (long)x;
|
||||
Long Double_to_MINUS_long(double x) {
|
||||
return (Long)x;
|
||||
}
|
||||
|
||||
double Double_from_MINUS_long(long x) {
|
||||
double Double_from_MINUS_long(Long x) {
|
||||
return (double)x;
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ String IO_get_MINUS_line() {
|
||||
|
||||
String IO_read_MINUS_file(const String *filename) {
|
||||
String buffer = 0;
|
||||
long length;
|
||||
Long length;
|
||||
FILE *f = fopen(*filename, "rb");
|
||||
|
||||
if (f) {
|
||||
|
@ -1,87 +1,87 @@
|
||||
long Long__PLUS_(long x, long y) {
|
||||
Long Long__PLUS_(Long x, Long y) {
|
||||
return x + y;
|
||||
}
|
||||
long Long__MINUS_(long x, long y) {
|
||||
Long Long__MINUS_(Long x, Long y) {
|
||||
return x - y;
|
||||
}
|
||||
long Long__MUL_(long x, long y) {
|
||||
Long Long__MUL_(Long x, Long y) {
|
||||
return x * y;
|
||||
}
|
||||
long Long__DIV_(long x, long y) {
|
||||
Long Long__DIV_(Long x, Long y) {
|
||||
return x / y;
|
||||
}
|
||||
#ifndef _WIN32
|
||||
bool Long_safe_MINUS_add(long x, long y, long* res) {
|
||||
return __builtin_saddl_overflow(x, y, res);
|
||||
bool Long_safe_MINUS_add(Long x, Long y, Long* res) {
|
||||
return __builtin_saddll_overflow(x, y, res);
|
||||
}
|
||||
bool Long_safe_MINUS_sub(long x, long y, long* res) {
|
||||
return __builtin_ssubl_overflow(x, y, res);
|
||||
bool Long_safe_MINUS_sub(Long x, Long y, Long* res) {
|
||||
return __builtin_ssubll_overflow(x, y, res);
|
||||
}
|
||||
bool Long_safe_MINUS_mul(long x, long y, long* res) {
|
||||
return __builtin_smull_overflow(x, y, res);
|
||||
bool Long_safe_MINUS_mul(Long x, Long y, Long* res) {
|
||||
return __builtin_smulll_overflow(x, y, res);
|
||||
}
|
||||
#endif
|
||||
bool Long__EQ_(long x, long y) {
|
||||
bool Long__EQ_(Long x, Long y) {
|
||||
return x == y;
|
||||
}
|
||||
bool Long__LT_(long x, long y) {
|
||||
bool Long__LT_(Long x, Long y) {
|
||||
return x < y;
|
||||
}
|
||||
bool Long__GT_(long x, long y) {
|
||||
bool Long__GT_(Long x, Long y) {
|
||||
return x > y;
|
||||
}
|
||||
long Long_neg(long x) {
|
||||
Long Long_neg(Long x) {
|
||||
return -x;
|
||||
}
|
||||
|
||||
long Long_inc(long x) {
|
||||
Long Long_inc(Long x) {
|
||||
return x + 1;
|
||||
}
|
||||
long Long_dec(long x) {
|
||||
Long Long_dec(Long x) {
|
||||
return x - 1;
|
||||
}
|
||||
long Long_abs(long x) {
|
||||
Long Long_abs(Long x) {
|
||||
return x > 0 ? x : -x;
|
||||
}
|
||||
long Long_bit_MINUS_shift_MINUS_left(long x, long y) {
|
||||
Long Long_bit_MINUS_shift_MINUS_left(Long x, Long y) {
|
||||
return x << y;
|
||||
}
|
||||
long Long_bit_MINUS_shift_MINUS_right(long x, long y) {
|
||||
Long Long_bit_MINUS_shift_MINUS_right(Long x, Long y) {
|
||||
return x >> y;
|
||||
}
|
||||
long Long_bit_MINUS_and(long x, long y) {
|
||||
Long Long_bit_MINUS_and(Long x, Long y) {
|
||||
return x & y;
|
||||
}
|
||||
long Long_bit_MINUS_or(long x, long y) {
|
||||
Long Long_bit_MINUS_or(Long x, Long y) {
|
||||
return x | y;
|
||||
}
|
||||
long Long_bit_MINUS_xor(long x, long y) {
|
||||
Long Long_bit_MINUS_xor(Long x, Long y) {
|
||||
return x ^ y;
|
||||
}
|
||||
long Long_bit_MINUS_not(long x) {
|
||||
Long Long_bit_MINUS_not(Long x) {
|
||||
return ~x;
|
||||
}
|
||||
|
||||
long Long_copy(const long* x) {
|
||||
Long Long_copy(const Long* x) {
|
||||
return *x;
|
||||
}
|
||||
|
||||
long Long_mod(long x, long divider) {
|
||||
Long Long_mod(Long x, Long divider) {
|
||||
return x % divider;
|
||||
}
|
||||
|
||||
void Long_seed(long seed) {
|
||||
void Long_seed(Long seed) {
|
||||
srand(seed);
|
||||
}
|
||||
|
||||
bool Long_mask(long a, long b) {
|
||||
bool Long_mask(Long a, Long b) {
|
||||
return a & b;
|
||||
}
|
||||
|
||||
int Long_to_MINUS_int(long a) {
|
||||
int Long_to_MINUS_int(Long a) {
|
||||
return (int)a;
|
||||
}
|
||||
|
||||
long Long_from_MINUS_int(int a) {
|
||||
return (long)a;
|
||||
Long Long_from_MINUS_int(int a) {
|
||||
return (Long)a;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
#ifdef LOG_MEMORY
|
||||
|
||||
long malloc_balance_counter = 0;
|
||||
Long malloc_balance_counter = 0;
|
||||
bool log_memory_balance = false;
|
||||
|
||||
void *logged_malloc(size_t size) {
|
||||
@ -35,7 +35,7 @@ void Debug_log_MINUS_memory_MINUS_balance_BANG_(bool value) {
|
||||
#define CARP_FREE(ptr) logged_free(ptr)
|
||||
#define CARP_REALLOC(ptr, size) realloc(ptr, size)
|
||||
|
||||
long Debug_memory_MINUS_balance() {
|
||||
Long Debug_memory_MINUS_balance() {
|
||||
return malloc_balance_counter;
|
||||
}
|
||||
|
||||
@ -63,7 +63,7 @@ void* CARP_REALLOC(void* ptr, size_t size) {
|
||||
|
||||
#define CARP_FREE(ptr) free(ptr)
|
||||
|
||||
long Debug_memory_MINUS_balance() {
|
||||
Long Debug_memory_MINUS_balance() {
|
||||
printf(
|
||||
"Error - calling 'memory-balance' without compiling with LOG_MEMORY "
|
||||
"enabled (--log-memory).\n");
|
||||
|
@ -239,21 +239,21 @@ int Int_from_MINUS_string(const String *s) {
|
||||
return atoi(*s);
|
||||
}
|
||||
|
||||
String Long_str(long x) {
|
||||
int size = snprintf(NULL, 0, "%ldl", x) + 1;
|
||||
String Long_str(Long x) {
|
||||
int size = snprintf(NULL, 0, "%" PRIi64, x) + 1;
|
||||
String buffer = CARP_MALLOC(size);
|
||||
sprintf(buffer, "%ldl", x);
|
||||
sprintf(buffer, "%" PRIi64, x);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
String Long_format(const String *str, long x) {
|
||||
String Long_format(const String *str, Long x) {
|
||||
int size = snprintf(NULL, 0, *str, x) + 1;
|
||||
String buffer = CARP_MALLOC(size);
|
||||
sprintf(buffer, *str, x);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
long Long_from_MINUS_string(const String *s) {
|
||||
Long Long_from_MINUS_string(const String *s) {
|
||||
return atol(*s);
|
||||
}
|
||||
|
||||
|
@ -7,9 +7,11 @@ typedef SSIZE_T ssize_t;
|
||||
#ifndef _WIN32
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <inttypes.h>
|
||||
|
||||
typedef char *String;
|
||||
typedef char *Pattern;
|
||||
typedef int64_t Long;
|
||||
|
||||
#if defined NDEBUG
|
||||
#define CHK_INDEX(i, n)
|
||||
|
@ -124,7 +124,7 @@ tyToCManglePtr _ IntTy = "int"
|
||||
tyToCManglePtr _ BoolTy = "bool"
|
||||
tyToCManglePtr _ FloatTy = "float"
|
||||
tyToCManglePtr _ DoubleTy = "double"
|
||||
tyToCManglePtr _ LongTy = "long"
|
||||
tyToCManglePtr _ LongTy = "Long"
|
||||
tyToCManglePtr _ ByteTy = "uint8_t"
|
||||
tyToCManglePtr _ StringTy = "String"
|
||||
tyToCManglePtr _ PatternTy = "Pattern"
|
||||
|
Loading…
Reference in New Issue
Block a user