summaryrefslogtreecommitdiff
path: root/evaluate.h
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2017-02-11 22:54:35 +0100
committertomsmeding <tom.smeding@gmail.com>2017-02-11 22:55:53 +0100
commit164a8d297429d58d216b9fa44e0cb42db5d23e2c (patch)
treeb6ca185472108fe4de3578b9efd8d46dd2476582 /evaluate.h
parent15d1419c0d97d63a70271c451fdeef1e69ad7d96 (diff)
Handle functions better in 'compilation'
Diffstat (limited to 'evaluate.h')
-rw-r--r--evaluate.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/evaluate.h b/evaluate.h
index e2dc241..9571626 100644
--- a/evaluate.h
+++ b/evaluate.h
@@ -23,6 +23,7 @@ public:
class ScopeVal;
+class Assembly;
class Value{
public:
@@ -31,17 +32,21 @@ public:
number, // numval
string, // strval
scope, // scopeval
+ lazy, // asmval
+ function, // asmval
};
Type type;
double numval;
string strval;
ScopeVal *scopeval=nullptr;
+ Assembly *asmval=nullptr;
Value();
Value(double numval);
Value(const string &strval);
Value(ScopeVal *scopeval);
+ Value(Type type,Assembly *asmval); // lazy, function
Value(const Value &other);
Value(Value &&other);
~Value();
@@ -80,6 +85,7 @@ class Assembly{
pushnum, // [ -> this.num]
pushstr, // [ -> this.str]
pushscope, // [ -> this.scope]
+ pushfunc, // [ -> Value(function,this.asmval)]
newscope, // [ -> {}]
pop, // [x -> ]
swap, // [x,y -> y,x]
@@ -102,12 +108,14 @@ class Assembly{
ScopeDef *scope=nullptr;
string name;
int nargs;
+ Assembly *asmval=nullptr;
Instruction(Type type);
Instruction(Type type,double num); // pushnum
Instruction(Type type,const string &str); // pushstr, create, store, load
Instruction(Type type,ScopeDef *scope); // pushscope
Instruction(Type type,int nargs); // call
+ Instruction(Type type,Assembly *asmval); // pushfunc
Instruction(const Instruction &other);
Instruction(Instruction &&other);
~Instruction();
@@ -122,6 +130,8 @@ class Assembly{
void codegen(const Statement &stmt);
void codegen(const Expression &expr);
+ Assembly(const ScopeDef &scopeDef);
+
public:
Assembly(const StatementList &stl);