Skip to content

Commit

Permalink
Add map_inplace function to array module
Browse files Browse the repository at this point in the history
  • Loading branch information
tjammer committed Nov 16, 2024
1 parent 035900a commit 9c0e289
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
13 changes: 13 additions & 0 deletions std/array.smu
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,19 @@ fun map(arr, f) {
inner(!ret, 0)
}

fun map_inplace(arr&, f) {
fun rec inner(i) {
if i == length(arr) {
()
} else {
f(&arr.[i])
inner(i + 1)
}
}

inner(0)
}

fun pop_back(arr&) {
use option
if length(arr) == 0 {
Expand Down
4 changes: 2 additions & 2 deletions test/functions.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -2359,8 +2359,8 @@ The lamba passed as array-iter argument is polymorphic
!7 = !DILocation(line: 63, column: 6, scope: !2)
!8 = distinct !DISubprogram(name: "_array_iteri", linkageName: "__array_iteri_al_2lru__", scope: !3, file: !3, line: 58, type: !4, scopeLine: 58, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !5)
!9 = !DILocation(line: 68, column: 2, scope: !8)
!10 = distinct !DISubprogram(name: "_array_pop_back", linkageName: "__array_pop_back_ac_rvc__", scope: !3, file: !3, line: 112, type: !4, scopeLine: 112, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !5)
!11 = !DILocation(line: 114, column: 5, scope: !10)
!10 = distinct !DISubprogram(name: "_array_pop_back", linkageName: "__array_pop_back_ac_rvc__", scope: !3, file: !3, line: 125, type: !4, scopeLine: 125, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !5)
!11 = !DILocation(line: 127, column: 5, scope: !10)
!12 = distinct !DISubprogram(name: "_array_push", linkageName: "__array_push_ac_c_", scope: !3, file: !3, line: 29, type: !4, scopeLine: 29, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !5)
!13 = !DILocation(line: 33, column: 5, scope: !12)
!14 = !DILocation(line: 34, column: 7, scope: !12)
Expand Down
8 changes: 4 additions & 4 deletions test/memory.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,11 @@ Drop last element

!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "schmu 0.1x", isOptimized: false, runtimeVersion: 0, emissionKind: LineTablesOnly)
!1 = !DIFile(filename: "array_drop_back.smu", directory: "$TESTCASE_ROOT")
!2 = distinct !DISubprogram(name: "_array_pop_back", linkageName: "__array_pop_back_2al2_rval2__", scope: !3, file: !3, line: 112, type: !4, scopeLine: 112, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !5)
!2 = distinct !DISubprogram(name: "_array_pop_back", linkageName: "__array_pop_back_2al2_rval2__", scope: !3, file: !3, line: 125, type: !4, scopeLine: 125, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !5)
!3 = !DIFile(filename: "array.smu", directory: "")
!4 = !DISubroutineType(flags: DIFlagPrototyped, types: !5)
!5 = !{}
!6 = !DILocation(line: 114, column: 5, scope: !2)
!6 = !DILocation(line: 127, column: 5, scope: !2)
!7 = distinct !DISubprogram(name: "main", linkageName: "main", scope: !8, file: !8, line: 1, type: !4, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !5)
!8 = !DIFile(filename: "array_drop_back.smu", directory: "")
!9 = !DILocation(line: 3, column: 6, scope: !7)
Expand Down Expand Up @@ -1150,8 +1150,8 @@ Monomorphization in closures
!7 = !DILocation(line: 50, column: 6, scope: !2)
!8 = distinct !DISubprogram(name: "_array_iter", linkageName: "__array_iter_al_lru__", scope: !3, file: !3, line: 45, type: !4, scopeLine: 45, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !5)
!9 = !DILocation(line: 55, column: 2, scope: !8)
!10 = distinct !DISubprogram(name: "_array_swap_items", linkageName: "__array_swap_items_al__", scope: !3, file: !3, line: 122, type: !4, scopeLine: 122, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !5)
!11 = !DILocation(line: 123, column: 5, scope: !10)
!10 = distinct !DISubprogram(name: "_array_swap_items", linkageName: "__array_swap_items_al__", scope: !3, file: !3, line: 135, type: !4, scopeLine: 135, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !5)
!11 = !DILocation(line: 136, column: 5, scope: !10)
!12 = distinct !DISubprogram(name: "__fun_schmu0", linkageName: "__fun_schmu0_Cal_2lrl_ll_", scope: !13, file: !13, line: 5, type: !4, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !5)
!13 = !DIFile(filename: "closure_monomorph.smu", directory: "")
!14 = !DILocation(line: 6, column: 9, scope: !12)
Expand Down

0 comments on commit 9c0e289

Please sign in to comment.