Skip to content

Commit

Permalink
std: add list methods (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
tjjfvi authored Oct 22, 2024
1 parent a2edabf commit 9ce52cc
Show file tree
Hide file tree
Showing 32 changed files with 595 additions and 222 deletions.
35 changes: 35 additions & 0 deletions tests/programs/cyclist.vi
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

use std::{
io::println,
u32,
bool::{true, false},
list::List,
list::List::{len, map, join, pop_front, push_front, push_back, iter},
option::Option::{unwrap, Some},
};

fn main(io) {
let list = [0];
while list.len() < 32 {
list ++= {list}.map(fn(x) list.len() + x);
}

while list.pop_front() is Some(val) {
cycle(&list, val);
io.println(u32::to_string(val) ++ ";\t" ++ show(list));
}
}

const show = List::to_string(u32::to_string);

fn cycle(&list, count) {
let len = list.len();
if len {
count = count % len;
while count {
let el = list.pop_front().unwrap();
list.push_back(el);
count -= 1;
}
}
}
22 changes: 11 additions & 11 deletions tests/snaps/vine/basic_diverge/compiled.iv
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
::basic_diverge::foo = fn(0 fn(ref(n6 n10) n7))
::std::io::println = fn(ref(n8 _) fn(n12 _))
::std::u32::to_string = fn(n10 n11)
::std::str::concat = fn(tup(13 fn(n9 tup(10 tup(122 tup(101 tup(114 tup(111 tup(95 tup(99 tup(111 tup(117 tup(110 tup(116 tup(58 tup(32 n9))))))))))))))) fn(n11 n12))
::std::str::concat = fn(tup(13 tup(tup(10 tup(122 tup(101 tup(114 tup(111 tup(95 tup(99 tup(111 tup(117 tup(110 tup(116 tup(58 tup(32 n9))))))))))))) n9)) fn(n11 n12))
}

::basic_diverge::foo { fn(?(::basic_diverge::foo::4 ::basic_diverge::foo::1 x(n0 x(n1 n2))) fn(ref(n0 n1) n2)) }

::basic_diverge::foo::1 { x(n1 x(n1 tup(9 fn(n0 tup(110 tup(111 tup(110 tup(45 tup(122 tup(101 tup(114 tup(111 tup(33 n0))))))))))))) }
::basic_diverge::foo::1 { x(n1 x(n1 tup(9 tup(tup(110 tup(111 tup(110 tup(45 tup(122 tup(101 tup(114 tup(111 tup(33 n0))))))))) n0)))) }

::basic_diverge::foo::4 { x(@add(1 n1) x(n1 tup(4 fn(n0 tup(122 tup(101 tup(114 tup(111 n0)))))))) }
::basic_diverge::foo::4 { x(@add(1 n1) x(n1 tup(4 tup(tup(122 tup(101 tup(114 tup(111 n0)))) n0)))) }

::std::io::println {
fn(ref(n0 n3) fn(n1 _))
Expand All @@ -27,7 +27,7 @@
}

::std::io::print {
fn(ref(n0 n1) fn(tup(n2 fn(_ n3)) _))
fn(ref(n0 n1) fn(tup(n2 tup(n3 _)) _))
::std::io::print::1 = x(n0 x(n1 x(n2 n3)))
}

Expand All @@ -43,24 +43,24 @@

::std::io::print_char { fn(ref(@io_print_char(char io) io) fn(char _)) }

::std::str::concat { fn(tup(@add(n0 n1) fn(n3 n4)) fn(tup(n0 fn(n2 n3)) tup(n1 fn(n2 n4)))) }
::std::str::concat { fn(tup(@add(n1 n2) tup(n3 n0)) fn(tup(n1 tup(n0 n4)) tup(n2 tup(n3 n4)))) }

::std::u32::to_string { fn(dup177(?(::std::u32::to_string::5 ::std::u32::to_string::1 x(n1 n0)) n1) n0) }
::std::u32::to_string { fn(dup241(?(::std::u32::to_string::5 ::std::u32::to_string::1 x(n1 n0)) n1) n0) }

::std::u32::to_string::1 {
x(n1 n2)
::std::u32::to_string::2 = x(n1 x(tup(0 fn(n0 n0)) n2))
::std::u32::to_string::2 = x(n1 x(tup(0 tup(n0 n0)) n2))
}

