-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ytsao
committed
Dec 6, 2024
1 parent
26b066b
commit ec6ed89
Showing
3 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include "ast.hpp" | ||
|
||
class AbstractInterpreter { | ||
public: | ||
void eval(const ASTNode& ast){ | ||
|
||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include "ast.hpp" | ||
|
||
class Interval { | ||
public: | ||
int lower; | ||
int upper; | ||
|
||
Interval() : lower(0), upper(0) {} | ||
Interval(int lower, int upper) : lower(lower), upper(upper) {} | ||
|
||
void add(){return;} | ||
void sub(){return;} | ||
void mul(){return;} | ||
void div(){return;} | ||
|
||
void le(){return;} | ||
void leq(){return;} | ||
void ge(){return;} | ||
void geq(){return;} | ||
void eq(){return;} | ||
void neq(){return;} | ||
|
||
void meet(const Interval& other){ | ||
lower = std::max(lower, other.lower); | ||
upper = std::min(upper, other.upper); | ||
} | ||
|
||
void join(const Interval& other){ | ||
lower = std::min(lower, other.lower); | ||
upper = std::max(upper, other.upper); | ||
} | ||
|
||
void widen(const Interval& other){ | ||
if (lower > other.lower){ | ||
lower = std::numeric_limits<int>::min(); | ||
} | ||
if (upper < other.upper){ | ||
upper = std::numeric_limits<int>::max(); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#include "ast.hpp" | ||
#include "interval.hpp" | ||
|
||
class InterValStore { | ||
public: | ||
std::map<std::string, Interval> store; | ||
|
||
void set(const std::string& name, const Interval& value){ | ||
store[name] = value; | ||
} | ||
|
||
Interval get(const std::string& name){ | ||
return store[name]; | ||
} | ||
|
||
void add(const std::string& name, const Interval& value){ | ||
store[name].add(); | ||
} | ||
|
||
void sub(const std::string& name, const Interval& value){ | ||
store[name].sub(); | ||
} | ||
|
||
void mul(const std::string& name, const Interval& value){ | ||
store[name].mul(); | ||
} | ||
|
||
void div(const std::string& name, const Interval& value){ | ||
store[name].div(); | ||
} | ||
|
||
void le(const std::string& name, const Interval& value){ | ||
store[name].le(); | ||
} | ||
|
||
void leq(const std::string& name, const Interval& value){ | ||
store[name].leq(); | ||
} | ||
|
||
void ge(const std::string& name, const Interval& value){ | ||
store[name].ge(); | ||
} | ||
|
||
void geq(const std::string& name, const Interval& value){ | ||
store[name].geq(); | ||
} | ||
|
||
void eq(const std::string& name, const Interval& value){ | ||
store[name].eq(); | ||
} | ||
|
||
void neq(const std::string& name, const Interval& value){ | ||
store[name].neq(); | ||
} | ||
|
||
void join(const std::string& name, const Interval& value){ | ||
store[name].join(value); | ||
} | ||
|
||
void meet(const std::string& name, const Interval& value){ | ||
store[name].meet(value); | ||
} | ||
|
||
void widen(const std::string& name, const Interval& value){ | ||
store[name].widen(value); | ||
} | ||
}; |