From 15d1419c0d97d63a70271c451fdeef1e69ad7d96 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Sat, 11 Feb 2017 21:01:18 +0100 Subject: Evaluate direct scopes, and fix bugs --- evaluate.h | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'evaluate.h') diff --git a/evaluate.h b/evaluate.h index 50166cd..e2dc241 100644 --- a/evaluate.h +++ b/evaluate.h @@ -36,12 +36,18 @@ public: Type type; double numval; string strval; - ScopeVal *scopeval; + ScopeVal *scopeval=nullptr; Value(); Value(double numval); Value(const string &strval); Value(ScopeVal *scopeval); + Value(const Value &other); + Value(Value &&other); + ~Value(); + + Value& operator=(const Value &other) = delete; + Value& operator=(Value &&other) = delete; }; class ScopeVal{ @@ -69,11 +75,12 @@ namespace A { class Assembly{ class Instruction{ public: - enum class Type{ // Effect on the value stack is given + enum class Type{ pushnil, // [ -> nil] pushnum, // [ -> this.num] pushstr, // [ -> this.str] pushscope, // [ -> this.scope] + newscope, // [ -> {}] pop, // [x -> ] swap, // [x,y -> y,x] add, // [x,y -> x+y] @@ -84,7 +91,7 @@ class Assembly{ create, // [value -> ] Creates binding this.name in the top scope store, // [value -> ] Stores in the first scope to contain a this.name binding load, // [ -> value] Retrieves from the first scope to contain a this.name binding - enter, // [scope -> ] Pushes the given scope on the scope stack + enter, // [scope -> scope] Copies the given scope to the scope stack leave, // [ -> ] Pops from the scope stack call, // [scope,arg,...,arg -> scope] Pops this.nargs arguments and replaces for names from scope.scopeDef.args }; @@ -92,7 +99,7 @@ class Assembly{ Type type; double num; string str; - ScopeDef *scope; + ScopeDef *scope=nullptr; string name; int nargs; @@ -101,6 +108,12 @@ class Assembly{ Instruction(Type type,const string &str); // pushstr, create, store, load Instruction(Type type,ScopeDef *scope); // pushscope Instruction(Type type,int nargs); // call + Instruction(const Instruction &other); + Instruction(Instruction &&other); + ~Instruction(); + + Instruction& operator=(const Instruction &other) = delete; + Instruction& operator=(Instruction &&other) = delete; }; vector listing; -- cgit v1.2.3-70-g09d2