project_files/hwc/rtl/system.h
author nemo
Mon, 15 Oct 2018 13:08:29 -0400
changeset 13925 7173b702e8db
parent 13885 5f819b90d479
child 14173 5c6f947c342c
permissions -rw-r--r--
tag both as overloadable - seems to satisfy clang 3.4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     1
#ifndef SYSTEM_H_
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     2
#define SYSTEM_H_
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     3
10566
cc90ea6448c7 map halt(t) to exit(t) rather than assert(0). all test cases except gravity pass with pas2c now
sheepluva
parents: 10131
diff changeset
     4
#include <stdlib.h>
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     5
#include <time.h>
8047
25a4daa6473c cleanup headers, remove -I . from rtl lib to save a few warnings
koda
parents: 7983
diff changeset
     6
#include "Types.h"
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     7
#include "misc.h"
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     8
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     9
extern double pi;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    10
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    11
typedef TDate* PDate;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    12
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    13
// dimension info for dynamic arrays
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    14
typedef struct {
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    15
    int dim;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    16
    int a[4]; // at most 4
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    17
} fpcrtl_dimension_t;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    18
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    19
/*
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    20
 * Copy returns a string which is a copy if the Count characters in S, starting at position Index.
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    21
 * If Count is larger than the length of the string S, the result is truncated.
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    22
 * If Index is larger than the length of the string S, then an empty string is returned.
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    23
 * Index is 1-based.
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    24
 */
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    25
string255   fpcrtl_copy(string255 s, Integer Index, Integer Count);
10127
7f29a65aa1e4 It compiles \o/
unc0rr
parents: 10124
diff changeset
    26
astring     fpcrtl_copyA(astring s, Integer Index, Integer Count);
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    27
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    28
/*
10838
2abe883c9c21 teach pas2c how to insert() shortstrings
sheepluva
parents: 10566
diff changeset
    29
 * Insert a shortstring in another at a specified index
2abe883c9c21 teach pas2c how to insert() shortstrings
sheepluva
parents: 10566
diff changeset
    30
 */
13925
7173b702e8db tag both as overloadable - seems to satisfy clang 3.4
nemo
parents: 13885
diff changeset
    31
void        __attribute__((overloadable))                   fpcrtl_insert__vars(string255 *src, string255 *dst, SizeInt index);
13885
5f819b90d479 - Fix insert() for strings in pas2c
unc0rr
parents: 10910
diff changeset
    32
void        __attribute__((overloadable))                   fpcrtl_insert__vars(astring *src, astring *dst, SizeInt index);
5f819b90d479 - Fix insert() for strings in pas2c
unc0rr
parents: 10910
diff changeset
    33
10838
2abe883c9c21 teach pas2c how to insert() shortstrings
sheepluva
parents: 10566
diff changeset
    34
#define     fpcrtl_insert(src, dst, index)                  fpcrtl_insert__vars(&(src), &(dst), index);
2abe883c9c21 teach pas2c how to insert() shortstrings
sheepluva
parents: 10566
diff changeset
    35
#define     fpcrtl_Insert                                   fpcrtl_insert
2abe883c9c21 teach pas2c how to insert() shortstrings
sheepluva
parents: 10566
diff changeset
    36
2abe883c9c21 teach pas2c how to insert() shortstrings
sheepluva
parents: 10566
diff changeset
    37
/*
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    38
 * Delete removes Count characters from string S, starting at position Index.
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    39
 * All characters after the deleted characters are shifted Count positions to the left,
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    40
 * and the length of the string is adjusted.
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    41
 */
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    42
#define     fpcrtl_delete(s, index, count)                  fpcrtl_delete__vars(&(s), index, count)
10131
4b4a043111f4 - pas2c recognizes typecasts in initialization expressions
unc0rr
parents: 10127
diff changeset
    43
void        __attribute__((overloadable))                   fpcrtl_delete__vars(string255 *s, SizeInt index, SizeInt count);
4b4a043111f4 - pas2c recognizes typecasts in initialization expressions
unc0rr
parents: 10127
diff changeset
    44
void        __attribute__((overloadable))                   fpcrtl_delete__vars(astring *s, SizeInt index, SizeInt count);
10838
2abe883c9c21 teach pas2c how to insert() shortstrings
sheepluva
parents: 10566
diff changeset
    45
#define     fpcrtl_Delete                                   fpcrtl_delete
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    46
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    47
string255   fpcrtl_floatToStr(double n);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    48
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    49
/*
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    50
 * Move data from one location in memory to another
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    51
 */
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    52
void        fpcrtl_move__vars(void *src, void *dst, SizeInt count);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    53
#define     fpcrtl_move(src, dst, count)                    fpcrtl_move__vars(&(src), &(dst), count);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    54
#define     fpcrtl_Move                                     fpcrtl_move
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    55
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    56
Integer     __attribute__((overloadable))                   fpcrtl_pos(Char c, string255 str);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    57
Integer     __attribute__((overloadable))                   fpcrtl_pos(string255 substr, string255 str);
10127
7f29a65aa1e4 It compiles \o/
unc0rr
parents: 10124
diff changeset
    58