::std::u32::to_string::2 { x(dup177(?(::std::u32::to_string::4 ::std::u32::to_string::3 x(n2 n0)) n2) n0) }
::std::u32::to_string::2 { x(dup241(?(::std::u32::to_string::4 ::std::u32::to_string::3 x(n2 n0)) n2) n0) }

::std::u32::to_string::3 {
x(dup177(@rem(10 n1) @div(10 n5)) x(tup(@add(1 n0) fn(n3 n4)) n6))
x(dup241(@rem(10 n1) @div(10 n5)) x(tup(@add(1 n0) tup(n3 n4)) n6))
48 = @add(n1 n2)
::std::u32::to_string::2 = x(n5 x(tup(n0 fn(n3 tup(n2 n4))) n6))
::std::u32::to_string::2 = x(n5 x(tup(n0 tup(tup(n2 n3) n4)) n6))
}

::std::u32::to_string::4 { x(_ x(n0 n0)) }

::std::u32::to_string::5 { x(_ tup(1 fn(n0 tup(48 n0)))) }
::std::u32::to_string::5 { x(_ tup(1 tup(tup(48 n0) n0))) }

197 changes: 197 additions & 0 deletions tests/snaps/vine/cyclist/compiled.iv
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@

::main { ::cyclist::main }

::cyclist::main {
fn(n1 _)
::cyclist::main::1 = x(tup(1 tup(tup(0 n0) n0)) n2)
::cyclist::main::4 = x(n1 n2)
}

::cyclist::main::1 {
x(n0 n2)
::std::list::List::len = fn(ref(n0 n1) @lt(32 ?(::cyclist::main::3 ::cyclist::main::2 x(n1 n2))))
}

::cyclist::main::2 {
x(dup2(n4 n5) n7)
::std::list::List::map = fn(ref(n4 _) fn(fn(n0 n1) n3))
::std::list::List::len = fn(ref(n5 n2) @add(n0 n1))
::std::str::concat = fn(n2 fn(n3 n6))
::cyclist::main::1 = x(n6 n7)
}

::cyclist::main::3 { x(n0 n0) }

::cyclist::main::4 {
x(n1 n0)
::std::list::List::pop_front = fn(ref(n0 n2) enum(::cyclist::main::5 enum(_ x(n1 n2))))
}

::cyclist::main::5 {
enum(dup4(n10 n11) x(n5 n6))
::cyclist::cycle = fn(ref(n6 dup2(n8 n9)) fn(n10 _))
::std::io::println = fn(ref(n5 n7) fn(n4 _))
::std::u32::to_string = fn(n11 n1)
::std::str::concat = fn(n1 fn(tup(2 tup(tup(59 tup(9 n0)) n0)) n2))
::cyclist::show = fn(n8 n3)
::std::str::concat = fn(n2 fn(n3 n4))
::cyclist::main::4 = x(n7 n9)
}

::cyclist::show {
n0
::std::list::List::to_string = fn(::std::u32::to_string n0)
}

::cyclist::cycle {
fn(ref(n0 n2) fn(n3 _))
::std::list::List::len = fn(ref(n0 n1) dup13(?(::cyclist::cycle::5 ::cyclist::cycle::1 x(n1 x(n2 x(n3 n4)))) n4))
}

::cyclist::cycle::1 {
x(n1 x(n2 x(@rem(n0 n3) n0)))
::cyclist::cycle::2 = x(n1 x(n2 n3))
}

::cyclist::cycle::2 { x(n0 x(n1 dup12(?(::cyclist::cycle::4 ::cyclist::cycle::3 x(n0 x(n1 n2))) n2))) }

::cyclist::cycle::3 {
x(n3 x(n5 @sub(1 n6)))
::std::list::List::pop_front = fn(ref(n3 n1) n0)
::std::option::Option::unwrap = fn(ref(n0 _) n2)
::std::list::List::push_back = fn(ref(n1 n4) fn(n2 _))
::cyclist::cycle::2 = x(n4 x(n5 n6))
}

::cyclist::cycle::4 { x(n0 x(n0 _)) }

::cyclist::cycle::5 { x(n0 x(n0 _)) }

::std::io::println {
fn(ref(n0 n3) fn(n1 _))
::std::io::print = fn(ref(n0 n2) fn(n1 _))
::std::io::print_char = fn(ref(n2 n3) fn(10 _))
}

