History

Add tests for parametric polymorphism. Update debugger to show parametric type as '*'. - e.g. reverse(list of *):list of *

arr committed 9 years ago

Commit 3098fb81 parent e5f12523 files · +41 −5Browse files

Unified · Split

3 files
  1. limbo/basic_limbo_tests.b +39 −0
  2. src/asm/sbl_reader.cpp +1 −4
  3. src/vm/execution_table.cpp +1 −1
limbo/basic_limbo_tests.b+39−0
@@ -22,6 +22,7 @@ init(args: list of string) · 21 unmodified lines
2222 args = tl args;
2323 }
2424
25+ test_poly();
2526 test_function_refs();
2627 test_alt();
2728 test_channel();
@@ -39,6 +40,44 @@ init(args: list of string) · 11 unmodified lines
3940 test_for_loop_function_call();
4041 }
4142
43+reverse[T](l: list of T): list of T
44+{
45+ rl: list of T;
46+ for(; l != nil; l = tl l)
47+ rl = hd l :: rl;
48+ return rl;
49+}
50+
51+equal[T](l, r: list of T): int
52+{
53+ l_v, r_v : T;
54+ l_v = hd l;
55+ r_v = hd r;
56+ l = tl l;
57+ r = tl r;
58+
59+ while (l_v == r_v)
60+ {
61+ l_v = hd l;
62+ r_v = hd r;
63+ l = tl l;
64+ r = tl r;
65+
66+ if (l == nil || r == nil)
67+ break;
68+ }
69+
70+ return l == r;
71+}
72+
73+test_poly()
74+{
75+ sys->print("test_poly()\n");
76+ l1 := list of {"a", "b", "c"};
77+ l2 := reverse(l1);
78+ if (!equal(l1, reverse(l2)) != 0) raise TEST_FAILED();
79+}
80+
4281 str_cmp(s1: string, s2: string): int
4382 {
4483 if (s1 < s2)
src/asm/sbl_reader.cpp+1−4
@@ -599,10 +599,7 @@ namespace · 598 unmodified lines
599599 case type_class_t::integer: return "int";
600600 case type_class_t::real: return "real";
601601 case type_class_t::string: return "string";
602−
603− case type_class_t::poly:
604− assert(false && "Not fully implemented");
605− return "poly<T>";
602+ case type_class_t::poly: return "*";
606603
607604 case type_class_t::array:
608605 return "array of " + to_string(tt.resolve_table_index<type_t>(t.value_index_1), tt);
src/vm/execution_table.cpp+1−1
@@ -1094,7 +1094,7 @@ namespace · 1093 unmodified lines
10941094 EXEC_DECL(newcl) { _newc_(r, vm, intrinsic_type_desc::type<big_t>(), _mov_<big_t>); }
10951095 EXEC_DECL(newcp) { _newc_(r, vm, intrinsic_type_desc::type<pointer_t>(), _mov_<vm_alloc_t>); }
10961096
1097− EXEC_DECL(newcm)
1097+ EXEC_DECL(newcm)
10981098 {
10991099 auto memory_size = vt_ref<word_t>(r.src);
11001100 auto channel_data_type = type_descriptor_t::create(memory_size);