aboutsummaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
authoreunhhu <[email protected]>2026-10-13 06:16:12 +0100
committereunhhu <[email protected]>2026-10-13 06:16:12 +0100
commit6209ddb42b953902828972b2e09f0296a51fe565 (patch)
tree51be65e5831760c3d416f9ed1431f39dfd569e6a /docs
parent557a69ef5102292eceb25f823ebcfc989810ab0c (diff)
downloadaup-6209ddb42b953902828972b2e09f0296a51fe565.tar.gz
aup-6209ddb42b953902828972b2e09f0296a51fe565.zip
Formats, joins, slices, lets of bytes and text, while and && and || that decide alone (Pure 027's stage 2a): {v:08x}, {p:.2f} (Python's mini-language, [0][width][.digits][d x X b o f]), a + b of texts or of bytes, b[a .. c] of bytes and of texts (a cut inside a character failing as encoding), byte(n), let s = bytes or text (16 of each a handler, s = s + e appending in place), while c { } as a count to 2^53 that breaks when c is false, && and || computing their right side only where it decides (an AND or OR still where it cannot fail: comparisons, states and fields, a walked item's fields, a number plus a small literal, what the left side computed; every module of the apps and benchmarks byte for byte the same but json's); examples/json.aup, examples/sha256.aup in formats and joined bytes; 14 diagnostics, one accepted form, 144 random formats against Python's format() and an app cutting at commas
Diffstat (limited to 'docs')
-rw-r--r--docs/design/002-dsl-direction.md50
1 files changed, 50 insertions, 0 deletions
diff --git a/docs/design/002-dsl-direction.md b/docs/design/002-dsl-direction.md
index f05123f..a7a5eaf 100644
--- a/docs/design/002-dsl-direction.md
+++ b/docs/design/002-dsl-direction.md
@@ -643,3 +643,53 @@ on hash {
- 무작위 비트 식 192개(파이썬의 정수와 i64의 넘침, 시프트 한도로) 사건 768개, 그중 실패 196개가 파이썬과 같다.
- 바이트와 리스트의 앱이 파이썬과 같다(`limit`, `not_found` 포함).
- `examples/sha256.aup`는 Pure의 검사가 FIPS 180-2의 예와 길이 0–129 등의 메시지로 `hashlib`와 대조한다(세 실행 길).
+
+### 형식, 잇기와 자르기, 바이트와 text의 let, while, 단락 평가 (Pure 027의 2a)
+
+`examples/json.aup`(JSON 텍스트인지 판정)과 다시 쓴 `examples/sha256.aup`가 이것으로 쓰였다.
+
+```text
+on check {
+ let d = check.data # 바이트를 담는 let
+ let out = "" # text를 담는 let
+ let i = 0
+ while i < d.bytes && d[i] != 0x2c { # 왼쪽이 거짓이면 오른쪽은 계산하지 않는다
+ out = out + text(d[i .. i + 1]) # 덧붙이기(제자리)
+ i = i + 1
+ }
+ shown = "{i:5}|{h:08x}|{price:.2f}" # 형식
+}
+```
+
+- **형식** `{값:형식}`은 파이썬의 형식 미니 언어의 일부다: `[0][폭][.자릿수][d x X b o f]`.
+ - `0`은 부호 뒤를 0으로 채운다. 폭은 255까지다.
+ - `d x X b o`는 i64나 정수인 수를 그 진법으로 쓴다. 정수가 아닌 수면 이벤트가 `limit`으로 실패한다.
+ - `f`는 수를 고정 자릿수로 쓴다(자릿수 0–30, 기본 6). −0은 0으로 쓴다.
+ - 형식 없이 폭만 주면 지금의 글자를 왼쪽으로 채운다. bool은 폭만 받는다.
+ - 파이썬의 `format()`과 같은 글자를 낸다(무작위 대조).
+- **잇기** `a + b`는 text끼리, 바이트끼리 잇는다. 섞으면 진단이 나온다.
+- **자르기** `b[a .. c]`는 a부터 c 앞까지의 바이트다.
+ - text는 바이트 자리로 자르고, 글자 가운데를 자르면 `encoding`으로 실패한다.
+ - 끝은 둘 다 수이거나 둘 다 i64이고, 정수가 아니거나 값 밖이면 `limit`이다.
+- **`byte(n)`** 은 i64 0–255 하나의 바이트다.
+- **바이트와 text의 let.**
+ - `let s = …`, `s = …`로 쓰고, 핸들러마다 바이트 16개와 text 16개까지다.
+ - `s = s + e`는 s를 복사하지 않고 덧붙인다(Pure의 BYTES_STORE 덧붙이기).
+ - 담은 바이트는 이벤트의 메모리 몫에 센다. 한 번에 주기(`a, b = b, a`)는 수의 let과 상태에만 쓴다.
+- **`while 조건 { }`** 은 0부터 2^53까지 세는 반복의 첫 줄에 `if !조건 { break }`를 둔 것이다. 끝나지 않는 반복은 실행량 예산이
+ `work`로 끝낸다. `break`는 가장 안쪽의 `while`이나 `for`를 끝낸다.
+- **`&&`와 `||`는 단락 평가다**(뜻이 바뀌었다).
+ - 왼쪽이 답을 정하면 오른쪽은 계산하지 않는다. 그래서 `i < n && d[i] == x`처럼 범위를 먼저 볼 수 있다.
+ - 식은 아무것도 바꾸지 않으므로, 전과 다른 것은 오른쪽이 실패할 수 있을 때뿐이다.
+ - 오른쪽이 실패할 수 없으면(비교, 상태와 필드 읽기, 걷는 항목의 필드, 왼쪽이 이미 계산한 식) 컴파일러는 지금처럼 AND와 OR
+ 하나를 낸다. 그래서 Pure의 범위 찾기와 접기의 모양이 그대로다. 그 밖에서는 분기를 낸다.
+ - Pure, aup, Vega의 소스 36개 가운데 모듈이 달라진 것은 이 단락 평가가 필요한 JSON 검사기 하나다. TPC-C의 필터는 오른쪽의 키 찾기를
+ 왼쪽이 이미 계산하므로 바이트까지 같다.
+
+검증:
+- 진단 14건: 형식, 폭, 자릿수, 형식과 타입, text의 `-`, 잇기의 타입, let의 타입, 한 번에 주기의 text, `while`의 bool, 리스트의
+ 자르기, 수의 자르기, let 수의 한도.
+- 받아들이는 꼴 하나.
+- 무작위 형식 144개, 사건 720개(그중 `limit` 171개)가 파이썬과 같다.
+- 쉼표로 자르는 앱 하나가 67개의 입력에서 파이썬과 같다. 빈 입력도 단락 평가로 읽지 않는다.
+- `examples/json.aup`는 Pure의 검사가 JSONTestSuite로 대조한다.