Advertisement
Guest User

Untitled

a guest
Apr 20th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.87 KB | None | 0 0
  1. // Foreign includes
  2. #include <stdio.h>
  3.  
  4. // Forward declarations
  5. typedef struct T T;
  6. typedef struct ConstVector ConstVector;
  7. typedef struct Any Any;
  8.  
  9. #line 2 "<builtin>"
  10. typedef enum TypeKind {
  11. TYPE_NONE,
  12. TYPE_VOID,
  13. TYPE_BOOL,
  14. TYPE_CHAR,
  15. TYPE_UCHAR,
  16. TYPE_SCHAR,
  17. TYPE_SHORT,
  18. TYPE_USHORT,
  19. TYPE_IN
  20. "\"
  21. typedef enum Color {
  22. COLOR_NONE,
  23. COLOR_RED,
  24. COLOR_GREEN,
  25. COLOR_BLUE,
  26. NUM_COLORS,
  27. } Color;
  28.  
  29. #line 27 "<builtin>"
  30. struct TypeFieldInfo {
  31. char const ((*name));
  32. typeid type;
  33. int offset;
  34. };
  35.  
  36. struct TypeInfo {
  37. TypeKind kind;
  38. int size;
  39. int align;
  40. char const ((*name));
  41. int count;
  42.  
  43.  
  44. };
  45. ;
  46.  
  47. #line 14 "..\\ion\\test1.ion"
  48. extern SomeIncompleteType (*incomplete_ptr);
  49.  
  50. #line 27
  51. #define PI (3.140000f)
  52.  
  53. #line 28
  54. #define PI2 ((PI) + (PI))
  55.  
  56. #define U8 ((uint8)(42))
  57.  
  58. extern char c;
  59.  
  60. #line 33
  61. extern uchar uc;
  62.  
  63. #line 34
  64. extern schar sc;
  65.  
  66. #define N ((((char)(42)) + (8)) != (0))
  67.  
  68. #line 136
  69. uchar h(void);
  70.  
  71. #line 38
  72. typedef int (A[(1) + ((2) * (h)())))]);
  73.  
  74. extern char (*code);
  75.  
  76. #line 49
  77. struct S1 {
  78. int a;
  79. int const (b);
  80. };
  81.  
  82. struct S2 {
  83. S1 s1;
  84. };
  85.  
  86. void f10(int (a[3]));
  87.  
  88. #line 62
  89. void test_arrays(void);
  90.  
  91. #line 68
  92. void test_loops(void);
  93.  
  94. #line 102
  95. void test_nonmodifiable);
  96.  
  97. #line 114
  98. struct UartCtrl {
  99. bool tx_enable;
  100. #line 115
  101. bool rx_enable;
  102. };
  103.  
  104. #define UART_CTRL_REG ((uint *)(0x12345678))
  105.  
  106. uint32 pack);
  107.  
  108. #line 124
  109. UartCtrl unpack);
  110.  
  111. #line 128
  112. void test_uart(void);
  113.  
  114. #line 205
  115. struct Vector {
  116. int x;
  117. #line 206
  118. int y;
  119. };
  120.  
  121. #line 163
  122. typedef IntOrPtr U;
  123.  
  124. #line 169
  125. union IntOrPtr {
  126. int i;
  127. int (*p);
  128. };
  129.  
  130. #line 146
  131. int g(U u);
  132.  
  133. #line 150
  134. void k(void (*vp),);
  135.  
  136. #line 155
  137. void f1(void);
  138.  
  139. #line 160
  140. void f3(int (a[]));
  141.  
  142. #line 165
  143. int example_test);
  144.  
  145. #line 221
  146. int fact_rec(int n);
  147.  
  148. #line 213
  149. int fact_iter(int n);
  150.  
  151. #line 174
  152. extern char const ((escape_to_char[256]));
  153.  
  154. #line 184
  155. extern int (a2[11]);
  156.  
  157. #line 187
  158. int is_even);
  159.  
  160. #line 203
  161. extern int i;
  162.  
  163. #line 209
  164. void f2(Vector v);
  165.  
  166. #line 231
  167. extern T (*p);
  168.  
  169. #line 229
  170. #define M ((1) + (sizeof(p)))
  171.  
  172. #line 233
  173. struct T {
  174. int (a[M]);
  175. };
  176.  
  177. #line 245
  178. extern char const ((*(color_names[NUM_COLORS])));
  179.  
  180. #line 252
  181. void test_enum(void);
  182.  
  183. #line 261
  184. void test_assign(void);
  185.  
  186. #line 284
  187. void benchmark(int n);
  188.  
  189. #line 291
  190. int va_test(int );
  191.  
  192. #line 295
  193. typedef int (*F)(int, ...);
  194.  
  195. void test_lits(void);
  196.  
  197. #line 314
  198. void test_ops(void);
  199.  
  200. #line 344
  201. #define IS_DEBUG (true)
  202.  
  203. void test_bool(void);
  204.  
  205. #line 353
  206. int test_ctrl(void);
  207.  
  208. #line 363
  209. extern int const (j);
  210.  
  211. #line 364
  212. extern int const ((*q));
  213.  
  214. #line 365
  215. extern Vector const (cv);
  216.  
  217. void f4);
  218.  
  219. #line 370
  220. struct ConstVector {
  221. int const (x);
  222. #line 371
  223. int const (y);
  224. };
  225. ;
  226.  
  227. #line 377
  228. void test_convert);
  229.  
  230. #line 385
  231. void test_const(void);
  232.  
  233. #line 408
  234. void test_init(void);
  235.  
  236. #line 421
  237. void test_sizeof(void);
  238.  
  239. #line 429
  240. void test_cast(void);
  241.  
  242. #line 438
  243. struct Any {
  244. void (*ptr);
  245. typeid type;
  246. };
  247.  
  248. void print_any);
  249.  
  250. #line 461
  251. void print_type);
  252.  
  253. #line 456
  254. void println_any);
  255.  
  256. #line 485
  257. void println_type);
  258.  
  259. #line 490
  260. void print_typeinfo);
  261.  
  262. #line 514
  263. void println_typeinfo);
  264.  
  265. #line 519
  266. void test_typeof(void);
  267.  
  268. #line 534
  269. void test_typeinfo);
  270.  
  271. #line 543
  272. int main(int argc,);
  273. // Typeinfo
  274. TypeInfo *typeinfo_table[76] = {
  275. [0] = NULL, // No associated type
  276. [1] = &(TypeInfo){TYPE_VOID, .name = "void"},
  277. [2] = &(TypeInfo){TYPE_BOOL, .size = sizeof(bool), .align = sizeof(bool), .name = "bool"},
  278. [3] = &(TypeInfo){TYPE_CHAR, .size = sizeof(char), .align = sizeof(char), .name = "char"},
  279. [4] = &(TypeInfo){TYPE_UCHAR, .size = sizeof(uchar), .align = sizeof(uchar), .name = "uchar"},
  280. [5] = &(TypeInfo){TYPE_SCHAR, .size = sizeof(schar), .align = sizeof(schar), .name = "schar"},
  281. [6] = &(TypeInfo){TYPE_SHORT, .size = sizeof(short), .align = sizeof(short), .name = "short"},
  282. [7] = &(TypeInfo){TYPE_USHORT, .size = sizeof(ushort), .align = sizeof(ushort), .name = "ushort"},
  283. [8] = &(TypeInfo){TYPE_INT, .size = sizeof(int), .align = sizeof(int), .name = "int"},
  284. [9] = &(TypeInfo){TYPE_UINT, .size = sizeof(uint), .align = sizeof(uint), .name = "uint"},
  285. [10] = &(TypeInfo){TYPE_LONG, .size = sizeof(long), .align = sizeof(long), .name = "long"},
  286. [11] = &(TypeInfo){TYPE_ULONG, .size = sizeof(ulong), .align = sizeof(ulong), .name = "ulong"},
  287. [12] = &(TypeInfo){TYPE_LLONG, .size = sizeof(llong), .align = sizeof(llong), .name = "llong"},
  288. [13] = &(TypeInfo){TYPE_ULLONG, .size = sizeof(ullong), .align = sizeof(ullong), .name = "ullong"},
  289. [14] = &(TypeInfo){TYPE_FLOAT, .size = sizeof(float), .align = sizeof(float), .name = "float"},
  290. [15] = &(TypeInfo){TYPE_DOUBLE, .size = sizeof(double), .align = sizeof(double), .name = "double"},
  291. [16] = &(TypeInfo){TYPE_PTR, .size = sizeof(void *), .align = alignof(void *), .base = 1},
  292. [17] = NULL, // Enum
  293. [18] = &(TypeInfo){TYPE_STRUCT, .size = sizeof(TypeFieldInfo), .align = alignof(TypeFieldInfo), .name = "TypeFieldInfo", .num_fields = 3, .fields = (TypeFieldInfo[]) {
  294. {"name", .type = 31, .offset = offsetof(TypeFieldInfo, name)},
  295. {"type", .type = 8, .offset = offsetof(TypeFieldInfo, type)},
  296. {"offset", .type = 8, .offset = offsetof(TypeFieldInfo, offset)},
  297. }},
  298. [19] = &(TypeInfo){TYPE_STRUCT, .size = sizeof(TypeInfo), .align = alignof(TypeInfo), .name = "TypeInfo", .num_fields = 8, .fields = (TypeFieldInfo"S{"{"b", .type = 43, .offset = offsetof(S1, b)},
  299. }},
  300. [22] = &(TypeInfo){TYPE_STRUCT, .size = sizeof(S2), .align = alignof(S2), .name = "S2", .num_fields = 1, .fields = (TypeFieldInfo[]) {
  301. {"s1", .type = 21, .offset = offsetof(S2, s1)},
  302. }},
  303. [23] = &(TypeInfo){TYPE_STRUCT, .size = sizeof(UartCtrl), .align = alignof(UartCtrl), .name = "UartCtrl", .num_fields = 2, .fields = (TypeFieldInfo[]) {
  304. {"tx_enable", .type = 2, .offset = offsetof(UartCtrl, tx_enable)},
  305. {"rx_enable", .type = 2, .offset = offsetof(UartCtrl, rx_enable)},
  306. }},
  307. [24] = &(TypeInfo){TYPE_UNION, .size = sizeof(IntOrPtr), .align = alignof(IntOrPtr), .name = "IntOrPtr", .num_fields = 2, .fields = (TypeFieldInfo[]) {
  308. {"i", .type = 8, .offset = offsetof(IntOrPtr, i)},
  309. {"p", .type = 45, .offset = offsetof(IntOrPtr, p)},
  310. }},
  311. [25] = &(TypeInfo){TYPE_STRUCT, .size = sizeof(Vector), .align = alignof(Vector), .name = "Vector", .num_fields = 2, .fields = (TypeFieldInfo[]) {
  312. {"x", .type = 8, .offset = offsetof(Vector, x)},
  313. {"y", .type = 8, .offset = offsetof(Vector, y)},
  314. }},
  315. [26] = &(TypeInfo){TYPE_STRUCT, .size = sizeof(T), .align = alignof(T), .name = "T", .num_fields = 1, .fields = (TypeFieldInfo[]) {
  316. {"a", .type = 60, .offset = offsetof(T, a)},
  317. }},
  318. [27] = NULL, // Enum
  319. [28] = &(TypeInfo){TYPE_STRUCT, .size = sizeof(ConstVector), .align = alignof(ConstVector), .name = "ConstVector", .num_fields = 2, .fields = (TypeFieldInfo[]) {
  320. {"x", .type = 43, .offset = offsetof(ConstVector, x)},
  321. {"y", .type = 43, .offset = offsetof(ConstVector, y)},
  322. }},
  323. [29] = &(TypeInfo){TYPE_STRUCT, .size = sizeof(Any), .align = alignof(Any), .name = "Any", .num_fields = 2, .fields = (TypeFieldInfo[]) {
  324. {"ptr", .type = 16, .offset = offsetof(Any, ptr)},
  325. {"type", .type = 8, .offset = offsetof(Any, type)},
  326. }},
  327. [30] = &(TypeInfo){TYPE_CONST, .size = sizeof(char const ), .align = alignof(char const ), .base = 3},
  328. [31] = &(TypeInfo){TYPE_PTR, .size = sizeof(void *), .align = alignof(void *), .base = 30},
  329. [32] = &(TypeInfo){TYPE_PTR, .size = sizeof(void *), .align = alignof(void *), .base = 18},
  330. [33] = &(TypeInfo){TYPE_PTR, .size = sizeof(void *), .align = alignof(void *), .base = 19},
  331. [34] = &(TypeInfo){TYPE_PTR, .size = sizeof(void *), .align = alignof(void *), .base = 33},
  332. [35] = NULL, // Func
  333. [36] = NULL, // Func
  334. [37] = NULL, // Func
  335. [38] = NULL, // Func
  336. [39] = &(TypeInfo){TYPE_PTR, .size = sizeof(void *), .align = alignof(void *), .base = 20},
  337. [40] = NULL, // Func
  338. [41] = &(TypeInfo){TYPE_ARRAY, .size = sizeof(int [3]), .align = alignof(int [3]), .base = 8, .count = 3},
  339. [42] = &(TypeInfo){TYPE_PTR, .size = sizeof(void *), .align = alignof(void *), .base = 3},
  340. [43] = &(TypeInfo){TYPE_CONST, .size = sizeof(int const ), .align = alignof(int const ), .base = 8},
  341. [44] = NULL, // Func
  342. [45] = &(TypeInfo){TYPE_PTR, .size = sizeof(void *), .align = alignof(void *), .base = 8},
  343. [46] = NULL, // Func
  344. [47] = NULL, // Incomplete array type
  345. [48] = &(TypeInfo){TYPE_PTR, .size = sizeof(void *), .align = alignof(void *), .base = 9},
  346. [49] = NULL, // Func
  347. [50] = NULL, // Func
  348. [51] = &(TypeInfo){TYPE_PTR, .size = sizeof(void *), .align = alignof(void *), .base = 25},
  349. [52] = NULL, // Func
  350. [53] = NULL, // Func
  351. [54] = NULL, // Func
  352. [55] = NULL, // Func
  353. [56] = &(TypeInfo){TYPE_ARRAY, .size = sizeof(char const [256]), .align = alignof(char const [256]), .base = 30, .count = 256},
  354. [57] = &(TypeInfo){TYPE_ARRAY, .size = sizeof(int [11]), .align = alignof(int [11]), .base = 8, .count = 11},
  355. [58] = NULL, // Func
  356. [59] = &(TypeInfo){TYPE_PTR, .size = sizeof(void *), .align = alignof(void *), .base = 26},
  357. [60] = &(TypeInfo){TYPE_ARRAY, .size = sizeof(int [9]), .align = alignof(int [9]), .base = 8, .count = 9},
  358. [61] = &(TypeInfo){TYPE_ARRAY, .size = sizeof(char const (*[4])), .align = alignof(char const (*[4])), .base = 31, .count = 4},
  359. [62] = NULL, // Func
  360. [63] = NULL, // Func
  361. [64] = &(TypeInfo){TYPE_PTR, .size = sizeof(void *), .align = alignof(void *), .base = 43},
  362. [65] = &(TypeInfo){TYPE_CONST, .size = sizeof(Vector const ), .align = alignof(Vector const ), .base = 25},
  363. [66] = NULL, // Func
  364. [67] = NULL, // Func
  365. [68] = NULL, // Func
  366. [69] = &(TypeInfo){TYPE_CONST, .size = sizeof(float const ), .align = alignof(float const ), .base = 14},
  367. [70] = &(TypeInfo){TYPE_PTR, .size = sizeof(void *), .align = alignof(void *), .base = 69},
  368. [71] = &(TypeInfo){TYPE_PTR, .size = sizeof(void *), .align = alignof(void *), .base = 14},
  369. [72] = &(TypeInfo){TYPE_PTR, .size = sizeof(void *), .align = alignof(void *), .base = 45},
  370. [73] = &(TypeInfo){TYPE_ARRAY, .size = sizeof(int const (*[42])), .align = alignof(int const (*[42])), .base = 64, .count = 42},
  371. [74] = &(TypeInfo){TYPE_PTR, .size = sizeof(void *), .align = alignof(void *), .base = 31},
  372. [75] = NULL, // Func
  373. };
  374.  
  375. int num_typeinfos = 76;
  376. TypeInfo **typeinfos = typeinfo_table;
  377. // Definitions
  378. #line 50 "<builtin>"
  379. TypeInfo (*get_typeinfo)) {
  380. if ((typeinfos) && ((type) < (num_typeinfos))) {
  381. return typeinfos[type];
  382. } else {
  383. return NULL;
  384. }
  385. }
  386.  
  387. SomeIncompleteType (*incomplete_ptr);
  388. char c = 1; = 11;
  389. char (*code) =
  390. "\n"
  391. "#include <stdio.h>\n"
  392. "\n"
  393. "int main(int argc, char **argv) {\n"
  394. " printf(\"Hello, world!\\n\");\n"
  395. " return 0;\n"
  396. "}\n";
  397. #line 58 "..\\ion\\test1.ion"
  398. void f10(int (a[3])) {
  399. a[1] = 42;
  400. }
  401.  
  402. void test_arrays(void) {
  403. int (a[3]) = {1, 2, 3};
  404. #line 65
  405. (f10)(a);
  406. }
  407.  
  408. void test_loops(void) {
  409. #line 71
  410. switch (0) {
  411. default: {
  412. if (1) {
  413. break;
  414. }
  415. for (;;) {
  416. continue;
  417. }
  418. break;
  419. }
  420. }
  421. while (0) {
  422. }
  423. for (int i = 0; (i) < (10); i++) {
  424. }
  425. for (;;) {
  426. break;
  427. }
  428. for (int i = 0;;) {
  429. break;
  430. }
  431. for (; 0;) {
  432. }
  433. for (int i = 0;; i++) {
  434. break;
  435. }
  436. int i = 0;
  437. for (;; i++) {
  438. break;
  439. }
  440. }
  441.  
  442. #line 102
  443. void test_nonmodifiable) {
  444. S1 s1;
  445. s1.a = 0;
  446. #line 107
  447. S2 s2;
  448. s2.s1.a = 0;
  449. }
  450.  
  451. #line 120
  452. uint32 pack) {
  453. return ((ctrl.tx_enable) & (1)) | (((ctrl.rx_enable) & (1)) << (1));
  454. }
  455.  
  456. UartCtrl unpack) {
  457. return (UartCtrl){.tx_enable = (word) & (0x1), .rx_enable = ((word) & (0x2)) >> (1)};
  458. }
  459.  
  460. void test_uart(void) {
  461. bool tx_enable = (unpack)(*(UART_CTRL_REG)).tx_enable;
  462. *(UART_CTRL_REG) = (pack)((UartCtrl){.tx_enable = !(tx_enable), .rx_enable = false});
  463. UartCtrl ctrl = (unpack)(*(UART_CTRL_REG));
  464. ctrl.rx_enable = true;
  465. *(UART_CTRL_REG) = (pack)(ctrl);
  466. }
  467.  
  468. uchar h(void) {
  469. (Vector){.x = 1, .y = 2}.x = 42;
  470. Vector (*v) = &((Vector){1, 2});
  471. v->x = 42;
  472. int (*p) = &((int){0});
  473. ulong x = ((uint){1}) + ((long){2});
  474. int y = +(c);
  475. return (uchar)(x);
  476. }
  477.  
  478. int g(U u) {
  479. return u.i;
  480. }
  481.  
  482. void k(void (*vp),) {
  483. vp = ip;
  484. ip = vp;
  485. }
  486.  
  487. void f1(void) {
  488. int (*p) = &((int){0});
  489. *(p) = 42;
  490. }
  491.  
  492. void f3(int (a[])) {
  493. }
  494.  
  495. #line 165
  496. int example_test) {
  497. return ((fact_rec)(10)) == ((fact_iter)(10));
  498. }
  499.  
  500. char const ((escape_to_char[256])) = {['n'] = '\n', ['r'] = '\r', ['t'] = '\t', ['v'] = '\v', ['b'] = '\b', ['a'] = '\a', ['0'] = 0};
  501. int (a2[11]) = {1, 2, 3, [10] = 4};
  502. #line 187
  503. int is_even) {
  504. int b = 0;
  505. switch (digit) {
  506. case 0:
  507. case 2:
  508. case 4:
  509. case 6:
  510. case 8: {
  511. #line 191
  512. b = 1;
  513. break;
  514. }
  515. }
  516. #line 193
  517. return b;
  518. }
  519.  
  520. int i;
  521. #line 209
  522. void f2(Vector v) {
  523. v = (Vector){0};
  524. }
  525.  
  526. int fact_iter(int n) {
  527. int r = 1;
  528. for (int i = 0; (i) <= (n); i++) {
  529. r *= i;
  530. }
  531. return r;
  532. }
  533.  
  534. int fact_rec(int n) {
  535. if ((n) == (0)) {
  536. return 1;
  537. } else {
  538. return (n) * ((fact_rec)((n) - (1)));
  539. }
  540. }
  541.  
  542. T (*p);
  543. char const ((*(color_names[NUM_COLORS]))) = {[COLOR_NONE] = "none", [COLOR_RED] = "red", [COLOR_GREEN] = "green", [COLOR_BLUE] = "blue"};
  544. #line 252
  545. void test_enum(void) {
  546. Color a = COLOR_RED;
  547. Color b = COLOR_RED;
  548. int c = (a) + (b);
  549. int i = a;
  550. a = i;
  551. (printf)("%d %d %d %d\n", COLOR_NONE, COLOR_RED, COLOR_GREEN, COLOR_BLUE);
  552. }
  553.  
  554. void test_assign(void) {
  555. int i = 0;
  556. float f = 3.140000f;
  557. int (*p) = &(i);
  558. i++;
  559. i--;
  560. p++;
  561. p--;
  562. p += 1;
  563. i /= 2;
  564. i *= 123;
  565. i %= 3;
  566. i <<= 1;
  567. i >>= 2;
  568. i &= 0xff;
  569. i |= 0xff00;
  570. i ^= 0xff0;
  571. }
  572.  
  573. #line 284
  574. void benchmark(int n) {
  575. int r = 1;
  576. for (int i = 1; (i) <= (n); i++) {
  577. r *= i;
  578. }
  579. }
  580.  
  581. int va_test(int ) {
  582. return 0;
  583. }
  584.  
  585. #line 297
  586. void test_lits(void) {
  587. float f = 3.140000f;
  588. double d = 3.140000;
  589. int i = 1;
  590. uint u = 0xffffffffu;
  591. long l = 1l;
  592. ulong ul = 1ul;
  593. llong ll = 0x100000000ll;
  594. ullong ull = 0xffffffffffffffffull;
  595. uint x1 = 0xffffffff;
  596. llong x2 = 4294967295;
  597. ullong x3 = 0xffffffffffffffff;
  598. int x4 = (0xaa) + (0x55);
  599. }
  600.  
  601. #line 314
  602. void test_ops(void) {
  603. float pi = 3.140000f;
  604. float f = 0.000000f;
  605. f = +(pi);
  606. f = -(pi);
  607. int n = -(1);
  608. n = ~(n);
  609. f = ((f) * (pi)) + (n);
  610. f = (pi) / (pi);
  611. n = (3) % (2);
  612. n = (n) + ((uchar)(1));
  613. int (*p) = &(n);
  614. p = (p) + (1);
  615. n = (int)(((p) + (1)) - (p));
  616. n = (n) << (1);
  617. n = (n) >> (1);
  618. int b = ((p) + (1)) > (p);
  619. b = ((p) + (1)) >= (p);
  620. b = ((p) + (1)) < (p);
  621. b = ((p) + (1)) <= (p);
  622. b = ((p) + (1)) == (p);
  623. b = (1) > (2);
  624. b = (1.230000f) <= (pi);
  625. n = 0xff;
  626. b = (n) & (~(1));
  627. b = (n) & (1);
  628. b = ((n) & (~(1))) ^ (1);
  629. b = (p) && (pi);
  630. }
  631.  
  632. #line 346
  633. void test_bool(void) {
  634. bool b = false;
  635. b = true;
  636. int i = 0;
  637. i = IS_DEBUG;
  638. }
  639.  
  640. int test_ctrl(void) {
  641. switch (1) {
  642. case 0: {
  643. return 0;
  644. break;
  645. }
  646. default: {
  647. #line 358
  648. return 1;
  649. break;
  650. }
  651. }
  652. }
  653.  
  654. int const (j);
  655. int const ((*q));
  656. Vector const (cv);
  657. void f4) {
  658. }
  659.  
  660. #line 374
  661. void f5) {
  662. }
  663.  
  664. void test_convert) {
  665. int const ((*a)) = 0;
  666. int (*b) = 0;
  667. a = b;
  668. void (*p) = 0;
  669. (f5)(p);
  670. }
  671.  
  672. void test_const(void) {
  673. ConstVector cv2 = {1, 2};
  674. #line 388
  675. int i = 0;
  676. i = 1;
  677. #line 392
  678. int x = cv.x;
  679. #line 394
  680. char c = escape_to_char[0];
  681. #line 396
  682. (f4)(escape_to_char);
  683. char const ((*p)) = (char const (*))(0);
  684. p = (escape_to_char) + (1);
  685. char (*q) = (char *)(escape_to_char);
  686. c = q['n'];
  687. #line 402
  688. p = (char const (*))(1);
  689. #line 405
  690. i = (int)((ullong)(p));
  691. }
  692.  
  693. void test_init(void) {
  694. int x = (int const )(0);
  695. int y;
  696. y = 0;
  697. int z = 42;
  698. int (a[3]) = {1, 2, 3};
  699. #line 416
  700. for (ullong i = 0; (i) < (10); i++) {
  701. (printf)("%llu\n", i);
  702. }
  703. }
  704.  
  705. void test_sizeof(void) {
  706. int i = 0;
  707. ullong n = sizeof(i);
  708. n = sizeof(int);
  709. n = sizeof(int);
  710. n = sizeof(int *);
  711. }
  712.  
  713. void test_cast(void) {
  714. int (*p) = 0;
  715. uint64 a = 0;
  716. #line 433
  717. a = (uint64)(p);
  718. #line 435
  719. p = (int *)(a);
  720. }
  721.  
  722. #line 443
  723. void print_any) {
  724. switch (any.type) {
  725. case 8: {
  726. (printf)("%d", *((int const (*))(any.ptr)));
  727. break;
  728. }
  729. case 14: {
  730. #line 448
  731. (printf)("%f", *((float const (*))(any.ptr)));
  732. break;
  733. }
  734. default: {
  735. #line 450
  736. (printf)("<unknown>");
  737. break;
  738. }
  739. }
  740. #line 452
  741. (printf)(": ");
  742. (print_type)(any.type);
  743. }
  744.  
  745. void println_any) {
  746. (print_any)(any);
  747. (printf)("\n");
  748. }
  749.  
  750. void print_type) {
  751. TypeInfo (*typeinfo) = (get_typeinfo)(type);
  752. if (!(typeinfo)) {
  753. (printf)("<typeid %d>", type);
  754. }
  755. switch (typeinfo->kind) {
  756. case TYPE_PTR: {
  757. (print_type)(typeinfo->base);
  758. (printf)("*");
  759. break;
  760. }
  761. case TYPE_CONST: {
  762. #line 471
  763. (print_type)(typeinfo->base);
  764. (printf)(" const");
  765. break;
  766. }
  767. case TYPE_ARRAY: {
  768. #line 474
  769. (print_type)(typeinfo->base);
  770. (printf)("[%d]", typeinfo->count);
  771. break;
  772. }
  773. default: {
  774. #line 477
  775. if (typeinfo->name) {
  776. (printf)("%s", typeinfo->name);
  777. } else {
  778. (printf)("typeid %d>", type);
  779. }
  780. break;
  781. }
  782. }
  783. }
  784.  
  785. #line 485
  786. void println_type) {
  787. (print_type)(type);
  788. (printf)("\n");
  789. }
  790.  
  791. void print_typeinfo) {
  792. TypeInfo (*typeinfo) = (get_typeinfo)(type);
  793. if (!(typeinfo)) {
  794. (printf)("<typeid %d>", type);
  795. return;
  796. }
  797. (printf)("<");
  798. (print_type)(type);
  799. (printf)(" size=%d align=%d", typeinfo->size, typeinfo->align);
  800. switch (typeinfo->kind) {
  801. case TYPE_STRUCT:
  802. case TYPE_UNION: {
  803. (printf)(" %s={ ", ((typeinfo->kind) == (TYPE_STRUCT) ? "struct" : "union"));
  804. for (int i = 0; (i) < (typeinfo->num_fields); i++) {
  805. TypeFieldInfo field = typeinfo->fields[i];
  806. (printf)("@offset(%d) %s: ", field.offset, field.name);
  807. (print_type)(field.type);
  808. (printf)("; ");
  809. }
  810. (printf)("}");
  811. break;
  812. }
  813. }
  814. #line 511
  815. (printf)(">");
  816. }
  817.  
  818. void println_typeinfo) {
  819. (print_typeinfo)(type);
  820. (printf)("\n");
  821. }
  822.  
  823. void test_typeof(void) {
  824. int i = 42;
  825. float f = 3.140000f;
  826. int (*p) = &(i);
  827. #line 524
  828. int type1 = 8;
  829. int type2 = 8;
  830. int type3 = 8;
  831. int type4 = 45;
  832. #line 529
  833. (println_any)((Any){&(i), 8});
  834. (println_any)((Any){&(f), 14});
  835. (println_any)((Any){&(p), 45});
  836. }
  837.  
  838. void test_typeinfo) {
  839. (println_typeinfo)(8);
  840. (println_typeinfo)(23);
  841. (println_type)(8);
  842. (println_type)(64);
  843. (println_type)(73);
  844. (println_type)(23);
  845. }
  846.  
  847. int main(int argc,) {
  848. if ((argv) == (0)) {
  849. (printf)("argv is null\n");
  850. }
  851. (test_typeof)();
  852. (test_loops)();
  853. (test_sizeof)();
  854. (test_assign)();
  855. (test_enum)();
  856. (test_arrays)();
  857. (test_cast)();
  858. (test_init)();
  859. (test_lits)();
  860. (test_const)();
  861. (test_bool)();
  862. (test_ops)();
  863. (test_typeinfo)();
  864. (getchar)();
  865. return 0;
  866. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement