Skip to content

Commit

Permalink
Compiles again
Browse files Browse the repository at this point in the history
  • Loading branch information
thepowersgang committed Dec 14, 2014
1 parent 5d29fda commit e1a5155
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 46 deletions.
5 changes: 4 additions & 1 deletion ast/ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,14 @@ void Impl::add_function(bool is_public, Function fcn)
{
}

void Crate::iterate_functions(Crate::fcn_visitor_t* visitor)
{
}

void Module::add_constant(bool is_public, ::std::string name, TypeRef type, Expr val)
{
::std::cout << "add_constant()" << ::std::endl;
}

void Module::add_global(bool is_public, bool is_mut, ::std::string name, TypeRef type, Expr val)
{
::std::cout << "add_global()" << ::std::endl;
Expand Down
52 changes: 12 additions & 40 deletions ast/ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "../coretypes.hpp"
#include <memory>

class TypeRef;
#include "../types.hpp"

namespace AST {

Expand All @@ -30,40 +30,6 @@ class MetaItem

class ExprNode;

class TypeParam
{
public:
TypeParam(bool is_lifetime, ::std::string name);
void addLifetimeBound(::std::string name);
void addTypeBound(TypeRef type);
};

typedef ::std::vector<TypeParam> TypeParams;
typedef ::std::pair< ::std::string, TypeRef> StructItem;

class PathNode
{
::std::string m_name;
::std::vector<TypeRef> m_params;
public:
PathNode(::std::string name, ::std::vector<TypeRef> args);
const ::std::string& name() const;
const ::std::vector<TypeRef>& args() const;
};

class Path
{
public:
Path();
struct TagAbsolute {};
Path(TagAbsolute);

void append(PathNode node) {}
size_t length() const {return 0;}

PathNode& operator[](size_t idx) { throw ::std::out_of_range("Path []"); }
};

class Pattern
{
public:
Expand Down Expand Up @@ -156,24 +122,30 @@ class Expr

class Function
{
Expr m_code;
::std::auto_ptr<TypeRef> m_rettype;
public:

enum Class
{
CLASS_UNBOUND,
CLASS_REFMETHOD,
CLASS_MUTMETHOD,
CLASS_VALMETHOD,
};
typedef ::std::vector<StructItem> Arglist;

Function(::std::string name, TypeParams params, Class fcn_class, TypeRef ret_type, ::std::vector<StructItem> args, Expr code);
private:
Expr m_code;
TypeRef m_rettype;
Arglist m_args;
public:

Function(::std::string name, TypeParams params, Class fcn_class, TypeRef ret_type, Arglist args, Expr code);

Expr& code() { return m_code; }
const Expr code() const { return m_code; }

TypeRef& rettype() { return *m_rettype; }
TypeRef& rettype() { return m_rettype; }

Arglist& args() { return m_args; }
};

class Impl
Expand Down
49 changes: 49 additions & 0 deletions ast/path.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
*/
#ifndef AST_PATH_HPP_INCLUDED
#define AST_PATH_HPP_INCLUDED

#include <string>
#include <stdexcept>

class TypeRef;

namespace AST {

class TypeParam
{
public:
TypeParam(bool is_lifetime, ::std::string name);
void addLifetimeBound(::std::string name);
void addTypeBound(TypeRef type);
};

typedef ::std::vector<TypeParam> TypeParams;
typedef ::std::pair< ::std::string, TypeRef> StructItem;

class PathNode
{
::std::string m_name;
::std::vector<TypeRef> m_params;
public:
PathNode(::std::string name, ::std::vector<TypeRef> args);
const ::std::string& name() const;
const ::std::vector<TypeRef>& args() const;
};

class Path
{
public:
Path();
struct TagAbsolute {};
Path(TagAbsolute);

void append(PathNode node) {}
size_t length() const {return 0;}

PathNode& operator[](size_t idx) { throw ::std::out_of_range("Path []"); }
};

} // namespace AST

#endif
9 changes: 9 additions & 0 deletions common.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
*/
#ifndef COMMON_HPP_INCLUDED
#define COMMON_HPP_INCLUDED

#define FOREACH(basetype, it, src) for(basetype::const_iterator it = src.begin(); it != src.end(); ++ it)
#define FOREACH_M(basetype, it, src) for(basetype::iterator it = src.begin(); it != src.end(); ++ it)

#endif
13 changes: 11 additions & 2 deletions convert/resolve.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

#include "../common.hpp"
#include "../ast/ast.hpp"
#include "../parse/parseerror.hpp"

// Path resolution checking
void ResolvePaths(AST::Crate& crate);
Expand All @@ -17,18 +19,25 @@ class CResolvePaths_NodeVisitor:

void visit(AST::ExprNode::TagNamedValue, AST::ExprNode& node) {
// TODO: Convert into a real absolute path
throw ParseError::Todo("CResolvePaths_NodeVisitor::visit(TagNamedValue)");
}
};

void ResolvePaths_Type(TypeRef& type)
{
// TODO: Convert type into absolute
throw ParseError::Todo("ResolvePaths_Type");
}

void ResolvePaths_HandleFunction(const AST::Crate& crate, AST::Function& fcn)
{
fcn.code().visit_nodes( CResolvePaths_NodeVisitor(crate) );

ResolvePaths_Type(fcn.rettype());

FOREACH(arg, fcn.args())
FOREACH_M(AST::Function::Arglist, arg, fcn.args())
{
ResolvePaths_Type(arg.type());
ResolvePaths_Type(arg->second);
}
}

Expand Down
3 changes: 1 addition & 2 deletions macros.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/*
*/
#include "common.hpp"
#include "macros.hpp"
#include "parse/parseerror.hpp"
#include "parse/tokentree.hpp"
#include "parse/common.hpp"

#define FOREACH(basetype, it, src) for(basetype::const_iterator it = src.begin(); it != src.end(); ++ it)

typedef ::std::map< ::std::string, MacroRules> t_macro_regs;

t_macro_regs g_macro_registrations;
Expand Down
2 changes: 2 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <iostream>
#include <string>
#include "parse/lex.hpp"
#include "parse/parseerror.hpp"
#include "ast/ast.hpp"

using namespace std;

Expand Down
4 changes: 4 additions & 0 deletions mrustc.cbp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
</Compiler>
<Unit filename="ast/ast.cpp" />
<Unit filename="ast/ast.hpp" />
<Unit filename="ast/path.hpp" />
<Unit filename="common.hpp" />
<Unit filename="convert/resolve.cpp" />
<Unit filename="coretypes.hpp" />
<Unit filename="macros.cpp" />
<Unit filename="main.cpp" />
Expand All @@ -49,6 +52,7 @@
<Unit filename="parse/preproc.hpp" />
<Unit filename="parse/root.cpp" />
<Unit filename="samples/1.rs" />
<Unit filename="types.cpp" />
<Unit filename="types.hpp" />
<Extensions>
<code_completion />
Expand Down
2 changes: 1 addition & 1 deletion parse/preproc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Token Preproc::getTokenInt()
while(true)
{
Token tok = m_lex.getToken();
::std::cout << "getTokenInt: tok = " << tok << ::std::endl;
//::std::cout << "getTokenInt: tok = " << tok << ::std::endl;
switch(tok.type())
{
case TOK_WHITESPACE:
Expand Down
8 changes: 8 additions & 0 deletions types.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
*/
#include "types.hpp"
#include "ast/ast.hpp"

TypeRef::TypeRef(TypeRef::TagSizedArray, TypeRef inner, AST::Expr size_expr)
{
}
1 change: 1 addition & 0 deletions types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <vector>
#include "coretypes.hpp"
#include "ast/path.hpp"

namespace AST {
class Expr;
Expand Down

0 comments on commit e1a5155

Please sign in to comment.