summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hodge (bugs) <tpg@mutabah.net>2014-12-21 18:08:24 +0800
committerJohn Hodge (bugs) <tpg@mutabah.net>2014-12-21 18:08:24 +0800
commit89771222961d699f5ca6f586033b5fb915ced431 (patch)
treeea9c38b65e10f495a0fbb82475221fa8875cba73
parente1a51554c956ccde6a59952a8b9a557df904cf71 (diff)
downloadmrust-89771222961d699f5ca6f586033b5fb915ced431.tar.gz
Hacking up conversion
-rw-r--r--ast/ast.hpp6
-rw-r--r--convert/flatten.cpp8
-rw-r--r--convert/render.cpp52
-rw-r--r--convert/resolve.cpp6
-rw-r--r--main.cpp11
-rw-r--r--mrustc.cbp2
6 files changed, 77 insertions, 8 deletions
diff --git a/ast/ast.hpp b/ast/ast.hpp
index fdb1114d..9e4728b3 100644
--- a/ast/ast.hpp
+++ b/ast/ast.hpp
@@ -182,6 +182,12 @@ public:
void iterate_functions( fcn_visitor_t* visitor );
};
+class Flat
+{
+ ::std::vector<Function> m_functions;
+public:
+};
+
}
#endif // AST_HPP_INCLUDED
diff --git a/convert/flatten.cpp b/convert/flatten.cpp
new file mode 100644
index 00000000..a1c89998
--- /dev/null
+++ b/convert/flatten.cpp
@@ -0,0 +1,8 @@
+/*
+ */
+#include "../ast/ast.hpp"
+
+AST::Flat Convert_Flattern(const AST::Crate& crate)
+{
+ throw ParseError::Todo("Flatten");
+}
diff --git a/convert/render.cpp b/convert/render.cpp
new file mode 100644
index 00000000..6de8dc57
--- /dev/null
+++ b/convert/render.cpp
@@ -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";
+ }
+}
+
diff --git a/convert/resolve.cpp b/convert/resolve.cpp
index 29ad8dac..0d79f1cd 100644
--- a/convert/resolve.cpp
+++ b/convert/resolve.cpp
@@ -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())
{
diff --git a/main.cpp b/main.cpp
index 50b77f5b..f3ea8136 100644
--- a/main.cpp
+++ b/main.cpp
@@ -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[])
@@ -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)
{
diff --git a/mrustc.cbp b/mrustc.cbp
index f7d200eb..7fd0f363 100644
--- a/mrustc.cbp
+++ b/mrustc.cbp
@@ -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" />