From 97a566e973ff467f73c4d7a1227f5f549e6d8ef1 Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Thu, 12 Apr 2018 14:22:55 -0700 Subject: [PATCH] Allow allocation in assignment again --- src/Data/Syntax/Statement.hs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Data/Syntax/Statement.hs b/src/Data/Syntax/Statement.hs index 6400c1c50..1b99b482a 100644 --- a/src/Data/Syntax/Statement.hs +++ b/src/Data/Syntax/Statement.hs @@ -96,8 +96,15 @@ instance Show1 Assignment where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Assignment where eval Assignment{..} = do - lhs <- subtermValue assignmentTarget >>= scopedEnvironment - localEnv (mappend lhs) (subtermValue assignmentValue) + case freeVariables (subterm assignmentTarget) of + [name] -> do + v <- subtermValue assignmentValue + addr <- lookupOrAlloc name + assign addr v + modifyEnv (Env.insert name addr) $> v + _ -> do + lhs <- subtermValue assignmentTarget >>= scopedEnvironment + localEnv (mappend lhs) (subtermValue assignmentValue) -- | Post increment operator (e.g. 1++ in Go, or i++ in C). newtype PostIncrement a = PostIncrement a