Skip to content

Commit

Permalink
Decide about return/defer
Browse files Browse the repository at this point in the history
  • Loading branch information
dy committed Sep 30, 2024
1 parent 11c807f commit c892adb
Show file tree
Hide file tree
Showing 5 changed files with 231 additions and 174 deletions.
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ Compiles to compact 0-runtime WASM with linear memory.<br/>
x[i] x[] ;; member access, length
a..b a.. ..b .. ;; ranges
|> _ ;; pipe/loop, map
./ ../ / ;; continue/skip, break/stop, return
./ ../ / . ;; continue/skip, break/stop, return, void
~ ~= ~< ~/ ~* ~// ~** ;; clamp, normalize, lerp
* ^ . ;; static, defer, void
# ^ ;; static, defer
;; Numbers
16, 0x10, 0b0; ;; int, hex or binary
Expand Down Expand Up @@ -81,7 +81,7 @@ m[0..] = m[-1..]; ;; reverse
m[0..] = m[1..,0]; ;; rotate
;; Conditions
a ? b; ;; if a then b, void
a ? b; ;; if a then b
sign = a < 0 ? -1 : +1; ;; ternary conditional
(2+2 >= 4) ? log(1) : ;; multiline/switch
3 <= 1..2 ? log(2) : ;; else if
Expand All @@ -91,8 +91,8 @@ a && b || c; ;; (a and b) or c
;; Loops
(a, b, c) |> f(_); ;; for each item in a, b, c do f(item)
(i = 10..) |> ( ;; descend over range
i < 5 ? ./ ;; if item < 5 skip (continue)
i < 0 ? ../ ;; if item < 0 stop (break)
i < 5 ? a ./; ;; if item < 5 skip (continue)
i < 0 ? a ../; ;; if item < 0 stop (break)
); ;;
x[..] |> f(_) |> g(_); ;; pipeline sequence
x[..] |>= _ * 2; ;; overwrite source
Expand All @@ -114,12 +114,14 @@ times(4), times(,5); ;; 4, 5: optional, skipped arg
dup(x) = (x,x); ;; return multiple
(a,b) = dup(b); ;; destructure
a=1,b=1; x()=(a=2;b=2); x(); ;; a==1, b==2: first statement declares locals
a() = ( *i=0; ++i ); ;; static vars: keep value between calls
;; Static vars
a() = ( #i=0; ++i ); ;; i keeps value between calls
a(), a(); ;; 1,2
a1() = ( *copy=a; copy()); ;; clone function
a1() = ( #copy=a; copy() ); ;; clone function
a(), a(); a1(), a1(); ;; 3,4; 1,2;
f() = (*t=0; ^t++; t*2); ;; defer: t++ called after return
x(a[], f()) = (a[0] + f(1)); ;; array, function args
f() = ( #t=0; ^t++; t*2 ); ;; defer: t++ called after return
x(a[], f()) = f(a[0]); ;; array, func args
;; Export
x, y, z ;; exports last statement
Expand Down
Loading

0 comments on commit c892adb

Please sign in to comment.