Skip to content

Commit

Permalink
c89 backend
Browse files Browse the repository at this point in the history
  • Loading branch information
thradams committed Dec 15, 2024
1 parent d657032 commit 49a1bd4
Show file tree
Hide file tree
Showing 29 changed files with 49,122 additions and 1,610 deletions.
21 changes: 8 additions & 13 deletions manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,6 @@ C89 not implemented yet. TODO!
#include <stdio.h>

#define debug(...) fprintf(stderr, __VA_ARGS__)
#pragma expand debug

int main()
{
Expand Down Expand Up @@ -584,7 +583,6 @@ https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1441.htm
default: cbrtl \
)(X)

#pragma expand cbrt

int main(void)
{
Expand Down Expand Up @@ -910,7 +908,6 @@ https://open-std.org/JTC1/SC22/WG14/www/docs/n3007.htm
typeof(a) temp = a; a = b; b = temp; \
} while (0)

#pragma expand SWAP

int main()
{
Expand Down Expand Up @@ -1287,11 +1284,6 @@ Implemented.
#define SDEF(sname, ...) S sname __VA_OPT__(= { __VA_ARGS__ })
#define EMP

/*maybe this could be automatic if <C23*/
#pragma expand F
#pragma expand G
#pragma expand SDEF
#pragma expand EMP

void f(int i, ...) {}

Expand Down Expand Up @@ -1359,7 +1351,6 @@ https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2778.pdf
### Obsolete implicitly octal literals
```c
static_assert(0o52 == 052);
Expand All @@ -1373,7 +1364,8 @@ int main()
```

c89 backend (all constantes are decimals)

https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3353.htm

### Extension - defer

Expand Down Expand Up @@ -1535,10 +1527,10 @@ catch

### Extension Literal function - lambdas

Lambdas without capture where implemented using a syntax similar of compound literal for function pointer.
Lambdas without capture where implemented using a compound literal syntax.
Since, we cannot have compound literal of function types (only pointer to function) the
syntax can be reused.

Lambdas are the most complex code transformation so far because sometimes function scope types needs to be transformed to file scope. This is important because manual lambda capture
is something we want to use in function scope.

For instance:

Expand Down Expand Up @@ -1578,6 +1570,8 @@ void create_app(char * appname)
```

Code generation is already working, but static analysis
is not implemented.

### Extension #pragma dir

Expand Down Expand Up @@ -1620,6 +1614,7 @@ _is_scalar
Arithmetic types, pointer types, and the nullptr_t type are collectively called scalar types

```

Note: Type traits that can be easily created with \_Generic will be removed.
_
### Extension - Object lifetime checks
Expand Down
45 changes: 45 additions & 0 deletions out/src/console.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
struct _iobuf {
void * _Placeholder;
};


void *GetStdHandle(unsigned long nStdHandle);
int GetConsoleMode(void * hConsoleHandle, unsigned long * lpMode);
int SetConsoleMode(void * hConsoleHandle, unsigned long dwMode);
int SetConsoleOutputCP(unsigned int wCodePageID);

unsigned char enable_vt_mode(void)
{
unsigned long mode = 0;
void * h_out = GetStdHandle(((unsigned long) -11));
if (h_out != ((void *)(long) -1) && GetConsoleMode(h_out, &mode) != 0 && SetConsoleMode(h_out, mode = 4) != 0 && SetConsoleOutputCP(65001) != 0)
{
return 1;
}
return 0;
}

int _kbhit(void);

int c_kbhit(void)
{
return _kbhit();
}

int _getch(void);

int c_getch(void)
{
return _getch();
}

int puts(char * _Buffer);
int fflush(struct _iobuf * _Stream);
struct _iobuf *__acrt_iob_func(unsigned int _Ix);

void c_clrscr()
{
puts("\x1b[2J\x1b[1;1H");
fflush((__acrt_iob_func(1)));
}

Loading

0 comments on commit 49a1bd4

Please sign in to comment.