diff --git a/source/lang/builtin_functions.cpp b/source/lang/builtin_functions.cpp index 824fc2c50..f13953aa8 100644 --- a/source/lang/builtin_functions.cpp +++ b/source/lang/builtin_functions.cpp @@ -121,11 +121,11 @@ namespace hex::lang { case Token::ValueType::Signed32Bit: message += std::to_string(std::get(integerLiteral->getValue())); break; case Token::ValueType::Unsigned64Bit: message += std::to_string(std::get(integerLiteral->getValue())); break; case Token::ValueType::Signed64Bit: message += std::to_string(std::get(integerLiteral->getValue())); break; - //case Token::ValueType::Unsigned128Bit: message += std::to_string(std::get(integerLiteral->getValue())); break; - //case Token::ValueType::Signed128Bit: message += std::to_string(std::get(integerLiteral->getValue())); break; + case Token::ValueType::Unsigned128Bit: message += "A lot"; break; // TODO: Implement u128 to_string + case Token::ValueType::Signed128Bit: message += "A lot"; break; // TODO: Implement s128 to_string case Token::ValueType::Float: message += std::to_string(std::get(integerLiteral->getValue())); break; case Token::ValueType::Double: message += std::to_string(std::get(integerLiteral->getValue())); break; - case Token::ValueType::Boolean: message += std::get(integerLiteral->getValue()) ? "true" : "false"; break; + case Token::ValueType::Boolean: message += std::get(integerLiteral->getValue()) ? "true" : "false"; break; case Token::ValueType::CustomType: message += "< Custom Type >"; break; } } diff --git a/source/lang/evaluator.cpp b/source/lang/evaluator.cpp index e32915c7f..1d5e56e38 100644 --- a/source/lang/evaluator.cpp +++ b/source/lang/evaluator.cpp @@ -211,6 +211,11 @@ namespace hex::lang { #define CHECK_TYPE(type) if (left->getType() == (type) || right->getType() == (type)) return (type) #define DEFAULT_TYPE(type) return (type) + if (left->getType() == Token::ValueType::Any && right->getType() != Token::ValueType::Any) + return right->getType(); + if (left->getType() != Token::ValueType::Any && right->getType() == Token::ValueType::Any) + return left->getType(); + CHECK_TYPE(Token::ValueType::Double); CHECK_TYPE(Token::ValueType::Float); CHECK_TYPE(Token::ValueType::Unsigned128Bit); @@ -224,6 +229,7 @@ namespace hex::lang { CHECK_TYPE(Token::ValueType::Unsigned8Bit); CHECK_TYPE(Token::ValueType::Signed8Bit); CHECK_TYPE(Token::ValueType::Character); + CHECK_TYPE(Token::ValueType::Boolean); DEFAULT_TYPE(Token::ValueType::Signed32Bit); #undef CHECK_TYPE diff --git a/source/lang/lexer.cpp b/source/lang/lexer.cpp index f22ca8ba4..53d7668d4 100644 --- a/source/lang/lexer.cpp +++ b/source/lang/lexer.cpp @@ -403,9 +403,9 @@ namespace hex::lang { else if (identifier == "else") tokens.emplace_back(TOKEN(Keyword, Else)); else if (identifier == "false") - tokens.emplace_back(VALUE_TOKEN(Integer, Token::IntegerLiteral(Token::ValueType::Unsigned8Bit, u8(0)))); + tokens.emplace_back(VALUE_TOKEN(Integer, Token::IntegerLiteral(Token::ValueType::Boolean, s32(0)))); else if (identifier == "true") - tokens.emplace_back(VALUE_TOKEN(Integer, Token::IntegerLiteral(Token::ValueType::Unsigned8Bit, u8(1)))); + tokens.emplace_back(VALUE_TOKEN(Integer, Token::IntegerLiteral(Token::ValueType::Boolean, s32(1)))); // Check for built-in types else if (identifier == "u8") diff --git a/source/lang/parser.cpp b/source/lang/parser.cpp index ea2fca299..9bc4e208e 100644 --- a/source/lang/parser.cpp +++ b/source/lang/parser.cpp @@ -5,7 +5,7 @@ #define MATCHES(x) (begin() && x) -#define TO_NUMERIC_EXPRESSION(node) new ASTNodeNumericExpression((node), new ASTNodeIntegerLiteral({ Token::ValueType::Signed32Bit, s32(0) }), Token::Operator::Plus) +#define TO_NUMERIC_EXPRESSION(node) new ASTNodeNumericExpression((node), new ASTNodeIntegerLiteral({ Token::ValueType::Any, s32(0) }), Token::Operator::Plus) // Definition syntax: // [A] : Either A or no token @@ -106,7 +106,7 @@ namespace hex::lang { if (MATCHES(sequence(OPERATOR_PLUS) || sequence(OPERATOR_MINUS) || sequence(OPERATOR_BOOLNOT) || sequence(OPERATOR_BITNOT))) { auto op = getValue(-1); - return new ASTNodeNumericExpression(new ASTNodeIntegerLiteral({ Token::ValueType::Signed32Bit, 0}), this->parseFactor(), op); + return new ASTNodeNumericExpression(new ASTNodeIntegerLiteral({ Token::ValueType::Any, 0 }), this->parseFactor(), op); } return this->parseFactor(); @@ -473,7 +473,7 @@ namespace hex::lang { if (enumNode->getEntries().empty()) lastEntry = TO_NUMERIC_EXPRESSION(new ASTNodeIntegerLiteral({ Token::ValueType::Unsigned8Bit, u8(0) })); else - valueExpr = new ASTNodeNumericExpression(lastEntry->clone(), new ASTNodeIntegerLiteral({ Token::ValueType::Signed32Bit, s32(1) }), Token::Operator::Plus); + valueExpr = new ASTNodeNumericExpression(lastEntry->clone(), new ASTNodeIntegerLiteral({ Token::ValueType::Any, s32(1) }), Token::Operator::Plus); enumNode->addEntry(name, valueExpr); }