1
1
mirror of https://github.com/github/semantic.git synced 2025-01-06 23:46:21 +03:00

Use declare in define implementation

This commit is contained in:
joshvera 2018-09-24 14:12:26 -05:00
parent b2a2486059
commit 153a7ad7cb

View File

@ -13,7 +13,7 @@ import Data.Abstract.Environment
import Control.Abstract.Context import Control.Abstract.Context
import Control.Abstract.Environment import Control.Abstract.Environment
import Control.Abstract.Evaluator import Control.Abstract.Evaluator
import Control.Abstract.ScopeGraph (Declaration(..)) import Control.Abstract.ScopeGraph (Declaration(..), declare, ScopeEnv, currentScope, newScope, EdgeLabel(..), withScope)
import Control.Abstract.Heap import Control.Abstract.Heap
import Control.Abstract.Value import Control.Abstract.Value
import qualified Data.Abstract.Environment as Env import qualified Data.Abstract.Environment as Env
@ -22,28 +22,32 @@ import qualified Data.Abstract.Name as Name
import Data.Abstract.Name (Name) import Data.Abstract.Name (Name)
import Data.Text (unpack) import Data.Text (unpack)
import Prologue import Prologue
import qualified Data.Map.Strict as Map
define :: ( HasCallStack define :: ( HasCallStack
, Member (Allocator address) effects , Member (Allocator (Address address)) effects
, Member (Deref value) effects , Member (Deref value) effects
, Member (Env address) effects , Member (Env address) effects
, Member (Reader ModuleInfo) effects , Member (Reader ModuleInfo) effects
, Member (Reader Span) effects , Member (Reader Span) effects
, Member (State (Heap address address value)) effects , Member (State (Heap address address value)) effects
, Member (ScopeEnv address) effects
, Ord address , Ord address
) )
=> Declaration => Declaration
-> Evaluator address value effects value -> Evaluator address value effects value
-> Evaluator address value effects () -> Evaluator address value effects ()
define declaration def = withCurrentCallStack callStack $ do define declaration def = withCurrentCallStack callStack $ do
addr <- alloc (name declaration) span <- ask @Span -- TODO: This Span is most definitely wrong
def >>= assign addr declaration addr <- declare declaration span Nothing
def >>= assign addr
-- TODO: This probably needs to declare something in the scope graph. -- TODO: This probably needs to declare something in the scope graph.
bind (name declaration) addr -- TODO: Insert something in the heap bind (name declaration) (Control.Abstract.Heap.address addr) -- TODO: Insert something in the heap
defineClass :: ( AbstractValue address value effects defineClass :: ( AbstractValue address value effects
, HasCallStack , HasCallStack
, Member (Allocator address) effects , Member (Allocator (Address address)) effects
, Member (ScopeEnv address) effects
, Member (Deref value) effects , Member (Deref value) effects
, Member (Env address) effects , Member (Env address) effects
, Member (Reader ModuleInfo) effects , Member (Reader ModuleInfo) effects
@ -61,7 +65,8 @@ defineClass declaration superclasses body = define declaration $ do
defineNamespace :: ( AbstractValue address value effects defineNamespace :: ( AbstractValue address value effects
, HasCallStack , HasCallStack
, Member (Allocator address) effects , Member (Allocator (Address address)) effects
, Member (ScopeEnv address) effects
, Member (Deref value) effects , Member (Deref value) effects
, Member (Env address) effects , Member (Env address) effects
, Member (Reader ModuleInfo) effects , Member (Reader ModuleInfo) effects
@ -123,7 +128,8 @@ builtInPrint :: ( AbstractValue address value effects
) )
=> Evaluator address value effects value => Evaluator address value effects value
-- TODO: This Declaration usage might be wrong. How do we know name exists. -- TODO: This Declaration usage might be wrong. How do we know name exists.
builtInPrint = lambda (\ v -> variable v >>= flip deref (Declaration v) >>= asString >>= trace . unpack >> box unit) builtInPrint =
lambda (\ v -> variable v >>= deref >>= asString >>= trace . unpack >> currentFrame) -- box unit)
builtInExport :: ( AbstractValue address value effects builtInExport :: ( AbstractValue address value effects
, HasCallStack , HasCallStack