| Copyright | (c) Kimiyuki Onaka 2020 |
|---|---|
| License | Apache License 2.0 |
| Maintainer | kimiyuki95@gmail.com |
| Stability | experimental |
| Portability | portable |
| Safe Haskell | None |
| Language | Haskell2010 |
Jikka.RestrictedPython.Language.Expr
Contents
Description
Synopsis
- newtype TypeName = TypeName String
- unTypeName :: TypeName -> String
- data Type
- pattern NoneTy :: Type
- data UnaryOp
- data Operator
- data BoolOp
- data CmpOp
- data CmpOp' = CmpOp' CmpOp Type
- data Constant
- data Builtin
- = BuiltinAbs
- | BuiltinPow
- | BuiltinModPow
- | BuiltinDivMod
- | BuiltinCeilDiv
- | BuiltinCeilMod
- | BuiltinFloorDiv
- | BuiltinFloorMod
- | BuiltinGcd
- | BuiltinLcm
- | BuiltinInt Type
- | BuiltinBool Type
- | BuiltinList Type
- | BuiltinTuple [Type]
- | BuiltinLen Type
- | BuiltinMap [Type] Type
- | BuiltinSorted Type
- | BuiltinReversed Type
- | BuiltinEnumerate Type
- | BuiltinFilter Type
- | BuiltinZip [Type]
- | BuiltinAll
- | BuiltinAny
- | BuiltinSum
- | BuiltinProduct
- | BuiltinRange1
- | BuiltinRange2
- | BuiltinRange3
- | BuiltinMax1 Type
- | BuiltinMax Type Int
- | BuiltinMin1 Type
- | BuiltinMin Type Int
- | BuiltinArgMax Type
- | BuiltinArgMin Type
- | BuiltinFact
- | BuiltinChoose
- | BuiltinPermute
- | BuiltinMultiChoose
- | BuiltinModInv
- | BuiltinInput
- | BuiltinPrint [Type]
- newtype AttributeName = AttributeName String
- unAttributeName :: AttributeName -> String
- data Attribute
- type Attribute' = WithLoc' Attribute
- newtype VarName = VarName String
- unVarName :: VarName -> String
- module Jikka.Common.Location
- type VarName' = WithLoc' VarName
- data Expr
- = BoolOp Expr' BoolOp Expr'
- | BinOp Expr' Operator Expr'
- | UnaryOp UnaryOp Expr'
- | Lambda [(VarName', Type)] Expr'
- | IfExp Expr' Expr' Expr'
- | ListComp Expr' Comprehension
- | Compare Expr' CmpOp' Expr'
- | Call Expr' [Expr']
- | Constant Constant
- | Attribute Expr' Attribute'
- | Subscript Expr' Expr'
- | Starred Expr'
- | Name VarName'
- | List Type [Expr']
- | Tuple [Expr']
- | SubscriptSlice Expr' (Maybe Expr') (Maybe Expr') (Maybe Expr')
- type Expr' = WithLoc' Expr
- data Comprehension = Comprehension Target' Expr' (Maybe Expr')
- data Target
- type Target' = WithLoc' Target
- data Statement
- pattern Append :: Maybe Loc -> Type -> Expr' -> Expr' -> Statement
- data ToplevelStatement
- type Program = [ToplevelStatement]
types
unTypeName :: TypeName -> String Source #
Type represents the types of our restricted Python-like language.
\[ \newcommand\int{\mathbf{int}} \newcommand\bool{\mathbf{bool}} \newcommand\list{\mathbf{list}} \newcommand\string{\mathbf{string}} \begin{array}{rl} \tau ::= & \alpha \\ \vert & \int \\ \vert & \bool \\ \vert & \list(\tau) \\ \vert & \tau \times \tau \times \dots \times \tau \\ \vert & \tau \times \tau \times \dots \times \tau \to \tau \vert & \string \vert & \mathbf{side-effect} \end{array} \]
NOTE: \(\mathbf{None}\) is represented as the 0-tuple.
Constructors
| VarTy TypeName | |
| IntTy | |
| BoolTy | |
| ListTy Type | |
| TupleTy [Type] | |
| CallableTy [Type] Type | |
| StringTy | |
| SideEffectTy |
operators
Constructors
| Add | |
| Sub | |
| Mult | |
| MatMult | |
| Div | |
| FloorDiv | |
| FloorMod | |
| CeilDiv | our extension |
| CeilMod | our extension |
| Pow | |
| BitLShift | |
| BitRShift | |
| BitOr | |
| BitXor | |
| BitAnd | |
| Max | our extension |
| Min | our extension |
CmpOp` is a type for comparision operators.
This is annotated with its type as let-polymorphism.
Constructors
| BuiltinAbs | "abs" \(: \int \to \int\) |
| BuiltinPow | "pow" \((\lambda x k. x^k) : \int \times \int \to \int\) |
| BuiltinModPow | modulo power "pow" \((\lambda x k m. x^k \bmod m): \int \times \int \to \int\) |
| BuiltinDivMod | "divmod" \(: \int \times \int \to \int \times \int\) |
| BuiltinCeilDiv | ceil div \(: \int \times \int \to \int\) |
| BuiltinCeilMod | ceil mod \(: \int \times \int \to \int\) |
| BuiltinFloorDiv | floor div \(: \int \times \int \to \int\) |
| BuiltinFloorMod | floor mod \(: \int \times \int \to \int\) |
| BuiltinGcd | \(\gcd: \int \times \int \to \int\) |
| BuiltinLcm | \(\mathbf{lcm}: \int \times \int \to \int\) |
| BuiltinInt Type | "int" \(: \forall \alpha. \alpha \to \int\) |
| BuiltinBool Type | "bool" \(: \forall \alpha. \alpha \to \bool\) |
| BuiltinList Type | "list" \(: \forall \alpha. \list(\alpha) \to \list(\alpha)\) |
| BuiltinTuple [Type] | "tuple" \(: \forall \alpha_0 \alpha_1 \dots \alpha _ {n - 1}. \tau \to \tau\) where \(\tau = \alpha_0 \times \dots \times \alpha _ {n - 1}\) |
| BuiltinLen Type | "len" \(: \forall \alpha. \list(\alpha) \to \int\) |
| BuiltinMap [Type] Type | "map" \(: \forall \alpha_0 \alpha_1 \dots \alpha_n. (\alpha_0 \times \dots \times \alpha _ {n - 1} \to \alpha_n) \times \list(\alpha_0) \times \dots \list(\alpha _ {n - 1}) \to \list(\alpha_n)\) |
| BuiltinSorted Type | "sorted" \(: \forall \alpha. \list(\alpha) \to \list(\alpha)\) |
| BuiltinReversed Type | "reversed" \(: \forall \alpha. \list(\alpha) \to \list(\alpha)\) |
| BuiltinEnumerate Type | "enumerate" \(: \forall \alpha. \list(\alpha) \to \list(\int \times \alpha)\) |
| BuiltinFilter Type | "filter" \(: \forall \alpha. (\alpha \to \bool) \times \list(\alpha) \to \list(\alpha)\) |
| BuiltinZip [Type] | "zip" \(: \forall \alpha_0 \alpha_1 \dots \alpha _ {n - 1}. \list(\alpha_0) \times \dots \list(\alpha _ {n - 1}) \to \list(\alpha_0 \times \dots \times \alpha _ {n - 1})\) |
| BuiltinAll | "all" \(: \list(\bool) \to \bool\) |
| BuiltinAny | "any" \(: \list(\bool) \to \bool\) |
| BuiltinSum | "sum" \(: \list(\int) \to \int\) |
| BuiltinProduct | product \(: \list(\int) \to \int\) |
| BuiltinRange1 | "range" \(: \int \to \list(\int)\) |
| BuiltinRange2 | "range" \(: \int \times \int \to \list(\int)\) |
| BuiltinRange3 | "range" \(: \int \times \int \times \int \to \list(\int)\) |
| BuiltinMax1 Type | "max" \(: \forall \alpha. \list(\alpha) \to \alpha\) |
| BuiltinMax Type Int | "max" \(: \forall \alpha. \underbrace{\alpha \times \alpha \times \dots \times \alpha} _ {n ~\text{times}} \to \alpha\) |
| BuiltinMin1 Type | "min" \(: \forall \alpha. \list(\alpha) \to \alpha\) |
| BuiltinMin Type Int | "min" \(: \forall \alpha. \underbrace{\alpha \times \alpha \times \dots \times \alpha} _ {n ~\text{times}} \to \alpha\) |
| BuiltinArgMax Type | \(: \forall \alpha. \list(\alpha) \to \int\) |
| BuiltinArgMin Type | \(: \forall \alpha. \list(\alpha) \to \int\) |
| BuiltinFact | factorial \((\lambda n. n!): \int \to \int\) |
| BuiltinChoose | \((\lambda n r. {} _ n C _ r): \int \times \int \to \int\) |
| BuiltinPermute | \((\lambda n r. {} _ n P _ r): \int \times \int \to \int\) |
| BuiltinMultiChoose | \((\lambda n r. {} _ n H _ r): \int \times \int \to \int\) |
| BuiltinModInv | modulo inverse \((\lambda x m. x^{-1} \bmod m): \int \times \int \to \int\) |
| BuiltinInput | "input" \(: \epsilon \to \string\) |
| BuiltinPrint [Type] | "print" \(: \forall \alpha_0 \alpha_1 \dots \alpha _ {n - 1}. \alpha_0 \times \dots \alpha _ {n - 1} \to \epsilon\) |
newtype AttributeName Source #
Constructors
| AttributeName String |
Instances
Constructors
| UnresolvedAttribute AttributeName | |
| BuiltinCount Type | "list.count" \(: \forall \alpha. \list(\alpha) \to \alpha \to \int\) |
| BuiltinIndex Type | "list.index" \(: \forall \alpha. \list(\alpha) \to \alpha \to \int\) |
| BuiltinCopy Type | "list.copy" \(: \forall \alpha. \list(\alpha) \to \epsilon \to \list(\alpha)\) |
| BuiltinAppend Type | "list.append" \(: \forall \alpha. \list(\alpha) \to \alpha \to \mathbf{side-effect}\) |
| BuiltinSplit | "str.split" \(: \forall \alpha. \string \to \epsilon \to \list(\string)\) |
Instances
| Eq Attribute Source # | |
| Ord Attribute Source # | |
Defined in Jikka.RestrictedPython.Language.Expr | |
| Read Attribute Source # | |
| Show Attribute Source # | |
type Attribute' = WithLoc' Attribute Source #
exprs
module Jikka.Common.Location
Expr represents the exprs of our restricted Python-like language.
\[ \begin{array}{rl} e ::= & e \operatorname{boolop} e \\ \vert & e \operatorname{binop} e \\ \vert & \operatorname{unaryop} e \\ \vert & \lambda x _ \tau x _ \tau \dots x _ \tau. e \\ \vert & \mathbf{if}~ e ~\mathbf{then}~ e ~\mathbf{else}~ e \\ \vert & \lbrack e ~\mathbf{for}~ y ~\mathbf{in}~ e ~(\mathbf{if}~ e)? \rbrack \\ \vert & e \operatorname{cmpop} e \\ \vert & e (e, e, \dots, e) \\ \vert & \operatorname{constant} \\ \vert & e \lbrack e \rbrack \\ \vert & x \\ \vert & \lbrack e, e, \dots, e \rbrack _ \tau \\ \vert & e \lbrack e? \colon e? \colon e? \rbrack \\ \end{array} \]
Constructors
data Comprehension Source #
Constructors
| Comprehension Target' Expr' (Maybe Expr') |
Instances
| Eq Comprehension Source # | |
Defined in Jikka.RestrictedPython.Language.Expr Methods (==) :: Comprehension -> Comprehension -> Bool # (/=) :: Comprehension -> Comprehension -> Bool # | |
| Ord Comprehension Source # | |
Defined in Jikka.RestrictedPython.Language.Expr Methods compare :: Comprehension -> Comprehension -> Ordering # (<) :: Comprehension -> Comprehension -> Bool # (<=) :: Comprehension -> Comprehension -> Bool # (>) :: Comprehension -> Comprehension -> Bool # (>=) :: Comprehension -> Comprehension -> Bool # max :: Comprehension -> Comprehension -> Comprehension # min :: Comprehension -> Comprehension -> Comprehension # | |
| Read Comprehension Source # | |
Defined in Jikka.RestrictedPython.Language.Expr Methods readsPrec :: Int -> ReadS Comprehension # readList :: ReadS [Comprehension] # | |
| Show Comprehension Source # | |
Defined in Jikka.RestrictedPython.Language.Expr Methods showsPrec :: Int -> Comprehension -> ShowS # show :: Comprehension -> String # showList :: [Comprehension] -> ShowS # | |
statements
Target represents the lvalue of our restricted Python-like language.
\[ \begin{array}{rl} y ::= & y \lbrack e \rbrack \\ \vert & x \\ \vert & (y, y, \dots, y) \\ \end{array} \]
Statement represents the statements of our restricted Python-like language.
They appear in bodies of def.
\[ \begin{array}{rl} \mathrm{stmt} ::= & \mathbf{return}~ e \\ \vert & y \operatorname{binop} = e \\ \vert & y _ \tau := e \\ \vert & \mathbf{for}~ y ~\mathbf{in}~ e \colon\quad \mathrm{stmt}; \mathrm{stmt}; \dots; \mathrm{stmt} \\ \vert & \mathbf{if}~ e \colon\quad \mathrm{stmt}; \mathrm{stmt}; \dots; \mathrm{stmt};\quad \mathbf{else}\colon\quad \mathrm{stmt}; \mathrm{stmt}; \dots; \mathrm{stmt} \\ \vert & \mathbf{assert}~ e \\ \end{array} \]
Constructors
| Return Expr' | |
| AugAssign Target' Operator Expr' | |
| AnnAssign Target' Type Expr' | |
| For Target' Expr' [Statement] | |
| If Expr' [Statement] [Statement] | |
| Assert Expr' | |
| Expr' Expr' | expression statements |
Instances
| Eq Statement Source # | |
| Ord Statement Source # | |
Defined in Jikka.RestrictedPython.Language.Expr | |
| Read Statement Source # | |
| Show Statement Source # | |
data ToplevelStatement Source #
TopLevelStatement represents the statements of our restricted Python-like language.
They appear in the toplevel of programs.
\[ \begin{array}{rl} \mathrm{tlstmt} ::= & x _ \tau := e \\ \vert & \mathbf{def}~ x (x _ \tau, x _ \tau, \dots, x _ \tau) \to \tau \colon\quad \mathrm{stmt}; \mathrm{stmt}; \dots; \mathrm{stmt} \\ \vert & \mathbf{assert}~ e \\ \end{array} \]
Constructors
| ToplevelAnnAssign VarName' Type Expr' | |
| ToplevelFunctionDef VarName' [(VarName', Type)] Type [Statement] | |
| ToplevelAssert Expr' |
Instances
type Program = [ToplevelStatement] Source #
Program represents the programs of our restricted Python-like language.
\[ \begin{array}{rl} \mathrm{prog} ::= & \mathrm{tlstmt}; \mathrm{tlstmt}; \dots; \mathrm{tlstmt} \\ \end{array} \]