Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
rsoeldner committed Sep 12, 2023
1 parent 8802ac6 commit a3deb2a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 82 deletions.
7 changes: 3 additions & 4 deletions pact-core/Pact/Core/IR/Desugar.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ module Pact.Core.IR.Desugar
, DesugarBuiltin(..)
) where

import Debug.Trace
import Control.Monad ( when, forM, (>=>))
import Control.Monad.Reader
import Control.Monad.State.Strict
Expand Down Expand Up @@ -652,7 +651,7 @@ resolveModuleName
resolveModuleName mn i =
use (rsLoaded . loModules . at mn) >>= \case
Just md -> pure md
Nothing -> trace "@@@@@@" $
Nothing ->
view rePactDb >>= liftIO . (`readModule` mn) >>= \case
Nothing -> throwDesugarError (NoSuchModule mn) i
Just md -> case md of
Expand Down Expand Up @@ -776,7 +775,7 @@ lookupModuleMember modName name i = do
loadInterface iface deps dconstDeps dcDeps
pure (Name name nk, dk)
Nothing -> throwDesugarError (NoSuchModuleMember modName name) i
Nothing -> trace "!!!!!!!" $ throwDesugarError (NoSuchModule modName) i
Nothing -> throwDesugarError (NoSuchModule modName) i
where
toDepMap mhash def = (defName def, (NTopLevel modName mhash, defKind def))

Expand Down Expand Up @@ -1089,7 +1088,7 @@ resolveBare (BareName bn) i = views reBinds (M.lookup bn) >>= \case
(nk, dk) -> pure (Name bn nk, dk)
Nothing -> uses (rsLoaded . loToplevel) (M.lookup bn) >>= \case
Just (fqn, dk) -> pure (Name bn (NTopLevel (_fqModule fqn) (_fqHash fqn)), Just dk)
Nothing -> trace (show bn) $ do
Nothing -> do
let mn = ModuleName bn Nothing
resolveModuleName mn i >>= \case
ModuleData md _ -> do
Expand Down
117 changes: 39 additions & 78 deletions pact-core/Pact/Core/IR/Term.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,46 +38,6 @@ import Pact.Core.Imports
import Pact.Core.Capabilities
import Pact.Core.Pretty

data LamInfo
= TLDefun ModuleName Text
| TLDefCap ModuleName Text
| TLDefPact ModuleName Text
| AnonLamInfo
deriving Show

-- | Core IR
data Term name ty builtin info
= Var name info
-- ^ single variables e.g x
| Lam LamInfo (NonEmpty (Arg ty)) (Term name ty builtin info) info
-- ^ $f = \x.e
-- Lambdas are named for the sake of the callstack.
| Let (Arg ty) (Term name ty builtin info) (Term name ty builtin info) info
-- ^ let x = e1 in e2
| App (Term name ty builtin info) (NonEmpty (Term name ty builtin info)) info
-- ^ (e1 e2)
| Sequence (Term name ty builtin info) (Term name ty builtin info) info
-- ^ error term , error "blah"
| Conditional (BuiltinForm (Term name ty builtin info)) info
-- ^ Conditional terms
| Builtin builtin info
-- ^ Built-in ops, e.g (+)
| Constant Literal info
-- ^ Literals
| ListLit [Term name ty builtin info] info
-- ^ List Literals
| Try (Term name ty builtin info) (Term name ty builtin info) info
-- ^ try (catch expr) (try-expr)
| CapabilityForm (CapForm name (Term name ty builtin info)) info
-- ^ Capability Natives
| ObjectLit [(Field, Term name ty builtin info)] info
-- ^ an object literal
| DynInvoke (Term name ty builtin info) Text info
-- ^ dynamic module reference invocation m::f
| Error Text info
-- ^ Error term
deriving (Show, Functor)

data Defun name ty builtin info
= Defun
{ _dfunName :: Text
Expand Down Expand Up @@ -278,44 +238,45 @@ type EvalDef b i = Def Name Type b i
type EvalModule b i = Module Name Type b i
type EvalInterface b i = Interface Name Type b i

-- data LamInfo
-- = TLDefun ModuleName Text
-- | TLDefCap ModuleName Text
-- | AnonLamInfo
-- deriving Show

-- -- | Core IR
-- data Term name ty builtin info
-- = Var name info
-- -- ^ single variables e.g x
-- | Lam LamInfo (NonEmpty (Arg ty)) (Term name ty builtin info) info
-- -- ^ $f = \x.e
-- -- Lambdas are named for the sake of the callstack.
-- | Let (Arg ty) (Term name ty builtin info) (Term name ty builtin info) info
-- -- ^ let x = e1 in e2
-- | App (Term name ty builtin info) (NonEmpty (Term name ty builtin info)) info
-- -- ^ (e1 e2)
-- | Sequence (Term name ty builtin info) (Term name ty builtin info) info
-- -- ^ error term , error "blah"
-- | Conditional (BuiltinForm (Term name ty builtin info)) info
-- -- ^ Conditional terms
-- | Builtin builtin info
-- -- ^ Built-in ops, e.g (+)
-- | Constant Literal info
-- -- ^ Literals
-- | ListLit [Term name ty builtin info] info
-- -- ^ List Literals
-- | Try (Term name ty builtin info) (Term name ty builtin info) info
-- -- ^ try (catch expr) (try-expr)
-- | CapabilityForm (CapForm name (Term name ty builtin info)) info
-- -- ^ Capability Natives
-- | ObjectLit [(Field, Term name ty builtin info)] info
-- -- ^ an object literal
-- | DynInvoke (Term name ty builtin info) Text info
-- -- ^ dynamic module reference invocation m::f
-- | Error Text info
-- -- ^ Error term
-- deriving (Show, Functor)
data LamInfo
= TLDefun ModuleName Text
| TLDefCap ModuleName Text
| TLDefPact ModuleName Text
| AnonLamInfo
deriving Show

-- | Core IR
data Term name ty builtin info
= Var name info
-- ^ single variables e.g x
| Lam LamInfo (NonEmpty (Arg ty)) (Term name ty builtin info) info
-- ^ $f = \x.e
-- Lambdas are named for the sake of the callstack.
| Let (Arg ty) (Term name ty builtin info) (Term name ty builtin info) info
-- ^ let x = e1 in e2
| App (Term name ty builtin info) (NonEmpty (Term name ty builtin info)) info
-- ^ (e1 e2)
| Sequence (Term name ty builtin info) (Term name ty builtin info) info
-- ^ error term , error "blah"
| Conditional (BuiltinForm (Term name ty builtin info)) info
-- ^ Conditional terms
| Builtin builtin info
-- ^ Built-in ops, e.g (+)
| Constant Literal info
-- ^ Literals
| ListLit [Term name ty builtin info] info
-- ^ List Literals
| Try (Term name ty builtin info) (Term name ty builtin info) info
-- ^ try (catch expr) (try-expr)
| CapabilityForm (CapForm name (Term name ty builtin info)) info
-- ^ Capability Natives
| ObjectLit [(Field, Term name ty builtin info)] info
-- ^ an object literal
| DynInvoke (Term name ty builtin info) Text info
-- ^ dynamic module reference invocation m::f
| Error Text info
-- ^ Error term
deriving (Show, Functor)

instance (Pretty name, Pretty builtin, Pretty ty) => Pretty (Term name ty builtin info) where
pretty = \case
Expand Down

0 comments on commit a3deb2a

Please sign in to comment.