diff options
-rw-r--r-- | samples/std.rs | 11 | ||||
-rw-r--r-- | src/ast/ast.hpp | 2 | ||||
-rw-r--r-- | src/ast/path.cpp | 4 | ||||
-rw-r--r-- | src/ast/path.hpp | 7 | ||||
-rw-r--r-- | src/convert/resolve.cpp | 5 | ||||
-rw-r--r-- | src/convert/typecheck_expr.cpp | 51 |
6 files changed, 77 insertions, 3 deletions
diff --git a/samples/std.rs b/samples/std.rs index 125021b4..4f152fc6 100644 --- a/samples/std.rs +++ b/samples/std.rs @@ -43,6 +43,15 @@ pub mod iter } } +pub mod char +{ + pub fn from_u32(v: u32) -> char + { + v // TODO: This should generate a typecheck failure, but that part is incomplete + // Will eventually need a version of mem::transmute() + } +} + pub mod prelude { pub mod v1 @@ -55,3 +64,5 @@ pub mod prelude } } +// vim: ft=rust + diff --git a/src/ast/ast.hpp b/src/ast/ast.hpp index b684379f..b4ccf582 100644 --- a/src/ast/ast.hpp +++ b/src/ast/ast.hpp @@ -206,6 +206,8 @@ public: m_value( move(value) )
{}
+ const TypeRef& type() const { return m_type; }
+
SERIALISABLE_PROTOTYPES();
};
diff --git a/src/ast/path.cpp b/src/ast/path.cpp index fd543120..6d5e50b2 100644 --- a/src/ast/path.cpp +++ b/src/ast/path.cpp @@ -143,7 +143,9 @@ void Path::resolve(const Crate& root_crate) { DEBUG("Found function"); if( is_last ) { - throw ParseError::Todo("Path::resolve() bind to function"); + m_binding_type = FUNCTION; + m_binding.func_ = &it->data; + return ; } else { throw ParseError::Generic("Import of function, too many extra nodes"); diff --git a/src/ast/path.hpp b/src/ast/path.hpp index 01c8ed03..02e028d7 100644 --- a/src/ast/path.hpp +++ b/src/ast/path.hpp @@ -160,9 +160,14 @@ public: _(Module, module, MODULE) _(Trait, trait, TRAIT) _(Struct, struct, STRUCT) - _(Enum, enum, ENUM) + //_(Enum, enum, ENUM) _(Function, func, FUNCTION) + _(Static, static, STATIC) #undef _ + const Enum& bound_enum() const { + assert(m_binding_type == ENUM || m_binding_type == ENUM_VAR); + return *m_binding.enum_; + } ::std::vector<PathNode>& nodes() { return m_nodes; } const ::std::vector<PathNode>& nodes() const { return m_nodes; } diff --git a/src/convert/resolve.cpp b/src/convert/resolve.cpp index 3a42beff..0450a348 100644 --- a/src/convert/resolve.cpp +++ b/src/convert/resolve.cpp @@ -91,6 +91,11 @@ public: DEBUG("ExprNode_NamedValue");
m_res.handle_path(node.m_path, CASTIterator::MODE_EXPR);
}
+ void visit(AST::ExprNode_CallPath& node) {
+ DEBUG("ExprNode_CallPath");
+ AST::NodeVisitor::visit(node);
+ m_res.handle_path(node.m_path, CASTIterator::MODE_EXPR);
+ }
void visit(AST::ExprNode_Match& node)
{
diff --git a/src/convert/typecheck_expr.cpp b/src/convert/typecheck_expr.cpp index 43043fdb..3886c2ea 100644 --- a/src/convert/typecheck_expr.cpp +++ b/src/convert/typecheck_expr.cpp @@ -28,11 +28,15 @@ public: m_tc(tc) {} + virtual void visit(AST::ExprNode_NamedValue& node) override; + virtual void visit(AST::ExprNode_LetBinding& node) override; + virtual void visit(AST::ExprNode_Assign& node) override; virtual void visit(AST::ExprNode_Match& node) override; virtual void visit(AST::ExprNode_CallMethod& node) override; + virtual void visit(AST::ExprNode_CallPath& node) override; }; @@ -61,10 +65,27 @@ void CTypeChecker::lookup_method(const TypeRef& type, const char* name) //} } +void CTC_NodeVisitor::visit(AST::ExprNode_NamedValue& node) +{ + const AST::Path& p = node.m_path; + if( p.is_absolute() ) + { + // grab bound item + switch(p.binding_type()) + { + case AST::Path::STATIC: + node.get_res_type() = p.bound_static().type(); + break; + } + } +} + void CTC_NodeVisitor::visit(AST::ExprNode_LetBinding& node) { DEBUG("ExprNode_LetBinding"); + node.get_res_type() = TypeRef(TypeRef::TagUnit()); + // Evaluate value AST::NodeVisitor::visit(node.m_value); @@ -100,6 +121,13 @@ void CTC_NodeVisitor::visit(AST::ExprNode_LetBinding& node) m_tc.handle_pattern(node.m_pat, node.m_type); } +void CTC_NodeVisitor::visit(AST::ExprNode_Assign& node) +{ + node.get_res_type() = TypeRef(TypeRef::TagUnit()); + AST::NodeVisitor::visit(node.m_slot); + AST::NodeVisitor::visit(node.m_value); +} + void CTC_NodeVisitor::visit(AST::ExprNode_Match& node) { DEBUG("ExprNode_Match"); @@ -116,7 +144,7 @@ void CTC_NodeVisitor::visit(AST::ExprNode_Match& node) void CTC_NodeVisitor::visit(AST::ExprNode_CallMethod& node) { - DEBUG("ExprNode_CallMethod"); + DEBUG("ExprNode_CallMethod " << node.m_method); AST::NodeVisitor::visit(node.m_val); @@ -127,6 +155,7 @@ void CTC_NodeVisitor::visit(AST::ExprNode_CallMethod& node) // Locate method const TypeRef& type = node.m_val->get_res_type(); + DEBUG("- type = " << type); if( type.is_wildcard() ) { // No idea (yet) @@ -138,6 +167,26 @@ void CTC_NodeVisitor::visit(AST::ExprNode_CallMethod& node) //const Function& fcn = type.lookup_method(node.m_method.name()); } } +void CTC_NodeVisitor::visit(AST::ExprNode_CallPath& node) +{ + DEBUG("ExprNode_CallPath - " << node.m_path); + for( auto& arg : node.m_args ) + { + AST::NodeVisitor::visit(arg); + } + + if(node.m_path.binding_type() == AST::Path::FUNCTION) { + const AST::Function& fcn = node.m_path.bound_func(); + } + else if(node.m_path.binding_type() == AST::Path::ENUM_VAR) { + const AST::Enum& emn = node.m_path.bound_enum(); + // We know the enum, but it might have type params, need to handle that case + } + else + { + throw ::std::runtime_error("CallPath on non-function"); + } +} void Typecheck_Expr(AST::Crate& crate) { |