Skip to content

Commit

Permalink
Hacking up conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
thepowersgang committed Dec 21, 2014
1 parent e1a5155 commit 8977122
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 8 deletions.
6 changes: 6 additions & 0 deletions ast/ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ class Crate
void iterate_functions( fcn_visitor_t* visitor );
};

class Flat
{
::std::vector<Function> m_functions;
public:
};

}

#endif // AST_HPP_INCLUDED
8 changes: 8 additions & 0 deletions convert/flatten.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
*/
#include "../ast/ast.hpp"

AST::Flat Convert_Flattern(const AST::Crate& crate)
{
throw ParseError::Todo("Flatten");
}
52 changes: 52 additions & 0 deletions convert/render.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
*/
#include "../ast/ast.hpp"

void Render_Type(::std::ostream& os, const TypeRef& type, const char *name)
{
/*
swicth(type.class())
{
case TYPECLASS_STRUCT:
os << "struct " << type.struct().mangled_name() << " " << name;
break;
}
*/
}

void Render_CStruct(::std::ostream& os, const AST::CStruct& str)
{
os << "struct " << str.name() << "{\n";
FOREACH(::std::vector<std::pair<std::string,TypeRef> >, f, str.fields())
{
os << "\t";
Render_Type(os, f->second(), f->first().c_str());
os << ";\n";
}
os << "}\n"
}

void Render_Crate(::std::ostream& os, const AST::Flat& crate)
{
// First off, print forward declarations of all structs + enums
FOREACH(::std::vector<AST::CStruct>, s, crate.structs())
os << "struct " << s->mangled_name() << ";\n";

FOREACH(::std::vector<AST::Function>, fcn, crate.functions())
{
Render_Type(os, fcn->rettype(), nullptr);
os << " " << fcn->name() << "(";
bool is_first = true;
FOREACH(::std::vector<std::pair<std::string,TypeRef> >, f, fcn.args())
{
if( !is_first )
os << ", ";
is_first = false;
Render_Type(os, f->second(), f->first().c_str());
}
os << ")\n{\n";
// Dump expression AST
os << "}\n";
}
}

6 changes: 3 additions & 3 deletions convert/resolve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ void ResolvePaths_Type(TypeRef& type)
throw ParseError::Todo("ResolvePaths_Type");
}

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

ResolvePaths_Type(fcn.rettype());
ResolvePaths_Type(crate, module, fcn.rettype());

FOREACH_M(AST::Function::Arglist, arg, fcn.args())
{
Expand Down
11 changes: 6 additions & 5 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
#include "parse/parseerror.hpp"
#include "ast/ast.hpp"

using namespace std;

extern AST::Crate Parse_Crate(::std::string mainfile);
extern void ResolvePaths(AST::Crate& crate);
extern AST::Flat Convert_Flatten(const AST::Crate& crate);

/// main!
int main(int argc, char *argv[])
Expand All @@ -16,14 +15,16 @@ int main(int argc, char *argv[])
{
AST::Crate crate = Parse_Crate("samples/1.rs");

// Resolve names into absolute?
// Resolve names to be absolute names (include references to the relevant struct/global/function)
ResolvePaths(crate);

// Flatten modules into "mangled" set

// Typecheck / type propagate module (type annotations of all values)

// Flatten modules into "mangled" set
AST::Flat flat_crate = Convert_Flattern(crate);

// Convert structures to C structures / tagged enums
//Convert_Render(flat_crate, stdout);
}
catch(const ParseError::Base& e)
{
Expand Down
2 changes: 2 additions & 0 deletions mrustc.cbp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
<Unit filename="ast/ast.hpp" />
<Unit filename="ast/path.hpp" />
<Unit filename="common.hpp" />
<Unit filename="convert/flatten.cpp" />
<Unit filename="convert/render.cpp" />
<Unit filename="convert/resolve.cpp" />
<Unit filename="coretypes.hpp" />
<Unit filename="macros.cpp" />
Expand Down

0 comments on commit 8977122

Please sign in to comment.