author | unc0rr |
Fri, 11 May 2012 21:10:58 +0400 | |
changeset 7054 | 7e8fb07ef91c |
parent 7053 | 8c9dcaedc7a8 |
child 7060 | 861d6897917f |
permissions | -rw-r--r-- |
6875
6528171ce36d
First try to compile with clang: improve renderer a bit. The result of pas2c is still far from normal C source.
unc0rr
parents:
diff
changeset
|
1 |
#pragma once |
6528171ce36d
First try to compile with clang: improve renderer a bit. The result of pas2c is still far from normal C source.
unc0rr
parents:
diff
changeset
|
2 |
|
6971
b7b38e051b5f
add NULL definition and align types to their correct bitwidth
koda
parents:
6967
diff
changeset
|
3 |
#include <stdint.h> |
6878
0af34406b83d
Improve rendering of function types, arrays, and more
unc0rr
parents:
6875
diff
changeset
|
4 |
#include <stdbool.h> |
0af34406b83d
Improve rendering of function types, arrays, and more
unc0rr
parents:
6875
diff
changeset
|
5 |
|
6896
23b38e530967
Move all strings into constants to make them of string255 type
unc0rr
parents:
6895
diff
changeset
|
6 |
typedef union string255_ |
6883 | 7 |
{ |
6896
23b38e530967
Move all strings into constants to make them of string255 type
unc0rr
parents:
6895
diff
changeset
|
8 |
struct { |
23b38e530967
Move all strings into constants to make them of string255 type
unc0rr
parents:
6895
diff
changeset
|
9 |
char s[256]; |
23b38e530967
Move all strings into constants to make them of string255 type
unc0rr
parents:
6895
diff
changeset
|
10 |
}; |
23b38e530967
Move all strings into constants to make them of string255 type
unc0rr
parents:
6895
diff
changeset
|
11 |
struct { |
23b38e530967
Move all strings into constants to make them of string255 type
unc0rr
parents:
6895
diff
changeset
|
12 |
char len; |
23b38e530967
Move all strings into constants to make them of string255 type
unc0rr
parents:
6895
diff
changeset
|
13 |
char str[255]; |
23b38e530967
Move all strings into constants to make them of string255 type
unc0rr
parents:
6895
diff
changeset
|
14 |
}; |
6883 | 15 |
} string255; |
6889 | 16 |
typedef struct string192_ |
17 |
{ |
|
18 |
char s[193]; |
|
19 |
} string192; |
|
20 |
typedef struct string31_ |
|
21 |
{ |
|
22 |
char s[32]; |
|
23 |
} string31; |
|
6891
ab9843957664
Improve rendering of function types, ranges, and more
unc0rr
parents:
6889
diff
changeset
|
24 |
typedef struct string15_ |
ab9843957664
Improve rendering of function types, ranges, and more
unc0rr
parents:
6889
diff
changeset
|
25 |
{ |
ab9843957664
Improve rendering of function types, ranges, and more
unc0rr
parents:
6889
diff
changeset
|
26 |
char s[16]; |
ab9843957664
Improve rendering of function types, ranges, and more
unc0rr
parents:
6889
diff
changeset
|
27 |
} string15; |
6875
6528171ce36d
First try to compile with clang: improve renderer a bit. The result of pas2c is still far from normal C source.
unc0rr
parents:
diff
changeset
|
28 |
|
6971
b7b38e051b5f
add NULL definition and align types to their correct bitwidth
koda
parents:
6967
diff
changeset
|
29 |
typedef uint8_t Byte; |
b7b38e051b5f
add NULL definition and align types to their correct bitwidth
koda
parents:
6967
diff
changeset
|
30 |
typedef int8_t ShortInt; |
b7b38e051b5f
add NULL definition and align types to their correct bitwidth
koda
parents:
6967
diff
changeset
|
31 |
typedef uint16_t Word; |
b7b38e051b5f
add NULL definition and align types to their correct bitwidth
koda
parents:
6967
diff
changeset
|
32 |
typedef int16_t SmallInt; |
b7b38e051b5f
add NULL definition and align types to their correct bitwidth
koda
parents:
6967
diff
changeset
|
33 |
typedef uint32_t LongWord; |
b7b38e051b5f
add NULL definition and align types to their correct bitwidth
koda
parents:
6967
diff
changeset
|
34 |
typedef int32_t LongInt; |
b7b38e051b5f
add NULL definition and align types to their correct bitwidth
koda
parents:
6967
diff
changeset
|
35 |
typedef uint64_t QWord; |
b7b38e051b5f
add NULL definition and align types to their correct bitwidth
koda
parents:
6967
diff
changeset
|
36 |
typedef int64_t Int64; |
6878
0af34406b83d
Improve rendering of function types, arrays, and more
unc0rr
parents:
6875
diff
changeset
|
37 |
|
6971
b7b38e051b5f
add NULL definition and align types to their correct bitwidth
koda
parents:
6967
diff
changeset
|
38 |
typedef LongInt Integer; |
6878
0af34406b83d
Improve rendering of function types, arrays, and more
unc0rr
parents:
6875
diff
changeset
|
39 |
typedef float extended; |
0af34406b83d
Improve rendering of function types, arrays, and more
unc0rr
parents:
6875
diff
changeset
|
40 |
typedef float real; |
7043
7c080e5ac8d0
Some work to make more units compile after conversion to c
unc0rr
parents:
7041
diff
changeset
|
41 |
typedef float single; |
6878
0af34406b83d
Improve rendering of function types, arrays, and more
unc0rr
parents:
6875
diff
changeset
|
42 |
|
0af34406b83d
Improve rendering of function types, arrays, and more
unc0rr
parents:
6875
diff
changeset
|
43 |
typedef bool boolean; |
7043
7c080e5ac8d0
Some work to make more units compile after conversion to c
unc0rr
parents:
7041
diff
changeset
|
44 |
typedef int LongBool; |
6875
6528171ce36d
First try to compile with clang: improve renderer a bit. The result of pas2c is still far from normal C source.
unc0rr
parents:
diff
changeset
|
45 |
|
6528171ce36d
First try to compile with clang: improve renderer a bit. The result of pas2c is still far from normal C source.
unc0rr
parents:
diff
changeset
|
46 |
typedef void * pointer; |
6878
0af34406b83d
Improve rendering of function types, arrays, and more
unc0rr
parents:
6875
diff
changeset
|
47 |
typedef Byte * PByte; |
0af34406b83d
Improve rendering of function types, arrays, and more
unc0rr
parents:
6875
diff
changeset
|
48 |
typedef char * PChar; |
0af34406b83d
Improve rendering of function types, arrays, and more
unc0rr
parents:
6875
diff
changeset
|
49 |
typedef LongInt * PLongInt; |
0af34406b83d
Improve rendering of function types, arrays, and more
unc0rr
parents:
6875
diff
changeset
|
50 |
typedef Integer * PInteger; |
7038 | 51 |
typedef int * PtrInt; |
6875
6528171ce36d
First try to compile with clang: improve renderer a bit. The result of pas2c is still far from normal C source.
unc0rr
parents:
diff
changeset
|
52 |
|
6971
b7b38e051b5f
add NULL definition and align types to their correct bitwidth
koda
parents:
6967
diff
changeset
|
53 |
#ifdef __GNUG__ |
b7b38e051b5f
add NULL definition and align types to their correct bitwidth
koda
parents:
6967
diff
changeset
|
54 |
#define NULL __null |
b7b38e051b5f
add NULL definition and align types to their correct bitwidth
koda
parents:
6967
diff
changeset
|
55 |
#else /* G++ */ |
b7b38e051b5f
add NULL definition and align types to their correct bitwidth
koda
parents:
6967
diff
changeset
|
56 |
/* shield NULL definition for non-gnu parsers */ |
b7b38e051b5f
add NULL definition and align types to their correct bitwidth
koda
parents:
6967
diff
changeset
|
57 |
#ifndef __cplusplus |
b7b38e051b5f
add NULL definition and align types to their correct bitwidth
koda
parents:
6967
diff
changeset
|
58 |
#define NULL ((void *)0) |
b7b38e051b5f
add NULL definition and align types to their correct bitwidth
koda
parents:
6967
diff
changeset
|
59 |
#else |
b7b38e051b5f
add NULL definition and align types to their correct bitwidth
koda
parents:
6967
diff
changeset
|
60 |
#define NULL 0 |
b7b38e051b5f
add NULL definition and align types to their correct bitwidth
koda
parents:
6967
diff
changeset
|
61 |
#endif /* __cplusplus */ |
b7b38e051b5f
add NULL definition and align types to their correct bitwidth
koda
parents:
6967
diff
changeset
|
62 |
#endif /* G++ */ |
b7b38e051b5f
add NULL definition and align types to their correct bitwidth
koda
parents:
6967
diff
changeset
|
63 |
|
6922 | 64 |
#define new(a) __new((void **)&a, sizeof(*(a))) |
65 |
void __new(void ** p, int size); |
|
6895 | 66 |
#define dispose(a) __dispose(a, sizeof(*(a))) |
67 |
void __dispose(pointer p, int size); |
|
6894 | 68 |
|
7053 | 69 |
void * GetMem(int size); |
70 |
void FreeMem(void * p, int size); |
|
71 |
||
6894 | 72 |
#define FillChar(a, b, c) __FillChar(&(a), b, c) |
73 |
||
74 |
void __FillChar(pointer p, int size, char fill); |
|
75 |
string255 _strconcat(string255 a, string255 b); |
|
6898 | 76 |
string255 _strappend(string255 s, char c); |
77 |
string255 _strprepend(char c, string255 s); |
|
6923 | 78 |
bool _strcompare(string255 a, string255 b); |
7054 | 79 |
bool _strcomparec(string255 a, char b); |
7043
7c080e5ac8d0
Some work to make more units compile after conversion to c
unc0rr
parents:
7041
diff
changeset
|
80 |
bool _strncompare(string255 a, string255 b); |
6898 | 81 |
char * _pchar(string255 s); |
6894 | 82 |
|
6895 | 83 |
int Length(string255 a); |
84 |
string255 copy(string255 a, int s, int l); |
|
85 |
string255 delete(string255 a, int s, int l); |
|
86 |
||
6967
1224c6fb36c3
Support recurrent function calls. The code is kinda hackish and ugly, but I really spent a few hours thinking on a good solution.
unc0rr
parents:
6965
diff
changeset
|
87 |
#define STRINIT(a) {.len = sizeof(a) - 1, .str = a} |
6898 | 88 |
|
89 |
typedef int file; |
|
7043
7c080e5ac8d0
Some work to make more units compile after conversion to c
unc0rr
parents:
7041
diff
changeset
|
90 |
typedef int TextFile; |
6898 | 91 |
extern int FileMode; |
92 |
extern int IOResult; |
|
93 |
||
6902
7d4e5ce73b98
Make pas2c even smarter. Now uIO.c compiles fine, and only 1 warning when compiled with -Wall (clang).
unc0rr
parents:
6898
diff
changeset
|
94 |
#define assign(a, b) assign_(&(a), b) |
7d4e5ce73b98
Make pas2c even smarter. Now uIO.c compiles fine, and only 1 warning when compiled with -Wall (clang).
unc0rr
parents:
6898
diff
changeset
|
95 |
void assign_(int * f, string255 fileName); |
6898 | 96 |
void reset(int f, int size); |
97 |
#define BlockRead(a, b, c, d) BlockRead_(a, &(b), c, &(d)) |
|
98 |
void BlockRead_(int f, void * p, int size, int * sizeRead); |
|
7053 | 99 |
#define BlockWrite(a, b, c) BlockWrite_(a, &(b), c) |
100 |
void BlockWrite_(int f, void * p, int size); |
|
6898 | 101 |
void close(int f); |
7002 | 102 |
|
7054 | 103 |
void write(string255 s); |
104 |
||
7053 | 105 |
bool DirectoryExists(string255 dir); |
106 |
bool FileExists(string255 filename); |
|
107 |
||
7002 | 108 |
bool odd(int i); |
7038 | 109 |
|
110 |
||
111 |
typedef int TThreadId; |
|
112 |
void ThreadSwitch(); |
|
113 |
#define InterlockedIncrement(a) __InterlockedIncrement(&(a)) |
|
114 |
#define InterlockedDecrement(a) __InterlockedDecrement(&(a)) |
|
115 |
void __InterlockedIncrement(int * a); |
|
116 |
void __InterlockedDecrement(int * a); |
|
117 |
||
118 |
bool Assigned(void * a); |
|
119 |
||
7054 | 120 |
void randomize(); |
7038 | 121 |
int random(int max); |
122 |
int abs(int i); |
|
7041 | 123 |
double sqr(double n); |
124 |
double sqrt(double n); |
|
125 |
int trunc(double n); |
|
7043
7c080e5ac8d0
Some work to make more units compile after conversion to c
unc0rr
parents:
7041
diff
changeset
|
126 |
int round(double n); |
7045 | 127 |
|
128 |
string255 ParamStr(int n); |
|
129 |
int ParamCount(); |
|
7054 | 130 |
|
131 |
#define val(a, b) _val(a, (LongInt*)&(b)) |
|
132 |
void _val(string255 str, LongInt * a); |