Integer     __attribute__((overloadable))                   fpcrtl_pos(string255 substr, astring str);
10131
4b4a043111f4 - pas2c recognizes typecasts in initialization expressions
unc0rr
parents: 10127
diff changeset
    59
Integer     __attribute__((overloadable))                   fpcrtl_pos(Char c, astring str);
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    60
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    61
Integer     fpcrtl_length(string255 s);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    62
#define     fpcrtl_Length                                   fpcrtl_length
10124
aabd1b75d5a3 Even more explicit type conversions and other stuff to help pas2c use ansistrings
unc0rr
parents: 8850
diff changeset
    63
Integer     fpcrtl_lengthA(astring s);
aabd1b75d5a3 Even more explicit type conversions and other stuff to help pas2c use ansistrings
unc0rr
parents: 8850
diff changeset
    64
#define     fpcrtl_LengthA                                  fpcrtl_lengthA
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    65
10131
4b4a043111f4 - pas2c recognizes typecasts in initialization expressions
unc0rr
parents: 10127
diff changeset
    66
#define     fpcrtl_SetLengthA(s, l)                         do{(s).len = (l);}while(0)
4b4a043111f4 - pas2c recognizes typecasts in initialization expressions
unc0rr
parents: 10127
diff changeset
    67
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    68
#define     fpcrtl_sqr(x)                                   ((x) * (x))
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    69
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    70
#define     fpcrtl_odd(x)                                   ((x) % 2 != 0 ? true : false)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    71
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    72
#define     fpcrtl_StrLen                                   strlen
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    73
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    74
#define     SizeOf                                          sizeof
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    75
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    76
string255   fpcrtl_lowerCase(string255 s);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    77
#define     fpcrtl_LowerCase                                fpcrtl_lowerCase
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    78
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    79
void        fpcrtl_fillChar__vars(void *x, SizeInt count, Byte value);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    80
#define     fpcrtl_fillChar(x, count, value)                fpcrtl_fillChar__vars(&(x), count, value)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    81
#define     fpcrtl_FillChar                                 fpcrtl_fillChar
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    82
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    83
void        fpcrtl_new__vars(void **p, int size);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    84
#define     fpcrtl_new(a)                                   fpcrtl_new__vars((void **)&(a), sizeof(*(a)))
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    85
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    86
#define     fpcrtl_dispose                                  free
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    87
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    88
#define     fpcrtl_freeMem(p, size)                         free(p)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    89
#define     fpcrtl_FreeMem(p, size)                         free(p)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    90
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    91
#define     fpcrtl_getMem(size)                             malloc(size)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    92
#define     fpcrtl_GetMem                                   fpcrtl_getMem
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    93
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    94
#define     fpcrtl_assigned(p)                              ((p) != NULL)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    95
#define     fpcrtl_Assigned                                 fpcrtl_assigned
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    96
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    97
Integer     fpcrtl_trunc(extended n);
10910
df11dea74701 Add ceil() function to fpcrtl of pas2c
unc0rr
parents: 10838
diff changeset
    98
Integer     fpcrtl_ceil(extended n);
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    99
8850
ae8a957c69fd engine to c now compiles with some manual intervention (as of bug 596)
koda
parents: 8047
diff changeset
   100
#define     fpcrtl_val(s, a)                                fpcrtl_val__vars(s, &(a))
ae8a957c69fd engine to c now compiles with some manual intervention (as of bug 596)
koda
parents: 8047
diff changeset
   101
void        __attribute__((overloadable))                   fpcrtl_val__vars(string255 s, LongInt *a);
ae8a957c69fd engine to c now compiles with some manual intervention (as of bug 596)
koda
parents: 8047
diff changeset
   102
void        __attribute__((overloadable))                   fpcrtl_val__vars(string255 s, Byte *a);
ae8a957c69fd engine to c now compiles with some manual intervention (as of bug 596)
koda
parents: 8047
diff changeset
   103
