From e7bdc35aa82339f0734ec7014d2da0459ff0462d Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 4 Jun 2018 17:23:02 -0700 Subject: Cleanups to try/catch logic and object logic. --- lib/object.nom | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'lib/object.nom') diff --git a/lib/object.nom b/lib/object.nom index 9229d21..eb9beb8 100644 --- a/lib/object.nom +++ b/lib/object.nom @@ -11,22 +11,26 @@ action [new %classname %inst] immediately parse [new %classname] as: new %classname {} -parse [as %instance %body] as - lua> "local self;" - do - using - lua> ".." - self = \%instance - local cls = self.class - local old_self = self.class:set_self(self) - ACTIONS = cls.ACTIONS - COMPILE_ACTIONS = cls.COMPILE_ACTIONS - ARG_ORDERS = cls.ARG_ORDERS - ..do - %body - ..then always - lua> ".." +compile [as %instance %body] to + Lua ".." + do + local self = \(%instance as lua expr) + local old_self = self.class:set_self(self) + old_actions, ACTIONS = ACTIONS, self.class.ACTIONS + old_compile_actions, COMPILE_ACTIONS = COMPILE_ACTIONS, self.class.COMPILE_ACTIONS + old_arg_orders, ARG_ORDERS = ARG_ORDERS, self.class.ARG_ORDERS + local fell_through = false + local ok, ret = pcall(function() + \(%body as lua statements) + fell_through = true + end) self.class:set_self(old_self) + ACTIONS = old_actions + COMPILE_ACTIONS = old_compile_actions + ARG_ORDERS = old_arg_orders + if not ok then error(ret) end + if not fell_through then return ret end + end parse [object %classname %class_body] as using -- cgit v1.2.3