Skip to content

Commit

Permalink
Repetition macro for function calls (thank you Matthew Flatt!)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashton314 committed Jan 24, 2024
1 parent 14ca022 commit 29c6ee9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
22 changes: 20 additions & 2 deletions main.rhm
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,26 @@ expr.macro '$func dyn_app ($args, ...)':
$func #%call ($temps, ...)'
| '$func #%call ($args, ...)'

repet.macro '$func dyn_app ($args, ...)':
repet_meta.pack_list('(dyn_app, n, [$args, ...], 1, 0, (), #false)')
repet.macro '$func dyn_app ($(args :: repet_meta.Parsed))':
~op_stx self
def '($func_orig, $func_name, $func_expr, $func_depth, $func_use_depth, $func_statinfos, $func_is_immed)':
repet_meta.unpack_list(func)
def '($orig, $name, $expr, $depth, $use_depth, $statinfos, $is_immed)':
repet_meta.unpack_list(args)
unless func_depth.unwrap() == 0 && depth.unwrap() == 1
| error("only handle argument repetitions right now")
def (pred, si): // ← just a way to grab the static info we need?
annot_meta.unpack_predicate(match 'List' | '$(p :: annot_meta.Parsed)': p)
repet_meta.pack_list('($self(),
$name,
for PairList:
each:
elem: ($expr) :~ PairList
$func_expr dyn_app (elem),
$depth,
$use_depth,
$si,
#false)')

expr.macro
| '$thing dyn_idx [$idx] $assn_op $rhs_expr':
Expand Down
10 changes: 10 additions & 0 deletions tests/general.rhm
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,13 @@ check_dyn:
for:
each v: should_be_lst
println("You got" +& v)

/// Repetition macros

check_dyn:
block:
fun foo(x :: Dyn) :: Dyn:
x + 1

def [xs, ...] = [1, 2, 3]
[foo(xs), ...]

0 comments on commit 29c6ee9

Please sign in to comment.