mirror of
https://github.com/github/semantic.git
synced 2024-11-28 10:15:55 +03:00
Merge branch 'master' into fix413s
This commit is contained in:
commit
9df7c82bb1
@ -10,7 +10,6 @@ module Control.Abstract.Heap
|
|||||||
, alloc
|
, alloc
|
||||||
, deref
|
, deref
|
||||||
, assign
|
, assign
|
||||||
, lookupOrAlloc
|
|
||||||
, letrec
|
, letrec
|
||||||
, letrec'
|
, letrec'
|
||||||
, variable
|
, variable
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
{-# LANGUAGE FunctionalDependencies, UndecidableInstances #-}
|
||||||
module Control.Abstract.Primitive
|
module Control.Abstract.Primitive
|
||||||
( define
|
( define
|
||||||
, defineClass
|
, defineClass
|
||||||
@ -5,6 +6,7 @@ module Control.Abstract.Primitive
|
|||||||
, builtInPrint
|
, builtInPrint
|
||||||
, builtInExport
|
, builtInExport
|
||||||
, lambda
|
, lambda
|
||||||
|
, Lambda(..)
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Abstract.Context
|
import Control.Abstract.Context
|
||||||
@ -60,17 +62,33 @@ defineNamespace name scope = define name $ do
|
|||||||
binds <- Env.head <$> locally (scope >> getEnv)
|
binds <- Env.head <$> locally (scope >> getEnv)
|
||||||
namespace name Nothing binds
|
namespace name Nothing binds
|
||||||
|
|
||||||
|
-- | Construct a function from a Haskell function taking 'Name's as arguments.
|
||||||
|
--
|
||||||
|
-- The constructed function will have the same arity as the Haskell function. Nullary functions are constructed by providing an evaluator producing an address. Note that the constructed function must not contain free variables as they will not be captured by the closure, and/or will be garbage collected.
|
||||||
lambda :: ( HasCallStack
|
lambda :: ( HasCallStack
|
||||||
, Member Fresh effects
|
, Lambda address value effects fn
|
||||||
, Member (Function address value) effects
|
|
||||||
, Member (Reader ModuleInfo) effects
|
, Member (Reader ModuleInfo) effects
|
||||||
, Member (Reader Span) effects
|
, Member (Reader Span) effects
|
||||||
)
|
)
|
||||||
=> (Name -> Evaluator address value effects address)
|
=> fn
|
||||||
-> Evaluator address value effects value
|
-> Evaluator address value effects value
|
||||||
lambda body = withCurrentCallStack callStack $ do
|
lambda body = withCurrentCallStack callStack (lambda' [] body)
|
||||||
var <- gensym
|
|
||||||
function [var] lowerBound (body var)
|
-- | A class of types forming the body of 'lambda's. Note that there should in general only be two cases: a recursive case of functions taking 'Name's as parameters, and a base case of an 'Evaluator'.
|
||||||
|
class Lambda address value effects ty | ty -> address, ty -> value, ty -> effects where
|
||||||
|
lambda' :: [Name]
|
||||||
|
-> ty
|
||||||
|
-> Evaluator address value effects value
|
||||||
|
|
||||||
|
instance (Member Fresh effects, Lambda address value effects ret) => Lambda address value effects (Name -> ret) where
|
||||||
|
lambda' vars body = do
|
||||||
|
var <- gensym
|
||||||
|
lambda' (var : vars) (body var)
|
||||||
|
{-# INLINE lambda' #-}
|
||||||
|
|
||||||
|
instance Member (Function address value) effects => Lambda address value effects (Evaluator address value effects address) where
|
||||||
|
lambda' vars body = function vars lowerBound body
|
||||||
|
{-# INLINE lambda' #-}
|
||||||
|
|
||||||
builtInPrint :: ( AbstractValue address value effects
|
builtInPrint :: ( AbstractValue address value effects
|
||||||
, HasCallStack
|
, HasCallStack
|
||||||
|
@ -169,7 +169,7 @@ instance HasPrelude 'Ruby where
|
|||||||
define (name "puts") builtInPrint
|
define (name "puts") builtInPrint
|
||||||
|
|
||||||
defineClass (name "Object") [] $ do
|
defineClass (name "Object") [] $ do
|
||||||
define (name "inspect") (lambda (const (box (string "<object>"))))
|
define (name "inspect") (lambda (box (string "<object>")))
|
||||||
|
|
||||||
instance HasPrelude 'TypeScript where
|
instance HasPrelude 'TypeScript where
|
||||||
definePrelude _ =
|
definePrelude _ =
|
||||||
|
@ -256,9 +256,7 @@ instance Show1 TypeAlias where liftShowsPrec = genericLiftShowsPrec
|
|||||||
instance Evaluatable TypeAlias where
|
instance Evaluatable TypeAlias where
|
||||||
eval TypeAlias{..} = do
|
eval TypeAlias{..} = do
|
||||||
name <- maybeM (throwEvalError NoNameError) (declaredName (subterm typeAliasIdentifier))
|
name <- maybeM (throwEvalError NoNameError) (declaredName (subterm typeAliasIdentifier))
|
||||||
v <- subtermValue typeAliasKind
|
addr <- subtermAddress typeAliasKind
|
||||||
addr <- lookupOrAlloc name
|
|
||||||
assign addr v
|
|
||||||
bind name addr
|
bind name addr
|
||||||
pure (Rval addr)
|
pure (Rval addr)
|
||||||
|
|
||||||
|
@ -118,13 +118,11 @@ instance Show1 Assignment where liftShowsPrec = genericLiftShowsPrec
|
|||||||
instance Evaluatable Assignment where
|
instance Evaluatable Assignment where
|
||||||
eval Assignment{..} = do
|
eval Assignment{..} = do
|
||||||
lhs <- subtermRef assignmentTarget
|
lhs <- subtermRef assignmentTarget
|
||||||
rhs <- subtermValue assignmentValue
|
rhs <- subtermAddress assignmentValue
|
||||||
|
|
||||||
case lhs of
|
case lhs of
|
||||||
LvalLocal nam -> do
|
LvalLocal nam -> do
|
||||||
addr <- lookupOrAlloc nam
|
bind nam rhs
|
||||||
assign addr rhs
|
|
||||||
bind nam addr
|
|
||||||
LvalMember _ _ ->
|
LvalMember _ _ ->
|
||||||
-- we don't yet support mutable object properties:
|
-- we don't yet support mutable object properties:
|
||||||
pure ()
|
pure ()
|
||||||
@ -132,7 +130,7 @@ instance Evaluatable Assignment where
|
|||||||
-- the left hand side of the assignment expression is invalid:
|
-- the left hand side of the assignment expression is invalid:
|
||||||
pure ()
|
pure ()
|
||||||
|
|
||||||
rvalBox rhs
|
pure (Rval rhs)
|
||||||
|
|
||||||
-- | Post increment operator (e.g. 1++ in Go, or i++ in C).
|
-- | Post increment operator (e.g. 1++ in Go, or i++ in C).
|
||||||
newtype PostIncrement a = PostIncrement a
|
newtype PostIncrement a = PostIncrement a
|
||||||
|
@ -110,9 +110,7 @@ instance Evaluatable DefaultExport where
|
|||||||
eval (DefaultExport term) = do
|
eval (DefaultExport term) = do
|
||||||
case declaredName term of
|
case declaredName term of
|
||||||
Just name -> do
|
Just name -> do
|
||||||
addr <- lookupOrAlloc name
|
addr <- subtermAddress term
|
||||||
v <- subtermValue term
|
|
||||||
assign addr v
|
|
||||||
export name name Nothing
|
export name name Nothing
|
||||||
bind name addr
|
bind name addr
|
||||||
Nothing -> throwEvalError DefaultExportError
|
Nothing -> throwEvalError DefaultExportError
|
||||||
|
Loading…
Reference in New Issue
Block a user