::std::io::print {
fn(ref(n0 n1) fn(tup(n2 tup(n3 _)) _))
::std::io::print::1 = x(n0 x(n1 x(n2 n3)))
}

::std::io::print::1 { x(n0 x(n1 x(dup26(?(::std::io::print::3 ::std::io::print::2 x(n0 x(n1 x(n3 n2)))) n3) n2))) }

::std::io::print::2 {
x(n1 x(n3 x(@sub(1 n4) tup(n0 n5))))
::std::io::print_char = fn(ref(n1 n2) fn(n0 _))
::std::io::print::1 = x(n2 x(n3 x(n4 n5)))
}

::std::io::print::3 { x(n0 x(n0 _)) }

::std::io::print_char { fn(ref(@io_print_char(char io) io) fn(char _)) }

::std::list::List::len { fn(ref(tup(dup50(n2 n3) n0) tup(n3 n0)) n2) }

::std::list::List::map {
fn(ref(tup(dup53(n4 n5) tup(n0 _)) _) fn(n1 tup(n4 tup(n2 n3))))
::std::list::List::map::1 = x(n5 x(n0 x(n1 x(n2 n3))))
}

::std::list::List::map::1 { x(dup53(?(::std::list::List::map::3 ::std::list::List::map::2 x(n4 n0)) n4) n0) }

::std::list::List::map::2 {
x(@sub(1 n2) x(tup(n0 n3) x(dup55(fn(n0 n1) n6) x(tup(n1 n4) n5))))
::std::list::List::map::1 = x(n2 x(n3 x(n6 x(n4 n5))))
}

::std::list::List::map::3 { x(_ x(_ x(_ x(n0 n0)))) }

::std::list::List::pop_front { fn(ref(tup(dup64(?(::std::list::List::pop_front::2 ::std::list::List::pop_front::1 x(n1 x(n2 x(n3 x(n4 n5))))) n1) tup(n3 n0)) tup(n2 tup(n4 n0))) n5) }

::std::list::List::pop_front::1 {
x(@sub(1 n1) x(n1 x(tup(n0 n2) x(n2 n3))))
::std::option::Option::Some = fn(n0 n3)
}

::std::list::List::pop_front::2 { x(n0 x(n0 x(n1 x(n1 ::std::option::Option::None)))) }

::std::list::List::push_back {
fn(ref(n2 n3) fn(n0 _))
::std::str::concat = fn(n2 fn(tup(1 tup(tup(n0 n1) n1)) n3))
}

::std::list::List::join {
fn(ref(n0 _) fn(n2 n4))
::std::list::List::into_iter = fn(ref(n0 _) n1)
::std::list::List::into_iter::next = fn(ref(n1 n3) enum(::std::list::List::join::1 enum(::std::list::List::join::5 x(n2 x(n3 n4)))))
}

::std::list::List::join::1 {
enum(n2 x(n0 x(n1 n3)))
::std::list::List::join::2 = x(n0 x(n1 x(n2 n3)))
}

::std::list::List::join::2 {
x(n1 x(n0 n3))
::std::list::List::into_iter::next = fn(ref(n0 n2) enum(::std::list::List::join::3 enum(::std::list::List::join::4 x(n1 x(n2 n3)))))
}

::std::list::List::join::3 {
enum(n0 x(dup80(n6 n7) x(n3 x(n2 n5))))
::std::str::concat = fn(n6 fn(n0 n1))
::std::str::concat = fn(n2 fn(n1 n4))
::std::list::List::join::2 = x(n7 x(n3 x(n4 n5)))
}

::std::list::List::join::4 { x(_ x(_ x(n0 n0))) }

::std::list::List::join::5 { x(_ x(_ tup(0 tup(n0 n0)))) }

::std::list::List::to_string {
fn(n2 fn(n1 n8))
::std::list::List::map = fn(ref(n1 _) fn(n2 n3))
::std::list::List::join = fn(ref(n3 _) fn(tup(2 tup(tup(44 tup(32 n4)) n4)) n5))
::std::str::concat = fn(tup(1 tup(tup(91 n0) n0)) fn(n5 n7))
::std::str::concat = fn(n7 fn(tup(1 tup(tup(93 n6) n6)) n8))
}

::std::list::List::into_iter { fn(ref(tup(n0 tup(n1 _)) _) tup(n0 n1)) }

