Skip to content

Commit

Permalink
Add float parse capability to expreval
Browse files Browse the repository at this point in the history
- somewhat extensive rewrite of expreval to make it dynamic dispatch based
- ... which allows us to use typeswitches
- and using the above, add `.float` and `.double` assembler directives
  • Loading branch information
mortbopet committed Nov 5, 2023
1 parent 110b50c commit 3ffd72a
Show file tree
Hide file tree
Showing 9 changed files with 324 additions and 167 deletions.
5 changes: 4 additions & 1 deletion src/assembler/assembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,10 @@ class Assembler : public AssemblerBase {
errors.push_back(*err);
continue;
} else {
symbolValue = std::get<ExprEvalVT>(exprRes);
auto valuePtr = dynamic_cast<IntRes *>(exprRes->get());
assert(valuePtr &&
"Expected integer result from expression evaluation");
symbolValue = valuePtr->v;
}

if (!linkRequest.fieldRequest.relocation.isEmpty()) {
Expand Down
2 changes: 1 addition & 1 deletion src/assembler/assemblerbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ ExprEvalRes AssemblerBase::evalExpr(const Location &location,

auto symbolValue = relativeMap.find(expr);
if (symbolValue != relativeMap.end()) {
return symbolValue->second;
return ExprEvalRes(std::make_shared<IntRes>(symbolValue->second));
} else {
return evaluate(location, expr, &relativeMap);
}
Expand Down
13 changes: 13 additions & 0 deletions src/assembler/assemblererror.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,25 @@ struct Result : public std::variant<Error, T> {
return std::get<Error>(*this); // Make compiler happy
}

const T &operator*() { return value(); }
const T *operator->() { return &value(); }

bool isError() const { return std::holds_alternative<Error>(*this); }
bool isResult() const { return std::holds_alternative<T>(*this); }

// Convenience function for a default constructed value of T.
static T def() { return std::monostate(); }
};

// Free functions for determining whether a Result is an error or not.
template <typename T>
static bool failed(const Result<T> &res) {
return res.isError();
}
template <typename T>
static bool succeeded(const Result<T> &res) {
return res.isResult();
}

} // namespace Assembler
} // namespace Ripes
Loading

0 comments on commit 3ffd72a

Please sign in to comment.