Skip to content

Commit 72de394

Browse files
Typescript migration, code organization and responsive design. (#1)
* Typescript migration, code organization and responsive design. * Update README * Add more examples and reorder dialog
1 parent 5e58a03 commit 72de394

38 files changed

+2530
-1861
lines changed

.github/workflows/deploy.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ jobs:
2121
- name: Checkout repository
2222
uses: actions/checkout@v4
2323

24-
- name: Set up Node.js
25-
uses: actions/setup-node@v4
24+
- name: Set up Bun
25+
uses: oven-sh/setup-bun@v2
2626
with:
27-
node-version: '20'
27+
bun-version: latest
2828

2929
- name: Run setup script
30-
run: npm run setup
30+
run: bun run setup
3131

3232
- name: Build project
33-
run: npm run build
33+
run: bun run build
3434

3535
- name: Deploy to GitHub Pages
3636
uses: peaceiris/actions-gh-pages@v4

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
## Quick Start
66

77
```bash
8-
npm run setup # Install deps & download clang (~30MB, one-time)
9-
npm run dev # Start dev server
10-
npm run build # Build for production
11-
npm run preview # Preview production build
8+
bun run setup # Install deps & download clang (~30MB, one-time)
9+
bun run dev # Start dev server
10+
bun run build # Build for production
11+
bun run preview # Preview production build
1212
```
1313

1414
## Build & Deploy
1515

16-
`dist/` contains the static site after `npm run build`. Upload it to any static host (GitHub Pages, Netlify, Vercel, etc).
16+
`dist/` contains the static site after `bun run build`. Upload it to any static host (GitHub Pages, Netlify, Vercel, etc).
1717

1818
For best performance, set these headers:
1919

@@ -26,22 +26,21 @@ If you can't set headers, the service worker will polyfill (may require reload).
2626

2727
## Dependencies
2828

29-
All dependencies are managed via npm:
29+
All dependencies are managed via Bun:
3030

3131
| Package | Purpose |
3232
|-----------------|--------------------------|
3333
| monaco-editor | Code editor (VS Code UI) |
3434
| vite | Build tool & dev server |
35+
| typescript | Type safety |
3536

3637
## Updating Dependencies
3738

38-
## Update Deps
39-
4039
```bash
41-
npm outdated # Check for updates
42-
npm update # Update all
43-
npm install <pkg> # Update specific
44-
npm run build # Rebuild
40+
bun outdated # Check for updates
41+
bun update # Update all
42+
bun add <pkg> # Add/update specific package
43+
bun run build # Rebuild
4544
```
4645

4746
## Features
@@ -63,6 +62,7 @@ On first load, Clang (~30MB) is downloaded & cached.
6362

6463
## Requirements
6564

65+
- [Bun](https://bun.sh) (package manager and runtime)
6666
- Modern browser (WebAssembly, SharedArrayBuffer)
6767

6868
## License

bun.lock

Lines changed: 187 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/advanced/enums.c

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#include <stdio.h>
2+
3+
// Basic enum declaration
4+
enum Color {
5+
RED,
6+
GREEN,
7+
BLUE
8+
};
9+
10+
// Enum with explicit values
11+
enum Status {
12+
PENDING = 1,
13+
PROCESSING = 5,
14+
COMPLETED = 10,
15+
FAILED = -1
16+
};
17+
18+
// Enum with typedef (common practice)
19+
typedef enum {
20+
MONDAY,
21+
TUESDAY,
22+
WEDNESDAY,
23+
THURSDAY,
24+
FRIDAY,
25+
SATURDAY,
26+
SUNDAY
27+
} Day;
28+
29+
// Enum for state machine
30+
typedef enum {
31+
IDLE,
32+
RUNNING,
33+
PAUSED,
34+
STOPPED
35+
} State;
36+
37+
const char* get_state_name(State s) {
38+
switch (s) {
39+
case IDLE: return "IDLE";
40+
case RUNNING: return "RUNNING";
41+
case PAUSED: return "PAUSED";
42+
case STOPPED: return "STOPPED";
43+
default: return "UNKNOWN";
44+
}
45+
}
46+
47+
int main() {
48+
printf("Enum Examples\n");
49+
printf("=============\n\n");
50+
51+
// 1. Basic enum usage
52+
printf("1. Basic Enum (Color):\n");
53+
enum Color c1 = RED;
54+
enum Color c2 = GREEN;
55+
enum Color c3 = BLUE;
56+
57+
printf(" RED = %d\n", c1);
58+
printf(" GREEN = %d\n", c2);
59+
printf(" BLUE = %d\n", c3);
60+
printf("\n");
61+
62+
// 2. Enum with explicit values
63+
printf("2. Enum with Explicit Values (Status):\n");
64+
enum Status s1 = PENDING;
65+
enum Status s2 = PROCESSING;
66+
enum Status s3 = COMPLETED;
67+
enum Status s4 = FAILED;
68+
69+
printf(" PENDING = %d\n", s1);
70+
printf(" PROCESSING = %d\n", s2);
71+
printf(" COMPLETED = %d\n", s3);
72+
printf(" FAILED = %d\n", s4);
73+
printf("\n");
74+
75+
// 3. Typedef enum usage
76+
printf("3. Typedef Enum (Day):\n");
77+
Day today = MONDAY;
78+
Day tomorrow = TUESDAY;
79+
80+
printf(" Today: %d (MONDAY)\n", today);
81+
printf(" Tomorrow: %d (TUESDAY)\n", tomorrow);
82+
printf(" Weekend starts at: %d (SATURDAY)\n", SATURDAY);
83+
printf("\n");
84+
85+
// 4. Enum in switch statement
86+
printf("4. Enum in Switch Statement (State Machine):\n");
87+
State current_state = IDLE;
88+
89+
printf(" Initial state: %s\n", get_state_name(current_state));
90+
91+
current_state = RUNNING;
92+
printf(" After start: %s\n", get_state_name(current_state));
93+
94+
current_state = PAUSED;
95+
printf(" After pause: %s\n", get_state_name(current_state));
96+
97+
current_state = STOPPED;
98+
printf(" After stop: %s\n", get_state_name(current_state));
99+
printf("\n");
100+
101+
// 5. Enum iteration
102+
printf("5. Enum Values:\n");
103+
printf(" All days of the week:\n");
104+
for (int i = MONDAY; i <= SUNDAY; i++) {
105+
const char* day_names[] = {
106+
"Monday", "Tuesday", "Wednesday", "Thursday",
107+
"Friday", "Saturday", "Sunday"
108+
};
109+
printf(" %d: %s\n", i, day_names[i]);
110+
}
111+
printf("\n");
112+
113+
// 6. Enum comparison
114+
printf("6. Enum Comparison:\n");
115+
Day day1 = FRIDAY;
116+
Day day2 = MONDAY;
117+
118+
if (day1 > day2) {
119+
printf(" FRIDAY (%d) comes after MONDAY (%d)\n", day1, day2);
120+
}
121+
122+
if (day1 == FRIDAY) {
123+
printf(" day1 is indeed FRIDAY\n");
124+
}
125+
126+
return 0;
127+
}
128+
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#include <stdio.h>
2+
3+
// Function pointer type definitions
4+
typedef int (*MathOperation)(int, int);
5+
typedef void (*PrintFunction)(const char*);
6+
7+
// Math operations
8+
int add(int a, int b) {
9+
return a + b;
10+
}
11+
12+
int subtract(int a, int b) {
13+
return a - b;
14+
}
15+
16+
int multiply(int a, int b) {
17+
return a * b;
18+
}
19+
20+
int divide(int a, int b) {
21+
if (b == 0) {
22+
printf("Error: Division by zero!\n");
23+
return 0;
24+
}
25+
return a / b;
26+
}
27+
28+
// Print functions
29+
void print_normal(const char* msg) {
30+
printf("%s\n", msg);
31+
}
32+
33+
void print_uppercase(const char* msg) {
34+
int i = 0;
35+
while (msg[i] != '\0') {
36+
if (msg[i] >= 'a' && msg[i] <= 'z') {
37+
printf("%c", msg[i] - 32);
38+
} else {
39+
printf("%c", msg[i]);
40+
}
41+
i++;
42+
}
43+
printf("\n");
44+
}
45+
46+
void print_with_prefix(const char* msg) {
47+
printf(">>> %s\n", msg);
48+
}
49+
50+
// Calculator using function pointers
51+
int calculate(int a, int b, MathOperation op) {
52+
return op(a, b);
53+
}
54+
55+
// Apply print function
56+
void apply_print(const char* message, PrintFunction print_func) {
57+
print_func(message);
58+
}
59+
60+
int main() {
61+
printf("Function Pointers Demo\n");
62+
printf("=====================\n\n");
63+
64+
printf("1. Math Operations:\n");
65+
int x = 20, y = 4;
66+
67+
MathOperation operations[] = {add, subtract, multiply, divide};
68+
const char* op_names[] = {"Add", "Subtract", "Multiply", "Divide"};
69+
70+
for (int i = 0; i < 4; i++) {
71+
int result = calculate(x, y, operations[i]);
72+
printf(" %s(%d, %d) = %d\n", op_names[i], x, y, result);
73+
}
74+
75+
printf("\n2. Print Functions:\n");
76+
const char* message = "Hello from function pointer!";
77+
78+
PrintFunction printers[] = {print_normal, print_uppercase, print_with_prefix};
79+
const char* printer_names[] = {"Normal", "Uppercase", "With Prefix"};
80+
81+
for (int i = 0; i < 3; i++) {
82+
printf(" %s: ", printer_names[i]);
83+
apply_print(message, printers[i]);
84+
}
85+
86+
printf("\n3. Function Pointer Array:\n");
87+
MathOperation ops[] = {add, multiply};
88+
int values[] = {10, 5, 8, 2};
89+
90+
for (int i = 0; i < 2; i++) {
91+
int result = ops[i](values[i * 2], values[i * 2 + 1]);
92+
printf(" Operation %d: %d\n", i + 1, result);
93+
}
94+
95+
return 0;
96+
}
97+

examples/advanced/macros.c

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <math.h>
4+
5+
// Simple macros
6+
#define PI 3.14159265359
7+
#define MAX(a, b) ((a) > (b) ? (a) : (b))
8+
#define MIN(a, b) ((a) < (b) ? (a) : (b))
9+
#define SQUARE(x) ((x) * (x))
10+
#define ABS(x) ((x) < 0 ? -(x) : (x))
11+
12+
// Multi-line macro
13+
#define PRINT_SUM(a, b) \
14+
do { \
15+
printf("Sum of %d and %d = %d\n", a, b, (a) + (b)); \
16+
} while(0)
17+
18+
// Conditional compilation
19+
#define DEBUG 1
20+
21+
// Macro with stringification
22+
#define PRINT_VAR(x) printf(#x " = %d\n", x)
23+
24+
// Macro with token pasting
25+
#define CONCAT(a, b) a##b
26+
27+
int main() {
28+
printf("Preprocessor Macros Demo\n");
29+
printf("========================\n\n");
30+
31+
printf("1. Constant Macros:\n");
32+
printf(" PI = %.5f\n", PI);
33+
printf(" PI * 2 = %.5f\n\n", PI * 2);
34+
35+
printf("2. Function-like Macros:\n");
36+
int a = 15, b = 25;
37+
printf(" MAX(%d, %d) = %d\n", a, b, MAX(a, b));
38+
printf(" MIN(%d, %d) = %d\n", a, b, MIN(a, b));
39+
printf(" SQUARE(%d) = %d\n", a, SQUARE(a));
40+
printf(" ABS(-%d) = %d\n\n", a, ABS(-a));
41+
42+
printf("3. Multi-line Macro:\n");
43+
PRINT_SUM(10, 20);
44+
printf("\n");
45+
46+
printf("4. Stringification:\n");
47+
int value = 42;
48+
PRINT_VAR(value);
49+
printf("\n");
50+
51+
printf("5. Conditional Compilation:\n");
52+
#ifdef DEBUG
53+
printf(" DEBUG mode is ON\n");
54+
#else
55+
printf(" DEBUG mode is OFF\n");
56+
#endif
57+
58+
#if DEBUG == 1
59+
printf(" Debug level: 1\n");
60+
#endif
61+
printf("\n");
62+
63+
printf("6. Token Pasting:\n");
64+
int CONCAT(var, 1) = 100; // Creates var1
65+
int CONCAT(var, 2) = 200; // Creates var2
66+
printf(" var1 = %d\n", CONCAT(var, 1));
67+
printf(" var2 = %d\n", CONCAT(var, 2));
68+
69+
return 0;
70+
}
71+

0 commit comments

Comments
 (0)