기능

Vais Playground Features

Comprehensive guide to all features available in the Vais Playground.

Editor Features

Syntax Highlighting

The Monaco editor provides rich syntax highlighting for Vais:

  • Keywords: F, S, E, I, L, M, T, U, R, C, O
  • Types: i8, i16, i32, i64, u8, u16, u32, u64, f32, f64, bool, char, str
  • Operators: @, :=, =>, &&, ||, ==, !=, etc.
  • Comments: Single-line (#) and multi-line (/* */)
  • Strings: Double-quoted with escape sequences
  • Numbers: Integers, floats, hex, binary

Code Completion

Press Ctrl+Space or start typing to see intelligent suggestions:

Keyword Snippets

  • F → Function template with parameters and return type
  • S → Struct definition template
  • E → Enum definition template
  • I → If-else expression
  • L → Loop with range
  • M → Match expression

Built-in Functions

  • puts("text") → Print string
  • putchar(65) → Print character
  • printf("format", args) → Formatted output

Common Patterns

  • main → Complete main function
  • fn → Generic function template

Keyboard Shortcuts

ShortcutAction
Ctrl/Cmd + EnterRun code
Ctrl/Cmd + SFormat code
Ctrl + SpaceTrigger suggestions
Ctrl/Cmd + /Toggle comment
Ctrl/Cmd + [Decrease indentation
Ctrl/Cmd + ]Increase indentation
Alt + Up/DownMove line up/down
Shift + Alt + Up/DownCopy line up/down
Ctrl/Cmd + DSelect next occurrence
Ctrl/Cmd + FFind
Ctrl/Cmd + HReplace
F11Toggle fullscreen

Editor Configuration

Customizable settings in the editor:

  • Font size: 14px
  • Font family: Monaco, Menlo, Consolas
  • Tab size: 4 spaces
  • Line numbers: Enabled
  • Minimap: Enabled
  • Bracket pair colorization: Enabled
  • Word wrap: Disabled (configurable)

Example Programs

1. Hello World

Simple program demonstrating basic output.

F main()->i64 {
    puts("Hello, Vais!")
    0
}

2. Fibonacci

Recursive function using self-recursion operator @.

F fib(n:i64)->i64 = n<2 ? n : @(n-1) + @(n-2)
F main()->i64 = fib(10)

3. Generics

Type-generic functions with type inference.

F identity<T>(x: T) -> T = x

F main() -> i64 {
    a := identity(42)
    0
}

4. Control Flow

If-else expressions and loop constructs.

F main()->i64 {
    x := 10
    result := I x > 5 {
        puts("Greater than 5")
        1
    } E {
        puts("Not greater")
        0
    }

    L i:0..5 {
        putchar(i + 48)
    }
    0
}

5. Structs

Struct definitions with methods.

S Point {
    x: f64,
    y: f64
}

I Point {
    F distance_from_origin() -> f64 {
        sqrt(@.x * @.x + @.y * @.y)
    }
}

6. Enums

Algebraic data types with pattern matching.

E Option<T> {
    Some(T),
    None
}

F get_value(opt: Option<i64>) -> i64 {
    M opt {
        Some(v) => v,
        None => 0
    }
}

7. Pattern Matching

Exhaustive pattern matching with bindings.

F classify(n: i64) -> i64 {
    M n {
        0 => 0,
        1 => 1,
        _ => -1
    }
}

8. Loops

Range-based and while-style loops.

F main() -> i64 {
    # Range loop
    L i:0..10 {
        putchar(i + 48)
    }

    # While-style with break
    counter := 0
    L {
        I counter >= 5 { break }
        counter += 1
    }

    0
}

9. Self-Recursion

Using @ operator for recursive calls.

F factorial(n: i64) -> i64 =
    I n <= 1 { 1 } E { n * @(n - 1) }

10. Type Inference

Automatic type deduction.

F main() -> i64 {
    x := 42          # Inferred as i64
    y := 3.14        # Inferred as f64
    z := add(10, 20) # Inferred from return type
    0
}

F add(a: i64, b: i64) -> i64 = a + b

UI Components

  • Examples List: Quick access to all example programs
  • Active Indicator: Shows currently loaded example
  • Keyboard Shortcuts: Reference card for common actions

Toolbar

  • Example Dropdown: Alternative way to select examples
  • Format Button: Auto-format code
  • Clear Button: Clear output panel
  • Run Button: Compile and execute code

Output Panel

  • Status Indicator: Shows compilation/execution state

    • 🔵 Ready
    • 🟡 Running (animated)
    • 🟢 Success
    • 🔴 Error
  • Output Types:

    • Regular output (white)
    • Success messages (green)
    • Warnings (yellow)
    • Errors (red)
    • Info messages (blue)

Status Bar

Real-time status updates:

  • "Ready" - Waiting for input
  • "Compiling..." - Compilation in progress
  • "Compilation successful" - No errors
  • "Execution completed" - Finished running
  • "Compilation failed" - Errors found

Compilation Features

Mock Compiler (Current)

The playground includes a demonstration compiler:

  1. Syntax Validation

    • Checks for empty files
    • Validates brace matching
    • Detects missing main function
  2. Error Reporting

    • Line and column numbers
    • Descriptive error messages
    • Multiple error display
  3. Warning System

    • Non-fatal issues
    • Best practice suggestions
  4. IR Generation

    • Mock LLVM IR output
    • Shows compilation structure

Real Compiler (Future)

When integrated with WASM:

  1. Full Compilation Pipeline

    • Lexical analysis
    • Parsing
    • Type checking
    • Code generation
  2. Advanced Diagnostics

    • Precise error locations
    • Suggested fixes
    • Type mismatch details
  3. Optimization

    • Constant folding
    • Dead code elimination
    • Inline expansion
  4. Execution

    • Direct WASM execution
    • Real stdout/stderr capture
    • Exit code reporting

Theme

Dark Theme (Default)

Optimized for reduced eye strain:

  • Background: #0f172a
  • Surface: #1e293b
  • Editor: #1e1e1e
  • Primary: #6366f1 (Indigo)
  • Success: #22c55e (Green)
  • Error: #ef4444 (Red)
  • Warning: #f59e0b (Amber)

Syntax Colors

  • Keywords: Purple (#C586C0)
  • Types: Teal (#4EC9B0)
  • Strings: Orange (#CE9178)
  • Numbers: Light green (#B5CEA8)
  • Comments: Green (#6A9955)
  • Operators: White (#D4D4D4)

Responsive Design

Desktop (1200px+)

┌─────────────────────────────────────┐
│          Header                     │
├──────┬──────────────────┬──────────┤
│      │                  │          │
│ Side │     Editor       │  Output  │
│ bar  │                  │          │
│      │                  │          │
└──────┴──────────────────┴──────────┘

Tablet (768px - 1199px)

┌─────────────────────────────────────┐
│          Header                     │
├──────┬──────────────────────────────┤
│ Side │                              │
│ bar  │         Editor               │
├──────┴──────────────────────────────┤
│          Output                     │
└─────────────────────────────────────┘

Mobile (< 768px)

┌───────────────────────┐
│      Header           │
├───────────────────────┤
│   Example Select      │
├───────────────────────┤
│                       │
│      Editor           │
│                       │
├───────────────────────┤
│      Output           │
└───────────────────────┘

Browser Support

Fully Supported

  • Chrome 90+ ✅
  • Edge 90+ ✅
  • Firefox 88+ ✅
  • Safari 14+ ✅
  • Opera 76+ ✅

Minimum Requirements

  • ES6+ support
  • WebAssembly support (for real compiler)
  • Local Storage API
  • Web Workers (for background compilation)

Feature Detection

The playground checks for:

  • WebAssembly availability
  • Service Worker support
  • Local Storage access

Performance

Optimization Techniques

  1. Lazy Loading

    • Monaco editor loaded on demand
    • WASM module loaded when needed
    • Examples loaded incrementally
  2. Code Splitting

    • Separate chunks for editor and examples
    • Vendor bundle optimization
  3. Caching

    • Service Worker for offline access
    • Browser cache headers
    • WASM module caching
  4. Minification

    • JavaScript minification
    • CSS minification
    • WASM optimization

Benchmarks

Typical load times on fast connection:

  • Initial page load: ~500ms
  • Editor initialization: ~300ms
  • WASM module load: ~200ms
  • Example switch: <50ms
  • Compilation: ~100ms (mock) / ~500ms (real)

Accessibility

Keyboard Navigation

  • Full keyboard access to all features
  • Tab navigation between components
  • Focus indicators on interactive elements

Screen Readers

  • ARIA labels on buttons
  • Semantic HTML structure
  • Alt text for icons

Contrast

  • WCAG AA compliant color contrast
  • High contrast mode support
  • Customizable themes (future)

Future Features

Planned Enhancements

  • Multi-file projects
  • Import from GitHub
  • Share code via URL
  • Export to file
  • Diff view for changes
  • Collaborative editing
  • Custom themes
  • Plugin system
  • Performance profiling
  • Assembly viewer
  • Interactive tutorials
  • AI code assistance

Community Requested

  • Mobile app version
  • Offline mode
  • Project templates
  • Code snippets library
  • Video tutorials
  • Community examples
  • Code challenges
  • Leaderboards

Contributing

Want to add features? See CONTRIBUTING.md for guidelines.

Adding Examples

  1. Edit src/examples.js
  2. Add your example to the examples object
  3. Include name, description, and code
  4. Test in the playground

Improving UI

  1. Edit src/styles.css for styling
  2. Update index.html for structure
  3. Modify src/main.js for behavior

Fixing Bugs

  1. Check existing issues
  2. Create a new branch
  3. Fix the bug
  4. Submit a pull request

License

MIT License - See LICENSE for details