diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ast/expr.cpp | 19 | ||||
-rw-r--r-- | src/ast/expr.hpp | 34 | ||||
-rw-r--r-- | src/ast/pattern.hpp | 6 | ||||
-rw-r--r-- | src/dump_as_rust.cpp | 21 | ||||
-rw-r--r-- | src/include/serialise.hpp | 2 | ||||
-rw-r--r-- | src/include/serialiser_texttree.hpp | 2 | ||||
-rw-r--r-- | src/parse/expr.cpp | 22 | ||||
-rw-r--r-- | src/serialise.cpp | 13 |
8 files changed, 106 insertions, 13 deletions
diff --git a/src/ast/expr.cpp b/src/ast/expr.cpp index e29b3068..3e20655d 100644 --- a/src/ast/expr.cpp +++ b/src/ast/expr.cpp @@ -185,6 +185,17 @@ NODE(ExprNode_Integer, { },{ os << m_value; }) +NODE(ExprNode_Float, { + s % m_datatype; + s.item(m_value); +},{ + os << m_value; +}) +NODE(ExprNode_Bool, { + s.item(m_value); +},{ + os << m_value; +}) NODE(ExprNode_StructLiteral, { s.item(m_path); @@ -392,10 +403,10 @@ NV(ExprNode_If, UNINDENT(); }) -NV(ExprNode_Integer, -{ - // LEAF -}) +NV(ExprNode_Integer, {}) +NV(ExprNode_Float, {}) +NV(ExprNode_Bool, {}) + NV(ExprNode_StructLiteral, { visit(node.m_base_value); diff --git a/src/ast/expr.hpp b/src/ast/expr.hpp index b9ab5d05..28526377 100644 --- a/src/ast/expr.hpp +++ b/src/ast/expr.hpp @@ -218,6 +218,36 @@ struct ExprNode_Integer: NODE_METHODS(); }; +// Literal float +struct ExprNode_Float: + public ExprNode +{ + enum eCoreType m_datatype; + double m_value; + + ExprNode_Float() {} + ExprNode_Float(double value, enum eCoreType datatype): + m_datatype(datatype), + m_value(value) + { + } + + NODE_METHODS(); +}; +// Literal boolean +struct ExprNode_Bool: + public ExprNode +{ + bool m_value; + + ExprNode_Bool() {} + ExprNode_Bool(bool value): + m_value(value) + { + } + + NODE_METHODS(); +}; // Literal structure struct ExprNode_StructLiteral: public ExprNode @@ -397,6 +427,8 @@ public: NT(ExprNode_If); NT(ExprNode_Integer); + NT(ExprNode_Float); + NT(ExprNode_Bool); NT(ExprNode_StructLiteral); NT(ExprNode_Tuple); NT(ExprNode_NamedValue); @@ -431,6 +463,8 @@ public: NT(ExprNode_If); NT(ExprNode_Integer); + NT(ExprNode_Float); + NT(ExprNode_Bool); NT(ExprNode_StructLiteral); NT(ExprNode_Tuple); NT(ExprNode_NamedValue); diff --git a/src/ast/pattern.hpp b/src/ast/pattern.hpp index deda0b97..78b224d0 100644 --- a/src/ast/pattern.hpp +++ b/src/ast/pattern.hpp @@ -88,8 +88,10 @@ public: struct TagReference {}; Pattern(TagReference, Pattern sub_pattern): m_class(REF), - m_sub_patterns( { ::std::move(sub_pattern) } ) - {} + m_sub_patterns() + { + m_sub_patterns.push_back( ::std::move(sub_pattern) ); + } struct TagTuple {}; Pattern(TagTuple, ::std::vector<Pattern> sub_patterns): diff --git a/src/dump_as_rust.cpp b/src/dump_as_rust.cpp index ae6a6337..e5d225bd 100644 --- a/src/dump_as_rust.cpp +++ b/src/dump_as_rust.cpp @@ -202,6 +202,7 @@ public: case CORETYPE_U32: case CORETYPE_U64: case CORETYPE_UINT: + case CORETYPE_ANY: m_os << "0x" << ::std::hex << n.m_value << ::std::dec; break; case CORETYPE_I8: @@ -213,6 +214,26 @@ public: break; } } + virtual void visit(AST::ExprNode_Float& n) override { + m_expr_root = false; + switch(n.m_datatype) + { + case CORETYPE_ANY: + case CORETYPE_F32: + case CORETYPE_F64: + m_os << n.m_value; + break; + default: + break; + } + } + virtual void visit(AST::ExprNode_Bool& n) override { + m_expr_root = false; + if( n.m_value ) + m_os << "true"; + else + m_os << "false"; + } virtual void visit(AST::ExprNode_StructLiteral& n) override { m_expr_root = false; m_os << n.m_path << " {\n"; diff --git a/src/include/serialise.hpp b/src/include/serialise.hpp index 1c2b882e..e70ec113 100644 --- a/src/include/serialise.hpp +++ b/src/include/serialise.hpp @@ -44,6 +44,7 @@ public: virtual Serialiser& operator<<(bool val) = 0; virtual Serialiser& operator<<(uint64_t val) = 0; + virtual Serialiser& operator<<(double val) = 0; virtual Serialiser& operator<<(const char* s) = 0; Serialiser& operator<<(const ::std::string& s) { return *this << s.c_str(); @@ -105,6 +106,7 @@ protected: public: virtual void item(bool& b) = 0; virtual void item(uint64_t& v) = 0; + virtual void item(double& v) = 0; virtual void item(::std::string& s) = 0; virtual void start_object(const char *tag) = 0; diff --git a/src/include/serialiser_texttree.hpp b/src/include/serialiser_texttree.hpp index 4e8a9cf8..890be31a 100644 --- a/src/include/serialiser_texttree.hpp +++ b/src/include/serialiser_texttree.hpp @@ -19,6 +19,7 @@ public: virtual Serialiser& operator<<(bool val) override; virtual Serialiser& operator<<(uint64_t val) override; + virtual Serialiser& operator<<(double val) override; virtual Serialiser& operator<<(const char* s) override; protected: @@ -53,6 +54,7 @@ protected: public: virtual void item(bool& b) override; virtual void item(uint64_t& v) override; + virtual void item(double& v) override; virtual void item(::std::string& s) override; virtual void start_object(const char *tag) override; diff --git a/src/parse/expr.cpp b/src/parse/expr.cpp index 3d812fb8..2ae94794 100644 --- a/src/parse/expr.cpp +++ b/src/parse/expr.cpp @@ -47,7 +47,6 @@ AST::Pattern Parse_Pattern(TokenStream& lex) {
TRACE_FUNCTION;
- AST::Path path;
Token tok;
tok = lex.getToken();
@@ -71,24 +70,25 @@ AST::Pattern Parse_Pattern(TokenStream& lex) }
::std::string bind_name;
+ // If a 'ref' or 'mut' annotation was seen, the next name must be a binding name
if( expect_bind )
{
CHECK_TOK(tok, TOK_IDENT);
bind_name = tok.str();
+ // If there's no '@' after it, it's a name binding only (_ pattern)
if( GET_TOK(tok, lex) != TOK_AT )
{
- // No '@', it's a name binding
lex.putback(tok);
return AST::Pattern(AST::Pattern::TagBind(), bind_name);
}
tok = lex.getToken();
}
-
- if( !expect_bind && tok.type() == TOK_IDENT )
+ // Otherwise, handle MaybeBind
+ else if( tok.type() == TOK_IDENT )
{
lex.putback(tok);
- path = Parse_Path(lex, false, PATH_GENERIC_EXPR);
+ AST::Path path = Parse_Path(lex, false, PATH_GENERIC_EXPR);
// - If the path is trivial
if( path.size() == 1 && path[0].args().size() == 0 )
{
@@ -98,6 +98,7 @@ AST::Pattern Parse_Pattern(TokenStream& lex) case TOK_AT:
bind_name = path[0].name();
GET_TOK(tok, lex);
+ // - Fall though
break;
// - Else, if the next token is a '(' or '{', treat as a struct/enum
case TOK_BRACE_OPEN:
@@ -120,10 +121,12 @@ AST::Pattern Parse_Pattern(TokenStream& lex) lex.putback(tok);
AST::Pattern pat = Parse_PatternReal(lex);
pat.set_bind(bind_name, is_ref, is_mut);
- return pat;
+ return ::std::move(pat);
}
AST::Pattern Parse_PatternReal(TokenStream& lex)
{
+ TRACE_FUNCTION;
+
Token tok;
AST::Path path;
@@ -132,6 +135,7 @@ AST::Pattern Parse_PatternReal(TokenStream& lex) case TOK_UNDERSCORE:
return AST::Pattern( );
case TOK_AMP:
+ DEBUG("Ref");
return AST::Pattern( AST::Pattern::TagReference(), Parse_PatternReal(lex) );
case TOK_IDENT:
lex.putback(tok);
@@ -615,7 +619,11 @@ ExprNodeP Parse_ExprVal(TokenStream& lex) case TOK_INTEGER:
return NEWNODE( AST::ExprNode_Integer, tok.intval(), tok.datatype() );
case TOK_FLOAT:
- throw ParseError::Todo("Float");
+ return NEWNODE( AST::ExprNode_Float, tok.floatval(), tok.datatype() );
+ case TOK_RWORD_TRUE:
+ return NEWNODE( AST::ExprNode_Bool, true );
+ case TOK_RWORD_FALSE:
+ return NEWNODE( AST::ExprNode_Bool, false );
case TOK_RWORD_SELF:
return NEWNODE( AST::ExprNode_NamedValue, AST::Path(AST::Path::TagLocal(), "self") );
case TOK_PAREN_OPEN:
diff --git a/src/serialise.cpp b/src/serialise.cpp index 88b323f9..e7d94948 100644 --- a/src/serialise.cpp +++ b/src/serialise.cpp @@ -79,6 +79,12 @@ Serialiser& Serialiser_TextTree::operator<<(uint64_t val) m_os << val << "\n"; return *this; } +Serialiser& Serialiser_TextTree::operator<<(double val) +{ + print_indent(); + m_os << val << "\n"; + return *this; +} Serialiser& Serialiser_TextTree::operator<<(const char* s) { @@ -188,6 +194,13 @@ void Deserialiser_TextTree::item(uint64_t& v) if( !m_is.good() ) throw ::std::runtime_error("TODO: Less shit exception, item(uint64_t)"); } +void Deserialiser_TextTree::item(double& v) +{ + eat_ws(); + m_is >> v; + if( !m_is.good() ) + throw ::std::runtime_error("TODO: Less shit exception, item(double)"); +} void Deserialiser_TextTree::item(::std::string& s) { eat_ws(); |