From 78b086a8f3bc7e6424cef1e7c82fa2bd5c09ae93 Mon Sep 17 00:00:00 2001 From: joshvera Date: Tue, 17 Apr 2018 17:51:52 -0400 Subject: [PATCH 1/2] Add Evaluatable instance for AbstractClass --- src/Language/TypeScript/Syntax.hs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Language/TypeScript/Syntax.hs b/src/Language/TypeScript/Syntax.hs index dbe47dd63..ee149bf4b 100644 --- a/src/Language/TypeScript/Syntax.hs +++ b/src/Language/TypeScript/Syntax.hs @@ -663,16 +663,26 @@ instance Ord1 ClassHeritage where liftCompare = genericLiftCompare instance Show1 ClassHeritage where liftShowsPrec = genericLiftShowsPrec instance Evaluatable ClassHeritage -data AbstractClass a = AbstractClass { abstractClassIdentifier :: !a, _abstractClassTypeParameters :: !a, _classHeritage :: ![a], _classBody :: !a } +data AbstractClass a = AbstractClass { abstractClassIdentifier :: !a, _abstractClassTypeParameters :: !a, classHeritage :: ![a], classBody :: !a } deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable, FreeVariables1, Declarations1) instance Eq1 AbstractClass where liftEq = genericLiftEq instance Ord1 AbstractClass where liftCompare = genericLiftCompare instance Show1 AbstractClass where liftShowsPrec = genericLiftShowsPrec -instance Evaluatable AbstractClass instance Declarations a => Declarations (AbstractClass a) where declaredName AbstractClass{..} = declaredName abstractClassIdentifier +instance Evaluatable AbstractClass where + eval AbstractClass{..} = do + name <- either (throwEvalError . FreeVariablesError) pure (freeVariable $ subterm abstractClassIdentifier) + supers <- traverse subtermValue classHeritage + (v, addr) <- letrec name $ do + void $ subtermValue classBody + classEnv <- Env.head <$> getEnv + klass name supers classEnv + v <$ modifyEnv (Env.insert name addr) + + data JsxElement a = JsxElement { _jsxOpeningElement :: !a, _jsxElements :: ![a], _jsxClosingElement :: !a } deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable, FreeVariables1, Declarations1) From 8d8ebc9c87b407adef1544de003cf35ff29ec958 Mon Sep 17 00:00:00 2001 From: joshvera Date: Tue, 17 Apr 2018 18:26:29 -0400 Subject: [PATCH 2/2] Add a TypeAlias Evaluatable instance --- src/Data/Syntax/Declaration.hs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Data/Syntax/Declaration.hs b/src/Data/Syntax/Declaration.hs index 639a05dfb..bbbfedfd9 100644 --- a/src/Data/Syntax/Declaration.hs +++ b/src/Data/Syntax/Declaration.hs @@ -238,7 +238,13 @@ instance Ord1 TypeAlias where liftCompare = genericLiftCompare instance Show1 TypeAlias where liftShowsPrec = genericLiftShowsPrec -- TODO: Implement Eval instance for TypeAlias -instance Evaluatable TypeAlias +instance Evaluatable TypeAlias where + eval TypeAlias{..} = do + name <- either (throwEvalError . FreeVariablesError) pure (freeVariable (subterm typeAliasIdentifier)) + v <- subtermValue typeAliasKind + addr <- lookupOrAlloc name + assign addr v + modifyEnv (Env.insert name addr) $> v instance Declarations a => Declarations (TypeAlias a) where declaredName TypeAlias{..} = declaredName typeAliasIdentifier