xo-expression: initial commit (constant + primitive)
This commit is contained in:
commit
2d94fd51bf
17 changed files with 544 additions and 0 deletions
48
include/xo/expression/Expression.hpp
Normal file
48
include/xo/expression/Expression.hpp
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/** @file Expression.hpp
|
||||
*
|
||||
* Author: Roland Conybeare
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "xo/refcnt/Refcounted.hpp"
|
||||
#include "exprtype.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace ast {
|
||||
/** @class Expression
|
||||
* @brief abstract syntax tree for an EGAD program
|
||||
*
|
||||
* (Expression Graph with Automagic Derivation)
|
||||
*
|
||||
* Things you can do with an Expression:
|
||||
* - evaluate it using an interpreter
|
||||
* - execute it on a VM
|
||||
* - compile using LLVM
|
||||
* see xo-jit/
|
||||
**/
|
||||
class Expression : public ref::Refcount {
|
||||
public:
|
||||
explicit Expression(exprtype extype) : extype_{extype} {}
|
||||
|
||||
exprtype extype() const { return extype_; }
|
||||
|
||||
/** write human-readable representation to stream **/
|
||||
virtual void display(std::ostream & os) const = 0;
|
||||
/** human-readable string representation **/
|
||||
virtual std::string display_string() const;
|
||||
|
||||
private:
|
||||
/** expression type (constant | apply | ..) for this expression **/
|
||||
exprtype extype_ = exprtype::invalid;
|
||||
}; /*Expression*/
|
||||
|
||||
inline std::ostream &
|
||||
operator<<(std::ostream & os, const Expression & x) {
|
||||
x.display(os);
|
||||
return os;
|
||||
}
|
||||
} /*namespace ast*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/** end Expression.hpp **/
|
||||
Loading…
Add table
Add a link
Reference in a new issue