::std::list::List::into_iter::next { fn(ref(tup(dup110(?(::std::list::List::into_iter::next::2 ::std::list::List::into_iter::next::1 x(n0 x(n1 x(n2 x(n3 n4))))) n0) n2) tup(n1 n3)) n4) }

::std::list::List::into_iter::next::1 {
x(@sub(1 n1) x(n1 x(tup(n0 n2) x(n2 n3))))
::std::option::Option::Some = fn(n0 n3)
}

::std::list::List::into_iter::next::2 { x(n0 x(n0 x(n1 x(n1 ::std::option::Option::None)))) }

::std::option::Option::Some { fn(n0 enum(enum(n0 n1) enum(_ n1))) }

::std::option::Option::None { enum(_ enum(n0 n0)) }

::std::option::Option::unwrap { fn(ref(enum(::std::option::Option::unwrap::1 enum(_ n0)) _) n0) }

::std::option::Option::unwrap::1 { enum(n0 n0) }

::std::str::concat { fn(tup(@add(n1 n2) tup(n3 n0)) fn(tup(n1 tup(n0 n4)) tup(n2 tup(n3 n4)))) }

::std::u32::to_string { fn(dup249(?(::std::u32::to_string::5 ::std::u32::to_string::1 x(n1 n0)) n1) n0) }

::std::u32::to_string::1 {
x(n1 n2)
::std::u32::to_string::2 = x(n1 x(tup(0 tup(n0 n0)) n2))
}

::std::u32::to_string::2 { x(dup249(?(::std::u32::to_string::4 ::std::u32::to_string::3 x(n2 n0)) n2) n0) }

::std::u32::to_string::3 {
x(dup249(@rem(10 n1) @div(10 n5)) x(tup(@add(1 n0) tup(n3 n4)) n6))
48 = @add(n1 n2)
::std::u32::to_string::2 = x(n5 x(tup(n0 tup(tup(n2 n3) n4)) n6))
}

::std::u32::to_string::4 { x(_ x(n0 n0)) }

::std::u32::to_string::5 { x(_ tup(1 tup(tup(48 n0) n0))) }

32 changes: 32 additions & 0 deletions tests/snaps/vine/cyclist/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
0; [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
1; [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 2]
3; [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 2, 4, 5, 6]
7; [15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 2, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14]
15; [31, 2, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]
31; [9, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 2, 4, 5, 6, 8]
9; [20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 2, 4, 5, 6, 8, 10, 11, 12, 13, 14, 16, 17, 18, 19]
20; [16, 17, 18, 19, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 2, 4, 5, 6, 8, 10, 11, 12, 13, 14]
16; [6, 8, 10, 11, 12, 13, 14, 17, 18, 19, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 2, 4, 5]
6; [17, 18, 19, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 2, 4, 5, 8, 10, 11, 12, 13, 14]
17; [11, 12, 13, 14, 18, 19, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 2, 4, 5, 8, 10]
11; [27, 28, 29, 30, 2, 4, 5, 8, 10, 12, 13, 14, 18, 19, 21, 22, 23, 24, 25, 26]
27; [12, 13, 14, 18, 19, 21, 22, 23, 24, 25, 26, 28, 29, 30, 2, 4, 5, 8, 10]
12; [30, 2, 4, 5, 8, 10, 13, 14, 18, 19, 21, 22, 23, 24, 25, 26, 28, 29]
30; [25, 26, 28, 29, 2, 4, 5, 8, 10, 13, 14, 18, 19, 21, 22, 23, 24]
25; [14, 18, 19, 21, 22, 23, 24, 26, 28, 29, 2, 4, 5, 8, 10, 13]
14; [13, 18, 19, 21, 22, 23, 24, 26, 28, 29, 2, 4, 5, 8, 10]
13; [10, 18, 19, 21, 22, 23, 24, 26, 28, 29, 2, 4, 5, 8]
10; [4, 5, 8, 18, 19, 21, 22, 23, 24, 26, 28, 29, 2]
4; [21, 22, 23, 24, 26, 28, 29, 2, 5, 8, 18, 19]
21; [19, 22, 23, 24, 26, 28, 29, 2, 5, 8, 18]
19; [18, 22, 23, 24, 26, 28, 29, 2, 5, 8]
18; [22, 23, 24, 26, 28, 29, 2, 5, 8]
22; [5, 8, 23, 24, 26, 28, 29, 2]
5; [29, 2, 8, 23, 24, 26, 28]
29; [28, 2, 8, 23, 24, 26]
28; [24, 26, 2, 8, 23]
24; [26, 2, 8, 23]
26; [23, 2, 8]
23; [8, 2]
8; [2]
2; []
15 changes: 15 additions & 0 deletions tests/snaps/vine/cyclist/stats.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

Interactions
Total 115_848
Annihilate 60_232
Commute 2_523
Copy 9_367
Erase 10_056
Expand 17_464
Call 10_558
Branch 5_648

Memory
Heap 7_792 B
Allocated 2_432_128 B
Freed 2_432_128 B
20 changes: 10 additions & 10 deletions tests/snaps/vine/fib/compiled.iv
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
x(n8 x(dup3(n12 @add(1 n14)) x(dup4(n9 @add(n11 n7)) dup5(n10 n11))))
::std::io::println = fn(ref(n8 n13) fn(n6 _))
::std::u32::to_string = fn(n12 n1)
::std::str::concat = fn(tup(4 fn(n0 tup(102 tup(105 tup(98 tup(40 n0)))))) fn(n1 n3))
::std::str::concat = fn(n3 fn(tup(4 fn(n2 tup(41 tup(32 tup(61 tup(32 n2)))))) n4))
::std::str::concat = fn(tup(4 tup(tup(102 tup(105 tup(98 tup(40 n0)))) n0)) fn(n1 n3))
::std::str::concat = fn(n3 fn(tup(4 tup(tup(41 tup(32 tup(61 tup(32 n2)))) n2)) n4))
::std::u32::to_string = fn(n9 n5)
::std::str::concat = fn(n4 fn(n5 n6))
tup(n10 n7) = tup(n15 n16)
Expand All @@ -27,7 +27,7 @@
}

