Skip to content

Commit

Permalink
nyan: Allow floats for int operations.
Browse files Browse the repository at this point in the history
  • Loading branch information
heinezen committed Oct 17, 2020
1 parent 05f74f6 commit 5df4e4e
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 13 deletions.
4 changes: 2 additions & 2 deletions nyan/ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ bool ASTMemberType::exists() const {
}


ASTMemberArgument::ASTMemberArgument(TokenStream &tokens)
ASTMemberTypeArgument::ASTMemberTypeArgument(TokenStream &tokens)
:
has_key{false} {
auto token = tokens.next();
Expand Down Expand Up @@ -756,7 +756,7 @@ void ASTMemberType::strb(std::ostringstream &builder, int /*indentlevel*/) const
}


void ASTMemberArgument::strb(std::ostringstream &builder, int /*indentlevel*/) const {
void ASTMemberTypeArgument::strb(std::ostringstream &builder, int /*indentlevel*/) const {
if (this->has_key) {
builder << this->key.str() << "=";
}
Expand Down
6 changes: 3 additions & 3 deletions nyan/ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ class ASTBase {
/**
* AST representation of a member type argument declaration.
*/
class ASTMemberArgument : public ASTBase {
class ASTMemberTypeArgument : public ASTBase {
friend class ASTMemberType;
friend class Database;
friend class Type;

public:
ASTMemberArgument(TokenStream &tokens);
ASTMemberTypeArgument(TokenStream &tokens);

void strb(std::ostringstream &builder, int indentlevel=0) const override;

Expand Down Expand Up @@ -86,7 +86,7 @@ class ASTMemberType : ASTBase {
IDToken name;

bool has_args;
std::vector<ASTMemberArgument> args;
std::vector<ASTMemberTypeArgument> args;
};


Expand Down
1 change: 0 additions & 1 deletion nyan/member_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class Type;

/**
* Stores information for a member of an Object.
* Also responsible for validating applied operators.
*/
class MemberInfo {
public:
Expand Down
2 changes: 1 addition & 1 deletion nyan/type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ bool Type::is_container(container_t type) const {
}


bool Type::is_basic_compatible(const BasicType &type) const {
bool Type::is_basic_type_match(const BasicType &type) const {
return (this->basic_type == type);
}

Expand Down
4 changes: 2 additions & 2 deletions nyan/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ class Type {
bool is_container(container_t type) const;

/**
* Test if the basic type is compatbile, i. e. the same.
* Test if the basic type matches the given type, i. e. it's the same.
*/
bool is_basic_compatible(const BasicType &type) const;
bool is_basic_type_match(const BasicType &type) const;

/**
* Check if this type can be in the given other type.
Expand Down
16 changes: 12 additions & 4 deletions nyan/value/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,18 @@ static ValueHolder value_from_value_token(const Type &target_type,
return {std::make_shared<Text>(value_token)};

case primitive_t::INT:
return {std::make_shared<Int>(value_token)};

case primitive_t::FLOAT:
return {std::make_shared<Float>(value_token)};
case primitive_t::FLOAT: {
if (value_token.get_type() == token_type::INT) {
return {std::make_shared<Int>(value_token)};
}
else if (value_token.get_type() == token_type::FLOAT) {
return {std::make_shared<Float>(value_token)};
}
throw LangError{
value_token,
"invalid value for number, expecting float or int"
};
}

case primitive_t::FILENAME: {
// TODO: make relative to current namespace
Expand Down

0 comments on commit 5df4e4e

Please sign in to comment.