mirror of
https://github.com/carp-lang/Carp.git
synced 2024-10-03 16:48:14 +03:00
core: do not have short functions on single lines
This commit is contained in:
parent
65946224f0
commit
1829df07a5
@ -3,8 +3,8 @@ BasedOnStyle: Google
|
||||
AlignEscapedNewlinesLeft: 'true'
|
||||
AlignTrailingComments: 'true'
|
||||
AllowAllParametersOfDeclarationOnNextLine: 'true'
|
||||
AllowShortBlocksOnASingleLine: 'true'
|
||||
AllowShortFunctionsOnASingleLine: All
|
||||
AllowShortBlocksOnASingleLine: 'false'
|
||||
AllowShortFunctionsOnASingleLine: None
|
||||
AllowShortIfStatementsOnASingleLine: 'true'
|
||||
AllowShortLoopsOnASingleLine: 'true'
|
||||
BinPackParameters: 'true'
|
||||
|
@ -7,17 +7,27 @@ SDL_Event SDL_Event_init() {
|
||||
return e;
|
||||
}
|
||||
|
||||
int SDL_Event_type(SDL_Event *e) { return e->type; }
|
||||
int SDL_Event_type(SDL_Event *e) {
|
||||
return e->type;
|
||||
}
|
||||
|
||||
SDL_Keycode SDL_Event_keycode(SDL_Event *e) { return e->key.keysym.sym; }
|
||||
SDL_Keycode SDL_Event_keycode(SDL_Event *e) {
|
||||
return e->key.keysym.sym;
|
||||
}
|
||||
|
||||
bool SDL_Event__EQ_(SDL_EventType a, SDL_EventType b) { return a == b; }
|
||||
bool SDL_Event__EQ_(SDL_EventType a, SDL_EventType b) {
|
||||
return a == b;
|
||||
}
|
||||
|
||||
SDL_Event SDL_Event_copy(SDL_Event *e) { return *e; }
|
||||
SDL_Event SDL_Event_copy(SDL_Event *e) {
|
||||
return *e;
|
||||
}
|
||||
|
||||
// Keycode
|
||||
|
||||
SDL_Keycode SDL_Keycode_copy(SDL_Keycode *a) { return *a; }
|
||||
SDL_Keycode SDL_Keycode_copy(SDL_Keycode *a) {
|
||||
return *a;
|
||||
}
|
||||
|
||||
String SDL_Keycode_str(SDL_Keycode a) {
|
||||
char *buffer = CARP_MALLOC(32);
|
||||
@ -60,14 +70,26 @@ SDL_Color SDL_rgba(int r, int g, int b, int a) {
|
||||
return p;
|
||||
}
|
||||
|
||||
int SDL_Color_r(SDL_Color *col) { return (int)(col->r); }
|
||||
int SDL_Color_r(SDL_Color *col) {
|
||||
return (int)(col->r);
|
||||
}
|
||||
|
||||
int SDL_Color_g(SDL_Color *col) { return (int)(col->g); }
|
||||
int SDL_Color_g(SDL_Color *col) {
|
||||
return (int)(col->g);
|
||||
}
|
||||
|
||||
int SDL_Color_b(SDL_Color *col) { return (int)(col->b); }
|
||||
int SDL_Color_b(SDL_Color *col) {
|
||||
return (int)(col->b);
|
||||
}
|
||||
|
||||
int SDL_Color_a(SDL_Color *col) { return (int)(col->a); }
|
||||
int SDL_Color_a(SDL_Color *col) {
|
||||
return (int)(col->a);
|
||||
}
|
||||
|
||||
void *SDL_SurfacePixels(SDL_Surface *s) { return s->pixels; }
|
||||
void *SDL_SurfacePixels(SDL_Surface *s) {
|
||||
return s->pixels;
|
||||
}
|
||||
|
||||
int SDL_SurfacePitch(SDL_Surface *s) { return s->pitch; }
|
||||
int SDL_SurfacePitch(SDL_Surface *s) {
|
||||
return s->pitch;
|
||||
}
|
||||
|
@ -1,10 +1,20 @@
|
||||
// Bool
|
||||
bool Bool_copy(const bool* b) { return *b; }
|
||||
bool Bool_copy(const bool* b) {
|
||||
return *b;
|
||||
}
|
||||
|
||||
bool Bool__EQ_(bool a, bool b) { return a == b; }
|
||||
bool Bool__EQ_(bool a, bool b) {
|
||||
return a == b;
|
||||
}
|
||||
|
||||
bool Bool_not(bool a) { return !a; }
|
||||
bool Bool_not(bool a) {
|
||||
return !a;
|
||||
}
|
||||
|
||||
bool Bool_and(bool a, bool b) { return a && b; }
|
||||
bool Bool_and(bool a, bool b) {
|
||||
return a && b;
|
||||
}
|
||||
|
||||
bool Bool_or(bool a, bool b) { return a && b; }
|
||||
bool Bool_or(bool a, bool b) {
|
||||
return a && b;
|
||||
}
|
||||
|
@ -1,14 +1,26 @@
|
||||
bool Char__EQ_(char a, char b) { return a == b; }
|
||||
bool Char__EQ_(char a, char b) {
|
||||
return a == b;
|
||||
}
|
||||
|
||||
bool Char__LT_(char a, char b) { return a < b; }
|
||||
bool Char__LT_(char a, char b) {
|
||||
return a < b;
|
||||
}
|
||||
|
||||
bool Char__GT_(char a, char b) { return a > b; }
|
||||
bool Char__GT_(char a, char b) {
|
||||
return a > b;
|
||||
}
|
||||
|
||||
int Char_to_MINUS_int(char c) { return (int)(unsigned char)c; }
|
||||
int Char_to_MINUS_int(char c) {
|
||||
return (int)(unsigned char)c;
|
||||
}
|
||||
|
||||
char Char_from_MINUS_int(int i) { return (char)i; }
|
||||
char Char_from_MINUS_int(int i) {
|
||||
return (char)i;
|
||||
}
|
||||
|
||||
char Char_copy(const char *c) { return *c; }
|
||||
char Char_copy(const char *c) {
|
||||
return *c;
|
||||
}
|
||||
|
||||
String PtrChar_str(const char *c) {
|
||||
size_t len = strlen(c) + 1;
|
||||
|
@ -1,20 +1,42 @@
|
||||
const double CARP_DBL_MAX = DBL_MAX;
|
||||
|
||||
double Double__PLUS_(double x, double y) { return x + y; }
|
||||
double Double__MINUS_(double x, double y) { return x - y; }
|
||||
double Double__MUL_(double x, double y) { return x * y; }
|
||||
double Double__DIV_(double x, double y) { return x / y; }
|
||||
bool Double__LT_(double x, double y) { return x < y; }
|
||||
bool Double__GT_(double x, double y) { return x > y; }
|
||||
bool Double__EQ_(double x, double y) { return x == y; }
|
||||
double Double_neg(double x) { return -x; }
|
||||
double Double__PLUS_(double x, double y) {
|
||||
return x + y;
|
||||
}
|
||||
double Double__MINUS_(double x, double y) {
|
||||
return x - y;
|
||||
}
|
||||
double Double__MUL_(double x, double y) {
|
||||
return x * y;
|
||||
}
|
||||
double Double__DIV_(double x, double y) {
|
||||
return x / y;
|
||||
}
|
||||
bool Double__LT_(double x, double y) {
|
||||
return x < y;
|
||||
}
|
||||
bool Double__GT_(double x, double y) {
|
||||
return x > y;
|
||||
}
|
||||
bool Double__EQ_(double x, double y) {
|
||||
return x == y;
|
||||
}
|
||||
double Double_neg(double x) {
|
||||
return -x;
|
||||
}
|
||||
|
||||
double Double_copy(const double* x) { return *x; }
|
||||
double Double_copy(const double* x) {
|
||||
return *x;
|
||||
}
|
||||
|
||||
// Double.toInt : Double -> Int
|
||||
int Double_to_MINUS_int(double x) { return (int)x; }
|
||||
int Double_to_MINUS_int(double x) {
|
||||
return (int)x;
|
||||
}
|
||||
|
||||
double Double_from_MINUS_int(int x) { return (double)x; }
|
||||
double Double_from_MINUS_int(int x) {
|
||||
return (double)x;
|
||||
}
|
||||
|
||||
long Double_to_MINUS_bytes(double x) {
|
||||
long y;
|
||||
@ -22,52 +44,102 @@ long Double_to_MINUS_bytes(double x) {
|
||||
return y;
|
||||
}
|
||||
|
||||
float Double_to_MINUS_float(double x) { return (float)x; }
|
||||
float Double_to_MINUS_float(double x) {
|
||||
return (float)x;
|
||||
}
|
||||
|
||||
double Double_from_MINUS_float(float x) { return (double)x; }
|
||||
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) { return (double)x; }
|
||||
double Double_from_MINUS_long(long x) {
|
||||
return (double)x;
|
||||
}
|
||||
|
||||
double Double_abs(double x) { return x > 0.0 ? x : -x; }
|
||||
double Double_abs(double x) {
|
||||
return x > 0.0 ? x : -x;
|
||||
}
|
||||
|
||||
double Double_acos(double x) { return acos(x); }
|
||||
double Double_acos(double x) {
|
||||
return acos(x);
|
||||
}
|
||||
|
||||
double Double_asin(double x) { return asin(x); }
|
||||
double Double_asin(double x) {
|
||||
return asin(x);
|
||||
}
|
||||
|
||||
double Double_atan(double x) { return atan(x); }
|
||||
double Double_atan(double x) {
|
||||
return atan(x);
|
||||
}
|
||||
|
||||
double Double_atan2(double y, double x) { return atan2(y, x); }
|
||||
double Double_atan2(double y, double x) {
|
||||
return atan2(y, x);
|
||||
}
|
||||
|
||||
double Double_cos(double x) { return cos(x); }
|
||||
double Double_cos(double x) {
|
||||
return cos(x);
|
||||
}
|
||||
|
||||
double Double_cosh(double x) { return cosh(x); }
|
||||
double Double_cosh(double x) {
|
||||
return cosh(x);
|
||||
}
|
||||
|
||||
double Double_sin(double x) { return sin(x); }
|
||||
double Double_sin(double x) {
|
||||
return sin(x);
|
||||
}
|
||||
|
||||
double Double_sinh(double x) { return sinh(x); }
|
||||
double Double_sinh(double x) {
|
||||
return sinh(x);
|
||||
}
|
||||
|
||||
double Double_tanh(double x) { return tanh(x); }
|
||||
double Double_tanh(double x) {
|
||||
return tanh(x);
|
||||
}
|
||||
|
||||
double Double_exp(double x) { return exp(x); }
|
||||
double Double_exp(double x) {
|
||||
return exp(x);
|
||||
}
|
||||
|
||||
double Double_frexp(double x, int* exponent) { return frexp(x, exponent); }
|
||||
double Double_frexp(double x, int* exponent) {
|
||||
return frexp(x, exponent);
|
||||
}
|
||||
|
||||
double Double_ldexp(double x, int exponent) { return ldexp(x, exponent); }
|
||||
double Double_ldexp(double x, int exponent) {
|
||||
return ldexp(x, exponent);
|
||||
}
|
||||
|
||||
double Double_log(double x) { return log(x); }
|
||||
double Double_log(double x) {
|
||||
return log(x);
|
||||
}
|
||||
|
||||
double Double_log10(double x) { return log10(x); }
|
||||
double Double_log10(double x) {
|
||||
return log10(x);
|
||||
}
|
||||
|
||||
double Double_modf(double x, double* integer) { return modf(x, integer); }
|
||||
double Double_modf(double x, double* integer) {
|
||||
return modf(x, integer);
|
||||
}
|
||||
|
||||
double Double_pow(double x, double y) { return pow(x, y); }
|
||||
double Double_pow(double x, double y) {
|
||||
return pow(x, y);
|
||||
}
|
||||
|
||||
double Double_sqrt(double x) { return sqrt(x); }
|
||||
double Double_sqrt(double x) {
|
||||
return sqrt(x);
|
||||
}
|
||||
|
||||
double Double_ceil(double x) { return ceil(x); }
|
||||
double Double_ceil(double x) {
|
||||
return ceil(x);
|
||||
}
|
||||
|
||||
double Double_floor(double x) { return floor(x); }
|
||||
double Double_floor(double x) {
|
||||
return floor(x);
|
||||
}
|
||||
|
||||
double Double_mod(double x, double y) { return fmod(x, y); }
|
||||
double Double_mod(double x, double y) {
|
||||
return fmod(x, y);
|
||||
}
|
||||
|
@ -1,19 +1,41 @@
|
||||
const float CARP_FLT_MAX = FLT_MAX;
|
||||
|
||||
float Float__PLUS_(float x, float y) { return x + y; }
|
||||
float Float__MINUS_(float x, float y) { return x - y; }
|
||||
float Float__MUL_(float x, float y) { return x * y; }
|
||||
float Float__DIV_(float x, float y) { return x / y; }
|
||||
bool Float__LT_(float x, float y) { return x < y; }
|
||||
bool Float__GT_(float x, float y) { return x > y; }
|
||||
bool Float__EQ_(float x, float y) { return x == y; }
|
||||
float Float_neg(float x) { return -x; }
|
||||
float Float__PLUS_(float x, float y) {
|
||||
return x + y;
|
||||
}
|
||||
float Float__MINUS_(float x, float y) {
|
||||
return x - y;
|
||||
}
|
||||
float Float__MUL_(float x, float y) {
|
||||
return x * y;
|
||||
}
|
||||
float Float__DIV_(float x, float y) {
|
||||
return x / y;
|
||||
}
|
||||
bool Float__LT_(float x, float y) {
|
||||
return x < y;
|
||||
}
|
||||
bool Float__GT_(float x, float y) {
|
||||
return x > y;
|
||||
}
|
||||
bool Float__EQ_(float x, float y) {
|
||||
return x == y;
|
||||
}
|
||||
float Float_neg(float x) {
|
||||
return -x;
|
||||
}
|
||||
|
||||
float Float_copy(const float* x) { return *x; }
|
||||
float Float_copy(const float* x) {
|
||||
return *x;
|
||||
}
|
||||
|
||||
int Float_to_MINUS_int(float x) { return (int)x; }
|
||||
int Float_to_MINUS_int(float x) {
|
||||
return (int)x;
|
||||
}
|
||||
|
||||
float Float_from_MINUS_int(int x) { return (float)x; }
|
||||
float Float_from_MINUS_int(int x) {
|
||||
return (float)x;
|
||||
}
|
||||
|
||||
int Float_to_MINUS_bytes(float x) {
|
||||
int y;
|
||||
@ -21,46 +43,90 @@ int Float_to_MINUS_bytes(float x) {
|
||||
return y;
|
||||
}
|
||||
|
||||
float Float_abs(float x) { return fabsf(x); }
|
||||
float Float_abs(float x) {
|
||||
return fabsf(x);
|
||||
}
|
||||
|
||||
float Float_acos(float x) { return acosf(x); }
|
||||
float Float_acos(float x) {
|
||||
return acosf(x);
|
||||
}
|
||||
|
||||
float Float_asin(float x) { return asinf(x); }
|
||||
float Float_asin(float x) {
|
||||
return asinf(x);
|
||||
}
|
||||
|
||||
float Float_atan(float x) { return atanf(x); }
|
||||
float Float_atan(float x) {
|
||||
return atanf(x);
|
||||
}
|
||||
|
||||
float Float_atan2(float y, float x) { return atan2f(y, x); }
|
||||
float Float_atan2(float y, float x) {
|
||||
return atan2f(y, x);
|
||||
}
|
||||
|
||||
float Float_cos(float x) { return cosf(x); }
|
||||
float Float_cos(float x) {
|
||||
return cosf(x);
|
||||
}
|
||||
|
||||
float Float_cosh(float x) { return coshf(x); }
|
||||
float Float_cosh(float x) {
|
||||
return coshf(x);
|
||||
}
|
||||
|
||||
float Float_sin(float x) { return sinf(x); }
|
||||
float Float_sin(float x) {
|
||||
return sinf(x);
|
||||
}
|
||||
|
||||
float Float_sinh(float x) { return sinhf(x); }
|
||||
float Float_sinh(float x) {
|
||||
return sinhf(x);
|
||||
}
|
||||
|
||||
float Float_tan(float x) { return tanf(x); }
|
||||
float Float_tan(float x) {
|
||||
return tanf(x);
|
||||
}
|
||||
|
||||
float Float_tanh(float x) { return tanhf(x); }
|
||||
float Float_tanh(float x) {
|
||||
return tanhf(x);
|
||||
}
|
||||
|
||||
float Float_exp(float x) { return expf(x); }
|
||||
float Float_exp(float x) {
|
||||
return expf(x);
|
||||
}
|
||||
|
||||
float Float_frexp(float x, int* exponent) { return frexpf(x, exponent); }
|
||||
float Float_frexp(float x, int* exponent) {
|
||||
return frexpf(x, exponent);
|
||||
}
|
||||
|
||||
float Float_ldexp(float x, int exponent) { return ldexpf(x, exponent); }
|
||||
float Float_ldexp(float x, int exponent) {
|
||||
return ldexpf(x, exponent);
|
||||
}
|
||||
|
||||
float Float_log(float x) { return logf(x); }
|
||||
float Float_log(float x) {
|
||||
return logf(x);
|
||||
}
|
||||
|
||||
float Float_log10(float x) { return log10f(x); }
|
||||
float Float_log10(float x) {
|
||||
return log10f(x);
|
||||
}
|
||||
|
||||
float Float_modf(float x, float* integer) { return modff(x, integer); }
|
||||
float Float_modf(float x, float* integer) {
|
||||
return modff(x, integer);
|
||||
}
|
||||
|
||||
float Float_pow(float x, float y) { return powf(x, y); }
|
||||
float Float_pow(float x, float y) {
|
||||
return powf(x, y);
|
||||
}
|
||||
|
||||
float Float_sqrt(float x) { return sqrtf(x); }
|
||||
float Float_sqrt(float x) {
|
||||
return sqrtf(x);
|
||||
}
|
||||
|
||||
float Float_ceil(float x) { return ceilf(x); }
|
||||
float Float_ceil(float x) {
|
||||
return ceilf(x);
|
||||
}
|
||||
|
||||
float Float_floor(float x) { return floorf(x); }
|
||||
float Float_floor(float x) {
|
||||
return floorf(x);
|
||||
}
|
||||
|
||||
float Float_mod(float x, float y) { return fmodf(x, y); }
|
||||
float Float_mod(float x, float y) {
|
||||
return fmodf(x, y);
|
||||
}
|
||||
|
@ -1,27 +1,67 @@
|
||||
int CARP_INT_MAX = INT_MAX;
|
||||
int CARP_INT_MIN = INT_MIN;
|
||||
|
||||
int Int__PLUS_(int x, int y) { return x + y; }
|
||||
int Int__MINUS_(int x, int y) { return x - y; }
|
||||
int Int__MUL_(int x, int y) { return x * y; }
|
||||
int Int__DIV_(int x, int y) { return x / y; }
|
||||
bool Int__EQ_(int x, int y) { return x == y; }
|
||||
bool Int__LT_(int x, int y) { return x < y; }
|
||||
bool Int__GT_(int x, int y) { return x > y; }
|
||||
int Int_neg(int x) { return -x; }
|
||||
int Int__PLUS_(int x, int y) {
|
||||
return x + y;
|
||||
}
|
||||
int Int__MINUS_(int x, int y) {
|
||||
return x - y;
|
||||
}
|
||||
int Int__MUL_(int x, int y) {
|
||||
return x * y;
|
||||
}
|
||||
int Int__DIV_(int x, int y) {
|
||||
return x / y;
|
||||
}
|
||||
bool Int__EQ_(int x, int y) {
|
||||
return x == y;
|
||||
}
|
||||
bool Int__LT_(int x, int y) {
|
||||
return x < y;
|
||||
}
|
||||
bool Int__GT_(int x, int y) {
|
||||
return x > y;
|
||||
}
|
||||
int Int_neg(int x) {
|
||||
return -x;
|
||||
}
|
||||
|
||||
int Int_inc(int x) { return x + 1; }
|
||||
int Int_dec(int x) { return x - 1; }
|
||||
int Int_abs(int x) { return x > 0 ? x : -x; }
|
||||
int Int_bit_MINUS_shift_MINUS_left(int x, int y) { return x << y; }
|
||||
int Int_bit_MINUS_shift_MINUS_right(int x, int y) { return x >> y; }
|
||||
int Int_bit_MINUS_and(int x, int y) { return x & y; }
|
||||
int Int_bit_MINUS_or(int x, int y) { return x | y; }
|
||||
int Int_bit_MINUS_xor(int x, int y) { return x ^ y; }
|
||||
int Int_bit_MINUS_not(int x) { return ~x; }
|
||||
int Int_inc(int x) {
|
||||
return x + 1;
|
||||
}
|
||||
int Int_dec(int x) {
|
||||
return x - 1;
|
||||
}
|
||||
int Int_abs(int x) {
|
||||
return x > 0 ? x : -x;
|
||||
}
|
||||
int Int_bit_MINUS_shift_MINUS_left(int x, int y) {
|
||||
return x << y;
|
||||
}
|
||||
int Int_bit_MINUS_shift_MINUS_right(int x, int y) {
|
||||
return x >> y;
|
||||
}
|
||||
int Int_bit_MINUS_and(int x, int y) {
|
||||
return x & y;
|
||||
}
|
||||
int Int_bit_MINUS_or(int x, int y) {
|
||||
return x | y;
|
||||
}
|
||||
int Int_bit_MINUS_xor(int x, int y) {
|
||||
return x ^ y;
|
||||
}
|
||||
int Int_bit_MINUS_not(int x) {
|
||||
return ~x;
|
||||
}
|
||||
|
||||
int Int_copy(const int *x) { return *x; }
|
||||
int Int_copy(const int *x) {
|
||||
return *x;
|
||||
}
|
||||
|
||||
int Int_mod(int x, int divider) { return x % divider; }
|
||||
int Int_mod(int x, int divider) {
|
||||
return x % divider;
|
||||
}
|
||||
|
||||
bool Int_mask(int a, int b) { return a & b; }
|
||||
bool Int_mask(int a, int b) {
|
||||
return a & b;
|
||||
}
|
||||
|
@ -1,8 +1,16 @@
|
||||
void IO_println(String *s) { puts(*s); }
|
||||
void IO_print(String *s) { printf("%s", *s); }
|
||||
void IO_println(String *s) {
|
||||
puts(*s);
|
||||
}
|
||||
void IO_print(String *s) {
|
||||
printf("%s", *s);
|
||||
}
|
||||
|
||||
void IO_errorln(String *s) { fprintf(stderr, "%s\n", *s); }
|
||||
void IO_error(String *s) { fprintf(stderr, "%s", *s); }
|
||||
void IO_errorln(String *s) {
|
||||
fprintf(stderr, "%s\n", *s);
|
||||
}
|
||||
void IO_error(String *s) {
|
||||
fprintf(stderr, "%s", *s);
|
||||
}
|
||||
|
||||
char IO_EOF = (char)EOF;
|
||||
|
||||
@ -19,11 +27,15 @@ size_t getline(char **lineptr, size_t *n, FILE *stream) {
|
||||
}
|
||||
|
||||
c = fgetc(stream);
|
||||
if (c == EOF) { return -1; }
|
||||
if (c == EOF) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (*lineptr == NULL) {
|
||||
*lineptr = malloc(128);
|
||||
if (*lineptr == NULL) { return -1; }
|
||||
if (*lineptr == NULL) {
|
||||
return -1;
|
||||
}
|
||||
*n = 128;
|
||||
}
|
||||
|
||||
@ -31,15 +43,21 @@ size_t getline(char **lineptr, size_t *n, FILE *stream) {
|
||||
while (c != EOF) {
|
||||
if (pos + 1 >= *n) {
|
||||
size_t new_size = *n + (*n >> 2);
|
||||
if (new_size < 128) { new_size = 128; }
|
||||
if (new_size < 128) {
|
||||
new_size = 128;
|
||||
}
|
||||
char *new_ptr = CARP_REALLOC(*lineptr, new_size);
|
||||
if (new_ptr == NULL) { return -1; }
|
||||
if (new_ptr == NULL) {
|
||||
return -1;
|
||||
}
|
||||
*n = new_size;
|
||||
*lineptr = new_ptr;
|
||||
}
|
||||
|
||||
((unsigned char *)(*lineptr))[pos++] = c;
|
||||
if (c == '\n') { break; }
|
||||
if (c == '\n') {
|
||||
break;
|
||||
}
|
||||
c = fgetc(stream);
|
||||
}
|
||||
|
||||
@ -81,9 +99,13 @@ String IO_read_MINUS_file(const String *filename) {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
char IO_fgetc(FILE *f) { return (char)fgetc(f); }
|
||||
char IO_fgetc(FILE *f) {
|
||||
return (char)fgetc(f);
|
||||
}
|
||||
|
||||
void IO_fclose(FILE *f) { fclose(f); }
|
||||
void IO_fclose(FILE *f) {
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
FILE *IO_fopen(const String *filename, const String *mode) {
|
||||
return fopen(*filename, *mode);
|
||||
|
@ -1,7 +1,15 @@
|
||||
long Long__PLUS_(long x, long y) { return x + y; }
|
||||
long Long__MINUS_(long x, long y) { return x - y; }
|
||||
long Long__MUL_(long x, long y) { return x * y; }
|
||||
long Long__DIV_(long x, long y) { return x / y; }
|
||||
long Long__PLUS_(long x, long y) {
|
||||
return x + y;
|
||||
}
|
||||
long Long__MINUS_(long x, long y) {
|
||||
return x - y;
|
||||
}
|
||||
long Long__MUL_(long x, long y) {
|
||||
return x * 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);
|
||||
@ -13,29 +21,67 @@ bool Long_safe_MINUS_mul(long x, long y, long* res) {
|
||||
return __builtin_smull_overflow(x, y, res);
|
||||
}
|
||||
#endif
|
||||
bool Long__EQ_(long x, long y) { return x == y; }
|
||||
bool Long__LT_(long x, long y) { return x < y; }
|
||||
bool Long__GT_(long x, long y) { return x > y; }
|
||||
long Long_neg(long x) { return -x; }
|
||||
bool Long__EQ_(long x, long y) {
|
||||
return x == y;
|
||||
}
|
||||
bool Long__LT_(long x, long y) {
|
||||
return x < y;
|
||||
}
|
||||
bool Long__GT_(long x, long y) {
|
||||
return x > y;
|
||||
}
|
||||
long Long_neg(long x) {
|
||||
return -x;
|
||||
}
|
||||
|
||||
long Long_inc(long x) { return x + 1; }
|
||||
long Long_dec(long x) { return x - 1; }
|
||||
long Long_abs(long x) { return x > 0 ? x : -x; }
|
||||
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) { return x >> y; }
|
||||
long Long_bit_MINUS_and(long x, long y) { return x & y; }
|
||||
long Long_bit_MINUS_or(long x, long y) { return x | y; }
|
||||
long Long_bit_MINUS_xor(long x, long y) { return x ^ y; }
|
||||
long Long_bit_MINUS_not(long x) { return ~x; }
|
||||
long Long_inc(long x) {
|
||||
return x + 1;
|
||||
}
|
||||
long Long_dec(long x) {
|
||||
return x - 1;
|
||||
}
|
||||
long Long_abs(long x) {
|
||||
return x > 0 ? x : -x;
|
||||
}
|
||||
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) {
|
||||
return x >> y;
|
||||
}
|
||||
long Long_bit_MINUS_and(long x, long y) {
|
||||
return x & y;
|
||||
}
|
||||
long Long_bit_MINUS_or(long x, long y) {
|
||||
return x | y;
|
||||
}
|
||||
long Long_bit_MINUS_xor(long x, long y) {
|
||||
return x ^ y;
|
||||
}
|
||||
long Long_bit_MINUS_not(long x) {
|
||||
return ~x;
|
||||
}
|
||||
|
||||
long Long_copy(const long* x) { return *x; }
|
||||
long Long_copy(const long* x) {
|
||||
return *x;
|
||||
}
|
||||
|
||||
long Long_mod(long x, long divider) { return x % divider; }
|
||||
long Long_mod(long x, long divider) {
|
||||
return x % divider;
|
||||
}
|
||||
|
||||
void Long_seed(long seed) { srand(seed); }
|
||||
void Long_seed(long seed) {
|
||||
srand(seed);
|
||||
}
|
||||
|
||||
bool Long_mask(long a, long b) { return a & b; }
|
||||
bool Long_mask(long a, long b) {
|
||||
return a & b;
|
||||
}
|
||||
|
||||
int Long_to_MINUS_int(long a) { return (int)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;
|
||||
}
|
||||
|
@ -5,13 +5,17 @@ bool log_memory_balance = false;
|
||||
|
||||
void *logged_malloc(size_t size) {
|
||||
void *ptr = malloc(size);
|
||||
if (log_memory_balance) { printf("MALLOC: %p (%ld bytes)\n", ptr, size); }
|
||||
if (log_memory_balance) {
|
||||
printf("MALLOC: %p (%ld bytes)\n", ptr, size);
|
||||
}
|
||||
malloc_balance_counter++;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void logged_free(void *ptr) {
|
||||
if (log_memory_balance) { printf("FREE: %p\n", ptr); }
|
||||
if (log_memory_balance) {
|
||||
printf("FREE: %p\n", ptr);
|
||||
}
|
||||
free(ptr);
|
||||
malloc_balance_counter--;
|
||||
/* if(malloc_balance_counter == 0) { */
|
||||
@ -31,7 +35,9 @@ 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() { return malloc_balance_counter; }
|
||||
long Debug_memory_MINUS_balance() {
|
||||
return malloc_balance_counter;
|
||||
}
|
||||
|
||||
void Debug_reset_MINUS_memory_MINUS_balance_BANG_() {
|
||||
malloc_balance_counter = 0;
|
||||
|
@ -758,11 +758,17 @@ Pattern Pattern_copy(Pattern *p) {
|
||||
return (Pattern)memcpy(ptr, *p, len);
|
||||
}
|
||||
|
||||
void Pattern_delete(Pattern p) { CARP_FREE(p); }
|
||||
void Pattern_delete(Pattern p) {
|
||||
CARP_FREE(p);
|
||||
}
|
||||
|
||||
Pattern Pattern_init(String *p) { return Pattern_copy(p); }
|
||||
Pattern Pattern_init(String *p) {
|
||||
return Pattern_copy(p);
|
||||
}
|
||||
|
||||
String Pattern_str(Pattern *p) { return Pattern_copy(p); }
|
||||
String Pattern_str(Pattern *p) {
|
||||
return Pattern_copy(p);
|
||||
}
|
||||
|
||||
String Pattern_prn(Pattern *p) {
|
||||
int n = strlen(*p) + 4;
|
||||
@ -771,4 +777,6 @@ String Pattern_prn(Pattern *p) {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
bool Pattern__EQ_(Pattern *a, Pattern *b) { return strcmp(*a, *b) == 0; }
|
||||
bool Pattern__EQ_(Pattern *a, Pattern *b) {
|
||||
return strcmp(*a, *b) == 0;
|
||||
}
|
||||
|
@ -11,7 +11,9 @@ String String_allocate(int len, char byte) {
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void String_delete(String s) { CARP_FREE(s); }
|
||||
void String_delete(String s) {
|
||||
CARP_FREE(s);
|
||||
}
|
||||
|
||||
void String_string_MINUS_set_BANG_(String *s, int i, char ch) {
|
||||
CHK_INDEX(i, strlen(*s));
|
||||
@ -82,11 +84,17 @@ String String_append(const String *a, const String *b) {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
int String_length(const String *s) { return strlen(*s); }
|
||||
int String_length(const String *s) {
|
||||
return strlen(*s);
|
||||
}
|
||||
|
||||
char *String_cstr(const String *s) { return *s; }
|
||||
char *String_cstr(const String *s) {
|
||||
return *s;
|
||||
}
|
||||
|
||||
String String_str(const String *s) { return String_copy(s); }
|
||||
String String_str(const String *s) {
|
||||
return String_copy(s);
|
||||
}
|
||||
|
||||
String String_prn(const String *s) {
|
||||
int n = strlen(*s) + 4;
|
||||
@ -95,7 +103,9 @@ String String_prn(const String *s) {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
char String_char_MINUS_at(const String *s, int i) { return (*s)[i]; }
|
||||
char String_char_MINUS_at(const String *s, int i) {
|
||||
return (*s)[i];
|
||||
}
|
||||
|
||||
String String_format(const String *str, const String *s) {
|
||||
int size = snprintf(NULL, 0, *str, *s) + 1;
|
||||
@ -211,7 +221,9 @@ String Int_format(const String *str, int x) {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
int Int_from_MINUS_string(const String *s) { return atoi(*s); }
|
||||
int Int_from_MINUS_string(const String *s) {
|
||||
return atoi(*s);
|
||||
}
|
||||
|
||||
String Long_str(long x) {
|
||||
int size = snprintf(NULL, 0, "%ldl", x) + 1;
|
||||
@ -227,7 +239,9 @@ String Long_format(const String *str, long x) {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
long Long_from_MINUS_string(const String *s) { return atol(*s); }
|
||||
long Long_from_MINUS_string(const String *s) {
|
||||
return atol(*s);
|
||||
}
|
||||
|
||||
int String_index_MINUS_of_MINUS_from(const String *s, char c, int i) {
|
||||
/* Return index of first occurrence of `c` in `s` AFTER index i
|
||||
@ -236,7 +250,9 @@ int String_index_MINUS_of_MINUS_from(const String *s, char c, int i) {
|
||||
++i; // skip first character as we want AFTER i
|
||||
int len = strlen(*s);
|
||||
for (; i < len; ++i) {
|
||||
if (c == (*s)[i]) { return i; }
|
||||
if (c == (*s)[i]) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
@ -1,7 +1,11 @@
|
||||
|
||||
void System_free(void *p) { CARP_FREE(p); }
|
||||
void System_free(void *p) {
|
||||
CARP_FREE(p);
|
||||
}
|
||||
|
||||
int System_time() { return time(0); }
|
||||
int System_time() {
|
||||
return time(0);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
void System_sleep_MINUS_seconds(int t) {
|
||||
@ -12,11 +16,17 @@ void System_sleep_MINUS_micros(int t) {
|
||||
// TODO!
|
||||
}
|
||||
|
||||
double System_nanotime() { return 0; }
|
||||
double System_nanotime() {
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
void System_sleep_MINUS_seconds(int t) { sleep(t); }
|
||||
void System_sleep_MINUS_seconds(int t) {
|
||||
sleep(t);
|
||||
}
|
||||
|
||||
void System_sleep_MINUS_micros(int t) { usleep(t); }
|
||||
void System_sleep_MINUS_micros(int t) {
|
||||
usleep(t);
|
||||
}
|
||||
|
||||
double System_nanotime() {
|
||||
struct timespec tv;
|
||||
@ -25,7 +35,9 @@ double System_nanotime() {
|
||||
}
|
||||
#endif
|
||||
|
||||
void System_system(const String *command) { system(*command); }
|
||||
void System_system(const String *command) {
|
||||
system(*command);
|
||||
}
|
||||
|
||||
Array System_args;
|
||||
|
||||
@ -34,4 +46,6 @@ String *System_get_MINUS_arg(int idx) {
|
||||
return &(((String *)System_args.data)[idx]);
|
||||
}
|
||||
|
||||
int System_get_MINUS_args_MINUS_len() { return System_args.len; }
|
||||
int System_get_MINUS_args_MINUS_len() {
|
||||
return System_args.len;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user