diff options
-rw-r--r-- | Makefile | 29 | ||||
-rw-r--r-- | src/ast/ast.hpp | 17 | ||||
-rw-r--r-- | src/convert/flatten.cpp | 1 | ||||
-rw-r--r-- | src/convert/render.cpp | 16 | ||||
-rw-r--r-- | src/convert/resolve.cpp | 29 | ||||
-rw-r--r-- | src/main.cpp | 2 |
6 files changed, 78 insertions, 16 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..bd10d95c --- /dev/null +++ b/Makefile @@ -0,0 +1,29 @@ + +EXESUF ?= +CXX ?= g++ + +LINKFLAGS := +LIBS := +CXXFLAGS := -Wall -std=c++11 +CPPFLAGS := + + +OBJDIR = .obj/ + +BIN := bin/mrustc$(EXESUF) + +OBJ := main.o macros.o types.o ast/ast.o +OBJ += parse/parseerror.o parse/lex.o parse/preproc.o parse/root.o parse/expr.o +OBJ += convert/flatten.o convert/resolve.o convert/render.o +OBJ := $(addprefix $(OBJDIR),$(OBJ)) + +$(BIN): $(OBJ) + @mkdir -p $(dir $@) + $(CXX) -o $@ $(LINKFLAGS) $(OBJ) $(LIBS) + +$(OBJDIR)%.o: src/%.cpp + @mkdir -p $(dir $@) + $(CXX) -o $@ -c $< $(CXXFLAGS) $(CPPFLAGS) -MMD -MP -MF $@.dep + +-include $(OBJ:%=%.dep) + diff --git a/src/ast/ast.hpp b/src/ast/ast.hpp index 9e4728b3..ac153458 100644 --- a/src/ast/ast.hpp +++ b/src/ast/ast.hpp @@ -143,9 +143,13 @@ public: Expr& code() { return m_code; }
const Expr code() const { return m_code; }
+ const TypeRef& rettype() const { return m_rettype; }
TypeRef& rettype() { return m_rettype; }
+ const Arglist& args() const { return m_args; }
Arglist& args() { return m_args; }
+
+ const char* name() const { return "TODO"; }
};
class Impl
@@ -182,10 +186,23 @@ public: void iterate_functions( fcn_visitor_t* visitor );
};
+class CStruct
+{
+ ::std::vector<StructItem> m_fields;
+public:
+ const char* name() const { return "TODO"; }
+ const char* mangled_name() const { return "TODO"; }
+ const ::std::vector<StructItem>& fields() const { return m_fields; }
+};
+
class Flat
{
+ ::std::vector<CStruct> m_structs;
::std::vector<Function> m_functions;
public:
+
+ const ::std::vector<Function>& functions() const;
+ const ::std::vector<CStruct>& structs() const;
};
}
diff --git a/src/convert/flatten.cpp b/src/convert/flatten.cpp index a1c89998..a040d154 100644 --- a/src/convert/flatten.cpp +++ b/src/convert/flatten.cpp @@ -1,6 +1,7 @@ /*
*/
#include "../ast/ast.hpp"
+#include "../parse/parseerror.hpp"
AST::Flat Convert_Flattern(const AST::Crate& crate)
{
diff --git a/src/convert/render.cpp b/src/convert/render.cpp index 6de8dc57..7f65945a 100644 --- a/src/convert/render.cpp +++ b/src/convert/render.cpp @@ -1,11 +1,15 @@ /*
*/
+#include "../common.hpp"
#include "../ast/ast.hpp"
+#include <iostream>
+
+typedef ::std::vector< ::std::pair< ::std::string, TypeRef> > item_vec_t;
void Render_Type(::std::ostream& os, const TypeRef& type, const char *name)
{
/*
- swicth(type.class())
+ switch(type.class())
{
case TYPECLASS_STRUCT:
os << "struct " << type.struct().mangled_name() << " " << name;
@@ -17,13 +21,13 @@ void Render_Type(::std::ostream& os, const TypeRef& type, const char *name) 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())
+ FOREACH(item_vec_t, f, str.fields())
{
os << "\t";
- Render_Type(os, f->second(), f->first().c_str());
+ Render_Type(os, f->second, f->first.c_str());
os << ";\n";
}
- os << "}\n"
+ os << "}\n";
}
void Render_Crate(::std::ostream& os, const AST::Flat& crate)
@@ -37,12 +41,12 @@ void Render_Crate(::std::ostream& os, const AST::Flat& crate) Render_Type(os, fcn->rettype(), nullptr);
os << " " << fcn->name() << "(";
bool is_first = true;
- FOREACH(::std::vector<std::pair<std::string,TypeRef> >, f, fcn.args())
+ FOREACH(item_vec_t, f, fcn->args())
{
if( !is_first )
os << ", ";
is_first = false;
- Render_Type(os, f->second(), f->first().c_str());
+ Render_Type(os, f->second, f->first.c_str());
}
os << ")\n{\n";
// Dump expression AST
diff --git a/src/convert/resolve.cpp b/src/convert/resolve.cpp index 0d79f1cd..d4d9c38b 100644 --- a/src/convert/resolve.cpp +++ b/src/convert/resolve.cpp @@ -1,8 +1,19 @@ -
+/*
+ */
#include "../common.hpp"
#include "../ast/ast.hpp"
#include "../parse/parseerror.hpp"
+class CPathResolver
+{
+public:
+ CPathResolver(const AST::Crate& crate, AST::Function& fcn);
+
+ void resolve_type(TypeRef& type);
+
+ void handle_function(AST::Function& fcn);
+};
+
// Path resolution checking
void ResolvePaths(AST::Crate& crate);
void ResolvePaths_HandleFunction(const AST::Crate& crate, AST::Function& fcn);
@@ -10,10 +21,10 @@ void ResolvePaths_HandleFunction(const AST::Crate& crate, AST::Function& fcn); class CResolvePaths_NodeVisitor:
public AST::NodeVisitor
{
- const AST::Crate& m_crate;
+ const CPathResolver& m_res;
public:
- CResolvePaths_NodeVisitor(const AST::Crate& crate):
- m_crate(crate)
+ CResolvePaths_NodeVisitor(const CPathResolver& res):
+ m_res(res)
{
}
@@ -23,21 +34,21 @@ public: }
};
-void ResolvePaths_Type(TypeRef& type)
+void CPathResolver::resolve_type(TypeRef& type)
{
// TODO: Convert type into absolute
throw ParseError::Todo("ResolvePaths_Type");
}
-void ResolvePaths_HandleFunction(const AST::Crate& crate, const AST::Module& module, AST::Function& fcn)
+void CPathResolver::handle_function(AST::Function& fcn)
{
- fcn.code().visit_nodes( CResolvePaths_NodeVisitor(crate, module) );
+ fcn.code().visit_nodes( CResolvePaths_NodeVisitor(*this) );
- ResolvePaths_Type(crate, module, fcn.rettype());
+ resolve_type(fcn.rettype());
FOREACH_M(AST::Function::Arglist, arg, fcn.args())
{
- ResolvePaths_Type(arg->second);
+ resolve_type(arg->second);
}
}
diff --git a/src/main.cpp b/src/main.cpp index f3ea8136..4f92e593 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,7 +21,7 @@ int main(int argc, char *argv[]) // Typecheck / type propagate module (type annotations of all values)
// Flatten modules into "mangled" set
- AST::Flat flat_crate = Convert_Flattern(crate);
+ AST::Flat flat_crate = Convert_Flatten(crate);
// Convert structures to C structures / tagged enums
//Convert_Render(flat_crate, stdout);
|