Skip to content

Commit d85535c

Browse files
gh-193: Make DEL use STR.
Closes #193.
1 parent 405bcc7 commit d85535c

21 files changed

Lines changed: 178 additions & 95 deletions

docs/SPECIFICATION.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696

9797
The first assignment to a symbol MUST use a typed form such as `TYPE name = expression`, with one or more spaces between the type and name and optional spaces around `=`. Subsequent assignments MAY omit the type annotation, but the symbol's type MUST remain unchanged for the lifetime of that name, including after deletion and re-assignment.
9898

99-
Assignments to undeclared identifiers without a type annotation MUST raise a runtime error. A binding MUST remain allocated until it is deleted with `DEL(name)`.
99+
Assignments to undeclared identifiers without a type annotation MUST raise a runtime error. A binding MUST remain allocated until it is deleted with `DEL("name")`.
100100

101101
The built-in `ASSIGN(target, expression)` MUST provide expression-position assignment. The `target` MAY be a plain identifier or an indexed target. If the identifier does not yet exist, the typed form `ASSIGN(TYPE name, expression)` MUST be used, and that typed form is valid only for plain identifiers.
102102

@@ -695,9 +695,9 @@
695695

696696
#### 9.1.1 Symbol and type operators
697697

698-
- `BOOL DEL(SYMBOL name)` = MUST delete the readable runtime binding designated by `name`. Deletion MUST preserve the symbol's recorded static type as defined in [5.1](#51-declarations-bindings-and-lifetime). Deleting an undeclared, never-assigned, or already-deleted symbol MUST raise a runtime error. Deleting a frozen or permanently frozen binding MUST raise a runtime error. On success, `DEL` MUST return `FALSE`.
698+
- `BOOL DEL(STR target)` = MUST evaluate `target`, require the result to be a `STR`, and parse that string as exactly one Prefix target expression. The parsed target MUST be either a plain identifier such as `name` or an indexed identifier such as `name<key>` or `name<k1, k2, ...>`. If the parsed target is a plain identifier, `DEL` MUST delete the readable runtime binding designated by that identifier. Deletion MUST preserve the symbol's recorded static type as defined in [5.1](#51-declarations-bindings-and-lifetime). Deleting an undeclared, never-assigned, or already-deleted symbol MUST raise a runtime error. Deleting a frozen or permanently frozen binding MUST raise a runtime error.
699699

700-
- `BOOL DEL(target<key>)` or `BOOL DEL(target<k1, k2, ...>)` = MUST delete the map entry identified by the final key in the chain of map indices. `target` MUST resolve to a `MAP` value and all intermediate lookups MUST resolve to nested `MAP` values; indexing a non-`MAP` MUST raise a runtime error. If an intermediate key does not exist, the operation MUST be a no-op. After deletion the modified map MUST be written back to the environment. `DEL` in indexed form MUST return `FALSE` whether it deleted an entry or completed as a no-op.
700+
- When the parsed `DEL` target is indexed, the base target MUST resolve to a `MAP` value and all intermediate lookups MUST resolve to nested `MAP` values; indexing a non-`MAP` MUST raise a runtime error. The map entry identified by the final key in the chain MUST be deleted. If an intermediate key does not exist, the operation MUST be a no-op. After deletion the modified map MUST be written back to the environment. `DEL` MUST return `FALSE` on success, including indexed no-op cases.
701701

702702
- `ANY ASSIGN(target, ANY value)` = MUST evaluate `value`, assign it to `target`, and return the assigned value. `target` MAY be a plain identifier, a tensor indexed target, or a map indexed target. If a plain identifier has not yet been declared, the typed form `ASSIGN(TYPE name, value)` MUST be used. The typed form MUST NOT be used with indexed targets.
703703

lib/std/image/init.pre

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,6 @@ FUNC BOOL SHOW(TNS img){
131131
! ShellExecuteW(hwnd, operation, file, params, dir, showcmd)
132132
! Use NULL hwnd (0), operation "open", empty params and dir, showcmd=1
133133
win32.WIN_CALL("shell32", "ShellExecuteW", "PSSSSI", "P", 0d0, "open", img_path, "", "", 0d1)
134-
DEL(img_path)
134+
DEL("img_path")
135135
RETURN(FALSE)
136136
}

lib/std/path.pre

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ FUNC STR BASEPATH(STR path){ ! returns directory portion of path
1515
RETURN("")
1616
}
1717
STR dir = REPLACE(npath, JOIN("/", base), "")
18+
DEL("npath")
1819
POP("dir")
1920
}
2021