void        __attribute__((overloadable))                   fpcrtl_val__vars(string255 s, LongWord *a);
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   104
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   105
#define     fpcrtl_randomize()                              srand(time(NULL))
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   106
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   107
/*
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   108
 * Random returns a random number larger or equal to 0 and strictly less than L
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   109
 */
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   110
LongInt     fpcrtl_random(LongInt l);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   111
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   112
string255   fpcrtl_paramStr(LongInt);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   113
#define     fpcrtl_ParamStr                                 fpcrtl_paramStr
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   114
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   115
/*
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   116
 * Str returns a string which represents the value of X. X can be any numerical type.
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   117
 */
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   118
#define     fpcrtl_str(x, s)                                fpcrtl_str__vars(x, &(s))
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   119
void        __attribute__((overloadable))                   fpcrtl_str__vars(float x, string255 *s);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   120
void        __attribute__((overloadable))                   fpcrtl_str__vars(double x, string255 *s);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   121
void        __attribute__((overloadable))                   fpcrtl_str__vars(uint8_t x, string255 *s);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   122
void        __attribute__((overloadable))                   fpcrtl_str__vars(int8_t x, string255 *s);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   123
void        __attribute__((overloadable))                   fpcrtl_str__vars(uint16_t x, string255 *s);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   124
void        __attribute__((overloadable))                   fpcrtl_str__vars(int16_t x, string255 *s);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   125
void        __attribute__((overloadable))                   fpcrtl_str__vars(uint32_t x, string255 *s);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   126
void        __attribute__((overloadable))                   fpcrtl_str__vars(int32_t x, string255 *s);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   127
void        __attribute__((overloadable))                   fpcrtl_str__vars(uint64_t x, string255 *s);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   128
void        __attribute__((overloadable))                   fpcrtl_str__vars(int64_t x, string255 *s);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   129
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   130
void        fpcrtl_interlockedIncrement__vars(int *i);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   131
void        fpcrtl_interlockedDecrement__vars(int *i);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   132
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   133
#define     fpcrtl_interlockedIncrement(i)                  fpcrtl_interlockedIncrement__vars(&(i))
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   134
#define     fpcrtl_interlockedDecrement(i)                  fpcrtl_interlockedDecrement__vars(&(i))
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   135
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   136
#define     fpcrtl_InterlockedIncrement                     fpcrtl_interlockedIncrement
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   137
#define     fpcrtl_InterlockedDecrement                     fpcrtl_interlockedDecrement
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   138
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   139
void        fpcrtl_init(int argc, char** argv);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   140
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   141
int         fpcrtl_paramCount();
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   142
#define     fpcrtl_ParamCount                               fpcrtl_paramCount
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   143
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   144
string255   fpcrtl_paramStr(int i);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   145
#define     fpcrtl_ParamStr                                 fpcrtl_paramStr
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   146
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   147
int         fpcrtl_UTF8ToUnicode(PWideChar dest, PChar src, SizeInt maxLen);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   148
10566
cc90ea6448c7 map halt(t) to exit(t) rather than assert(0). all test cases except gravity pass with pas2c now
sheepluva
parents: 10131
diff changeset
   149
// #define     fpcrtl_halt(t)                                  assert(0)
cc90ea6448c7 map halt(t) to exit(t) rather than assert(0). all test cases except gravity pass with pas2c now
sheepluva
parents: 10131
diff changeset
   150
#define     fpcrtl_halt(t)                                  exit(t)
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   151
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   152
#define     fpcrtl_Load_GL_VERSION_2_0()                    1
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   153
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   154
uint32_t    __attribute__((overloadable))                   fpcrtl_lo(uint64_t);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   155
#define     fpcrtl_Lo                                       fpcrtl_lo
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   156
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   157
#define     __SET_LENGTH2(arr, d, b) do{\
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   158
                d.dim = 1;\
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   159
                arr = realloc(arr, b * sizeof(typeof(*arr)));\
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   160
                d.a[0] = b;\
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   161
            }while(0)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   162
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   163
#define     SET_LENGTH2(arr, b)                             __SET_LENGTH2(arr, arr##_dimension_info, (b))
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   164
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   165
#define     __SET_LENGTH3(arr, d, b, c) do{\
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   166
                d.dim = 2;\
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   167
                for (int i = 0; i < d.a[0]; i++) {\
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   168
                    arr[i] = realloc(arr[i], c * sizeof(typeof(**arr)));\
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   169
                }\
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   170
                if (d.a[0] > b) {\
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   171
                    for (int i = b; i < d.a[0]; i++) {\
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   172
                        free(arr[i]);\
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   173
                    }\
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   174
                    arr = realloc(arr, b * sizeof(typeof(*arr)));\
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   175
                } else if (d.a[0] < b) {\
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   176
                    arr = realloc(arr, b * sizeof(typeof(*arr)));\
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   177
                    for (int i = d.a[0]; i < b; i++) {\
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   178
                        arr[i] = malloc(c * sizeof(typeof(**arr)));\
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   179
                        memset(arr[i], 0, c * sizeof(typeof(**arr)));\
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   180
                    }\
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   181
                }\
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   182
                d.a[0] = b;\
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   183
                d.a[1] = c;\
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   184
            }while(0)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   185
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   186
#define     SET_LENGTH3(arr, b, c)                          __SET_LENGTH3(arr, arr##_dimension_info, (b), (c))
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   187
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   188
#define     fpcrtl_SetLength(...)                           macro_dispatcher(SET_LENGTH, __VA_ARGS__)(__VA_ARGS__)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   189
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   190
#endif /* SYSTEM_H_ */