-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstants.ts
More file actions
409 lines (369 loc) · 9.94 KB
/
constants.ts
File metadata and controls
409 lines (369 loc) · 9.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
import { Project } from "./types";
export const HOME_FEATURES = {
en: [
{
id: "concurrency",
title: "Go-Powered Concurrency",
description:
"Spawn lightweight actors that communicate via message passing. Go's goroutines meet PHP's simple syntax.",
code: `// 并发示例
echo "Main thread started\\n";
function worker($id: int) {
echo "Worker {$id} started\\n";
}
// 生成轻量级线程 (goroutine)
spawn worker(1);
spawn worker(2);
echo "Main thread finished\\n";
`,
},
{
id: "types",
title: "Refined Types",
description:
"Strong typing with runtime flexibility. Express complex constraints that are validated at compile time.",
code: `// 类型系统示例
function add($a: int, $b: int): int {
return $a + $b;
}
$res = add(10, 20);
echo "10 + 20 = {$res}\\n";
// 类型错误会在编译时捕获
// $err = add("1", "2");
`,
},
{
id: "interop",
title: "Seamless Go Interop",
description:
"Call Go functions and use Go structs directly. No FFI, no glue code, just seamless integration.",
code: `// Go 互操作示例
// 目前 WASM 环境支持部分内置函数
$arr = [1, 2, 3];
$sum = 0;
foreach ($arr as $v) {
$sum += $v;
}
echo "Sum: {$sum}\\n";
`,
},
],
zh: [
{
id: "concurrency",
title: "Go 驱动的并发",
description:
"生成通过消息传递进行通信的轻量级 Actor。Go 的 Goroutine 遇上 PHP 的简洁语法。",
code: `// 并发示例
echo "Main thread started\\n";
function worker($id: int) {
echo "Worker {$id} started\\n";
}
// 生成轻量级线程 (goroutine)
spawn worker(1);
spawn worker(2);
echo "Main thread finished\\n";
`,
},
{
id: "types",
title: "精炼类型系统",
description:
"强类型与运行时灵活性的结合。直接在类型系统中表达复杂的约束,并在编译时进行验证。",
code: `// 类型系统示例
function add($a: int, $b: int): int {
return $a + $b;
}
$res = add(10, 20);
echo "10 + 20 = {$res}\\n";
// 类型错误会在编译时捕获
// $err = add("1", "2");
`,
},
{
id: "interop",
title: "无缝 Go 互操作",
description:
"直接调用 Go 函数和使用 Go 结构体。没有 FFI,没有胶水代码,只有无缝集成。",
code: `// Go 互操作示例
// 目前 WASM 环境支持部分内置函数
$arr = [1, 2, 3];
$sum = 0;
foreach ($arr as $v) {
$sum += $v;
}
echo "Sum: {$sum}\\n";
`,
},
],
};
export const MOCK_PROJECTS: Project[] = [
{
id: "hello-world",
name: "Hello World",
description: "Output and Function example",
files: {
"main.zy": {
name: "main.zy",
language: "origami",
isEntry: true,
content: `// 输出与返回示例
echo "Hello Origami from WASM!\\n";
function add($a: int, $b: int): int {
return $a + $b;
}
$x = add(3, 5);
echo "3 + 5 = {$x}\\n";
`,
},
},
},
{
id: "arrays",
name: "Arrays",
description: "Array methods: map, filter, join",
files: {
"main.zy": {
name: "main.zy",
language: "origami",
isEntry: true,
content: `// 数组链式方法示例
$nums = [1,2,3,4,5];
$doubled = $nums->map(($n) => $n * 2);
$evens = $nums->filter(($n) => $n % 2 == 0);
echo "doubled: ".$doubled->join(",")."\\n";
echo "evens: ".$evens->join(",")."\\n";
`,
},
},
},
{
id: "control-flow",
name: "Control Flow",
description: "if, for, foreach, recursion",
files: {
"main.zy": {
name: "main.zy",
language: "origami",
isEntry: true,
content: `// 控制结构示例:if / for / foreach
function fib($n: int): int {
if ($n <= 1) {
return $n;
}
return fib($n - 1) + fib($n - 2);
}
$nums = [1, 2, 3, 4, 5];
$sum = 0;
for ($i = 0; $i < 5; $i = $i + 1) {
$sum = $sum + $nums[$i];
}
echo "sum via for: {$sum}\\n";
$sum2 = 0;
foreach ($nums as $n) {
$sum2 = $sum2 + $n;
}
echo "sum via foreach: {$sum2}\\n";
echo "fib(8) = " . fib(8) . "\\n";
`,
},
},
},
{
id: "strings",
name: "Strings",
description: "String manipulation methods",
files: {
"main.zy": {
name: "main.zy",
language: "origami",
isEntry: true,
content: `// 字符串操作示例
$s = " Hello, Origami wasm! ";
echo "原始: '{$s}'\\n";
echo "trim: '" . $s->trim() . "'\\n";
echo "toUpper: " . $s->toUpperCase() . "\\n";
echo "toLower: " . $s->toLowerCase() . "\\n";
echo "startsWith(' He'): ";
echo $s->startsWith(" He") ? "true\\n" : "false\\n";
echo "endsWith('! '): ";
echo $s->endsWith("! ") ? "true\\n" : "false\\n";
$idx = $s->indexOf("Origami");
echo "indexOf('Origami'): {$idx}\\n";
$sub = $s->substring(2, 7);
echo "substring(2,7): '{$sub}'\\n";
$repl = $s->replace("wasm", "WASM");
echo "replace: '{$repl}'\\n";
return "done";
`,
},
},
},
];
export const SHOWCASE_PROJECTS = {
en: [
{
id: 1,
title: "Cosmos Desktop",
description:
"Cross-platform creative suite built with Origami WebView. Merges Web UI flexibility with native Go performance.",
image:
"https://images.unsplash.com/photo-1600607686527-6fb886090705?auto=format&fit=crop&q=80&w=800",
tags: ["GUI", "WebView", "Desktop"],
author: "CreativeLabs",
},
{
id: 2,
title: "Bolt IM",
description:
"Enterprise-grade chat infrastructure supporting 1M+ concurrent users per node with sub-millisecond latency.",
image:
"https://images.unsplash.com/photo-1556761175-5973dc0f32e7?auto=format&fit=crop&q=80&w=800",
tags: ["IM", "WebSocket", "Concurrency"],
author: "ConnectTech",
},
{
id: 3,
title: "HyperScale API",
description:
"Payment processing gateway handling $5B daily transaction volume. Replaced legacy Java stack with 1/10th resources.",
image:
"https://images.unsplash.com/photo-1551288049-bebda4e38f71?auto=format&fit=crop&q=80&w=800",
tags: ["FinTech", "High Performance", "API"],
author: "FinCore",
},
{
id: 4,
title: "Nebula Engine",
description:
"Real-time game server engine utilizing Actor model for zero-lock physics synchronization.",
image:
"https://images.unsplash.com/photo-1550751827-4bd374c3f58b?auto=format&fit=crop&q=80&w=800",
tags: ["Game Server", "Actor Model", "Real-time"],
author: "PixelForge",
},
],
zh: [
{
id: 1,
title: "Cosmos Desktop (宇宙桌面)",
description:
"使用 Origami WebView 构建的跨平台创意套件。融合了 Web UI 的灵活性与原生 Go 的高性能。",
image:
"https://images.unsplash.com/photo-1600607686527-6fb886090705?auto=format&fit=crop&q=80&w=800",
tags: ["GUI", "WebView", "桌面应用"],
author: "CreativeLabs",
},
{
id: 2,
title: "Bolt IM (闪电通讯)",
description:
"企业级聊天基础设施,单节点支持 100 万+ 并发用户,延迟低于 1 毫秒。",
image:
"https://images.unsplash.com/photo-1556761175-5973dc0f32e7?auto=format&fit=crop&q=80&w=800",
tags: ["即时通讯", "WebSocket", "高并发"],
author: "ConnectTech",
},
{
id: 3,
title: "HyperScale API (超大规模网关)",
description:
"日处理 50 亿美元交易额的支付网关。替代了旧的 Java 技术栈,仅使用 1/10 的资源。",
image:
"https://images.unsplash.com/photo-1551288049-bebda4e38f71?auto=format&fit=crop&q=80&w=800",
tags: ["金融科技", "高性能", "API"],
author: "FinCore",
},
{
id: 4,
title: "Nebula Engine (星云引擎)",
description: "利用 Actor 模型实现零锁物理同步的实时游戏服务器引擎。",
image:
"https://images.unsplash.com/photo-1550751827-4bd374c3f58b?auto=format&fit=crop&q=80&w=800",
tags: ["游戏服务器", "Actor 模型", "实时"],
author: "PixelForge",
},
],
};
export const CODE_EXAMPLES = {
en: [
{
category: "Basics",
title: "Hello World",
description: "Basic syntax and function definition.",
code: `// 基础语法示例
echo "Hello Origami!\\n";
function greet($name: string) {
echo "Hello, {$name}\\n";
}
greet("User");
`,
},
{
category: "Data Structures",
title: "Array Processing",
description: "Using map and filter on arrays.",
code: `// 数组处理示例
$nums = [1, 2, 3, 4, 5];
// 使用 map 转换
$doubled = $nums->map(($n) => $n * 2);
echo "Doubled: " . $doubled->join(", ") . "\\n";
// 使用 filter 过滤
$evens = $nums->filter(($n) => $n % 2 == 0);
echo "Evens: " . $evens->join(", ") . "\\n";
`,
},
{
category: "Algorithms",
title: "Fibonacci",
description: "Recursive function call.",
code: `// 递归示例
function fib($n: int): int {
if ($n <= 1) return $n;
return fib($n - 1) + fib($n - 2);
}
echo "fib(10) = " . fib(10) . "\\n";
`,
},
],
zh: [
{
category: "基础",
title: "Hello World",
description: "基本语法和函数定义。",
code: `// 基础语法示例
echo "Hello Origami!\\n";
function greet($name: string) {
echo "Hello, {$name}\\n";
}
greet("User");
`,
},
{
category: "数据结构",
title: "数组处理",
description: "在数组上使用 map 和 filter。",
code: `// 数组处理示例
$nums = [1, 2, 3, 4, 5];
// 使用 map 转换
$doubled = $nums->map(($n) => $n * 2);
echo "Doubled: " . $doubled->join(", ") . "\\n";
// 使用 filter 过滤
$evens = $nums->filter(($n) => $n % 2 == 0);
echo "Evens: " . $evens->join(", ") . "\\n";
`,
},
{
category: "算法",
title: "斐波那契数列",
description: "递归函数调用。",
code: `// 递归示例
function fib($n: int): int {
if ($n <= 1) return $n;
return fib($n - 1) + fib($n - 2);
}
echo "fib(10) = " . fib(10) . "\\n";
`,
},
],
};