1
1
mirror of https://github.com/github/semantic.git synced 2024-12-25 07:55:12 +03:00

Merge branch 'master' into evaluate-to-values

This commit is contained in:
Rob Rix 2018-12-11 09:12:48 -05:00
commit 35fd93be1c
27 changed files with 209 additions and 189 deletions

View File

@ -216,33 +216,33 @@ message FloorDivision {
} }
message BOr { message BOr {
GoDiff left = 1; GoDiff lhs = 1;
GoDiff right = 2; GoDiff rhs = 2;
} }
message BAnd { message BAnd {
GoDiff left = 1; GoDiff lhs = 1;
GoDiff right = 2; GoDiff rhs = 2;
} }
message BXOr { message BXOr {
GoDiff left = 1; GoDiff lhs = 1;
GoDiff right = 2; GoDiff rhs = 2;
} }
message LShift { message LShift {
GoDiff left = 1; GoDiff lhs = 1;
GoDiff right = 2; GoDiff rhs = 2;
} }
message RShift { message RShift {
GoDiff left = 1; GoDiff lhs = 1;
GoDiff right = 2; GoDiff rhs = 2;
} }
message UnsignedRShift { message UnsignedRShift {
GoDiff left = 1; GoDiff lhs = 1;
GoDiff right = 2; GoDiff rhs = 2;
} }
message Complement { message Complement {

View File

@ -198,33 +198,33 @@ message FloorDivision {
} }
message BOr { message BOr {
GoTerm left = 1; GoTerm lhs = 1;
GoTerm right = 2; GoTerm rhs = 2;
} }
message BAnd { message BAnd {
GoTerm left = 1; GoTerm lhs = 1;
GoTerm right = 2; GoTerm rhs = 2;
} }
message BXOr { message BXOr {
GoTerm left = 1; GoTerm lhs = 1;
GoTerm right = 2; GoTerm rhs = 2;
} }
message LShift { message LShift {
GoTerm left = 1; GoTerm lhs = 1;
GoTerm right = 2; GoTerm rhs = 2;
} }
message RShift { message RShift {
GoTerm left = 1; GoTerm lhs = 1;
GoTerm right = 2; GoTerm rhs = 2;
} }
message UnsignedRShift { message UnsignedRShift {
GoTerm left = 1; GoTerm lhs = 1;
GoTerm right = 2; GoTerm rhs = 2;
} }
message Complement { message Complement {

View File

@ -256,33 +256,33 @@ message Comparison {
} }
message BOr { message BOr {
JavaDiff left = 1; JavaDiff lhs = 1;
JavaDiff right = 2; JavaDiff rhs = 2;
} }
message BXOr { message BXOr {
JavaDiff left = 1; JavaDiff lhs = 1;
JavaDiff right = 2; JavaDiff rhs = 2;
} }
message BAnd { message BAnd {
JavaDiff left = 1; JavaDiff lhs = 1;
JavaDiff right = 2; JavaDiff rhs = 2;
} }
message LShift { message LShift {
JavaDiff left = 1; JavaDiff lhs = 1;
JavaDiff right = 2; JavaDiff rhs = 2;
} }
message RShift { message RShift {
JavaDiff left = 1; JavaDiff lhs = 1;
JavaDiff right = 2; JavaDiff rhs = 2;
} }
message UnsignedRShift { message UnsignedRShift {
JavaDiff left = 1; JavaDiff lhs = 1;
JavaDiff right = 2; JavaDiff rhs = 2;
} }
message Complement { message Complement {

View File

@ -238,33 +238,33 @@ message Comparison {
} }
message BOr { message BOr {
JavaTerm left = 1; JavaTerm lhs = 1;
JavaTerm right = 2; JavaTerm rhs = 2;
} }
message BXOr { message BXOr {
JavaTerm left = 1; JavaTerm lhs = 1;
JavaTerm right = 2; JavaTerm rhs = 2;
} }
message BAnd { message BAnd {
JavaTerm left = 1; JavaTerm lhs = 1;
JavaTerm right = 2; JavaTerm rhs = 2;
} }
message LShift { message LShift {
JavaTerm left = 1; JavaTerm lhs = 1;
JavaTerm right = 2; JavaTerm rhs = 2;
} }
message RShift { message RShift {
JavaTerm left = 1; JavaTerm lhs = 1;
JavaTerm right = 2; JavaTerm rhs = 2;
} }
message UnsignedRShift { message UnsignedRShift {
JavaTerm left = 1; JavaTerm lhs = 1;
JavaTerm right = 2; JavaTerm rhs = 2;
} }
message Complement { message Complement {

View File

@ -227,28 +227,28 @@ message FloorDivision {
} }
message BAnd { message BAnd {
PHPDiff left = 1; PHPDiff lhs = 1;
PHPDiff right = 2; PHPDiff rhs = 2;
} }
message BOr { message BOr {
PHPDiff left = 1; PHPDiff lhs = 1;
PHPDiff right = 2; PHPDiff rhs = 2;
} }
message BXOr { message BXOr {
PHPDiff left = 1; PHPDiff lhs = 1;
PHPDiff right = 2; PHPDiff rhs = 2;
} }
message LShift { message LShift {
PHPDiff left = 1; PHPDiff lhs = 1;
PHPDiff right = 2; PHPDiff rhs = 2;
} }
message RShift { message RShift {
PHPDiff left = 1; PHPDiff lhs = 1;
PHPDiff right = 2; PHPDiff rhs = 2;
} }
message And { message And {

View File

@ -209,28 +209,28 @@ message FloorDivision {
} }
message BAnd { message BAnd {
PHPTerm left = 1; PHPTerm lhs = 1;
PHPTerm right = 2; PHPTerm rhs = 2;
} }
message BOr { message BOr {
PHPTerm left = 1; PHPTerm lhs = 1;
PHPTerm right = 2; PHPTerm rhs = 2;
} }
message BXOr { message BXOr {
PHPTerm left = 1; PHPTerm lhs = 1;
PHPTerm right = 2; PHPTerm rhs = 2;
} }
message LShift { message LShift {
PHPTerm left = 1; PHPTerm lhs = 1;
PHPTerm right = 2; PHPTerm rhs = 2;
} }
message RShift { message RShift {
PHPTerm left = 1; PHPTerm lhs = 1;
PHPTerm right = 2; PHPTerm rhs = 2;
} }
message And { message And {

View File

@ -198,28 +198,28 @@ message XOr {
} }
message BAnd { message BAnd {
PythonDiff left = 1; PythonDiff lhs = 1;
PythonDiff right = 2; PythonDiff rhs = 2;
} }
message BOr { message BOr {
PythonDiff left = 1; PythonDiff lhs = 1;
PythonDiff right = 2; PythonDiff rhs = 2;
} }
message BXOr { message BXOr {
PythonDiff left = 1; PythonDiff lhs = 1;
PythonDiff right = 2; PythonDiff rhs = 2;
} }
message LShift { message LShift {
PythonDiff left = 1; PythonDiff lhs = 1;
PythonDiff right = 2; PythonDiff rhs = 2;
} }
message RShift { message RShift {
PythonDiff left = 1; PythonDiff lhs = 1;
PythonDiff right = 2; PythonDiff rhs = 2;
} }
message Complement { message Complement {

View File

@ -180,28 +180,28 @@ message XOr {
} }
message BAnd { message BAnd {
PythonTerm left = 1; PythonTerm lhs = 1;
PythonTerm right = 2; PythonTerm rhs = 2;
} }
message BOr { message BOr {
PythonTerm left = 1; PythonTerm lhs = 1;
PythonTerm right = 2; PythonTerm rhs = 2;
} }
message BXOr { message BXOr {
PythonTerm left = 1; PythonTerm lhs = 1;
PythonTerm right = 2; PythonTerm rhs = 2;
} }
message LShift { message LShift {
PythonTerm left = 1; PythonTerm lhs = 1;
PythonTerm right = 2; PythonTerm rhs = 2;
} }
message RShift { message RShift {
PythonTerm left = 1; PythonTerm lhs = 1;
PythonTerm right = 2; PythonTerm rhs = 2;
} }
message Complement { message Complement {

View File

@ -117,7 +117,8 @@ message RubySyntax {
Module module = 83; Module module = 83;
Require require = 84; Require require = 84;
Send send = 85; Send send = 85;
List list = 86; ZSuper zSuper = 86;
List list = 87;
} }
} }
@ -184,28 +185,28 @@ message FloorDivision {
} }
message BAnd { message BAnd {
RubyDiff left = 1; RubyDiff lhs = 1;
RubyDiff right = 2; RubyDiff rhs = 2;
} }
message BOr { message BOr {
RubyDiff left = 1; RubyDiff lhs = 1;
RubyDiff right = 2; RubyDiff rhs = 2;
} }
message BXOr { message BXOr {
RubyDiff left = 1; RubyDiff lhs = 1;
RubyDiff right = 2; RubyDiff rhs = 2;
} }
message LShift { message LShift {
RubyDiff left = 1; RubyDiff lhs = 1;
RubyDiff right = 2; RubyDiff rhs = 2;
} }
message RShift { message RShift {
RubyDiff left = 1; RubyDiff lhs = 1;
RubyDiff right = 2; RubyDiff rhs = 2;
} }
message Complement { message Complement {
@ -517,6 +518,8 @@ message Send {
repeated RubyDiff sendBlock = 4; repeated RubyDiff sendBlock = 4;
} }
message ZSuper { }
message List { message List {
repeated RubyDiff listContent = 1; repeated RubyDiff listContent = 1;
} }

View File

@ -99,7 +99,8 @@ message RubySyntax {
Module module = 83; Module module = 83;
Require require = 84; Require require = 84;
Send send = 85; Send send = 85;
List list = 86; ZSuper zSuper = 86;
List list = 87;
} }
} }
@ -166,28 +167,28 @@ message FloorDivision {
} }
message BAnd { message BAnd {
RubyTerm left = 1; RubyTerm lhs = 1;
RubyTerm right = 2; RubyTerm rhs = 2;
} }
message BOr { message BOr {
RubyTerm left = 1; RubyTerm lhs = 1;
RubyTerm right = 2; RubyTerm rhs = 2;
} }
message BXOr { message BXOr {
RubyTerm left = 1; RubyTerm lhs = 1;
RubyTerm right = 2; RubyTerm rhs = 2;
} }
message LShift { message LShift {
RubyTerm left = 1; RubyTerm lhs = 1;
RubyTerm right = 2; RubyTerm rhs = 2;
} }
message RShift { message RShift {
RubyTerm left = 1; RubyTerm lhs = 1;
RubyTerm right = 2; RubyTerm rhs = 2;
} }
message Complement { message Complement {
@ -499,6 +500,8 @@ message Send {
repeated RubyTerm sendBlock = 4; repeated RubyTerm sendBlock = 4;
} }
message ZSuper { }
message List { message List {
repeated RubyTerm listContent = 1; repeated RubyTerm listContent = 1;
} }

View File

@ -196,6 +196,7 @@ message TypeScriptSyntax {
QualifiedExportFrom qualifiedExportFrom = 162; QualifiedExportFrom qualifiedExportFrom = 162;
JavaScriptRequire javaScriptRequire = 163; JavaScriptRequire javaScriptRequire = 163;
List list = 164; List list = 164;
StatementBlock statementBlock = 165;
} }
} }
@ -298,33 +299,33 @@ message FloorDivision {
} }
message BAnd { message BAnd {
TypeScriptDiff left = 1; TypeScriptDiff lhs = 1;
TypeScriptDiff right = 2; TypeScriptDiff rhs = 2;
} }
message BOr { message BOr {
TypeScriptDiff left = 1; TypeScriptDiff lhs = 1;
TypeScriptDiff right = 2; TypeScriptDiff rhs = 2;
} }
message BXOr { message BXOr {
TypeScriptDiff left = 1; TypeScriptDiff lhs = 1;
TypeScriptDiff right = 2; TypeScriptDiff rhs = 2;
} }
message LShift { message LShift {
TypeScriptDiff left = 1; TypeScriptDiff lhs = 1;
TypeScriptDiff right = 2; TypeScriptDiff rhs = 2;
} }
message RShift { message RShift {
TypeScriptDiff left = 1; TypeScriptDiff lhs = 1;
TypeScriptDiff right = 2; TypeScriptDiff rhs = 2;
} }
message UnsignedRShift { message UnsignedRShift {
TypeScriptDiff left = 1; TypeScriptDiff lhs = 1;
TypeScriptDiff right = 2; TypeScriptDiff rhs = 2;
} }
message Complement { message Complement {
@ -857,6 +858,7 @@ message OptionalParameter {
message RequiredParameter { message RequiredParameter {
repeated TypeScriptDiff requiredParameterContext = 1; repeated TypeScriptDiff requiredParameterContext = 1;
TypeScriptDiff requiredParameterSubject = 2; TypeScriptDiff requiredParameterSubject = 2;
TypeScriptDiff requiredParameterValue = 3;
} }
message RestParameter { message RestParameter {
@ -965,6 +967,10 @@ message List {
repeated TypeScriptDiff listContent = 1; repeated TypeScriptDiff listContent = 1;
} }
message StatementBlock {
repeated TypeScriptDiff statements = 1;
}
message Alias { message Alias {
bytes aliasValue = 1; bytes aliasValue = 1;
bytes aliasName = 2; bytes aliasName = 2;

View File

@ -178,6 +178,7 @@ message TypeScriptSyntax {
QualifiedExportFrom qualifiedExportFrom = 162; QualifiedExportFrom qualifiedExportFrom = 162;
JavaScriptRequire javaScriptRequire = 163; JavaScriptRequire javaScriptRequire = 163;
List list = 164; List list = 164;
StatementBlock statementBlock = 165;
} }
} }
@ -280,33 +281,33 @@ message FloorDivision {
} }
message BAnd { message BAnd {
TypeScriptTerm left = 1; TypeScriptTerm lhs = 1;
TypeScriptTerm right = 2; TypeScriptTerm rhs = 2;
} }
message BOr { message BOr {
TypeScriptTerm left = 1; TypeScriptTerm lhs = 1;
TypeScriptTerm right = 2; TypeScriptTerm rhs = 2;
} }
message BXOr { message BXOr {
TypeScriptTerm left = 1; TypeScriptTerm lhs = 1;
TypeScriptTerm right = 2; TypeScriptTerm rhs = 2;
} }
message LShift { message LShift {
TypeScriptTerm left = 1; TypeScriptTerm lhs = 1;
TypeScriptTerm right = 2; TypeScriptTerm rhs = 2;
} }
message RShift { message RShift {
TypeScriptTerm left = 1; TypeScriptTerm lhs = 1;
TypeScriptTerm right = 2; TypeScriptTerm rhs = 2;
} }
message UnsignedRShift { message UnsignedRShift {
TypeScriptTerm left = 1; TypeScriptTerm lhs = 1;
TypeScriptTerm right = 2; TypeScriptTerm rhs = 2;
} }
message Complement { message Complement {
@ -839,6 +840,7 @@ message OptionalParameter {
message RequiredParameter { message RequiredParameter {
repeated TypeScriptTerm requiredParameterContext = 1; repeated TypeScriptTerm requiredParameterContext = 1;
TypeScriptTerm requiredParameterSubject = 2; TypeScriptTerm requiredParameterSubject = 2;
TypeScriptTerm requiredParameterValue = 3;
} }
message RestParameter { message RestParameter {
@ -947,6 +949,10 @@ message List {
repeated TypeScriptTerm listContent = 1; repeated TypeScriptTerm listContent = 1;
} }
message StatementBlock {
repeated TypeScriptTerm statements = 1;
}
message Alias { message Alias {
bytes aliasValue = 1; bytes aliasValue = 1;
bytes aliasName = 2; bytes aliasName = 2;

View File

@ -144,9 +144,9 @@ newtype Cache term address value = Cache { unCache :: Monoidal.Map (Configuratio
-- | A single point in a programs execution. -- | A single point in a programs execution.
data Configuration term address value = Configuration data Configuration term address value = Configuration
{ configurationTerm :: term -- ^ The “instruction,” i.e. the current term to evaluate. { configurationTerm :: term -- ^ The “instruction,” i.e. the current term to evaluate.
, configurationRoots :: Live address -- ^ The set of rooted addresses. , configurationRoots :: Live address -- ^ The set of rooted addresses.
, configurationHeap :: Heap address address value -- ^ The heap of values. , configurationHeap :: Heap address address value -- ^ The heap of values.
} }
deriving (Eq, Ord, Show) deriving (Eq, Ord, Show)

View File

@ -65,23 +65,24 @@ style = (defaultStyle (T.encodeUtf8Builder . vertexIdentifier))
graphingTerms :: ( Member (Reader ModuleInfo) sig graphingTerms :: ( Member (Reader ModuleInfo) sig
, Member (Reader Span) sig , Member (Reader Span) sig
, Member (State (Graph ControlFlowVertex)) sig , Member (State (Graph ControlFlowVertex)) sig
, Member (State (Map (Slot (Hole context (Located address))) ControlFlowVertex)) sig , Member (State (Map (Slot hole) ControlFlowVertex)) sig
, Member (State (Heap (Hole context (Located address)) (Hole context (Located address)) value)) sig , Member (State (Heap hole hole value)) sig
, Member (State (ScopeGraph (Hole context (Located address)))) sig , Member (State (ScopeGraph (Hole context (Located address)))) sig
, Member (Resumable (BaseError (ScopeError (Hole context (Located address))))) sig , Member (Resumable (BaseError (ScopeError hole))) sig
, Member (Resumable (BaseError (HeapError (Hole context (Located address))))) sig , Member (Resumable (BaseError (HeapError hole))) sig
, Member (Reader (CurrentFrame (Hole context (Located address)))) sig , Member (Reader (CurrentFrame hole)) sig
, Member (Reader (CurrentScope (Hole context (Located address)))) sig , Member (Reader (CurrentScope hole)) sig
, Member (Reader ControlFlowVertex) sig , Member (Reader ControlFlowVertex) sig
, VertexDeclaration syntax , VertexDeclaration syntax
, Declarations1 syntax , Declarations1 syntax
, Ord address , Ord address
, Ord context , Ord context
, Foldable syntax , Foldable syntax
, hole ~ Hole context (Located address)
, term ~ Term syntax Location , term ~ Term syntax Location
, Carrier sig m , Carrier sig m
) )
=> Open (term -> Evaluator term (Hole context (Located address)) value m a) => Open (term -> Evaluator term hole value m a)
graphingTerms recur term@(Term (In a syntax)) = do graphingTerms recur term@(Term (In a syntax)) = do
definedInModule <- currentModule definedInModule <- currentModule
case toVertex a definedInModule syntax of case toVertex a definedInModule syntax of

View File

@ -35,7 +35,7 @@ getConfiguration term = Configuration term <$> getHeap
-- | A single point in a programs execution. -- | A single point in a programs execution.
data Configuration term address value = Configuration data Configuration term address value = Configuration
{ configurationTerm :: term -- ^ The “instruction,” i.e. the current term to evaluate. { configurationTerm :: term -- ^ The “instruction,” i.e. the current term to evaluate.
, configurationHeap :: Heap address address value -- ^ The heap of values. , configurationHeap :: Heap address address value -- ^ The heap of values.
} }
deriving (Eq, Ord, Show) deriving (Eq, Ord, Show)

View File

@ -80,9 +80,9 @@ sendFunction :: (Member (Function term address value) sig, Carrier sig m) => Fun
sendFunction = send sendFunction = send
data Function term address value (m :: * -> *) k data Function term address value (m :: * -> *) k
= Function Name [Name] term address (value -> k) = Function Name [Name] term address (value -> k) -- ^ A function is parameterized by its name, parameter names, body, parent scope, and returns a ValueRef.
| BuiltIn address BuiltIn (value -> k) | BuiltIn address BuiltIn (value -> k) -- ^ A built-in is parameterized by its parent scope, BuiltIn type, and returns a value.
| Call value [value] (value -> k) | Call value [value] (value -> k) -- ^ A Call takes a set of values as parameters and returns a ValueRef.
deriving (Functor) deriving (Functor)
instance HFunctor (Function term address value) where instance HFunctor (Function term address value) where

View File

@ -147,8 +147,9 @@ instance HasPrelude 'Ruby where
defineBuiltIn (Declaration $ X.name "inspect") Show defineBuiltIn (Declaration $ X.name "inspect") Show
instance HasPrelude 'TypeScript where instance HasPrelude 'TypeScript where
definePrelude _ = defineSelf definePrelude _ = do
-- defineNamespace (Declaration (X.name "console")) $ defineBuiltIn (Declaration $ X.name "log") Print defineSelf
defineNamespace (Declaration (X.name "console")) $ defineBuiltIn (Declaration $ X.name "log") Print
instance HasPrelude 'JavaScript where instance HasPrelude 'JavaScript where
definePrelude _ = do definePrelude _ = do

View File

@ -41,14 +41,20 @@ import qualified Data.Map.Strict as Map
import Prelude hiding (lookup) import Prelude hiding (lookup)
import Prologue import Prologue
-- | A Frame describes the vertices of the Heap. Think of it as an instance of a Scope in the ScopeGraph.
data Frame scopeAddress frameAddress value = Frame data Frame scopeAddress frameAddress value = Frame
{ scopeAddress :: scopeAddress { scopeAddress :: scopeAddress
-- ^ The scope address of its corresponding Scope
, links :: Map EdgeLabel (Map scopeAddress frameAddress) , links :: Map EdgeLabel (Map scopeAddress frameAddress)
-- ^ A map of edge labels to maps of scope addresses to frame addresses (scope addresses are unique keys in the ScopeGraph
-- and frame addresses are unique keys in the Heap). This map describes the frames links to other frames.
-- A frames links are always in one-to-one correspondence with its scopes edges to parent scopes.
, slots :: IntMap (Set value) , slots :: IntMap (Set value)
-- ^ An IntMap of values that are declared in the frame.
} }
deriving (Eq, Ord, Show, Generic, NFData) deriving (Eq, Ord, Show, Generic, NFData)
-- | A map of frame addresses onto Frames. -- | A Heap is a Map from frame addresses to frames.
newtype Heap scopeAddress frameAddress value = Heap { unHeap :: Map frameAddress (Frame scopeAddress frameAddress value) } newtype Heap scopeAddress frameAddress value = Heap { unHeap :: Map frameAddress (Frame scopeAddress frameAddress value) }
deriving stock (Eq, Generic, Ord) deriving stock (Eq, Generic, Ord)
deriving newtype (NFData) deriving newtype (NFData)
@ -135,11 +141,13 @@ heapSize = Map.size . unHeap
heapRestrict :: Ord address => Heap address address value -> Live address -> Heap address address value heapRestrict :: Ord address => Heap address address value -> Live address -> Heap address address value
heapRestrict (Heap m) roots = Heap (Map.filterWithKey (\ address _ -> address `liveMember` roots) m) heapRestrict (Heap m) roots = Heap (Map.filterWithKey (\ address _ -> address `liveMember` roots) m)
-- | Checks whether a heap as no slots and links.
isHeapEmpty :: (Eq address, Eq value) => Heap scope address value -> Bool isHeapEmpty :: (Eq address, Eq value) => Heap scope address value -> Bool
isHeapEmpty h@(Heap heap) isHeapEmpty h@(Heap heap)
= heapSize h == 1 = heapSize h == 1
&& (toEmptyFrame <$> Map.elems heap) == [ Frame () mempty mempty ] && (toEmptyFrame <$> Map.elems heap) == [ Frame () mempty mempty ]
where where
-- Maps a frame's address param to () so we can check that its slots and links are empty.
toEmptyFrame Frame{..} = Frame () (Map.mapKeysMonotonic (const ()) <$> links) slots toEmptyFrame Frame{..} = Frame () (Map.mapKeysMonotonic (const ()) <$> links) slots

View File

@ -176,34 +176,6 @@ instance (Show address, Show term) => AbstractIntro (Value term address) where
null = Null null = Null
-- materializeEnvironment :: ( Member (Deref (Value term address)) sig
-- , Member (Reader ModuleInfo) sig
-- , Member (Reader Span) sig
-- , Member (Resumable (BaseError (AddressError address (Value term address)))) sig
-- , Member (State (Heap address address (Value term address))) sig
-- , Ord address
-- , Carrier sig m
-- )
-- => Value term address
-- -> Evaluator term address (Value term address) m (Maybe (Environment address))
-- materializeEnvironment val = do
-- ancestors <- rec val
-- pure (Env.Environment <$> nonEmpty ancestors)
-- where
-- rec val = do
-- supers <- concat <$> traverse (deref >=> rec) (parents val)
-- pure . maybe [] (: supers) $ bindsFrom val
--
-- bindsFrom = \case
-- Class _ _ binds -> Just binds
-- Namespace _ _ binds -> Just binds
-- _ -> Nothing
--
-- parents = \case
-- Class _ supers _ -> supers
-- Namespace _ supers _ -> toList supers
-- _ -> []
-- | Construct a 'Value' wrapping the value arguments (if any). -- | Construct a 'Value' wrapping the value arguments (if any).
instance ( Member (Allocator address) sig instance ( Member (Allocator address) sig
, Member (Abstract.Boolean (Value term address)) sig , Member (Abstract.Boolean (Value term address)) sig
@ -243,6 +215,7 @@ instance ( Member (Allocator address) sig
scopedEnvironment v scopedEnvironment v
| Object address <- v = pure (Just address) | Object address <- v = pure (Just address)
| Class _ _ address <- v = pure (Just address) | Class _ _ address <- v = pure (Just address)
| Namespace _ address <- v = pure (Just address)
| otherwise = pure Nothing | otherwise = pure Nothing
asString v asString v

View File

@ -126,6 +126,7 @@ type Syntax = '[
, Ruby.Syntax.Module , Ruby.Syntax.Module
, Ruby.Syntax.Require , Ruby.Syntax.Require
, Ruby.Syntax.Send , Ruby.Syntax.Send
, Ruby.Syntax.ZSuper
, [] , []
] ]
@ -214,12 +215,12 @@ withNewScope inner = withExtendedScope $ do
identifier :: Assignment Term identifier :: Assignment Term
identifier = identifier =
vcallOrLocal vcallOrLocal
<|> zsuper
<|> mk Constant <|> mk Constant
<|> mk InstanceVariable <|> mk InstanceVariable
<|> mk ClassVariable <|> mk ClassVariable
<|> mk GlobalVariable <|> mk GlobalVariable
<|> mk Operator <|> mk Operator
<|> mk Super
<|> mk Setter <|> mk Setter
<|> mk SplatArgument <|> mk SplatArgument
<|> mk HashSplatArgument <|> mk HashSplatArgument
@ -227,6 +228,7 @@ identifier =
<|> mk Uninterpreted <|> mk Uninterpreted
where where
mk s = makeTerm <$> symbol s <*> (Syntax.Identifier . name <$> source) mk s = makeTerm <$> symbol s <*> (Syntax.Identifier . name <$> source)
zsuper = makeTerm <$> symbol Super <*> (Ruby.Syntax.ZSuper <$ source)
vcallOrLocal = do vcallOrLocal = do
(loc, ident, locals) <- identWithLocals (loc, ident, locals) <- identWithLocals
case ident of case ident of

View File

@ -374,3 +374,18 @@ instance Evaluatable Assignment where
instance Tokenize Assignment where instance Tokenize Assignment where
-- Should we be using 'assignmentContext' in here? -- Should we be using 'assignmentContext' in here?
tokenize Assignment{..} = assignmentTarget *> yield Token.Assign <* assignmentValue tokenize Assignment{..} = assignmentTarget *> yield Token.Assign <* assignmentValue
-- | A call to @super@ without parentheses in Ruby is known as "zsuper", which has
-- the semantics of invoking @super()@ but implicitly passing the current function's
-- arguments to the @super()@ invocation.
data ZSuper a = ZSuper
deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1, NFData1)
instance Evaluatable ZSuper
instance Eq1 ZSuper where liftEq = genericLiftEq
instance Ord1 ZSuper where liftCompare = genericLiftCompare
instance Show1 ZSuper where liftShowsPrec = genericLiftShowsPrec
instance Tokenize ZSuper where
tokenize _ = yield $ Run "super"

View File

@ -7,7 +7,6 @@ module Language.TypeScript.Resolution
, resolveModule , resolveModule
, resolveNonRelativePath , resolveNonRelativePath
, javascriptExtensions , javascriptExtensions
-- , evalRequire
, typescriptExtensions , typescriptExtensions
) where ) where
@ -19,8 +18,8 @@ import Data.Abstract.Evaluatable
import qualified Data.Abstract.Module as M import qualified Data.Abstract.Module as M
import Data.Abstract.Package import Data.Abstract.Package
import Data.Abstract.Path import Data.Abstract.Path
import Data.ImportPath
import qualified Data.Language as Language import qualified Data.Language as Language
import Data.ImportPath
-- Node.js resolution algorithm: https://nodejs.org/api/modules.html#modules_all_together -- Node.js resolution algorithm: https://nodejs.org/api/modules.html#modules_all_together
-- --

View File

@ -85,7 +85,7 @@ instance Ord1 OptionalParameter where liftCompare = genericLiftCompare
instance Show1 OptionalParameter where liftShowsPrec = genericLiftShowsPrec instance Show1 OptionalParameter where liftShowsPrec = genericLiftShowsPrec
instance Evaluatable OptionalParameter instance Evaluatable OptionalParameter
data RequiredParameter a = RequiredParameter { requiredParameterContext :: ![a], requiredParameterSubject :: !a, requiredParameterValue :: !a } data RequiredParameter a = RequiredParameter { requiredParameterContext :: [a], requiredParameterSubject :: a, requiredParameterValue :: a }
deriving (Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Message1, NFData1, Named1, Ord, Show, ToJSONFields1, Traversable) deriving (Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Message1, NFData1, Named1, Ord, Show, ToJSONFields1, Traversable)
instance Declarations1 RequiredParameter where instance Declarations1 RequiredParameter where

View File

@ -611,6 +611,7 @@ instance Taggable Ruby.Load
instance Taggable Ruby.LowPrecedenceAnd instance Taggable Ruby.LowPrecedenceAnd
instance Taggable Ruby.LowPrecedenceOr instance Taggable Ruby.LowPrecedenceOr
instance Taggable Ruby.Assignment instance Taggable Ruby.Assignment
instance Taggable Ruby.ZSuper
instance Taggable TypeScript.JavaScriptRequire instance Taggable TypeScript.JavaScriptRequire
instance Taggable TypeScript.Debugger instance Taggable TypeScript.Debugger

View File

@ -44,13 +44,12 @@ spec config = parallel $ do
(scopeGraph, (heap, res)) <- evaluate ["main1.ts", "foo.ts", "a.ts"] (scopeGraph, (heap, res)) <- evaluate ["main1.ts", "foo.ts", "a.ts"]
case ModuleTable.lookup "main1.ts" <$> res of case ModuleTable.lookup "main1.ts" <$> res of
Right (Just (Module _ (scopeAndFrame, _) :| [])) -> do Right (Just (Module _ (scopeAndFrame, _) :| [])) -> do
-- Env.names env `shouldBe` [ "b", "z" ]
() <$ SpecHelpers.lookupDeclaration "b" scopeAndFrame heap scopeGraph `shouldBe` Just () () <$ SpecHelpers.lookupDeclaration "b" scopeAndFrame heap scopeGraph `shouldBe` Just ()
() <$ SpecHelpers.lookupDeclaration "z" scopeAndFrame heap scopeGraph `shouldBe` Just () () <$ SpecHelpers.lookupDeclaration "z" scopeAndFrame heap scopeGraph `shouldBe` Just ()
lookupMembers "b" Import scopeAndFrame heap scopeGraph `shouldBe` Just [ "baz", "foo" ] lookupMembers "b" Import scopeAndFrame heap scopeGraph `shouldBe` Just [ "baz", "foo" ]
lookupMembers "z" Import scopeAndFrame heap scopeGraph `shouldBe` Just [ "baz", "foo" ] lookupMembers "z" Import scopeAndFrame heap scopeGraph `shouldBe` Just [ "baz", "foo" ]
-- (Heap.lookupDeclaration "b" heap >>= deNamespace heap) `shouldBe` Just ("b", [ "baz", "foo" ])
-- (Heap.lookupDeclaration "z" heap >>= deNamespace heap) `shouldBe` Just ("z", [ "baz", "foo" ])
() <$ SpecHelpers.lookupDeclaration "baz" scopeAndFrame heap scopeGraph `shouldBe` Nothing () <$ SpecHelpers.lookupDeclaration "baz" scopeAndFrame heap scopeGraph `shouldBe` Nothing
() <$ SpecHelpers.lookupDeclaration "foo" scopeAndFrame heap scopeGraph `shouldBe` Nothing () <$ SpecHelpers.lookupDeclaration "foo" scopeAndFrame heap scopeGraph `shouldBe` Nothing
other -> expectationFailure (show other) other -> expectationFailure (show other)
@ -77,7 +76,7 @@ spec config = parallel $ do
Right (Just (Module _ (scopeAndFrame@(currentScope, currentFrame), value) :| [])) -> do Right (Just (Module _ (scopeAndFrame@(currentScope, currentFrame), value) :| [])) -> do
() <$ SpecHelpers.lookupDeclaration "baz" scopeAndFrame heap scopeGraph `shouldBe` Nothing () <$ SpecHelpers.lookupDeclaration "baz" scopeAndFrame heap scopeGraph `shouldBe` Nothing
value `shouldBe` Unit value `shouldBe` Unit
Heap.heapSize heap `shouldBe` 3 Heap.heapSize heap `shouldBe` 4
other -> expectationFailure (show other) other -> expectationFailure (show other)
it "fails exporting symbols not defined in the module" $ do it "fails exporting symbols not defined in the module" $ do

View File

@ -477,6 +477,9 @@ instance Listable1 Ruby.Syntax.Module where
instance Listable1 Ruby.Syntax.Require where instance Listable1 Ruby.Syntax.Require where
liftTiers tiers' = liftCons2 tiers tiers' Ruby.Syntax.Require liftTiers tiers' = liftCons2 tiers tiers' Ruby.Syntax.Require
instance Listable1 Ruby.Syntax.ZSuper where
liftTiers tiers = cons0 Ruby.Syntax.ZSuper
instance Listable1 Ruby.Syntax.Send where instance Listable1 Ruby.Syntax.Send where
liftTiers tiers = liftCons4 (liftTiers tiers) (liftTiers tiers) (liftTiers tiers) (liftTiers tiers) Ruby.Syntax.Send liftTiers tiers = liftCons4 (liftTiers tiers) (liftTiers tiers) (liftTiers tiers) (liftTiers tiers) Ruby.Syntax.Send

View File

@ -5,7 +5,7 @@
(SymbolElement) (SymbolElement)
(Integer) (Integer)
(This) (This)
(Identifier) (ZSuper)
(Enumeration (Enumeration
(Integer) (Integer)
(Integer) (Integer)