summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ast/ast.hpp4
-rw-r--r--src/expand/derive.cpp21
-rw-r--r--src/parse/root.cpp8
-rw-r--r--src/resolve/absolute.cpp8
-rw-r--r--src/resolve/index.cpp4
5 files changed, 37 insertions, 8 deletions
diff --git a/src/ast/ast.hpp b/src/ast/ast.hpp
index 03827d6e..4ca16210 100644
--- a/src/ast/ast.hpp
+++ b/src/ast/ast.hpp
@@ -346,6 +346,10 @@ public:
m_params( move(params) ),
m_data( StructData::make_Struct({mv$(fields)}) )
{}
+ Struct( GenericParams params, ::std::vector<TupleItem> fields ):
+ m_params( move(params) ),
+ m_data( StructData::make_Tuple({mv$(fields)}) )
+ {}
const GenericParams& params() const { return m_params; }
diff --git a/src/expand/derive.cpp b/src/expand/derive.cpp
index 6b52982d..c14753e9 100644
--- a/src/expand/derive.cpp
+++ b/src/expand/derive.cpp
@@ -83,7 +83,26 @@ public:
node = NEWNODE(AST::ExprNode_CallMethod, mv$(node), AST::PathNode("finish",{}), {});
),
(Tuple,
- assert(!"TODO: derive() debug on tuple struct");
+ node = NEWNODE(AST::ExprNode_NamedValue, AST::Path("f"));
+ node = NEWNODE(AST::ExprNode_CallMethod,
+ mv$(node), AST::PathNode("debug_tuple",{}),
+ vec$( NEWNODE(AST::ExprNode_String, name) )
+ );
+ for( unsigned int idx = 0; idx < e.ents.size(); idx ++ )
+ {
+ node = NEWNODE(AST::ExprNode_CallMethod,
+ mv$(node), AST::PathNode("field",{}),
+ vec$(
+ NEWNODE(AST::ExprNode_UniOp, AST::ExprNode_UniOp::REF,
+ NEWNODE(AST::ExprNode_Field,
+ NEWNODE(AST::ExprNode_NamedValue, AST::Path("self")),
+ FMT(idx)
+ )
+ )
+ )
+ );
+ }
+ node = NEWNODE(AST::ExprNode_CallMethod, mv$(node), AST::PathNode("finish",{}), {});
)
)
diff --git a/src/parse/root.cpp b/src/parse/root.cpp
index 0ce6935b..4dc8f999 100644
--- a/src/parse/root.cpp
+++ b/src/parse/root.cpp
@@ -442,7 +442,7 @@ AST::Struct Parse_Struct(TokenStream& lex, const AST::MetaItems& meta_items)
{
// Tuple structs
// TODO: Using `StructItem` here isn't the best option. Should have another type
- ::std::vector<AST::StructItem> refs;
+ ::std::vector<AST::TupleItem> refs;
while(GET_TOK(tok, lex) != TOK_PAREN_CLOSE)
{
AST::MetaItems item_attrs;
@@ -460,7 +460,7 @@ AST::Struct Parse_Struct(TokenStream& lex, const AST::MetaItems& meta_items)
else
lex.putback(tok);
- refs.push_back( AST::StructItem( mv$(item_attrs), is_pub, "", Parse_Type(lex) ) );
+ refs.push_back( AST::TupleItem( mv$(item_attrs), is_pub, Parse_Type(lex) ) );
if( GET_TOK(tok, lex) != TOK_COMMA )
break;
}
@@ -474,12 +474,12 @@ AST::Struct Parse_Struct(TokenStream& lex, const AST::MetaItems& meta_items)
GET_CHECK_TOK(tok, lex, TOK_SEMICOLON);
//if( refs.size() == 0 )
// WARNING( , W000, "Use 'struct Name;' instead of 'struct Name();' ... ning-nong");
- return AST::Struct(::std::move(params), ::std::move(refs));
+ return AST::Struct(mv$(params), mv$(refs));
}
else if(tok.type() == TOK_SEMICOLON)
{
// Unit-like struct
- return AST::Struct(::std::move(params), ::std::vector<AST::StructItem>());
+ return AST::Struct(mv$(params), ::std::vector<AST::TupleItem>());
}
else if(tok.type() == TOK_BRACE_OPEN)
{
diff --git a/src/resolve/absolute.cpp b/src/resolve/absolute.cpp
index 19d8d53d..0fe9fe8e 100644
--- a/src/resolve/absolute.cpp
+++ b/src/resolve/absolute.cpp
@@ -229,7 +229,7 @@ void Resolve_Absolute_Path(const Context& context, const Span& sp, bool is_type,
if(e.nodes.size() > 1 || is_type) {
// Look up type
auto p = context.lookup_type(sp, e.nodes[0].name());
- DEBUG("Found - " << p);
+ DEBUG("Found type/mod - " << p);
path = mv$(p);
}
else {
@@ -501,7 +501,7 @@ void Resolve_Absolute_Pattern(Context& context, bool allow_refutable, ::AST::Pa
void Resolve_Absolute_ImplItems(Context& item_context, ::AST::NamedList< ::AST::Item >& items)
{
- TRACE_FUNCTION_F("()");
+ TRACE_FUNCTION_F("");
for(auto& i : items)
{
TU_MATCH(AST::Item, (i.data), (e),
@@ -513,8 +513,10 @@ void Resolve_Absolute_ImplItems(Context& item_context, ::AST::NamedList< ::AST:
(Struct, BUG(Span(), "Resolve_Absolute_ImplItems - Struct");),
(Type,
DEBUG("Type - " << i.name);
+ assert( e.params().ty_params().size() == 0 );
+ assert( e.params().lft_params().size() == 0 );
//item_context.push( e.params(), GenericSlot::Level::Method );
- //Resolve_Absolute_Generic(item_context, e.params());
+ Resolve_Absolute_Generic(item_context, e.params());
Resolve_Absolute_Type( item_context, e.type() );
diff --git a/src/resolve/index.cpp b/src/resolve/index.cpp
index b5fdbf33..e905de26 100644
--- a/src/resolve/index.cpp
+++ b/src/resolve/index.cpp
@@ -107,6 +107,10 @@ void Resolve_Index_Module_Base(AST::Module& mod)
(Struct,
_add_item_type(mod, i.name, i.is_pub, b.clone());
+ // - If the struct is a tuple-like struct, it presents in the value namespace
+ if( e.struct_->m_data.is_Tuple() ) {
+ _add_item_value(mod, i.name, i.is_pub, b.clone());
+ }
),
(Static , _add_item_value(mod, i.name, i.is_pub, b.clone()); ),
(Function, _add_item_value(mod, i.name, i.is_pub, b.clone()); ),