2122
FUNC STR BASENAME(STR path){ ! returns filename portion of path
2223
TNS tpath = SPLIT(NORMALIZE_PATH(path), "/")
2324
STR basename = tpath[MAX(TLEN(tpath, 0d1), 0d1)]
24-
DEL(tpath)
25+
DEL("tpath")
2526
POP("basename")
2627
}
2728

@@ -32,15 +33,15 @@ FUNC TNS SPLITEXT(STR path){ ! returns [name without ext, ext]
3233
TNS parts = SPLIT(base, ".")
3334
! If there is no dot, return the path unchanged and empty ext
3435
IF(EQ(TLEN(parts, 0d1), 0d1)){
35-
DEL(base)
36+
DEL("base")
3637
TNS result = [npath, ""]
3738
POP("result")
3839
}
3940
! Extension is the last segment (1-based indexing)
4041
STR ext = parts[ TLEN(parts, 0d1) ]
4142
! Name is base without the final "." + ext suffix
4243
STR name = REPLACE(base, JOIN(".", ext), "")
43-
DEL(parts)
44+
DEL("parts")
4445
STR delex = ""
4546
IF(EQ(dir, "")){
4647
delex = name
@@ -51,8 +52,8 @@ FUNC TNS SPLITEXT(STR path){ ! returns [name without ext, ext]
5152
delex = JOIN(dir, name)
5253
}
5354
}
54-
DEL(dir)
55-
DEL(name)
55+
DEL("dir")
56+
DEL("name")
5657
TNS result = [delex, ext]
5758
POP("result")
5859
}
@@ -76,7 +77,7 @@ FUNC STR TEMPFILE(STR local_path){
7677
STR temp = "/tmp/"
7778
}
7879
STR final_path = JOIN(temp, local_path)
79-
DEL(temp)
80+
DEL("temp")
8081
POP("final_path")
8182
}
8283

lib/std/waveforms.pre

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ FUNC TNS SQUARE(INT freq, INT ms, INT amp, INT sr){
1919
INT frames = /(*(sr, ms), MS_DEN)
2020
TNS shape = [frames]
2121
TNS out = TNS(shape, 0d0)
22-
DEL(shape)
22+
DEL("shape")
2323
INT period = CDIV(sr, freq)
2424
IF(LTE(period, 0d0)){ RETURN(out) }
2525
INT half = /(period, 0d2)
@@ -29,11 +29,11 @@ FUNC TNS SQUARE(INT freq, INT ms, INT amp, INT sr){
2929
IF(GTE(pos, half)){ v = NEG(amp) }
3030
out[idx] = AUDIO_CLAMP(v)
3131
}
32-
DEL(frames)
33-
DEL(period)
34-
DEL(half)
35-
DEL(pos)
36-
DEL(v)
32+
DEL("frames")
33+
DEL("period")
34+
DEL("half")
35+
DEL("pos")
36+
DEL("v")
3737
RETURN(out)
3838
}
3939

@@ -44,7 +44,7 @@ FUNC TNS SAWTOOTH(INT freq, INT ms, INT amp, INT sr){
4444
INT frames = /(*(sr, ms), MS_DEN)
4545
TNS shape = [frames]
4646
TNS out = TNS(shape, 0d0)
47-
DEL(shape)
47+
DEL("shape")
4848
INT period = CDIV(sr, freq)
4949
IF(LTE(period, 0d0)){ RETURN(out) }
5050
PARFOR(idx, frames){
@@ -54,12 +54,12 @@ FUNC TNS SAWTOOTH(INT freq, INT ms, INT amp, INT sr){
5454
INT v = -(tmp, amp)
5555
out[idx] = AUDIO_CLAMP(v)
5656
}
57-
DEL(frames)
58-
DEL(period)
59-
DEL(pos)
60-
DEL(num)
61-
DEL(tmp)
62-
DEL(v)
57+
DEL("frames")
58+
DEL("period")
59+
DEL("pos")
60+
DEL("num")
61+
DEL("tmp")
62+
DEL("v")
6363
RETURN(out)
6464
}
6565

@@ -70,7 +70,7 @@ FUNC TNS TRIANGLE(INT freq, INT ms, INT amp, INT sr){
7070
INT frames = /(*(sr, ms), MS_DEN)
7171
TNS shape = [frames]
7272
TNS out = TNS(shape, 0d0)
73-
DEL(shape)
73+
DEL("shape")
7474
INT period = CDIV(sr, freq)
7575
IF(LTE(period, 0d0)){ RETURN(out) }
7676
INT half = /(period, 0d2)
@@ -89,14 +89,14 @@ FUNC TNS TRIANGLE(INT freq, INT ms, INT amp, INT sr){
8989
}
9090
out[idx] = AUDIO_CLAMP(v)
9191
}
92-
DEL(frames)
93-
DEL(period)
94-
DEL(half)
95-
DEL(pos)
96-
DEL(v)
97-
DEL(num)
98-
DEL(tmp)
99-
DEL(t)
92+
DEL("frames")
93+
DEL("period")
94+
DEL("half")
95+
DEL("pos")
96+
DEL("v")
97+
DEL("num")
98+
DEL("tmp")
99+
DEL("t")
100100
RETURN(out)
101101
}
102102

