Commits

Alex Suraci committed 4dc1068

added raise, raise', newScope helpers

  • Participants
  • Parent commits 5134e54

Comments (0)

Files changed (1)

File src/Atomy/Runtime.hs

         }
 
     return res
+
+newScope :: VM a -> VM a
+newScope x = do
+    Trait t <- gets top
+    nt <- derive t
+
+    modify $ \env -> env
+        { methods = Methods M.empty (methods env)
+        }
+
+    r <- withTop (Trait nt) x
+
+    modify $ \env -> env { methods = mNext (methods env) }
+
+    return r
+
 -- | Evaluate an expression, yielding a value.
 eval :: Expr -> VM Value
 eval (Define { emPattern = p, eExpr = ev }) = do
   {-where-}
     {-msg t = keyword ["error"] [t, asValue e]-}
 
+-- | Raise a keyword particle as an error.
+raise :: [String] -> [Value] -> VM a
+{-# INLINE raise #-}
+raise ns vs = throwError . Error $ keyParticleN ns vs
+
+-- | Raise a single particle as an error.
+raise' :: String -> VM a
+{-# INLINE raise' #-}
+raise' = throwError . Error . particle