diff --git a/language/culebra.h b/language/culebra.h index e86ee74..b01bafe 100644 --- a/language/culebra.h +++ b/language/culebra.h @@ -86,7 +86,7 @@ inline peglib::peg& get_parser() throw std::logic_error("invalid peg grammar"); } - parser.enable_ast(true, { "PARAMETERS", "ARGUMENTS" }); + parser.enable_ast(true, { "PARAMETERS", "ARGUMENTS", "OBJECT" }); } return parser; @@ -355,9 +355,6 @@ struct Environment if (dic_.find(s) != dic_.end()) { return true; } - if (object.has_property(s)) { - return true; - } return outer && outer->has(s); } @@ -365,9 +362,6 @@ struct Environment if (dic_.find(s) != dic_.end()) { return dic_.at(s).val; } - if (object.has_property(s)) { - return object.get_property(s); - } if (outer) { return outer->get(s); } @@ -400,7 +394,6 @@ struct Environment } std::shared_ptr outer; - ObjectValue object; private: struct Symbol { @@ -513,6 +506,7 @@ struct Eval case "IF"_: return eval_if(ast, env); case "FUNCTION"_: return eval_function(ast, env); case "CALL"_: return eval_call(ast, env); + case "BLOCK"_: return eval_block(ast, env); case "ASSIGNMENT"_: return eval_assignment(ast, env); case "LOGICAL_OR"_: return eval_logical_or(ast, env); case "LOGICAL_AND"_: return eval_logical_and(ast, env); @@ -650,9 +644,6 @@ private: *pf.params, [=](std::shared_ptr callEnv) { callEnv->initialize("this", val, false); - if (val.type == Value::Object) { - callEnv->object = val.to_object(); - } return pf.eval(callEnv); } )); @@ -667,6 +658,10 @@ private: return std::move(val); } + static Value eval_block(const peglib::Ast& ast, std::shared_ptr env) { + return Value(); + } + static Value eval_logical_or(const peglib::Ast& ast, std::shared_ptr env) { assert(ast.nodes.size() > 1); // if the size is 1, thes node will be hoisted. Value val; diff --git a/language/samples/test.cul b/language/samples/test.cul index 29ddb6e..959cbcb 100644 --- a/language/samples/test.cul +++ b/language/samples/test.cul @@ -75,7 +75,7 @@ test_object = fn () { } assert(o.size() == 4) assert(o.f1(10) == 133) - assert(o.f2(10) == 133) + assert(o.f2(10) == 11) } test_object_factory = fn () {