Skip to content

Commit c745c2e

Browse files
committed
Rebrand playground and fix output formatting
- Rename to "Nullsafe C Playground" - Update tagline to emphasize Clang fork with strict null checking - Add tooltips to all buttons for better UX - Fix output formatting (remove stray backticks in compiler output) - Update pure function example to const function with proper attribute syntax
1 parent abadfe9 commit c745c2e

File tree

3 files changed

+20
-22
lines changed

3 files changed

+20
-22
lines changed
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
// Pure functions preserve narrowing across calls
2-
int is_valid(int* ptr) {
3-
return ptr != 0; // Pure function
4-
}
1+
// Const functions preserve narrowing across calls
2+
int is_valid(char c) __attribute__((const));
53

6-
void example(int* data) {
7-
if (is_valid(data)) {
8-
*data = 42; // OK - narrowing preserved
9-
}
4+
void example(const char* data) {
5+
if (!data) return;
6+
const int isvalid = is_valid(*data);
7+
char val = *data; // OK - narrowing preserved by const function
108
}

nullsafe-playground/index.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta charset="UTF-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6-
<title>Null-Safe Clang Playground</title>
6+
<title>Nullsafe C Playground</title>
77

88
<!-- Monaco Editor from CDN (cached by browser) -->
99
<link rel="stylesheet" data-name="vs/editor/editor.main" href="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.45.0/min/vs/editor/editor.main.min.css">
@@ -538,18 +538,18 @@
538538

539539
<div class="header">
540540
<div class="header-content">
541-
<h1>Null-Safe Clang Playground</h1>
542-
<p>Flow-sensitive null safety for C - Try the experimental compiler live in your browser</p>
541+
<h1>Nullsafe C Playground</h1>
542+
<p>An experimental Clang fork with strict null checking</p>
543543
</div>
544544
<div class="header-links">
545-
<button id="reportBugBtn" class="header-link" style="background: none; border: none; cursor: pointer;">
545+
<button id="reportBugBtn" class="header-link" style="background: none; border: none; cursor: pointer;" title="Report a bug or issue with the playground or compiler">
546546
<svg width="20" height="20" fill="currentColor" viewBox="0 0 16 16" style="vertical-align: text-bottom;">
547547
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z"/>
548548
<path d="M7.002 11a1 1 0 1 1 2 0 1 1 0 0 1-2 0zM7.1 4.995a.905.905 0 1 1 1.8 0l-.35 3.507a.552.552 0 0 1-1.1 0L7.1 4.995z"/>
549549
</svg>
550550
Report Bug
551551
</button>
552-
<a href="https://github.com/cs01/llvm-project/" target="_blank" class="header-link">
552+
<a href="https://github.com/cs01/llvm-project/" target="_blank" class="header-link" title="View the Nullsafe C source code on GitHub">
553553
<svg width="20" height="20" fill="currentColor" viewBox="0 0 16 16" style="vertical-align: text-bottom;">
554554
<path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.012 8.012 0 0 0 16 8c0-4.42-3.58-8-8-8z"/>
555555
</svg>
@@ -559,14 +559,14 @@ <h1>Null-Safe Clang Playground</h1>
559559
</div>
560560

561561
<div class="controls">
562-
<button id="compileBtn" class="btn btn-primary" disabled>
562+
<button id="compileBtn" class="btn btn-primary" disabled title="Compile the code and show warnings (Ctrl+Enter)">
563563
<span></span> Compile
564564
</button>
565565

566-
<select id="examplesSelect" class="examples-select">
566+
<select id="examplesSelect" class="examples-select" title="Load example code to see Nullsafe C in action">
567567
<option value="null-check" selected>1. Basic Null Check</option>
568568
<option value="early-return">2. Early Return Pattern</option>
569-
<option value="pure-function">3. Pure Functions Preserve Narrowing</option>
569+
<option value="pure-function">3. Const Functions Preserve Narrowing</option>
570570
<option value="function-invalidates">4. Function Invalidates Narrowing</option>
571571
<option value="nonnull-annotation">5. _Nonnull Annotations</option>
572572
<option value="multi-level">6. Multi-Level Pointers</option>
@@ -580,7 +580,7 @@ <h1>Null-Safe Clang Playground</h1>
580580
</optgroup>
581581
</select>
582582

583-
<button id="shareBtn" class="btn btn-secondary">
583+
<button id="shareBtn" class="btn btn-secondary" title="Copy a shareable link with your code to clipboard">
584584
<svg width="16" height="16" fill="currentColor" viewBox="0 0 16 16" style="vertical-align: text-bottom;">
585585
<path d="M13.5 1a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3zM11 2.5a2.5 2.5 0 1 1 .603 1.628l-6.718 3.12a2.499 2.499 0 0 1 0 1.504l6.718 3.12a2.5 2.5 0 1 1-.488.876l-6.718-3.12a2.5 2.5 0 1 1 0-3.256l6.718-3.12A2.5 2.5 0 0 1 11 2.5zm-8.5 4a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3zm11 5.5a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3z"/>
586586
</svg>

nullsafe-playground/playground.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ async function loadExamples() {
127127
// Parse clang diagnostics into Monaco markers
128128
function parseDiagnostics(stderr) {
129129
const markers = [];
130-
const lines = stderr.split('\x60\x60\x60\n');
130+
const lines = stderr.split('\n');
131131
const diagnosticRegex = /^input\.c:(\d+):(\d+):\s+(error|warning|note):\s+(.+)$/;
132132

133133
for (const line of lines) {
@@ -572,14 +572,14 @@ async function loadExamples() {
572572

573573
// Display null-safe results with command
574574
if (nullsafeResult.stdout || nullsafeResult.stderr) {
575-
outputNullsafe.textContent = nullsafeCmd + '\x60\x60\x60\n' + nullsafeResult.stderr + nullsafeResult.stdout;
575+
outputNullsafe.textContent = nullsafeCmd + '\n' + nullsafeResult.stderr + nullsafeResult.stdout;
576576
} else {
577577
outputNullsafe.textContent = nullsafeCmd + '\n✓ No errors or warnings';
578578
}
579579

580580
// Display mainline results with command and comparison
581581
if (mainlineResult.stdout || mainlineResult.stderr) {
582-
outputMainline.textContent = mainlineCmd + '\x60\x60\x60\n' + mainlineResult.stderr + mainlineResult.stdout;
582+
outputMainline.textContent = mainlineCmd + '\n' + mainlineResult.stderr + mainlineResult.stdout;
583583
} else {
584584
// No warnings suppressed, but check if null-safe had warnings
585585
if (nullWarningCount > 0) {
@@ -631,9 +631,9 @@ async function loadExamples() {
631631
extraFlags
632632
});
633633
} else if (type === 'stdout') {
634-
stdout += text + '\x60\x60\x60\n';
634+
stdout += text + '\n';
635635
} else if (type === 'stderr') {
636-
stderr += text + '\x60\x60\x60\n';
636+
stderr += text + '\n';
637637
} else if (type === 'complete') {
638638
completed = true;
639639
clearTimeout(timeout);

0 commit comments

Comments
 (0)