From 164a8d297429d58d216b9fa44e0cb42db5d23e2c Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Sat, 11 Feb 2017 22:54:35 +0100 Subject: Handle functions better in 'compilation' --- evaluate.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'evaluate.h') 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); -- cgit v1.2.3-70-g09d2