summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md21
-rw-r--r--src/main.cpp8
-rw-r--r--src/parse/common.hpp14
-rw-r--r--src/parse/expr.cpp10
-rw-r--r--src/parse/lex.cpp17
-rw-r--r--src/parse/lex.hpp7
-rw-r--r--src/parse/parseerror.cpp5
-rw-r--r--src/parse/root.cpp9
8 files changed, 77 insertions, 14 deletions
diff --git a/README.md b/README.md
index 8a2c19e4..bcbd25a3 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,21 @@
-This project is an attempt at creating a simple rust compiler in C++.
+=== Intro ===
+This project is an attempt at creating a simple rust compiler in C++, with the ultimate goal of being a seperate reimplementation.
+
+The short-term goal is to compile pre-borrowchecked rust code into C, for passing to an existing C compiler. Thankfully, (from what I have seen), the borrow checker is not needed to compile rust code (just to ensure that it's valid)
+
+=== Current Features ===
+- Successfully parses libcore
+- Resolves all paths to absolute forms
+- Outputs the processed AST as (almost) rust code
+ - Almost because it uses special path types to handle: external crates, 'str', and anonymous modules.
+
+=== Short-Term Plans ===
+- Type resolution and checking (quite interlinked)
+- Converting operator invocations to explicit calls
+
+=== Medium-Term Goals ===
+- Flattening AST into an intermediate form with no module higherarchy or generics
+- Converting flat AST into C
+ - Bonus points for making it readable C
-Initially it will compile a superset of valid rust code into C code (avoiding all safety validations).
diff --git a/src/main.cpp b/src/main.cpp
index f7748b14..85224156 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,4 +1,9 @@
/*
+ * MRustC - Rust Compiler
+ * - By John Hodge (Mutabah/thePowersGang)
+ *
+ * main.cpp
+ * - Compiler Entrypoint
*/
#include <iostream>
#include <string>
@@ -28,6 +33,7 @@ int main(int argc, char *argv[])
{
AST_InitProvidedModule();
+ // Hacky command-line parsing
const char *infile = NULL;
::std::string outfile;
const char *crate_path = ".";
@@ -88,8 +94,6 @@ int main(int argc, char *argv[])
outfile += ".o";
}
- //Serialiser_TextTree s_tt(::std::cout);
- //Serialiser& s = s_tt;
try
{
g_cur_phase = "Parse";
diff --git a/src/parse/common.hpp b/src/parse/common.hpp
index d701f45a..0ee430af 100644
--- a/src/parse/common.hpp
+++ b/src/parse/common.hpp
@@ -1,3 +1,10 @@
+/*
+ * MRustC - Rust Compiler
+ * - By John Hodge (Mutabah/thePowersGang)
+ *
+ * parse/common.hpp
+ * - Common definitions used by the parser
+ */
#ifndef PARSE_COMMON_HPP_INCLUDED
#define PARSE_COMMON_HPP_INCLUDED
#include <iostream>
@@ -18,22 +25,21 @@
} \
} while(0)
+// --- path.cpp
enum eParsePathGenericMode
{
PATH_GENERIC_NONE,
PATH_GENERIC_EXPR,
PATH_GENERIC_TYPE
};
-
-extern AST::MetaItem Parse_MetaItem(TokenStream& lex);
extern AST::Path Parse_Path(TokenStream& lex, eParsePathGenericMode generic_mode); // Auto-determines
extern AST::Path Parse_Path(TokenStream& lex, bool is_abs, eParsePathGenericMode generic_mode);
extern AST::Path Parse_PathFrom(TokenStream& lex, AST::Path src, eParsePathGenericMode generic_mode);
extern ::std::vector<TypeRef> Parse_Path_GenericList(TokenStream& lex);
-extern TypeRef Parse_Type(TokenStream& lex);
-
+extern AST::MetaItem Parse_MetaItem(TokenStream& lex);
+extern TypeRef Parse_Type(TokenStream& lex);
extern AST::Pattern Parse_Pattern(TokenStream& lex, bool is_refutable);
extern void Parse_Use(TokenStream& lex, ::std::function<void(AST::Path, ::std::string)> fcn);
diff --git a/src/parse/expr.cpp b/src/parse/expr.cpp
index 61678eea..32fd171e 100644
--- a/src/parse/expr.cpp
+++ b/src/parse/expr.cpp
@@ -1,4 +1,14 @@
/*
+ * MRustC - Rust Compiler
+ * - By John Hodge (Mutabah/thePowersGang)
+ *
+ * parse/expr.cpp
+ * - Expression (i.e. code) parsing
+ *
+ * Start points:
+ * - Parse_ExprBlockNode : Parses a block
+ * - Parse_Stmt : Parse a single statement
+ * - Parse_Expr0 : Parse a single expression
*/
#include "parseerror.hpp"
#include "../ast/ast.hpp"
diff --git a/src/parse/lex.cpp b/src/parse/lex.cpp
index 34a2ff58..c81c3149 100644
--- a/src/parse/lex.cpp
+++ b/src/parse/lex.cpp
@@ -1,9 +1,14 @@
/*
- * "MRustC" - Primitive rust compiler in C++
- */
-/**
- * \file parse/lex.cpp
- * \brief Low-level lexer
+ * MRustC - Rust Compiler
+ * - By John Hodge (Mutabah/thePowersGang)
+ *
+ * parse/lex.cpp
+ * - Lexer (converts input file to token stream)
+ *
+ * Provides:
+ * - Lexer : The file->token lexer
+ * - TTStream : A stream of tokens from a TokenTree
+ * - TokenStream : Common interface for all token streams
*/
#include "lex.hpp"
#include "tokentree.hpp"
@@ -31,7 +36,7 @@ Lexer::Lexer(::std::string filename):
#define SINGLEQUOTE -3
#define DOUBLEQUOTE -4
-// NOTE: This array must be kept reverse sorted
+// NOTE: This array must be kept sorted, or symbols are will be skipped
#define TOKENT(str, sym) {sizeof(str)-1, str, sym}
static const struct {
unsigned char len;
diff --git a/src/parse/lex.hpp b/src/parse/lex.hpp
index aa5ed623..0dab9a24 100644
--- a/src/parse/lex.hpp
+++ b/src/parse/lex.hpp
@@ -1,3 +1,10 @@
+/*
+ * MRustC - Rust Compiler
+ * - By John Hodge (Mutabah/thePowersGang)
+ *
+ * parse/lex.hpp
+ * - Lexer header
+ */
#ifndef LEX_HPP_INCLUDED
#define LEX_HPP_INCLUDED
diff --git a/src/parse/parseerror.cpp b/src/parse/parseerror.cpp
index 3905ae33..01c8cced 100644
--- a/src/parse/parseerror.cpp
+++ b/src/parse/parseerror.cpp
@@ -1,4 +1,9 @@
/*
+ * MRustC - Rust Compiler
+ * - By John Hodge (Mutabah/thePowersGang)
+ *
+ * parse/parseerror.cpp
+ * - Exceptions thrown for different types of parsing errors
*/
#include "parseerror.hpp"
#include <iostream>
diff --git a/src/parse/root.cpp b/src/parse/root.cpp
index c7518422..3bf43e1f 100644
--- a/src/parse/root.cpp
+++ b/src/parse/root.cpp
@@ -1,4 +1,13 @@
/*
+ * MRustC - Rust Compiler
+ * - By John Hodge (Mutabah/thePowersGang)
+ *
+ * parse/root.cpp
+ * - Parsing at the module level (highest-level parsing)
+ *
+ * Entrypoint:
+ * - Parse_Crate : Handles crate attrbutes, and passes on to Parse_ModRoot
+ * - Parse_ModRoot
*/
#include "../ast/ast.hpp"
#include "parseerror.hpp"