@@ -108,7 +108,7 @@ FUNC TNS SINE(INT freq, INT ms, INT amp, INT sr){
108108
TNS shape = [frames]
109109
TNS base = SAWTOOTH(freq, ms, amp, sr)
110110
TNS out = TNS(shape, 0d0)
111-
DEL(shape)
111+
DEL("shape")
112112
PARFOR(idx, frames){
113113
INT previ = idx
114114
IF(GT(idx, 0d1)){ previ = -(idx, 0d1) }
@@ -121,13 +121,13 @@ FUNC TNS SINE(INT freq, INT ms, INT amp, INT sr){
121121
INT v = /(sum, 0d3)
122122
out[idx] = AUDIO_CLAMP(v)
123123
}
124-
DEL(frames)
125-
DEL(previ)
126-
DEL(nexti)
127-
DEL(a)
128-
DEL(b)
129-
DEL(c)
130-
DEL(sum)
124+
DEL("frames")
125+
DEL("previ")
126+
DEL("nexti")
127+
DEL("a")
128+
DEL("b")
129+
DEL("c")
130+
DEL("sum")
131131
RETURN(out)
132132
}
133133

@@ -140,7 +140,7 @@ FUNC TNS PULSE(INT freq, INT ms, INT amp, INT sr, INT duty){
140140
INT frames = /(*(sr, ms), MS_DEN)
141141
TNS shape = [frames]
142142
TNS out = TNS(shape, 0d0)
143-
DEL(shape)
143+
DEL("shape")
144144
INT period = CDIV(sr, freq)
145145
IF(LTE(period, 0d0)){ RETURN(out) }
146146
INT thresh = /(*(period, duty), 0d100)
@@ -150,11 +150,11 @@ FUNC TNS PULSE(INT freq, INT ms, INT amp, INT sr, INT duty){
150150
IF(GTE(pos, thresh)){ v = NEG(amp) }
151151
out[idx] = AUDIO_CLAMP(v)
152152
}
153-
DEL(frames)
154-
DEL(period)
155-
DEL(thresh)
156-
DEL(pos)
157-
DEL(v)
153+
DEL("frames")
154+
DEL("period")
155+
DEL("thresh")
156+
DEL("pos")
157+
DEL("v")
158158
RETURN(out)
159159
}
160160

@@ -224,12 +224,12 @@ FUNC TNS ENVELOPE_ADSR( ^
224224
}
225225
out[idx] = AUDIO_CLAMP(v)
226226
}
227-
DEL(slen)
228-
DEL(frames)
229-
DEL(a)
230-
DEL(d)
231-
DEL(r)
232-
DEL(s_len)
227+
DEL("slen")
228+
DEL("frames")
229+
DEL("a")
230+
DEL("d")
231+
DEL("r")
232+
DEL("s_len")
233233
RETURN(out)
234234
}
235235

@@ -260,14 +260,14 @@ FUNC TNS LOWPASS(TNS inp, INT cutoff, INT sr){
260260
IF(GTE(count, 0d1)){ avg = /(sum, count) }
261261
out[idx] = AUDIO_CLAMP(avg)
262262
}
263-
DEL(slen)
264-
DEL(frames)
265-
DEL(period)
266-
DEL(start)
267-
DEL(j)
268-
DEL(sum)
269-
DEL(count)
270-
DEL(avg)
263+
DEL("slen")
264+
DEL("frames")
265+
DEL("period")
266+
DEL("start")
267+
DEL("j")
268+
DEL("sum")
269+
DEL("count")
270+
DEL("avg")
271271
RETURN(out)
272272
}
273273

@@ -285,8 +285,8 @@ FUNC TNS HIGHPASS(TNS inp, INT cutoff, INT sr){
285285
INT b = low[i1]
286286
out[i1] = AUDIO_CLAMP(-(a, b))
287287
}
288-
DEL(slen)
289-
DEL(frames)
290-
DEL(low)
288+
DEL("slen")
289+
DEL("frames")
290+
DEL("low")
291291
RETURN(out)
292292
}

0 commit comments

Comments
 (0)