::std::io::print {
fn(ref(n0 n1) fn(tup(n2 fn(_ n3)) _))
fn(ref(n0 n1) fn(tup(n2 tup(n3 _)) _))
::std::io::print::1 = x(n0 x(n1 x(n2 n3)))
}

Expand All @@ -43,24 +43,24 @@

::std::io::print_char { fn(ref(@io_print_char(char io) io) fn(char _)) }

::std::str::concat { fn(tup(@add(n0 n1) fn(n3 n4)) fn(tup(n0 fn(n2 n3)) tup(n1 fn(n2 n4)))) }
::std::str::concat { fn(tup(@add(n1 n2) tup(n3 n0)) fn(tup(n1 tup(n0 n4)) tup(n2 tup(n3 n4)))) }

::std::u32::to_string { fn(dup175(?(::std::u32::to_string::5 ::std::u32::to_string::1 x(n1 n0)) n1) n0) }
::std::u32::to_string { fn(dup239(?(::std::u32::to_string::5 ::std::u32::to_string::1 x(n1 n0)) n1) n0) }

::std::u32::to_string::1 {
x(n1 n2)
::std::u32::to_string::2 = x(n1 x(tup(0 fn(n0 n0)) n2))
::std::u32::to_string::2 = x(n1 x(tup(0 tup(n0 n0)) n2))
}

::std::u32::to_string::2 { x(dup175(?(::std::u32::to_string::4 ::std::u32::to_string::3 x(n2 n0)) n2) n0) }
::std::u32::to_string::2 { x(dup239(?(::std::u32::to_string::4 ::std::u32::to_string::3 x(n2 n0)) n2) n0) }

::std::u32::to_string::3 {
x(dup175(@rem(10 n1) @div(10 n5)) x(tup(@add(1 n0) fn(n3 n4)) n6))
x(dup239(@rem(10 n1) @div(10 n5)) x(tup(@add(1 n0) tup(n3 n4)) n6))
48 = @add(n1 n2)
::std::u32::to_string::2 = x(n5 x(tup(n0 fn(n3 tup(n2 n4))) n6))
::std::u32::to_string::2 = x(n5 x(tup(n0 tup(tup(n2 n3) n4)) n6))
}

::std::u32::to_string::4 { x(_ x(n0 n0)) }

::std::u32::to_string::5 { x(_ tup(1 fn(n0 tup(48 n0)))) }
::std::u32::to_string::5 { x(_ tup(1 tup(tup(48 n0) n0))) }

Loading

0 comments on commit 9ce52cc

Please sign in to comment.