dreamstack/examples/language-features.ds
enzotar f4e5ace37c feat: *= /= operators + 6 new array methods
New assignment operators (full pipeline: lexer → parser → analyzer → codegen):
- *= (MulAssign): count *= 2
- /= (DivAssign): count /= 2

New array methods in event handler (all flush signal + stream diff):
- .clear()   → items = []
- .insert(i, v) → splice at index
- .sort()    → immutable sort
- .reverse() → immutable reverse
- .filter(fn) → filter in place
- .map(fn)   → map in place

New example: language-features.ds (65KB)
- Tests all assignment ops (+=, -=, *=, /=)
- Tests array methods (push, pop, sort, reverse, clear)
- Tests match expressions
- Tests comparison operators
- Tests derived signals (let doubled = count * 2)
- Browser-verified: zero console errors

All 11 examples pass.
2026-02-26 20:29:35 -08:00

84 lines
3.1 KiB
Text
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- DreamStack Language Features Test
-- Exercises all core language features in one place
-- Tests: operators, assignment ops, array methods, computed signals,
-- when/else, match, each, method calls, string interpolation
import { Card } from "../registry/components/card"
import { Badge } from "../registry/components/badge"
import { Button } from "../registry/components/button"
-- State
let count = 10
let items = ["Alpha", "Beta", "Gamma"]
let loggedIn = false
let mode = "normal"
-- Computed signals (derived)
let doubled = count * 2
let isHigh = count > 50
view test = column [
text "🧪 Language Features" { variant: "title" }
text "Testing all operators and methods" { variant: "subtitle" }
-- 1. All assignment operators: +=, -=, *=, /=
Card { title: "Assignment Operators", subtitle: "+= -= *= /=" } [
text "count: {count} | doubled: {doubled}" { variant: "title" }
row [
Button { label: "+5", variant: "primary", onClick: count += 5 }
Button { label: "-3", variant: "secondary", onClick: count -= 3 }
Button { label: "×2", variant: "primary", onClick: count *= 2 }
Button { label: "÷2", variant: "secondary", onClick: count /= 2 }
Button { label: "=1", variant: "ghost", onClick: count = 1 }
]
]
-- 2. Boolean operators && || !
Card { title: "Boolean Logic", subtitle: "&& || ! operators" } [
Button { label: "Toggle Login", variant: "primary", onClick: loggedIn = !loggedIn }
when loggedIn ->
Badge { label: "Logged In ✓", variant: "success" }
else ->
Badge { label: "Logged Out", variant: "error" }
]
-- 3. Array methods: push, pop, clear, sort, reverse
Card { title: "Array Methods", subtitle: "push pop clear sort reverse" } [
text "Items: {items}" { variant: "title" }
text "{items}" { variant: "subtitle" }
row [
Button { label: "Push", variant: "primary", onClick: items.push("New") }
Button { label: "Pop", variant: "secondary", onClick: items.pop() }
Button { label: "Sort", variant: "ghost", onClick: items.sort() }
Button { label: "Reverse", variant: "ghost", onClick: items.reverse() }
Button { label: "Clear", variant: "destructive", onClick: items.clear() }
]
each item in items ->
row [
text "→"
text item
]
]
-- 4. Match expressions
Card { title: "Pattern Matching", subtitle: "match with fall-through" } [
row [
Button { label: "Normal", variant: "secondary", onClick: mode = "normal" }
Button { label: "Turbo", variant: "primary", onClick: mode = "turbo" }
Button { label: "Zen", variant: "ghost", onClick: mode = "zen" }
]
match mode
"turbo" -> Badge { label: "🔥 TURBO", variant: "warning" }
"zen" -> Badge { label: "🧘 ZEN", variant: "info" }
_ -> Badge { label: "📝 Normal", variant: "default" }
]
-- 5. Comparison operators
Card { title: "Comparisons", subtitle: "> < >= <= == !=" } [
text "count = {count}"
when count > 50 -> Badge { label: "HIGH (>50)", variant: "warning" }
when count > 20 -> Badge { label: "MEDIUM (>20)", variant: "info" }
else -> Badge { label: "LOW (≤20)", variant: "success" }
]
]