diff --git a/src/data.hpp b/src/data.hpp index 256a7e4..dc049b5 100644 --- a/src/data.hpp +++ b/src/data.hpp @@ -7,6 +7,6 @@ namespace lily { struct constructor { int parent_type; int tag; - std::vector params; + std::vector> params; }; } diff --git a/src/main.cpp b/src/main.cpp index 8298a1e..7afe916 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,7 +7,7 @@ int main() { lily::parse( "data Bool = { True, False }\n" "data Color = { Red, Black }\n" - "data IntList = { Nil, Cons(Int, Int) }\n" + "data IntList = { Nil, Cons(Int, IntList) }\n" "defn add x y = { x + y }"); } catch(lily::error& e) { std::cout << e.message << std::endl; diff --git a/src/parser.cpp b/src/parser.cpp index 4892307..7223edd 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -167,10 +167,10 @@ namespace lily { return prog.types[str]; } - static void collect_type_params(program& prog, std::vector& into, pgs_tree* params, const char* source) { + static void collect_type_params(program& prog, std::vector>& into, pgs_tree* params, const char* source) { while(true) { pgs_tree* param = PGS_TREE_NT_CHILD(*params, 0); - into.push_back(type_tree(prog, param, source)); + into.push_back(std::weak_ptr(type_tree(prog, param, source))); if(PGS_TREE_NT_COUNT(*params) == 1) break; params = PGS_TREE_NT_CHILD(*params, 2); @@ -213,9 +213,9 @@ namespace lily { if(prog.types.count(data_name)) throw error("cannot redefine type"); int new_type = prog.next_free_type_id++; + prog.types[data_name] = type_ptr(new type_int(new_type)); collect_constructors(prog, new_type, PGS_TREE_NT_CHILD(*PGS_TREE_NT_CHILD(*def, PGS_TREE_NT_COUNT(*def) - 1), 1), source); - prog.types[data_name] = type_ptr(new type_int(new_type)); } }