git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
592 files changed+2705−42404
since splitsnapshots
unifiedsplit
.gitignore+4 .gitmodules−3 .travis.yml−73 CONTRIBUTING.md−44 CONTRIBUTORS.md−76 ChangeLog.md+3 INSTALL.md−53 LICENSE+24−2163 README-go.md+48 README.md+32−20 Setup.hs−4 app/Main.hs+250 appveyor.yml−57 bundle/.gitignore−4 bundle/README−24 bundle/build-stack.sh−63 core-tests/.gitignore−2 core-tests/test-everything.sh−79 core-tests/tests/generic-deriving/Main.purs−27 default.nix+23 examples/.gitignore−1 examples/docs/LICENSE−1 examples/docs/bower.json−20 examples/docs/bower_components/purescript-prelude/src/Prelude.purs−8 examples/docs/src/Clash.purs−32 examples/docs/src/ConstrainedArgument.purs−9 examples/docs/src/DuplicateNames.purs−9 examples/docs/src/Example.purs−7 examples/docs/src/Example2.purs−7 examples/docs/src/ExplicitTypeSignatures.purs−16 examples/docs/src/ImportedTwice.purs−27 examples/docs/src/MultiVirtual.purs−27 examples/docs/src/NewOperators.purs−12 examples/docs/src/NotAllCtors.purs−5 examples/docs/src/OldOperators.purs−10 examples/docs/src/ReExportedTypeClass.purs−5 examples/docs/src/SolitaryTypeClassMember.purs−6 examples/docs/src/SomeTypeClass.purs−5 examples/docs/src/Transitive1.purs−5 examples/docs/src/Transitive2.purs−5 examples/docs/src/Transitive3.purs−4 examples/docs/src/TypeClassWithoutMembers.purs−11 examples/docs/src/UTF8.purs−7 examples/docs/src/Virtual.purs−5 examples/failing/1071.purs−8 examples/failing/1169.purs−12 examples/failing/1175.purs−11 examples/failing/1310.purs−18 examples/failing/1570.purs−6 examples/failing/1733.purs−13 examples/failing/1825.purs−9 examples/failing/365.purs−14 examples/failing/438.purs−15 examples/failing/881.purs−13 examples/failing/AnonArgument1.purs−5 examples/failing/AnonArgument2.purs−7 examples/failing/AnonArgument3.purs−5 examples/failing/ArrayType.purs−14 examples/failing/Arrays.purs−8 examples/failing/CaseBinderLengthsDiffer.purs−6 examples/failing/CaseDoesNotMatchAllConstructorArgs.purs−15 examples/failing/ConflictingExports.purs−16 examples/failing/ConflictingImports.purs−19 examples/failing/ConflictingImports2.purs−20 examples/failing/ConflictingQualifiedImports.purs−17 examples/failing/ConflictingQualifiedImports2.purs−15 examples/failing/ConstraintInference.purs−10 examples/failing/DctorOperatorAliasExport.purs−6 examples/failing/Do.purs−12 examples/failing/DoNotSuggestComposition.purs−13 examples/failing/DoNotSuggestComposition2.purs−7 examples/failing/DuplicateDeclarationsInLet.purs−12 examples/failing/DuplicateProperties1.purs−12 examples/failing/DuplicateProperties2.purs−12 examples/failing/DuplicateTypeVars.purs−6 examples/failing/Eff.purs−13 examples/failing/EmptyCase.purs−4 examples/failing/EmptyClass.purs−7 examples/failing/EmptyDo.purs−6 examples/failing/ExtraRecordField.purs−9 examples/failing/Foldable.purs−17 examples/failing/Generalization1.purs−11 examples/failing/Generalization2.purs−8 examples/failing/ImportHidingModule.purs−10 examples/failing/InfiniteKind.purs−5 examples/failing/InfiniteType.purs−5 examples/failing/InstanceExport.purs−19 examples/failing/IntOutOfRange.purs−6 examples/failing/InvalidOperatorInBinder.purs−12 examples/failing/KindError.purs−6 examples/failing/KindStar.purs−8 examples/failing/LeadingZeros1.purs−6 examples/failing/LeadingZeros2.purs−6 examples/failing/Let.purs−6 examples/failing/MPTCs.purs−10 examples/failing/MissingClassExport.purs−7 examples/failing/MissingClassMemberExport.purs−7 examples/failing/MissingRecordField.purs−10 examples/failing/MultipleErrors.purs−13 examples/failing/MultipleErrors2.purs−9 examples/failing/MutRec.purs−9 examples/failing/MutRec2.purs−6 examples/failing/NewtypeMultiArgs.purs−6 examples/failing/NewtypeMultiCtor.purs−6 examples/failing/NullaryAbs.purs−6 examples/failing/Object.purs−8 examples/failing/OperatorAliasNoExport.purs−7 examples/failing/OperatorSections.purs−8 examples/failing/OrphanInstance.purs−12 examples/failing/OverlappingArguments.purs−6 examples/failing/OverlappingBinders.purs−9 examples/failing/OverlappingReExport.purs−10 examples/failing/OverlappingVars.purs−15 examples/failing/Rank2Types.purs−8 examples/failing/Reserved.purs−7 examples/failing/RowConstructors1.purs−9 examples/failing/RowConstructors2.purs−9 examples/failing/RowConstructors3.purs−9 examples/failing/SkolemEscape.purs−8 examples/failing/SkolemEscape2.purs−10 examples/failing/SuggestComposition.purs−7 examples/failing/Superclasses1.purs−14 examples/failing/Superclasses2.purs−13 examples/failing/Superclasses3.purs−8 examples/failing/Superclasses5.purs−25 examples/failing/TopLevelCaseNoArgs.purs−8 examples/failing/TransitiveDctorExport.purs−5 examples/failing/TransitiveSynonymExport.purs−5 examples/failing/TypeClassInstances.purs−11 examples/failing/TypeClasses2.purs−9 examples/failing/TypeError.purs−6 examples/failing/TypeSynonyms.purs−8 examples/failing/TypeSynonyms2.purs−12 examples/failing/TypeSynonyms3.purs−12 examples/failing/TypeSynonyms4.purs−11 examples/failing/TypeSynonyms5.purs−6 examples/failing/TypeWildcards1.purs−7 examples/failing/TypeWildcards2.purs−7 examples/failing/TypeWildcards3.purs−10 examples/failing/TypedBinders.purs−10 examples/failing/TypedBinders2.purs−9 examples/failing/TypedBinders3.purs−12 examples/failing/UnderscoreModuleName.purs−6 examples/failing/UnifyInTypeInstanceLookup.purs−22 examples/failing/UnknownType.purs−7 examples/manual/QualifiedNames.purs−13 examples/manual/failing/ArgLengthMismatch.purs−6 examples/manual/failing/ExportExplicit.purs−7 examples/manual/failing/ExportExplicit1.purs−14 examples/manual/failing/ExportExplicit2.purs−7 examples/manual/failing/ExportExplicit3.purs−13 examples/manual/failing/ImportExplicit.purs−7 examples/manual/failing/ImportExplicit2.purs−7 examples/manual/failing/ImportModule.purs−7 examples/manual/failing/OrphanTypeDecl.purs−3 examples/manual/failing/RedefinedFixity.purs−8 examples/manual/failing/RequiredHiddenType.purs−8 examples/manual/passing/ExportExplicit.purs−20 examples/manual/passing/ExportExplicit2.purs−15 examples/manual/passing/ExportedInstanceDeclarations.purs−43 examples/manual/passing/Import.purs−19 examples/manual/passing/ImportExplicit.purs−14 examples/manual/passing/ImportQualified.purs−12 examples/manual/passing/Module.purs−28 examples/manual/passing/ModuleDeps.purs−17 examples/manual/passing/RedefinedFixity.purs−24 examples/manual/passing/ShadowedName.purs−10 examples/manual/passing/TransitiveImport.purs−24 examples/manual/passing/WildcardType.purs−13 examples/passing/1185.purs−13 examples/passing/1335.purs−12 examples/passing/1570.purs−6 examples/passing/1664.purs−16 examples/passing/1697.purs−24 examples/passing/1991.purs−20 examples/passing/2018.purs−25 examples/passing/652.purs−17 examples/passing/810.purs−13 examples/passing/862.purs−8 examples/passing/922.purs−20 examples/passing/Applicative.purs−16 examples/passing/ArrayType.purs−11 examples/passing/Auto.purs−15 examples/passing/AutoPrelude.purs−9 examples/passing/AutoPrelude2.purs−10 examples/passing/BindersInFunctions.purs−11 examples/passing/BindingGroups.purs−10 examples/passing/BlockString.purs−8 examples/passing/CaseInDo.purs−19 examples/passing/CaseInputWildcard.purs−18 examples/passing/CaseMultipleExpressions.purs−19 examples/passing/CaseStatement.purs−21 examples/passing/CheckFunction.purs−7 examples/passing/CheckSynonymBug.purs−12 examples/passing/CheckTypeClass.purs−18 examples/passing/Church.purs−18 examples/passing/ClassRefSyntax.purs−13 examples/passing/Collatz.purs−18 examples/passing/Comparisons.purs−15 examples/passing/Conditional.purs−9 examples/passing/Console.purs−13 examples/passing/ConstraintInference.purs−7 examples/passing/ContextSimplification.purs−13 examples/passing/DataAndType.purs−9 examples/passing/DctorOperatorAlias.purs−40 examples/passing/DeepArrayBinder.purs−16 examples/passing/DeepCase.purs−15 examples/passing/Deriving.purs−31 examples/passing/Do.purs−67 examples/passing/Dollar.purs−16 examples/passing/Eff.purs−25 examples/passing/EmptyDataDecls.purs−19 examples/passing/EmptyRow.purs−10 examples/passing/EmptyTypeClass.purs−12 examples/passing/EqOrd.purs−15 examples/passing/ExplicitImportReExport.purs−16 examples/passing/ExplicitOperatorSections.purs−14 examples/passing/ExtendedInfixOperators.purs−14 examples/passing/Fib.purs−15 examples/passing/FieldConsPuns.purs−10 examples/passing/FieldPuns.purs−8 examples/passing/FinalTagless.purs−22 examples/passing/FunctionScope.purs−12 examples/passing/Functions.purs−15 examples/passing/Functions2.purs−12 examples/passing/Generalization1.purs−10 examples/passing/Guards.purs−29 examples/passing/HoistError.purs−12 examples/passing/IfThenElseMaybe.purs−11 examples/passing/IfWildcard.purs−19 examples/passing/ImplicitEmptyImport.purs−8 examples/passing/ImportHiding.purs−18 examples/passing/InferRecFunWithConstrainedArgument.purs−8 examples/passing/InstanceBeforeClass.purs−11 examples/passing/IntAndChar.purs−18 examples/passing/JSReserved.purs−12 examples/passing/KindedType.purs−33 examples/passing/LargeSumType.purs−33 examples/passing/Let.purs−53 examples/passing/Let2.purs−17 examples/passing/LetInInstance.purs−14 examples/passing/LiberalTypeSynonyms.purs−21 examples/passing/MPTCs.purs−20 examples/passing/Match.purs−9 examples/passing/ModuleExport.purs−9 examples/passing/ModuleExportDupes.purs−19 examples/passing/ModuleExportExcluded.purs−14 examples/passing/ModuleExportQualified.purs−9 examples/passing/ModuleExportSelf.purs−14 examples/passing/Monad.purs−32 examples/passing/MonadState.purs−61 examples/passing/MultiArgFunctions.purs−27 examples/passing/MutRec.purs−19 examples/passing/MutRec2.purs−19 examples/passing/MutRec3.purs−19 examples/passing/NakedConstraint.purs−10 examples/passing/NamedPatterns.purs−9 examples/passing/NegativeBinder.purs−9 examples/passing/NegativeIntInRange.purs−8 examples/passing/Nested.purs−9 examples/passing/NestedTypeSynonyms.purs−11 examples/passing/NestedWhere.purs−12 examples/passing/Newtype.purs−23 examples/passing/NewtypeEff.purs−29 examples/passing/NewtypeWithRecordUpdate.purs−16 examples/passing/NonConflictingExports.purs−14 examples/passing/ObjectGetter.purs−13 examples/passing/ObjectSynonym.purs−15 examples/passing/ObjectUpdate.purs−20 examples/passing/ObjectUpdate2.purs−17 examples/passing/ObjectUpdater.purs−24 examples/passing/ObjectWildcards.purs−20 examples/passing/Objects.purs−35 examples/passing/OneConstructor.purs−9 examples/passing/OperatorAlias.purs−11 examples/passing/OperatorAliasElsewhere.purs−14 examples/passing/OperatorAssociativity.purs−25 examples/passing/OperatorInlining.purs−47 examples/passing/OperatorSections.purs−17 examples/passing/Operators.purs−99 examples/passing/OptimizerBug.purs−9 examples/passing/OptionalQualified.purs−13 examples/passing/OverlappingInstances.purs−13 examples/passing/OverlappingInstances2.purs−23 examples/passing/OverlappingInstances3.purs−16 examples/passing/PartialFunction.purs−10 examples/passing/Patterns.purs−22 examples/passing/PendingConflictingImports.purs−17 examples/passing/PendingConflictingImports2.purs−14 examples/passing/Person.purs−11 examples/passing/QualifiedQualifiedImports.purs−6 examples/passing/Rank2Data.purs−29 examples/passing/Rank2Object.purs−11 examples/passing/Rank2TypeSynonym.purs−16 examples/passing/Rank2Types.purs−11 examples/passing/ReExportQualified.purs−16 examples/passing/RebindableSyntax.purs−39 examples/passing/Recursion.purs−10 examples/passing/ReservedWords.purs−15 examples/passing/ResolvableScopeConflict.purs−25 examples/passing/ResolvableScopeConflict2.purs−22 examples/passing/ResolvableScopeConflict3.purs−15 examples/passing/RowConstructors.purs−42 examples/passing/RowPolyInstanceContext.purs−22 examples/passing/RuntimeScopeIssue.purs−19 examples/passing/ScopedTypeVariables.purs−36 examples/passing/Sequence.purs−15 examples/passing/SequenceDesugared.purs−37 examples/passing/ShadowedModuleName.purs−15 examples/passing/ShadowedRename.purs−14 examples/passing/ShadowedTCO.purs−18 examples/passing/ShadowedTCOLet.purs−9 examples/passing/SignedNumericLiterals.purs−17 examples/passing/StringEscapes.purs−15 examples/passing/Superclasses1.purs−20 examples/passing/Superclasses3.purs−41 examples/passing/TCO.purs−20 examples/passing/TCOCase.purs−12 examples/passing/TailCall.purs−17 examples/passing/Tick.purs−7 examples/passing/TopLevelCase.purs−18 examples/passing/TypeClassMemberOrderChange.purs−13 examples/passing/TypeClasses.purs−69 examples/passing/TypeClassesInOrder.purs−11 examples/passing/TypeClassesWithOverlappingTypeVariables.purs−11 examples/passing/TypeDecl.purs−12 examples/passing/TypeOperators.purs−34 examples/passing/TypeSynonymInData.purs−11 examples/passing/TypeSynonyms.purs−27 examples/passing/TypeWildcards.purs−15 examples/passing/TypeWildcardsRecordExtension.purs−8 examples/passing/TypeWithoutParens.purs−16 examples/passing/TypedBinders.purs−67 examples/passing/TypedWhere.purs−17 examples/passing/UTF8Sourcefile.purs−10 examples/passing/UnderscoreIdent.purs−11 examples/passing/UnicodeIdentifier.purs−5 examples/passing/UnicodeOperators.purs−20 examples/passing/UnicodeType.purs−23 examples/passing/Unit.purs−6 examples/passing/UnknownInTypeClassLookup.purs−14 examples/passing/UntupledConstraints.purs−17 examples/passing/Where.purs−49 examples/passing/iota.purs−9 examples/passing/s.purs−7 hierarchy/Main.hs−115 license-generator/generate.hs−40 license-generator/header.txt−23 logo.png make_release_notes−2 package.yaml+86 pcc/Main.hs−179 pcc/Make.hs−174 pcc/Makefile−63 pcc/Makefile.hs−50 pcc/TestMain.hs−120 pcc/include/purescript.cc−382 pcc/include/purescript.hh−382 psc-bundle/Main.hs−136 psc-bundle/README.md−18 psc-docs/Ctags.hs−13 psc-docs/Etags.hs−13 psc-docs/Main.hs−249 psc-docs/Tags.hs−18 psc-ide-client/Main.hs−56 psc-ide-server/Main.hs−163 psc-ide-server/PROTOCOL.md−525 psc-ide-server/README.md−40 psc-publish/Main.hs−50 psc/Main.hs−201 psci/PSCi.hs−372 psci/PSCi/Completion.hs−226 psci/PSCi/Directive.hs−119 psci/PSCi/IO.hs−68 psci/PSCi/Message.hs−53 psci/PSCi/Module.hs−106 psci/PSCi/Option.hs−57 psci/PSCi/Parser.hs−140 psci/PSCi/Printer.hs−131 psci/PSCi/Types.hs−218 psci/main/Main.hs−6 psgo.cabal+145 purescript.cabal−420 src/CodeGen/IL.hs+321 src/CodeGen/IL/Common.hs+196 src/CodeGen/IL/Optimizer.hs+81 src/CodeGen/IL/Optimizer/Common.hs+18 src/CodeGen/IL/Optimizer/Inliner.hs+435 src/CodeGen/IL/Optimizer/MagicDo.hs+146 src/CodeGen/IL/Optimizer/TCO.hs+141 src/CodeGen/IL/Printer.hs+527 src/Control/Monad/Logger.hs−72 src/Control/Monad/Supply.hs−45 src/Control/Monad/Supply/Class.hs−24 src/Language/PureScript.hs−48 src/Language/PureScript/AST.hs−14 src/Language/PureScript/AST/Binders.hs−81 src/Language/PureScript/AST/Declarations.hs−477 src/Language/PureScript/AST/Exported.hs−157 src/Language/PureScript/AST/Literals.hs−37 src/Language/PureScript/AST/Operators.hs−51 src/Language/PureScript/AST/SourcePos.hs−83 src/Language/PureScript/AST/Traversals.hs−605 src/Language/PureScript/Bundle.hs−607 src/Language/PureScript/CodeGen.hs−20 src/Language/PureScript/CodeGen/Cpp.hs−870 src/Language/PureScript/CodeGen/Cpp/AST.hs−375 src/Language/PureScript/CodeGen/Cpp/Common.hs−203 src/Language/PureScript/CodeGen/Cpp/File.hs−179 src/Language/PureScript/CodeGen/Cpp/Optimizer.hs−93 src/Language/PureScript/CodeGen/Cpp/Optimizer/Blocks.hs−83 src/Language/PureScript/CodeGen/Cpp/Optimizer/Common.hs−75 src/Language/PureScript/CodeGen/Cpp/Optimizer/Inliner.hs−344 src/Language/PureScript/CodeGen/Cpp/Optimizer/MagicDo.hs−125 src/Language/PureScript/CodeGen/Cpp/Optimizer/TCO.hs−149 src/Language/PureScript/CodeGen/Cpp/Optimizer/Unused.hs−45 src/Language/PureScript/CodeGen/Cpp/Types.hs−128 src/Language/PureScript/CodeGen/JS.hs−452 src/Language/PureScript/CodeGen/JS/AST.hs−404 src/Language/PureScript/CodeGen/JS/Common.hs−231 src/Language/PureScript/CodeGen/JS/Optimizer.hs−83 src/Language/PureScript/CodeGen/JS/Optimizer/Blocks.hs−42 src/Language/PureScript/CodeGen/JS/Optimizer/Common.hs−81 src/Language/PureScript/CodeGen/JS/Optimizer/Inliner.hs−368 src/Language/PureScript/CodeGen/JS/Optimizer/MagicDo.hs−134 src/Language/PureScript/CodeGen/JS/Optimizer/TCO.hs−130 src/Language/PureScript/CodeGen/JS/Optimizer/Unused.hs−46 src/Language/PureScript/Comments.hs−15 src/Language/PureScript/Constants.hs−373 src/Language/PureScript/CoreFn.hs−15 src/Language/PureScript/CoreFn/Ann.hs−37 src/Language/PureScript/CoreFn/Binders.hs−42 src/Language/PureScript/CoreFn/Desugar.hs−278 src/Language/PureScript/CoreFn/Expr.hs−121 src/Language/PureScript/CoreFn/Meta.hs−40 src/Language/PureScript/CoreFn/Module.hs−31 src/Language/PureScript/CoreFn/Traversals.hs−75 src/Language/PureScript/Crash.hs−9 src/Language/PureScript/Docs.hs−14 src/Language/PureScript/Docs/AsMarkdown.hs−142 src/Language/PureScript/Docs/Convert.hs−194 src/Language/PureScript/Docs/Convert/ReExports.hs−475 src/Language/PureScript/Docs/Convert/Single.hs−235 src/Language/PureScript/Docs/ParseAndBookmark.hs−100 src/Language/PureScript/Docs/Render.hs−136 src/Language/PureScript/Docs/RenderedCode.hs−11 src/Language/PureScript/Docs/RenderedCode/Render.hs−200 src/Language/PureScript/Docs/RenderedCode/Types.hs−197 src/Language/PureScript/Docs/Types.hs−590 src/Language/PureScript/Docs/Utils/MonoidExtras.hs−9 src/Language/PureScript/Environment.hs−274 src/Language/PureScript/Errors.hs−1377 src/Language/PureScript/Errors/JSON.hs−80 src/Language/PureScript/Externs.hs−208 src/Language/PureScript/Ide.hs−242 src/Language/PureScript/Ide/CaseSplit.hs−162 src/Language/PureScript/Ide/Command.hs−157 src/Language/PureScript/Ide/Completion.hs−32 src/Language/PureScript/Ide/Error.hs−57 src/Language/PureScript/Ide/Externs.hs−114 src/Language/PureScript/Ide/Filter.hs−127 src/Language/PureScript/Ide/Imports.hs−355 src/Language/PureScript/Ide/Matcher.hs−131 src/Language/PureScript/Ide/Pursuit.hs−79 src/Language/PureScript/Ide/Rebuild.hs src/Language/PureScript/Ide/Reexports.hs−91 src/Language/PureScript/Ide/SourceFile.hs−121 src/Language/PureScript/Ide/State.hs−98 src/Language/PureScript/Ide/Types.hs−238 src/Language/PureScript/Ide/Util.hs−65 src/Language/PureScript/Ide/Watcher.hs−55 src/Language/PureScript/Kinds.hs−57 src/Language/PureScript/Linter.hs−114 src/Language/PureScript/Linter/Exhaustive.hs−314 src/Language/PureScript/Linter/Imports.hs−344 src/Language/PureScript/Make.hs−475 src/Language/PureScript/ModuleDependencies.hs−96 src/Language/PureScript/Names.hs−143 src/Language/PureScript/Options.hs−52 src/Language/PureScript/Parser.hs−36 src/Language/PureScript/Parser/Common.hs−122 src/Language/PureScript/Parser/Declarations.hs−571 src/Language/PureScript/Parser/JS.hs−60 src/Language/PureScript/Parser/Kinds.hs−48 src/Language/PureScript/Parser/Lexer.hs−526 src/Language/PureScript/Parser/State.hs−30 src/Language/PureScript/Parser/Types.hs−118 src/Language/PureScript/Pretty.hs−29 src/Language/PureScript/Pretty/Common.hs−167 src/Language/PureScript/Pretty/Cpp.hs−540 src/Language/PureScript/Pretty/JS.hs−323 src/Language/PureScript/Pretty/Kinds.hs−59 src/Language/PureScript/Pretty/Types.hs−151 src/Language/PureScript/Pretty/Values.hs−187 src/Language/PureScript/Publish.hs−402 src/Language/PureScript/Publish/BoxesHelpers.hs−41 src/Language/PureScript/Publish/ErrorsWarnings.hs−403 src/Language/PureScript/Publish/Utils.hs−38 src/Language/PureScript/Renamer.hs−197 src/Language/PureScript/Sugar.hs−78 src/Language/PureScript/Sugar/BindingGroups.hs−227 src/Language/PureScript/Sugar/CaseDeclarations.hs−191 src/Language/PureScript/Sugar/DoNotation.hs−65 src/Language/PureScript/Sugar/Names.hs−413 src/Language/PureScript/Sugar/Names/Env.hs−279 src/Language/PureScript/Sugar/Names/Exports.hs−304 src/Language/PureScript/Sugar/Names/Imports.hs−326 src/Language/PureScript/Sugar/ObjectWildcards.hs−95 src/Language/PureScript/Sugar/Operators.hs−332 src/Language/PureScript/Sugar/Operators/Binders.hs−27 src/Language/PureScript/Sugar/Operators/Common.hs−84 src/Language/PureScript/Sugar/Operators/Expr.hs−48 src/Language/PureScript/Sugar/Operators/Types.hs−28 src/Language/PureScript/Sugar/TypeClasses.hs−334 src/Language/PureScript/Sugar/TypeClasses/Deriving.hs−416 src/Language/PureScript/Sugar/TypeDeclarations.hs−73 src/Language/PureScript/Traversals.hs−42 src/Language/PureScript/TypeChecker.hs−462 src/Language/PureScript/TypeChecker/Entailment.hs−217 src/Language/PureScript/TypeChecker/Kinds.hs−271 src/Language/PureScript/TypeChecker/Monad.hs−253 src/Language/PureScript/TypeChecker/Rows.hs−72 src/Language/PureScript/TypeChecker/Skolems.hs−142 src/Language/PureScript/TypeChecker/Subsumption.hs−102 src/Language/PureScript/TypeChecker/Synonyms.hs−63 src/Language/PureScript/TypeChecker/Types.hs−750 src/Language/PureScript/TypeChecker/Unify.hs−229 src/Language/PureScript/TypeClassDictionaries.hs−45 src/Language/PureScript/Types.hs−336 src/System/IO/UTF8.hs−25 src/Tests.hs+141 stack-lts-5.yaml−7 stack-nightly.yaml−6 stack.nix+23 stack.yaml+24−1 support/ffi-loader.go+30 support/go.mod.ffi-loader+2 support/go.mod.output+2 support/go.mod.working+1 test/Spec.hs+2 tests/Language/PureScript/Ide/FilterSpec.hs−63 tests/Language/PureScript/Ide/Imports/IntegrationSpec.hs−101 tests/Language/PureScript/Ide/ImportsSpec.hs−125 tests/Language/PureScript/Ide/Integration.hs−252 tests/Language/PureScript/Ide/MatcherSpec.hs−56 tests/Language/PureScript/Ide/RebuildSpec.hs−62 tests/Language/PureScript/Ide/ReexportsSpec.hs−78 tests/Language/PureScript/IdeSpec.hs−35 tests/Main.hs−54 tests/PscIdeSpec.hs−1 tests/TestCompiler.hs−194 tests/TestDocs.hs−303 tests/TestPscIde.hs−7 tests/TestPscPublish.hs−78 tests/TestPsci.hs−159 tests/TestUtils.hs−65 tests/support/.gitignore−2 tests/support/bower.json−11 tests/support/flattened/Control-Monad-Eff-Class.purs−24 tests/support/flattened/Control-Monad-Eff-Console.js−18 tests/support/flattened/Control-Monad-Eff-Console.purs−18 tests/support/flattened/Control-Monad-Eff-Unsafe.js−8 tests/support/flattened/Control-Monad-Eff-Unsafe.purs−10 tests/support/flattened/Control-Monad-Eff.js−62 tests/support/flattened/Control-Monad-Eff.purs−67 tests/support/flattened/Control-Monad-ST.js−38 tests/support/flattened/Control-Monad-ST.purs−42 tests/support/flattened/Data-Function.js−233 tests/support/flattened/Data-Function.purs−113 tests/support/flattened/Prelude.js−228 tests/support/flattened/Prelude.purs−872 tests/support/flattened/Test-Assert.js−27 tests/support/flattened/Test-Assert.purs−46 tests/support/package.json−7 tests/support/prelude−1 tests/support/psci/Sample.purs tests/support/pscide/.gitignore−7 tests/support/pscide/src/ImportsSpec.purs−5 tests/support/pscide/src/ImportsSpec1.purs−32 tests/support/pscide/src/Main.purs−7 tests/support/pscide/src/RebuildSpecDep.purs−3 tests/support/pscide/src/RebuildSpecSingleModule.fail−3 tests/support/pscide/src/RebuildSpecSingleModule.purs−4 tests/support/pscide/src/RebuildSpecWithDeps.purs−5 tests/support/pscide/src/RebuildSpecWithForeign.js−3 tests/support/pscide/src/RebuildSpecWithForeign.purs−3 tests/support/pscide/src/RebuildSpecWithMissingForeign.fail−3 tests/support/setup-win.cmd−3 tests/support/setup.js−22 travis/after.sh−13 travis/configure.sh−17 travis/test-install.sh−18
.gitignore+4
@@ -14,6 +14,10 @@ bower_components/
1414node_modules
1515tmp/
1616.stack-work/
17+stack.yaml.lock
1718output
1819examples/docs/docs/
1920core-tests/full-core-docs.md
21+.psc-ide-port
22+.vscode/
23+result
.gitmodulesdeleted−3
@@ -1,3 +0,0 @@
1−[submodule "tests/support/prelude"]
2− path = tests/support/prelude
3− url = https://github.com/purescript/purescript-prelude
.travis.ymldeleted−73
@@ -1,73 +0,0 @@
1−language: c
2−dist: trusty
3−sudo: required
4−matrix:
5− include:
6− - env: GHCVER=7.10.3 CABALVER=1.22 STACKAGE=lts-5.4 RUNSDISTTESTS=YES
7− compiler: ": #GHC 7.10.3 lts-5.4"
8− addons: {apt: {packages: [cabal-install-1.22,ghc-7.10.3,happy-1.19.5,alex-3.1.4], sources: [hvr-ghc]}}
9− - env: GHCVER=7.10.3 CABALVER=1.22 STACKAGE=nightly-2016-02-25
10− compiler: ": #GHC 7.10.3 nightly-2016-02-25"
11− addons: {apt: {packages: [cabal-install-1.22,ghc-7.10.3,happy-1.19.5,alex-3.1.4], sources: [hvr-ghc]}}
12− - env: GHCVER=7.10.3 CABALVER=1.22 DEPLOY=yes
13− compiler: ": #GHC 7.10.3"
14− addons: {apt: {packages: [cabal-install-1.22,ghc-7.10.3,happy-1.19.5,alex-3.1.4], sources: [hvr-ghc]}}
15−before_install:
16− - unset CC
17− - export PATH="/opt/ghc/$GHCVER/bin:$PATH"
18− - export PATH="/opt/cabal/$CABALVER/bin:$PATH"
19− - export PATH="$HOME/.cabal/bin:$PATH"
20− - export PATH="/opt/happy/1.19.5/bin:/$PATH"
21− - export PATH="/opt/alex/3.1.4/bin:/$PATH"
22− - export PATH="$HOME/build/purescript/purescript/dist/build/psc:/$PATH"
23− - export PATH="$HOME/build/purescript/purescript/dist/build/psc-ide-server:/$PATH"
24− - export PATH="$HOME/build/purescript/purescript/dist/build/psc-ide-client:/$PATH"
25−install:
26− - cabal --version
27− - echo "$(ghc --version) [$(ghc --print-project-git-commit-id 2> /dev/null || echo '?')]"
28− - travis_retry cabal update
29− # Run sequentially
30− # Travis container infrastructure seems to expose all host CPUs (16?), thus
31− # cabal and ghc tries to use them all. Which is bad idea on a shared box.
32− # See also: https://ghc.haskell.org/trac/ghc/ticket/9221
33− - sed -i 's/^jobs:/-- jobs:/' ${HOME}/.cabal/config
34− # Cache sandboxes in ~/cabal-sandboxes
35− # Move right sandbox to .cabal-sandbox if exists
36− - if [ -d ~/cabal-sandboxes/$GHCVER-${STACKAGE:-none} ]; then
37− mv ~/cabal-sandboxes/$GHCVER-${STACKAGE:-none} .cabal-sandbox;
38− fi
39− - mkdir -p .cabal-sandbox
40− - cabal sandbox init --sandbox .cabal-sandbox
41− # Download stackage cabal.config. Filter this package and 'extra deps'
42− - if [ -n "$STACKAGE" ]; then curl https://www.stackage.org/$STACKAGE/cabal.config | egrep -v 'purescript|language-javascript|bower-json' > cabal.config; fi
43− - cabal install --only-dependencies --enable-tests
44− - cabal install hpc-coveralls
45− # Snapshot state of the sandbox now, so we don't need to make new one for test install
46− - rm -rf ~/cabal-sandboxes/$GHCVER-${STACKAGE:-none}
47− - cp -r .cabal-sandbox ~/cabal-sandboxes/$GHCVER-${STACKAGE:-none}
48− # Install bower globally (for psc-docs/psc-publish tests)
49− - npm install -g bower
50−script:
51− - ./travis/configure.sh
52− - cabal build --ghc-options="-Werror"
53− - cabal test
54− - ./travis/test-install.sh
55−after_script:
56− - ./travis/after.sh
57−notifications:
58− email: true
59−before_deploy: "./bundle/build.sh linux64"
60−deploy:
61− provider: releases
62− api_key: $RELEASE_KEY
63− file:
64− - bundle/linux64.tar.gz
65− - bundle/linux64.sha
66− skip_cleanup: true
67− on:
68− all_branches: true
69− tags: true
70− condition: "$DEPLOY = yes"
71−cache:
72− directories:
73− - ~/cabal-sandboxes
CONTRIBUTING.mddeleted−44
@@ -1,44 +0,0 @@
1−An introductory overview of the compiler is available [here](https://www.youtube.com/watch?v=Y3P1dxqwFiE).
2−
3−Pull requests are encouraged.
4−
5−## Finding Issues to Work On
6−
7−If you would like to contribute, please consider the issues in the current milestone first. If you are a new contributor, you may want to have a go at the ["easy" issues](https://github.com/purescript/purescript/labels/easy) to get started.
8−
9−## Pull Requests
10−
11−Please follow the following guidelines:
12−
13−- Add at least a test to `examples/passing/` and possibly to `examples/failing`.
14−- Build the binaries and libs with `cabal build`
15−- Install the binaries and libs with `cabal install`.
16−- Run `cabal configure --enable-tests && cabal build && cabal test` to build the test suite. You will need `npm` and `node` on your PATH to run the tests.
17−- Build the core libraries by running the script in `core-tests`.
18−
19−## Code Review
20−
21−To prevent core libraries from getting broken, every change must be reviewed. A pull request will be merged as long as one other team member has verified the changes.
22−
23−## Adding Dependencies
24−
25−Because the PureScript compiler is distributed in binary form, we include
26−the licenses of all dependencies, including transitive ones, in the LICENSE
27−file. Therefore, whenever the dependencies change, the LICENSE file should be
28−updated.
29−
30−You can automate this (if you have bash):
31−
32−- get a copy of [cabal-dependency-licenses][]
33−- run at the command line: `runhaskell license-generator/generate.hs > LICENSE`
34−
35−[cabal-dependency-licenses]: https://github.com/jaspervdj/cabal-dependency-licenses
36−
37−## Writing Issues
38−
39−- If the issue is actually a question, please consider asking on Reddit, Stack Overflow or IRC first.
40−- Please include a minimal, repeatable test case with any bug report.
41−
42−## Copyright and Licensing
43−
44−For any code change, please append a copyright and licensing notice to the [CONTRIBUTORS.md](CONTRIBUTORS.md) file.
CONTRIBUTORS.mddeleted−76
@@ -1,76 +0,0 @@
1−## Contributors
2−
3−This file lists the contributors to the PureScript compiler project, and the terms under which their code is licensed.
4−
5−### Individuals
6−
7−- [@5outh](https://github.com/5outh) (Benjamin Kovach) - My existing contributions and all future contributions until further notice are Copyright Benjamin Kovach, and are licensed to the owners and users of the PureScript compiler project under the terms of the MIT license.
8−- [@andyarvanitis](https://github.com/andyarvanitis) (Andy Arvanitis) My existing contributions and all future contributions until further notice are Copyright Andy Arvanitis, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
9−- [@anthok88](https://github.com/anthoq88) - My existing contributions and all future contributions until further notice are Copyright anthoq88, and are licensed to the owners and users of the PureScript compiler project under the terms of the MIT license
10−- [@ardumont](https://github.com/ardumont) (Antoine R. Dumont) My existing contributions and all future contributions until further notice are Copyright Antoine R. Dumont, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
11−- [@aspidites](https://github.com/aspidites) (Edwin Marshall) My existing contributions and all future contributions until further notice are Copyright Edwin Marshall, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
12−- [@bagl](https://github.com/bagl) (Petr Vapenka) My existing contributions and all future contributions until further notice are Copyright Petr Vapenka, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
13−- [@balajirrao](https://github.com/balajirrao) (Balaji Rao) - My existing contributions and all future contributions until further notice are Copyright Balaji Rao, and are licensed to the owners and users of the PureScript compiler project under the terms of the MIT license.
14−- [@bergmark](https://github.com/bergmark) (Adam Bergmark) - My existing contributions and all future contributions until further notice are Copyright Adam Bergmark, and are licensed to the owners and users of the PureScript compiler project under the terms of the MIT license.
15−- [@Bogdanp](https://github.com/Bogdanp) (Bogdan Paul Popa) My existing contributions and all future contributions until further notice are Copyright Bogdan Paul Popa, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
16−- [@cdepillabout](https://github.com/cdepillabout) (Dennis Gosnell) My existing contributions and all future contributions until further notice are Copyright Dennis Gosnell, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
17−- [@chrissmoak](https://github.com/chrissmoak) (Chris Smoak) My existing contributions to the PureScript compiler and all future contributions to the PureScript compiler until further notice, are Copyright Chris Smoak, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
18−- [@codedmart](https://github.com/codedmart) (Brandon Martin) My existing contributions and all future contributions until further notice are Copyright Brandon Martin, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
19−- [@davidchambers](https://github.com/davidchambers) (David Chambers) My existing contributions and all future contributions until further notice are Copyright David Chambers, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
20−- [@DavidLindbom](https://github.com/DavidLindbom) (David Lindbom) My existing contributions and all future contributions until further notice are Copyright David Lindbom, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
21−- [@dckc](https://github.com/dckc) (Dan Connolly) My existing contributions and all future contributions until further notice are Copyright Dan Connolly, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
22−- [@dylex](https://github.com/dylex) (Dylan Simon) My existing and all future contributions to the PureScript compiler until further notice are Copyright Dylan Simon, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
23−- [@eamelink](https://github.com/eamelink) (Erik Bakker) - My existing contributions and all future contributions until further notice are Copyright Erik Bakker, and are licensed to the owners and users of the PureScript compiler project under the terms of the MIT license.
24−- [@epost](https://github.com/epost) (Erik Post) - My existing contributions and all future contributions until further notice are Copyright Erik Post, and are licensed to the owners and users of the PureScript compiler project under the terms of the MIT license
25−- [@erdeszt](https://github.com/erdeszt) (Tibor Erdesz) My existing contributions and all future contributions until further notice are Copyright Tibor Erdesz, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
26−- [@etrepum](https://github.com/etrepum) (Bob Ippolito) My existing contributions and all future contributions until further notice are Copyright Bob Ippolito, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
27−- [@faineance](https://github.com/faineance) My existing contributions and all future contributions until further notice are Copyright faineance, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
28−- [@garyb](https://github.com/garyb) (Gary Burgess) My existing contributions and all future contributions until further notice are Copyright Gary Burgess, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
29−- [@hdgarrood](https://github.com/hdgarrood) (Harry Garrood) My existing contributions and all future contributions until further notice are Copyright Harry Garrood, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
30−- [@izgzhen](https://github.com/izgzhen) (Zhen Zhang) My existing contributions and all future contributions until further notice are Copyright Zhen Zhang, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
31−- [@jacereda](https://github.com/jacereda) (Jorge Acereda) My existing contributions and all future contributions until further notice are Copyright Jorge Acereda, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
32−- [@japesinator](https://github.com/japesinator) (JP Smith) My existing contributions and all future contributions until further notice are Copyright JP Smith, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
33−- [@joneshf](https://github.com/joneshf) (Hardy Jones) - My existing contributions and all future contributions until further notice are Copyright Hardy Jones, and are licensed to the owners and users of the PureScript compiler project under the terms of the MIT license.
34−- [@kRITZCREEK](https://github.com/kRITZCREEK) (Christoph Hegemann) - My existing contributions and all future contributions until further notice are Copyright Christoph Hegemann, and are licensed to the owners and users of the PureScript compiler project under the terms of the MIT license.
35−- [@L8D](https://github.com/L8D) (Tenor Biel) My existing contributions and all future contributions until further notice are Copyright Tenor Biel, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
36−- [@leighman](http://github.com/leighman) (Jack Leigh) My existing contributions and all future contributions until further notice are Copyright Jack Leigh, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
37−- [@lukerandall](https://github.com/lukerandall) (Luke Randall) My existing contributions and all future contributions until further notice are Copyright Luke Randall, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
38−- [@mgmeier](https://github.com/mgmeier) (Michael Karg) My existing contributions and all future contributions until further notice are Copyright Michael Gilliland, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
39−- [@michaelficarra](https://github.com/michaelficarra) (Michael Ficarra) My existing contributions and all future contributions until further notice are Copyright Michael Ficarra, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
40−- [@MichaelXavier](https://github.com/MichaelXavier) (Michael Xavier) - My existing contributions and all future contributions until further notice are Copyright Michael Xavier, and are licensed to the owners and users of the PureScript compiler project under the terms of the MIT license.
41−- [@mjgpy3](https://github.com/mjgpy3) (Michael Gilliland) My existing contributions and all future contributions until further notice are Copyright Michael Gilliland, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
42−- [@mpietrzak](https://github.com/mpietrzak) (Maciej Pietrzak) My existing contributions and all future contributions until further notice are Copyright Maciej Pietrzak, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
43−- [@mrhania](https://github.com/mrhania) (Łukasz Hanuszczak) - My existing contributions and all future contributions until further notice are Copyright Łukasz Hanuszczak, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
44−- [@nagisa](https://github.com/nagisa) I hereby release my [only contribution](https://github.com/purescript/purescript/commit/80287a5d0de619862d3b4cda9c1ee276d18fdcd8) into public domain.
45−- [@natefaubion](https://github.com/natefaubion) (Nathan Faubion) My existing contributions and all future contributions until further notice are Copyright Nathan Faubion, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
46−- [@nicodelpiano](https://github.com/nicodelpiano) (Nicolas Del Piano) My existing contributions and all future contributions until further notice are Copyright Nicolas Del Piano, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
47−- [@nullobject](https://github.com/nullobject) (Josh Bassett) My existing contributions and all future contributions until further notice are Copyright Josh Bassett, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
48−- [@nwolverson](https://github.com/nwolverson) (Nicholas Wolverson) My existing contributions and all future contributions until further notice are Copyright Nicholas Wolverson, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
49−- [@osa1](https://github.com/osa1) (Ömer Sinan Ağacan) - My existing contributions and all future contributions until further notice are Copyright Ömer Sinan Ağacan, and are licensed to the owners and users of the PureScript compiler project under the terms of the MIT license.
50−- [@paf31](https://github.com/paf31) (Phil Freeman) My existing contributions and all future contributions until further notice are Copyright Phil Freeman, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
51−- [@passy](https://github.com/passy) (Pascal Hartig) My existing contributions and all future contributions until further notice are Copyright Pascal Hartig, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
52−- [@paulyoung](https://github.com/paulyoung) (Paul Young) My existing contributions and all future contributions until further notice are Copyright Paul Young, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
53−- [@pelotom](https://github.com/pelotom) (Thomas Crockett) My existing contributions and all future contributions until further notice are Copyright Thomas Crockett, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
54−- [@phadej](https://github.com/phadej) (Oleg Grenrus) My existing contributions and all future contributions until further notice are Copyright Oleg Grenrus, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
55−- [@philopon](https://github.com/philopon) (Hirotomo Moriwaki) - My existing contributions and all future contributions until further notice are Copyright Hirotomo Moriwaki, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
56−- [@pseudonom](https://github.com/pseudonom) (Eric Easley) My existing contributions and all future contributions until further notice are Copyright Eric Easley, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
57−- [@puffnfresh](https://github.com/puffnfresh) (Brian McKenna) All contributions I made during June 2015 were during employment at [SlamData, Inc.](#companies) who owns the copyright. I assign copyright of all my personal contributions before June 2015 to the owners of the PureScript compiler.
58−- [@robdaemon](https://github.com/robdaemon) (Robert Roland) My existing contributions and all future contributions until further notice are Copyright Robert Roland, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
59−- [@RossMeikleham](https://github.com/RossMeikleham) (Ross Meikleham) My existing contributions and all future contributions until further notice are Copyright Ross Meikleham, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
60−- [@sebastiaanvisser](https://github.com/sebastiaanvisser) (Sebastiaan Visser) - My existing contributions and all future contributions until further notice are Copyright Sebastiaan Visser, and are licensed to the owners and users of the PureScript compiler project under the terms of the MIT license.
61−- [@senju](https://github.com/senju) - My existing contributions and all future contributions until further notice are Copyright senju, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
62−- [@sharkdp](https://github.com/sharkdp) (David Peter) My existing contributions and all future contributions until further notice are Copyright David Peter, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
63−- [@soupi](https://github.com/soupi) (Gil Mizrahi) My existing contributions and all future contributions until further notice are Copyright Gil Mizrahi, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
64−- [@sztupi](https://github.com/sztupi) (Attila Sztupak) My existing contributions and all future contributions until further notice are Copyright Attila Sztupak, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
65−- [@taku0](https://github.com/taku0) - My existing contributions and all future contributions until further notice are Copyright taku0, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
66−- [@tfausak](https://github.com/tfausak) (Taylor Fausak) My existing contributions and all future contributions until further notice are Copyright Taylor Fausak, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
67−- [@trofi](https://github.com/trofi) (Sergei Trofimovich) My existing contributions and all future contributions until further notice are Copyright Sergei Trofimovich, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
68−- [@utkarshkukreti](https://github.com/utkarshkukreti) (Utkarsh Kukreti) My existing contributions and all future contributions until further notice are Copyright Utkarsh Kukreti, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
69−- [@vkorablin](https://github.com/vkorablin) (Vladimir Korablin) - My existing contributions and all future contributions until further notice are Copyright Vladimir Korablin, and are licensed to the owners and users of the PureScript compiler project under the terms of the MIT license.
70−- [@zudov](https://github.com/zudov) (Konstantin Zudov) My existing contributions and all future contributions until further notice are Copyright Konstantin Zudov, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
71−- [@LiamGoodacre](https://github.com/LiamGoodacre) (Liam Goodacre) My existing contributions and all future contributions until further notice are Copyright Liam Goodacre, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
72−- [@bsermons](https://github.com/bsermons) (Brian Sermons) My existing contributions and all future contributions until further notice are Copyright Brian Sermons, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
73−
74−### Companies
75−
76−- [@slamdata](https://github.com/slamdata) (SlamData, Inc.) Speaking on behalf of SlamData for SlamData employees, our existing contributions and all future contributions to the PureScript compiler are, until further notice, Copyright SlamData Inc., and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT). - @jdegoes
ChangeLog.mdnew file+3
@@ -0,0 +1,3 @@
1+# Changelog for pscpp
2+
3+## Unreleased changes
INSTALL.mddeleted−53
@@ -1,53 +0,0 @@
1−# Installation information
2−
3−If you are having difficulty installing the PureScript compiler, feel free to
4−ask for help! A good place is the #purescript IRC channel on Freenode, or
5−alternatively Stack Overflow.
6−
7−## Using prebuilt binaries
8−
9−The prebuilt binaries are compiled with GHC 7.10.3, and therefore they should
10−run on any operating system supported by GHC 7.10.3, such as:
11−
12−* Windows 2000 or later,
13−* OS X 10.7 or later,
14−* Linux ??? (we're not sure what the minimum version is).
15−
16−This list is not exhaustive. If your OS is too old or not listed, or if the
17−binaries fail to run, you may be able to install the compiler by building it
18−from source; see below.
19−
20−It's probably safe to assume that other prebuilt distributions (eg, Homebrew,
21−Chocolatey, AUR, npm) use the same binaries, and therefore have the same
22−requirements.
23−
24−## Compiling from source
25−
26−GHC 7.10.1 or newer is required to compile from source. The easiest way is to
27−use stack:
28−
29−```
30−$ stack install --resolver=nightly purescript
31−```
32−
33−This will then copy the compiler and utilities into `~/.local/bin`.
34−
35−
36−If you don't have stack installed yet there are install instructions
37−[here](https://github.com/commercialhaskell/stack/blob/master/doc/install_and_upgrade.md).
38−
39−If you don't have ghc installed yet, stack will prompt you to run `stack setup`
40−which will install ghc for you.
41−
42−## The "curses" library
43−
44−`psci` depends on the `curses` library (via the Haskell package `terminfo`). If
45−you are having difficulty running the compiler, it may be because the `curses`
46−library is missing.
47−
48−On Linux, you will probably need to install `ncurses` manually. On Ubuntu, for
49−example, this can be done by running:
50−
51−```
52−$ sudo apt-get install libncurses5-dev
53−```
LICENSE+24−2163
@@ -1,2169 +1,30 @@
1−The MIT License (MIT)
1+Copyright Andy Arvanitis (c) 2018
22
3−Copyright (c) 2013-15 Phil Freeman, (c) 2014-2015 Gary Burgess, and other
4−contributors
3+All rights reserved.
54
6−Permission is hereby granted, free of charge, to any person obtaining a copy of
7−this software and associated documentation files (the "Software"), to deal in
8−the Software without restriction, including without limitation the rights to
9−use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10−the Software, and to permit persons to whom the Software is furnished to do so,
11−subject to the following conditions:
12−
13−The above copyright notice and this permission notice shall be included in all
14−copies or substantial portions of the Software.
15−
16−THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17−IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18−FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19−COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20−IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21−CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22−
23−PureScript uses the following Haskell library packages. Their license files follow.
24−
25− Glob
26− HUnit
27− aeson
28− aeson-better-errors
29− ansi-terminal
30− ansi-wl-pprint
31− array
32− attoparsec
33− base
34− base-compat
35− binary
36− blaze-builder
37− bower-json
38− boxes
39− bytestring
40− containers
41− deepseq
42− directory
43− dlist
44− filepath
45− ghc-prim
46− hashable
47− haskeline
48− integer-gmp
49− language-javascript
50− lifted-base
51− monad-control
52− mtl
53− nats
54− old-locale
55− optparse-applicative
56− parallel
57− parsec
58− pattern-arrows
59− pretty
60− primitive
61− process
62− rts
63− safe
64− scientific
65− semigroups
66− sourcemap
67− split
68− stm
69− syb
70− tagged
71− template-haskell
72− terminfo
73− text
74− time
75− transformers
76− transformers-base
77− transformers-compat
78− unix
79− unordered-containers
80− utf8-string
81− vector
82− void
83−
84−Glob LICENSE file:
85−
86− The code in Glob is released under the license below. Copyrights to parts of
87− the code are held by whoever wrote the code in question: see CREDITS.txt for a
88− list of authors.
89−
90− Copyright (c) 2008-2012 <authors>
91− All rights reserved.
92−
93− Redistribution and use in source and binary forms, with or without
94− modification, are permitted provided that the following conditions are met:
95− * Redistributions of source code must retain the above copyright
96− notice, this list of conditions and the following disclaimer.
97− * Redistributions in binary form must reproduce the above copyright
98− notice, this list of conditions and the following disclaimer in the
99− documentation and/or other materials provided with the distribution.
100− * Neither the name of the project nor the names of its contributors may be
101− used to endorse or promote products derived from this software without
102− specific prior written permission.
103−
104− THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
105− WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
106− MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
107− EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
108− INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
109− LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
110− PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
111− LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
112− OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
113− ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
114−
115−HUnit LICENSE file:
116−
117− HUnit is Copyright (c) Dean Herington, 2002, all rights reserved,
118− and is distributed as free software under the following license.
119−
120− Redistribution and use in source and binary forms, with or without
121− modification, are permitted provided that the following conditions
122− are met:
123−
124− - Redistributions of source code must retain the above copyright
125− notice, this list of conditions, and the following disclaimer.
126−
127− - Redistributions in binary form must reproduce the above copyright
128− notice, this list of conditions, and the following disclaimer in the
129− documentation and/or other materials provided with the distribution.
130−
131− - The names of the copyright holders may not be used to endorse or
132− promote products derived from this software without specific prior
133− written permission.
134−
135− THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY
136− EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
137− IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
138− PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE
139− LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
140− CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
141− SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
142− BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
143− WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
144− OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
145− IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146−
147−aeson LICENSE file:
148−
149− Copyright (c) 2011, MailRank, Inc.
150−
151− All rights reserved.
152−
153− Redistribution and use in source and binary forms, with or without
154− modification, are permitted provided that the following conditions
155− are met:
156−
157− 1. Redistributions of source code must retain the above copyright
158− notice, this list of conditions and the following disclaimer.
159−
160− 2. Redistributions in binary form must reproduce the above copyright
161− notice, this list of conditions and the following disclaimer in the
162− documentation and/or other materials provided with the distribution.
163−
164− 3. Neither the name of the author nor the names of his contributors
165− may be used to endorse or promote products derived from this software
166− without specific prior written permission.
167−
168− THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS
169− OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
170− WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
171− DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
172− ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
173− DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
174− OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
175− HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
176− STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
177− ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
178− POSSIBILITY OF SUCH DAMAGE.
179−
180−aeson-better-errors LICENSE file:
181−
182− Copyright (c) 2015 Harry Garrood
183−
184− Permission is hereby granted, free of charge, to any person obtaining
185− a copy of this software and associated documentation files (the
186− "Software"), to deal in the Software without restriction, including
187− without limitation the rights to use, copy, modify, merge, publish,
188− distribute, sublicense, and/or sell copies of the Software, and to
189− permit persons to whom the Software is furnished to do so, subject to
190− the following conditions:
191−
192− The above copyright notice and this permission notice shall be included
193− in all copies or substantial portions of the Software.
194−
195− THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
196− EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
197− MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
198− IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
199− CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
200− TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
201− SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
202−
203−ansi-terminal LICENSE file:
204−
205− Copyright (c) 2008, Maximilian Bolingbroke
206− All rights reserved.
207−
208− Redistribution and use in source and binary forms, with or without modification, are permitted
209− provided that the following conditions are met:
210−
211− * Redistributions of source code must retain the above copyright notice, this list of
212− conditions and the following disclaimer.
213− * Redistributions in binary form must reproduce the above copyright notice, this list of
214− conditions and the following disclaimer in the documentation and/or other materials
215− provided with the distribution.
216− * Neither the name of Maximilian Bolingbroke nor the names of other contributors may be used to
217− endorse or promote products derived from this software without specific prior written permission.
218−
219− THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
220− IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
221− FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
222− CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
223− DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
224− DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
225− IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
226− OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
227−
228−ansi-wl-pprint LICENSE file:
229−
230− Copyright 2008, Daan Leijen and Max Bolingbroke. All rights reserved.
231−
232− Redistribution and use in source and binary forms, with or without
233− modification, are permitted provided that the following conditions are
234− met:
5+Redistribution and use in source and binary forms, with or without
6+modification, are permitted provided that the following conditions are met:
2357
2368 * Redistributions of source code must retain the above copyright
2379 notice, this list of conditions and the following disclaimer.
23810
239− * Redistributions in binary form must reproduce the above copyright
240− notice, this list of conditions and the following disclaimer in
241− the documentation and/or other materials provided with the
242− distribution.
243−
244− This software is provided by the copyright holders "as is" and any
245− express or implied warranties, including, but not limited to, the
246− implied warranties of merchantability and fitness for a particular
247− purpose are disclaimed. In no event shall the copyright holders be
248− liable for any direct, indirect, incidental, special, exemplary, or
249− consequential damages (including, but not limited to, procurement of
250− substitute goods or services; loss of use, data, or profits; or
251− business interruption) however caused and on any theory of liability,
252− whether in contract, strict liability, or tort (including negligence
253− or otherwise) arising in any way out of the use of this software, even
254− if advised of the possibility of such damage.
255−
256−array LICENSE file:
257−
258− This library (libraries/base) is derived from code from several
259− sources:
260−
261− * Code from the GHC project which is largely (c) The University of
262− Glasgow, and distributable under a BSD-style license (see below),
263−
264− * Code from the Haskell 98 Report which is (c) Simon Peyton Jones
265− and freely redistributable (but see the full license for
266− restrictions).
267−
268− * Code from the Haskell Foreign Function Interface specification,
269− which is (c) Manuel M. T. Chakravarty and freely redistributable
270− (but see the full license for restrictions).
271−
272− The full text of these licenses is reproduced below. All of the
273− licenses are BSD-style or compatible.
274−
275− -----------------------------------------------------------------------------
276−
277− The Glasgow Haskell Compiler License
278−
279− Copyright 2004, The University Court of the University of Glasgow.
280− All rights reserved.
281−
282− Redistribution and use in source and binary forms, with or without
283− modification, are permitted provided that the following conditions are met:
284−
285− - Redistributions of source code must retain the above copyright notice,
286− this list of conditions and the following disclaimer.
287−
288− - Redistributions in binary form must reproduce the above copyright notice,
289− this list of conditions and the following disclaimer in the documentation
290− and/or other materials provided with the distribution.
291−
292− - Neither name of the University nor the names of its contributors may be
293− used to endorse or promote products derived from this software without
294− specific prior written permission.
295−
296− THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY COURT OF THE UNIVERSITY OF
297− GLASGOW AND THE CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
298− INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
299− FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
300− UNIVERSITY COURT OF THE UNIVERSITY OF GLASGOW OR THE CONTRIBUTORS BE LIABLE
301− FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
302− DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
303− SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
304− CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
305− LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
306− OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
307− DAMAGE.
308−
309− -----------------------------------------------------------------------------
310−
311− Code derived from the document "Report on the Programming Language
312− Haskell 98", is distributed under the following license:
313−
314− Copyright (c) 2002 Simon Peyton Jones
315−
316− The authors intend this Report to belong to the entire Haskell
317− community, and so we grant permission to copy and distribute it for
318− any purpose, provided that it is reproduced in its entirety,
319− including this Notice. Modified versions of this Report may also be
320− copied and distributed for any purpose, provided that the modified
321− version is clearly presented as such, and that it does not claim to
322− be a definition of the Haskell 98 Language.
323−
324− -----------------------------------------------------------------------------
325−
326− Code derived from the document "The Haskell 98 Foreign Function
327− Interface, An Addendum to the Haskell 98 Report" is distributed under
328− the following license:
329−
330− Copyright (c) 2002 Manuel M. T. Chakravarty
331−
332− The authors intend this Report to belong to the entire Haskell
333− community, and so we grant permission to copy and distribute it for
334− any purpose, provided that it is reproduced in its entirety,
335− including this Notice. Modified versions of this Report may also be
336− copied and distributed for any purpose, provided that the modified
337− version is clearly presented as such, and that it does not claim to
338− be a definition of the Haskell 98 Foreign Function Interface.
339−
340− -----------------------------------------------------------------------------
341−
342−attoparsec LICENSE file:
343−
344− Copyright (c) Lennart Kolmodin
345−
346− All rights reserved.
347−
348− Redistribution and use in source and binary forms, with or without
349− modification, are permitted provided that the following conditions
350− are met:
351−
352− 1. Redistributions of source code must retain the above copyright
353− notice, this list of conditions and the following disclaimer.
354−
355− 2. Redistributions in binary form must reproduce the above copyright
356− notice, this list of conditions and the following disclaimer in the
357− documentation and/or other materials provided with the distribution.
358−
359− 3. Neither the name of the author nor the names of his contributors
360− may be used to endorse or promote products derived from this software
361− without specific prior written permission.
362−
363− THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS
364− OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
365− WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
366− DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
367− ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
368− DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
369− OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
370− HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
371− STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
372− ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
373− POSSIBILITY OF SUCH DAMAGE.
374−
375−base LICENSE file:
376−
377− This library (libraries/base) is derived from code from several
378− sources:
379−
380− * Code from the GHC project which is largely (c) The University of
381− Glasgow, and distributable under a BSD-style license (see below),
382−
383− * Code from the Haskell 98 Report which is (c) Simon Peyton Jones
384− and freely redistributable (but see the full license for
385− restrictions).
386−
387− * Code from the Haskell Foreign Function Interface specification,
388− which is (c) Manuel M. T. Chakravarty and freely redistributable
389− (but see the full license for restrictions).
390−
391− The full text of these licenses is reproduced below. All of the
392− licenses are BSD-style or compatible.
393−
394− -----------------------------------------------------------------------------
395−
396− The Glasgow Haskell Compiler License
397−
398− Copyright 2004, The University Court of the University of Glasgow.
399− All rights reserved.
400−
401− Redistribution and use in source and binary forms, with or without
402− modification, are permitted provided that the following conditions are met:
403−
404− - Redistributions of source code must retain the above copyright notice,
405− this list of conditions and the following disclaimer.
406−
407− - Redistributions in binary form must reproduce the above copyright notice,
408− this list of conditions and the following disclaimer in the documentation
409− and/or other materials provided with the distribution.
410−
411− - Neither name of the University nor the names of its contributors may be
412− used to endorse or promote products derived from this software without
413− specific prior written permission.
414−
415− THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY COURT OF THE UNIVERSITY OF
416− GLASGOW AND THE CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
417− INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
418− FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
419− UNIVERSITY COURT OF THE UNIVERSITY OF GLASGOW OR THE CONTRIBUTORS BE LIABLE
420− FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
421− DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
422− SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
423− CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
424− LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
425− OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
426− DAMAGE.
427−
428− -----------------------------------------------------------------------------
429−
430− Code derived from the document "Report on the Programming Language
431− Haskell 98", is distributed under the following license:
432−
433− Copyright (c) 2002 Simon Peyton Jones
434−
435− The authors intend this Report to belong to the entire Haskell
436− community, and so we grant permission to copy and distribute it for
437− any purpose, provided that it is reproduced in its entirety,
438− including this Notice. Modified versions of this Report may also be
439− copied and distributed for any purpose, provided that the modified
440− version is clearly presented as such, and that it does not claim to
441− be a definition of the Haskell 98 Language.
442−
443− -----------------------------------------------------------------------------
444−
445− Code derived from the document "The Haskell 98 Foreign Function
446− Interface, An Addendum to the Haskell 98 Report" is distributed under
447− the following license:
448−
449− Copyright (c) 2002 Manuel M. T. Chakravarty
450−
451− The authors intend this Report to belong to the entire Haskell
452− community, and so we grant permission to copy and distribute it for
453− any purpose, provided that it is reproduced in its entirety,
454− including this Notice. Modified versions of this Report may also be
455− copied and distributed for any purpose, provided that the modified
456− version is clearly presented as such, and that it does not claim to
457− be a definition of the Haskell 98 Foreign Function Interface.
458−
459− -----------------------------------------------------------------------------
460−
461−base-compat LICENSE file:
462−
463− Copyright (c) 2012-2015 Simon Hengel <sol@typeful.net> and Ryan Scott <ryan.gl.scott@ku.edu>
464−
465− Permission is hereby granted, free of charge, to any person obtaining a copy
466− of this software and associated documentation files (the "Software"), to deal
467− in the Software without restriction, including without limitation the rights
468− to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
469− copies of the Software, and to permit persons to whom the Software is
470− furnished to do so, subject to the following conditions:
471−
472− The above copyright notice and this permission notice shall be included in
473− all copies or substantial portions of the Software.
474−
475− THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
476− IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
477− FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
478− AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
479− LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
480− OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
481− THE SOFTWARE.
482−
483−binary LICENSE file:
484−
485− Copyright (c) Lennart Kolmodin
486−
487− All rights reserved.
488−
489− Redistribution and use in source and binary forms, with or without
490− modification, are permitted provided that the following conditions
491− are met:
492−
493− 1. Redistributions of source code must retain the above copyright
494− notice, this list of conditions and the following disclaimer.
495−
496− 2. Redistributions in binary form must reproduce the above copyright
497− notice, this list of conditions and the following disclaimer in the
498− documentation and/or other materials provided with the distribution.
499−
500− 3. Neither the name of the author nor the names of his contributors
501− may be used to endorse or promote products derived from this software
502− without specific prior written permission.
503−
504− THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS
505− OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
506− WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
507− DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
508− ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
509− DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
510− OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
511− HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
512− STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
513− ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
514− POSSIBILITY OF SUCH DAMAGE.
515−
516−blaze-builder LICENSE file:
517−
518− Copyright Jasper Van der Jeugt 2010, Simon Meier 2010 & 2011
519−
520− All rights reserved.
521−
522− Redistribution and use in source and binary forms, with or without
523− modification, are permitted provided that the following conditions are met:
524−
525− * Redistributions of source code must retain the above copyright
526− notice, this list of conditions and the following disclaimer.
527−
528− * Redistributions in binary form must reproduce the above
529− copyright notice, this list of conditions and the following
530− disclaimer in the documentation and/or other materials provided
531− with the distribution.
532−
533− * Neither the name of Jasper Van der Jeugt nor the names of other
534− contributors may be used to endorse or promote products derived
535− from this software without specific prior written permission.
536−
537− THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
538− "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
539− LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
540− A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
541− OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
542− SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
543− LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
544− DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
545− THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
546− (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
547− OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
548−
549−bower-json LICENSE file:
550−
551− Copyright (c) 2015 Harry Garrood
552−
553− Permission is hereby granted, free of charge, to any person obtaining
554− a copy of this software and associated documentation files (the
555− "Software"), to deal in the Software without restriction, including
556− without limitation the rights to use, copy, modify, merge, publish,
557− distribute, sublicense, and/or sell copies of the Software, and to
558− permit persons to whom the Software is furnished to do so, subject to
559− the following conditions:
560−
561− The above copyright notice and this permission notice shall be included
562− in all copies or substantial portions of the Software.
563−
564− THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
565− EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
566− MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
567− IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
568− CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
569− TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
570− SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
571−
572−boxes LICENSE file:
573−
574− Copyright (c) Brent Yorgey 2008
575−
576− Redistribution and use in source and binary forms, with or without
577− modification, are permitted provided that the following conditions
578− are met:
579− 1. Redistributions of source code must retain the above copyright
580− notice, this list of conditions and the following disclaimer.
581− 2. Redistributions in binary form must reproduce the above copyright
582− notice, this list of conditions and the following disclaimer in the
583− documentation and/or other materials provided with the distribution.
584− 3. Neither the name of the author nor the names of other contributors
585− may be used to endorse or promote products derived from this software
586− without specific prior written permission.
587−
588− All other rights are reserved.
589−
590− THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND
591− ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
592− IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
593− ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
594− FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
595− DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
596− OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
597− HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
598− LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
599− OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
600− SUCH DAMAGE.
601−
602−bytestring LICENSE file:
603−
604− Copyright (c) Don Stewart 2005-2009
605− (c) Duncan Coutts 2006-2015
606− (c) David Roundy 2003-2005
607− (c) Simon Meier 2010-2011
608−
609− All rights reserved.
610−
611− Redistribution and use in source and binary forms, with or without
612− modification, are permitted provided that the following conditions
613− are met:
614− 1. Redistributions of source code must retain the above copyright
615− notice, this list of conditions and the following disclaimer.
616− 2. Redistributions in binary form must reproduce the above copyright
617− notice, this list of conditions and the following disclaimer in the
618− documentation and/or other materials provided with the distribution.
619− 3. Neither the name of the author nor the names of his contributors
620− may be used to endorse or promote products derived from this software
621− without specific prior written permission.
622−
623− THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
624− ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
625− IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
626− ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
627− FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
628− DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
629− OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
630− HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
631− LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
632− OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
633− SUCH DAMAGE.
634−
635−containers LICENSE file:
636−
637− The Glasgow Haskell Compiler License
638−
639− Copyright 2004, The University Court of the University of Glasgow.
640− All rights reserved.
641−
642− Redistribution and use in source and binary forms, with or without
643− modification, are permitted provided that the following conditions are met:
644−
645− - Redistributions of source code must retain the above copyright notice,
646− this list of conditions and the following disclaimer.
647−
648− - Redistributions in binary form must reproduce the above copyright notice,
649− this list of conditions and the following disclaimer in the documentation
650− and/or other materials provided with the distribution.
651−
652− - Neither name of the University nor the names of its contributors may be
653− used to endorse or promote products derived from this software without
654− specific prior written permission.
655−
656− THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY COURT OF THE UNIVERSITY OF
657− GLASGOW AND THE CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
658− INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
659− FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
660− UNIVERSITY COURT OF THE UNIVERSITY OF GLASGOW OR THE CONTRIBUTORS BE LIABLE
661− FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
662− DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
663− SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
664− CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
665− LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
666− OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
667− DAMAGE.
668−
669−deepseq LICENSE file:
670−
671− This library (deepseq) is derived from code from the GHC project which
672− is largely (c) The University of Glasgow, and distributable under a
673− BSD-style license (see below).
674−
675− -----------------------------------------------------------------------------
676−
677− The Glasgow Haskell Compiler License
678−
679− Copyright 2001-2009, The University Court of the University of Glasgow.
680− All rights reserved.
681−
682− Redistribution and use in source and binary forms, with or without
683− modification, are permitted provided that the following conditions are met:
684−
685− - Redistributions of source code must retain the above copyright notice,
686− this list of conditions and the following disclaimer.
687−
688− - Redistributions in binary form must reproduce the above copyright notice,
689− this list of conditions and the following disclaimer in the documentation
690− and/or other materials provided with the distribution.
691−
692− - Neither name of the University nor the names of its contributors may be
693− used to endorse or promote products derived from this software without
694− specific prior written permission.
695−
696− THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY COURT OF THE UNIVERSITY OF
697− GLASGOW AND THE CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
698− INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
699− FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
700− UNIVERSITY COURT OF THE UNIVERSITY OF GLASGOW OR THE CONTRIBUTORS BE LIABLE
701− FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
702− DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
703− SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
704− CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
705− LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
706− OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
707− DAMAGE.
708−
709− -----------------------------------------------------------------------------
710−
711−directory LICENSE file:
712−
713− This library (libraries/base) is derived from code from two
714− sources:
715−
716− * Code from the GHC project which is largely (c) The University of
717− Glasgow, and distributable under a BSD-style license (see below),
718−
719− * Code from the Haskell 98 Report which is (c) Simon Peyton Jones
720− and freely redistributable (but see the full license for
721− restrictions).
722−
723− The full text of these licenses is reproduced below. Both of the
724− licenses are BSD-style or compatible.
725−
726− -----------------------------------------------------------------------------
727−
728− The Glasgow Haskell Compiler License
729−
730− Copyright 2004, The University Court of the University of Glasgow.
731− All rights reserved.
732−
733− Redistribution and use in source and binary forms, with or without
734− modification, are permitted provided that the following conditions are met:
735−
736− - Redistributions of source code must retain the above copyright notice,
737− this list of conditions and the following disclaimer.
738−
739− - Redistributions in binary form must reproduce the above copyright notice,
740− this list of conditions and the following disclaimer in the documentation
741− and/or other materials provided with the distribution.
742−
743− - Neither name of the University nor the names of its contributors may be
744− used to endorse or promote products derived from this software without
745− specific prior written permission.
746−
747− THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY COURT OF THE UNIVERSITY OF
748− GLASGOW AND THE CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
749− INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
750− FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
751− UNIVERSITY COURT OF THE UNIVERSITY OF GLASGOW OR THE CONTRIBUTORS BE LIABLE
752− FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
753− DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
754− SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
755− CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
756− LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
757− OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
758− DAMAGE.
759−
760− -----------------------------------------------------------------------------
761−
762− Code derived from the document "Report on the Programming Language
763− Haskell 98", is distributed under the following license:
764−
765− Copyright (c) 2002 Simon Peyton Jones
766−
767− The authors intend this Report to belong to the entire Haskell
768− community, and so we grant permission to copy and distribute it for
769− any purpose, provided that it is reproduced in its entirety,
770− including this Notice. Modified versions of this Report may also be
771− copied and distributed for any purpose, provided that the modified
772− version is clearly presented as such, and that it does not claim to
773− be a definition of the Haskell 98 Language.
774−
775− -----------------------------------------------------------------------------
776−
777−dlist LICENSE file:
778−
779− Copyright (c) 2006-2009 Don Stewart, 2013-2014 Sean Leather
780−
781− All rights reserved.
782−
783− Redistribution and use in source and binary forms, with or without
784− modification, are permitted provided that the following conditions are
785− met:
786−
787− * Redistributions of source code must retain the above copyright
788− notice, this list of conditions and the following disclaimer.
789−
790− * Redistributions in binary form must reproduce the above
791− copyright notice, this list of conditions and the following
792− disclaimer in the documentation and/or other materials provided
793− with the distribution.
794−
795− * Neither the name of Don Stewart nor the names of other
796− contributors may be used to endorse or promote products derived
797− from this software without specific prior written permission.
798−
799− THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
800− "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
801− LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
802− A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
803− OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
804− SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
805− LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
806− DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
807− THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
808− (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
809− OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
810−
811−filepath LICENSE file:
812−
813− Copyright Neil Mitchell 2005-2015.
814− All rights reserved.
815−
816− Redistribution and use in source and binary forms, with or without
817− modification, are permitted provided that the following conditions are
818− met:
819−
820− * Redistributions of source code must retain the above copyright
821− notice, this list of conditions and the following disclaimer.
822−
823− * Redistributions in binary form must reproduce the above
824− copyright notice, this list of conditions and the following
825− disclaimer in the documentation and/or other materials provided
826− with the distribution.
827−
828− * Neither the name of Neil Mitchell nor the names of other
829− contributors may be used to endorse or promote products derived
830− from this software without specific prior written permission.
831−
832− THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
833− "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
834− LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
835− A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
836− OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
837− SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
838− LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
839− DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
840− THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
841− (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
842− OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
843−
844−ghc-prim LICENSE file:
845−
846− This library (libraries/ghc-prim) is derived from code from several
847− sources:
848−
849− * Code from the GHC project which is largely (c) The University of
850− Glasgow, and distributable under a BSD-style license (see below),
851−
852− * Code from the Haskell 98 Report which is (c) Simon Peyton Jones
853− and freely redistributable (but see the full license for
854− restrictions).
855−
856− The full text of these licenses is reproduced below. All of the
857− licenses are BSD-style or compatible.
858−
859− -----------------------------------------------------------------------------
860−
861− The Glasgow Haskell Compiler License
862−
863− Copyright 2004, The University Court of the University of Glasgow.
864− All rights reserved.
865−
866− Redistribution and use in source and binary forms, with or without
867− modification, are permitted provided that the following conditions are met:
868−
869− - Redistributions of source code must retain the above copyright notice,
870− this list of conditions and the following disclaimer.
871−
872− - Redistributions in binary form must reproduce the above copyright notice,
873− this list of conditions and the following disclaimer in the documentation
874− and/or other materials provided with the distribution.
875−
876− - Neither name of the University nor the names of its contributors may be
877− used to endorse or promote products derived from this software without
878− specific prior written permission.
879−
880− THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY COURT OF THE UNIVERSITY OF
881− GLASGOW AND THE CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
882− INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
883− FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
884− UNIVERSITY COURT OF THE UNIVERSITY OF GLASGOW OR THE CONTRIBUTORS BE LIABLE
885− FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
886− DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
887− SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
888− CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
889− LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
890− OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
891− DAMAGE.
892−
893− -----------------------------------------------------------------------------
894−
895− Code derived from the document "Report on the Programming Language
896− Haskell 98", is distributed under the following license:
897−
898− Copyright (c) 2002 Simon Peyton Jones
899−
900− The authors intend this Report to belong to the entire Haskell
901− community, and so we grant permission to copy and distribute it for
902− any purpose, provided that it is reproduced in its entirety,
903− including this Notice. Modified versions of this Report may also be
904− copied and distributed for any purpose, provided that the modified
905− version is clearly presented as such, and that it does not claim to
906− be a definition of the Haskell 98 Language.
907−
908−
909−hashable LICENSE file:
910−
911− Copyright Milan Straka 2010
912−
913− All rights reserved.
914−
915− Redistribution and use in source and binary forms, with or without
916− modification, are permitted provided that the following conditions are met:
917−
918− * Redistributions of source code must retain the above copyright
919− notice, this list of conditions and the following disclaimer.
920−
921− * Redistributions in binary form must reproduce the above
922− copyright notice, this list of conditions and the following
923− disclaimer in the documentation and/or other materials provided
924− with the distribution.
925−
926− * Neither the name of Milan Straka nor the names of other
927− contributors may be used to endorse or promote products derived
928− from this software without specific prior written permission.
929−
930− THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
931− "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
932− LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
933− A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
934− OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
935− SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
936− LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
937− DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
938− THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
939− (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
940− OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
941−
942−haskeline LICENSE file:
943−
944− Copyright 2007-2009, Judah Jacobson.
945− All Rights Reserved.
946−
947− Redistribution and use in source and binary forms, with or without
948− modification, are permitted provided that the following conditions are met:
949−
950− - Redistribution of source code must retain the above copyright notice,
951− this list of conditions and the following disclaimer.
952−
953− - Redistribution in binary form must reproduce the above copyright notice,
954− this list of conditions and the following disclaimer in the documentation
955− and/or other materials provided with the distribution.
956−
957− THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY
958− EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
959− WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
960− DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR THE CONTRIBUTORS BE LIABLE
961− FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
962− DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
963− SERVICES; LOSS OF USE, DATA OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
964− CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
965− OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
966− USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
967−
968−integer-gmp LICENSE file:
969−
970− Copyright (c) 2014, Herbert Valerio Riedel
971−
972− All rights reserved.
973−
974− Redistribution and use in source and binary forms, with or without
975− modification, are permitted provided that the following conditions are met:
976−
977− * Redistributions of source code must retain the above copyright
978− notice, this list of conditions and the following disclaimer.
979−
980− * Redistributions in binary form must reproduce the above
981− copyright notice, this list of conditions and the following
982− disclaimer in the documentation and/or other materials provided
983− with the distribution.
984−
985− * Neither the name of Herbert Valerio Riedel nor the names of other
986− contributors may be used to endorse or promote products derived
987− from this software without specific prior written permission.
988−
989− THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
990− "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
991− LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
992− A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
993− OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
994− SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
995− LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
996− DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
997− THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
998− (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
999− OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1000−
1001−language-javascript LICENSE file:
1002−
1003− Copyright (c)2010, Alan Zimmerman
1004−
1005− All rights reserved.
1006−
1007− Redistribution and use in source and binary forms, with or without
1008− modification, are permitted provided that the following conditions are met:
1009−
1010− * Redistributions of source code must retain the above copyright
1011− notice, this list of conditions and the following disclaimer.
1012−
1013− * Redistributions in binary form must reproduce the above
1014− copyright notice, this list of conditions and the following
1015− disclaimer in the documentation and/or other materials provided
1016− with the distribution.
1017−
1018− * Neither the name of Alan Zimmerman nor the names of other
1019− contributors may be used to endorse or promote products derived
1020− from this software without specific prior written permission.
1021−
1022− THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1023− "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1024− LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1025− A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1026− OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1027− SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1028− LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1029− DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1030− THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1031− (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1032− OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1033−
1034−lifted-base LICENSE file:
1035−
1036− Copyright © 2010-2012, Bas van Dijk, Anders Kaseorg
1037− All rights reserved.
1038−
1039− Redistribution and use in source and binary forms, with or without
1040− modification, are permitted provided that the following conditions are
1041− met:
1042−
1043− • Redistributions of source code must retain the above copyright
1044− notice, this list of conditions and the following disclaimer.
1045−
1046− • Redistributions in binary form must reproduce the above copyright
1047− notice, this list of conditions and the following disclaimer in the
1048− documentation and/or other materials provided with the distribution.
1049−
1050− • Neither the name of the author nor the names of other contributors
1051− may be used to endorse or promote products derived from this
1052− software without specific prior written permission.
1053−
1054− THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1055− “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1056− LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1057− A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1058− HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1059− SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1060− LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1061− DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1062− THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1063− (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1064− OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1065−
1066−monad-control LICENSE file:
1067−
1068− Copyright © 2010, Bas van Dijk, Anders Kaseorg
1069− All rights reserved.
1070−
1071− Redistribution and use in source and binary forms, with or without
1072− modification, are permitted provided that the following conditions are
1073− met:
1074−
1075− • Redistributions of source code must retain the above copyright
1076− notice, this list of conditions and the following disclaimer.
1077−
1078− • Redistributions in binary form must reproduce the above copyright
1079− notice, this list of conditions and the following disclaimer in the
1080− documentation and/or other materials provided with the distribution.
1081−
1082− • Neither the name of the author nor the names of other contributors
1083− may be used to endorse or promote products derived from this
1084− software without specific prior written permission.
1085−
1086− THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1087− “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1088− LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1089− A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1090− HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1091− SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1092− LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1093− DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1094− THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1095− (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1096− OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1097−
1098−mtl LICENSE file:
1099−
1100− The Glasgow Haskell Compiler License
1101−
1102− Copyright 2004, The University Court of the University of Glasgow.
1103− All rights reserved.
1104−
1105− Redistribution and use in source and binary forms, with or without
1106− modification, are permitted provided that the following conditions are met:
1107−
1108− - Redistributions of source code must retain the above copyright notice,
1109− this list of conditions and the following disclaimer.
1110−
1111− - Redistributions in binary form must reproduce the above copyright notice,
1112− this list of conditions and the following disclaimer in the documentation
1113− and/or other materials provided with the distribution.
1114−
1115− - Neither name of the University nor the names of its contributors may be
1116− used to endorse or promote products derived from this software without
1117− specific prior written permission.
1118−
1119− THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY COURT OF THE UNIVERSITY OF
1120− GLASGOW AND THE CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
1121− INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
1122− FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
1123− UNIVERSITY COURT OF THE UNIVERSITY OF GLASGOW OR THE CONTRIBUTORS BE LIABLE
1124− FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1125− DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1126− SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
1127− CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1128− LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1129− OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
1130− DAMAGE.
1131−
1132−nats LICENSE file:
1133−
1134− Copyright 2011-2014 Edward Kmett
1135−
1136− All rights reserved.
1137−
1138− Redistribution and use in source and binary forms, with or without
1139− modification, are permitted provided that the following conditions
1140− are met:
1141−
1142− 1. Redistributions of source code must retain the above copyright
1143− notice, this list of conditions and the following disclaimer.
1144−
1145− 2. Redistributions in binary form must reproduce the above copyright
1146− notice, this list of conditions and the following disclaimer in the
1147− documentation and/or other materials provided with the distribution.
1148−
1149− 3. Neither the name of the author nor the names of his contributors
1150− may be used to endorse or promote products derived from this software
1151− without specific prior written permission.
1152−
1153− THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
1154− IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1155− WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1156− DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
1157− ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1158− DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1159− OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1160− HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
1161− STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
1162− ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1163− POSSIBILITY OF SUCH DAMAGE.
1164−
1165−old-locale LICENSE file:
1166−
1167− This library (libraries/base) is derived from code from two
1168− sources:
1169−
1170− * Code from the GHC project which is largely (c) The University of
1171− Glasgow, and distributable under a BSD-style license (see below),
1172−
1173− * Code from the Haskell 98 Report which is (c) Simon Peyton Jones
1174− and freely redistributable (but see the full license for
1175− restrictions).
1176−
1177− The full text of these licenses is reproduced below. Both of the
1178− licenses are BSD-style or compatible.
1179−
1180− -----------------------------------------------------------------------------
1181−
1182− The Glasgow Haskell Compiler License
1183−
1184− Copyright 2004, The University Court of the University of Glasgow.
1185− All rights reserved.
1186−
1187− Redistribution and use in source and binary forms, with or without
1188− modification, are permitted provided that the following conditions are met:
1189−
1190− - Redistributions of source code must retain the above copyright notice,
1191− this list of conditions and the following disclaimer.
1192−
1193− - Redistributions in binary form must reproduce the above copyright notice,
1194− this list of conditions and the following disclaimer in the documentation
1195− and/or other materials provided with the distribution.
1196−
1197− - Neither name of the University nor the names of its contributors may be
1198− used to endorse or promote products derived from this software without
1199− specific prior written permission.
1200−
1201− THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY COURT OF THE UNIVERSITY OF
1202− GLASGOW AND THE CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
1203− INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
1204− FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
1205− UNIVERSITY COURT OF THE UNIVERSITY OF GLASGOW OR THE CONTRIBUTORS BE LIABLE
1206− FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1207− DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1208− SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
1209− CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1210− LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1211− OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
1212− DAMAGE.
1213−
1214− -----------------------------------------------------------------------------
1215−
1216− Code derived from the document "Report on the Programming Language
1217− Haskell 98", is distributed under the following license:
1218−
1219− Copyright (c) 2002 Simon Peyton Jones
1220−
1221− The authors intend this Report to belong to the entire Haskell
1222− community, and so we grant permission to copy and distribute it for
1223− any purpose, provided that it is reproduced in its entirety,
1224− including this Notice. Modified versions of this Report may also be
1225− copied and distributed for any purpose, provided that the modified
1226− version is clearly presented as such, and that it does not claim to
1227− be a definition of the Haskell 98 Language.
1228−
1229− -----------------------------------------------------------------------------
1230−
1231−optparse-applicative LICENSE file:
1232−
1233− Copyright (c) 2012, Paolo Capriotti
1234−
1235− All rights reserved.
1236−
1237− Redistribution and use in source and binary forms, with or without
1238− modification, are permitted provided that the following conditions are met:
1239−
1240− * Redistributions of source code must retain the above copyright
1241− notice, this list of conditions and the following disclaimer.
1242−
1243− * Redistributions in binary form must reproduce the above
1244− copyright notice, this list of conditions and the following
1245− disclaimer in the documentation and/or other materials provided
1246− with the distribution.
1247−
1248− * Neither the name of Paolo Capriotti nor the names of other
1249− contributors may be used to endorse or promote products derived
1250− from this software without specific prior written permission.
1251−
1252− THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1253− "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1254− LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1255− A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1256− OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1257− SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1258− LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1259− DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1260− THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1261− (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1262− OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1263−
1264−parallel LICENSE file:
1265−
1266− This library (libraries/parallel) is derived from code from
1267− the GHC project which is largely (c) The University of
1268− Glasgow, and distributable under a BSD-style license (see below).
1269−
1270− -----------------------------------------------------------------------------
1271−
1272− The Glasgow Haskell Compiler License
1273−
1274− Copyright 2004, The University Court of the University of Glasgow.
1275− All rights reserved.
1276−
1277− Redistribution and use in source and binary forms, with or without
1278− modification, are permitted provided that the following conditions are met:
1279−
1280− - Redistributions of source code must retain the above copyright notice,
1281− this list of conditions and the following disclaimer.
1282−
1283− - Redistributions in binary form must reproduce the above copyright notice,
1284− this list of conditions and the following disclaimer in the documentation
1285− and/or other materials provided with the distribution.
1286−
1287− - Neither name of the University nor the names of its contributors may be
1288− used to endorse or promote products derived from this software without
1289− specific prior written permission.
1290−
1291− THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY COURT OF THE UNIVERSITY OF
1292− GLASGOW AND THE CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
1293− INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
1294− FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
1295− UNIVERSITY COURT OF THE UNIVERSITY OF GLASGOW OR THE CONTRIBUTORS BE LIABLE
1296− FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1297− DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1298− SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
1299− CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1300− LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1301− OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
1302− DAMAGE.
1303−
1304− -----------------------------------------------------------------------------
1305−
1306−parsec LICENSE file:
1307−
1308− Copyright 1999-2000, Daan Leijen; 2007, Paolo Martini. All rights reserved.
1309−
1310− Redistribution and use in source and binary forms, with or without
1311− modification, are permitted provided that the following conditions are met:
1312−
1313− * Redistributions of source code must retain the above copyright notice,
1314− this list of conditions and the following disclaimer.
1315− * Redistributions in binary form must reproduce the above copyright
1316− notice, this list of conditions and the following disclaimer in the
1317− documentation and/or other materials provided with the distribution.
1318−
1319− This software is provided by the copyright holders "as is" and any express or
1320− implied warranties, including, but not limited to, the implied warranties of
1321− merchantability and fitness for a particular purpose are disclaimed. In no
1322− event shall the copyright holders be liable for any direct, indirect,
1323− incidental, special, exemplary, or consequential damages (including, but not
1324− limited to, procurement of substitute goods or services; loss of use, data,
1325− or profits; or business interruption) however caused and on any theory of
1326− liability, whether in contract, strict liability, or tort (including
1327− negligence or otherwise) arising in any way out of the use of this software,
1328− even if advised of the possibility of such damage.
1329−
1330−pattern-arrows LICENSE file:
1331−
1332− The MIT License (MIT)
1333−
1334− Copyright (c) 2013 Phil Freeman
1335−
1336− Permission is hereby granted, free of charge, to any person obtaining a copy of
1337− this software and associated documentation files (the "Software"), to deal in
1338− the Software without restriction, including without limitation the rights to
1339− use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
1340− the Software, and to permit persons to whom the Software is furnished to do so,
1341− subject to the following conditions:
1342−
1343− The above copyright notice and this permission notice shall be included in all
1344− copies or substantial portions of the Software.
1345−
1346− THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1347− IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
1348− FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
1349− COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
1350− IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1351− CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1352−
1353−pretty LICENSE file:
1354−
1355− This library (libraries/pretty) is derived from code from
1356− the GHC project which is largely (c) The University of
1357− Glasgow, and distributable under a BSD-style license (see below).
1358−
1359− -----------------------------------------------------------------------------
1360−
1361− The Glasgow Haskell Compiler License
1362−
1363− Copyright 2004, The University Court of the University of Glasgow.
1364− All rights reserved.
1365−
1366− Redistribution and use in source and binary forms, with or without
1367− modification, are permitted provided that the following conditions are met:
1368−
1369− - Redistributions of source code must retain the above copyright notice,
1370− this list of conditions and the following disclaimer.
1371−
1372− - Redistributions in binary form must reproduce the above copyright notice,
1373− this list of conditions and the following disclaimer in the documentation
1374− and/or other materials provided with the distribution.
1375−
1376− - Neither name of the University nor the names of its contributors may be
1377− used to endorse or promote products derived from this software without
1378− specific prior written permission.
1379−
1380− THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY COURT OF THE UNIVERSITY OF
1381− GLASGOW AND THE CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
1382− INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
1383− FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
1384− UNIVERSITY COURT OF THE UNIVERSITY OF GLASGOW OR THE CONTRIBUTORS BE LIABLE
1385− FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1386− DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1387− SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
1388− CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1389− LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1390− OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
1391− DAMAGE.
1392−
1393− -----------------------------------------------------------------------------
1394−
1395−primitive LICENSE file:
1396−
1397− Copyright (c) 2008-2009, Roman Leshchinskiy
1398− All rights reserved.
1399−
1400− Redistribution and use in source and binary forms, with or without
1401− modification, are permitted provided that the following conditions are met:
1402−
1403− - Redistributions of source code must retain the above copyright notice,
1404− this list of conditions and the following disclaimer.
1405−
1406− - Redistributions in binary form must reproduce the above copyright notice,
1407− this list of conditions and the following disclaimer in the documentation
1408− and/or other materials provided with the distribution.
1409−
1410− - Neither name of the University nor the names of its contributors may be
1411− used to endorse or promote products derived from this software without
1412− specific prior written permission.
1413−
1414− THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY COURT OF THE UNIVERSITY OF
1415− GLASGOW AND THE CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
1416− INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
1417− FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
1418− UNIVERSITY COURT OF THE UNIVERSITY OF GLASGOW OR THE CONTRIBUTORS BE LIABLE
1419− FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1420− DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1421− SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
1422− CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1423− LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1424− OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
1425− DAMAGE.
1426−
1427−
1428−process LICENSE file:
1429−
1430− This library (libraries/process) is derived from code from two
1431− sources:
1432−
1433− * Code from the GHC project which is largely (c) The University of
1434− Glasgow, and distributable under a BSD-style license (see below),
1435−
1436− * Code from the Haskell 98 Report which is (c) Simon Peyton Jones
1437− and freely redistributable (but see the full license for
1438− restrictions).
1439−
1440− The full text of these licenses is reproduced below. Both of the
1441− licenses are BSD-style or compatible.
1442−
1443− -----------------------------------------------------------------------------
1444−
1445− The Glasgow Haskell Compiler License
1446−
1447− Copyright 2004, The University Court of the University of Glasgow.
1448− All rights reserved.
1449−
1450− Redistribution and use in source and binary forms, with or without
1451− modification, are permitted provided that the following conditions are met:
1452−
1453− - Redistributions of source code must retain the above copyright notice,
1454− this list of conditions and the following disclaimer.
1455−
1456− - Redistributions in binary form must reproduce the above copyright notice,
1457− this list of conditions and the following disclaimer in the documentation
1458− and/or other materials provided with the distribution.
1459−
1460− - Neither name of the University nor the names of its contributors may be
1461− used to endorse or promote products derived from this software without
1462− specific prior written permission.
1463−
1464− THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY COURT OF THE UNIVERSITY OF
1465− GLASGOW AND THE CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
1466− INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
1467− FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
1468− UNIVERSITY COURT OF THE UNIVERSITY OF GLASGOW OR THE CONTRIBUTORS BE LIABLE
1469− FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1470− DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1471− SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
1472− CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1473− LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1474− OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
1475− DAMAGE.
1476−
1477− -----------------------------------------------------------------------------
1478−
1479− Code derived from the document "Report on the Programming Language
1480− Haskell 98", is distributed under the following license:
1481−
1482− Copyright (c) 2002 Simon Peyton Jones
1483−
1484− The authors intend this Report to belong to the entire Haskell
1485− community, and so we grant permission to copy and distribute it for
1486− any purpose, provided that it is reproduced in its entirety,
1487− including this Notice. Modified versions of this Report may also be
1488− copied and distributed for any purpose, provided that the modified
1489− version is clearly presented as such, and that it does not claim to
1490− be a definition of the Haskell 98 Language.
1491−
1492− -----------------------------------------------------------------------------
1493−
1494−rts LICENSE file:
1495−
1496− Package not found: No such package in package index
1497−
1498−safe LICENSE file:
1499−
1500− Copyright Neil Mitchell 2007-2015.
1501− All rights reserved.
1502−
1503− Redistribution and use in source and binary forms, with or without
1504− modification, are permitted provided that the following conditions are
1505− met:
1506−
1507− * Redistributions of source code must retain the above copyright
1508− notice, this list of conditions and the following disclaimer.
1509−
1510− * Redistributions in binary form must reproduce the above
1511− copyright notice, this list of conditions and the following
1512− disclaimer in the documentation and/or other materials provided
1513− with the distribution.
1514−
1515− * Neither the name of Neil Mitchell nor the names of other
1516− contributors may be used to endorse or promote products derived
1517− from this software without specific prior written permission.
1518−
1519− THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1520− "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1521− LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1522− A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1523− OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1524− SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1525− LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1526− DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1527− THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1528− (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1529− OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1530−
1531−scientific LICENSE file:
1532−
1533− Copyright (c) 2013, Bas van Dijk
1534−
1535− All rights reserved.
1536−
1537− Redistribution and use in source and binary forms, with or without
1538− modification, are permitted provided that the following conditions are met:
1539−
1540− * Redistributions of source code must retain the above copyright
1541− notice, this list of conditions and the following disclaimer.
1542−
1543− * Redistributions in binary form must reproduce the above
1544− copyright notice, this list of conditions and the following
1545− disclaimer in the documentation and/or other materials provided
1546− with the distribution.
1547−
1548− * Neither the name of Bas van Dijk nor the names of other
1549− contributors may be used to endorse or promote products derived
1550− from this software without specific prior written permission.
1551−
1552− THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1553− "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1554− LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1555− A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1556− OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1557− SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1558− LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1559− DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1560− THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1561− (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1562− OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1563−
1564−semigroups LICENSE file:
1565−
1566− Copyright 2011-2015 Edward Kmett
1567−
1568− All rights reserved.
1569−
1570− Redistribution and use in source and binary forms, with or without
1571− modification, are permitted provided that the following conditions
1572− are met:
1573−
1574− 1. Redistributions of source code must retain the above copyright
1575− notice, this list of conditions and the following disclaimer.
1576−
1577− 2. Redistributions in binary form must reproduce the above copyright
1578− notice, this list of conditions and the following disclaimer in the
1579− documentation and/or other materials provided with the distribution.
1580−
1581− THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
1582− IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1583− WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1584− DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
1585− ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1586− DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1587− OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1588− HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
1589− STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
1590− ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1591− POSSIBILITY OF SUCH DAMAGE.
1592−
1593−sourcemap LICENSE file:
1594−
1595− Copyright (c) 2012, Chris Done
1596−
1597− All rights reserved.
1598−
1599− Redistribution and use in source and binary forms, with or without
1600− modification, are permitted provided that the following conditions are met:
1601−
1602− * Redistributions of source code must retain the above copyright
1603− notice, this list of conditions and the following disclaimer.
1604−
1605− * Redistributions in binary form must reproduce the above
1606− copyright notice, this list of conditions and the following
1607− disclaimer in the documentation and/or other materials provided
1608− with the distribution.
1609−
1610− * Neither the name of Chris Done nor the names of other
1611− contributors may be used to endorse or promote products derived
1612− from this software without specific prior written permission.
1613−
1614− THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1615− "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1616− LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1617− A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1618− OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1619− SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1620− LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1621− DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1622− THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1623− (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1624− OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1625−
1626−split LICENSE file:
1627−
1628− Copyright (c) 2008 Brent Yorgey, Louis Wasserman
1629−
1630− All rights reserved.
1631−
1632− Redistribution and use in source and binary forms, with or without
1633− modification, are permitted provided that the following conditions
1634− are met:
1635− 1. Redistributions of source code must retain the above copyright
1636− notice, this list of conditions and the following disclaimer.
1637− 2. Redistributions in binary form must reproduce the above copyright
1638− notice, this list of conditions and the following disclaimer in the
1639− documentation and/or other materials provided with the distribution.
1640− 3. Neither the name of the author nor the names of other contributors
1641− may be used to endorse or promote products derived from this software
1642− without specific prior written permission.
1643−
1644− THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND
1645− ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1646− IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1647− ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
1648− FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1649− DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1650− OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1651− HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1652− LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1653− OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1654− SUCH DAMAGE.
1655−
1656−stm LICENSE file:
1657−
1658− The Glasgow Haskell Compiler License
1659−
1660− Copyright 2004, The University Court of the University of Glasgow.
1661− All rights reserved.
1662−
1663− Redistribution and use in source and binary forms, with or without
1664− modification, are permitted provided that the following conditions are met:
1665−
1666− - Redistributions of source code must retain the above copyright notice,
1667− this list of conditions and the following disclaimer.
1668−
1669− - Redistributions in binary form must reproduce the above copyright notice,
1670− this list of conditions and the following disclaimer in the documentation
1671− and/or other materials provided with the distribution.
1672−
1673− - Neither name of the University nor the names of its contributors may be
1674− used to endorse or promote products derived from this software without
1675− specific prior written permission.
1676−
1677− THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY COURT OF THE UNIVERSITY OF
1678− GLASGOW AND THE CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
1679− INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
1680− FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
1681− UNIVERSITY COURT OF THE UNIVERSITY OF GLASGOW OR THE CONTRIBUTORS BE LIABLE
1682− FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1683− DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1684− SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
1685− CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1686− LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1687− OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
1688− DAMAGE.
1689−
1690−syb LICENSE file:
1691−
1692− This library (libraries/syb) is derived from code from several
1693− sources:
1694−
1695− * Code from the GHC project which is largely (c) The University of
1696− Glasgow, and distributable under a BSD-style license (see below),
1697−
1698− * Code from the Haskell 98 Report which is (c) Simon Peyton Jones
1699− and freely redistributable (but see the full license for
1700− restrictions).
1701−
1702− * Code from the Haskell Foreign Function Interface specification,
1703− which is (c) Manuel M. T. Chakravarty and freely redistributable
1704− (but see the full license for restrictions).
1705−
1706− The full text of these licenses is reproduced below. All of the
1707− licenses are BSD-style or compatible.
1708−
1709− -----------------------------------------------------------------------------
1710−
1711− The Glasgow Haskell Compiler License
1712−
1713− Copyright 2004, The University Court of the University of Glasgow.
1714− All rights reserved.
1715−
1716− Redistribution and use in source and binary forms, with or without
1717− modification, are permitted provided that the following conditions are met:
1718−
1719− - Redistributions of source code must retain the above copyright notice,
1720− this list of conditions and the following disclaimer.
1721−
1722− - Redistributions in binary form must reproduce the above copyright notice,
1723− this list of conditions and the following disclaimer in the documentation
1724− and/or other materials provided with the distribution.
1725−
1726− - Neither name of the University nor the names of its contributors may be
1727− used to endorse or promote products derived from this software without
1728− specific prior written permission.
1729−
1730− THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY COURT OF THE UNIVERSITY OF
1731− GLASGOW AND THE CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
1732− INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
1733− FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
1734− UNIVERSITY COURT OF THE UNIVERSITY OF GLASGOW OR THE CONTRIBUTORS BE LIABLE
1735− FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1736− DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1737− SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
1738− CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1739− LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1740− OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
1741− DAMAGE.
1742−
1743− -----------------------------------------------------------------------------
1744−
1745− Code derived from the document "Report on the Programming Language
1746− Haskell 98", is distributed under the following license:
1747−
1748− Copyright (c) 2002 Simon Peyton Jones
1749−
1750− The authors intend this Report to belong to the entire Haskell
1751− community, and so we grant permission to copy and distribute it for
1752− any purpose, provided that it is reproduced in its entirety,
1753− including this Notice. Modified versions of this Report may also be
1754− copied and distributed for any purpose, provided that the modified
1755− version is clearly presented as such, and that it does not claim to
1756− be a definition of the Haskell 98 Language.
1757−
1758− -----------------------------------------------------------------------------
1759−
1760− Code derived from the document "The Haskell 98 Foreign Function
1761− Interface, An Addendum to the Haskell 98 Report" is distributed under
1762− the following license:
1763−
1764− Copyright (c) 2002 Manuel M. T. Chakravarty
1765−
1766− The authors intend this Report to belong to the entire Haskell
1767− community, and so we grant permission to copy and distribute it for
1768− any purpose, provided that it is reproduced in its entirety,
1769− including this Notice. Modified versions of this Report may also be
1770− copied and distributed for any purpose, provided that the modified
1771− version is clearly presented as such, and that it does not claim to
1772− be a definition of the Haskell 98 Foreign Function Interface.
1773−
1774− -----------------------------------------------------------------------------
1775−
1776−tagged LICENSE file:
1777−
1778− Copyright (c) 2009-2015 Edward Kmett
1779− All rights reserved.
1780−
1781− Redistribution and use in source and binary forms, with or without
1782− modification, are permitted provided that the following conditions are
1783− met:
1784−
1785− * Redistributions of source code must retain the above copyright
1786− notice, this list of conditions and the following disclaimer.
1787−
1788− * Redistributions in binary form must reproduce the above
1789− copyright notice, this list of conditions and the following
1790− disclaimer in the documentation and/or other materials provided
1791− with the distribution.
1792−
1793− * Neither the name of Edward Kmett nor the names of other
1794− contributors may be used to endorse or promote products derived
1795− from this software without specific prior written permission.
1796−
1797− THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1798− "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1799− LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1800− A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1801− OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1802− SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1803− LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1804− DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1805− THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1806− (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1807− OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1808−
1809−template-haskell LICENSE file:
1810−
1811−
1812− The Glasgow Haskell Compiler License
1813−
1814− Copyright 2002-2007, The University Court of the University of Glasgow.
1815− All rights reserved.
1816−
1817− Redistribution and use in source and binary forms, with or without
1818− modification, are permitted provided that the following conditions are met:
1819−
1820− - Redistributions of source code must retain the above copyright notice,
1821− this list of conditions and the following disclaimer.
1822−
1823− - Redistributions in binary form must reproduce the above copyright notice,
1824− this list of conditions and the following disclaimer in the documentation
1825− and/or other materials provided with the distribution.
1826−
1827− - Neither name of the University nor the names of its contributors may be
1828− used to endorse or promote products derived from this software without
1829− specific prior written permission.
1830−
1831− THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY COURT OF THE UNIVERSITY OF
1832− GLASGOW AND THE CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
1833− INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
1834− FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
1835− UNIVERSITY COURT OF THE UNIVERSITY OF GLASGOW OR THE CONTRIBUTORS BE LIABLE
1836− FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1837− DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1838− SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
1839− CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1840− LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1841− OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
1842− DAMAGE.
1843−
1844−
1845−terminfo LICENSE file:
1846−
1847− Copyright 2007, Judah Jacobson.
1848− All Rights Reserved.
1849−
1850− Redistribution and use in source and binary forms, with or without
1851− modification, are permitted provided that the following conditions are met:
1852−
1853− - Redistribution of source code must retain the above copyright notice,
1854− this list of conditions and the following disclamer.
1855−
1856− - Redistribution in binary form must reproduce the above copyright notice,
1857− this list of conditions and the following disclamer in the documentation
1858− and/or other materials provided with the distribution.
1859−
1860− THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY
1861− EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1862− WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1863− DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR THE CONTRIBUTORS BE LIABLE
1864− FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1865− DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1866− SERVICES; LOSS OF USE, DATA OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
1867− CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
1868− OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
1869− USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1870−
1871−text LICENSE file:
1872−
1873− Copyright (c) 2008-2009, Tom Harper
1874− All rights reserved.
1875−
1876− Redistribution and use in source and binary forms, with or without
1877− modification, are permitted provided that the following conditions
1878− are met:
1879−
1880− * Redistributions of source code must retain the above copyright
1881− notice, this list of conditions and the following disclaimer.
1882−
1883− * Redistributions in binary form must reproduce the above
1884− copyright notice, this list of conditions and the following
1885− disclaimer in the documentation and/or other materials provided
1886− with the distribution.
1887−
1888− THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1889− "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1890− LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1891− A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1892− OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1893− SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1894− LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1895− DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1896− THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1897− (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1898− OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1899−
1900−time LICENSE file:
1901−
1902− TimeLib is Copyright (c) Ashley Yakeley, 2004-2014. All rights reserved.
1903− Certain sections are Copyright 2004, The University Court of the University of Glasgow. All rights reserved.
1904−
1905− Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1906−
1907− - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
1908−
1909− - Neither name of the copyright holders nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
1910−
1911− THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1912−
1913−transformers LICENSE file:
1914−
1915− The Glasgow Haskell Compiler License
1916−
1917− Copyright 2004, The University Court of the University of Glasgow.
1918− All rights reserved.
1919−
1920− Redistribution and use in source and binary forms, with or without
1921− modification, are permitted provided that the following conditions are met:
1922−
1923− - Redistributions of source code must retain the above copyright notice,
1924− this list of conditions and the following disclaimer.
1925−
1926− - Redistributions in binary form must reproduce the above copyright notice,
1927− this list of conditions and the following disclaimer in the documentation
1928− and/or other materials provided with the distribution.
1929−
1930− - Neither name of the University nor the names of its contributors may be
1931− used to endorse or promote products derived from this software without
1932− specific prior written permission.
1933−
1934− THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY COURT OF THE UNIVERSITY OF
1935− GLASGOW AND THE CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
1936− INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
1937− FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
1938− UNIVERSITY COURT OF THE UNIVERSITY OF GLASGOW OR THE CONTRIBUTORS BE LIABLE
1939− FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1940− DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1941− SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
1942− CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1943− LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1944− OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
1945− DAMAGE.
1946−
1947−transformers-base LICENSE file:
1948−
1949− Copyright (c) 2011, Mikhail Vorozhtsov, Bas van Dijk
1950− All rights reserved.
1951−
1952− Redistribution and use in source and binary forms, with or without
1953− modification, are permitted provided that the following conditions are met:
1954−
1955− - Redistributions of source code must retain the above copyright notice,
1956− this list of conditions and the following disclaimer.
1957− - Redistributions in binary form must reproduce the above copyright
1958− notice, this list of conditions and the following disclaimer in the
1959− documentation and/or other materials provided with the distribution.
1960− - Neither the names of the copyright owners nor the names of the
1961− contributors may be used to endorse or promote products derived
1962− from this software without specific prior written permission.
1963−
1964− THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1965− "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1966− LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1967− A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1968− OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1969− SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1970− LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1971− DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1972− THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1973− (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1974− OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1975−
1976−
1977−transformers-compat LICENSE file:
1978−
1979− Copyright 2012 Edward Kmett
1980−
1981− All rights reserved.
1982−
1983− Redistribution and use in source and binary forms, with or without
1984− modification, are permitted provided that the following conditions
1985− are met:
1986−
1987− 1. Redistributions of source code must retain the above copyright
1988− notice, this list of conditions and the following disclaimer.
1989−
1990− 2. Redistributions in binary form must reproduce the above copyright
1991− notice, this list of conditions and the following disclaimer in the
1992− documentation and/or other materials provided with the distribution.
1993−
1994− 3. Neither the name of the author nor the names of his contributors
1995− may be used to endorse or promote products derived from this software
1996− without specific prior written permission.
1997−
1998− THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
1999− IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
2000− WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2001− DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
2002− ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2003− DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2004− OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2005− HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
2006− STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
2007− ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2008− POSSIBILITY OF SUCH DAMAGE.
2009−
2010−unix LICENSE file:
2011−
2012− The Glasgow Haskell Compiler License
2013−
2014− Copyright 2004, The University Court of the University of Glasgow.
2015− All rights reserved.
2016−
2017− Redistribution and use in source and binary forms, with or without
2018− modification, are permitted provided that the following conditions are met:
2019−
2020− - Redistributions of source code must retain the above copyright notice,
2021− this list of conditions and the following disclaimer.
2022−
2023− - Redistributions in binary form must reproduce the above copyright notice,
2024− this list of conditions and the following disclaimer in the documentation
2025− and/or other materials provided with the distribution.
2026−
2027− - Neither name of the University nor the names of its contributors may be
2028− used to endorse or promote products derived from this software without
2029− specific prior written permission.
2030−
2031− THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY COURT OF THE UNIVERSITY OF
2032− GLASGOW AND THE CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
2033− INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
2034− FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
2035− UNIVERSITY COURT OF THE UNIVERSITY OF GLASGOW OR THE CONTRIBUTORS BE LIABLE
2036− FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2037− DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
2038− SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
2039− CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2040− LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2041− OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
2042− DAMAGE.
2043−
2044−unordered-containers LICENSE file:
2045−
2046− Copyright (c) 2010, Johan Tibell
2047−
2048− All rights reserved.
2049−
2050− Redistribution and use in source and binary forms, with or without
2051− modification, are permitted provided that the following conditions are met:
2052−
2053− * Redistributions of source code must retain the above copyright
2054− notice, this list of conditions and the following disclaimer.
2055−
2056− * Redistributions in binary form must reproduce the above
2057− copyright notice, this list of conditions and the following
2058− disclaimer in the documentation and/or other materials provided
2059− with the distribution.
2060−
2061− * Neither the name of Johan Tibell nor the names of other
2062− contributors may be used to endorse or promote products derived
2063− from this software without specific prior written permission.
2064−
2065− THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2066− "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2067− LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2068− A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2069− OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2070− SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2071− LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2072− DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2073− THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2074− (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2075− OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2076−
2077−utf8-string LICENSE file:
2078−
2079− * Copyright (c) 2007, Galois Inc.
2080− * All rights reserved.
2081− *
2082− * Redistribution and use in source and binary forms, with or without
2083− * modification, are permitted provided that the following conditions are met:
2084− * * Redistributions of source code must retain the above copyright
2085− * notice, this list of conditions and the following disclaimer.
2086− * * Redistributions in binary form must reproduce the above copyright
2087− * notice, this list of conditions and the following disclaimer in the
2088− * documentation and/or other materials provided with the distribution.
2089− * * Neither the name of Galois Inc. nor the
2090− * names of its contributors may be used to endorse or promote products
2091− * derived from this software without specific prior written permission.
2092− *
2093− * THIS SOFTWARE IS PROVIDED BY Galois Inc. ``AS IS'' AND ANY
2094− * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
2095− * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2096− * DISCLAIMED. IN NO EVENT SHALL Galois Inc. BE LIABLE FOR ANY
2097− * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
2098− * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
2099− * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
2100− * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2101− * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2102− * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2103−
2104−vector LICENSE file:
2105−
2106− Copyright (c) 2008-2012, Roman Leshchinskiy
2107− All rights reserved.
2108−
2109− Redistribution and use in source and binary forms, with or without
2110− modification, are permitted provided that the following conditions are met:
2111−
2112− - Redistributions of source code must retain the above copyright notice,
2113− this list of conditions and the following disclaimer.
2114−
2115− - Redistributions in binary form must reproduce the above copyright notice,
2116− this list of conditions and the following disclaimer in the documentation
2117− and/or other materials provided with the distribution.
2118−
2119− - Neither name of the University nor the names of its contributors may be
2120− used to endorse or promote products derived from this software without
2121− specific prior written permission.
2122−
2123− THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY COURT OF THE UNIVERSITY OF
2124− GLASGOW AND THE CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
2125− INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
2126− FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
2127− UNIVERSITY COURT OF THE UNIVERSITY OF GLASGOW OR THE CONTRIBUTORS BE LIABLE
2128− FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2129− DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
2130− SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
2131− CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2132− LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2133− OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
2134− DAMAGE.
2135−
2136−
2137−void LICENSE file:
2138−
2139− Copyright 2015 Edward Kmett
2140−
2141− All rights reserved.
2142−
2143− Redistribution and use in source and binary forms, with or without
2144− modification, are permitted provided that the following conditions
2145− are met:
2146−
2147− 1. Redistributions of source code must retain the above copyright
2148− notice, this list of conditions and the following disclaimer.
2149−
2150− 2. Redistributions in binary form must reproduce the above copyright
2151− notice, this list of conditions and the following disclaimer in the
2152− documentation and/or other materials provided with the distribution.
2153−
2154− 3. Neither the name of the author nor the names of his contributors
2155− may be used to endorse or promote products derived from this software
2156− without specific prior written permission.
2157−
2158− THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
2159− IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
2160− WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2161− DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
2162− ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2163− DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2164− OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2165− HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
2166− STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
2167− ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2168− POSSIBILITY OF SUCH DAMAGE.
2169−
11+ * Redistributions in binary form must reproduce the above
12+ copyright notice, this list of conditions and the following
13+ disclaimer in the documentation and/or other materials provided
14+ with the distribution.
15+
16+ * Neither the name of Author name here nor the names of other
17+ contributors may be used to endorse or promote products derived
18+ from this software without specific prior written permission.
19+
20+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
README-go.mdnew file+48
@@ -0,0 +1,48 @@
1+
2+### psgo
3+
4+#### Performance
5+
6+* No runtime system beyond some support types and functions
7+* Uses PureScript's normal tail call optimization techniques for generated Go code
8+
9+#### Differences from PureScript:
10+
11+* Foreign imports/exports are Go instead of JavaScript – see [standard library foreign implementations](https://github.com/andyarvanitis/purescript-native-go-ffi)
12+* No Go-specific REPL
13+
14+#### Other notes:
15+
16+* The provided `Any` type is just an alias for `interface{}`
17+* PureScript types are represented in Go with:
18+
19+ | PureScript | Go |
20+ |------------|----|
21+ |`Array` | `[]Any`|
22+ |`String` | `string`|
23+ |`Number` | `float64`|
24+ |`Int` | `int`|
25+ |`Char` | `string` (single UTF-8 entity)|
26+ |`Boolean` | `bool`|
27+ |Records | `map[string]Any`|
28+
29+#### Future ideas:
30+
31+* Nice facilities (modules) for concurrency/parallelism, using goroutines
32+
33+
34+#### Getting Started
35+This assumes you are running macOS (OS X) or a Unix-like system (Linux, *BSD, etc.).
36+
37+1. Choose a working directory wherever you like. Then create a `src` subdirectory under it, which will be where you will place your own PureScript source files.
38+
39+1. Initialize your project with `spago init`, and install any dependencies with `spago install` (please see their instructions if you haven't used it before).
40+
41+1. Add the `backend = "psgo"` option to your `spago.dhall` file. That way `spago` will use the psgo backend when compiling.
42+
43+1. You should now be ready to build a PureScript program:
44+ * As stated above, place your source file(s) in the working directory's `src` subdirectory and execute `spago build`.
45+
46+ * This will generate the Go source tree for your program and then build an executable binary. The resulting executable will be in your working directory and will be named `Main`. The generated source files will be under `output/`.
47+
48+---
README.md+32−20
@@ -1,29 +1,41 @@
1−[![PureScript](logo.png)](http://purescript.org)
1+[![PureScript](https://raw.githubusercontent.com/purescript/purescript/master/logo.png)](http://purescript.org)
22
3−A small strongly typed programming language with expressive types that compiles to Javascript, written in and inspired by Haskell.
3+This is a platform-native compiler backend for [PureScript](https://github.com/purescript/purescript). It attempts to generate "sane", debuggable, and portable [C++11](https://isocpp.org/wiki/faq/cpp11) (or later) or [Go](https://golang.org/) code as an intermediate language, which is then compiled to a native executable binary. This also enables easy interoperability with existing C/C++ or Go frameworks and libraries on a number of platforms.
44
5−[![Hackage](https://img.shields.io/hackage/v/purescript.svg)](http://hackage.haskell.org/package/purescript) [![Build Status](https://api.travis-ci.org/purescript/purescript.svg?branch=master)](http://travis-ci.org/purescript/purescript)
5+There are two utilities in the purescript-native "suite": `pscpp` and `psgo`. The source code in this branch is for `psgo`, the purescript-to-Go transpiler. For the source code of the `pscpp` purescript-to-C++ transpiler, please see the [cpp branch](https://github.com/andyarvanitis/purescript-native/tree/cpp).
66
7−[![Stackage LTS 2](http://stackage.org/package/purescript/badge/lts-2)](http://stackage.org/lts-2/package/purescript)
8−[![Stackage LTS 3](http://stackage.org/package/purescript/badge/lts-3)](http://stackage.org/lts-3/package/purescript)
9−[![Stackage Nightly](http://stackage.org/package/purescript/badge/nightly)](http://stackage.org/nightly/package/purescript)
7+#### Platforms
8+* Although purescript-native should work on any platform supporting PureScript and modern C++ or Go, the generated code and resulting binary executables have been tested on:
9+ * macOS Mojave 10.14.5 – full test suite
10+ * For C++, Xcode 10.2.1's `clang` was used
11+ * For Go, `go` version 1.12.7 was used
12+ * Windows 10 x64 – full test suite
13+ * C++: Visual Studio 2017 and `clang`
14+ * Go: `go` version 1.12.7
15+ * Linux Debian 9.5 amd64 – full test suite (C++)
16+ * Default versions of `clang` and `gcc`
17+ * Linux Debian 10 amd64 – full test suite (Go)
18+ * Default version of `go`
19+ * Raspberry Pi 3 B+ Raspbian official build (ARM), default versions of `clang` and `gcc`
1020
11−## Language info
1221
13−- [PureScript home](http://purescript.org)
14−- [Releases & changelog](https://github.com/purescript/purescript/releases)
15−- [Contributing to PureScript](https://github.com/purescript/purescript/blob/master/CONTRIBUTING.md)
22+#### Requirements for building `pscpp` and `psgo`
1623
17−## Resources
24+* [Haskell Stack](https://docs.haskellstack.org/en/stable/README/) (if you're running macOS 10.14.5+, you can use pre-built binaries from [here](https://github.com/andyarvanitis/purescript-native/releases/))
1825
19−- [PureScript book](https://leanpub.com/purescript/read)
20−- [Wiki](http://wiki.purescript.org)
21−- [Try PureScript](http://try.purescript.org)
22−- [Pursuit Package Index](http://pursuit.purescript.org/)
26+#### Requirements for using PureScript + purescript-native
2327
24−## Help!
28+* A recent version (0.13+) of [purescript](https://github.com/purescript/purescript/releases).
2529
26−- [#purescript IRC @ FreeNode](http://webchat.freenode.net/?channels=purescript)
27−- [PureScript on StackOverflow](http://stackoverflow.com/questions/tagged/purescript)
28−- [Google Group](https://groups.google.com/forum/#!forum/purescript)
29−- [Gitter Channel](https://gitter.im/purescript/purescript?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
30+* For `pscpp`, a C++11-capable toolchain, e.g. recent versions of clang, gcc, Microsoft Visual Studio
31+ * GNU Make + `psc-package` is the default supported build tool, but you should be able to use your favorite package manager, C++ build system, tools, debuggers, etc.
32+* For `psgo`, the [Go toolchain](https://golang.org) for your system
33+ * You can use your favorite PureScript package manager and build tools – but for simplicity, [`spago`](https://github.com/spacchetti/spago) is recommended.
34+
35+
36+#### For more information and a Getting Started guide, please see
37+* [`pscpp`](https://github.com/andyarvanitis/purescript-native/blob/cpp/README-cpp.md)
38+* [`psgo`](https://github.com/andyarvanitis/purescript-native/blob/golang/README-go.md)
39+
40+
41+---
Setup.hs−4
@@ -1,6 +1,2 @@
1−module Main where
2−
31import Distribution.Simple
4−
5−main :: IO ()
62main = defaultMain
app/Main.hsnew file+250
@@ -0,0 +1,250 @@
1+{-# LANGUAGE OverloadedStrings #-}
2+{-# LANGUAGE RankNTypes #-}
3+{-# LANGUAGE TemplateHaskell #-}
4+
5+module Main where
6+
7+import Control.Monad (when)
8+import qualified Control.Monad.Parallel as Par
9+import Data.Aeson
10+import Data.Aeson.Types
11+import Data.Char
12+import Data.FileEmbed (embedFile)
13+import Data.List (delete, intercalate, isPrefixOf, nub, partition, (\\))
14+import Data.Maybe
15+import Data.Monoid ((<>))
16+import Data.Version
17+import Control.Monad.Supply
18+import Control.Monad.Supply.Class
19+import Text.Printf
20+
21+import System.Environment
22+import System.Directory (createDirectoryIfMissing, doesDirectoryExist, doesFileExist, getCurrentDirectory, getModificationTime)
23+import System.FilePath ((</>), joinPath, splitDirectories, takeDirectory)
24+import System.FilePath.Find
25+import System.Process
26+
27+import Data.Text (Text)
28+import qualified Data.Text as T
29+import qualified Data.Text.Encoding as T
30+import qualified Data.Text.Lazy as L
31+import qualified Data.Text.Lazy.Encoding as L
32+import qualified Data.ByteString as B
33+
34+import Development.GitRev
35+
36+import Language.PureScript.AST.Literals
37+import Language.PureScript.CoreFn
38+import Language.PureScript.CoreFn.FromJSON
39+
40+import CodeGen.IL
41+import CodeGen.IL.Common
42+import CodeGen.IL.Printer
43+
44+import Tests
45+
46+data Command = Build | Run (Maybe String)
47+
48+parseJson :: Text -> Value
49+parseJson text
50+ | Just fileJson <- decode . L.encodeUtf8 $ L.fromStrict text = fileJson
51+ | otherwise = error "Bad json"
52+
53+jsonToModule :: Value -> Module Ann
54+jsonToModule value =
55+ case parse moduleFromJSON value of
56+ Success (_, r) -> r
57+ _ -> error "Failed parsing corefn. Psgo currently supports purescript <= 0.13.8"
58+
59+splitArgs :: [String] -> ([String], Maybe String, [String])
60+splitArgs args =
61+ let (opts, files) = partition (isPrefixOf "--") args
62+ opts' = (map . map) toLower opts
63+ (moduleName, files') =
64+ if null files
65+ then (Nothing, files)
66+ else
67+ if "--run" `elem` opts' && length (files) >= 1
68+ then do
69+ let file0 = head files
70+ files' = tail files
71+ case file0 of
72+ "Main.main" -> (Just "Main", files')
73+ "Test.Main.main" -> (Just "Test.Main", files')
74+ _ -> (Nothing, files)
75+ else (Nothing, files)
76+ in (opts, moduleName, files')
77+
78+main :: IO ()
79+main = do
80+ args <- getArgs
81+ -- let (opts, files) = partition (isPrefixOf "--") args
82+ let (opts, moduleName, files) = splitArgs args
83+ opts' = (map . map) toLower opts
84+ if "--tests" `elem` opts'
85+ then runTests
86+ else do
87+ if "--help" `elem` opts' || "--version" `elem` opts'
88+ then do
89+ when ("--help" `elem` opts') $ do
90+ putStrLn help
91+ when ("--version" `elem` opts') $ do
92+ let branch = $(gitBranch)
93+ details | branch == "golang" = "master, commit " ++ $(gitHash)
94+ | otherwise = branch
95+ putStrLn $ details ++ if $(gitDirty) then " (DIRTY)" else ""
96+ else do
97+ if null files
98+ then do
99+ currentDir <- getCurrentDirectory
100+ processFiles opts' [currentDir]
101+ else
102+ processFiles opts' files
103+ if "--run" `elem` opts
104+ then runBuildTool $ Run moduleName
105+ else when ("--no-build" `notElem` opts) $
106+ runBuildTool Build
107+ return ()
108+ where
109+ processFiles :: [String] -> [FilePath] -> IO ()
110+ processFiles opts [file] = do
111+ isDir <- doesDirectoryExist file
112+ if isDir then do
113+ files <- find always (fileName ==? corefn) file
114+ if null files
115+ then errorNoCorefnFiles
116+ else generateFiles opts files
117+ else generateFiles opts [file]
118+ processFiles opts files = do
119+ generateFiles opts files
120+ basePath :: [FilePath] -> FilePath
121+ basePath files =
122+ let filepath = takeDirectory (head files) in
123+ joinPath $ (init $ splitDirectories filepath)
124+ generateFiles :: [String] -> [FilePath] -> IO ()
125+ generateFiles opts files = do
126+ let baseOutpath = basePath files
127+ writeSupportFiles baseOutpath
128+ Par.mapM (generateCode opts baseOutpath) files
129+ return ()
130+ runBuildTool :: Command -> IO ()
131+ runBuildTool cmd = do
132+ project <- projectEnv
133+ case cmd of
134+ Build -> do
135+ callProcess "go" ["build", T.unpack project </> modPrefix' </> "Main"]
136+ Run moduleName -> do
137+ callProcess "go" ["run", T.unpack project </> modPrefix' </> fromMaybe "Main" moduleName]
138+ return ()
139+
140+generateCode :: [String] -> FilePath -> FilePath -> IO ()
141+generateCode opts baseOutpath jsonFile = do
142+ jsonModTime <- getModificationTime jsonFile
143+ let filepath = takeDirectory jsonFile
144+ dirparts = splitDirectories $ filepath
145+ mname = last dirparts
146+ basedir = joinPath $ init dirparts
147+ mname' = T.pack mname
148+ possibleFileName = basedir </> (T.unpack mname') </> implFileName mname'
149+ exists <- doesFileExist possibleFileName
150+ if exists
151+ then do
152+ modTime <- getModificationTime possibleFileName
153+ when (modTime < jsonModTime) $
154+ transpile opts baseOutpath jsonFile
155+ else transpile opts baseOutpath jsonFile
156+
157+transpile :: [String] -> FilePath -> FilePath -> IO ()
158+transpile opts baseOutpath jsonFile = do
159+ jsonText <- T.decodeUtf8 <$> B.readFile jsonFile
160+ project <- projectEnv
161+ let module' = jsonToModule $ parseJson jsonText
162+ ((_, foreigns, asts, implHeader, implFooter), _) <- runSupplyT 5 (moduleToIL module' project)
163+ let mn = moduleNameToIL' $ moduleName module'
164+ implementation = prettyPrintIL asts
165+ outpath = joinPath [baseOutpath, T.unpack mn]
166+ implPath = outpath </> implFileName mn
167+ createDirectoryIfMissing True outpath
168+ putStrLn implPath
169+ B.writeFile implPath $ T.encodeUtf8 (implHeader <> implementation <> implFooter)
170+
171+writeSupportFiles :: FilePath -> IO ()
172+writeSupportFiles baseOutpath = do
173+ currentDir <- getCurrentDirectory
174+ let outputdir = T.pack $ baseOutpath \\ currentDir
175+ ffiOutpath = currentDir </> subdir
176+ createDirectoryIfMissing True baseOutpath
177+ createDirectoryIfMissing True ffiOutpath
178+ writeModuleFile outputdir currentDir $(embedFile "support/go.mod.working")
179+ writeModuleFile outputdir baseOutpath $(embedFile "support/go.mod.output")
180+ writeModuleFile outputdir ffiOutpath $(embedFile "support/go.mod.ffi-loader")
181+ writeLoaderFile ffiOutpath $(embedFile "support/ffi-loader.go")
182+ where
183+ writeModuleFile :: Text -> FilePath -> B.ByteString -> IO ()
184+ writeModuleFile outputdir path modText = do
185+ let goModSource = path </> "go.mod"
186+ goModSourceExists <- doesFileExist goModSource
187+ when (not goModSourceExists) $ do
188+ project <- projectEnv
189+ let project' = T.unpack project
190+ outputdir' = tail $ T.unpack outputdir
191+ modText' = T.replace "$PROJECT" project $ T.decodeUtf8 modText
192+ replaceLoader = project' </> ffiLoader' <> "=." </> subdir
193+ replaceOutput = project' </> modPrefix' <> "=." </> outputdir'
194+ B.writeFile goModSource $ T.encodeUtf8 modText'
195+ callProcess "go" ["mod", "edit", "-replace", replaceLoader]
196+ callProcess "go" ["mod", "edit", "-replace", replaceOutput]
197+ callProcess "go" ["clean", "-modcache"]
198+ writeLoaderFile :: FilePath -> B.ByteString -> IO ()
199+ writeLoaderFile ffiOutpath loaderText = do
200+ let loaderSource = ffiOutpath </> "ffi_loader.go"
201+ loaderSourceExists <- doesFileExist loaderSource
202+ when (not loaderSourceExists) $ do
203+ B.writeFile loaderSource loaderText
204+
205+implFileName :: Text -> FilePath
206+implFileName mn = ((\c -> if c == '.' then '_' else c) <$> T.unpack mn) <> ".go"
207+
208+projectEnv :: IO Text
209+projectEnv = do
210+ T.pack . fromMaybe defaultProject <$> lookupEnv goproject
211+
212+help :: String
213+help = "Usage: psgo OPTIONS COREFN-FILES\n\
214+ \ PureScript to native (via go) compiler\n\n\
215+ \Available options:\n\
216+ \ --help Show this help text\n\n\
217+ \ --version Show the version number\n\n\
218+ \ --run Run the generated go code directly, without building an\n\
219+ \ executable\n\
220+ \ --no-build Generate go source files, but do not build an executable\n\
221+ \ --tests Run test cases (under construction)\n\n\
222+ \See also:\n\
223+ \ purs compile --help\n"
224+
225+corefn :: String
226+corefn = "corefn.json"
227+
228+goSrc :: String
229+goSrc = ".go"
230+
231+goproject :: String
232+goproject = "GOPROJECT"
233+
234+defaultProject :: String
235+defaultProject = "project.localhost"
236+
237+modPrefix' :: String
238+modPrefix' = T.unpack modPrefix
239+
240+ffiLoader' :: String
241+ffiLoader' = T.unpack ffiLoader
242+
243+subdir :: String
244+subdir = T.unpack modLabel
245+
246+errorNoCorefnFiles :: IO ()
247+errorNoCorefnFiles = do
248+ ioError . userError $ "no compiled purescript '" <> corefn <> "' files found –\n" <>
249+ " make sure to use the '--codegen corefn' option with your purs\n" <>
250+ " project build tool"
appveyor.ymldeleted−57
@@ -1,57 +0,0 @@
1−platform: x64
2−version: '{build}'
3−environment:
4− # Keep the path as short as possible, just in case.
5− STACK_ROOT: c:\s
6− # Appveyor does not seem to be able to cope with the symbolic link
7− # stack.yaml, so this is a workaround.
8− STACK_YAML: stack-lts-5.yaml
9− RELEASE_USER: purescript
10− RELEASE_REPO: purescript
11−cache:
12−- c:\s
13−install:
14−- git submodule update --init
15−- ps: Install-Product node 5
16−- npm install -g bower
17−
18−- ps: |
19− New-Item -ItemType Directory -Force -Path C:\tools
20− $env:Path += ";C:\tools"
21− (New-Object Net.WebClient).DownloadFile('https://www.stackage.org/stack/windows-x86_64', 'c:\tools\stack.zip')
22− pushd c:\tools
23− 7z x c:\tools\stack.zip stack.exe
24− popd
25−
26−- stack --no-terminal --verbosity=error setup 1>stack-setup.log 2>&1 || type stack-setup.log
27−
28−build_script:
29−# Override the default build script.
30−- echo ""
31−test_script:
32−- stack -j1 --no-terminal test --pedantic
33−on_success:
34−# this seems to be necessary; if omitted, the bash script fails to find the
35−# tool 'strip'.
36−- copy C:\MinGW\bin\strip.exe C:\tools\strip.exe
37−- ps: |
38− function UploadFile
39− {
40− github-release upload --user $env:RELEASE_USER --repo $env:RELEASE_REPO --tag $env:APPVEYOR_REPO_TAG_NAME --file $args[0] --name $args[0]
41− }
42−
43− if ($env:APPVEYOR_REPO_TAG_NAME)
44− {
45− bash ./bundle/build-stack.sh win64
46−
47− (New-Object Net.WebClient).DownloadFile('https://github.com/aktau/github-release/releases/download/v0.6.2/windows-amd64-github-release.zip', 'c:\tools\github-release.zip')
48− pushd c:\tools
49− 7z x github-release.zip bin/windows/amd64/github-release.exe
50− Copy-Item bin/windows/amd64/github-release.exe github-release.exe
51− popd
52−
53− pushd bundle
54− UploadFile win64.tar.gz
55− UploadFile win64.sha
56− popd
57− }
bundle/.gitignoredeleted−4
@@ -1,4 +0,0 @@
1−build/
2−*.tar.gz
3−*.sha
4−*.md5
bundle/READMEdeleted−24
@@ -1,24 +0,0 @@
1− ____ ____ _ _
2−| _ \ _ _ _ __ ___/ ___| ___ _ __(_)_ __ | |_
3−| |_) | | | | '__/ _ \___ \ / __| '__| | '_ \| __|
4−| __/| |_| | | | __/___) | (__| | | | |_) | |_
5−|_| \__,_|_| \___|____/ \___|_| |_| .__/ \__|
6− |_|
7−
8−Installation Instructions
9−-------------------------
10−
11−This bundle contains the following executables:
12−
13−- psc The PureScript compiler
14−- psci The PureScript interactive REPL (requires NodeJS)
15−- psc-docs A Markdown documentation generator for PureScript code
16−- psc-bundle Bundles together CommonJS modules produced by `psc` into a
17− single JavaScript file; useful for running in the browser.
18−- psc-publish Generates documentation packages for uploading to Pursuit
19−- psc-ide-server Provides Editor Support in the form of type information and
20− autocompletion
21−- psc-ide-client Utility to query psc-ide-server
22−
23−Copy these files anywhere on your PATH.
24−
bundle/build-stack.shdeleted−63
@@ -1,63 +0,0 @@
1−## This script can be run on any supported OS to create a binary .tar.gz
2−## bundle.
3−## For Windows, msysgit contains all of the pieces needed to run this script.
4−set -e
5−
6−OS=$1
7−
8−if [ -z $OS ]
9−then
10− echo "Usage: build.sh osname"
11− exit 1
12−fi
13−
14−pushd $(stack path --project-root)
15−
16−LOCAL_INSTALL_ROOT=$(stack path --local-install-root)
17−
18−if [ "$OS" = "win64" ]
19−then
20− BIN_EXT=".exe"
21−else
22− BIN_EXT=""
23−fi
24−
25−# Make the staging directory
26−mkdir -p bundle/build/purescript
27−
28−# Strip the binaries, and copy them to the staging directory
29−for BIN in psc psci psc-docs psc-publish psc-bundle psc-ide-server psc-ide-client
30−do
31− FULL_BIN="$LOCAL_INSTALL_ROOT/bin/${BIN}${BIN_EXT}"
32− strip "$FULL_BIN" || true # not the end of the world if this fails, and
33− # AppVeyor can't seem to handle it for some reason
34− cp "$FULL_BIN" bundle/build/purescript
35−done
36−
37−# Copy extra files to the staging directory
38−cp bundle/README bundle/build/purescript/
39−cp LICENSE bundle/build/purescript/
40−cp INSTALL.md bundle/build/purescript/
41−
42−stack list-dependencies >bundle/build/purescript/dependencies.txt
43−
44−# Make the binary bundle
45−pushd bundle/build > /dev/null
46−tar -zcvf ../${OS}.tar.gz purescript
47−popd > /dev/null
48−
49−# Calculate the SHA hash
50−if [ "$OS" = "win64" ]
51−then
52− # msys/mingw does not include shasum. :(
53− SHASUM="openssl dgst -sha1"
54−else
55− SHASUM="shasum"
56−fi
57−
58−$SHASUM bundle/${OS}.tar.gz > bundle/${OS}.sha
59−
60−# Remove the staging directory
61−rm -rf build/
62−
63−popd > /dev/null
core-tests/.gitignoredeleted−2
@@ -1,2 +0,0 @@
1−bower_components/
2−output/
core-tests/test-everything.shdeleted−79
@@ -1,79 +0,0 @@
1−#!/bin/bash
2−
3−set -e
4−
5−force_recompile='false'
6−force_reinstall='false'
7−
8−while getopts 'ci' flag; do
9− case "${flag}" in
10− c) force_recompile='true' ;;
11− i) force_reinstall='true' ;;
12− *) error "Unexpected option ${flag}" ;;
13− esac
14−done
15−
16−if [ "$force_reinstall" = "true" ] && [ -d "bower_components" ]; then
17− echo "Reinstalling core packages..."
18− rm -r bower_components
19−fi
20−
21−bower i \
22− purescript-prelude \
23− purescript-eff \
24− purescript-st \
25− purescript-integers \
26− purescript-functions \
27− purescript-console \
28− purescript-profunctor \
29− purescript-contravariant \
30− purescript-parallel \
31− purescript-control \
32− purescript-tailrec \
33− purescript-maps \
34− purescript-free \
35− purescript-transformers \
36− purescript-exists \
37− purescript-monoid \
38− purescript-either \
39− purescript-maybe \
40− purescript-inject \
41− purescript-graphs \
42− purescript-enums \
43− purescript-unfoldable \
44− purescript-coproducts \
45− purescript-lazy \
46− purescript-distributive \
47− purescript-identity \
48− purescript-bifunctors \
49− purescript-const \
50− purescript-sets \
51− purescript-quickcheck \
52− purescript-foreign \
53− purescript-foldable-traversable \
54− purescript-tuples \
55− purescript-strings \
56− purescript-arrays \
57− purescript-random \
58− purescript-refs \
59− purescript-globals \
60− purescript-exceptions \
61− purescript-validation \
62− purescript-parallel \
63− purescript-proxy \
64− purescript-semirings \
65− purescript-math \
66− purescript-generics
67−
68−if [ "$force_recompile" = "true" ] && [ -d "output" ]; then
69− echo "Recompiling..."
70− rm -r output
71−fi
72−
73−../dist/build/psc/psc tests/*/*.purs \
74− 'bower_components/purescript-*/src/**/*.purs' \
75− --ffi 'bower_components/purescript-*/src/**/*.js'
76−
77−../dist/build/psc-docs/psc-docs tests/*/*.purs \
78− 'bower_components/purescript-*/src/**/*.purs' \
79− > full-core-docs.md
core-tests/tests/generic-deriving/Main.pursdeleted−27
@@ -1,27 +0,0 @@
1−module GenericDeriving where
2−
3−import Prelude
4−
5−import Control.Monad.Eff (Eff())
6−import Control.Monad.Eff.Console (CONSOLE())
7−import Data.Generic
8−
9−data Void
10−
11−derive instance genericVoid :: Generic Void
12−
13−data A a
14− = A Number String
15− | B Int
16− | C (Array (A a))
17− | D { "asgård" :: a }
18− | E Void
19−
20−derive instance genericA :: (Generic b) => Generic (A b)
21−
22−newtype X b = X b
23−
24−derive instance genericX :: Generic (X String)
25−
26−main :: forall eff. Eff (console :: CONSOLE | eff) Unit
27−main = Control.Monad.Eff.Console.log (gShow (D { "asgård": C [ A 1.0 "test", B 42, D { "asgård": true } ] }))
default.nixnew file+23
@@ -0,0 +1,23 @@
1+let
2+ haskellNix = import (builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz) {};
3+ nixpkgsSrc = haskellNix.sources.nixpkgs-1903; # has hsc2hs-0.68.4
4+
5+ hsc2hsOverlay = self: super: {
6+ buildPackages = super.buildPackages // {
7+ hsc2hs = super.haskellPackages.hsc2hs;
8+ };
9+ };
10+
11+ nixpkgsArgs = haskellNix.nixpkgsArgs // {
12+ overlays = haskellNix.nixpkgsArgs.overlays ++ [ hsc2hsOverlay ];
13+ };
14+in
15+{ pkgs ? import nixpkgsSrc nixpkgsArgs
16+}:
17+
18+pkgs.haskell-nix.stackProject {
19+ src = pkgs.haskell-nix.haskellLib.cleanGit {
20+ name = "purescript-native";
21+ src = ./.;
22+ };
23+}
examples/.gitignoredeleted−1
@@ -1 +0,0 @@
1−shelltest/tests
examples/docs/LICENSEdeleted−1
@@ -1 +0,0 @@
1−This isn't a real license, it's just here for the sake of the tests.
examples/docs/bower.jsondeleted−20
@@ -1,20 +0,0 @@
1−{
2− "name": "docs-test-package",
3− "version": "1.0.0",
4− "moduleType": [
5− "node"
6− ],
7− "repository": {
8− "type": "git",
9− "url": "git://github.com/not-real/not-a-real-repo.git"
10− },
11− "ignore": [
12− "**/.*",
13− "node_modules",
14− "bower_components",
15− "output"
16− ],
17− "dependencies": {
18− },
19− "license": "replaceme"
20−}
examples/docs/bower_components/purescript-prelude/src/Prelude.pursdeleted−8
@@ -1,8 +0,0 @@
1−module Prelude where
2−
3−newtype Unit = Unit {}
4−
5−unit :: Unit
6−unit = Unit {}
7−
8−data Boolean2 = True | False
examples/docs/src/Clash.pursdeleted−32
@@ -1,32 +0,0 @@
1−module Clash (module Clash1) where
2−
3−import Clash1 as Clash1
4−import Clash2 as Clash2
5−
6−module Clash1 (module Clash1a) where
7−
8−import Clash1a
9−
10−module Clash1a where
11−
12−value :: Int
13−value = 0
14−
15−type Type = Int
16−
17−class TypeClass a where
18− typeClassMember :: a
19−
20−module Clash2 (module Clash2a) where
21−
22−import Clash2a
23−
24−module Clash2a where
25−
26−value :: String
27−value = "hello"
28−
29−type Type = String
30−
31−class TypeClass a b where
32− typeClassMember :: a -> b
examples/docs/src/ConstrainedArgument.pursdeleted−9
@@ -1,9 +0,0 @@
1−module ConstrainedArgument where
2−
3−class Foo t
4−
5−type WithoutArgs = forall a. (Partial => a) -> a
6−type WithArgs = forall a. (Foo a => a) -> a
7−type MultiWithoutArgs = forall a. ((Partial, Partial) => a) -> a
8−type MultiWithArgs = forall a b. ((Foo a, Foo b) => a) -> a
9−
examples/docs/src/DuplicateNames.pursdeleted−9
@@ -1,9 +0,0 @@
1−module DuplicateNames
2− ( module DuplicateNames
3− , module Prelude
4− ) where
5−
6−import Prelude (Unit)
7−
8−unit :: Int
9−unit = 0
examples/docs/src/Example.pursdeleted−7
@@ -1,7 +0,0 @@
1−module Example
2− ( module Prelude
3− , module Example2
4− ) where
5−
6−import Prelude (Unit())
7−import Example2 (one)
examples/docs/src/Example2.pursdeleted−7
@@ -1,7 +0,0 @@
1−module Example2 where
2−
3−one :: Int
4−one = 1
5−
6−two :: Int
7−two = 2
examples/docs/src/ExplicitTypeSignatures.pursdeleted−16
@@ -1,16 +0,0 @@
1−
2−module ExplicitTypeSignatures where
3−
4−-- This should use the explicit type signature so that the type variable name
5−-- is preserved.
6−explicit :: forall something. something -> something
7−explicit x
8− | true = x
9− | false = x
10−
11−-- This should use the inferred type.
12−anInt :: _
13−anInt = 0
14−
15−-- This should infer a type.
16−aNumber = 1.0
examples/docs/src/ImportedTwice.pursdeleted−27
@@ -1,27 +0,0 @@
1−-- See also an example in the wild: purescript-transformers v0.8.4.
2−-- Control.Monad.RWS.Trans re-exports `lift` from both Control.Monad.Trans
3−-- (where it is originally defined) and Control.Monad.RWS.Class (which
4−-- re-exports it from Control.Monad.Trans).
5−
6−module ImportedTwice
7− ( module A
8− , module B
9− )
10− where
11−
12−import A
13−import B
14−
15−module A
16− ( module B )
17− where
18−
19−import B
20−
21−bar :: Int
22−bar = 1
23−
24−module B where
25−
26−foo :: Int
27−foo = 0
examples/docs/src/MultiVirtual.pursdeleted−27
@@ -1,27 +0,0 @@
1−module MultiVirtual
2− ( module X )
3− where
4−
5−import MultiVirtual1 as X
6−import MultiVirtual2 as X
7−
8−
9−module MultiVirtual1 where
10−
11−foo :: Int
12−foo = 1
13−
14−module MultiVirtual2
15− ( module MultiVirtual2
16− , module MultiVirtual3
17− ) where
18−
19−import MultiVirtual3
20−
21−bar :: Int
22−bar = 2
23−
24−module MultiVirtual3 where
25−
26−baz :: Int
27−baz = 3
examples/docs/src/NewOperators.pursdeleted−12
@@ -1,12 +0,0 @@
1−module NewOperators
2− ( module NewOperators2 )
3− where
4−
5−import NewOperators2
6−
7−module NewOperators2 where
8−
9−infixl 8 _compose as >>>
10−
11−_compose :: forall a b c. (b -> c) -> (a -> b) -> (a -> c)
12−_compose f g x = f (g x)
examples/docs/src/NotAllCtors.pursdeleted−5
@@ -1,5 +0,0 @@
1−module NotAllCtors
2− ( module Prelude )
3− where
4−
5−import Prelude (Boolean2(True))
examples/docs/src/OldOperators.pursdeleted−10
@@ -1,10 +0,0 @@
1−
2−-- Remove this after 0.9.
3−module OldOperators (module OldOperators2) where
4−
5−import OldOperators2
6−
7−module OldOperators2 where
8−
9−(>>) :: forall a. a -> a -> a
10−(>>) a b = b
examples/docs/src/ReExportedTypeClass.pursdeleted−5
@@ -1,5 +0,0 @@
1−module ReExportedTypeClass
2− ( module SomeTypeClass )
3− where
4−
5−import SomeTypeClass
examples/docs/src/SolitaryTypeClassMember.pursdeleted−6
@@ -1,6 +0,0 @@
1−module SolitaryTypeClassMember
2− ( module SomeTypeClass )
3− where
4−
5−import SomeTypeClass (member)
6−
examples/docs/src/SomeTypeClass.pursdeleted−5
@@ -1,5 +0,0 @@
1−
2−module SomeTypeClass where
3−
4−class SomeClass a where
5− member :: a
examples/docs/src/Transitive1.pursdeleted−5
@@ -1,5 +0,0 @@
1−module Transitive1
2− ( module Transitive2 )
3− where
4−
5−import Transitive2
examples/docs/src/Transitive2.pursdeleted−5
@@ -1,5 +0,0 @@
1−module Transitive2
2− ( module Transitive3 )
3− where
4−
5−import Transitive3
examples/docs/src/Transitive3.pursdeleted−4
@@ -1,4 +0,0 @@
1−module Transitive3 where
2−
3−transitive3 :: Int
4−transitive3 = 0
examples/docs/src/TypeClassWithoutMembers.pursdeleted−11
@@ -1,11 +0,0 @@
1−module TypeClassWithoutMembers
2− ( module Intermediate )
3− where
4−
5−import Intermediate
6−
7−module Intermediate
8− ( module SomeTypeClass )
9− where
10−
11−import SomeTypeClass (SomeClass)
examples/docs/src/UTF8.pursdeleted−7
@@ -1,7 +0,0 @@
1−module UTF8 where
2−
3−import Prelude (Unit, unit)
4−
5−-- | üÜäÄ 😰
6−thing :: Unit
7−thing = unit
examples/docs/src/Virtual.pursdeleted−5
@@ -1,5 +0,0 @@
1−module Virtual
2− ( module VirtualPrelude )
3− where
4−
5−import Prelude as VirtualPrelude
examples/failing/1071.pursdeleted−8
@@ -1,8 +0,0 @@
1−-- @shouldFailWith KindsDoNotUnify
2−module Main where
3−
4−class Foo a b where
5− foo :: a -> b
6−
7−bar :: forall a. (Foo a) => a -> a
8−bar a = a
examples/failing/1169.pursdeleted−12
@@ -1,12 +0,0 @@
1−-- @shouldFailWith IncorrectConstructorArity
2−module Test where
3−
4−data Outer a = Outer a
5−
6−data Inner a b = Inner a b
7−
8−test1 :: forall a b. Outer (Inner a b) -> Boolean
9−test1 (Outer (Inner _)) = true
10−
11−test2 :: forall a b. Inner a b -> Boolean
12−test2 (Inner _) = true
examples/failing/1175.pursdeleted−11
@@ -1,11 +0,0 @@
1−-- @shouldFailWith TypesDoNotUnify
2−module X where
3−
4−class Foo where
5− foo :: String
6−
7−instance f :: Foo where
8− foo = "a"
9− where
10− bar :: String
11− bar = 1
examples/failing/1310.pursdeleted−18
@@ -1,18 +0,0 @@
1−-- @shouldFailWith NoInstanceFound
2−
3−module Issue1310 where
4−
5−import Prelude
6−import Control.Monad.Eff
7−import Control.Monad.Eff.Console
8−
9−class Inject f g where
10− inj :: forall a. f a -> g a
11−
12−instance inject :: Inject f f where
13− inj x = x
14−
15−foreign import data Oops :: !
16−
17−main :: forall eff. Eff (oops :: Oops | eff) Unit
18−main = inj (log "Oops")
examples/failing/1570.pursdeleted−6
@@ -1,6 +0,0 @@
1−-- @shouldFailWith ExpectedType
2−module M where
3−
4−data F a = F a
5−
6−test = \(x :: F) -> x
examples/failing/1733.pursdeleted−13
@@ -1,13 +0,0 @@
1−-- @shouldFailWith UnknownValue
2−
3−module Main where
4−
5−import Thingy as Thing
6−
7−main = Thing.doesntExist "hi"
8−
9−module Thingy where
10−
11−foo :: Int
12−foo = 1
13−
examples/failing/1825.pursdeleted−9
@@ -1,9 +0,0 @@
1−-- @shouldFailWith UnknownValue
2−
3−module Main where
4−
5−data W = X | Y | Z
6−
7−bad X a = a
8−bad Y _ = a
9−bad Z a = a
examples/failing/365.pursdeleted−14
@@ -1,14 +0,0 @@
1−-- @shouldFailWith CycleInDeclaration
2−module Main where
3−
4−import Prelude
5−
6−class C a where
7− f :: a -> a
8− g :: a -> a
9−
10−instance cS :: C String where
11− f s = s
12− g = f
13−
14−main = g "Done"
examples/failing/438.pursdeleted−15
@@ -1,15 +0,0 @@
1−-- @shouldFailWith PossiblyInfiniteInstance
2−
3−-- See issue 438 for details: this test is mainly here to test that code like
4−-- this doesn't cause the compiler to loop.
5−
6−module Main where
7−
8−import Prelude
9−
10−data Fix f = In (f (Fix f))
11−
12−instance eqFix :: (Eq (f (Fix f))) => Eq (Fix f) where
13− eq (In f) (In g) = f == g
14−
15−example = In [] == In []
examples/failing/881.pursdeleted−13
@@ -1,13 +0,0 @@
1−-- @shouldFailWith DuplicateValueDeclaration
2−module Main where
3−
4−data X = X | Y
5−
6−class Foo a where
7− foo :: a -> a
8− bar :: a
9−
10−instance fooX :: Foo X where
11− foo X = X
12− bar = X
13− foo Y = Y
examples/failing/AnonArgument1.pursdeleted−5
@@ -1,5 +0,0 @@
1−-- @shouldFailWith IncorrectAnonymousArgument
2−module Main where
3−
4−test :: Int -> Int
5−test = _
examples/failing/AnonArgument2.pursdeleted−7
@@ -1,7 +0,0 @@
1−-- @shouldFailWith IncorrectAnonymousArgument
2−module Main where
3−
4−import Prelude
5−
6−test :: Int -> Int
7−test = 1 + 2 * _
examples/failing/AnonArgument3.pursdeleted−5
@@ -1,5 +0,0 @@
1−-- @shouldFailWith IncorrectAnonymousArgument
2−module Main where
3−
4−test :: Int -> Int
5−test = 1 + _
examples/failing/ArrayType.pursdeleted−14
@@ -1,14 +0,0 @@
1−-- @shouldFailWith TypesDoNotUnify
2−
3−module Main where
4−
5−import Prelude
6−import Control.Monad.Eff.Console
7−
8−bar :: Number -> Number -> Number
9−bar n m = n + m
10−
11−foo = x `bar` y
12− where
13− x = 1
14− y = []
examples/failing/Arrays.pursdeleted−8
@@ -1,8 +0,0 @@
1−-- @shouldFailWith TypesDoNotUnify
2−module Main where
3−
4−import Prelude
5−
6−foreign import (!!) :: forall a. Array a -> Int -> a
7−
8−test = \arr -> arr !! (0 !! 0)
examples/failing/CaseBinderLengthsDiffer.pursdeleted−6
@@ -1,6 +0,0 @@
1−-- @shouldFailWith CaseBinderLengthDiffers
2−module Main where
3−
4−test = case 1, 2 of
5− 1, 2, 3 -> 42
6− _, _ -> 43
examples/failing/CaseDoesNotMatchAllConstructorArgs.pursdeleted−15
@@ -1,15 +0,0 @@
1−-- @shouldFailWith IncorrectConstructorArity
2−module Main where
3−
4−import Prelude
5−
6−data Person = Person String Int
7−
8−data TwoPeople = Two Person Person
9−
10−getName p = case p of
11− (Two (Person n) (Person n2 a2)) -> n
12− _ -> "Unknown"
13−
14−
15−name = getName (Two (Person "Jimmy" 20) (Person "" 1))
examples/failing/ConflictingExports.pursdeleted−16
@@ -1,16 +0,0 @@
1−-- @shouldFailWith ScopeConflict
2−module A where
3−
4− thing :: Int
5− thing = 1
6−
7−module B where
8−
9− thing :: Int
10− thing = 2
11−
12−-- Fails here because re-exporting forces any scope conflicts to be resolved
13−module Main (module A, module B) where
14−
15− import A
16− import B
examples/failing/ConflictingImports.pursdeleted−19
@@ -1,19 +0,0 @@
1−-- @shouldFailWith ScopeConflict
2−module A where
3−
4− thing :: Int
5− thing = 1
6−
7−module B where
8−
9− thing :: Int
10− thing = 2
11−
12−module Main where
13−
14− import A
15− import B
16−
17− -- Error due to referencing `thing` which is in scope as A.thing and B.thing
18− what :: Int
19− what = thing
examples/failing/ConflictingImports2.pursdeleted−20
@@ -1,20 +0,0 @@
1−-- @shouldFailWith ScopeConflict
2−module A where
3−
4− thing :: Int
5− thing = 1
6−
7−module B where
8−
9− thing :: Int
10− thing = 2
11−
12−module Main where
13−
14− import A (thing)
15− import B (thing)
16−
17− -- Error due to referencing `thing` which is explicitly in scope as A.thing
18− -- and B.thing
19− what :: Int
20− what = thing
examples/failing/ConflictingQualifiedImports.pursdeleted−17
@@ -1,17 +0,0 @@
1−-- @shouldFailWith ScopeConflict
2−module A where
3−
4− thing :: Int
5− thing = 1
6−
7−module B where
8−
9− thing :: Int
10− thing = 2
11−
12−module Main where
13−
14− import A as X
15− import B as X
16−
17− foo = X.thing
examples/failing/ConflictingQualifiedImports2.pursdeleted−15
@@ -1,15 +0,0 @@
1−-- @shouldFailWith ScopeConflict
2−module A where
3−
4− thing :: Int
5− thing = 1
6−
7−module B where
8−
9− thing :: Int
10− thing = 2
11−
12−module Main (module X) where
13−
14− import A as X
15− import B as X
examples/failing/ConstraintInference.pursdeleted−10
@@ -1,10 +0,0 @@
1−-- @shouldFailWith NoInstanceFound
2−
3−module Main where
4−
5−import Prelude
6−
7−spin :: forall a b. a -> b
8−spin x = spin x
9−
10−test = show <<< spin
examples/failing/DctorOperatorAliasExport.pursdeleted−6
@@ -1,6 +0,0 @@
1−-- @shouldFailWith TransitiveDctorExportError
2−module Data.List (List, (:)) where
3−
4− data List a = Cons a (List a) | Nil
5−
6− infixr 6 Cons as :
examples/failing/Do.pursdeleted−12
@@ -1,12 +0,0 @@
1−-- @shouldFailWith InvalidDoBind
2−-- @shouldFailWith InvalidDoLet
3−module Main where
4−
5−import Prelude
6−
7−test1 = do let x = 1
8−
9−test2 y = do x <- y
10−
11−test3 = do return 1
12− return 2
examples/failing/DoNotSuggestComposition.pursdeleted−13
@@ -1,13 +0,0 @@
1−-- @shouldFailWith TypesDoNotUnify
2−-- TODO: Check that this does not produce a "function composition is (<<<)"
3−-- suggestion.
4−module DoNotSuggestComposition where
5−
6−import Prelude
7−
8−x = { y: 3 }
9−
10−foo :: String -> String
11−foo y = y
12−
13−bar = foo x
examples/failing/DoNotSuggestComposition2.pursdeleted−7
@@ -1,7 +0,0 @@
1−-- @shouldFailWith CannotApplyFunction
2−-- TODO: Check that this does not produce a "function composition is (<<<)"
3−-- suggestion.
4−
5−module DoNotSuggestComposition2 where
6−
7−foo = let x = { y: 3 } in x 2
examples/failing/DuplicateDeclarationsInLet.pursdeleted−12
@@ -1,12 +0,0 @@
1−-- @shouldFailWith OverlappingNamesInLet
2−module Main where
3−
4−import Prelude
5−
6−foo = a
7− where
8− a :: Number
9− a = 1
10−
11− a :: Number
12− a = 2
examples/failing/DuplicateProperties1.pursdeleted−12
@@ -1,12 +0,0 @@
1−-- @shouldFailWith TypesDoNotUnify
2−module DuplicateProperties where
3−
4−import Prelude
5−
6−foreign import data Test :: # * -> *
7−
8−foreign import subtractX :: forall r. Test (x :: Unit | r) -> Test r
9−
10−foreign import hasX :: Test (x :: Unit, y :: Unit)
11−
12−baz = subtractX (subtractX hasX)
examples/failing/DuplicateProperties2.pursdeleted−12
@@ -1,12 +0,0 @@
1−-- @shouldFailWith DuplicateLabel
2−module DuplicateProperties where
3−
4−import Prelude
5−
6−foreign import data Test :: # * -> *
7−
8−foreign import subtractX :: forall r. Test (x :: Unit | r) -> Test r
9−
10−foreign import hasX :: forall r. Test (x :: Unit, y :: Unit | r)
11−
12−baz = subtractX (subtractX hasX)
examples/failing/DuplicateTypeVars.pursdeleted−6
@@ -1,6 +0,0 @@
1−-- @shouldFailWith DuplicateTypeArgument
2−module Main where
3−
4−import Prelude
5−
6−type Foo a a = a
examples/failing/Eff.pursdeleted−13
@@ -1,13 +0,0 @@
1−-- @shouldFailWith TypesDoNotUnify
2−module Main where
3−
4−import Prelude
5−import Control.Monad.Eff
6−import Control.Monad.ST
7−import Control.Monad.Eff.Console
8−
9−test = pureST (do
10− ref <- newSTRef 0
11− log "ST"
12− modifySTRef ref $ \n -> n + 1
13− readSTRef ref)
examples/failing/EmptyCase.pursdeleted−4
@@ -1,4 +0,0 @@
1−-- @shouldFailWith ErrorParsingModule
2−module Main where
3−
4−error err = case err of \_ -> 1
examples/failing/EmptyClass.pursdeleted−7
@@ -1,7 +0,0 @@
1−-- @shouldFailWith ErrorParsingModule
2−module Main where
3−
4−class Foo x where
5−
6−bar :: String
7−bar = "hello"
examples/failing/EmptyDo.pursdeleted−6
@@ -1,6 +0,0 @@
1−-- @shouldFailWith ErrorParsingModule
2−
3−module Main where
4−
5−main = do
6−
examples/failing/ExtraRecordField.pursdeleted−9
@@ -1,9 +0,0 @@
1−-- @shouldFailWith AdditionalProperty
2−module ExtraRecordField where
3−
4−import Prelude ((<>))
5−
6−full :: { first :: String, last :: String } -> String
7−full p = p.first <> " " <> p.last
8−
9−oops = full { first: "Jane", last: "Smith", age: 29 }
examples/failing/Foldable.pursdeleted−17
@@ -1,17 +0,0 @@
1−-- @shouldFailWith CycleInDeclaration
2−module Main where
3−
4−import Prelude
5−
6−class Foldable f where
7− fold :: forall a b. (a -> b -> b) -> b -> f a -> b
8− size :: forall a. f a -> Number
9−
10−data L a = C a (L a) | N
11−
12−instance foldableL :: Foldable L where
13− fold _ z N = z
14− fold f z (C x xs) = x `f` (fold f z xs)
15− size = fold (const ((+) 1.0)) 0.0
16−
17−x = size (C 1 (C 2 (C 3 N)))
examples/failing/Generalization1.pursdeleted−11
@@ -1,11 +0,0 @@
1−-- @shouldFailWith CannotGeneralizeRecursiveFunction
2−module Main where
3−
4−import Prelude
5−
6−foo 0 x _ = x
7−foo n x y = x <> bar (n - 1) x y
8−
9−bar 0 x _ = x
10−bar n x y = y <> foo (n - 1) x y
11−
examples/failing/Generalization2.pursdeleted−8
@@ -1,8 +0,0 @@
1−-- @shouldFailWith CannotGeneralizeRecursiveFunction
2−module Main where
3−
4−import Prelude
5−
6−test n m | n <= 1 = m
7− | otherwise = test (n - 1) (m <> m)
8−
examples/failing/ImportHidingModule.pursdeleted−10
@@ -1,10 +0,0 @@
1−-- @shouldFailWith ImportHidingModule
2−module A where
3− x = 1
4−
5−module B (module B, module A) where
6− import A
7− y = 1
8−
9−module C where
10− import B hiding (module A)
examples/failing/InfiniteKind.pursdeleted−5
@@ -1,5 +0,0 @@
1−-- @shouldFailWith InfiniteKind
2−
3−module Main where
4−
5−data F a = F (a a)
examples/failing/InfiniteType.pursdeleted−5
@@ -1,5 +0,0 @@
1−-- @shouldFailWith InfiniteType
2−
3−module Main where
4−
5−f a = a a
examples/failing/InstanceExport.pursdeleted−19
@@ -1,19 +0,0 @@
1−-- @shouldFailWith TransitiveExportError
2−module InstanceExport (S(..), f) where
3−
4−import Prelude
5−
6−newtype S = S String
7−
8−class F a where
9− f :: a -> String
10−
11−instance fs :: F S where
12− f (S s) = s
13−
14−module Test where
15−
16−import InstanceExport
17−import Prelude
18−
19−test = f $ S "Test"
examples/failing/IntOutOfRange.pursdeleted−6
@@ -1,6 +0,0 @@
1−-- @shouldFailWith IntOutOfRange
2−
3−module Main where
4−
5−n :: Int
6−n = 2147483648
examples/failing/InvalidOperatorInBinder.pursdeleted−12
@@ -1,12 +0,0 @@
1−-- @shouldFailWith InvalidOperatorInBinder
2−module Main where
3−
4−data List a = Cons a (List a) | Nil
5−
6−cons ∷ ∀ a. a → List a → List a
7−cons = Cons
8−
9−infixl 6 cons as :
10−
11−get ∷ ∀ a. List a → a
12−get (_ : x : _) = x
examples/failing/KindError.pursdeleted−6
@@ -1,6 +0,0 @@
1−-- @shouldFailWith KindsDoNotUnify
2−module Main where
3−
4−import Prelude
5−
6−data KindError f a = One f | Two (f a)
examples/failing/KindStar.pursdeleted−8
@@ -1,8 +0,0 @@
1−-- @shouldFailWith ExpectedType
2−
3−module X where
4−
5−data List a = Nil | Cons a (List a)
6−
7−test :: List
8−test = Nil
examples/failing/LeadingZeros1.pursdeleted−6
@@ -1,6 +0,0 @@
1−-- @shouldFailWith ErrorParsingModule
2−module Main where
3−
4−import Prelude
5−
6−x = 01
examples/failing/LeadingZeros2.pursdeleted−6
@@ -1,6 +0,0 @@
1−-- @shouldFailWith ErrorParsingModule
2−module Main where
3−
4−import Prelude
5−
6−x = 00.1
examples/failing/Let.pursdeleted−6
@@ -1,6 +0,0 @@
1−-- @shouldFailWith CycleInDeclaration
2−module Main where
3−
4−import Prelude
5−
6−test = let x = x in x
examples/failing/MPTCs.pursdeleted−10
@@ -1,10 +0,0 @@
1−-- @shouldFailWith KindsDoNotUnify
2−module Main where
3−
4−import Prelude
5−
6−class Foo a where
7− f :: a -> a
8−
9−instance fooStringString :: Foo String String where
10− f a = a
examples/failing/MissingClassExport.pursdeleted−7
@@ -1,7 +0,0 @@
1−-- @shouldFailWith TransitiveExportError
2−module Test (bar) where
3−
4−import Prelude
5−
6−class Foo a where
7− bar :: a -> a
examples/failing/MissingClassMemberExport.pursdeleted−7
@@ -1,7 +0,0 @@
1−-- @shouldFailWith TransitiveExportError
2−module Test (Foo) where
3−
4−import Prelude
5−
6−class Foo a where
7− bar :: a -> a
examples/failing/MissingRecordField.pursdeleted−10
@@ -1,10 +0,0 @@
1−-- @shouldFailWith PropertyIsMissing
2−module MissingRecordField where
3−
4−import Prelude ((>))
5−
6−john = { first: "John", last: "Smith" }
7−
8−isOver50 p = p.age > 50.0
9−
10−result = isOver50 john
examples/failing/MultipleErrors.pursdeleted−13
@@ -1,13 +0,0 @@
1−-- @shouldFailWith TypesDoNotUnify
2−-- @shouldFailWith TypesDoNotUnify
3−module MultipleErrors where
4−
5−import Prelude
6−
7−foo :: Int -> Int
8−foo 0 = "Test"
9−foo n = bar (n - 1)
10−
11−bar :: Int -> Int
12−bar 0 = "Test"
13−bar n = foo (n - 1)
examples/failing/MultipleErrors2.pursdeleted−9
@@ -1,9 +0,0 @@
1−-- @shouldFailWith UnknownValue
2−-- @shouldFailWith UnknownValue
3−module MultipleErrors2 where
4−
5−import Prelude
6−
7−foo = itDoesntExist
8−
9−bar = neitherDoesThis
examples/failing/MutRec.pursdeleted−9
@@ -1,9 +0,0 @@
1−-- @shouldFailWith CycleInDeclaration
2−-- @shouldFailWith CycleInDeclaration
3−module MutRec where
4−
5−import Prelude
6−
7−x = y
8−
9−y = x
examples/failing/MutRec2.pursdeleted−6
@@ -1,6 +0,0 @@
1−-- @shouldFailWith CycleInDeclaration
2−module Main where
3−
4−import Prelude
5−
6−x = x
examples/failing/NewtypeMultiArgs.pursdeleted−6
@@ -1,6 +0,0 @@
1−-- @shouldFailWith InvalidNewtype
2−module Main where
3−
4−import Prelude
5−
6−newtype Thing = Thing String Boolean
examples/failing/NewtypeMultiCtor.pursdeleted−6
@@ -1,6 +0,0 @@
1−-- @shouldFailWith InvalidNewtype
2−module Main where
3−
4−import Prelude
5−
6−newtype Thing = Thing String | Other
examples/failing/NullaryAbs.pursdeleted−6
@@ -1,6 +0,0 @@
1−-- @shouldFailWith ErrorParsingModule
2−module Main where
3−
4−import Prelude
5−
6−func = \ -> "no"
examples/failing/Object.pursdeleted−8
@@ -1,8 +0,0 @@
1−-- @shouldFailWith PropertyIsMissing
2−module Main where
3−
4−import Prelude
5−
6−test o = o.foo
7−
8−test1 = test {}
examples/failing/OperatorAliasNoExport.pursdeleted−7
@@ -1,7 +0,0 @@
1−-- @shouldFailWith TransitiveExportError
2−module Test ((?!)) where
3−
4−infixl 4 what as ?!
5−
6−what :: forall a b. a -> b -> a
7−what a _ = a
examples/failing/OperatorSections.pursdeleted−8
@@ -1,8 +0,0 @@
1−-- @shouldFailWith CannotApplyFunction
2−module Main where
3−
4−import Prelude
5−
6−main = do
7− (true `not` _)
8−
examples/failing/OrphanInstance.pursdeleted−12
@@ -1,12 +0,0 @@
1−-- @shouldFailWith OrphanInstance
2−module Class where
3−
4− class C a where
5− op :: a -> a
6−
7−module Test where
8−
9− import Class
10−
11− instance cBoolean :: C Boolean where
12− op a = a
examples/failing/OverlappingArguments.pursdeleted−6
@@ -1,6 +0,0 @@
1−-- @shouldFailWith OverlappingArgNames
2−module OverlappingArguments where
3−
4−import Prelude
5−
6−f x x = x
examples/failing/OverlappingBinders.pursdeleted−9
@@ -1,9 +0,0 @@
1−-- @shouldFailWith OverlappingArgNames
2−module OverlappingBinders where
3−
4−import Prelude
5−
6−data S a = S a (S a)
7−
8−f x = case x of
9− (S y (S y@(S z zs))) -> y
examples/failing/OverlappingReExport.pursdeleted−10
@@ -1,10 +0,0 @@
1−-- @shouldFailWith DuplicateValueExport
2−module A where
3− x = true
4−
5−module B where
6− x = false
7−
8−module C (module A, module M2) where
9− import A
10− import qualified B as M2
examples/failing/OverlappingVars.pursdeleted−15
@@ -1,15 +0,0 @@
1−-- @shouldFailWith NoInstanceFound
2−module Main where
3−
4−import Prelude
5−
6−class OverlappingVars a where
7− f :: a -> a
8−
9−data Foo a b = Foo a b
10−
11−instance overlappingVarsFoo :: OverlappingVars (Foo a a) where
12− f a = a
13−
14−test = f (Foo "" 0)
15−
examples/failing/Rank2Types.pursdeleted−8
@@ -1,8 +0,0 @@
1−-- @shouldFailWith TypesDoNotUnify
2−module Main where
3−
4−import Prelude
5−
6−foreign import test :: (forall a. a -> a) -> Number
7−
8−test1 = test (\n -> n + 1)
examples/failing/Reserved.pursdeleted−7
@@ -1,7 +0,0 @@
1−-- @shouldFailWith ErrorParsingModule
2−module Main where
3−
4−import Prelude
5−
6−(<) :: Number -> Number -> Number
7−(<) a b = !(a >= b)
examples/failing/RowConstructors1.pursdeleted−9
@@ -1,9 +0,0 @@
1−-- @shouldFailWith KindsDoNotUnify
2−module Main where
3−
4−import Prelude
5−
6−data Foo = Bar
7−type Baz = { | Foo }
8−
9−main = Control.Monad.Eff.Console.log "Done"
examples/failing/RowConstructors2.pursdeleted−9
@@ -1,9 +0,0 @@
1−-- @shouldFailWith KindsDoNotUnify
2−module Main where
3−
4−import Prelude
5−
6−type Foo r = (x :: Number | r)
7−type Bar = { | Foo }
8−
9−main = Control.Monad.Eff.Console.log "Done"
examples/failing/RowConstructors3.pursdeleted−9
@@ -1,9 +0,0 @@
1−-- @shouldFailWith KindsDoNotUnify
2−module Main where
3−
4−import Prelude
5−
6−type Foo = { x :: Number }
7−type Bar = { | Foo }
8−
9−main = Control.Monad.Eff.Console.log "Done"
examples/failing/SkolemEscape.pursdeleted−8
@@ -1,8 +0,0 @@
1−-- @shouldFailWith EscapedSkolem
2−module Main where
3−
4−import Prelude
5−
6−foreign import foo :: (forall a. a -> a) -> Number
7−
8−test = \x -> foo x
examples/failing/SkolemEscape2.pursdeleted−10
@@ -1,10 +0,0 @@
1−-- @shouldFailWith EscapedSkolem
2−module Main where
3−
4−import Prelude
5−import Control.Monad.Eff
6−import Control.Monad.ST
7−
8−test _ = do
9− r <- runST (newSTRef 0)
10− return 0
examples/failing/SuggestComposition.pursdeleted−7
@@ -1,7 +0,0 @@
1−-- @shouldFailWith TypesDoNotUnify
2−-- TODO: Ensure the correct suggestion is produced.
3−module SuggestComposition where
4−
5−import Prelude
6−
7−f = g . g where g = (+1)
examples/failing/Superclasses1.pursdeleted−14
@@ -1,14 +0,0 @@
1−-- @shouldFailWith NoInstanceFound
2−module Main where
3−
4−import Prelude
5−
6−class Su a where
7− su :: a -> a
8−
9−class (Su a) <= Cl a where
10− cl :: a -> a -> a
11−
12−instance clNumber :: Cl Number where
13− cl n m = n + m
14−
examples/failing/Superclasses2.pursdeleted−13
@@ -1,13 +0,0 @@
1−-- @shouldFailWith CycleInTypeSynonym
2−-- TODO: Should this have its own error, perhaps CycleInTypeClassDeclaration?
3−module CycleInSuperclasses where
4−
5−import Prelude
6−
7−class (Foo a) <= Bar a
8−
9−class (Bar a) <= Foo a
10−
11−instance barString :: Bar String
12−
13−instance fooString :: Foo String
examples/failing/Superclasses3.pursdeleted−8
@@ -1,8 +0,0 @@
1−-- @shouldFailWith UndefinedTypeVariable
2−module UnknownSuperclassTypeVar where
3−
4−import Prelude
5−
6−class Foo a
7−
8−class (Foo b) <= Bar a
examples/failing/Superclasses5.pursdeleted−25
@@ -1,25 +0,0 @@
1−-- @shouldFailWith NoInstanceFound
2−
3−module Main where
4−
5−import Prelude
6−
7−class Su a where
8− su :: a -> a
9−
10−class (Su (Array a)) <= Cl a where
11− cl :: a -> a -> a
12−
13−instance suNumber :: Su Number where
14− su n = n + 1.0
15−
16−instance suArray :: (Su a) => Su (Array a) where
17− su [x] = [su x]
18−
19−instance clNumber :: Cl Number where
20− cl n m = n + m
21−
22−test :: forall a. (Cl a) => a -> Array a
23−test x = su [cl x x]
24−
25−main = Control.Monad.Eff.Console.print $ test 10.0
examples/failing/TopLevelCaseNoArgs.pursdeleted−8
@@ -1,8 +0,0 @@
1−-- @shouldFailWith DuplicateValueDeclaration
2−module Main where
3−
4−import Prelude
5−
6−foo :: Number
7−foo = 1
8−foo = 2
examples/failing/TransitiveDctorExport.pursdeleted−5
@@ -1,5 +0,0 @@
1−-- @shouldFailWith TransitiveExportError
2−module Main (Y(..)) where
3−
4−type X = Int
5−data Y = Y X
examples/failing/TransitiveSynonymExport.pursdeleted−5
@@ -1,5 +0,0 @@
1−-- @shouldFailWith TransitiveExportError
2−module Main (Y()) where
3−
4−type X = Int
5−type Y = X
examples/failing/TypeClassInstances.pursdeleted−11
@@ -1,11 +0,0 @@
1−-- @shouldFailWith MissingClassMember
2−module Main where
3−
4−import Prelude
5−
6−class A a where
7− a :: a -> String
8− b :: a -> Number
9−
10−instance aString :: A String where
11− a s = s
examples/failing/TypeClasses2.pursdeleted−9
@@ -1,9 +0,0 @@
1−-- @shouldFailWith NoInstanceFound
2−module Main where
3−
4−import Prelude ()
5−
6−class Show a where
7− show :: a -> String
8−
9−test = show "testing"
examples/failing/TypeError.pursdeleted−6
@@ -1,6 +0,0 @@
1−-- @shouldFailWith TypesDoNotUnify
2−module Main where
3−
4−import Prelude
5−
6−test = 1 ++ "A"
examples/failing/TypeSynonyms.pursdeleted−8
@@ -1,8 +0,0 @@
1−-- @shouldFailWith CycleInTypeSynonym
2−module Main where
3−
4−import Prelude
5−
6−type T1 = Array T2
7−
8−type T2 = T1
examples/failing/TypeSynonyms2.pursdeleted−12
@@ -1,12 +0,0 @@
1−-- @shouldFailWith TypeSynonymInstance
2−module Main where
3−
4−import Prelude
5−
6−class Foo a where
7− foo :: a -> String
8−
9−type Bar = String
10−
11−instance fooBar :: Foo Bar where
12− foo s = s
examples/failing/TypeSynonyms3.pursdeleted−12
@@ -1,12 +0,0 @@
1−-- @shouldFailWith TypeSynonymInstance
2−module Main where
3−
4−import Prelude
5−
6−class Foo a where
7− foo :: a -> String
8−
9−type Bar = String
10−
11−instance fooBar :: Foo Bar where
12− foo s = s
examples/failing/TypeSynonyms4.pursdeleted−11
@@ -1,11 +0,0 @@
1−-- @shouldFailWith PartiallyAppliedSynonym
2−module TypeSynonyms4 where
3−
4−import Prelude
5−
6−type F x y = x -> y
7−
8−type G x = F x
9−
10−f :: G String String -> String
11−f k = k "Done"
examples/failing/TypeSynonyms5.pursdeleted−6
@@ -1,6 +0,0 @@
1−-- @shouldFailWith CycleInTypeSynonym
2−module Main where
3−
4−import Prelude
5−
6−type T = T
examples/failing/TypeWildcards1.pursdeleted−7
@@ -1,7 +0,0 @@
1−-- @shouldFailWith ErrorParsingModule
2−module TypeWildcards where
3−
4−import Prelude
5−
6−type Test = _
7−
examples/failing/TypeWildcards2.pursdeleted−7
@@ -1,7 +0,0 @@
1−-- @shouldFailWith ErrorParsingModule
2−module TypeWildcards where
3−
4−import Prelude
5−
6−data Test = Test _
7−
examples/failing/TypeWildcards3.pursdeleted−10
@@ -1,10 +0,0 @@
1−-- @shouldFailWith ErrorParsingModule
2−module TypeWildcards where
3−
4−import Prelude
5−
6−data Foo a = Foo
7−
8−instance showFoo :: Show (Foo _) where
9− show Foo = "Foo"
10−
examples/failing/TypedBinders.pursdeleted−10
@@ -1,10 +0,0 @@
1−-- @shouldFailWith ErrorParsingModule
2−module Main where
3−
4−import Prelude
5−
6−test = (\f :: Int -> Int -> f 10) id
7−
8−main = do
9− let t1 = test
10− Control.Monad.Eff.Console.log "Done"
examples/failing/TypedBinders2.pursdeleted−9
@@ -1,9 +0,0 @@
1−-- @shouldFailWith TypesDoNotUnify
2−module Main where
3−
4−import Prelude
5−
6−main = do
7− s :: String <- Control.Monad.Eff.Console.log "Foo"
8− Control.Monad.Eff.Console.log "Done"
9−
examples/failing/TypedBinders3.pursdeleted−12
@@ -1,12 +0,0 @@
1−-- @shouldFailWith TypesDoNotUnify
2−module Main where
3−
4−import Prelude
5−
6−test = case 1 of
7− (0 :: String) -> true
8− _ -> false
9−
10−main = do
11− let t = test
12− Control.Monad.Eff.Console.log "Done"
examples/failing/UnderscoreModuleName.pursdeleted−6
@@ -1,6 +0,0 @@
1−-- @shouldFailWith ErrorParsingModule
2−module Bad_Module where
3−
4−import Prelude
5−
6−main = Control.Monad.Eff.Console.log "Done"
examples/failing/UnifyInTypeInstanceLookup.pursdeleted−22
@@ -1,22 +0,0 @@
1−-- @shouldFailWith NoInstanceFound
2−-- See issue #390.
3−-- TODO: Improve this error.
4−module Main where
5−
6−import Prelude
7−
8−data Z = Z
9−data S n = S n
10−
11−data T
12−data F
13−
14−class EQ x y b
15−instance eqT :: EQ x x T
16−instance eqF :: EQ x y F
17−
18−foreign import test :: forall a b. (EQ a b T) => a -> b -> a
19−
20−foreign import anyNat :: forall a. a
21−
22−test1 = test anyNat (S Z)
examples/failing/UnknownType.pursdeleted−7
@@ -1,7 +0,0 @@
1−-- @shouldFailWith UnknownType
2−module Main where
3−
4−import Prelude
5−
6−test :: Number -> Something
7−test = {}
examples/manual/QualifiedNames.pursdeleted−13
@@ -1,13 +0,0 @@
1−module Data.Either where
2−
3−import Prelude
4−
5−data Either a b = Left a | Right b
6−
7−module Main where
8−
9−either :: forall a b c. (a -> c) -> (b -> c) -> Data.Either.Either a b -> c
10−either f _ (Data.Either.Left x) = f x
11−either _ g (Data.Either.Right y) = g y
12−
13−main = Control.Monad.Eff.Console.log (either id id (Data.Either.Left "Done"))
examples/manual/failing/ArgLengthMismatch.pursdeleted−6
@@ -1,6 +0,0 @@
1−module ArgLengthMismatch where
2−
3−import Prelude
4−
5−f x y = true
6−f = false
examples/manual/failing/ExportExplicit.pursdeleted−7
@@ -1,7 +0,0 @@
1−-- should fail as z does not exist in the module
2−module M1 (x, y, z) where
3−
4−import Prelude
5−
6−x = 1
7−y = 2
examples/manual/failing/ExportExplicit1.pursdeleted−14
@@ -1,14 +0,0 @@
1−module M1 (X(X)) where
2−
3− data X = X | Y
4−
5−module Main where
6−
7− import M1
8−
9− testX = X
10−
11− -- should fail as Y constructor is not exported from M1
12− testY = Y
13−
14− main = Control.Monad.Eff.Console.log "Done"
examples/manual/failing/ExportExplicit2.pursdeleted−7
@@ -1,7 +0,0 @@
1−-- should fail as Y is not a data constructor for X
2−module M1 (X(Y)) where
3−
4−import Prelude
5−
6−data X = X
7−data Y = Y
examples/manual/failing/ExportExplicit3.pursdeleted−13
@@ -1,13 +0,0 @@
1−module M1 (X(..)) where
2−
3− data X = X | Y
4− data Z = Z
5−
6−module Main where
7−
8− import M1
9−
10− -- should fail as Z is not exported from M1
11− testZ = M1.Z
12−
13− main = Control.Monad.Eff.Console.log "Done"
examples/manual/failing/ImportExplicit.pursdeleted−7
@@ -1,7 +0,0 @@
1−module M1 where
2−
3− foo = "foo"
4−
5−module Main where
6−
7− import M1 (X(..))
examples/manual/failing/ImportExplicit2.pursdeleted−7
@@ -1,7 +0,0 @@
1−module M1 where
2−
3− data X = Y
4−
5−module Main where
6−
7− import M1 (X(Z, Q))
examples/manual/failing/ImportModule.pursdeleted−7
@@ -1,7 +0,0 @@
1−module M2 where
2−
3− data X = X
4−
5−module Main where
6−
7− import M1
examples/manual/failing/OrphanTypeDecl.pursdeleted−3
@@ -1,3 +0,0 @@
1−module OrphanTypeDecl where
2−
3−fn :: Number -> Boolean
examples/manual/failing/RedefinedFixity.pursdeleted−8
@@ -1,8 +0,0 @@
1−module RedefinedFixity where
2−
3−import Prelude
4−
5−(!?) x y = x + y
6−
7−infix 2 !?
8−infix 2 !?
examples/manual/failing/RequiredHiddenType.pursdeleted−8
@@ -1,8 +0,0 @@
1−-- exporting `a` should fail as `A` is hidden
2−module Foo (B(..), a, b) where
3−
4−data A = A
5−data B = B
6−
7−a = A
8−b = B
examples/manual/passing/ExportExplicit.pursdeleted−20
@@ -1,20 +0,0 @@
1−module M1 (X(X), Z(..), foo) where
2−
3− data X = X | Y
4− data Z = Z
5−
6− foo :: Number
7− foo = 0
8−
9− bar :: Number
10− bar = 1
11−
12−module Main where
13−
14− import M1
15−
16− testX = X
17− testZ = Z
18− testFoo = foo
19−
20− main = Control.Monad.Eff.Console.log "Done"
examples/manual/passing/ExportExplicit2.pursdeleted−15
@@ -1,15 +0,0 @@
1−module M1 (bar) where
2−
3− foo :: Number
4− foo = 0
5−
6− bar :: Number
7− bar = foo
8−
9−module Main where
10−
11− import M1
12−
13− testBar = bar
14−
15− main = Control.Monad.Eff.Console.log "Done"
examples/manual/passing/ExportedInstanceDeclarations.pursdeleted−43
@@ -1,43 +0,0 @@
1−
2−-- Tests that instances for non-exported classes / types do not appear in the
3−-- result of `exportedDeclarations`.
4−
5−module ExportedInstanceDeclarations
6− ( Const(..)
7− , Foo
8− , foo
9− ) where
10−
11−import Prelude
12−
13−data Const a b = Const a
14−
15−class Foo a where
16− foo :: a
17−
18−data NonexportedType = NonexportedType
19−
20−class NonexportedClass a where
21− notExported :: a
22−
23−-- There are three places that a nonexported type or type class can occur,
24−-- leading an instance to count as non-exported:
25−-- * Constraints
26−-- * The type class itself
27−-- * The instance types
28−
29−-- Case 1: constraints
30−instance nonExportedFoo :: (NonexportedClass a) => Foo a where
31− foo = notExported
32−
33−-- Another instance of case 1:
34−instance nonExportedFoo2 :: (Foo NonexportedType) => Foo (a -> a) where
35− foo = id
36−
37−-- Case 2: type class
38−instance nonExportedNonexportedType :: NonexportedClass (Const Number a) where
39− notExported = Const 0
40−
41−-- Case 3: instance types
42−instance constFoo :: Foo (Const NonexportedType b) where
43− foo = Const NonexportedType
examples/manual/passing/Import.pursdeleted−19
@@ -1,19 +0,0 @@
1−module M1 where
2−
3− import Prelude ()
4−
5− id :: forall a. a -> a
6− id = \x -> x
7−
8− foo = id
9−
10−module M2 where
11−
12− import Prelude ()
13− import M1
14−
15− main = \_ -> foo 42
16−
17−module Main where
18−
19−main = Control.Monad.Eff.Console.log "Done"
examples/manual/passing/ImportExplicit.pursdeleted−14
@@ -1,14 +0,0 @@
1−module M1 where
2−
3− data X = X | Y
4− data Z = Z
5−
6−module Main where
7−
8− import M1 (X(..))
9−
10− testX :: X
11− testX = X
12− testY = Y
13−
14− main = Control.Monad.Eff.Console.log "Done"
examples/manual/passing/ImportQualified.pursdeleted−12
@@ -1,12 +0,0 @@
1−module M1 where
2−
3− log x = x
4−
5−module Main where
6−
7− import Prelude
8− import Control.Monad.Eff
9− import M1
10− import qualified Control.Monad.Eff.Console as C
11−
12− main = C.log (log "Done")
examples/manual/passing/Module.pursdeleted−28
@@ -1,28 +0,0 @@
1−module M1 where
2−
3− import Prelude
4−
5− data Foo = Foo String
6−
7− foo :: M1.Foo -> String
8− foo = \f -> case f of Foo s -> s ++ "foo"
9−
10− bar :: Foo -> String
11− bar = foo
12−
13− incr :: Number -> Number
14− incr x = x + 1
15−
16−module M2 where
17−
18− import Prelude
19−
20− baz :: M1.Foo -> String
21− baz = M1.foo
22−
23− match :: M1.Foo -> String
24− match = \f -> case f of M1.Foo s -> s ++ "foo"
25−
26−module Main where
27−
28−main = Control.Monad.Eff.Console.log "Done"
examples/manual/passing/ModuleDeps.pursdeleted−17
@@ -1,17 +0,0 @@
1−module M1 where
2−
3−import M2
4−
5−foo = M3.baz
6−
7−module M2 where
8−
9−bar = M3.baz
10−
11−module M3 where
12−
13−baz = 1
14−
15−module Main where
16−
17−main = Control.Monad.Eff.Console.log "Done"
examples/manual/passing/RedefinedFixity.pursdeleted−24
@@ -1,24 +0,0 @@
1−module M1 where
2−
3−import Prelude ()
4−
5−($) f a = f a
6−
7−infixr 1000 $
8−
9−module M2 where
10−
11−import Prelude ()
12−
13−import M1
14−
15−module M3 where
16−
17−import Prelude ()
18−
19−import M1
20−import M2
21−
22−module Main where
23−
24−main = Control.Monad.Eff.Console.log "Done"
examples/manual/passing/ShadowedName.pursdeleted−10
@@ -1,10 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff.Console
5−
6−done :: String
7−done = let str = "Not yet done" in
8− let str = "Done" in str
9−
10−main = Control.Monad.Eff.Console.log done
examples/manual/passing/TransitiveImport.pursdeleted−24
@@ -1,24 +0,0 @@
1−module Test where
2−
3− import Prelude
4−
5− class TestCls a where
6− test :: a -> a
7−
8− instance unitTestCls :: TestCls Unit where
9− test _ = unit
10−
11−module Middle where
12−
13− middle = Test.test
14−
15−module Main where
16−
17− import Prelude
18− import Middle
19− import Control.Monad.Eff.Console
20−
21− main = do
22− print (middle unit)
23− trace "Done"
24− return unit
examples/manual/passing/WildcardType.pursdeleted−13
@@ -1,13 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff.Console
5−
6−f1 :: (_ -> _) -> _
7−f1 g = g 1
8−
9−f2 :: _ -> _
10−f2 _ = "Done"
11−
12−main = Control.Monad.Eff.Console.log $ f1 f2
13−
examples/passing/1185.pursdeleted−13
@@ -1,13 +0,0 @@
1−module Main where
2−
3−data Person = Person String Boolean
4−
5−getName :: Person -> String
6−getName p = case p of
7− Person name true -> name
8− _ -> "Unknown"
9−
10−name :: String
11−name = getName (Person "John Smith" true)
12−
13−main = Control.Monad.Eff.Console.log "Done"
examples/passing/1335.pursdeleted−12
@@ -1,12 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff.Console (log)
5−
6−x :: forall a. a -> String
7−x a = y "Done"
8− where
9− y :: forall a. (Show a) => a -> String
10− y a = show (a :: a)
11−
12−main = log (x 0)
examples/passing/1570.pursdeleted−6
@@ -1,6 +0,0 @@
1−module Main where
2−
3−test :: forall a. a -> a
4−test = \(x :: a) -> x
5−
6−main = Control.Monad.Eff.Console.log "Done"
examples/passing/1664.pursdeleted−16
@@ -1,16 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff
5−import Control.Monad.Eff.Console
6−
7−data Identity a = Identity a
8−
9−newtype IdentityEff e a = IdentityEff (Eff e (Identity a))
10−
11−test :: forall e a. IdentityEff e a -> IdentityEff e Unit
12−test (IdentityEff action) = IdentityEff $ do
13− (Identity x :: Identity _) <- action
14− return $ Identity unit
15−
16−main = log "Done"
examples/passing/1697.pursdeleted−24
@@ -1,24 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−_2 :: forall a. a -> a
6−_2 a = a
7−
8−x :: forall m. (Monad m) => m Unit
9−x = do
10− _ <- pure unit
11− pure unit
12−
13−y :: forall m. (Monad m) => m Unit
14−y = do
15− _ <- pure unit
16− pure unit
17−
18−wtf :: forall m. (Monad m) => m Unit
19−wtf = do
20− _ <- pure unit
21− let tmp = _2 1
22− pure unit
23−
24−main = Control.Monad.Eff.Console.log "Done"
examples/passing/1991.pursdeleted−20
@@ -1,20 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−singleton :: forall a. a -> Array a
6−singleton x = [x]
7−
8−empty :: forall a. Array a
9−empty = []
10−
11−foldMap :: forall a m. (Semigroup m) => (a -> m) -> Array a -> m
12−foldMap f [a, b, c, d, e] = f a <> f b <> f c <> f d <> f e
13−
14−regression :: Array Int
15−regression =
16− let as = [1,2,3,4,5]
17− as' = foldMap (\x -> if 1 < x && x < 4 then singleton x else empty) as
18− in as'
19−
20−main = Control.Monad.Eff.Console.log "Done"
examples/passing/2018.pursdeleted−25
@@ -1,25 +0,0 @@
1−module B where
2−
3− data Foo = X | Y
4−
5−module A where
6−
7− import B as Main
8−
9− -- Prior to the 2018 fix this would be detected as a cycle between A and Main.
10− foo ∷ Main.Foo → Main.Foo
11− foo x = x
12−
13−module Main where
14−
15−import Prelude
16−import A (foo)
17−import B (Foo(..))
18−import Control.Monad.Eff (Eff)
19−import Control.Monad.Eff.Console (CONSOLE, log)
20−
21−main :: forall e. Eff (console :: CONSOLE | e) Unit
22−main = do
23− let tmp = foo X
24− log "Done"
25−
examples/passing/652.pursdeleted−17
@@ -1,17 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−class Foo a b
6−
7−class Bar a c
8−
9−class (Foo a b, Bar a c) <= Baz a b c
10−
11−instance foo :: Foo (a -> b) a
12−
13−instance bar :: Bar (a -> b) b
14−
15−instance baz :: (Eq a) => Baz (a -> b) a b
16−
17−main = Control.Monad.Eff.Console.log "Done"
examples/passing/810.pursdeleted−13
@@ -1,13 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−data Maybe a = Nothing | Just a
6−
7−test :: forall a. Maybe a -> Maybe a
8−test m = o.x
9− where
10− o = case m of Nothing -> { x : Nothing }
11− Just a -> { x : Just a }
12−
13−main = Control.Monad.Eff.Console.log "Done"
examples/passing/862.pursdeleted−8
@@ -1,8 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff.Console
5−
6−id' = (\x -> x) <$> \y -> y
7−
8−main = log (id' "Done")
examples/passing/922.pursdeleted−20
@@ -1,20 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−import Control.Monad.Eff.Console
6−
7−class Default a where
8− def :: a
9−
10−instance defaultString :: Default String where
11− def = "Done"
12−
13−data I a = I a
14−
15−instance defaultI :: (Default a) => Default (I a) where
16− def = I def
17−
18−main = do
19− case def of
20− I s -> log s
examples/passing/Applicative.pursdeleted−16
@@ -1,16 +0,0 @@
1−module Main where
2−
3−import Prelude ()
4−
5−class Applicative f where
6− pure :: forall a. a -> f a
7− apply :: forall a b. f (a -> b) -> f a -> f b
8−
9−data Maybe a = Nothing | Just a
10−
11−instance applicativeMaybe :: Applicative Maybe where
12− pure = Just
13− apply (Just f) (Just a) = Just (f a)
14− apply _ _ = Nothing
15−
16−main = Control.Monad.Eff.Console.log "Done"
examples/passing/ArrayType.pursdeleted−11
@@ -1,11 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−class Pointed p where
6− point :: forall a. a -> p a
7−
8−instance pointedArray :: Pointed Array where
9− point a = [a]
10−
11−main = Control.Monad.Eff.Console.log "Done"
examples/passing/Auto.pursdeleted−15
@@ -1,15 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−data Auto s i o = Auto { state :: s, step :: s -> i -> o }
6−
7−type SomeAuto i o = forall r. (forall s. Auto s i o -> r) -> r
8−
9−exists :: forall s i o. s -> (s -> i -> o) -> SomeAuto i o
10−exists = \state step f -> f (Auto { state: state, step: step })
11−
12−run :: forall i o. SomeAuto i o -> i -> o
13−run = \s i -> s (\a -> case a of Auto a -> a.step a.state i)
14−
15−main = Control.Monad.Eff.Console.log "Done"
examples/passing/AutoPrelude.pursdeleted−9
@@ -1,9 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff.Console
5−
6−f x = x * 10.0
7−g y = y - 10.0
8−
9−main = log $ show $ (f <<< g) 100.0
examples/passing/AutoPrelude2.pursdeleted−10
@@ -1,10 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import qualified Prelude as P
5−import Control.Monad.Eff.Console
6−
7−f :: forall a. a -> a
8−f = P.id
9−
10−main = P.($) log ((f P.<<< f) "Done")
examples/passing/BindersInFunctions.pursdeleted−11
@@ -1,11 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Test.Assert
5−
6−snd = \[_, y] -> y
7−
8−main = do
9− let ts = snd [1.0, 2.0]
10− assert' "Incorrect result from 'snd'." (ts == 2.0)
11− Control.Monad.Eff.Console.log "Done"
examples/passing/BindingGroups.pursdeleted−10
@@ -1,10 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−foo = bar
6− where bar r = r + 1.0
7−
8−r = foo 2.0
9−
10−main = Control.Monad.Eff.Console.log "Done"
examples/passing/BlockString.pursdeleted−8
@@ -1,8 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−foo :: String
6−foo = """foo"""
7−
8−main = Control.Monad.Eff.Console.log "Done"
examples/passing/CaseInDo.pursdeleted−19
@@ -1,19 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff.Console
5−import Control.Monad.Eff
6−
7−doIt :: forall eff. Eff eff Boolean
8−doIt = return true
9−
10−set = do
11− log "Testing..."
12− case 0 of
13− 0 -> doIt
14− _ -> return false
15−
16−main = do
17− b <- set
18− case b of
19− true -> log "Done"
examples/passing/CaseInputWildcard.pursdeleted−18
@@ -1,18 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff (Eff)
5−import Control.Monad.Eff.Console (log, CONSOLE)
6−
7−data Foo = X | Y
8−
9−what ∷ Foo → Int → Boolean → Foo
10−what x = case _, x, _ of
11− 0, X, true → X
12− 0, Y, true → X
13− _, _, _ → Y
14−
15−main :: forall e. Eff (console :: CONSOLE | e) Unit
16−main = do
17− let tmp = what Y 0 true
18− log "Done"
examples/passing/CaseMultipleExpressions.pursdeleted−19
@@ -1,19 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff.Console
5−import Control.Monad.Eff
6−
7−doIt :: forall eff. Eff eff Boolean
8−doIt = return true
9−
10−set = do
11− log "Testing..."
12− case 42, 10 of
13− 42, 10 -> doIt
14− _ , _ -> return false
15−
16−main = do
17− b <- set
18− case b of
19− true -> log "Done"
examples/passing/CaseStatement.pursdeleted−21
@@ -1,21 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−data A = A | B | C
6−
7−f a _ A = a
8−f _ a B = a
9−f _ _ C = "Done"
10−
11−g a _ A = a
12−g _ b B = b
13−g _ _ C = C
14−
15−data M a = N | J a
16−
17−h f N a = a
18−h f a N = a
19−h f (J a) (J b) = J (f a b)
20−
21−main = Control.Monad.Eff.Console.log $ f "Done" "Failed" A
examples/passing/CheckFunction.pursdeleted−7
@@ -1,7 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−test = ((\x -> x+1.0) >>> (\x -> x*2.0)) 4.0
6−
7−main = Control.Monad.Eff.Console.log "Done"
examples/passing/CheckSynonymBug.pursdeleted−12
@@ -1,12 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−length :: forall a. Array a -> Int
6−length _ = 0
7−
8−type Foo a = Array a
9−
10−foo _ = length ([] :: Foo Number)
11−
12−main = Control.Monad.Eff.Console.log "Done"
examples/passing/CheckTypeClass.pursdeleted−18
@@ -1,18 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−data Bar a = Bar
6−data Baz
7−
8−class Foo a where
9− foo :: Bar a -> Baz
10−
11−foo_ :: forall a. (Foo a) => a -> Baz
12−foo_ x = foo ((mkBar :: forall a. (Foo a) => a -> Bar a) x)
13−
14−mkBar :: forall a. a -> Bar a
15−mkBar _ = Bar
16−
17−main = Control.Monad.Eff.Console.log "Done"
18−
examples/passing/Church.pursdeleted−18
@@ -1,18 +0,0 @@
1−module Main where
2−
3−import Prelude ()
4−
5−type List a = forall r. r -> (a -> r -> r) -> r
6−
7−empty :: forall a. List a
8−empty = \r f -> r
9−
10−cons :: forall a. a -> List a -> List a
11−cons = \a l r f -> f a (l r f)
12−
13−append :: forall a. List a -> List a -> List a
14−append = \l1 l2 r f -> l2 (l1 r f) f
15−
16−test = append (cons 1 empty) (cons 2 empty)
17−
18−main = Control.Monad.Eff.Console.log "Done"
examples/passing/ClassRefSyntax.pursdeleted−13
@@ -1,13 +0,0 @@
1−module Lib (class X, go) where
2−
3− class X a where
4− go :: a -> a
5−
6−module Main where
7−
8− import Lib (class X, go)
9−
10− go' :: forall a. (X a) => a -> a
11− go' = go
12−
13− main = Control.Monad.Eff.Console.log "Done"
examples/passing/Collatz.pursdeleted−18
@@ -1,18 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff
5−import Control.Monad.ST
6−
7−collatz :: Int -> Int
8−collatz n = runPure (runST (do
9− r <- newSTRef n
10− count <- newSTRef 0
11− untilE $ do
12− modifySTRef count $ (+) 1
13− m <- readSTRef r
14− writeSTRef r $ if m `mod` 2 == 0 then m / 2 else 3 * m + 1
15− return $ m == 1
16− readSTRef count))
17−
18−main = Control.Monad.Eff.Console.print $ collatz 1000
examples/passing/Comparisons.pursdeleted−15
@@ -1,15 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff
5−import Control.Monad.Eff.Console
6−import Test.Assert
7−
8−main = do
9− assert (1.0 < 2.0)
10− assert (2.0 == 2.0)
11− assert (3.0 > 1.0)
12− assert ("a" < "b")
13− assert ("a" == "a")
14− assert ("z" > "a")
15− log "Done!"
examples/passing/Conditional.pursdeleted−9
@@ -1,9 +0,0 @@
1−module Main where
2−
3−import Prelude ()
4−
5−fns = \f -> if f true then f else \x -> x
6−
7−not = \x -> if x then false else true
8−
9−main = Control.Monad.Eff.Console.log "Done"
examples/passing/Console.pursdeleted−13
@@ -1,13 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff
5−import Control.Monad.Eff.Console
6−
7−replicateM_ :: forall m a. (Monad m) => Number -> m a -> m {}
8−replicateM_ 0.0 _ = return {}
9−replicateM_ n act = do
10− act
11− replicateM_ (n - 1.0) act
12−
13−main = replicateM_ 10.0 (log "Hello World!")
examples/passing/ConstraintInference.pursdeleted−7
@@ -1,7 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−shout = Control.Monad.Eff.Console.log <<< (<> "!") <<< show
6−
7−main = shout "Done"
examples/passing/ContextSimplification.pursdeleted−13
@@ -1,13 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff.Console
5−
6−shout = log <<< (<> "!") <<< show
7−
8−-- Here, we should simplify the context so that only one Show
9−-- constraint is added.
10−usesShowTwice true = shout
11−usesShowTwice false = print
12−
13−main = usesShowTwice true "Done"
examples/passing/DataAndType.pursdeleted−9
@@ -1,9 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−data A = A B
6−
7−type B = A
8−
9−main = Control.Monad.Eff.Console.log "Done"
examples/passing/DctorOperatorAlias.pursdeleted−40
@@ -1,40 +0,0 @@
1−module Data.List where
2−
3− data List a = Cons a (List a) | Nil
4−
5− infixr 6 Cons as :
6−
7−module Main where
8−
9− import Prelude (Unit, bind, (==))
10− import Control.Monad.Eff (Eff)
11− import Control.Monad.Eff.Console (CONSOLE, log)
12− import Test.Assert (ASSERT, assert')
13− import Data.List (List(..), (:))
14− import Data.List as L
15−
16− -- unqualified
17− infixl 6 Cons as !
18−
19− -- qualified
20− infixl 6 L.Cons as !!
21−
22− get1 ∷ ∀ a. a → List a → a
23− get1 y xs = case xs of
24− _ : x : _ → x
25− _ → y
26−
27− get2 ∷ ∀ a. a → List a → a
28− get2 _ (_ : x : _) = x
29− get2 y _ = y
30−
31− get3 ∷ ∀ a. a → List a → a
32− get3 _ (_ ! (x ! _)) = x
33− get3 y _ = y
34−
35− main ∷ Eff (assert ∷ ASSERT, console ∷ CONSOLE) Unit
36− main = do
37− assert' "Incorrect result!" (get1 0 (1 : 2 : 3 : Nil) == 2)
38− assert' "Incorrect result!" (get2 0 (1 ! (2 ! (3 ! Nil))) == 2)
39− assert' "Incorrect result!" (get3 0.0 (1.0 : 2.0 : (3.0 ! Nil)) == 2.0)
40− log "Done"
examples/passing/DeepArrayBinder.pursdeleted−16
@@ -1,16 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff
5−import Test.Assert
6−
7−data List a = Cons a (List a) | Nil
8−
9−match2 :: List Number -> Number
10−match2 (Cons x (Cons y xs)) = x * y + match2 xs
11−match2 _ = 0.0
12−
13−main = do
14− let result = match2 (Cons 1.0 (Cons 2.0 (Cons 3.0 (Cons 4.0 (Cons 5.0 (Cons 6.0 (Cons 7.0 (Cons 8.0 (Cons 9.0 Nil)))))))))
15− assert' "Incorrect result!" (result == 100.0)
16− Control.Monad.Eff.Console.log "Done"
examples/passing/DeepCase.pursdeleted−15
@@ -1,15 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff.Console
5−import Control.Monad.Eff
6−import Control.Monad.ST
7−
8−f x y =
9− let
10− g = case y of
11− 0.0 -> x
12− x -> 1.0 + x * x
13− in g + x + y
14−
15−main = print $ f 1.0 10.0
examples/passing/Deriving.pursdeleted−31
@@ -1,31 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Test.Assert
5−
6−data V
7−
8−derive instance eqV :: Eq V
9−
10−derive instance ordV :: Ord V
11−
12−data X = X Int | Y String
13−
14−derive instance eqX :: Eq X
15−
16−derive instance ordX :: Ord X
17−
18−newtype Z = Z { left :: X, right :: X }
19−
20−derive instance eqZ :: Eq Z
21−
22−main = do
23− assert $ X 0 == X 0
24− assert $ X 0 /= X 1
25− assert $ Y "Foo" == Y "Foo"
26− assert $ Y "Foo" /= Y "Bar"
27− assert $ X 0 < X 1
28− assert $ X 0 < Y "Foo"
29− assert $ Y "Bar" < Y "Baz"
30− assert $ z == z where
31− z = Z { left: X 0, right: Y "Foo" }
examples/passing/Do.pursdeleted−67
@@ -1,67 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−data Maybe a = Nothing | Just a
6−
7−instance functorMaybe :: Functor Maybe where
8− map f Nothing = Nothing
9− map f (Just x) = Just (f x)
10−
11−instance applyMaybe :: Apply Maybe where
12− apply (Just f) (Just x) = Just (f x)
13− apply _ _ = Nothing
14−
15−instance applicativeMaybe :: Applicative Maybe where
16− pure = Just
17−
18−instance bindMaybe :: Bind Maybe where
19− bind Nothing _ = Nothing
20− bind (Just a) f = f a
21−
22−instance monadMaybe :: Prelude.Monad Maybe
23−
24−test1 = \_ -> do
25− Just "abc"
26−
27−test2 = \_ -> do
28− x <- Just 1.0
29− y <- Just 2.0
30− Just (x + y)
31−
32−test3 = \_ -> do
33− Just 1.0
34− Nothing :: Maybe Number
35− Just 2.0
36−
37−test4 mx my = do
38− x <- mx
39− y <- my
40− Just (x + y + 1.0)
41−
42−test5 mx my mz = do
43− x <- mx
44− y <- my
45− let sum = x + y
46− z <- mz
47− Just (z + sum + 1.0)
48−
49−test6 mx = \_ -> do
50− let
51− f :: forall a. Maybe a -> a
52− f (Just x) = x
53− Just (f mx)
54−
55−test8 = \_ -> do
56− Just (do
57− Just 1.0)
58−
59−test9 = \_ -> (+) <$> Just 1.0 <*> Just 2.0
60−
61−test10 _ = do
62− let
63− f x = g x * 3.0
64− g x = f x / 2.0
65− Just (f 10.0)
66−
67−main = Control.Monad.Eff.Console.log "Done"
examples/passing/Dollar.pursdeleted−16
@@ -1,16 +0,0 @@
1−module Main where
2−
3−import Prelude ()
4−
5−($) :: forall a b. (a -> b) -> a -> b
6−($) f x = f x
7−
8−infixr 1000 $
9−
10−id x = x
11−
12−test1 x = id $ id $ id $ id $ x
13−
14−test2 x = id id $ id x
15−
16−main = Control.Monad.Eff.Console.log "Done"
examples/passing/Eff.pursdeleted−25
@@ -1,25 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff
5−import Control.Monad.ST
6−import Control.Monad.Eff.Console
7−
8−test1 = do
9− log "Line 1"
10− log "Line 2"
11−
12−test2 = runPure (runST (do
13− ref <- newSTRef 0.0
14− modifySTRef ref $ \n -> n + 1.0
15− readSTRef ref))
16−
17−test3 = pureST (do
18− ref <- newSTRef 0.0
19− modifySTRef ref $ \n -> n + 1.0
20− readSTRef ref)
21−
22−main = do
23− test1
24− Control.Monad.Eff.Console.print test2
25− Control.Monad.Eff.Console.print test3
examples/passing/EmptyDataDecls.pursdeleted−19
@@ -1,19 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Test.Assert
5−
6−data Z
7−data S n
8−
9−data ArrayBox n a = ArrayBox (Array a)
10−
11−nil :: forall a. ArrayBox Z a
12−nil = ArrayBox []
13−
14−cons' :: forall a n. a -> ArrayBox n a -> ArrayBox (S n) a
15−cons' x (ArrayBox xs) = ArrayBox $ append [x] xs
16−
17−main = case cons' 1 $ cons' 2 $ cons' 3 nil of
18− ArrayBox [1, 2, 3] -> Control.Monad.Eff.Console.log "Done"
19− _ -> assert' "Failed" false
examples/passing/EmptyRow.pursdeleted−10
@@ -1,10 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−data Foo r = Foo { | r }
6−
7−test :: Foo ()
8−test = Foo {}
9−
10−main = Control.Monad.Eff.Console.log "Done"
examples/passing/EmptyTypeClass.pursdeleted−12
@@ -1,12 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−class PartialP
6−
7−head :: forall a. (PartialP) => Array a -> a
8−head [x] = x
9−
10−instance allowPartials :: PartialP
11−
12−main = Control.Monad.Eff.Console.log $ head ["Done"]
examples/passing/EqOrd.pursdeleted−15
@@ -1,15 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−data Pair a b = Pair a b
6−
7−instance ordPair :: (Ord a, Ord b) => Ord (Pair a b) where
8− compare (Pair a1 b1) (Pair a2 b2) = case compare a1 a2 of
9− EQ -> compare b1 b2
10− r -> r
11−
12−instance eqPair :: (Eq a, Eq b) => Eq (Pair a b) where
13− eq (Pair a1 b1) (Pair a2 b2) = a1 == a2 && b1 == b2
14−
15−main = Control.Monad.Eff.Console.print $ Pair 1.0 2.0 == Pair 1.0 2.0
examples/passing/ExplicitImportReExport.pursdeleted−16
@@ -1,16 +0,0 @@
1−-- from #1244
2−module Foo where
3−
4− foo :: Int
5− foo = 3
6−
7−module Bar (module Foo) where
8−
9− import Foo
10−
11−module Baz where
12−
13− import Bar (foo)
14−
15− baz :: Int
16− baz = foo
examples/passing/ExplicitOperatorSections.pursdeleted−14
@@ -1,14 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−subtractOne :: Int -> Int
6−subtractOne = (_ - 1)
7−
8−addOne :: Int -> Int
9−addOne = (1 + _)
10−
11−named :: Int -> Int
12−named = (_ `sub` 1)
13−
14−main = Control.Monad.Eff.Console.log "Done"
examples/passing/ExtendedInfixOperators.pursdeleted−14
@@ -1,14 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−comparing :: forall a b. (Ord b) => (a -> b) -> a -> a -> Ordering
6−comparing f = compare `Data.Function.on` f
7−
8−null [] = true
9−null _ = false
10−
11−test = [1.0, 2.0, 3.0] `comparing null` [4.0, 5.0, 6.0]
12−
13−main = do
14− Control.Monad.Eff.Console.print test
examples/passing/Fib.pursdeleted−15
@@ -1,15 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff
5−import Control.Monad.ST
6−
7−main = runST (do
8− n1 <- newSTRef 1.0
9− n2 <- newSTRef 1.0
10− whileE ((>) 1000.0 <$> readSTRef n1) $ do
11− n1' <- readSTRef n1
12− n2' <- readSTRef n2
13− writeSTRef n2 $ n1' + n2'
14− writeSTRef n1 n2'
15− Control.Monad.Eff.Console.print n2')
examples/passing/FieldConsPuns.pursdeleted−10
@@ -1,10 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff.Console
5−
6−greet { greeting, name } = log $ greeting <> ", " <> name <> "."
7−
8−main = greet { greeting, name} where
9− greeting = "Hello"
10− name = "World"
examples/passing/FieldPuns.pursdeleted−8
@@ -1,8 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff.Console
5−
6−greet { greeting, name } = log $ greeting <> ", " <> name <> "."
7−
8−main = greet { greeting: "Hello", name: "World" }
examples/passing/FinalTagless.pursdeleted−22
@@ -1,22 +0,0 @@
1−module Main where
2−
3−import Prelude hiding (add)
4−
5−class E e where
6− num :: Number -> e Number
7− add :: e Number -> e Number -> e Number
8−
9−type Expr a = forall e. (E e) => e a
10−
11−data Id a = Id a
12−
13−instance exprId :: E Id where
14− num = Id
15− add (Id n) (Id m) = Id (n + m)
16−
17−runId (Id a) = a
18−
19−three :: Expr Number
20−three = add (num 1.0) (num 2.0)
21−
22−main = Control.Monad.Eff.Console.print $ runId three
examples/passing/FunctionScope.pursdeleted−12
@@ -1,12 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Test.Assert
5−
6−mkValue :: Number -> Number
7−mkValue id = id
8−
9−main = do
10− let value = mkValue 1.0
11− assert $ value == 1.0
12− Control.Monad.Eff.Console.log "Done"
examples/passing/Functions.pursdeleted−15
@@ -1,15 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−test1 = \_ -> 0.0
6−
7−test2 = \a b -> a + b + 1.0
8−
9−test3 = \a -> a
10−
11−test4 = \(%%) -> 1.0 %% 2.0
12−
13−test5 = \(+++) (***) -> 1.0 +++ 2.0 *** 3.0
14−
15−main = Control.Monad.Eff.Console.log "Done"
examples/passing/Functions2.pursdeleted−12
@@ -1,12 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Test.Assert
5−
6−test :: forall a b. a -> b -> a
7−test = \const _ -> const
8−
9−main = do
10− let value = test "Done" {}
11− assert' "Not done" $ value == "Done"
12− Control.Monad.Eff.Console.log "Done"
examples/passing/Generalization1.pursdeleted−10
@@ -1,10 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff.Console (print)
5−
6−main = do
7− print (sum 1.0 2.0)
8− print (sum 1 2)
9−
10−sum x y = x + y
examples/passing/Guards.pursdeleted−29
@@ -1,29 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−collatz = \x -> case x of
6− y | y `mod` 2.0 == 0.0 -> y / 2.0
7− y -> y * 3.0 + 1.0
8−
9−-- Guards have access to current scope
10−collatz2 = \x y -> case x of
11− z | y > 0.0 -> z / 2.0
12− z -> z * 3.0 + 1.0
13−
14−min :: forall a. (Ord a) => a -> a -> a
15−min n m | n < m = n
16− | otherwise = m
17−
18−max :: forall a. (Ord a) => a -> a -> a
19−max n m = case unit of
20− _ | m < n -> n
21− | otherwise -> m
22−
23−testIndentation :: Number -> Number -> Number
24−testIndentation x y | x > 0.0
25− = x + y
26− | otherwise
27− = y - x
28−
29−main = Control.Monad.Eff.Console.log $ min "Done" "ZZZZ"
examples/passing/HoistError.pursdeleted−12
@@ -1,12 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff
5−import Control.Monad.Eff.Console
6−import Test.Assert
7−
8−main = do
9− let x = 0.0
10− assert $ x == 0.0
11− let x = 1.0 + 1.0
12− log "Done"
examples/passing/IfThenElseMaybe.pursdeleted−11
@@ -1,11 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−data Maybe a = Nothing | Just a
6−
7−test1 = if true then Just 10 else Nothing
8−
9−test2 = if true then Nothing else Just 10
10−
11−main = Control.Monad.Eff.Console.log "Done"
examples/passing/IfWildcard.pursdeleted−19
@@ -1,19 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff (Eff)
5−import Control.Monad.Eff.Console (log, CONSOLE)
6−
7−data Foo = X | Y
8−
9−cond ∷ ∀ a. Boolean → a → a → a
10−cond = if _ then _ else _
11−
12−what ∷ Boolean → Foo
13−what = if _ then X else Y
14−
15−main :: forall e. Eff (console :: CONSOLE | e) Unit
16−main = do
17− let tmp1 = what true
18− tmp2 = cond true 0 1
19− log "Done"
examples/passing/ImplicitEmptyImport.pursdeleted−8
@@ -1,8 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−main = do
6− Control.Monad.Eff.Console.log "Hello"
7− Control.Monad.Eff.Console.log "Goodbye"
8− Control.Monad.Eff.Console.log "Done"
examples/passing/ImportHiding.pursdeleted−18
@@ -1,18 +0,0 @@
1−module Main where
2−
3−import Control.Monad.Eff.Console
4−import Prelude hiding (
5− show, -- a value
6− Show, -- a type class
7− Unit(..) -- a constructor
8− )
9−
10−show = 1.0
11−
12−class Show a where
13− noshow :: a -> a
14−
15−data Unit = X | Y
16−
17−main = do
18− print show
examples/passing/InferRecFunWithConstrainedArgument.pursdeleted−8
@@ -1,8 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−test 100.0 = 100.0
6−test n = test(1.0 + n)
7−
8−main = Control.Monad.Eff.Console.print $ test 0.0
examples/passing/InstanceBeforeClass.pursdeleted−11
@@ -1,11 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−instance fooNumber :: Foo Number where
6− foo = 0.0
7−
8−class Foo a where
9− foo :: a
10−
11−main = Control.Monad.Eff.Console.log "Done"
examples/passing/IntAndChar.pursdeleted−18
@@ -1,18 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff
5−import Test.Assert
6−
7−f 1 = 1
8−f _ = 0
9−
10−g 'a' = 'a'
11−g _ = 'b'
12−
13−main = do
14− assert $ f 1 == 1
15− assert $ f 0 == 0
16− assert $ g 'a' == 'a'
17− assert $ g 'b' == 'b'
18− Control.Monad.Eff.Console.log "Done"
examples/passing/JSReserved.pursdeleted−12
@@ -1,12 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−yield = 0
6−member = 1
7−
8−public = \return -> return
9−
10−this catch = catch
11−
12−main = Control.Monad.Eff.Console.log "Done"
examples/passing/KindedType.pursdeleted−33
@@ -1,33 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−type Star2Star f = f :: * -> *
6−
7−type Star t = t :: *
8−
9−test1 :: Star2Star Array String
10−test1 = ["test"]
11−
12−f :: Star (String -> String)
13−f s = s
14−
15−test2 = f "test"
16−
17−data Proxy (f :: * -> *) = Proxy
18−
19−test3 :: Proxy Array
20−test3 = Proxy
21−
22−type Test (f :: * -> *) = f String
23−
24−test4 :: Test Array
25−test4 = ["test"]
26−
27−class Clazz (a :: *) where
28− def :: a
29−
30−instance clazzString :: Clazz String where
31− def = "test"
32−
33−main = Control.Monad.Eff.Console.log "Done"
examples/passing/LargeSumType.pursdeleted−33
@@ -1,33 +0,0 @@
1−module Main where
2−
3−data Large = A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z
4−
5−explode A A = "A"
6−explode B B = "B"
7−explode C C = "C"
8−explode D D = "D"
9−explode E E = "E"
10−explode F F = "F"
11−explode G G = "G"
12−explode H H = "H"
13−explode I I = "I"
14−explode J J = "J"
15−explode K K = "K"
16−explode L L = "L"
17−explode M M = "M"
18−explode N N = "N"
19−explode O O = "O"
20−explode P P = "P"
21−explode Q Q = "Q"
22−explode R R = "R"
23−explode S S = "S"
24−explode T T = "T"
25−explode U U = "U"
26−explode V V = "V"
27−explode W W = "W"
28−explode X X = "X"
29−explode Y Y = "Y"
30−explode Z Z = "Z"
31−explode _ _ = ""
32−
33−main = Control.Monad.Eff.Console.log "Done"
examples/passing/Let.pursdeleted−53
@@ -1,53 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff
5−import Control.Monad.ST
6−
7−test1 x = let
8− y :: Number
9− y = x + 1.0
10− in y
11−
12−test2 x y =
13− let x' = x + 1.0 in
14− let y' = y + 1.0 in
15− x' + y'
16−
17−test3 = let f x y z = x + y + z in
18− f 1.0 2.0 3.0
19−
20−test4 = let f x [y, z] = x y z in
21− f (+) [1.0, 2.0]
22−
23−test5 = let
24− f x | x > 0.0 = g (x / 2.0) + 1.0
25− f x = 0.0
26− g x = f (x - 1.0) + 1.0
27− in f 10.0
28−
29−test7 = let
30− f :: forall a. a -> a
31− f x = x
32− in if f true then f 1.0 else f 2.0
33−
34−test8 :: Number -> Number
35−test8 x = let
36− go y | (x - 0.1 < y * y) && (y * y < x + 0.1) = y
37− go y = go $ (y + x / y) / 2.0
38− in go x
39−
40−test10 _ =
41− let
42− f x = g x * 3.0
43− g x = f x / 2.0
44− in f 10.0
45−
46−main = do
47− Control.Monad.Eff.Console.print (test1 1.0)
48− Control.Monad.Eff.Console.print (test2 1.0 2.0)
49− Control.Monad.Eff.Console.print test3
50− Control.Monad.Eff.Console.print test4
51− Control.Monad.Eff.Console.print test5
52− Control.Monad.Eff.Console.print test7
53− Control.Monad.Eff.Console.print (test8 100.0)
examples/passing/Let2.pursdeleted−17
@@ -1,17 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−test =
6− let f :: Number -> Boolean
7− f 0.0 = false
8− f n = g (n - 1.0)
9−
10− g :: Number -> Boolean
11− g 0.0 = true
12− g n = f (n - 1.0)
13−
14− x = f 1.0
15− in not x
16−
17−main = Control.Monad.Eff.Console.print test
examples/passing/LetInInstance.pursdeleted−14
@@ -1,14 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−class Foo a where
6− foo :: a -> String
7−
8−instance fooString :: Foo String where
9− foo = go
10− where
11− go :: String -> String
12− go s = s
13−
14−main = Control.Monad.Eff.Console.log "Done"
examples/passing/LiberalTypeSynonyms.pursdeleted−21
@@ -1,21 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−type Reader = (->) String
6−
7−foo :: Reader String
8−foo s = s
9−
10−type AndFoo r = (foo :: String | r)
11−
12−getFoo :: forall r. Prim.Object (AndFoo r) -> String
13−getFoo o = o.foo
14−
15−type F r = { | r } -> { | r }
16−
17−f :: (forall r. F r) -> String
18−f g = case g { x: "Hello" } of
19− { x = x } -> x
20−
21−main = Control.Monad.Eff.Console.log "Done"
examples/passing/MPTCs.pursdeleted−20
@@ -1,20 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−class NullaryTypeClass where
6− greeting :: String
7−
8−instance nullaryTypeClass :: NullaryTypeClass where
9− greeting = "Hello, World!"
10−
11−class Coerce a b where
12− coerce :: a -> b
13−
14−instance coerceRefl :: Coerce a a where
15− coerce a = a
16−
17−instance coerceShow :: (Prelude.Show a) => Coerce a String where
18− coerce = show
19−
20−main = Control.Monad.Eff.Console.log "Done"
examples/passing/Match.pursdeleted−9
@@ -1,9 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−data Foo a = Foo
6−
7−foo = \f -> case f of Foo -> "foo"
8−
9−main = Control.Monad.Eff.Console.log "Done"
examples/passing/ModuleExport.pursdeleted−9
@@ -1,9 +0,0 @@
1−module A (module Prelude) where
2− import Prelude
3−
4−module Main where
5− import Control.Monad.Eff.Console
6− import A
7−
8− main = do
9− print (show 1.0)
examples/passing/ModuleExportDupes.pursdeleted−19
@@ -1,19 +0,0 @@
1−module A (module Prelude) where
2− import Prelude
3−
4−module B (module Prelude) where
5− import Prelude
6−
7−module C (module Prelude, module A) where
8− import Prelude
9− import A
10−
11−module Main where
12− import Control.Monad.Eff.Console
13− import A
14− import B
15− import C
16− import Prelude
17−
18− main = do
19− print (show 1.0)
examples/passing/ModuleExportExcluded.pursdeleted−14
@@ -1,14 +0,0 @@
1−module A (module Prelude, foo) where
2− import Prelude
3−
4− foo :: Number -> Number
5− foo _ = 0.0
6−
7−module Main where
8− import Control.Monad.Eff.Console
9− import A (foo)
10−
11− otherwise = false
12−
13− main = do
14− print "1.0"
examples/passing/ModuleExportQualified.pursdeleted−9
@@ -1,9 +0,0 @@
1−module A (module Prelude) where
2− import Prelude
3−
4−module Main where
5− import Control.Monad.Eff.Console
6− import qualified A as B
7−
8− main = do
9− print (B.show 1.0)
examples/passing/ModuleExportSelf.pursdeleted−14
@@ -1,14 +0,0 @@
1−module A (module A, module Prelude) where
2− import Prelude
3−
4− type Foo = Boolean
5−
6−module Main where
7− import Control.Monad.Eff.Console
8− import A
9−
10− bar :: Foo
11− bar = true
12−
13− main = do
14− print (show bar)
examples/passing/Monad.pursdeleted−32
@@ -1,32 +0,0 @@
1−module Main where
2−
3−import Prelude ()
4−
5−type Monad m = { return :: forall a. a -> m a
6− , bind :: forall a b. m a -> (a -> m b) -> m b }
7−
8−data Id a = Id a
9−
10−id :: Monad Id
11−id = { return : Id
12− , bind : \ma f -> case ma of Id a -> f a }
13−
14−data Maybe a = Nothing | Just a
15−
16−maybe :: Monad Maybe
17−maybe = { return : Just
18− , bind : \ma f -> case ma of
19− Nothing -> Nothing
20− Just a -> f a
21− }
22−
23−test :: forall m. Monad m -> m Number
24−test = \m -> m.bind (m.return 1.0) (\n1 ->
25− m.bind (m.return "Test") (\n2 ->
26− m.return n1))
27−
28−test1 = test id
29−
30−test2 = test maybe
31−
32−main = Control.Monad.Eff.Console.log "Done"
examples/passing/MonadState.pursdeleted−61
@@ -1,61 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff.Console
5−
6−data Tuple a b = Tuple a b
7−
8−instance showTuple :: (Show a, Show b) => Show (Tuple a b) where
9− show (Tuple a b) = "(" <> show a <> ", " <> show b <> ")"
10−
11−class Monad m <= MonadState s m where
12− get :: m s
13− put :: s -> m Unit
14−
15−data State s a = State (s -> Tuple s a)
16−
17−runState s (State f) = f s
18−
19−instance functorState :: Functor (State s) where
20− map = liftM1
21−
22−instance applyState :: Apply (State s) where
23− apply = ap
24−
25−instance applicativeState :: Applicative (State s) where
26− pure a = State $ \s -> Tuple s a
27−
28−instance bindState :: Bind (State s) where
29− bind f g = State $ \s -> case runState s f of
30− Tuple s1 a -> runState s1 (g a)
31−
32−instance monadState :: Monad (State s)
33−
34−instance monadStateState :: MonadState s (State s) where
35− get = State (\s -> Tuple s s)
36− put s = State (\_ -> Tuple s unit)
37−
38−-- Without the call to same, the following strange (but correct, in the absence of
39−-- functional dependencies) type:
40−--
41−-- forall m t1 t2.
42−-- ( Bind m
43−-- , MonadState t1 m
44−-- , MonadState t2 m
45−-- ) => (t1 -> t2) -> m Unit
46−--
47−-- With the type hint, the inferred type is more sensible:
48−--
49−-- forall m t.
50−-- ( Bind m
51−-- , MonadState t m
52−-- ) => (t -> t) -> m Unit
53−modify f =
54− do
55− s <- get
56− put (same f s)
57− where
58− same :: forall a. (a -> a) -> (a -> a)
59− same = id
60−
61−main = print $ runState 0 (modify (+ 1))
examples/passing/MultiArgFunctions.pursdeleted−27
@@ -1,27 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Data.Function
5−import Control.Monad.Eff
6−import Control.Monad.Eff.Console
7−
8−f = mkFn2 $ \a b -> runFn2 g a b + runFn2 g b a
9−
10−g = mkFn2 $ \a b -> case {} of
11− _ | a <= 0.0 || b <= 0.0 -> b
12− _ -> runFn2 f (a - 0.0) (b - 0.0)
13−
14−main = do
15− runFn0 (mkFn0 $ \_ -> log $ show 0.0)
16− runFn1 (mkFn1 $ \a -> log $ show a) 0.0
17− runFn2 (mkFn2 $ \a b -> log $ show [a, b]) 0.0 0.0
18− runFn3 (mkFn3 $ \a b c -> log $ show [a, b, c]) 0.0 0.0 0.0
19− runFn4 (mkFn4 $ \a b c d -> log $ show [a, b, c, d]) 0.0 0.0 0.0 0.0
20− runFn5 (mkFn5 $ \a b c d e -> log $ show [a, b, c, d, e]) 0.0 0.0 0.0 0.0 0.0
21− runFn6 (mkFn6 $ \a b c d e f -> log $ show [a, b, c, d, e, f]) 0.0 0.0 0.0 0.0 0.0 0.0
22− runFn7 (mkFn7 $ \a b c d e f g -> log $ show [a, b, c, d, e, f, g]) 0.0 0.0 0.0 0.0 0.0 0.0 0.0
23− runFn8 (mkFn8 $ \a b c d e f g h -> log $ show [a, b, c, d, e, f, g, h]) 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
24− runFn9 (mkFn9 $ \a b c d e f g h i -> log $ show [a, b, c, d, e, f, g, h, i]) 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
25− runFn10 (mkFn10 $ \a b c d e f g h i j-> log $ show [a, b, c, d, e, f, g, h, i, j]) 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
26− print $ runFn2 g 0.0 0.0
27− log "Done!"
examples/passing/MutRec.pursdeleted−19
@@ -1,19 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−f 0.0 = 0.0
6−f x = g x + 0.0
7−
8−g x = f (x / 0.0)
9−
10−data Even = Zero | Even Odd
11−
12−data Odd = Odd Even
13−
14−evenToNumber Zero = 0.0
15−evenToNumber (Even n) = oddToNumber n + 0.0
16−
17−oddToNumber (Odd n) = evenToNumber n + 0.0
18−
19−main = Control.Monad.Eff.Console.log "Done"
examples/passing/MutRec2.pursdeleted−19
@@ -1,19 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−data A = A B
6−
7−data B = B A
8−
9−foreign import data S :: *
10−
11−f :: A -> S
12−f a = case a of A b -> g b
13−
14−g b = case b of B a -> f a
15−
16−showN :: A -> S
17−showN a = f a
18−
19−main = Control.Monad.Eff.Console.log "Done"
examples/passing/MutRec3.pursdeleted−19
@@ -1,19 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−data A = A B
6−
7−data B = B A
8−
9−foreign import data S :: *
10−
11−f a = case a of A b -> g b
12−
13−g :: B -> S
14−g b = case b of B a -> f a
15−
16−showN :: A -> S
17−showN a = f a
18−
19−main = Control.Monad.Eff.Console.log "Done"
examples/passing/NakedConstraint.pursdeleted−10
@@ -1,10 +0,0 @@
1−module Main where
2−
3−import Control.Monad.Eff.Console
4−
5−data List a = Nil | Cons a (List a)
6−
7−head :: (Partial) => List Int -> Int
8−head (Cons x _) = x
9−
10−main = log "Done"
examples/passing/NamedPatterns.pursdeleted−9
@@ -1,9 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−foo = \x -> case x of
6− y@{ foo = "Foo" } -> y
7− y -> y
8−
9−main = Control.Monad.Eff.Console.log "Done"
examples/passing/NegativeBinder.pursdeleted−9
@@ -1,9 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−test :: Number -> Boolean
6−test -1.0 = false
7−test _ = true
8−
9−main = Control.Monad.Eff.Console.log "Done"
examples/passing/NegativeIntInRange.pursdeleted−8
@@ -1,8 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−n :: Int
6−n = -2147483648
7−
8−main = Control.Monad.Eff.Console.log "Done"
examples/passing/Nested.pursdeleted−9
@@ -1,9 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−data Extend r a = Extend { prev :: r a, next :: a }
6−
7−data Matrix r a = Square (r (r a)) | Bigger (Matrix (Extend r) a)
8−
9−main = Control.Monad.Eff.Console.log "Done"
examples/passing/NestedTypeSynonyms.pursdeleted−11
@@ -1,11 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−type X = String
6−type Y = X -> X
7−
8−fn :: Y
9−fn a = a
10−
11−main = Control.Monad.Eff.Console.print (fn "Done")
examples/passing/NestedWhere.pursdeleted−12
@@ -1,12 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−f x = g x
6− where
7− g x = go x
8− where
9− go x = go1 (x - 1.0)
10− go1 x = go x
11−
12−main = Control.Monad.Eff.Console.log "Done"
examples/passing/Newtype.pursdeleted−23
@@ -1,23 +0,0 @@
1−module Main where
2−
3−import Prelude hiding (apply)
4−import Control.Monad.Eff
5−import Control.Monad.Eff.Console
6−
7−newtype Thing = Thing String
8−
9−instance showThing :: Show Thing where
10− show (Thing x) = "Thing " ++ show x
11−
12−newtype Box a = Box a
13−
14−instance showBox :: (Show a) => Show (Box a) where
15− show (Box x) = "Box " ++ show x
16−
17−apply f x = f x
18−
19−main = do
20− print $ Thing "hello"
21− print $ Box 42.0
22− print $ apply Box 9000.0
23− log "Done"
examples/passing/NewtypeEff.pursdeleted−29
@@ -1,29 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff.Console
5−import Control.Monad.Eff
6−
7−newtype T a = T (Eff (console :: CONSOLE) a)
8−
9−runT :: forall a. T a -> Eff (console :: CONSOLE) a
10−runT (T t) = t
11−
12−instance functorT :: Functor T where
13− map f (T t) = T (f <$> t)
14−
15−instance applyT :: Apply T where
16− apply (T f) (T x) = T (f <*> x)
17−
18−instance applicativeT :: Applicative T where
19− pure t = T (pure t)
20−
21−instance bindT :: Bind T where
22− bind (T t) f = T (t >>= \x -> runT (f x))
23−
24−instance monadT :: Monad T
25−
26−main = runT do
27− T $ log "Done"
28− T $ log "Done"
29− T $ log "Done"
examples/passing/NewtypeWithRecordUpdate.pursdeleted−16
@@ -1,16 +0,0 @@
1−-- https://github.com/purescript/purescript/issues/812.0
2−
3−module Main where
4−
5−import Prelude
6−import Control.Monad.Eff.Console
7−
8−newtype NewType a = NewType (Object a)
9−
10−rec1 :: Object (a :: Number, b :: Number, c:: Number)
11−rec1 = { a: 0.0, b: 0.0, c: 0.0 }
12−
13−rec2 :: NewType (a :: Number, b :: Number, c :: Number)
14−rec2 = NewType (rec1 { a = 1.0 })
15−
16−main = log "Done"
examples/passing/NonConflictingExports.pursdeleted−14
@@ -1,14 +0,0 @@
1−module A where
2−
3− thing :: Int
4− thing = 1
5−
6−-- No failure here as the export `thing` only refers to Main.thing
7−module Main (thing, main) where
8−
9− import A
10−
11− thing :: Int
12− thing = 2
13−
14− main = Control.Monad.Eff.Console.log "Done"
examples/passing/ObjectGetter.pursdeleted−13
@@ -1,13 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−getX = _.x
6−
7−point = { x: 1.0, y: 0.0 }
8−
9−main = do
10− Control.Monad.Eff.Console.print $ getX point
11− Control.Monad.Eff.Console.log $ _." 123 string Prop Name " { " 123 string Prop Name ": "OK" }
12− Control.Monad.Eff.Console.log $ (_.x >>> _.y) { x: { y: "Nested" } }
13− Control.Monad.Eff.Console.log $ _.value { value: "Done!" }
examples/passing/ObjectSynonym.pursdeleted−15
@@ -1,15 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−type Inner = Number
6−
7−inner :: Inner
8−inner = 0.0
9−
10−type Outer = { inner :: Inner }
11−
12−outer :: Outer
13−outer = { inner: inner }
14−
15−main = Control.Monad.Eff.Console.log "Done"
examples/passing/ObjectUpdate.pursdeleted−20
@@ -1,20 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−update1 = \o -> o { foo = "Foo" }
6−
7−update2 :: forall r. { foo :: String | r } -> { foo :: String | r }
8−update2 = \o -> o { foo = "Foo" }
9−
10−replace = \o -> case o of
11− { foo = "Foo" } -> o { foo = "Bar" }
12− { foo = "Bar" } -> o { bar = "Baz" }
13− o -> o
14−
15−polyUpdate :: forall a r. { foo :: a | r } -> { foo :: String | r }
16−polyUpdate = \o -> o { foo = "Foo" }
17−
18−inferPolyUpdate = \o -> o { foo = "Foo" }
19−
20−main = Control.Monad.Eff.Console.log ((update1 {foo: ""}).foo)
examples/passing/ObjectUpdate2.pursdeleted−17
@@ -1,17 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−type X r = { | r }
6−
7−x :: X (baz :: String)
8−x = { baz: "baz" }
9−
10−blah :: forall r. X r -> X r
11−blah x = x
12−
13−test = blah x
14− { baz = "blah"
15− }
16−
17−main = Control.Monad.Eff.Console.log "Done"
examples/passing/ObjectUpdater.pursdeleted−24
@@ -1,24 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff
5−import Control.Monad.Eff.Console
6−import Test.Assert
7−
8−getValue :: forall e. Eff (| e) Boolean
9−getValue = return true
10−
11−main = do
12− let record = { value: false }
13− record' <- record { value = _ } <$> getValue
14− assert $ record'.value == true
15−
16− let point = { x: 1.0, y: 1.0 }
17− x = 10.0
18− point' = (point { x = _, y = x }) 100.0
19−
20− assert $ point'.x == 100.0
21− assert $ point'.y == 10.0
22−
23− let record2 = (_ { x = _ }) { x: 0.0 } 10.0
24− assert $ record2.x == 10.0
examples/passing/ObjectWildcards.pursdeleted−20
@@ -1,20 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff
5−import Control.Monad.Eff.Console
6−import Test.Assert
7−
8−mkRecord = { foo: _, bar: _, baz: "baz" }
9−
10−getValue :: forall e. Eff (| e) Boolean
11−getValue = return true
12−
13−main = do
14− obj <- { value: _ } <$> getValue
15− print obj.value
16− let x = 1.0
17− point <- { x: _, y: x } <$> return 2.0
18− assert $ point.x == 2.0
19− assert $ point.y == 1.0
20− log (mkRecord 1.0 "Done!").bar
examples/passing/Objects.pursdeleted−35
@@ -1,35 +0,0 @@
1−module Main where
2−
3−import Prelude hiding (append)
4−
5−test = \x -> x.foo + x.bar + 1.0
6−
7−append = \o -> { foo: o.foo, bar: 1.0 }
8−
9−apTest = append({foo : "Foo", baz: "Baz"})
10−
11−f = (\a -> a.b.c) { b: { c: 1.0, d: "Hello" }, e: "World" }
12−
13−g = (\a -> a.f { x: 1.0, y: "y" }) { f: \o -> o.x + 1.0 }
14−
15−typed :: { foo :: Number }
16−typed = { foo: 0.0 }
17−
18−test2 = \x -> x."!@#"
19−
20−test3 = typed."foo"
21−
22−test4 = test2 weirdObj
23− where
24− weirdObj :: { "!@#" :: Number }
25− weirdObj = { "!@#": 1.0 }
26−
27−test5 = case { "***": 1.0 } of
28− { "***" = n } -> n
29−
30−test6 = case { "***": 1.0 } of
31− { "***": n } -> n
32−
33−test7 {a: snoog , b : blah } = blah
34−
35−main = Control.Monad.Eff.Console.log "Done"
examples/passing/OneConstructor.pursdeleted−9
@@ -1,9 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−data One a = One a
6−
7−one' (One a) = a
8−
9−main = Control.Monad.Eff.Console.log "Done"
examples/passing/OperatorAlias.pursdeleted−11
@@ -1,11 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff.Console
5−
6−infixl 4 what as ?!
7−
8−what :: forall a b. a -> b -> a
9−what a _ = a
10−
11−main = log $ "Done" ?! true
examples/passing/OperatorAliasElsewhere.pursdeleted−14
@@ -1,14 +0,0 @@
1−module Def where
2−
3−what :: forall a b. a -> b -> a
4−what a _ = a
5−
6−module Main where
7−
8−import Prelude
9−import Def (what)
10−import Control.Monad.Eff.Console
11−
12−infixl 4 what as ?!
13−
14−main = log $ "Done" ?! true
examples/passing/OperatorAssociativity.pursdeleted−25
@@ -1,25 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff
5−import Control.Monad.Eff.Console
6−import Test.Assert
7−
8−bug :: Number -> Number -> Number
9−bug a b = 0.0 - (a - b)
10−
11−main = do
12− assert (bug 0.0 2.0 == 2.0)
13− assert (0.0 - (0.0 - 2.0) == 2.0)
14− assert (0.0 - (0.0 + 2.0) == -2.0)
15− assert (6.0 / (3.0 * 2.0) == 1.0)
16− assert ((6.0 / 3.0) * 2.0 == 4.0)
17− assert (not (1.0 < 0.0) == true)
18− assert (not ((negate 1.0) < 0.0) == false)
19− assert (negate (1.0 + 10.0) == -11.0)
20− assert (2.0 * 3.0 / 4.0 == 1.5)
21− assert (1.0 * 2.0 * 3.0 * 4.0 * 5.0 / 6.0 == 20.0)
22− assert (1.0 + 10.0 - 5.0 == 6.0)
23− assert (1.0 + 10.0 * 5.0 == 51.0)
24− assert (10.0 * 5.0 - 1.0 == 49.0)
25− log "Success!"
examples/passing/OperatorInlining.pursdeleted−47
@@ -1,47 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff.Console
5−
6−main = do
7−
8− -- semiringNumber
9− print (1.0 + 2.0)
10− print (1.0 * 2.0)
11−
12− -- ringNumber
13− print (1.0 - 2.0)
14− print (negate 1.0)
15−
16− -- moduleSemiringNumber
17− print (1.0 / 2.0)
18−
19− -- ordNumber
20− print (1.0 > 2.0)
21− print (1.0 < 2.0)
22− print (1.0 <= 2.0)
23− print (1.0 >= 2.0)
24− print (1.0 == 2.0)
25−
26− -- eqNumber
27− print (1.0 == 2.0)
28− print (1.0 /= 2.0)
29−
30− -- eqString
31− print ("foo" == "bar")
32− print ("foo" /= "bar")
33−
34− -- eqBoolean
35− print (true == false)
36− print (true /= false)
37−
38− -- semigroupString
39− print ("foo" ++ "bar")
40− print ("foo" <> "bar")
41−
42− -- latticeBoolean
43− print (top && true)
44− print (bottom || false)
45−
46− -- complementedLatticeBoolean
47− print (not true)
examples/passing/OperatorSections.pursdeleted−17
@@ -1,17 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Test.Assert
5−
6−main = do
7− assert $ (/ 2.0) 4.0 == 2.0
8− assert $ (2.0 /) 4.0 == 0.5
9− assert $ (`const` 1.0) 2.0 == 2.0
10− assert $ (1.0 `const`) 2.0 == 1.0
11− let foo = { x: 2.0 }
12− assert $ (/ foo.x) 4.0 == 2.0
13− assert $ (foo.x /) 4.0 == 0.5
14− let (//) x y = x.x / y.x
15− assert $ (// foo { x = 4.0 }) { x: 4.0 } == 1.0
16− assert $ (foo { x = 4.0 } //) { x: 4.0 } == 1.0
17− Control.Monad.Eff.Console.log "Done!"
examples/passing/Operators.pursdeleted−99
@@ -1,99 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff
5−import Control.Monad.Eff.Console
6−
7−(?!) :: forall a. a -> a -> a
8−(?!) x _ = x
9−
10−bar :: String -> String -> String
11−bar = \s1 s2 -> s1 ++ s2
12−
13−test1 :: forall n. (Num n) => n -> n -> (n -> n -> n) -> n
14−test1 x y z = x * y + z x y
15−
16−test2 = (\x -> x.foo false) { foo : \_ -> 1.0 }
17−
18−test3 = (\x y -> x)(1.0 + 2.0 * (1.0 + 2.0)) (true && (false || false))
19−
20−k = \x -> \y -> x
21−
22−test4 = 1 `k` 2
23−
24−infixl 5 %%
25−
26−(%%) :: Number -> Number -> Number
27−(%%) x y = x * y + y
28−
29−test5 = 1.0 %% 2.0 %% 3.0
30−
31−test6 = ((\x -> x) `k` 2.0) 3.0
32−
33−(<+>) :: String -> String -> String
34−(<+>) = \s1 s2 -> s1 ++ s2
35−
36−test7 = "Hello" <+> "World!"
37−
38−(@@) :: forall a b. (a -> b) -> a -> b
39−(@@) = \f x -> f x
40−
41−foo :: String -> String
42−foo = \s -> s
43−
44−test8 = foo @@ "Hello World"
45−
46−test9 = Main.foo @@ "Hello World"
47−
48−test10 = "Hello" `Main.bar` "World"
49−
50−(...) :: forall a. Array a -> Array a -> Array a
51−(...) = \as -> \bs -> as
52−
53−test11 = [1.0, 2.0, 0.0] ... [4.0, 5.0, 6.0]
54−
55−test12 (<%>) a b = a <%> b
56−
57−test13 = \(<%>) a b -> a <%> b
58−
59−test14 :: Number -> Number -> Boolean
60−test14 a b = a < b
61−
62−test15 :: Number -> Number -> Boolean
63−test15 a b = const false $ a `test14` b
64−
65−test17 :: Number
66−test17 = negate (-1.0)
67−
68−test18 :: Number
69−test18 = negate $ negate 1.0
70−
71−test19 :: Number
72−test19 = negate $ negate (-1.0)
73−
74−test20 :: Number
75−test20 = 1.0 @ 2.0
76− where
77− (@) x y = x + y * y
78−
79−main = do
80− let t1 = test1 1.0 2.0 (\x y -> x + y)
81− let t2 = test2
82− let t3 = test3
83− let t4 = test4
84− let t5 = test5
85− let t6 = test6
86− let t7 = test7
87− let t8 = test8
88− let t9 = test9
89− let t10 = test10
90− let t11 = test11
91− let t12 = test12 k 1.0 2.0
92− let t13 = test13 k 1.0 2.0
93− let t14 = test14 1.0 2.0
94− let t15 = test15 1.0 2.0
95− let t17 = test17
96− let t18 = test18
97− let t19 = test19
98− let t20 = test20
99− log "Done"
examples/passing/OptimizerBug.pursdeleted−9
@@ -1,9 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−x a = 1.0 + y a
6−
7−y a = x a
8−
9−main = Control.Monad.Eff.Console.log "Done"
examples/passing/OptionalQualified.pursdeleted−13
@@ -1,13 +0,0 @@
1−module Main where
2−
3−-- qualified import with the "qualified" keyword
4−import qualified Prelude as P
5−
6−-- qualified import without the "qualified" keyword
7−import Control.Monad.Eff.Console as Console
8−
9−bind = P.bind
10−
11−main = do
12− message <- P.return "success!"
13− Console.log message
examples/passing/OverlappingInstances.pursdeleted−13
@@ -1,13 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−data A = A
6−
7−instance showA1 :: Show A where
8− show A = "Instance 1"
9−
10−instance showA2 :: Show A where
11− show A = "Instance 2"
12−
13−main = Test.Assert.assert $ show A == "Instance 1"
examples/passing/OverlappingInstances2.pursdeleted−23
@@ -1,23 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−data A = A | B
6−
7−instance eqA1 :: Eq A where
8− eq A A = true
9− eq B B = true
10− eq _ _ = false
11−
12−instance eqA2 :: Eq A where
13− eq _ _ = true
14−
15−instance ordA :: Ord A where
16− compare A B = LT
17− compare B A = GT
18− compare _ _ = EQ
19−
20−test :: forall a. (Ord a) => a -> a -> String
21−test x y = show $ x == y
22−
23−main = Test.Assert.assert $ test A B == "false"
examples/passing/OverlappingInstances3.pursdeleted−16
@@ -1,16 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−class Foo a
6−
7−instance foo1 :: Foo Number
8−
9−instance foo2 :: Foo Number
10−
11−test :: forall a. (Foo a) => a -> a
12−test a = a
13−
14−test1 = test 0.0
15−
16−main = Test.Assert.assert (test1 == 0.0)
examples/passing/PartialFunction.pursdeleted−10
@@ -1,10 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Test.Assert
5−
6−fn :: Number -> Number
7−fn 0.0 = 0.0
8−fn 1.0 = 2.0
9−
10−main = assertThrows $ \_ -> fn 2.0
examples/passing/Patterns.pursdeleted−22
@@ -1,22 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−test = \x -> case x of
6− { str = "Foo", bool = true } -> true
7− { str = "Bar", bool = b } -> b
8− _ -> false
9−
10−f = \o -> case o of
11− { foo = "Foo" } -> o.bar
12− _ -> 0
13−
14−h = \o -> case o of
15− a@[_,_,_] -> a
16− _ -> []
17−
18−isDesc :: Array Number -> Boolean
19−isDesc [x, y] | x > y = true
20−isDesc _ = false
21−
22−main = Control.Monad.Eff.Console.log "Done"
examples/passing/PendingConflictingImports.pursdeleted−17
@@ -1,17 +0,0 @@
1−module A where
2−
3− thing :: Int
4− thing = 1
5−
6−module B where
7−
8− thing :: Int
9− thing = 2
10−
11−module Main where
12−
13− -- No error as we never force `thing` to be resolved in `Main`
14− import A
15− import B
16−
17− main = Control.Monad.Eff.Console.log "Done"
examples/passing/PendingConflictingImports2.pursdeleted−14
@@ -1,14 +0,0 @@
1−module A where
2−
3− thing :: Int
4− thing = 1
5−
6−module Main where
7−
8− import A
9−
10− -- No error as we never force `thing` to be resolved in `Main`
11− thing :: Int
12− thing = 2
13−
14− main = Control.Monad.Eff.Console.log "Done"
examples/passing/Person.pursdeleted−11
@@ -1,11 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−data Person = Person { name :: String, age :: Number }
6−
7−showPerson :: Person -> String
8−showPerson = \p -> case p of
9− Person o -> o.name ++ ", aged " ++ show o.age
10−
11−main = Control.Monad.Eff.Console.log "Done"
examples/passing/QualifiedQualifiedImports.pursdeleted−6
@@ -1,6 +0,0 @@
1−module Main where
2−
3−-- qualified import with qualified imported names
4−import qualified Control.Monad.Eff.Console (log) as Console
5−
6−main = Console.log "Success!"
examples/passing/Rank2Data.pursdeleted−29
@@ -1,29 +0,0 @@
1−module Main where
2−
3−import Prelude hiding (add)
4−
5−data Id = Id forall a. a -> a
6−
7−runId = \id a -> case id of
8− Id f -> f a
9−
10−data Nat = Nat forall r. r -> (r -> r) -> r
11−
12−runNat = \nat -> case nat of
13− Nat f -> f 0.0 (\n -> n + 1.0)
14−
15−zero' = Nat (\zero' _ -> zero')
16−
17−succ = \n -> case n of
18− Nat f -> Nat (\zero' succ -> succ (f zero' succ))
19−
20−add = \n m -> case n of
21− Nat f -> case m of
22− Nat g -> Nat (\zero' succ -> g (f zero' succ) succ)
23−
24−one' = succ zero'
25−two = succ zero'
26−four = add two two
27−fourNumber = runNat four
28−
29−main = Control.Monad.Eff.Console.log "Done'"
examples/passing/Rank2Object.pursdeleted−11
@@ -1,11 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff.Console
5−
6−data Foo = Foo { id :: forall a. a -> a }
7−
8−foo :: Foo -> Number
9−foo (Foo { id = f }) = f 0.0
10−
11−main = log "Done"
examples/passing/Rank2TypeSynonym.pursdeleted−16
@@ -1,16 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff
5−
6−type Foo a = forall f. (Monad f) => f a
7−
8−foo :: forall a. a -> Foo a
9−foo x = pure x
10−
11−bar :: Foo Number
12−bar = foo 3.0
13−
14−main = do
15− x <- bar
16− Control.Monad.Eff.Console.print x
examples/passing/Rank2Types.pursdeleted−11
@@ -1,11 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−test1 :: (forall a. (a -> a)) -> Number
6−test1 = \f -> f 0.0
7−
8−forever :: forall m a b. (forall a b. m a -> (a -> m b) -> m b) -> m a -> m b
9−forever = \bind action -> bind action $ \_ -> forever bind action
10−
11−main = Control.Monad.Eff.Console.log "Done"
examples/passing/ReExportQualified.pursdeleted−16
@@ -1,16 +0,0 @@
1−module A where
2− x = "Do"
3−
4−module B where
5− y = "ne"
6−
7−module C (module A, module M2) where
8− import A
9− import qualified B as M2
10−
11−module Main where
12−
13− import Prelude
14− import C
15−
16− main = Control.Monad.Eff.Console.log (x ++ y)
examples/passing/RebindableSyntax.pursdeleted−39
@@ -1,39 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−example1 :: String
6−example1 = do
7− "Do"
8− " notation"
9− " for"
10− " Semigroup"
11− where
12− bind x f = x <> f unit
13−
14−(*>) :: forall f a b. (Apply f) => f a -> f b -> f b
15−(*>) fa fb = const id <$> fa <*> fb
16−
17−newtype Const a b = Const a
18−
19−runConst :: forall a b. Const a b -> a
20−runConst (Const a) = a
21−
22−instance functorConst :: Functor (Const a) where
23− map _ (Const a) = Const a
24−
25−instance applyConst :: (Semigroup a) => Apply (Const a) where
26− apply (Const a1) (Const a2) = Const (a1 <> a2)
27−
28−example2 :: Const String Unit
29−example2 = do
30− Const "Do"
31− Const " notation"
32− Const " for"
33− Const " Apply"
34− where
35− bind x f = x *> f unit
36−
37−main = do
38− Control.Monad.Eff.Console.log example1
39− Control.Monad.Eff.Console.log $ runConst example2
examples/passing/Recursion.pursdeleted−10
@@ -1,10 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−fib = \n -> case n of
6− 0.0 -> 1.0
7− 1.0 -> 1.0
8− n -> fib (n - 1.0) + fib (n - 2.0)
9−
10−main = Control.Monad.Eff.Console.log "Done"
examples/passing/ReservedWords.pursdeleted−15
@@ -1,15 +0,0 @@
1−-- See https://github.com/purescript/purescript/issues/606
2−module Main where
3−
4−import Prelude
5−
6−o :: { type :: String }
7−o = { type: "o" }
8−
9−p :: { type :: String }
10−p = o { type = "p" }
11−
12−f :: forall r. { type :: String | r } -> String
13−f { type = "p" } = "Done"
14−
15−main = Control.Monad.Eff.Console.log $ f { type: p.type, foo: "bar" }
examples/passing/ResolvableScopeConflict.pursdeleted−25
@@ -1,25 +0,0 @@
1−module A where
2−
3− thing :: Int
4− thing = 1
5−
6−module B where
7−
8− thing :: Int
9− thing = 2
10−
11− zing :: Int
12− zing = 3
13−
14−module Main where
15−
16− import A (thing)
17− import B
18−
19− -- Not an error as although we have `thing` in scope from both A and B, it is
20− -- imported explicitly from A, giving it a resolvable solution.
21− what :: Boolean -> Int
22− what true = thing
23− what false = zing
24−
25− main = Control.Monad.Eff.Console.log "Done"
examples/passing/ResolvableScopeConflict2.pursdeleted−22
@@ -1,22 +0,0 @@
1−module A where
2−
3− thing :: Int
4− thing = 2
5−
6− zing :: Int
7− zing = 3
8−
9−module Main where
10−
11− import A
12−
13− thing :: Int
14− thing = 1
15−
16− -- Not an error as although we have `thing` in scope from both Main and A,
17− -- as the local declaration takes precedence over the implicit import
18− what :: Boolean -> Int
19− what true = thing
20− what false = zing
21−
22− main = Control.Monad.Eff.Console.log "Done"
examples/passing/ResolvableScopeConflict3.pursdeleted−15
@@ -1,15 +0,0 @@
1−module A where
2−
3− thing :: Int
4− thing = 1
5−
6−module Main (thing, main, module A) where
7−
8− import A
9−
10− thing :: Int
11− thing = 2
12−
13− main = Control.Monad.Eff.Console.log "Done"
14−
15−
examples/passing/RowConstructors.pursdeleted−42
@@ -1,42 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−type Foo = (x :: Number | (y :: Number | (z :: Number)))
6−type Bar = (x :: Number, y :: Number, z :: Number)
7−type Baz = { w :: Number | Bar }
8−
9−foo :: { | Foo }
10−foo = { x: 0.0, y: 0.0, z: 0.0 }
11−
12−bar :: { | Bar }
13−bar = { x: 0.0, y: 0.0, z: 0.0 }
14−
15−id' :: Object Foo -> Object Bar
16−id' = id
17−
18−foo' :: { | Foo }
19−foo' = id' foo
20−
21−bar' :: { | Bar }
22−bar' = id' bar
23−
24−baz :: Baz
25−baz = { x: 0.0, y: 0.0, z: 0.0, w: 0.0 }
26−
27−type Quux r = (q :: Number | r)
28−type Norf r = (q' :: Number | Quux r)
29−
30−quux :: { f :: { | Foo } | Quux Bar }
31−quux = { f: foo', x: 0.0, y: 0.0, z: 0.0, q: 0.0 }
32−
33−quux' :: { | Norf Bar }
34−quux' = { x: 0.0, y: 0.0, z: 0.0, q: 0.0, q': 0.0 }
35−
36−wildcard :: { w :: Number | _ } -> Baz
37−wildcard { w: w } = { x: w, y: w, z: w, w: w }
38−
39−wildcard' :: { | Quux _ } -> Number
40−wildcard' { q: q } = q
41−
42−main = Control.Monad.Eff.Console.log "Done"
examples/passing/RowPolyInstanceContext.pursdeleted−22
@@ -1,22 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−class T s m where
6− state :: (s -> s) -> m Unit
7−
8−data S s a = S (s -> { new :: s, ret :: a })
9−
10−instance st :: T s (S s) where
11− state f = S $ \s -> { new: f s, ret: unit }
12−
13−test1 :: forall r . S { foo :: String | r } Unit
14−test1 = state $ \o -> o { foo = o.foo ++ "!" }
15−
16−test2 :: forall m r . (T { foo :: String | r } m) => m Unit
17−test2 = state $ \o -> o { foo = o.foo ++ "!" }
18−
19−main = do
20− let t1 = test1
21− let t2 = test2
22− Control.Monad.Eff.Console.log "Done"
examples/passing/RuntimeScopeIssue.pursdeleted−19
@@ -1,19 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−class A a where
6− a :: a -> Boolean
7−
8−class B a where
9− b :: a -> Boolean
10−
11−instance aNumber :: A Number where
12− a 0.0 = true
13− a n = b (n - 1.0)
14−
15−instance bNumber :: B Number where
16− b 0.0 = false
17− b n = a (n - 1.0)
18−
19−main = Control.Monad.Eff.Console.print $ a 10.0
examples/passing/ScopedTypeVariables.pursdeleted−36
@@ -1,36 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−test1 :: forall a. (a -> a) -> a -> a
6−test1 f x = g (g x)
7− where
8− g :: a -> a
9− g y = f (f y)
10−
11−test2 :: forall a. (a -> a) -> a -> a
12−test2 = h
13− where
14− h :: forall b. (b -> b) -> b -> b
15− h f x = g (g x)
16− where
17− g :: b -> b
18− g y = f (f y)
19−
20−test3 :: Number
21−test3 = ((\b -> b :: b) :: forall b. b -> b) 0.0
22−
23−test4 :: forall a. (a -> a) -> a -> a
24−test4 = h
25− where
26− h :: forall b. (b -> b) -> b -> b
27− h f x = g (g x)
28− where
29− g :: b -> b
30− g y = j (f (f y))
31− where
32− j :: forall b. b -> b
33− j x = x
34−
35−
36−main = Control.Monad.Eff.Console.log "Done"
examples/passing/Sequence.pursdeleted−15
@@ -1,15 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff
5−
6−data List a = Cons a (List a) | Nil
7−
8−class Sequence t where
9− sequence :: forall m a. (Monad m) => t (m a) -> m (t a)
10−
11−instance sequenceList :: Sequence List where
12− sequence Nil = pure Nil
13− sequence (Cons x xs) = Cons <$> x <*> sequence xs
14−
15−main = sequence $ Cons (Control.Monad.Eff.Console.log "Done") Nil
examples/passing/SequenceDesugared.pursdeleted−37
@@ -1,37 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff
5−
6−data List a = Cons a (List a) | Nil
7−
8−data Sequence t = Sequence (forall m a. (Monad m) => t (m a) -> m (t a))
9−
10−sequence :: forall t. Sequence t -> (forall m a. (Monad m) => t (m a) -> m (t a))
11−sequence (Sequence s) = s
12−
13−sequenceListSeq :: forall m a. (Monad m) => List (m a) -> m (List a)
14−sequenceListSeq Nil = pure Nil
15−sequenceListSeq (Cons x xs) = Cons <$> x <*> sequenceListSeq xs
16−
17−sequenceList :: Sequence List
18−sequenceList = Sequence (sequenceListSeq)
19−
20−sequenceList' :: Sequence List
21−sequenceList' = Sequence ((\val -> case val of
22− Nil -> pure Nil
23− Cons x xs -> Cons <$> x <*> sequence sequenceList' xs))
24−
25−sequenceList'' :: Sequence List
26−sequenceList'' = Sequence (sequenceListSeq :: forall m a. (Monad m) => List (m a) -> m (List a))
27−
28−sequenceList''' :: Sequence List
29−sequenceList''' = Sequence ((\val -> case val of
30− Nil -> pure Nil
31− Cons x xs -> Cons <$> x <*> sequence sequenceList''' xs) :: forall m a. (Monad m) => List (m a) -> m (List a))
32−
33−main = do
34− sequence sequenceList $ Cons (Control.Monad.Eff.Console.log "Done") Nil
35− sequence sequenceList' $ Cons (Control.Monad.Eff.Console.log "Done") Nil
36− sequence sequenceList'' $ Cons (Control.Monad.Eff.Console.log "Done") Nil
37− sequence sequenceList''' $ Cons (Control.Monad.Eff.Console.log "Done") Nil
examples/passing/ShadowedModuleName.pursdeleted−15
@@ -1,15 +0,0 @@
1−module Test where
2−
3− data Z = Z String
4−
5− runZ :: Z -> String
6− runZ (Z s) = s
7−
8−module Main where
9−
10− import Test
11− import Control.Monad.Eff.Console
12−
13− data Test = Test
14−
15− main = log (runZ (Z "done"))
examples/passing/ShadowedRename.pursdeleted−14
@@ -1,14 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff
5−import Control.Monad.Eff.Console
6−import Test.Assert
7−
8−foo foo = let foo_1 = \_ -> foo
9− foo_2 = foo_1 unit + 1.0
10− in foo_2
11−
12−main = do
13− assert $ foo 1.0 == 2.0
14− log "Done"
examples/passing/ShadowedTCO.pursdeleted−18
@@ -1,18 +0,0 @@
1−module Main where
2−
3−import Prelude hiding (add)
4−
5−runNat f = f 0.0 (\n -> n + 1.0)
6−
7−zero' z _ = z
8−
9−succ f zero' succ = succ (f zero' succ)
10−
11−add f g zero' succ = g (f zero' succ) succ
12−
13−one' = succ zero'
14−two = succ one'
15−four = add two two
16−fourNumber = runNat four
17−
18−main = Control.Monad.Eff.Console.log $ show fourNumber
examples/passing/ShadowedTCOLet.pursdeleted−9
@@ -1,9 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−f x y z =
6− let f 1.0 2.0 3.0 = 1.0
7− in f x z y
8−
9−main = Control.Monad.Eff.Console.log $ show $ f 1.0 3.0 2.0
examples/passing/SignedNumericLiterals.pursdeleted−17
@@ -1,17 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−p = 0.5
6−q = 1.0
7−x = -1.0
8−y = -0.5
9−z = 0.5
10−w = 1.0
11−
12−f :: Number -> Number
13−f x = -x
14−
15−test1 = 2.0 - 1.0
16−
17−main = Control.Monad.Eff.Console.log "Done"
examples/passing/StringEscapes.pursdeleted−15
@@ -1,15 +0,0 @@
1−module Main where
2−
3−import Prelude ((==), bind)
4−import Test.Assert (assert)
5−
6−singleCharacter = "\0\b\t\n\v\f\r\"\\" == "\x0\x8\x9\xA\xB\xC\xD\x22\x5C"
7−hex = "\x1D306\x2603\x3C6\xE0\x0" == "𝌆☃φà\0"
8−decimal = "\119558\9731\966\224\0" == "𝌆☃φà\0"
9−surrogatePair = "\xD834\xDF06" == "\x1D306"
10−
11−main = do
12− assert singleCharacter
13− assert hex
14− assert decimal
15− assert surrogatePair
examples/passing/Superclasses1.pursdeleted−20
@@ -1,20 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−class Su a where
6− su :: a -> a
7−
8−class (Su a) <= Cl a where
9− cl :: a -> a -> a
10−
11−instance suNumber :: Su Number where
12− su n = n + 1.0
13−
14−instance clNumber :: Cl Number where
15− cl n m = n + m
16−
17−test :: forall a. (Cl a) => a -> a
18−test a = su (cl a a)
19−
20−main = Control.Monad.Eff.Console.print $ test 10.0
examples/passing/Superclasses3.pursdeleted−41
@@ -1,41 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff.Console
5−import Control.Monad.Eff
6−
7−class (Monad m) <= MonadWriter w m where
8− tell :: w -> m Unit
9−
10−testFunctor :: forall m. (Monad m) => m Number -> m Number
11−testFunctor n = (+) 1.0 <$> n
12−
13−test :: forall w m. (Monad m, MonadWriter w m) => w -> m Unit
14−test w = do
15− tell w
16− tell w
17− tell w
18−
19−data MTrace a = MTrace (Eff (console :: CONSOLE) a)
20−
21−runMTrace :: forall a. MTrace a -> Eff (console :: CONSOLE) a
22−runMTrace (MTrace a) = a
23−
24−instance functorMTrace :: Functor MTrace where
25− map = liftM1
26−
27−instance applyMTrace :: Apply MTrace where
28− apply = ap
29−
30−instance applicativeMTrace :: Applicative MTrace where
31− pure = MTrace <<< return
32−
33−instance bindMTrace :: Bind MTrace where
34− bind m f = MTrace (runMTrace m >>= (runMTrace <<< f))
35−
36−instance monadMTrace :: Monad MTrace
37−
38−instance writerMTrace :: MonadWriter String MTrace where
39− tell s = MTrace (log s)
40−
41−main = runMTrace $ test "Done"
examples/passing/TCO.pursdeleted−20
@@ -1,20 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff.Console (print)
5−
6−main = do
7− let f x = x + 1
8− let v = 0
9− print (applyN 0 f v)
10− print (applyN 1 f v)
11− print (applyN 2 f v)
12− print (applyN 3 f v)
13− print (applyN 4 f v)
14−
15−applyN :: forall a. Int -> (a -> a) -> a -> a
16−applyN = go id
17− where
18− go f n _ | n <= 0 = f
19− go f n g = go (f >>> g) (n - 1) g
20−
examples/passing/TCOCase.pursdeleted−12
@@ -1,12 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−data Data = One | More Data
6−
7−main = Control.Monad.Eff.Console.log (from (to 10000.0 One))
8− where
9− to 0.0 a = a
10− to n a = to (n - 1.0) (More a)
11− from One = "Done"
12− from (More d) = from d
examples/passing/TailCall.pursdeleted−17
@@ -1,17 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−data L a = C a (L a) | N
6−
7−test :: Number -> L Number -> Number
8−test n N = n
9−test n (C x xs) = test (n + x) xs
10−
11−loop :: forall a. Number -> a
12−loop x = loop (x + 1.0)
13−
14−notATailCall = \x ->
15− (\notATailCall -> notATailCall x) (\x -> x)
16−
17−main = Control.Monad.Eff.Console.print (test 0.0 (1.0 `C` (2.0 `C` (3.0 `C` N))))
examples/passing/Tick.pursdeleted−7
@@ -1,7 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−test' x = x
6−
7−main = Control.Monad.Eff.Console.log "Done"
examples/passing/TopLevelCase.pursdeleted−18
@@ -1,18 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−gcd :: Number -> Number -> Number
6−gcd 0.0 x = x
7−gcd x 0.0 = x
8−gcd x y | x > y = gcd (x `mod` y) y
9−gcd x y = gcd (y `mod` x) x
10−
11−guardsTest [x] | x > 0.0 = []
12−guardsTest xs = xs
13−
14−data A = A
15−
16−parseTest A 0.0 = 0.0
17−
18−main = Control.Monad.Eff.Console.log "Done"
examples/passing/TypeClassMemberOrderChange.pursdeleted−13
@@ -1,13 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−class Test a where
6− fn :: a -> a -> a
7− val :: a
8−
9−instance testBoolean :: Test Boolean where
10− val = true
11− fn x y = y
12−
13−main = Control.Monad.Eff.Console.log (show (fn true val))
examples/passing/TypeClasses.pursdeleted−69
@@ -1,69 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−test1 = \_ -> show "testing"
6−
7−f :: forall a. (Prelude.Show a) => a -> String
8−f x = show x
9−
10−test2 = \_ -> f "testing"
11−
12−test7 :: forall a. (Prelude.Show a) => a -> String
13−test7 = show
14−
15−test8 = \_ -> show $ "testing"
16−
17−data Data a = Data a
18−
19−instance showData :: (Prelude.Show a) => Prelude.Show (Data a) where
20− show (Data a) = "Data (" ++ show a ++ ")"
21−
22−test3 = \_ -> show (Data "testing")
23−
24−instance functorData :: Functor Data where
25− map = liftM1
26−
27−instance applyData :: Apply Data where
28− apply = ap
29−
30−instance applicativeData :: Applicative Data where
31− pure = Data
32−
33−instance bindData :: Bind Data where
34− bind (Data a) f = f a
35−
36−instance monadData :: Monad Data
37−
38−data Maybe a = Nothing | Just a
39−
40−instance functorMaybe :: Functor Maybe where
41− map = liftM1
42−
43−instance applyMaybe :: Apply Maybe where
44− apply = ap
45−
46−instance applicativeMaybe :: Applicative Maybe where
47− pure = Just
48−
49−instance bindMaybe :: Bind Maybe where
50− bind Nothing _ = Nothing
51− bind (Just a) f = f a
52−
53−instance monadMaybe :: Monad Maybe
54−
55−test4 :: forall a m. (Monad m) => a -> m Number
56−test4 = \_ -> return 1.0
57−
58−test5 = \_ -> Just 1.0 >>= \n -> return (n + 1.0)
59−
60−ask r = r
61−
62−runReader r f = f r
63−
64−test9 _ = runReader 0.0 $ do
65− n <- ask
66− return $ n + 1.0
67−
68−main = Control.Monad.Eff.Console.log (test7 "Done")
69−
examples/passing/TypeClassesInOrder.pursdeleted−11
@@ -1,11 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−class Foo a where
6− foo :: a -> String
7−
8−instance fooString :: Foo String where
9− foo s = s
10−
11−main = Control.Monad.Eff.Console.log $ foo "Done"
examples/passing/TypeClassesWithOverlappingTypeVariables.pursdeleted−11
@@ -1,11 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−data Either a b = Left a | Right b
6−
7−instance functorEither :: Prelude.Functor (Either a) where
8− map _ (Left x) = Left x
9− map f (Right y) = Right (f y)
10−
11−main = Control.Monad.Eff.Console.log "Done"
examples/passing/TypeDecl.pursdeleted−12
@@ -1,12 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−k :: String -> Number -> String
6−k x y = x
7−
8−iterate :: forall a. Number -> (a -> a) -> a -> a
9−iterate 0.0 f a = a
10−iterate n f a = iterate (n - 1.0) f (f a)
11−
12−main = Control.Monad.Eff.Console.log "Done"
examples/passing/TypeOperators.pursdeleted−34
@@ -1,34 +0,0 @@
1−module A
2− ( Tuple(..)
3− , type (/\)
4− , (/\)
5− , Natural
6− , type (~>)
7− ) where
8−
9− data Tuple a b = Tuple a b
10−
11− infixl 6 Tuple as /\
12− infixl 6 type Tuple as /\
13−
14− type Natural f g = ∀ a. f a → g a
15−
16− infixr 0 type Natural as ~>
17−
18− tup ∷ ∀ a b. a → b → b /\ a
19− tup a b = b /\ a
20−
21− tupX ∷ ∀ a b c. a /\ b /\ c → c
22− tupX (a /\ b /\ c) = c
23−
24−module Main where
25−
26− import A (type (~>), type (/\), (/\))
27−
28− natty ∷ ∀ f. f ~> f
29− natty x = x
30−
31− swap ∷ ∀ a b. a /\ b → b /\ a
32− swap (a /\ b) = b /\ a
33−
34− main = Control.Monad.Eff.Console.log "Done"
examples/passing/TypeSynonymInData.pursdeleted−11
@@ -1,11 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−type A a = Array a
6−
7−data Foo a = Foo (A a) | Bar
8−
9−foo (Foo []) = Bar
10−
11−main = Control.Monad.Eff.Console.log "Done"
examples/passing/TypeSynonyms.pursdeleted−27
@@ -1,27 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−type Lens a b =
6− { get :: a -> b
7− , set :: a -> b -> a
8− }
9−
10−composeLenses :: forall a b c. Lens a b -> Lens b c -> Lens a c
11−composeLenses = \l1 -> \l2 ->
12− { get: \a -> l2.get (l1.get a)
13− , set: \a c -> l1.set a (l2.set (l1.get a) c)
14− }
15−
16−type Pair a b = { fst :: a, snd :: b }
17−
18−fst :: forall a b. Lens (Pair a b) a
19−fst =
20− { get: \p -> p.fst
21− , set: \p a -> { fst: a, snd: p.snd }
22− }
23−
24−test1 :: forall a b c. Lens (Pair (Pair a b) c) a
25−test1 = composeLenses fst fst
26−
27−main = Control.Monad.Eff.Console.log "Done"
examples/passing/TypeWildcards.pursdeleted−15
@@ -1,15 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−testTopLevel :: _ -> _
6−testTopLevel n = n + 1.0
7−
8−test :: forall a. (Eq a) => (a -> a) -> a -> a
9−test f a = go (f a) a
10− where
11− go :: _ -> _ -> _
12− go a1 a2 | a1 == a2 = a1
13− go a1 _ = go (f a1) a1
14−
15−main = Control.Monad.Eff.Console.log "Done"
examples/passing/TypeWildcardsRecordExtension.pursdeleted−8
@@ -1,8 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−foo :: forall a. {b :: Number | a} -> {b :: Number | _}
6−foo f = f
7−
8−main = Control.Monad.Eff.Console.log "Done"
examples/passing/TypeWithoutParens.pursdeleted−16
@@ -1,16 +0,0 @@
1−module Lib (X, Y) where
2−
3− data X = X
4− type Y = X
5−
6−module Main where
7−
8− import Lib (X, Y)
9−
10− idX :: X -> X
11− idX x = x
12−
13− idY :: Y -> Y
14− idY y = y
15−
16− main = Control.Monad.Eff.Console.log "Done"
examples/passing/TypedBinders.pursdeleted−67
@@ -1,67 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−data Tuple a b = Tuple a b
6−
7−class MonadState s m where
8− get :: m s
9− put :: s -> m {}
10−
11−data State s a = State (s -> Tuple s a)
12−
13−runState s (State f) = f s
14−
15−instance functorState :: Functor (State s) where
16− map = liftM1
17−
18−instance applyState :: Apply (State s) where
19− apply = ap
20−
21−instance applicativeState :: Applicative (State s) where
22− pure a = State $ \s -> Tuple s a
23−
24−instance bindState :: Bind (State s) where
25− bind f g = State $ \s -> case runState s f of
26− Tuple s1 a -> runState s1 (g a)
27−
28−instance monadState :: Monad (State s)
29−
30−instance monadStateState :: MonadState s (State s) where
31− get = State (\s -> Tuple s s)
32− put s = State (\_ -> Tuple s {})
33−
34−modify :: forall m s. (Prelude.Monad m, MonadState s m) => (s -> s) -> m {}
35−modify f = do
36− s <- get
37− put (f s)
38−
39−test :: Tuple String String
40−test = runState "" $ do
41− modify $ (++) "World!"
42− modify $ (++) "Hello, "
43− str :: String <- get
44− return str
45−
46−test2 :: (Int -> Int) -> Int
47−test2 = (\(f :: Int -> Int) -> f 10)
48−
49−test3 :: Int -> Boolean
50−test3 n = case n of
51− (0 :: Int) -> true
52− _ -> false
53−
54−test4 :: Tuple Int Int -> Tuple Int Int
55−test4 = (\(Tuple a b :: Tuple Int Int) -> Tuple b a)
56−
57−type Int1 = Int
58−
59−test5 :: Int1 -> Int1
60−test5 = \(x :: Int1) -> x
61−
62−main = do
63− let t1 = test
64− t2 = test2 id
65− t3 = test3 1
66− t4 = test4 (Tuple 1 0)
67− Control.Monad.Eff.Console.log "Done"
examples/passing/TypedWhere.pursdeleted−17
@@ -1,17 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−data E a b = L a | R b
6−
7−data L a = C a (L a) | N
8−
9−lefts :: forall a b. L (E a b) -> L a
10−lefts = go N
11− where
12− go :: forall a b. L a -> L (E a b) -> L a
13− go ls N = ls
14− go ls (C (L a) rest) = go (C a ls) rest
15− go ls (C _ rest) = go ls rest
16−
17−main = Control.Monad.Eff.Console.log "Done"
examples/passing/UTF8Sourcefile.pursdeleted−10
@@ -1,10 +0,0 @@
1−module Main where
2−
3−import Control.Monad.Eff.Console
4−
5−-- '→' is multibyte sequence \u2192.
6−utf8multibyte = "Hello λ→ world!!"
7−
8−main = do
9− log "done"
10−
examples/passing/UnderscoreIdent.pursdeleted−11
@@ -1,11 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−data Data_type = Con_Structor | Con_2 String
6−
7−type Type_name = Data_type
8−
9−done (Con_2 s) = s
10−
11−main = Control.Monad.Eff.Console.log (done (Con_2 "Done"))
examples/passing/UnicodeIdentifier.pursdeleted−5
@@ -1,5 +0,0 @@
1−module Main where
2−
3−f asgård = asgård
4−
5−main = Control.Monad.Eff.Console.log (f "Done")
examples/passing/UnicodeOperators.pursdeleted−20
@@ -1,20 +0,0 @@
1−module Main where
2−
3−compose :: forall a b c. (b -> c) -> (a -> b) -> a -> c
4−compose f g a = f (g a)
5−
6−infixr 9 compose as ∘
7−
8−test1 = (\x -> x) ∘ \y -> y
9−
10−elem :: forall a b. a -> (a -> Boolean) -> Boolean
11−elem x f = f x
12−
13−infixl 1 elem as ∈
14−
15−emptySet :: forall a. a -> Boolean
16−emptySet _ = true
17−
18−test2 = 1 ∈ emptySet
19−
20−main = Control.Monad.Eff.Console.log "Done"
examples/passing/UnicodeType.pursdeleted−23
@@ -1,23 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−class (Monad m) ⇐ Monad1 m where
6− f1 :: Int
7−
8−class (Monad m) <= Monad2 m where
9− f2 :: Int
10−
11−f ∷ ∀ m. Monad m ⇒ Int → m Int
12−f n = do
13− n' ← return n
14− return n'
15−
16−f' :: forall m. Monad m => Int -> m Int
17−f' n = do
18− n' <- return n
19− return n'
20−
21−(←→) a b = a ←→ b
22−
23−main = Control.Monad.Eff.Console.log "Done"
examples/passing/Unit.pursdeleted−6
@@ -1,6 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff.Console
5−
6−main = print (const unit $ "Hello world")
examples/passing/UnknownInTypeClassLookup.pursdeleted−14
@@ -1,14 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−class EQ a b
6−
7−instance eqAA :: EQ a a
8−
9−test :: forall a b. (EQ a b) => a -> b -> String
10−test _ _ = "Done"
11−
12−runTest a = test a a
13−
14−main = Control.Monad.Eff.Console.log $ runTest 0.0
examples/passing/UntupledConstraints.pursdeleted−17
@@ -1,17 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff.Console
5−
6−class Show a <= Nonsense a where
7− method :: a -> a
8−
9−data Box a = Box a
10−
11−instance showBox :: Show a => Show (Box a) where
12− show (Box a) = "Box " <> show a
13−
14−strangeThing :: forall m. Semigroup (m Unit) => m Unit -> m Unit -> m Unit
15−strangeThing x y = x <> y
16−
17−main = log "Done"
examples/passing/Where.pursdeleted−49
@@ -1,49 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff
5−import Control.Monad.ST
6−
7−test1 x = y
8− where
9− y :: Number
10− y = x + 1.0
11−
12−test2 x y = x' + y'
13− where
14− x' = x + 1.0
15− y' = y + 1.0
16−
17−
18−test3 = f 1.0 2.0 3.0
19− where f x y z = x + y + z
20−
21−
22−test4 = f (+) [1.0, 2.0]
23− where f x [y, z] = x y z
24−
25−
26−test5 = g 10.0
27− where
28− f x | x > 0.0 = g (x / 2.0) + 1.0
29− f x = 0.0
30− g x = f (x - 1.0) + 1.0
31−
32−test6 = if f true then f 1.0 else f 2.0
33− where f :: forall a. a -> a
34− f x = x
35−
36−test7 :: Number -> Number
37−test7 x = go x
38− where
39− go y | (x - 0.1 < y * y) && (y * y < x + 0.1) = y
40− go y = go $ (y + x / y) / 2.0
41−
42−main = do
43− Control.Monad.Eff.Console.print (test1 1.0)
44− Control.Monad.Eff.Console.print (test2 1.0 2.0)
45− Control.Monad.Eff.Console.print test3
46− Control.Monad.Eff.Console.print test4
47− Control.Monad.Eff.Console.print test5
48− Control.Monad.Eff.Console.print test6
49− Control.Monad.Eff.Console.print (test7 100.0)
examples/passing/iota.pursdeleted−9
@@ -1,9 +0,0 @@
1−module Main where
2−
3−s = \x -> \y -> \z -> x z (y z)
4−
5−k = \x -> \y -> x
6−
7−iota = \x -> x s k
8−
9−main = Control.Monad.Eff.Console.log "Done"
examples/passing/s.pursdeleted−7
@@ -1,7 +0,0 @@
1−module Main where
2−
3−import Prelude
4−
5−s = \x y z -> x z (y z)
6−
7−main = Control.Monad.Eff.Console.log "Done"
hierarchy/Main.hsdeleted−115
@@ -1,115 +0,0 @@
1−-----------------------------------------------------------------------------
2−--
3−-- Module : Main
4−-- Copyright : (c) Hardy Jones 2014
5−-- License : MIT (http://opensource.org/licenses/MIT)
6−--
7−-- Maintainer : Hardy Jones <jones3.hardy@gmail.com>
8−-- Stability : experimental
9−-- Portability :
10−--
11−-- |
12−-- Generate Directed Graphs of PureScript TypeClasses
13−--
14−-----------------------------------------------------------------------------
15−
16−{-# LANGUAGE TupleSections #-}
17−{-# LANGUAGE DataKinds #-}
18−
19−module Main where
20−
21−import Control.Monad (unless)
22−
23−import Data.List (intercalate,nub,sort)
24−import Data.Foldable (for_)
25−import Data.Version (showVersion)
26−
27−import Options.Applicative
28−import System.Directory (createDirectoryIfMissing)
29−import System.FilePath ((</>))
30−import System.FilePath.Glob (glob)
31−import System.Exit (exitFailure, exitSuccess)
32−import System.IO (hPutStr, stderr)
33−
34−import qualified Language.PureScript as P
35−import qualified Paths_purescript as Paths
36−
37−data HierarchyOptions = HierarchyOptions
38− { hierachyInput :: FilePath
39− , hierarchyOutput :: Maybe FilePath
40− }
41−
42−newtype SuperMap = SuperMap { unSuperMap :: Either (P.ProperName 'P.ClassName) ((P.ProperName 'P.ClassName), (P.ProperName 'P.ClassName)) }
43− deriving Eq
44−
45−instance Show SuperMap where
46− show (SuperMap (Left sub)) = show sub
47− show (SuperMap (Right (super, sub))) = show super ++ " -> " ++ show sub
48−
49−instance Ord SuperMap where
50− compare (SuperMap s) (SuperMap s') = getCls s `compare` getCls s'
51− where
52− getCls = either id snd
53−
54−runModuleName :: P.ModuleName -> String
55−runModuleName (P.ModuleName pns) = intercalate "_" (P.runProperName `map` pns)
56−
57−readInput :: [FilePath] -> IO (Either P.MultipleErrors [P.Module])
58−readInput paths = do
59− content <- mapM (\path -> (path, ) <$> readFile path) paths
60− return $ map snd <$> P.parseModulesFromFiles id content
61−
62−compile :: HierarchyOptions -> IO ()
63−compile (HierarchyOptions inputGlob mOutput) = do
64− input <- glob inputGlob
65− modules <- readInput input
66− case modules of
67− Left errs -> hPutStr stderr (P.prettyPrintMultipleErrors False errs) >> exitFailure
68− Right ms -> do
69− for_ ms $ \(P.Module _ _ moduleName decls _) ->
70− let name = runModuleName moduleName
71− tcs = filter P.isTypeClassDeclaration decls
72− supers = sort . nub . filter (not . null) $ fmap superClasses tcs
73− prologue = "digraph " ++ name ++ " {\n"
74− body = intercalate "\n" (concatMap (fmap (\s -> " " ++ show s ++ ";")) supers)
75− epilogue = "\n}"
76− hier = prologue ++ body ++ epilogue
77− in unless (null supers) $ case mOutput of
78− Just output -> do
79− createDirectoryIfMissing True output
80− writeFile (output </> name) hier
81− Nothing -> putStrLn hier
82− exitSuccess
83−
84−superClasses :: P.Declaration -> [SuperMap]
85−superClasses (P.TypeClassDeclaration sub _ supers@(_:_) _) =
86− fmap (\(P.Qualified _ super, _) -> SuperMap (Right (super, sub))) supers
87−superClasses (P.TypeClassDeclaration sub _ _ _) = [SuperMap (Left sub)]
88−superClasses (P.PositionedDeclaration _ _ decl) = superClasses decl
89−superClasses _ = []
90−
91−inputFile :: Parser FilePath
92−inputFile = strArgument $
93− metavar "FILE"
94− <> value "main.purs"
95− <> showDefault
96− <> help "The input file to generate a hierarchy from"
97−
98−outputFile :: Parser (Maybe FilePath)
99−outputFile = optional . strOption $
100− short 'o'
101− <> long "output"
102− <> help "The output directory"
103−
104−pscOptions :: Parser HierarchyOptions
105−pscOptions = HierarchyOptions <$> inputFile
106− <*> outputFile
107−
108−main :: IO ()
109−main = execParser opts >>= compile
110− where
111− opts = info (helper <*> pscOptions) infoModList
112− infoModList = fullDesc <> headerInfo <> footerInfo
113− headerInfo = header "hierarchy - Creates a GraphViz directed graph of PureScript TypeClasses"
114− footerInfo = footer $ "hierarchy " ++ showVersion Paths.version
115−
license-generator/generate.hsdeleted−40
@@ -1,40 +0,0 @@
1−module Main (main) where
2−
3−import Control.Monad (forM_)
4−import Data.Char (isSpace)
5−import Data.List
6−import System.Process
7−import System.IO (hPutStrLn, stderr)
8−
9−echoHeader :: IO ()
10−echoHeader =
11− readFile "license-generator/header.txt" >>= putStr
12−
13−depsNames :: IO [String]
14−depsNames = do
15− i <- readProcess "cabal-dependency-licenses" [] ""
16− return $ sort $ map (drop 2) $ filter startsWithDash $ lines i
17− where
18− startsWithDash ('-' : _) = True
19− startsWithDash _ = False
20−
21−depsLicense :: String -> IO ()
22−depsLicense dep = do
23− let licenseFile = if dep == "Glob" then "LICENSE.txt" else "LICENSE"
24− hPutStrLn stderr dep
25− license <- readProcess "curl" ["--silent", "https://hackage.haskell.org/package/" ++ dep ++ "/src/" ++ licenseFile] ""
26− putStrLn $ dep ++ " LICENSE file:"
27− putStrLn ""
28− putStrLn $ f license
29− where
30− f = unlines . map (trimEnd . (" " ++)) . lines
31− trimEnd = reverse . dropWhile isSpace . reverse
32−
33−main :: IO ()
34−main = do
35− deps <-depsNames
36− echoHeader
37− putStrLn ""
38− forM_ deps $ \d -> putStr " " >> putStrLn d
39− putStrLn ""
40− forM_ deps depsLicense
license-generator/header.txtdeleted−23
@@ -1,23 +0,0 @@
1−The MIT License (MIT)
2−
3−Copyright (c) 2013-15 Phil Freeman, (c) 2014-2015 Gary Burgess, and other
4−contributors
5−
6−Permission is hereby granted, free of charge, to any person obtaining a copy of
7−this software and associated documentation files (the "Software"), to deal in
8−the Software without restriction, including without limitation the rights to
9−use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10−the Software, and to permit persons to whom the Software is furnished to do so,
11−subject to the following conditions:
12−
13−The above copyright notice and this permission notice shall be included in all
14−copies or substantial portions of the Software.
15−
16−THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17−IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18−FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19−COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20−IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21−CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22−
23−PureScript uses the following Haskell library packages. Their license files follow.
logo.pngdeleted

Binary file not shown.

make_release_notesdeleted−2
@@ -1,2 +0,0 @@
1−curl https://api.github.com/repos/purescript/purescript/pulls?state=closed\&per_page=100 \
2− | jq -r '.[] | ("- " + .title + " (@" + .user.login + ")")'
package.yamlnew file+86
@@ -0,0 +1,86 @@
1+name: psgo
2+version: 0.1.0.0
3+github: "andyarvanitis/purescript-native"
4+license: BSD3
5+author: "Andy Arvanitis"
6+maintainer: "example@example.com"
7+copyright: "2018 Andy Arvanitis"
8+
9+extra-source-files:
10+- README.md
11+- ChangeLog.md
12+- stack.yaml
13+- support/*
14+
15+# Metadata used when publishing your package
16+# synopsis: Short description of your package
17+# category: Web
18+
19+# To avoid duplicated efforts in documentation and dealing with the
20+# complications of embedding Haddock markup inside cabal files, it is
21+# common to point users to the README.md file.
22+description: Please see the README on Github at <https://github.com/andyarvanitis/purescript-native#readme>
23+
24+dependencies:
25+- base >= 4.7 && < 5
26+- bytestring >= 0.10.8.2 && < 0.11
27+- purescript
28+- base-compat >=0.6.0
29+- protolude >=0.1.6
30+- text
31+- containers
32+- filepath
33+- monad-parallel >= 0.7.2.2 && <0.8
34+- pattern-arrows >=0.0.2 && <0.1
35+- safe >=0.3.9 && <0.4
36+- transformers >=0.3.0 && <0.6
37+- mtl >=2.1.0 && <2.3.0
38+- aeson >=1.0 && <1.5
39+- directory
40+- process
41+- file-embed
42+- filemanip
43+- gitrev
44+
45+library:
46+ source-dirs: src
47+ default-extensions:
48+ - ConstraintKinds
49+ - DataKinds
50+ - DeriveFunctor
51+ - EmptyDataDecls
52+ - FlexibleContexts
53+ - KindSignatures
54+ - LambdaCase
55+ - MultiParamTypeClasses
56+ - NoImplicitPrelude
57+ - PatternGuards
58+ - PatternSynonyms
59+ - RankNTypes
60+ - RecordWildCards
61+ - OverloadedStrings
62+ - ScopedTypeVariables
63+ - TupleSections
64+ - ViewPatterns
65+
66+executables:
67+ psgo:
68+ main: Main.hs
69+ source-dirs: app
70+ ghc-options:
71+ - -threaded
72+ - -rtsopts
73+ - -with-rtsopts=-N
74+ dependencies:
75+ - psgo
76+
77+tests:
78+ psgo-test:
79+ main: Spec.hs
80+ source-dirs: test
81+ ghc-options:
82+ - -threaded
83+ - -rtsopts
84+ - -with-rtsopts=-N
85+ dependencies:
86+ - psgo
pcc/Main.hsdeleted−179
@@ -1,179 +0,0 @@
1−-----------------------------------------------------------------------------
2−--
3−-- Module : Main
4−-- Copyright : (c) 2013-15 Phil Freeman, Andy Arvanitis, and other contributors
5−-- License : MIT
6−--
7−-- Maintainer : Andy Arvanitis
8−-- Stability : experimental
9−-- Portability :
10−--
11−-- |
12−--
13−-----------------------------------------------------------------------------
14−
15−{-# LANGUAGE DataKinds #-}
16−{-# LANGUAGE FlexibleContexts #-}
17−{-# LANGUAGE RecordWildCards #-}
18−{-# LANGUAGE TupleSections #-}
19−
20−module Main where
21−
22−import Control.Applicative
23−import Control.Monad
24−import Control.Monad.Error.Class (MonadError(..))
25−import Control.Monad.Writer.Strict
26−
27−import Data.Version (showVersion)
28−import qualified Data.Map as M
29−
30−import Options.Applicative as Opts
31−
32−import System.Exit (exitSuccess, exitFailure)
33−import System.IO (hPutStrLn, stderr)
34−import System.IO.UTF8
35−
36−import qualified Language.PureScript as P
37−import qualified Paths_purescript as Paths
38−
39−import Make
40−import Makefile
41−
42−data PCCOptions = PCCOptions
43− { pccmInput :: [FilePath]
44− , pccmForeignInput :: [FilePath]
45− , pccmOutputDir :: FilePath
46− , pccmOpts :: P.Options
47− , pccmUsePrefix :: Bool
48− }
49−
50−data InputOptions = InputOptions
51− { ioInputFiles :: [FilePath]
52− }
53−
54−compile :: PCCOptions -> IO ()
55−compile (PCCOptions input _ outputDir opts usePrefix) = do
56− when (null input) generateMakefile
57− moduleFiles <- readInput (InputOptions input)
58− case runWriterT (parseInputs moduleFiles []) of
59− Left errs -> do
60− hPutStrLn stderr (P.prettyPrintMultipleErrors (P.optionsVerboseErrors opts) errs)
61− exitFailure
62− Right ((ms, _), warnings) -> do
63− when (P.nonEmpty warnings) $
64− hPutStrLn stderr (P.prettyPrintMultipleWarnings (P.optionsVerboseErrors opts) warnings)
65− let filePathMap = M.fromList $ map (\(fp, P.Module _ _ mn _ _) -> (mn, fp)) ms
66− makeActions = buildMakeActions outputDir filePathMap usePrefix
67− (e, warnings') <- runMake opts $ P.make makeActions (map snd ms)
68− case e of
69− Left errs -> do
70− putStrLn (P.prettyPrintMultipleErrors (P.optionsVerboseErrors opts) errs)
71− exitFailure
72− Right _ -> exitSuccess
73−
74−readInput :: InputOptions -> IO [(Either P.RebuildPolicy FilePath, String)]
75−readInput InputOptions{..} = forM ioInputFiles $ \inFile -> (Right inFile, ) <$> readUTF8File inFile
76−
77−parseInputs :: (Functor m, Applicative m, MonadError P.MultipleErrors m, MonadWriter P.MultipleErrors m)
78− => [(Either P.RebuildPolicy FilePath, String)]
79− -> [(FilePath, P.ForeignJS)]
80− -> m ([(Either P.RebuildPolicy FilePath, P.Module)], M.Map P.ModuleName FilePath)
81−parseInputs modules foreigns =
82− (,) <$> P.parseModulesFromFiles (either (const "") id) modules
83− <*> P.parseForeignModulesFromFiles foreigns
84−
85−inputFile :: Parser FilePath
86−inputFile = strArgument $
87− metavar "FILE"
88− <> help "The input .purs file(s)"
89−
90−inputForeignFile :: Parser FilePath
91−inputForeignFile = strOption $
92− short 'f'
93− <> long "ffi"
94− <> help "The input .js file(s) providing foreign import implementations"
95−
96−outputDirectory :: Parser FilePath
97−outputDirectory = strOption $
98− short 'o'
99− <> long "output"
100− <> Opts.value "output"
101− <> showDefault
102− <> help "The output directory"
103−
104−requirePath :: Parser (Maybe FilePath)
105−requirePath = optional $ strOption $
106− short 'r'
107− <> long "require-path"
108− <> help "The path prefix to use for require() calls in the generated code"
109−
110−noTco :: Parser Bool
111−noTco = switch $
112− long "no-tco"
113− <> help "Disable tail call optimizations"
114−
115−noPrelude :: Parser Bool
116−noPrelude = switch $
117− long "no-prelude"
118− <> help "Omit the automatic Prelude import"
119−
120−noMagicDo :: Parser Bool
121−noMagicDo = switch $
122− long "no-magic-do"
123− <> help "Disable the optimization that overloads the do keyword to generate efficient code specifically for the Eff monad."
124−
125−noOpts :: Parser Bool
126−noOpts = switch $
127− long "no-opts"
128− <> help "Skip the optimization phase."
129−
130−comments :: Parser Bool
131−comments = switch $
132− short 'c'
133− <> long "comments"
134− <> help "Include comments in the generated code."
135−
136−verboseErrors :: Parser Bool
137−verboseErrors = switch $
138− short 'v'
139− <> long "verbose-errors"
140− <> help "Display verbose error messages"
141−
142−noPrefix :: Parser Bool
143−noPrefix = switch $
144− short 'p'
145− <> long "no-prefix"
146− <> help "Do not include comment header"
147−
148−sourceMaps :: Parser Bool
149−sourceMaps = switch $
150− long "source-maps"
151− <> help "Generate source maps"
152−
153−options :: Parser P.Options
154−options = P.Options <$> noTco
155− <*> noMagicDo
156− <*> pure Nothing
157− <*> noOpts
158− <*> verboseErrors
159− <*> (not <$> comments)
160− <*> requirePath
161− <*> sourceMaps
162−
163−pccOptions :: Parser PCCOptions
164−pccOptions = PCCOptions <$> many inputFile
165− <*> many inputForeignFile
166− <*> outputDirectory
167− <*> options
168− <*> (not <$> noPrefix)
169−
170−main :: IO ()
171−main = execParser opts >>= compile
172− where
173− opts = info (version <*> helper <*> pccOptions) infoModList
174− infoModList = fullDesc <> headerInfo <> footerInfo
175− headerInfo = header "pcc - Compiles PureScript to C++11"
176− footerInfo = footer $ "pcc " ++ showVersion Paths.version
177−
178− version :: Parser (a -> a)
179− version = abortOption (InfoMsg (showVersion Paths.version)) $ long "version" <> help "Show the version number" <> hidden
pcc/Make.hsdeleted−174
@@ -1,174 +0,0 @@
1−-----------------------------------------------------------------------------
2−--
3−-- Module : Make
4−-- Copyright : (c) 2013-14 Phil Freeman, (c) 2014 Gary Burgess, and other contributors
5−-- License : MIT
6−--
7−-- Maintainer : Andy Arvanitis
8−-- Stability : experimental
9−-- Portability :
10−--
11−-- |
12−--
13−-----------------------------------------------------------------------------
14−
15−{-# LANGUAGE DataKinds #-}
16−{-# LANGUAGE FlexibleContexts #-}
17−{-# LANGUAGE GeneralizedNewtypeDeriving #-}
18−{-# LANGUAGE TupleSections #-}
19−{-# LANGUAGE TemplateHaskell #-}
20−
21−module Make
22− ( Make(..)
23− , runMake
24− , buildMakeActions
25− ) where
26−
27−import Control.Monad
28−import Control.Monad.Error.Class (MonadError(..))
29−import Control.Monad.Reader
30−
31−import Data.FileEmbed (embedFile)
32−import Data.List (intercalate)
33−import Data.Maybe (fromMaybe)
34−import Data.String (fromString)
35−import Data.Time.Clock
36−import Data.Version (showVersion)
37−import qualified Data.Map as M
38−import qualified Data.ByteString.Char8 as B
39−
40−import System.Directory (doesDirectoryExist, doesFileExist, getModificationTime, createDirectoryIfMissing)
41−import System.FilePath ((</>), takeDirectory, addExtension, dropExtension)
42−import System.IO.Error (tryIOError)
43−import System.IO.UTF8
44−
45−import Language.PureScript.Errors
46−import Language.PureScript (Make, runMake)
47−
48−import qualified Language.PureScript as P
49−import qualified Language.PureScript.CodeGen.Cpp as CPP
50−import qualified Language.PureScript.CoreFn as CF
51−import qualified Paths_purescript as Paths
52−
53−makeIO :: (IOError -> P.ErrorMessage) -> IO a -> Make a
54−makeIO f io = do
55− e <- liftIO $ tryIOError io
56− either (throwError . P.singleError . f) return e
57−
58−-- Traverse (Either e) instance (base 4.7)
59−traverseEither :: Applicative f => (a -> f b) -> Either e a -> f (Either e b)
60−traverseEither _ (Left x) = pure (Left x)
61−traverseEither f (Right y) = Right <$> f y
62−
63−buildMakeActions :: FilePath
64− -> M.Map P.ModuleName (Either P.RebuildPolicy FilePath)
65− -> Bool
66− -> P.MakeActions Make
67−buildMakeActions outputDir filePathMap usePrefix =
68− P.MakeActions getInputTimestamp getOutputTimestamp readExterns codegen progress
69− where
70−
71− getInputFile :: P.ModuleName -> FilePath
72− getInputFile mn =
73− let path = fromMaybe (error "Module has no filename in 'make'") $ M.lookup mn filePathMap in
74− case path of
75− Right path' -> path'
76− Left _ -> error "Module has no filename in 'make'"
77−
78− getInputTimestamp :: P.ModuleName -> Make (Either P.RebuildPolicy (Maybe UTCTime))
79− getInputTimestamp mn = do
80− let path = fromMaybe (error "Module has no filename in 'make'") $ M.lookup mn filePathMap
81− traverseEither getTimestamp path
82−
83− getOutputTimestamp :: P.ModuleName -> Make (Maybe UTCTime)
84− getOutputTimestamp mn = do
85−
86− let filePath = dotsTo '/' $ P.runModuleName mn
87− fileBase = outputDir </> filePath </> (last . words . dotsTo ' ' $ P.runModuleName mn)
88− srcFile = addExtension fileBase "cc"
89−-- headerFile = addExtension fileBase "hh"
90− externsFile = outputDir </> filePath </> "externs.purs"
91− min <$> getTimestamp srcFile <*> getTimestamp externsFile
92−
93− readExterns :: P.ModuleName -> Make (FilePath, P.Externs)
94− readExterns mn = do
95− let path = outputDir </> (dotsTo '/' $ P.runModuleName mn) </> "externs.purs"
96− (path, ) <$> readTextFile path
97−
98− codegen :: CF.Module CF.Ann -> P.Environment -> P.Externs -> P.SupplyT Make ()
99− codegen m env exts = do
100− let mn = CF.moduleName m
101− let filePath = dotsTo '/' $ P.runModuleName mn
102− fileBase = outputDir </> filePath </> (last . words . dotsTo ' ' $ P.runModuleName mn)
103− srcFile = addExtension fileBase "cc"
104− headerFile = addExtension fileBase "hh"
105− externsFile = outputDir </> filePath </> "externs.purs"
106− prefix = ["Generated by pcc version " ++ showVersion Paths.version | usePrefix]
107− cpps <- CPP.moduleToCpp env m
108− let (hdrs,srcs) = span (/= CPP.CppEndOfHeader) cpps
109− psrcs <- CPP.prettyPrintCpp <$> pure srcs
110− phdrs <- CPP.prettyPrintCpp <$> pure hdrs
111− let src = unlines $ map ("// " ++) prefix ++ [psrcs]
112− hdr = unlines $ map ("// " ++) prefix ++ [phdrs]
113−
114− lift $ do
115− writeTextFile srcFile src
116− writeTextFile headerFile hdr
117− writeTextFile externsFile exts
118−
119− let supportDir = outputDir </> "PureScript"
120− supportFilesExist <- dirExists supportDir
121− when (not supportFilesExist) $ do
122− writeTextFile (supportDir </> "PureScript.hh") $ B.unpack $(embedFile "pcc/include/purescript.hh")
123− writeTextFile (supportDir </> "PureScript.cc") $ B.unpack $(embedFile "pcc/include/purescript.cc")
124−
125− let inputPath = dropExtension $ getInputFile mn
126− hfile = addExtension inputPath "hh"
127− sfile = addExtension inputPath "cc"
128− hfileExists <- textFileExists hfile
129− when (hfileExists || requiresForeign m) $ do
130− text <- if hfileExists
131− then readTextFile hfile
132− else pure []
133− writeTextFile (addExtension (fileBase ++ "_ffi") "hh") text
134− sfileExists <- textFileExists sfile
135− when (sfileExists) $ do
136− text' <- readTextFile sfile
137− writeTextFile (addExtension (fileBase ++ "_ffi") "cc") text'
138−
139− requiresForeign :: CF.Module a -> Bool
140− requiresForeign = not . null . CF.moduleForeign
141−
142− dirExists :: FilePath -> Make Bool
143− dirExists path = makeIO (const (ErrorMessage [] $ CannotReadFile path)) $ do
144− doesDirectoryExist path
145−
146− textFileExists :: FilePath -> Make Bool
147− textFileExists path = makeIO (const (ErrorMessage [] $ CannotReadFile path)) $ do
148− doesFileExist path
149−
150− getTimestamp :: FilePath -> Make (Maybe UTCTime)
151− getTimestamp path = makeIO (const (ErrorMessage [] $ CannotGetFileInfo path)) $ do
152− exists <- doesFileExist path
153− traverse (const $ getModificationTime path) $ guard exists
154−
155− readTextFile :: FilePath -> Make String
156− readTextFile path = makeIO (const (ErrorMessage [] $ CannotReadFile path)) $ readUTF8File path
157−
158− writeTextFile :: FilePath -> String -> Make ()
159− writeTextFile path text = makeIO (const (ErrorMessage [] $ CannotWriteFile path)) $ do
160− mkdirp path
161− writeFile path text
162− where
163− mkdirp :: FilePath -> IO ()
164− mkdirp = createDirectoryIfMissing True . takeDirectory
165−
166− -- | Render a progress message
167− renderProgressMessage :: P.ProgressMessage -> String
168− renderProgressMessage (P.CompilingModule mn) = "Compiling " ++ P.runModuleName mn
169−
170− progress :: P.ProgressMessage -> Make ()
171− progress = liftIO . putStrLn . renderProgressMessage
172−
173−dotsTo :: Char -> String -> String
174−dotsTo chr = map (\c -> if c == '.' then chr else c)
pcc/Makefiledeleted−63
@@ -1,63 +0,0 @@
1−# PureScript to native binary (via C++) Makefile
2−#
3−# Run 'make' or 'make release' to build an optimized release build
4−# Run 'make debug' to build a non-optimized build suitable for debugging
5−#
6−# You can also perform a parallel build with 'make -jN', where N is the
7−# number of cores to use.
8−#
9−# PCC, PURESCRIPT_PKGS, OUTPUT, and BIN can all be overridden with the
10−# command itself. For example: 'make PURESCRIPT_PKGS=../gitpackages BIN=myexe'
11−#
12−# Flags can be added to either the codegen or native build phases.
13−# For example: 'make PCCFLAGS=--no-tco CXXFLAGS=-DDEBUG LDFLAGS=lobjc'
14−#
15−# You can also edit the generated version of this file directly.
16−#
17−PCC := {bin/pcc} # example: /usr/local/bin/pcc
18−PURESCRIPT_PKGS := packages # example: bower_components
19−PURESCRIPT_SRC := src
20−OUTPUT := output
21−BIN := main
22−
23−override PCCFLAGS += --comments
24−override CXXFLAGS += -std=c++11
25−override LDFLAGS +=
26−
27−DEBUG := "-DDEBUG -g"
28−RELEASE := "-O3 -flto"
29−
30−PURESCRIPT_PKG_SRCS := $(shell find $(PURESCRIPT_PKGS) -name '*.purs' | grep -v \/test\/ | grep -v \/example\/ | grep -v \/examples\/)
31−PURESCRIPT_SRCS := $(shell find $(PURESCRIPT_SRC) -name '*.purs')
32−
33−INCLUDES := -I $(OUTPUT)
34−BIN_DIR := $(OUTPUT)/bin
35−
36−release: codegen
37− @$(MAKE) $(BIN) CXXFLAGS=$(RELEASE)
38−
39−debug: codegen
40− @$(MAKE) $(BIN) CXXFLAGS=$(DEBUG)
41−
42−codegen:
43− @$(PCC) $(PCCFLAGS) --output $(OUTPUT) $(PURESCRIPT_PKG_SRCS) $(PURESCRIPT_SRCS)
44−
45−SRCS := $(shell find $(OUTPUT) 2>/dev/null -name '*.cc')
46−
47−OBJS = $(SRCS:.cc=.o)
48−DEPS = $(SRCS:.cc=.d)
49−
50−$(BIN): $(OBJS)
51− @echo "Linking" $(BIN_DIR)/$(BIN)
52− @mkdir -p $(BIN_DIR)
53− @$(CXX) $(LDFLAGS) $^ -o $(BIN_DIR)/$@
54−
55−-include $(DEPS)
56−
57−%.o: %.cc
58− @echo "Creating" $@
59− @$(CXX) $(CXXFLAGS) $(INCLUDES) -MMD -MP -c $< -o $@
60−
61−.PHONY: clean
62−clean:
63− @-rm -rf $(OUTPUT)
pcc/Makefile.hsdeleted−50
@@ -1,50 +0,0 @@
1−-------------------------------------------------------------------------------
2−--
3−-- Module : Main
4−-- Copyright : (c) 2016 Andy Arvanitis and other contributors
5−-- License : MIT
6−--
7−-- Maintainer : Andy Arvanitis
8−-- Stability : experimental
9−-- Portability :
10−--
11−-------------------------------------------------------------------------------
12−{-# LANGUAGE OverloadedStrings #-}
13−{-# LANGUAGE TemplateHaskell #-}
14−
15−module Makefile where
16−
17−import Control.Monad (when)
18−import Data.FileEmbed (embedFile)
19−import Data.List
20−import System.Environment (getExecutablePath)
21−import System.Directory (doesFileExist)
22−
23−import qualified Data.ByteString.Char8 as B
24−
25−generateMakefile :: IO ()
26−generateMakefile = do
27− makefileExists <- doesFileExist "Makefile"
28− when (not makefileExists) $ do
29− let makefile = $(embedFile "pcc/Makefile")
30− exePath <- getExecutablePath
31− putStrLn ""
32− putStrLn "Generating Makefile..."
33− putStrLn $ "pcc executable location: " ++ exePath
34− writeFile "Makefile" $ replace makefile pccPath exePath
35− putStrLn "Done"
36− putStrLn "Run 'make' or 'make release' to build an optimized release build."
37− putStrLn "The resulting binary executable will be located in output/bin (by default)."
38− putStrLn ""
39−
40−replace :: B.ByteString -> B.ByteString -> String -> String
41−replace s orig repl = replace'
42− where
43− replace'
44− | (p1, p2) <- B.breakSubstring orig s,
45− not (B.null p2) = B.unpack p1 ++ repl ++ trim (B.unpack p2)
46− | otherwise = B.unpack s
47− trim = drop (B.length orig)
48−
49−pccPath :: B.ByteString
50−pccPath = "{bin/pcc}"
pcc/TestMain.hsdeleted−120
@@ -1,120 +0,0 @@
1−-------------------------------------------------------------------------------
2−--
3−-- Module : Main
4−-- Copyright : (c) 2015 Andy Arvanitis and other contributors
5−-- License : MIT
6−--
7−-- Maintainer : Andy Arvanitis
8−-- Stability : experimental
9−-- Portability :
10−--
11−--
12−--
13−-------------------------------------------------------------------------------
14−module Main where
15−
16−import Data.List
17−import Control.Applicative
18−import Control.Monad
19−
20−import System.Process
21−import System.FilePath
22−import System.Directory
23−
24−-------------------------------------------------------------------------------
25−testsDir :: IO (FilePath, FilePath)
26−-------------------------------------------------------------------------------
27−testsDir = do
28− baseDir <- getCurrentDirectory
29− return (baseDir </> "pcc-tests", baseDir)
30−
31−-------------------------------------------------------------------------------
32−main :: IO ()
33−-------------------------------------------------------------------------------
34−main = do
35−
36− (outputDir, baseDir) <- testsDir
37−
38− outputDirExists <- doesDirectoryExist outputDir
39− when outputDirExists $ removeDirectoryRecursive outputDir
40− createDirectory outputDir
41−
42− fetchPackages
43−
44− let srcDir = outputDir </> "src"
45− createDirectory srcDir
46−
47− let passingDir = baseDir </> "examples" </> "passing"
48− passingTestCases <- sort . filter (".purs" `isSuffixOf`) <$> getDirectoryContents passingDir
49−
50− -- Auto-generate Makefile
51− setCurrentDirectory outputDir
52− callProcess "../.cabal-sandbox/bin/pcc" []
53−
54− let tests = filter (`notElem` skipped) passingTestCases
55−
56− -- Run the tests
57− --
58− forM_ tests $ \inputFile -> do
59− --
60− -- Compile/build
61− --
62− putStrLn $ "Compiling test " ++ inputFile ++ " ..."
63− setCurrentDirectory outputDir
64− copyFile (passingDir </> inputFile) (srcDir </> inputFile)
65− callProcess "make" ["clean"]
66− callProcess "make" ["debug"]
67− --
68− -- Run C++ files
69− --
70− callProcess ("output" </> "bin" </> "main") []
71−
72− removeFile (srcDir </> inputFile)
73−
74− -- TODO: support failing test cases
75− --
76− -- let failing = baseDir </> "examples" </> "failing"
77− -- failingTestCases <- sort . filter (".purs" `isSuffixOf`) <$> getDirectoryContents failing
78− --
79−
80− setCurrentDirectory baseDir
81− putStrLn "pcc-tests finished"
82− putStrLn $ "Total tests available: " ++ show (length passingTestCases)
83− putStrLn $ "Tests run: " ++ show (length tests)
84− putStrLn $ "Tests skipped: " ++ show (length skipped)
85−
86−-------------------------------------------------------------------------------
87−repo :: String
88−-------------------------------------------------------------------------------
89−repo = "git://github.com/pure11/"
90−
91−-------------------------------------------------------------------------------
92−packages :: [(String, String)]
93−-------------------------------------------------------------------------------
94−packages =
95− [ ("purescript-eff", "")
96− , ("purescript-prelude", "")
97− , ("purescript-assert", "")
98− , ("purescript-st", "")
99− , ("purescript-console", "")
100− , ("purescript-functions", "")
101− ]
102−
103−-------------------------------------------------------------------------------
104−fetchPackages :: IO ()
105−-------------------------------------------------------------------------------
106−fetchPackages = do
107− (outputDir, baseDir) <- testsDir
108− let packageDir = outputDir </> "packages"
109− createDirectory packageDir
110− setCurrentDirectory packageDir
111− forM_ packages $ \package -> let branch = snd package in
112− callProcess "git" $ ["clone"] ++ (if null branch then [] else ["--branch", branch]) ++ [repo ++ (fst package) ++ ".git"]
113− setCurrentDirectory baseDir
114−
115−-------------------------------------------------------------------------------
116−skipped :: [String]
117−-------------------------------------------------------------------------------
118−skipped =
119− [ "ExplicitImportReExport.purs" -- OK, test has no main (would pass otherwise)
120− ]
pcc/include/purescript.ccdeleted−382
@@ -1,382 +0,0 @@
1−///////////////////////////////////////////////////////////////////////////////
2−//
3−// Module : purescript.cc
4−// Copyright : (c) Andy Arvanitis 2015
5−// License : MIT
6−//
7−// Maintainer : Andy Arvanitis <andy.arvanitis@gmail.com>
8−// Stability : experimental
9−// Portability :
10−//
11−// Basic types and functions to support purescript-to-C++1x rendering
12−//
13−///////////////////////////////////////////////////////////////////////////////
14−//
15−#include <cstring>
16−#include "PureScript.hh"
17−
18−namespace PureScript {
19−
20−#define RETURN_VALUE(TYPE, ACCESSOR, INDIRECTION) \
21− const any& variant = unthunkVariant(*this); \
22− assert(variant.type == TYPE); \
23− return INDIRECTION(variant.ACCESSOR); \
24−
25−template <typename T>
26−auto any::cast() const -> typename std::enable_if<std::is_same<T, long>::value, T>::type {
27− RETURN_VALUE(Type::Integer, i,)
28−}
29−template auto any::cast<long>() const -> long;
30−
31−template <typename T>
32−auto any::cast() const -> typename std::enable_if<std::is_same<T, double>::value, T>::type {
33− RETURN_VALUE(Type::Double, d,)
34−}
35−template auto any::cast<double>() const -> double;
36−
37−template <typename T>
38−auto any::cast() const -> typename std::enable_if<std::is_same<T, char>::value, T>::type {
39− RETURN_VALUE(Type::Character, c,)
40−}
41−template auto any::cast<char>() const -> char;
42−
43−template <typename T>
44−auto any::cast() const -> typename std::enable_if<std::is_same<T, bool>::value, T>::type {
45− RETURN_VALUE(Type::Boolean, b,)
46−}
47−template auto any::cast<bool>() const -> bool;
48−
49−template <typename T>
50−auto any::cast() const -> typename std::enable_if<std::is_same<T, string>::value, T>::type {
51− const any& variant = unthunkVariant(*this);
52− if (variant.type == Type::StringLiteral) {
53− return variant.r;
54− }
55− assert(variant.type == Type::String);
56− return variant.s->c_str();
57−}
58−template auto any::cast<string>() const -> string;
59−
60−template <typename T>
61−auto any::cast() const -> typename std::enable_if<std::is_same<T, map>::value, const T&>::type {
62− RETURN_VALUE(Type::Map, m, *)
63−}
64−template auto any::cast<any::map>() const -> const map&;
65−
66−template <typename T>
67−auto any::cast() const -> typename std::enable_if<std::is_same<T, data>::value, const T&>::type {
68− RETURN_VALUE(Type::Data, v, *)
69−}
70−template auto any::cast<any::data>() const -> const data&;
71−
72−template <typename T>
73−auto any::cast() const -> typename std::enable_if<std::is_same<T, array>::value, const T&>::type {
74− RETURN_VALUE(Type::Array, a, *)
75−}
76−template auto any::cast<any::array>() const -> const array&;
77−
78−auto any::operator()(const any& arg) const -> any {
79− const any& variant = unthunkVariant(*this);
80− if (variant.type == Type::Closure) {
81− return (*variant.l)(arg);
82− }
83− assert(variant.type == Type::Function);
84− return (*variant.f)(arg);
85−}
86−
87−auto any::operator()(const as_thunk) const -> const any& {
88− assert(type == Type::Thunk);
89− return (*t)(unthunk);
90−}
91−
92−auto any::operator()() const -> any {
93− const any& variant = unthunkVariant(*this);
94− assert(variant.type == Type::EffFunction);
95− return (*variant.e)();
96−}
97−
98−any::operator long() const {
99− return cast<long>();
100−}
101−
102−any::operator double() const {
103− return cast<double>();
104−}
105−
106−any::operator bool() const {
107− return cast<bool>();
108−}
109−
110−any::operator string() const {
111− return cast<string>();
112−}
113−
114−any::operator const map&() const {
115− return cast<map>();
116−}
117−
118−any::operator const data&() const {
119− return cast<data>();
120−}
121−
122−any::operator const array&() const {
123− return cast<array>();
124−}
125−
126−auto any::extractPointer() const -> void* {
127− RETURN_VALUE(Type::Pointer, p.get(),)
128−}
129−
130−auto any::unthunkVariant(const any& a) -> const any& {
131− const any * variant = &a;
132− while (variant->type == Type::Thunk) {
133− variant = &((*variant->t)(unthunk));
134− }
135− return *variant;
136−}
137−
138−auto any::operator[](const char rhs[]) const -> const any& {
139− const any& variant = unthunkVariant(*this);
140− assert(variant.type == Type::Map);
141− const auto begin = variant.m->cbegin();
142− const auto end = variant.m->cend();
143− for (auto it = begin; it != end; ++it) {
144− if (it->first == rhs) {
145− return it->second;
146− }
147− }
148− for (auto it = begin; it != end; ++it) {
149− if (strcmp(it->first, rhs) == 0) {
150− return it->second;
151− }
152− }
153− throw runtime_error("map key not found");
154−}
155−
156−auto any::operator[](const size_t rhs) const -> const any& {
157− const any& variant = unthunkVariant(*this);
158− assert(variant.type == Type::Array);
159− return (*variant.a)[rhs];
160−}
161−
162−auto any::operator[](const any& rhs) const -> const any& {
163− const any& variant = unthunkVariant(*this);
164− assert(variant.type == Type::Array);
165− return (*variant.a)[rhs.cast<long>()];
166−}
167−
168−auto any::contains(const char key[]) const -> bool {
169− const any& variant = unthunkVariant(*this);
170− assert(variant.type == Type::Map);
171− const auto begin = variant.m->cbegin();
172− const auto end = variant.m->cend();
173− for (auto it = begin; it != end; ++it) {
174− if (it->first == key) {
175− return true;
176− }
177− }
178− for (auto it = begin; it != end; ++it) {
179− if (strcmp(it->first, key) == 0) {
180− return true;
181− }
182− }
183− return false;
184−}
185−
186−//-----------------------------------------------------------------------------
187−// Operator helper macros
188−//-----------------------------------------------------------------------------
189−
190−#define DEFINE_OPERATOR(op, ty, rty) \
191−auto operator op (const any& lhs, ty rhs) -> rty { \
192− return lhs.cast<typename std::remove_const<std::remove_reference<ty>::type>::type>() op rhs; \
193−} \
194−auto operator op (ty lhs, const any& rhs) -> rty { \
195− return lhs op rhs.cast<typename std::remove_const<std::remove_reference<ty>::type>::type>(); \
196−}
197−
198−#define DEFINE_CSTR_EQUALS_OPERATOR() \
199− auto operator==(const any& lhs_, const char * rhs) -> bool { \
200− const any& lhs = any::unthunkVariant(lhs_); \
201− assert(lhs.type == any::Type::StringLiteral || lhs.type == any::Type::String); \
202− if (lhs.type == any::Type::StringLiteral) { \
203− return (lhs.r == rhs) || (strcmp(lhs.r, rhs) == 0); \
204− } \
205− return strcmp(lhs.s->c_str(), rhs) == 0; \
206− } \
207− auto operator==(const char * lhs, const any& rhs_) -> bool { \
208− const any& rhs = any::unthunkVariant(rhs_); \
209− assert(rhs.type == any::Type::StringLiteral || rhs.type == any::Type::String); \
210− if (rhs.type == any::Type::StringLiteral) { \
211− return (lhs == rhs.r) || (strcmp(lhs, rhs) == 0); \
212− } \
213− return strcmp(lhs, rhs.s->c_str()) == 0; \
214− }
215−
216−#define DEFINE_CSTR_COMPARISON_OPERATOR(op) \
217− auto operator op (const any& lhs, const char * rhs) -> bool { \
218− return strcmp(lhs.cast<string>(), rhs) op 0; \
219− } \
220− auto operator op (const char * lhs, const any& rhs) -> bool { \
221− return strcmp(lhs, rhs.cast<string>()) op 0; \
222− }
223−
224−#define DEFINE_COMPARISON_OPERATOR(op) \
225− auto operator op (const any& lhs_, const any& rhs_) -> bool { \
226− const any& lhs = any::unthunkVariant(lhs_); \
227− const any& rhs = any::unthunkVariant(rhs_); \
228− switch (lhs.type) { \
229− case any::Type::Integer: assert(lhs.type == any::Type::Integer); return lhs.i op rhs.i; \
230− case any::Type::Double: assert(lhs.type == any::Type::Double); return lhs.d op rhs.d; \
231− case any::Type::Character: assert(lhs.type == any::Type::Character); return lhs.c op rhs.c; \
232− case any::Type::Boolean: assert(lhs.type == any::Type::Boolean); return lhs.b op rhs.b; \
233− case any::Type::StringLiteral: \
234− assert(lhs.type == any::Type::StringLiteral || lhs.type == any::Type::String); \
235− assert(rhs.type == any::Type::StringLiteral || rhs.type == any::Type::String); \
236− return strcmp(lhs.r, rhs.type == any::Type::StringLiteral ? rhs.r : rhs.s->c_str()) op 0; \
237− case any::Type::String: \
238− assert(lhs.type == any::Type::StringLiteral || lhs.type == any::Type::String); \
239− assert(rhs.type == any::Type::StringLiteral || rhs.type == any::Type::String); \
240− return strcmp(lhs.s->c_str(), rhs.type == any::Type::StringLiteral ? rhs.r : rhs.s->c_str()) op 0; \
241− case any::Type::Pointer: return lhs.p op rhs.p; \
242− default: assert(false && "Unsupported type for operator " #op); \
243− } \
244− return false; \
245− } \
246− DEFINE_OPERATOR(op, long, bool) \
247− DEFINE_OPERATOR(op, double, bool) \
248− DEFINE_OPERATOR(op, char, bool) \
249− DEFINE_OPERATOR(op, bool, bool) \
250−
251−//-----------------------------------------------------------------------------
252−// Operator definitions
253−//-----------------------------------------------------------------------------
254−
255−DEFINE_COMPARISON_OPERATOR(==)
256−DEFINE_COMPARISON_OPERATOR(!=)
257−DEFINE_COMPARISON_OPERATOR(<)
258−DEFINE_COMPARISON_OPERATOR(<=)
259−DEFINE_COMPARISON_OPERATOR(>)
260−DEFINE_COMPARISON_OPERATOR(>=)
261−
262−DEFINE_CSTR_EQUALS_OPERATOR()
263−DEFINE_CSTR_COMPARISON_OPERATOR(!=)
264−DEFINE_CSTR_COMPARISON_OPERATOR(<)
265−DEFINE_CSTR_COMPARISON_OPERATOR(<=)
266−DEFINE_CSTR_COMPARISON_OPERATOR(>)
267−DEFINE_CSTR_COMPARISON_OPERATOR(>=)
268−
269−auto operator+(const any& lhs_, const any& rhs_) -> any {
270− const any& lhs = any::unthunkVariant(lhs_);
271− const any& rhs = any::unthunkVariant(rhs_);
272− switch (lhs.type) {
273− case any::Type::Integer: assert(lhs.type == any::Type::Integer); return lhs.i + rhs.i;
274− case any::Type::Double: assert(lhs.type == any::Type::Double); return lhs.d + rhs.d;
275− case any::Type::Character: assert(lhs.type == any::Type::Character); return any(char(lhs.c + rhs.c));
276− case any::Type::StringLiteral:
277− assert(lhs.type == any::Type::StringLiteral || lhs.type == any::Type::String);
278− assert(rhs.type == any::Type::StringLiteral || rhs.type == any::Type::String);
279− return rhs.type == any::Type::StringLiteral ? std::string(lhs.r) + rhs.r : lhs.r + *rhs.s;
280− case any::Type::String:
281− assert(lhs.type == any::Type::StringLiteral || lhs.type == any::Type::String);
282− assert(rhs.type == any::Type::StringLiteral || rhs.type == any::Type::String);
283− return rhs.type == any::Type::StringLiteral ? *lhs.s + rhs.r : *lhs.s + *rhs.s;
284− default: assert(false && "Unsupported type for '+' operator");
285− }
286− return nullptr;
287−}
288−
289−DEFINE_OPERATOR(+, long, long)
290−DEFINE_OPERATOR(+, double, double)
291−DEFINE_OPERATOR(+, char, char)
292−
293−auto operator+(const any& lhs_, const char * rhs) -> std::string {
294− const any& lhs = any::unthunkVariant(lhs_);
295− assert(lhs.type == any::Type::StringLiteral || lhs.type == any::Type::String);
296− return lhs.type == any::Type::StringLiteral ? std::string(lhs.r) + rhs : *lhs.s + rhs;
297−}
298−
299−auto operator+(const char * lhs, const any& rhs_) -> std::string {
300− const any& rhs = any::unthunkVariant(rhs_);
301− assert(rhs.type == any::Type::StringLiteral || rhs.type == any::Type::String);
302− return rhs.type == any::Type::StringLiteral ? lhs + std::string(rhs.r) : lhs + *rhs.s;
303−}
304−
305−auto operator-(const any& lhs_, const any& rhs_) -> any {
306− const any& lhs = any::unthunkVariant(lhs_);
307− const any& rhs = any::unthunkVariant(rhs_);
308− assert(lhs.type == rhs.type);
309− switch (lhs.type) {
310− case any::Type::Integer: return lhs.i - rhs.i;
311− case any::Type::Double: return lhs.d - rhs.d;
312− case any::Type::Character: return any(char(lhs.c - rhs.c));
313− default: assert(false && "Unsupported type for '-' operator");
314− }
315− return nullptr;
316−}
317−
318−DEFINE_OPERATOR(-, long, long)
319−DEFINE_OPERATOR(-, double, double)
320−DEFINE_OPERATOR(-, char, char)
321−
322−auto operator*(const any& lhs_, const any& rhs_) -> any {
323− const any& lhs = any::unthunkVariant(lhs_);
324− const any& rhs = any::unthunkVariant(rhs_);
325− assert(lhs.type == rhs.type);
326− switch (lhs.type) {
327− case any::Type::Integer: return lhs.i * rhs.i;
328− case any::Type::Double: return lhs.d * rhs.d;
329− case any::Type::Character: return any(char(lhs.c * rhs.c));
330− default: assert(false && "Unsupported type for '*' operator");
331− }
332− return nullptr;
333−}
334−
335−DEFINE_OPERATOR(*, long, long)
336−DEFINE_OPERATOR(*, double, double)
337−DEFINE_OPERATOR(*, char, char)
338−
339−auto operator/(const any& lhs_, const any& rhs_) -> any {
340− const any& lhs = any::unthunkVariant(lhs_);
341− const any& rhs = any::unthunkVariant(rhs_);
342− assert(lhs.type == rhs.type);
343− switch (lhs.type) {
344− case any::Type::Integer: return lhs.i / rhs.i;
345− case any::Type::Double: return lhs.d / rhs.d;
346− case any::Type::Character: return any(char(lhs.c / rhs.c));
347− default: assert(false && "Unsupported type for '/' operator");
348− }
349− return nullptr;
350−}
351−
352−DEFINE_OPERATOR(/, long, long)
353−DEFINE_OPERATOR(/, double, double)
354−DEFINE_OPERATOR(/, char, char)
355−
356−auto operator%(const any& lhs_, const any& rhs_) -> any {
357− const any& lhs = any::unthunkVariant(lhs_);
358− const any& rhs = any::unthunkVariant(rhs_);
359− assert(lhs.type == rhs.type);
360− switch (lhs.type) {
361− case any::Type::Integer: return lhs.i % rhs.i;
362− case any::Type::Character: return any(char(lhs.c % rhs.c));
363− default: assert(false && "Unsupported type for '%' operator");
364− }
365− return nullptr;
366−}
367−
368−DEFINE_OPERATOR(%, long, long)
369−DEFINE_OPERATOR(%, char, char)
370−
371−// unary negate
372−auto operator-(const any& rhs_) -> any {
373− const any& rhs = any::unthunkVariant(rhs_);
374− switch (rhs.type) {
375− case any::Type::Integer: return (- rhs.i);
376− case any::Type::Double: return (- rhs.d);
377− default: assert(false && "Unsupported type for unary '-' operator");
378− }
379− return nullptr;
380−}
381−
382−} // namespace PureScript
pcc/include/purescript.hhdeleted−382
@@ -1,382 +0,0 @@
1−///////////////////////////////////////////////////////////////////////////////
2−//
3−// Module : purescript.hh
4−// Copyright : (c) Andy Arvanitis 2015
5−// License : MIT
6−//
7−// Maintainer : Andy Arvanitis <andy.arvanitis@gmail.com>
8−// Stability : experimental
9−// Portability :
10−//
11−// Basic types and functions to support purescript-to-C++1x rendering
12−//
13−///////////////////////////////////////////////////////////////////////////////
14−//
15−#ifndef PureScript_HH
16−#define PureScript_HH
17−
18−// Standard includes
19−
20−#if defined(DEBUG)
21− #include <cassert>
22−#else
23− #define NDEBUG
24− #undef assert
25− #define assert(x)
26−#endif
27−
28−#include <memory>
29−#include <functional>
30−#include <string>
31−#include <vector>
32−#include <deque>
33−#include <utility>
34−#include <stdexcept>
35−#include <iso646.h> // mostly for MS Visual Studio compiler
36−
37−#define DECLARE_OPERATOR(op, ty, rty) \
38− friend auto operator op (const any&, ty) -> rty; \
39− friend auto operator op (ty, const any&) -> rty;
40−
41−#define DECLARE_COMPARISON_OPERATOR(op) \
42− friend auto operator op (const any&, const any&) -> bool; \
43− DECLARE_OPERATOR(op, long, bool) \
44− DECLARE_OPERATOR(op, double, bool) \
45− DECLARE_OPERATOR(op, char, bool) \
46− DECLARE_OPERATOR(op, const char *, bool)
47−
48−
49−namespace PureScript {
50−
51−using string = const char *;
52−using nullptr_t = std::nullptr_t;
53−
54−// Workaround for missing C++11 version in gcc
55−class runtime_error : public std::runtime_error {
56−public:
57− runtime_error(const char message[]) : std::runtime_error(std::string(message)) {}
58−};
59−
60−const bool undefined = false;
61−const size_t constructor = 0;
62−
63−// A variant data class designed to provide some features of dynamic typing.
64−//
65−class any {
66−
67− public:
68− enum class Type : int8_t {
69− Unknown,
70− Integer,
71− Double,
72− Character,
73− Boolean,
74− StringLiteral,
75− String,
76− Map,
77− Data,
78− Array,
79− Function,
80− Closure,
81− EffFunction,
82− Thunk,
83− Pointer
84− };
85−
86− private:
87− mutable Type type;
88− mutable bool is_shared;
89−
90− public:
91− struct as_thunk {
92− };
93− static constexpr as_thunk unthunk = as_thunk{};
94−
95− using map = std::vector<std::pair<const char * const, const any>>;
96− using data = std::vector<any>;
97− using array = std::deque<any>;
98− using fn = auto (*)(const any&) -> any;
99− using thunk = auto (*)(const as_thunk) -> const any&;
100−
101− private:
102− class closure {
103− public:
104− virtual auto operator()(const any&) const -> any = 0;
105− virtual ~closure() {}
106− };
107−
108− template <typename T>
109− class _closure : public closure {
110− const T lambda;
111− public:
112− _closure(const T& l) noexcept : lambda(l) {}
113− auto operator()(const any& arg) const -> any {
114− return lambda(arg);
115− }
116− };
117−
118− class eff_fn {
119− public:
120− virtual auto operator()() const -> any = 0;
121− };
122−
123− template <typename T>
124− class _eff_fn : public eff_fn {
125− const T lambda;
126− public:
127− _eff_fn(const T& l) noexcept : lambda(l) {}
128− auto operator()() const -> any {
129− return lambda();
130− }
131− };
132−
133− public:
134− template <typename T>
135− using shared = std::shared_ptr<T>;
136−
137− template <typename T, typename... Args>
138− inline static auto make_shared(Args&&... args) -> decltype(std::make_shared<T>(std::forward<Args>(args)...)) {
139− return std::make_shared<T>(std::forward<Args>(args)...);
140− }
141−
142− private:
143− union {
144− mutable long i;
145− mutable double d;
146− mutable char c;
147− mutable bool b;
148− mutable string r;
149− mutable shared<std::string> s;
150− mutable shared<map> m;
151− mutable shared<data> v;
152− mutable shared<array> a;
153− mutable fn f;
154− mutable shared<closure> l;
155− mutable shared<eff_fn> e;
156− mutable thunk t;
157− mutable shared<void> p;
158− };
159−
160− public:
161−
162− any(const long val) : type(Type::Integer), is_shared(false), i(val) {}
163− any(const int val) : type(Type::Integer), is_shared(false), i(val) {}
164− any(const unsigned int val) : type(Type::Integer), is_shared(false), i(val) {}
165− any(const double val) : type(Type::Double), is_shared(false), d(val) {}
166− any(const char val) : type(Type::Character), is_shared(false), c(val) {}
167−
168− template <typename T, typename = typename std::enable_if<std::is_same<bool,T>::value>::type>
169− any(const T val) : type(Type::Boolean), is_shared(false), b(val) {}
170−
171− template <size_t N>
172− any(const char (&val)[N]) : type(Type::StringLiteral), is_shared(false), r(val) {}
173− any(char * val) : type(Type::String), is_shared(true), s(make_shared<std::string>(val)) {}
174−
175− any(const std::string& val) : type(Type::String), is_shared(true), s(make_shared<std::string>(val)) {}
176− any(std::string&& val) : type(Type::String), is_shared(true), s(make_shared<std::string>(std::move(val))) {}
177−
178− any(const shared<std::string>& val) : type(Type::String), is_shared(true), s(val) {}
179− any(shared<std::string>&& val) noexcept : type(Type::String), is_shared(true), s(std::move(val)) {}
180−
181− any(const map& val) : type(Type::Map), is_shared(true), m(make_shared<map>(val)) {}
182− any(map&& val) noexcept : type(Type::Map), is_shared(true), m(make_shared<map>(std::move(val))) {}
183−
184− any(const data& val) : type(Type::Data), is_shared(true), v(make_shared<data>(val)) {}
185− any(data&& val) noexcept : type(Type::Data), is_shared(true), v(make_shared<data>(std::move(val))) {}
186−
187− any(const array& val) : type(Type::Array), is_shared(true), a(make_shared<array>(val)) {}
188− any(array&& val) noexcept : type(Type::Array), is_shared(true), a(make_shared<array>(std::move(val))) {}
189−
190− template <typename T>
191− any(const T& val, typename std::enable_if<std::is_convertible<T,fn>::value>::type* = 0)
192− : type(Type::Function), is_shared(false), f(val) {}
193−
194− template <typename T, typename = typename std::enable_if<!std::is_same<any,T>::value &&
195− !std::is_convertible<T,fn>::value>::type>
196− any(const T& val, typename std::enable_if<std::is_assignable<std::function<any(const any&)>,T>::value>::type* = 0)
197− : type(Type::Closure), is_shared(true), l(make_shared<_closure<T>>(val)) {}
198−
199− template <typename T>
200− any(const T& val, typename std::enable_if<std::is_assignable<std::function<any()>,T>::value>::type* = 0)
201− : type(Type::EffFunction), is_shared(true), e(make_shared<_eff_fn<T>>(val)) {}
202−
203− template <typename T>
204− any(const T& val, typename std::enable_if<std::is_convertible<T,thunk>::value>::type* = 0)
205− : type(Type::Thunk), is_shared(false), t(val) {}
206−
207− template <typename T>
208− any(const T& val, typename std::enable_if<std::is_assignable<shared<void>,T>::value>::type* = 0)
209− : type(Type::Pointer), is_shared(true), p(val) {}
210−
211− template <typename T>
212− any(T&& val, typename std::enable_if<std::is_assignable<shared<void>,T>::value>::type* = 0) noexcept
213− : type(Type::Pointer), is_shared(true), p(std::move(val)) {}
214−
215− any(std::nullptr_t) : type(Type::Pointer), is_shared(true), p(nullptr) {}
216−
217− private:
218−
219− auto copy(const any& other) const -> void {
220− if (is_shared) {
221− new (&p) shared<void>(other.p);
222− } else {
223− f = other.f;
224− }
225− }
226−
227− auto move(any& other) const noexcept -> void {
228− if (is_shared) {
229− new (&p) shared<void>(std::move(other.p));
230− } else {
231− f = other.f;
232− }
233− }
234−
235− auto destruct() noexcept -> void {
236− if (is_shared) {
237− p.~shared<void>();
238− }
239− }
240−
241− public:
242−
243− any(const any& other) : type(other.type), is_shared(other.is_shared) {
244− copy(other);
245− }
246−
247− any(any&& other) noexcept : type(other.type), is_shared(other.is_shared) {
248− move(other);
249− }
250−
251− auto operator=(const any& rhs) -> any& {
252− destruct();
253− type = rhs.type;
254− is_shared = rhs.is_shared;
255− copy(rhs);
256− return *this;
257− }
258−
259− auto operator=(any&& rhs) noexcept -> any& {
260− destruct();
261− type = rhs.type;
262− is_shared = rhs.is_shared;
263− move(rhs);
264− return *this;
265− }
266−
267− any() = delete;
268−
269− ~any() {
270− destruct();
271− }
272−
273− template <typename T>
274− auto cast() const -> typename std::enable_if<std::is_same<T, long>::value, T>::type;
275−
276− template <typename T>
277− auto cast() const -> typename std::enable_if<std::is_same<T, double>::value, T>::type;
278−
279− template <typename T>
280− auto cast() const -> typename std::enable_if<std::is_same<T, char>::value, T>::type;
281−
282− template <typename T>
283− auto cast() const -> typename std::enable_if<std::is_same<T, bool>::value, T>::type;
284−
285− template <typename T>
286− auto cast() const -> typename std::enable_if<std::is_same<T, string>::value, T>::type;
287−
288− template <typename T>
289− auto cast() const -> typename std::enable_if<std::is_same<T, map>::value, const T&>::type;
290−
291− template <typename T>
292− auto cast() const -> typename std::enable_if<std::is_same<T, data>::value, const T&>::type;
293−
294− template <typename T>
295− auto cast() const -> typename std::enable_if<std::is_same<T, array>::value, const T&>::type;
296−
297− template <typename T>
298− auto cast() const -> typename std::enable_if<std::is_assignable<shared<void>,T>::value, typename T::element_type*>::type {
299− return static_cast<typename T::element_type*>(extractPointer());
300− }
301−
302− auto operator()(const any&) const -> any;
303− auto operator()(const as_thunk) const -> const any&;
304− auto operator()() const -> any;
305−
306− operator long() const;
307− operator double() const;
308− operator bool() const;
309−
310− operator string() const;
311− operator const map&() const;
312− operator const data&() const;
313− operator const array&() const;
314−
315− auto operator[](const char[]) const -> const any&;
316− auto operator[](const size_t) const -> const any&;
317− auto operator[](const any&) const -> const any&;
318−
319− auto contains(const char[]) const -> bool;
320−
321− auto extractPointer() const -> void*;
322−
323− static auto unthunkVariant(const any&) -> const any&;
324−
325− DECLARE_COMPARISON_OPERATOR(==)
326− DECLARE_COMPARISON_OPERATOR(!=)
327− DECLARE_COMPARISON_OPERATOR(<)
328− DECLARE_COMPARISON_OPERATOR(<=)
329− DECLARE_COMPARISON_OPERATOR(>)
330− DECLARE_COMPARISON_OPERATOR(>=)
331−
332− // For MS Visual Studio compiler: broken typed-enum workaround
333− DECLARE_OPERATOR(==, int, bool)
334− DECLARE_OPERATOR(!=, int, bool)
335−
336− friend auto operator+(const any&, const any&) -> any;
337−
338− DECLARE_OPERATOR(+, long, long)
339− DECLARE_OPERATOR(+, double, double)
340− DECLARE_OPERATOR(+, char, char)
341− DECLARE_OPERATOR(+, const char *, std::string)
342−
343− friend auto operator-(const any&, const any&) -> any;
344−
345− DECLARE_OPERATOR(-, long, long)
346− DECLARE_OPERATOR(-, double, double)
347− DECLARE_OPERATOR(-, char, char)
348−
349− friend auto operator*(const any&, const any&) -> any;
350−
351− DECLARE_OPERATOR(*, long, long)
352− DECLARE_OPERATOR(*, double, double)
353− DECLARE_OPERATOR(*, char, char)
354−
355− friend auto operator/(const any&, const any&) -> any;
356−
357− DECLARE_OPERATOR(/, long, long)
358− DECLARE_OPERATOR(/, double, double)
359− DECLARE_OPERATOR(/, char, char)
360−
361− friend auto operator%(const any&, const any&) -> any;
362−
363− DECLARE_OPERATOR(%, long, long)
364− DECLARE_OPERATOR(%, char, char)
365−
366− friend auto operator-(const any&) -> any; // unary negate
367−};
368−
369−// For MS Visual Studio compiler: broken typed-enum workaround
370−inline auto operator==(const any& lhs, int rhs) -> bool {
371− return lhs == (long)rhs;
372−}
373−inline auto operator!=(const any& lhs, int rhs) -> bool {
374− return lhs != (long)rhs;
375−}
376−
377−} // namespace PureScript
378−
379−#undef DECLARE_OPERATOR
380−#undef DECLARE_COMPARISON_OPERATOR
381−
382−#endif // PureScript_HH
psc-bundle/Main.hsdeleted−136
@@ -1,136 +0,0 @@
1−{-# LANGUAGE FlexibleContexts #-}
2−{-# LANGUAGE ScopedTypeVariables #-}
3−{-# LANGUAGE TupleSections #-}
4−{-# LANGUAGE RecordWildCards #-}
5−
6−-- | Bundles compiled PureScript modules for the browser.
7−module Main (main) where
8−
9−import Data.Maybe
10−import Data.Traversable (for)
11−import Data.Version (showVersion)
12−
13−import Control.Applicative
14−import Control.Monad
15−import Control.Monad.Error.Class
16−import Control.Monad.Trans.Except
17−import Control.Monad.IO.Class
18−
19−import System.FilePath (takeFileName, takeDirectory)
20−import System.FilePath.Glob (glob)
21−import System.Exit (exitFailure)
22−import System.IO (stderr, stdout, hPutStrLn, hSetEncoding, utf8)
23−import System.Directory (createDirectoryIfMissing)
24−
25−import Language.PureScript.Bundle
26−
27−import Options.Applicative as Opts
28−
29−import qualified Paths_purescript as Paths
30−
31−-- | Command line options.
32−data Options = Options
33− { optionsInputFiles :: [FilePath]
34− , optionsOutputFile :: Maybe FilePath
35− , optionsEntryPoints :: [String]
36− , optionsMainModule :: Maybe String
37− , optionsNamespace :: String
38− , optionsRequirePath :: Maybe FilePath
39− } deriving Show
40−
41−-- | Given a filename, assuming it is in the correct place on disk, infer a ModuleIdentifier.
42−guessModuleIdentifier :: (MonadError ErrorMessage m) => FilePath -> m ModuleIdentifier
43−guessModuleIdentifier filename = ModuleIdentifier (takeFileName (takeDirectory filename)) <$> guessModuleType (takeFileName filename)
44− where
45− guessModuleType "index.js" = pure Regular
46− guessModuleType "foreign.js" = pure Foreign
47− guessModuleType name = throwError $ UnsupportedModulePath name
48−
49−-- | The main application function.
50−-- This function parses the input files, performs dead code elimination, filters empty modules
51−-- and generates and prints the final Javascript bundle.
52−app :: (MonadError ErrorMessage m, MonadIO m) => Options -> m String
53−app Options{..} = do
54− inputFiles <- concat <$> mapM (liftIO . glob) optionsInputFiles
55− when (null inputFiles) . liftIO $ do
56− hPutStrLn stderr "psc-bundle: No input files."
57− exitFailure
58− input <- for inputFiles $ \filename -> do
59− js <- liftIO (readFile filename)
60− mid <- guessModuleIdentifier filename
61− length js `seq` return (mid, js) -- evaluate readFile till EOF before returning, not to exhaust file handles
62−
63− let entryIds = map (`ModuleIdentifier` Regular) optionsEntryPoints
64−
65− bundle input entryIds optionsMainModule optionsNamespace optionsRequirePath
66−
67−-- | Command line options parser.
68−options :: Parser Options
69−options = Options <$> some inputFile
70− <*> optional outputFile
71− <*> many entryPoint
72− <*> optional mainModule
73− <*> namespace
74− <*> optional requirePath
75− where
76− inputFile :: Parser FilePath
77− inputFile = strArgument $
78− metavar "FILE"
79− <> help "The input .js file(s)"
80−
81− outputFile :: Parser FilePath
82− outputFile = strOption $
83− short 'o'
84− <> long "output"
85− <> help "The output .js file"
86−
87− entryPoint :: Parser String
88− entryPoint = strOption $
89− short 'm'
90− <> long "module"
91− <> help "Entry point module name(s). All code which is not a transitive dependency of an entry point module will be removed."
92−
93− mainModule :: Parser String
94− mainModule = strOption $
95− long "main"
96− <> help "Generate code to run the main method in the specified module."
97−
98− namespace :: Parser String
99− namespace = strOption $
100− short 'n'
101− <> long "namespace"
102− <> Opts.value "PS"
103− <> showDefault
104− <> help "Specify the namespace that PureScript modules will be exported to when running in the browser."
105−
106− requirePath :: Parser FilePath
107− requirePath = strOption $
108− short 'r'
109− <> long "require-path"
110− <> help "The path prefix used in require() calls in the generated JavaScript [deprecated]"
111−
112−-- | Make it go.
113−main :: IO ()
114−main = do
115− hSetEncoding stdout utf8
116− hSetEncoding stderr utf8
117− opts <- execParser (info (version <*> helper <*> options) infoModList)
118− when (isJust (optionsRequirePath opts)) $ hPutStrLn stderr "The require-path option is deprecated and will be removed in PureScript 0.9."
119− output <- runExceptT (app opts)
120− case output of
121− Left err -> do
122− hPutStrLn stderr (unlines (printErrorMessage err))
123− exitFailure
124− Right js ->
125− case optionsOutputFile opts of
126− Just outputFile -> do
127− createDirectoryIfMissing True (takeDirectory outputFile)
128− writeFile outputFile js
129− Nothing -> putStrLn js
130− where
131− infoModList = fullDesc <> headerInfo <> footerInfo
132− headerInfo = header "psc-bundle - Bundles compiled PureScript modules for the browser"
133− footerInfo = footer $ "psc-bundle " ++ showVersion Paths.version
134−
135− version :: Parser (a -> a)
136− version = abortOption (InfoMsg (showVersion Paths.version)) $ long "version" <> help "Show the version number" <> hidden
psc-bundle/README.mddeleted−18
@@ -1,18 +0,0 @@
1−# psc-bundle
2−
3−A dead code elimination tool for PureScript-style CommonJS modules. This can be used as an alternative to Browserify.
4−
5−## Usage
6−
7− psc-bundle FILE (-m|--module ARG) [--main ARG] [--namespace ARG]
8−
9−Options:
10−
11−- The input .js file(s)
12−- Entry point module name(s) are specified with `-m` or `--module`. All code which is not a transitive dependency of an entry point module will be removed.
13−- The main module is (optionally) specified using `--main`. If specified, this will generate code to run the main method in the specified module.
14−- The browser namespace defaults to `PS`, and can be overridden with `--namespace`.
15−
16−For example, to bundle the modules in the `output` directory, with main module `Main`:
17−
18− psc-bundle output/**/*.js -m Main --main Main
psc-docs/Ctags.hsdeleted−13
@@ -1,13 +0,0 @@
1−module Ctags (dumpCtags) where
2−
3−import qualified Language.PureScript as P
4−import Tags
5−import Data.List (sort)
6−
7−dumpCtags :: [(String, P.Module)] -> [String]
8−dumpCtags = sort . concatMap renderModCtags
9−
10−renderModCtags :: (String, P.Module) -> [String]
11−renderModCtags (path, mdl) = sort tagLines
12− where tagLines = map tagLine $ tags mdl
13− tagLine (name, line) = name ++ "\t" ++ path ++ "\t" ++ show line
psc-docs/Etags.hsdeleted−13
@@ -1,13 +0,0 @@
1−module Etags (dumpEtags) where
2−
3−import qualified Language.PureScript as P
4−import Tags
5−
6−dumpEtags :: [(String, P.Module)] -> [String]
7−dumpEtags = concatMap renderModEtags
8−
9−renderModEtags :: (String, P.Module) -> [String]
10−renderModEtags (path, mdl) = ["\x0c", path ++ "," ++ show tagsLen] ++ tagLines
11− where tagsLen = sum $ map length tagLines
12− tagLines = map tagLine $ tags mdl
13− tagLine (name, line) = "\x7f" ++ name ++ "\x01" ++ show line ++ ","
psc-docs/Main.hsdeleted−249
@@ -1,249 +0,0 @@
1−{-# LANGUAGE TupleSections #-}
2−
3−module Main where
4−
5−import Control.Applicative
6−import Control.Monad.Trans.Except (runExceptT)
7−import Control.Arrow (first, second)
8−import Control.Category ((>>>))
9−import Control.Monad.Writer
10−import Data.Function (on)
11−import Data.List
12−import Data.Maybe (fromMaybe)
13−import Data.Tuple (swap)
14−import Data.Version (showVersion)
15−
16−import Options.Applicative
17−import qualified Text.PrettyPrint.ANSI.Leijen as PP
18−
19−import qualified Language.PureScript as P
20−import qualified Paths_purescript as Paths
21−import System.Exit (exitFailure)
22−import System.IO (hPutStrLn, hPrint, hSetEncoding, stderr, stdout, utf8)
23−import System.Directory (createDirectoryIfMissing)
24−import System.FilePath (takeDirectory)
25−import System.FilePath.Glob (glob)
26−
27−import Etags
28−import Ctags
29−import qualified Language.PureScript.Docs as D
30−import qualified Language.PureScript.Docs.AsMarkdown as D
31−
32−-- Available output formats
33−data Format = Markdown -- Output documentation in Markdown format
34− | Ctags -- Output ctags symbol index suitable for use with vi
35− | Etags -- Output etags symbol index suitable for use with emacs
36− deriving (Show, Eq, Ord)
37−
38−-- | Available methods of outputting Markdown documentation
39−data DocgenOutput
40− = EverythingToStdOut
41− | ToStdOut [P.ModuleName]
42− | ToFiles [(P.ModuleName, FilePath)]
43− deriving (Show)
44−
45−data PSCDocsOptions = PSCDocsOptions
46− { pscdFormat :: Format
47− , pscdInputFiles :: [FilePath]
48− , pscdDocgen :: DocgenOutput
49− }
50− deriving (Show)
51−
52−docgen :: PSCDocsOptions -> IO ()
53−docgen (PSCDocsOptions fmt inputGlob output) = do
54− input <- concat <$> mapM glob inputGlob
55− case fmt of
56− Etags -> dumpTags input dumpEtags
57− Ctags -> dumpTags input dumpCtags
58− Markdown -> do
59− ms <- runExceptT (D.parseAndBookmark input []
60− >>= (fst >>> D.convertModulesInPackage))
61− >>= successOrExit
62−
63− case output of
64− EverythingToStdOut ->
65− putStrLn (D.runDocs (D.modulesAsMarkdown ms))
66− ToStdOut names -> do
67− let (ms', missing) = takeByName ms names
68− guardMissing missing
69− putStrLn (D.runDocs (D.modulesAsMarkdown ms'))
70− ToFiles names -> do
71− let (ms', missing) = takeByName' ms names
72− guardMissing missing
73−
74− let ms'' = groupBy ((==) `on` fst) . sortBy (compare `on` fst) $ map swap ms'
75− forM_ ms'' $ \grp -> do
76− let fp = fst (head grp)
77− createDirectoryIfMissing True (takeDirectory fp)
78− writeFile fp (D.runDocs (D.modulesAsMarkdown (map snd grp)))
79−
80− where
81− guardMissing [] = return ()
82− guardMissing [mn] = do
83− hPutStrLn stderr ("psc-docs: error: unknown module \"" ++ P.runModuleName mn ++ "\"")
84− exitFailure
85− guardMissing mns = do
86− hPutStrLn stderr "psc-docs: error: unknown modules:"
87− forM_ mns $ \mn ->
88− hPutStrLn stderr (" * " ++ P.runModuleName mn)
89− exitFailure
90−
91− successOrExit :: Either P.MultipleErrors a -> IO a
92− successOrExit act =
93− case act of
94− Right x ->
95− return x
96− Left err -> do
97− hPutStrLn stderr $ P.prettyPrintMultipleErrors False err
98− exitFailure
99−
100− takeByName = takeModulesByName D.modName
101− takeByName' = takeModulesByName' D.modName
102−
103−-- |
104−-- Given a list of module names and a list of modules, return a list of modules
105−-- whose names appeared in the given name list, together with a list of names
106−-- for which no module could be found in the module list.
107−--
108−takeModulesByName :: (Eq n) => (m -> n) -> [m] -> [n] -> ([m], [n])
109−takeModulesByName getModuleName modules names =
110− first (map fst) (takeModulesByName' getModuleName modules (map (,()) names))
111−
112−-- |
113−-- Like takeModulesByName, but also keeps some extra information with each
114−-- module.
115−--
116−takeModulesByName' :: (Eq n) => (m -> n) -> [m] -> [(n, a)] -> ([(m, a)], [n])
117−takeModulesByName' getModuleName modules = foldl go ([], [])
118− where
119− go (ms, missing) (name, x) =
120− case find ((== name) . getModuleName) modules of
121− Just m -> ((m, x) : ms, missing)
122− Nothing -> (ms, name : missing)
123−
124−dumpTags :: [FilePath] -> ([(String, P.Module)] -> [String]) -> IO ()
125−dumpTags input renderTags = do
126− e <- P.parseModulesFromFiles (fromMaybe "") <$> mapM (fmap (first Just) . parseFile) (nub input)
127− case e of
128− Left err -> do
129− hPrint stderr err
130− exitFailure
131− Right ms ->
132− ldump (renderTags (pairs ms))
133−
134− where
135− pairs :: [(Maybe String, m)] -> [(String, m)]
136− pairs = map (first (fromMaybe ""))
137−
138− ldump :: [String] -> IO ()
139− ldump = mapM_ putStrLn
140−
141−parseFile :: FilePath -> IO (FilePath, String)
142−parseFile input = (,) input <$> readFile input
143−
144−inputFile :: Parser FilePath
145−inputFile = strArgument $
146− metavar "FILE"
147− <> help "The input .purs file(s)"
148−
149−instance Read Format where
150− readsPrec _ "etags" = [(Etags, "")]
151− readsPrec _ "ctags" = [(Ctags, "")]
152− readsPrec _ "markdown" = [(Markdown, "")]
153− readsPrec _ _ = []
154−
155−format :: Parser Format
156−format = option auto $ value Markdown
157− <> long "format"
158− <> metavar "FORMAT"
159− <> help "Set output FORMAT (markdown | etags | ctags)"
160−
161−docgenModule :: Parser String
162−docgenModule = strOption $
163− long "docgen"
164− <> help "A list of module names which should appear in the output. This can optionally include file paths to write individual modules to, by separating with a colon ':'. For example, Prelude:docs/Prelude.md. This option may be specified multiple times."
165−
166−pscDocsOptions :: Parser (Format, [FilePath], [String])
167−pscDocsOptions = (,,) <$> format <*> many inputFile <*> many docgenModule
168−
169−parseDocgen :: [String] -> Either String DocgenOutput
170−parseDocgen [] = Right EverythingToStdOut
171−parseDocgen xs = go xs
172− where
173− go = intersperse " "
174− >>> concat
175− >>> words
176− >>> map parseItem
177− >>> combine
178−
179−data DocgenOutputItem
180− = IToStdOut P.ModuleName
181− | IToFile (P.ModuleName, FilePath)
182−
183−parseItem :: String -> DocgenOutputItem
184−parseItem s = case elemIndex ':' s of
185− Just i ->
186− s # splitAt i
187− >>> first P.moduleNameFromString
188− >>> second (drop 1)
189− >>> IToFile
190− Nothing ->
191− IToStdOut (P.moduleNameFromString s)
192−
193− where
194− infixr 1 #
195− (#) = flip ($)
196−
197−combine :: [DocgenOutputItem] -> Either String DocgenOutput
198−combine [] = Right EverythingToStdOut
199−combine (x:xs) = foldM go (initial x) xs
200− where
201− initial (IToStdOut m) = ToStdOut [m]
202− initial (IToFile m) = ToFiles [m]
203−
204− go (ToStdOut ms) (IToStdOut m) = Right (ToStdOut (m:ms))
205− go (ToFiles ms) (IToFile m) = Right (ToFiles (m:ms))
206− go _ _ = Left "Can't mix module names and module name/file path pairs in the same invocation."
207−
208−buildOptions :: (Format, [FilePath], [String]) -> IO PSCDocsOptions
209−buildOptions (fmt, input, mapping) =
210− case parseDocgen mapping of
211− Right mapping' -> return (PSCDocsOptions fmt input mapping')
212− Left err -> do
213− hPutStrLn stderr "psc-docs: error in --docgen option:"
214− hPutStrLn stderr (" " ++ err)
215− exitFailure
216−
217−main :: IO ()
218−main = do
219− hSetEncoding stdout utf8
220− hSetEncoding stderr utf8
221− execParser opts >>= buildOptions >>= docgen
222− where
223− opts = info (version <*> helper <*> pscDocsOptions) infoModList
224− infoModList = fullDesc <> headerInfo <> footerInfo
225− headerInfo = header "psc-docs - Generate Markdown documentation from PureScript source files"
226− footerInfo = footerDoc $ Just $ PP.vcat
227− [ examples, PP.empty, PP.text ("psc-docs " ++ showVersion Paths.version) ]
228−
229− version :: Parser (a -> a)
230− version = abortOption (InfoMsg (showVersion Paths.version)) $ long "version" <> help "Show the version number" <> hidden
231−
232−examples :: PP.Doc
233−examples =
234− PP.vcat $ map PP.text
235− [ "Examples:"
236− , " print documentation for Data.List to stdout:"
237− , " psc-docs \"src/**/*.purs\" \"bower_components/*/src/**/*.purs\" \\"
238− , " --docgen Data.List"
239− , ""
240− , " write documentation for Data.List to docs/Data.List.md:"
241− , " psc-docs \"src/**/*.purs\" \"bower_components/*/src/**/*.purs\" \\"
242− , " --docgen Data.List:docs/Data.List.md"
243− , ""
244− , " write documentation for Data.List to docs/Data.List.md, and"
245− , " documentation for Data.List.Lazy to docs/Data.List.Lazy.md:"
246− , " psc-docs \"src/**/*.purs\" \"bower_components/*/src/**/*.purs\" \\"
247− , " --docgen Data.List:docs/Data.List.md \\"
248− , " --docgen Data.List.Lazy:docs/Data.List.Lazy.md"
249− ]
psc-docs/Tags.hsdeleted−18
@@ -1,18 +0,0 @@
1−module Tags where
2−
3−import qualified Language.PureScript as P
4−
5−tags :: P.Module -> [(String, Int)]
6−tags = concatMap dtags . P.exportedDeclarations
7− where dtags (P.PositionedDeclaration sp _ d) = map tag $ names d
8− where tag name = (name, line)
9− line = P.sourcePosLine $ P.spanStart sp
10− dtags _ = []
11− names (P.DataDeclaration _ name _ dcons) = P.runProperName name : consNames
12− where consNames = map (\(cname, _) -> P.runProperName cname) dcons
13− names (P.TypeDeclaration ident _) = [P.showIdent ident]
14− names (P.ExternDeclaration ident _) = [P.showIdent ident]
15− names (P.TypeSynonymDeclaration name _ _) = [P.runProperName name]
16− names (P.TypeClassDeclaration name _ _ _) = [P.runProperName name]
17− names (P.TypeInstanceDeclaration name _ _ _ _) = [P.showIdent name]
18− names _ = []
psc-ide-client/Main.hsdeleted−56
@@ -1,56 +0,0 @@
1−{-# LANGUAGE OverloadedStrings #-}
2−module Main where
3−
4−import Prelude ()
5−import Prelude.Compat
6−
7−import Control.Exception
8−import Data.Text (Text)
9−import qualified Data.Text as T
10−import qualified Data.Text.IO as T
11−import Data.Version (showVersion)
12−import Network
13−import Options.Applicative
14−import System.Exit
15−import System.IO
16−
17−import qualified Paths_purescript as Paths
18−
19−data Options = Options
20− { optionsPort :: PortID
21− }
22−
23−main :: IO ()
24−main = do
25− Options port <- execParser opts
26− client port
27− where
28− parser =
29− Options <$>
30− (PortNumber . fromIntegral <$>
31− option auto (long "port" <> short 'p' <> value (4242 :: Integer)))
32− opts = info (version <*> helper <*> parser) mempty
33− version = abortOption (InfoMsg (showVersion Paths.version)) $ long "version" <> help "Show the version number" <> hidden
34−
35−client :: PortID -> IO ()
36−client port = do
37− h <-
38− connectTo "localhost" port `catch`
39− (\(SomeException e) ->
40− putStrLn
41− ("Couldn't connect to psc-ide-server on port: " ++
42− show port ++ " Error: " ++ show e) >>
43− exitFailure)
44− cmd <- T.getLine
45− -- Temporary fix for emacs windows bug
46− let cleanedCmd = removeSurroundingTicks cmd
47− --
48− T.hPutStrLn h cleanedCmd
49− res <- T.hGetLine h
50− putStrLn (T.unpack res)
51− hFlush stdout
52− hClose h
53−
54−-- TODO: Fix this in the emacs plugin by using a real process over shellcommands
55−removeSurroundingTicks :: Text -> Text
56−removeSurroundingTicks = T.dropWhile (== '\'') . T.dropWhileEnd (== '\'')
psc-ide-server/Main.hsdeleted−163
@@ -1,163 +0,0 @@
1−-----------------------------------------------------------------------------
2−--
3−-- Module : Main
4−-- Description : The server accepting commands for psc-ide
5−-- Copyright : Christoph Hegemann 2016
6−-- License : MIT (http://opensource.org/licenses/MIT)
7−--
8−-- Maintainer : Christoph Hegemann <christoph.hegemann1337@gmail.com>
9−-- Stability : experimental
10−--
11−-- |
12−-- The server accepting commands for psc-ide
13−-----------------------------------------------------------------------------
14−
15−{-# LANGUAGE ConstraintKinds #-}
16−{-# LANGUAGE FlexibleContexts #-}
17−{-# LANGUAGE MultiParamTypeClasses #-}
18−{-# LANGUAGE OverloadedStrings #-}
19−{-# LANGUAGE PackageImports #-}
20−{-# LANGUAGE TemplateHaskell #-}
21−
22−module Main where
23−
24−import Prelude ()
25−import Prelude.Compat
26−
27−import Control.Concurrent (forkFinally)
28−import Control.Concurrent.STM
29−import Control.Exception (bracketOnError, catchJust)
30−import Control.Monad
31−import Control.Monad.Error.Class
32−import "monad-logger" Control.Monad.Logger
33−import Control.Monad.Reader
34−import Control.Monad.Trans.Except
35−import qualified Data.Text as T
36−import qualified Data.Text.IO as T
37−import Data.Version (showVersion)
38−import Language.PureScript.Ide
39−import Language.PureScript.Ide.Util
40−import Language.PureScript.Ide.Error
41−import Language.PureScript.Ide.Types
42−import Language.PureScript.Ide.Watcher
43−import Network hiding (socketPort)
44−import Network.BSD (getProtocolNumber)
45−import Network.Socket hiding (PortNumber, Type,
46− accept, sClose)
47−import Options.Applicative
48−import System.Directory
49−import System.FilePath
50−import System.IO
51−import System.IO.Error (isEOFError)
52−
53−import qualified Paths_purescript as Paths
54−
55−-- "Borrowed" from the Idris Compiler
56−-- Copied from upstream impl of listenOn
57−-- bound to localhost interface instead of iNADDR_ANY
58−listenOnLocalhost :: PortID -> IO Socket
59−listenOnLocalhost (PortNumber port) = do
60− proto <- getProtocolNumber "tcp"
61− localhost <- inet_addr "127.0.0.1"
62− bracketOnError
63− (socket AF_INET Stream proto)
64− sClose
65− (\sock -> do
66− setSocketOption sock ReuseAddr 1
67− bindSocket sock (SockAddrInet port localhost)
68− listen sock maxListenQueue
69− pure sock)
70−listenOnLocalhost _ = error "Wrong Porttype"
71−
72−data Options = Options
73− { optionsDirectory :: Maybe FilePath
74− , optionsOutputPath :: FilePath
75− , optionsPort :: PortID
76− , optionsDebug :: Bool
77− }
78−
79−main :: IO ()
80−main = do
81− Options dir outputPath port debug <- execParser opts
82− maybe (pure ()) setCurrentDirectory dir
83− serverState <- newTVarIO emptyPscIdeState
84− cwd <- getCurrentDirectory
85− _ <- forkFinally (watcher serverState (cwd </> outputPath)) print
86− let conf =
87− Configuration
88− {
89− confDebug = debug
90− , confOutputPath = outputPath
91− }
92− let env =
93− PscIdeEnvironment
94− {
95− envStateVar = serverState
96− , envConfiguration = conf
97− }
98− startServer port env
99− where
100− parser =
101− Options <$>
102− optional (strOption (long "directory" <> short 'd')) <*>
103− strOption (long "output-directory" <> value "output/") <*>
104− (PortNumber . fromIntegral <$>
105− option auto (long "port" <> short 'p' <> value (4242 :: Integer))) <*>
106− switch (long "debug")
107− opts = info (version <*> helper <*> parser) mempty
108− version = abortOption
109− (InfoMsg (showVersion Paths.version))
110− (long "version" <> help "Show the version number")
111−
112−startServer :: PortID -> PscIdeEnvironment -> IO ()
113−startServer port env = withSocketsDo $ do
114− sock <- listenOnLocalhost port
115− runLogger (runReaderT (forever (loop sock)) env)
116− where
117− runLogger = runStdoutLoggingT . filterLogger (\_ _ -> confDebug (envConfiguration env))
118−
119− loop :: (PscIde m, MonadLogger m) => Socket -> m ()
120− loop sock = do
121− accepted <- runExceptT $ acceptCommand sock
122− case accepted of
123− Left err -> $(logDebug) err
124− Right (cmd, h) -> do
125− case decodeT cmd of
126− Just cmd' -> do
127− result <- runExceptT (handleCommand cmd')
128− -- $(logDebug) ("Answer was: " <> T.pack (show result))
129− liftIO (hFlush stdout)
130− case result of
131− -- What function can I use to clean this up?
132− Right r -> liftIO $ T.hPutStrLn h (encodeT r)
133− Left err -> liftIO $ T.hPutStrLn h (encodeT err)
134− Nothing -> do
135− $(logDebug) ("Parsing the command failed. Command: " <> cmd)
136− liftIO $ do
137− T.hPutStrLn h (encodeT (GeneralError "Error parsing Command."))
138− hFlush stdout
139− liftIO (hClose h)
140−
141−
142−acceptCommand :: (MonadIO m, MonadLogger m, MonadError T.Text m)
143− => Socket -> m (T.Text, Handle)
144−acceptCommand sock = do
145− h <- acceptConnection
146− $(logDebug) "Accepted a connection"
147− cmd' <- liftIO (catchJust
148− -- this means that the connection was
149− -- terminated without receiving any input
150− (\e -> if isEOFError e then Just () else Nothing)
151− (Just <$> T.hGetLine h)
152− (const (pure Nothing)))
153− case cmd' of
154− Nothing -> throwError "Connection was closed before any input arrived"
155− Just cmd -> do
156− $(logDebug) cmd
157− pure (cmd, h)
158− where
159− acceptConnection = liftIO $ do
160− (h,_,_) <- accept sock
161− hSetEncoding h utf8
162− hSetBuffering h LineBuffering
163− pure h
psc-ide-server/PROTOCOL.mddeleted−525
@@ -1,525 +0,0 @@
1−# Protocol
2−
3−Encode the following JSON formats into a single line string and pass them to
4−`psc-ide-client`s stdin. You can then read the result from `psc-ide-client`s
5−stdout as a single line. The result needs to be unwrapped from the "wrapper"
6−which separates success from failure. This wrapper is described at the end of
7−this document.
8−
9−## Command:
10−### Load
11−The `load` command "loads" the requested modules into the server for completion
12−and type info. If the `params` object is left off, the `load` command will try
13−to detect all the compiled modules in your project and load them.
14−
15−**Params:**
16− - `modules :: (optional) [ModuleName]`: A list of modules to load.
17− psc-ide-server will try to parse all the declarations in these modules
18− - `dependencies :: (optional) [ModuleName]`: A list of modules to load
19− including their dependencies. In contrast to the `module` field, all the
20− imports in these Modules will also be loaded.
21−
22−```json
23−{
24− "command": "load",
25− "params": (optional) {
26− "modules": (optional)["Module.Name1", "Module.Name2"],
27− "dependencies": (optional)["Module.Name3"]
28− }
29−}
30−```
31−
32−**Result:**
33−
34−The Load Command returns a string.
35−
36−### Type
37−The `type` command looks up the type for a given identifier.
38−
39−**Params:**
40− - `search :: String`: The identifier to look for. Only matches on equality.
41− - `filters :: [Filter]`: These filters will be applied before looking for the
42− identifier. These filters get combined with *AND*, so a candidate must match *ALL*
43− of them to be eligible.
44−```json
45−{
46− "command": "type",
47− "params": {
48− "search": "filterM",
49− "filters": [Filter]
50− }
51−}
52−```
53−
54−**Result:**
55−The possible types are returned in the same format as completions
56−
57−### Complete
58−The `complete` command looks up possible completions/corrections.
59−
60−**Params**:
61− - `filters :: [Filter]`: The same as for the `type` command. A candidate must match
62− all filters.
63− - `matcher :: (optional) Matcher`: The strategy used for matching candidates after filtering.
64− Results are scored internally and will be returned in the descending order where
65− the nth element is better then the n+1-th.
66−
67− If no matcher is given every candidate, that passes the filters, is returned in no
68− particular order.
69−```json
70−{
71− "command": "complete",
72− "params": {
73− "filters": [Filter],
74− "matcher": (optional) Matcher
75− }
76−}
77−```
78−
79−**Result:**
80−
81−The following format is returned as the Result:
82−
83−```json
84−[
85− {
86− "module": "Data.Array",
87− "identifier": "filter",
88− "type": "forall a. (a -> Boolean) -> Array a -> Array a"
89− }
90−]
91−```
92−
93−
94−### CaseSplit
95−
96−The CaseSplit command takes a line of source code, an area in that line of code
97−and replaces it with all patterns for a given type. The parameter `annotations`
98−is used to turn type annotations on or off for the constructor fields.
99−
100−```json
101−{
102− "command": "caseSplit",
103− "params": {
104− "line": "elem a as",
105− "begin": 8,
106− "end": 10,
107− "annotations": true,
108− "type": "List"
109− }
110−}
111−```
112−
113−**Result:**
114−
115−The following format is returned as the Result:
116−
117−```json
118−[
119− "elem a Nil",
120− "elem a (Cons (_ :: a) (_ :: List a))"
121−]
122−```
123−You should then be able to replace the affected line of code in the editor with the new suggestions.
124−
125−### Add Clause
126−
127−The AddClause command takes a typedeclaration and generates a function template for the given type.
128−The `annotations` option turns type annotations on or off for the function arguments.
129−
130−```json
131−{
132− "command": "addClause",
133− "params": {
134− "line": "elem :: forall a. (Eq a) => a -> List a",
135− "annotations": true
136− }
137−}
138−```
139−
140−**Result:**
141−
142−The following format is returned as the Result:
143−
144−```json
145−[
146− "elem :: forall a. (Eq a) => a -> List a",
147− "elem ( _ :: a) = ?elem"
148−]
149−```
150−You should then be able to replace the affected line of code in the editor with the new suggestions.
151−
152−### Import
153−
154−For now all of the import related commands work with a file on the filesystem.
155−
156−You can specify it with the `file` parameter.
157−
158−If you supply the optional `outfile` parameter, the output will be written to
159−that file, and an info message will be returned from the client.
160−
161−If you don't supply `outfile`, the server responds with a list of strings which,
162−when inserted into a file linewise create the module with the applied changes.
163−
164−Arguments:
165−
166−- `file` :: String
167−- `outfile` :: Maybe String
168−- `filters` :: Maybe [Filter]
169−
170−Example:
171−
172−```json
173−{
174− "command": "import",
175− "params": {
176− "file": "/home/creek/Documents/chromacannon/src/Main.purs",
177− "outfile": "/home/creek/Documents/chromacannon/src/Main.purs",
178− "filters": [{
179− "filter": "modules",
180− "params": {
181− "modules": ["My.Module"]
182− }
183− }],
184− "importCommand": {
185− "yadda": "yadda"
186− }
187− }
188−}
189−```
190−
191−
192−#### Subcommand `addImplicitImport`
193−
194−This command just adds an unqualified import for the given modulename.
195−
196−Arguments:
197−- `moduleName :: String`
198−
199−Example:
200−```json
201−{
202− "command": "import",
203− "params": {
204− "file": "/home/creek/Documents/chromacannon/src/Main.purs",
205− "importCommand": {
206− "importCommand": "addImplicitImport",
207− "module": "Data.Array.LOL"
208− }
209− }
210−}
211−```
212−#### Subcommand `addImport`
213−
214−This command takes an identifier and searches the currently loaded modules for
215−it. If it finds no matches it responds with an Error. If it finds exactly one
216−match it adds the import and returns. If it finds more than one match it
217−responds with a list of the found matches as completions like the complete
218−command.
219−
220−You can also supply a list of filters like the ones for completion. This way you
221−can narrow down the search to a certain module and resolve the case in which
222−more then one match was found.
223−
224−Arguments:
225−- `moduleName :: String`
226−- `filters :: [Filter]`
227−
228−Example:
229−```json
230−{
231− "command": "import",
232− "params": {
233− "file": "/home/creek/Documents/chromacannon/src/Demo.purs",
234− "outfile": "/home/creek/Documents/chromacannon/src/Demo.purs",
235− "importCommand": {
236− "importCommand": "addImport",
237− "identifier": "bind"
238− }
239− }
240−}
241−```
242−
243−### Rebuild
244−
245−The `rebuild` command provides a fast rebuild for a single module. It doesn't
246−recompile the entire project though. All the modules dependencies need to be
247−loaded.
248−
249−Arguments:
250−- `file :: String` the path to the module to rebuild
251−
252−```json
253−{
254− "command": "rebuild",
255− "params": {
256− "file": "/path/to/file.purs"
257− }
258−}
259−```
260−
261−**Result**
262−
263−In the Success case you get a list of warnings in the compilers json format.
264−
265−In the Error case you get the errors in the compilers json format
266−
267−### Pursuit
268−The `pursuit` command looks up the packages/completions for a given identifier from Pursuit.
269−
270−**Params:**
271− - `query :: String`: With `type: "package"` this should be a module name. With
272− `type: "completion"` this can be any string to look up.
273− - `type :: String`: Takes the following values:
274− - `package`: Looks for packages that contain the given module name.
275− - `completion` Looks for declarations for the query from Pursuit.
276−
277−```json
278−{
279− "command": "pursuit",
280− "params": {
281− "query": "Data.Array",
282− "type": "package"
283− }
284−}
285−```
286−
287−**Result:**
288−
289−`package` returns:
290−
291−```json
292−[
293− {
294− "module": "Module1.Name",
295− "package": "purescript-packagename"
296− }
297−]
298−```
299−
300−`completion` returns:
301−
302−```json
303−[
304− {
305− "module": "Data.Array",
306− "identifier": "filter",
307− "type": "forall a. (a -> Boolean) -> Array a -> Array a",
308− "package": "purescript-arrays"
309− }
310−]
311−```
312−
313−### List
314−
315−#### Loaded Modules
316−
317−`list` of type `loadedModules` lists all loaded modules (This means they can be searched for completions etc)
318−
319−```json
320−{
321− "command": "list",
322− "params": {
323− "type": "loadedModules"
324− }
325−}
326−```
327−
328−#### Response:
329−
330−The list loadedModules command returns a list of strings.
331−
332−#### Available Modules
333−
334−`list` of type `availableModules` lists all available modules. (This basically
335−means the contents of the `output/` folder.))
336−
337−```json
338−{
339− "command": "list",
340− "params": {
341− "type": "availableModules"
342− }
343−}
344−```
345−
346−#### Response:
347−
348−The list availableModules command returns a list of strings.
349−
350−#### Imports
351−
352−The list commmand can also list the imports for a given file.
353−
354−```json
355−{
356− "command": "list",
357− "params": {
358− "type": "import",
359− "file": "/home/kritzcreek/Documents/psc-ide/examples/Main.purs"
360− }
361−}
362−```
363−
364−#### Response:
365−
366−The list import command returns a list of imports where imports are of the following form:
367−
368−Implicit Import(`import Data.Array`):
369−```json
370−[
371− {
372− "module": "Data.Array",
373− "importType": "implicit"
374− }
375−]
376−```
377−
378−Implicit qualified Import(`import qualified Data.Array as A`):
379−```json
380−[
381− {
382− "module": "Data.Array",
383− "importType": "implicit",
384− "qualifier": "A"
385− }
386−]
387−```
388−
389−Explicit Import(`import Data.Array (filter, filterM, join)`):
390−```json
391−[
392− {
393− "module": "Data.Array",
394− "importType": "explicit",
395− "identifiers": ["filter", "filterM", "join"]
396− }
397−]
398−```
399−
400−Hiding Import(`import Data.Array hiding (filter, filterM, join)`):
401−```json
402−[
403− {
404− "module": "Data.Array",
405− "importType": "hiding",
406− "identifiers": ["filter", "filterM", "join"]
407− }
408−]
409−```
410−### Cwd/Quit
411−`cwd` returns the working directory of the server(should be your project root).
412−
413−`quit` quits the server.
414−
415−```json
416−{
417− "command": "cwd|quit"
418−}
419−```
420−
421−**Result:**
422−These commands return strings.
423−
424−## Filter:
425−
426−### Exact filter
427−The Exact filter only keeps identifiers that are equal to the search term.
428−
429−```json
430−{
431− "filter": "exact",
432− "params": {
433− "search": "filterM"
434− }
435−}
436−```
437−### Prefix filter
438−The Prefix filter keeps identifiers/modules/data declarations that
439−are prefixed by the search term.
440−
441−```json
442−{
443− "filter": "prefix",
444− "params": {
445− "search": "filt"
446− }
447−}
448−```
449−
450−### Module filter
451−The Module filter only keeps identifiers that appear in the listed modules.
452−
453−```json
454−{
455− "filter": "modules",
456− "params": {
457− "modules": ["My.Module"]
458− }
459−}
460−```
461−
462−### Dependency filter
463−The Dependency filter only keeps identifiers that appear in the listed modules
464−and in any of their dependencies/imports.
465−
466−```json
467−{
468− "filter": "dependencies",
469− "params": {
470− "modules": ["My.Module"]
471− }
472−}
473−```
474−
475−## Matcher:
476−
477−### Flex matcher
478−Matches any occurence of the search string with intersections
479−
480−The scoring measures how far the matches span the string, where
481−closer is better. The matches then get sorted with highest score first.
482−
483−Examples:
484−- flMa matches **fl**ex**Ma**tcher. Score: 14.28
485−- sons matches **so**rtCompletio**ns**. Score: 6.25
486−```json
487−
488−{
489− "matcher": "flex",
490− "params": {
491− "search": "filt"
492− }
493−}
494−```
495−
496−### Distance Matcher
497−
498−The Distance matcher is meant to provide corrections for typos. It calculates
499−the edit distance in between the search and the loaded identifiers.
500−
501−```json
502−{
503− "matcher": "distance",
504− "params": {
505− "search": "dilterM",
506− "maximumDistance": 3
507− }
508−}
509−```
510−
511−## Responses
512−
513−All Responses are wrapped in the following format:
514−
515−```json
516−{
517− "resultType": "success|error",
518− "result": Result|Error
519−}
520−```
521−
522−### Error
523−
524−Errors at this point are merely Error strings. Newlines are escaped like `\n`
525−and should be taken care of by the editor-plugin.
psc-ide-server/README.mddeleted−40
@@ -1,40 +0,0 @@
1−psc-ide
2−===
3−
4−A tool which provides editor support for the PureScript programming language.
5−
6−## Editor Integration
7−* [@epost](https://github.com/epost) wrote a plugin to integrate psc-ide with Emacs at https://github.com/epost/psc-ide-emacs.
8−* Atom integration is available with https://github.com/nwolverson/atom-ide-purescript.
9−* Visual Studio Code integration is available with https://github.com/nwolverson/vscode-ide-purescript.
10−* Vim integration is available here: https://github.com/FrigoEU/psc-ide-vim.
11−
12−## Running the Server
13−Start the server by running the `psc-ide-server` executable.
14−It supports the following options:
15−
16−- `-p / --port` specify a port. Defaults to 4242
17−- `-d / --directory` specify the toplevel directory of your project. Defaults to
18− the current directory
19−- `--output-directory`: Specify where to look for compiled output inside your
20− project directory. Defaults to `output/`, relative to either the current
21− directory or the directory specified by `-d`.
22−- `--debug`: Enables some logging meant for debugging
23−- `--version`: Output psc-ide version
24−
25−## Issuing queries
26−
27−After you started the server you can start issuing requests using
28−`psc-ide-client`. Make sure you start by loading the modules before you try to
29−query them.
30−
31−`psc-ide-server` expects the build externs.purs inside the `output/` folder of
32−your project after running `pulp build` or `psc-make` respectively.
33−
34−(If you changed the port of the server you can change the port for
35−`psc-ide-client` by using the -p option accordingly)
36−
37−## Protocol
38−
39−For documentation about the protocol have a look at:
40−[PROTOCOL.md](PROTOCOL.md)
psc-publish/Main.hsdeleted−50
@@ -1,50 +0,0 @@
1−
2−module Main where
3−
4−import Data.Version (Version(..), showVersion)
5−import qualified Data.Aeson as A
6−import qualified Data.ByteString.Lazy.Char8 as BL
7−
8−import Options.Applicative hiding (str)
9−
10−import System.IO (hSetEncoding, stderr, stdout, utf8)
11−
12−import qualified Paths_purescript as Paths
13−import Language.PureScript.Publish
14−import Language.PureScript.Publish.ErrorsWarnings
15−
16−dryRun :: Parser Bool
17−dryRun = switch $
18− long "dry-run"
19− <> help "Produce no output, and don't require a tagged version to be checked out."
20−
21−dryRunOptions :: PublishOptions
22−dryRunOptions = defaultPublishOptions
23− { publishGetVersion = return dummyVersion
24− , publishWorkingTreeDirty = warn DirtyWorkingTree_Warn
25− }
26− where dummyVersion = ("0.0.0", Version [0,0,0] [])
27−
28−main :: IO ()
29−main = do
30− hSetEncoding stdout utf8
31− hSetEncoding stderr utf8
32− execParser opts >>= publish
33− where
34− opts = info (version <*> helper <*> dryRun) infoModList
35− infoModList = fullDesc <> headerInfo <> footerInfo
36− headerInfo = header "psc-publish - Generates documentation packages for upload to http://pursuit.purescript.org"
37− footerInfo = footer $ "psc-publish " ++ showVersion Paths.version
38−
39− version :: Parser (a -> a)
40− version = abortOption (InfoMsg (showVersion Paths.version)) $ long "version" <> help "Show the version number" <> hidden
41−
42−publish :: Bool -> IO ()
43−publish isDryRun =
44− if isDryRun
45− then do
46− _ <- unsafePreparePackage dryRunOptions
47− putStrLn "Dry run completed, no errors."
48− else do
49− pkg <- unsafePreparePackage defaultPublishOptions
50− BL.putStrLn (A.encode pkg)
psc/Main.hsdeleted−201
@@ -1,201 +0,0 @@
1−{-# LANGUAGE DataKinds #-}
2−{-# LANGUAGE FlexibleContexts #-}
3−{-# LANGUAGE RecordWildCards #-}
4−{-# LANGUAGE TupleSections #-}
5−
6−module Main where
7−
8−import Control.Applicative
9−import Control.Monad
10−import Control.Monad.Error.Class (MonadError(..))
11−import Control.Monad.Writer.Strict
12−
13−import Data.List (isSuffixOf, partition)
14−import Data.Version (showVersion)
15−import qualified Data.Map as M
16−import qualified Data.Aeson as A
17−import qualified Data.ByteString.Lazy as B
18−import qualified Data.ByteString.UTF8 as BU8
19−
20−import Options.Applicative as Opts
21−
22−import System.Exit (exitSuccess, exitFailure)
23−import System.IO (hSetEncoding, hPutStrLn, stdout, stderr, utf8)
24−import System.IO.UTF8
25−import System.FilePath.Glob (glob)
26−
27−import qualified Language.PureScript as P
28−import qualified Paths_purescript as Paths
29−
30−import Language.PureScript.Make
31−import Language.PureScript.Errors.JSON
32−
33−data PSCMakeOptions = PSCMakeOptions
34− { pscmInput :: [FilePath]
35− , pscmForeignInput :: [FilePath]
36− , pscmOutputDir :: FilePath
37− , pscmOpts :: P.Options
38− , pscmUsePrefix :: Bool
39− , pscmJSONErrors :: Bool
40− }
41−
42−data InputOptions = InputOptions
43− { ioInputFiles :: [FilePath]
44− }
45−
46−-- | Argumnets: verbose, use JSON, warnings, errors
47−printWarningsAndErrors :: Bool -> Bool -> P.MultipleErrors -> Either P.MultipleErrors a -> IO ()
48−printWarningsAndErrors verbose False warnings errors = do
49− when (P.nonEmpty warnings) $
50− hPutStrLn stderr (P.prettyPrintMultipleWarnings verbose warnings)
51− case errors of
52− Left errs -> do
53− hPutStrLn stderr (P.prettyPrintMultipleErrors verbose errs)
54− exitFailure
55− Right _ -> return ()
56−printWarningsAndErrors verbose True warnings errors = do
57− hPutStrLn stderr . BU8.toString . B.toStrict . A.encode $
58− JSONResult (toJSONErrors verbose P.Warning warnings)
59− (either (toJSONErrors verbose P.Error) (const []) errors)
60− either (const exitFailure) (const (return ())) errors
61−
62−compile :: PSCMakeOptions -> IO ()
63−compile PSCMakeOptions{..} = do
64− input <- globWarningOnMisses (unless pscmJSONErrors . warnFileTypeNotFound) pscmInput
65− when (null input && not pscmJSONErrors) $ do
66− hPutStrLn stderr "psc: No input files."
67− exitFailure
68− let (jsFiles, pursFiles) = partition (isSuffixOf ".js") input
69− moduleFiles <- readInput (InputOptions pursFiles)
70− inputForeign <- globWarningOnMisses (unless pscmJSONErrors . warnFileTypeNotFound) pscmForeignInput
71− foreignFiles <- forM (inputForeign ++ jsFiles) (\inFile -> (inFile,) <$> readUTF8File inFile)
72− (makeErrors, makeWarnings) <- runMake pscmOpts $ do
73− (ms, foreigns) <- parseInputs moduleFiles foreignFiles
74− let filePathMap = M.fromList $ map (\(fp, P.Module _ _ mn _ _) -> (mn, fp)) ms
75− makeActions = buildMakeActions pscmOutputDir filePathMap foreigns pscmUsePrefix
76− P.make makeActions (map snd ms)
77− printWarningsAndErrors (P.optionsVerboseErrors pscmOpts) pscmJSONErrors makeWarnings makeErrors
78− exitSuccess
79−
80−warnFileTypeNotFound :: String -> IO ()
81−warnFileTypeNotFound = hPutStrLn stderr . ("psc: No files found using pattern: " ++)
82−
83−globWarningOnMisses :: (String -> IO ()) -> [FilePath] -> IO [FilePath]
84−globWarningOnMisses warn = concatMapM globWithWarning
85− where
86− globWithWarning pattern = do
87− paths <- glob pattern
88− when (null paths) $ warn pattern
89− return paths
90− concatMapM f = liftM concat . mapM f
91−
92−readInput :: InputOptions -> IO [(Either P.RebuildPolicy FilePath, String)]
93−readInput InputOptions{..} = forM ioInputFiles $ \inFile -> (Right inFile, ) <$> readUTF8File inFile
94−
95−parseInputs :: (MonadError P.MultipleErrors m, MonadWriter P.MultipleErrors m)
96− => [(Either P.RebuildPolicy FilePath, String)]
97− -> [(FilePath, P.ForeignJS)]
98− -> m ([(Either P.RebuildPolicy FilePath, P.Module)], M.Map P.ModuleName FilePath)
99−parseInputs modules foreigns =
100− (,) <$> P.parseModulesFromFiles (either (const "") id) modules
101− <*> P.parseForeignModulesFromFiles foreigns
102−
103−inputFile :: Parser FilePath
104−inputFile = strArgument $
105− metavar "FILE"
106− <> help "The input .purs file(s)"
107−
108−inputForeignFile :: Parser FilePath
109−inputForeignFile = strOption $
110− short 'f'
111− <> long "ffi"
112− <> help "The input .js file(s) providing foreign import implementations"
113−
114−outputDirectory :: Parser FilePath
115−outputDirectory = strOption $
116− short 'o'
117− <> long "output"
118− <> Opts.value "output"
119− <> showDefault
120− <> help "The output directory"
121−
122−requirePath :: Parser (Maybe FilePath)
123−requirePath = optional $ strOption $
124− short 'r'
125− <> long "require-path"
126− <> help "The path prefix to use for require() calls in the generated JavaScript [deprecated]"
127−
128−noTco :: Parser Bool
129−noTco = switch $
130− long "no-tco"
131− <> help "Disable tail call optimizations"
132−
133−noMagicDo :: Parser Bool
134−noMagicDo = switch $
135− long "no-magic-do"
136− <> help "Disable the optimization that overloads the do keyword to generate efficient code specifically for the Eff monad"
137−
138−noOpts :: Parser Bool
139−noOpts = switch $
140− long "no-opts"
141− <> help "Skip the optimization phase"
142−
143−comments :: Parser Bool
144−comments = switch $
145− short 'c'
146− <> long "comments"
147− <> help "Include comments in the generated code"
148−
149−verboseErrors :: Parser Bool
150−verboseErrors = switch $
151− short 'v'
152− <> long "verbose-errors"
153− <> help "Display verbose error messages"
154−
155−noPrefix :: Parser Bool
156−noPrefix = switch $
157− short 'p'
158− <> long "no-prefix"
159− <> help "Do not include comment header"
160−
161−jsonErrors :: Parser Bool
162−jsonErrors = switch $
163− long "json-errors"
164− <> help "Print errors to stderr as JSON"
165−sourceMaps :: Parser Bool
166−sourceMaps = switch $
167− long "source-maps"
168− <> help "Generate source maps"
169−
170−
171−options :: Parser P.Options
172−options = P.Options <$> noTco
173− <*> noMagicDo
174− <*> pure Nothing
175− <*> noOpts
176− <*> verboseErrors
177− <*> (not <$> comments)
178− <*> requirePath
179− <*> sourceMaps
180−
181−pscMakeOptions :: Parser PSCMakeOptions
182−pscMakeOptions = PSCMakeOptions <$> many inputFile
183− <*> many inputForeignFile
184− <*> outputDirectory
185− <*> options
186− <*> (not <$> noPrefix)
187− <*> jsonErrors
188−
189−main :: IO ()
190−main = do
191− hSetEncoding stdout utf8
192− hSetEncoding stderr utf8
193− execParser opts >>= compile
194− where
195− opts = info (version <*> helper <*> pscMakeOptions) infoModList
196− infoModList = fullDesc <> headerInfo <> footerInfo
197− headerInfo = header "psc - Compiles PureScript to Javascript"
198− footerInfo = footer $ "psc " ++ showVersion Paths.version
199−
200− version :: Parser (a -> a)
201− version = abortOption (InfoMsg (showVersion Paths.version)) $ long "version" <> help "Show the version number" <> hidden
psci/PSCi.hsdeleted−372
@@ -1,372 +0,0 @@
1−{-# LANGUAGE DoAndIfThenElse #-}
2−{-# LANGUAGE GeneralizedNewtypeDeriving #-}
3−{-# LANGUAGE RecordWildCards #-}
4−{-# LANGUAGE TupleSections #-}
5−{-# LANGUAGE DataKinds #-}
6−
7−-- |
8−-- PureScript Compiler Interactive.
9−--
10−module PSCi (runPSCi) where
11−
12−import Prelude ()
13−import Prelude.Compat
14−
15−import Data.Foldable (traverse_)
16−import Data.List (intercalate, nub, sort, find)
17−import Data.Tuple (swap)
18−import qualified Data.Map as M
19−
20−import Control.Arrow (first)
21−import Control.Monad
22−import Control.Monad.Error.Class (MonadError(..))
23−import Control.Monad.Trans.Class
24−import Control.Monad.Trans.Except (ExceptT(), runExceptT)
25−import Control.Monad.Trans.State.Strict
26−import Control.Monad.IO.Class (liftIO)
27−import Control.Monad.Writer.Strict (Writer(), runWriter)
28−
29−import System.Console.Haskeline
30−import System.Directory (doesFileExist, getHomeDirectory, getCurrentDirectory)
31−import System.Exit
32−import System.FilePath ((</>))
33−import System.FilePath.Glob (glob)
34−import System.Process (readProcessWithExitCode)
35−import System.IO.Error (tryIOError)
36−
37−import qualified Language.PureScript as P
38−import qualified Language.PureScript.Names as N
39−
40−import PSCi.Completion (completion)
41−import PSCi.Parser (parseCommand)
42−import PSCi.Option
43−import PSCi.Types
44−import PSCi.Message
45−import PSCi.IO
46−import PSCi.Printer
47−import PSCi.Module
48−
49−-- |
50−-- PSCI monad
51−--
52−newtype PSCI a = PSCI { runPSCI :: InputT (StateT PSCiState IO) a } deriving (Functor, Applicative, Monad)
53−
54−psciIO :: IO a -> PSCI a
55−psciIO io = PSCI . lift $ lift io
56−
57−-- |
58−-- The runner
59−--
60−runPSCi :: IO ()
61−runPSCi = getOpt >>= loop
62−
63−-- |
64−-- The PSCI main loop.
65−--
66−loop :: PSCiOptions -> IO ()
67−loop PSCiOptions{..} = do
68− config <- loadUserConfig
69− inputFiles <- concat <$> traverse glob psciInputFile
70− foreignFiles <- concat <$> traverse glob psciForeignInputFiles
71− modulesOrFirstError <- loadAllModules inputFiles
72− case modulesOrFirstError of
73− Left errs -> putStrLn (P.prettyPrintMultipleErrors False errs) >> exitFailure
74− Right modules -> do
75− historyFilename <- getHistoryFilename
76− let settings = defaultSettings { historyFile = Just historyFilename }
77− foreignsOrError <- runMake $ do
78− foreignFilesContent <- forM foreignFiles (\inFile -> (inFile,) <$> makeIO (const (P.ErrorMessage [] $ P.CannotReadFile inFile)) (readFile inFile))
79− P.parseForeignModulesFromFiles foreignFilesContent
80− case foreignsOrError of
81− Left errs -> putStrLn (P.prettyPrintMultipleErrors False errs) >> exitFailure
82− Right foreigns ->
83− flip evalStateT (mkPSCiState [] modules foreigns [] psciInputNodeFlags) . runInputT (setComplete completion settings) $ do
84− outputStrLn prologueMessage
85− traverse_ (traverse_ (runPSCI . handleCommand)) config
86− modules' <- lift $ gets psciLoadedModules
87− unless (consoleIsDefined (map snd modules')) . outputStrLn $ unlines
88− [ "PSCi requires the purescript-console module to be installed."
89− , "For help getting started, visit http://wiki.purescript.org/PSCi"
90− ]
91− go
92− where
93− go :: InputT (StateT PSCiState IO) ()
94− go = do
95− c <- getCommand (not psciMultiLineMode)
96− case c of
97− Left err -> outputStrLn err >> go
98− Right Nothing -> go
99− Right (Just QuitPSCi) -> outputStrLn quitMessage
100− Right (Just c') -> do
101− handleInterrupt (outputStrLn "Interrupted.")
102− (withInterrupt (runPSCI (loadAllImportedModules >> handleCommand c')))
103− go
104−
105−-- Compile the module
106−
107−-- |
108−-- Load all modules, updating the application state
109−--
110−loadAllImportedModules :: PSCI ()
111−loadAllImportedModules = do
112− files <- PSCI . lift $ fmap psciImportedFilenames get
113− modulesOrFirstError <- psciIO $ loadAllModules files
114− case modulesOrFirstError of
115− Left errs -> PSCI $ printErrors errs
116− Right modules -> PSCI . lift . modify $ updateModules modules
117−
118−-- | This is different than the runMake in 'Language.PureScript.Make' in that it specifies the
119−-- options and ignores the warning messages.
120−runMake :: P.Make a -> IO (Either P.MultipleErrors a)
121−runMake mk = fst <$> P.runMake P.defaultOptions mk
122−
123−makeIO :: (IOError -> P.ErrorMessage) -> IO a -> P.Make a
124−makeIO f io = do
125− e <- liftIO $ tryIOError io
126− either (throwError . P.singleError . f) return e
127−
128−make :: PSCiState -> [P.Module] -> P.Make P.Environment
129−make st@PSCiState{..} ms = P.make actions' (map snd loadedModules ++ ms)
130− where
131− filePathMap = M.fromList $ (first P.getModuleName . swap) `map` allModules
132− actions = P.buildMakeActions modulesDir filePathMap psciForeignFiles False
133− actions' = actions { P.progress = const (return ()) }
134− loadedModules = psciLoadedModules st
135− allModules = map (first Right) loadedModules ++ map (Left P.RebuildAlways,) ms
136−
137−
138−-- Commands
139−
140−-- |
141−-- Parses the input and returns either a Metacommand, or an error as a string.
142−--
143−getCommand :: Bool -> InputT (StateT PSCiState IO) (Either String (Maybe Command))
144−getCommand singleLineMode = handleInterrupt (return (Right Nothing)) $ do
145− firstLine <- withInterrupt $ getInputLine "> "
146− case firstLine of
147− Nothing -> return (Right (Just QuitPSCi)) -- Ctrl-D when input is empty
148− Just "" -> return (Right Nothing)
149− Just s | singleLineMode || head s == ':' -> return .fmap Just $ parseCommand s
150− Just s -> fmap Just . parseCommand <$> go [s]
151− where
152− go :: [String] -> InputT (StateT PSCiState IO) String
153− go ls = maybe (return . unlines $ reverse ls) (go . (:ls)) =<< getInputLine " "
154−
155−-- |
156−-- Performs an action for each meta-command given, and also for expressions.
157−--
158−handleCommand :: Command -> PSCI ()
159−handleCommand (Expression val) = handleExpression val
160−handleCommand ShowHelp = PSCI $ outputStrLn helpMessage
161−handleCommand (Import im) = handleImport im
162−handleCommand (Decls l) = handleDecls l
163−handleCommand (LoadFile filePath) = PSCI $ whenFileExists filePath $ \absPath -> do
164− m <- lift . lift $ loadModule absPath
165− case m of
166− Left err -> outputStrLn err
167− Right mods -> lift $ modify (updateModules (map (absPath,) mods))
168−handleCommand (LoadForeign filePath) = PSCI $ whenFileExists filePath $ \absPath -> do
169− foreignsOrError <- lift . lift . runMake $ do
170− foreignFile <- makeIO (const (P.ErrorMessage [] $ P.CannotReadFile absPath)) (readFile absPath)
171− P.parseForeignModulesFromFiles [(absPath, foreignFile)]
172− case foreignsOrError of
173− Left err -> outputStrLn $ P.prettyPrintMultipleErrors False err
174− Right foreigns -> lift $ modify (updateForeignFiles foreigns)
175−handleCommand ResetState = do
176− PSCI . lift . modify $ \st ->
177− st { psciImportedModules = []
178− , psciLetBindings = []
179− }
180− loadAllImportedModules
181−handleCommand (TypeOf val) = handleTypeOf val
182−handleCommand (KindOf typ) = handleKindOf typ
183−handleCommand (BrowseModule moduleName) = handleBrowse moduleName
184−handleCommand (ShowInfo QueryLoaded) = handleShowLoadedModules
185−handleCommand (ShowInfo QueryImport) = handleShowImportedModules
186−handleCommand QuitPSCi = P.internalError "`handleCommand QuitPSCi` was called. This is a bug."
187−
188−
189−-- |
190−-- Takes a value expression and evaluates it with the current state.
191−--
192−handleExpression :: P.Expr -> PSCI ()
193−handleExpression val = do
194− st <- PSCI $ lift get
195− let m = createTemporaryModule True st val
196− let nodeArgs = psciNodeFlags st ++ [indexFile]
197− e <- psciIO . runMake $ make st [supportModule, m]
198− case e of
199− Left errs -> PSCI $ printErrors errs
200− Right _ -> do
201− psciIO $ writeFile indexFile "require('$PSCI')['$main']();"
202− process <- psciIO findNodeProcess
203− result <- psciIO $ traverse (\node -> readProcessWithExitCode node nodeArgs "") process
204− case result of
205− Just (ExitSuccess, out, _) -> PSCI $ outputStrLn out
206− Just (ExitFailure _, _, err) -> PSCI $ outputStrLn err
207− Nothing -> PSCI $ outputStrLn "Couldn't find node.js"
208−
209−-- |
210−-- Takes a list of declarations and updates the environment, then run a make. If the declaration fails,
211−-- restore the original environment.
212−--
213−handleDecls :: [P.Declaration] -> PSCI ()
214−handleDecls ds = do
215− st <- PSCI $ lift get
216− let st' = updateLets ds st
217− let m = createTemporaryModule False st' (P.Literal (P.ObjectLiteral []))
218− e <- psciIO . runMake $ make st' [m]
219− case e of
220− Left err -> PSCI $ printErrors err
221− Right _ -> PSCI $ lift (put st')
222−
223−-- |
224−-- Show actual loaded modules in psci.
225−--
226−handleShowLoadedModules :: PSCI ()
227−handleShowLoadedModules = do
228− loadedModules <- PSCI $ lift $ gets psciLoadedModules
229− psciIO $ readModules loadedModules >>= putStrLn
230− return ()
231− where readModules = return . unlines . sort . nub . map toModuleName
232− toModuleName = N.runModuleName . (\ (P.Module _ _ mdName _ _) -> mdName) . snd
233−
234−-- |
235−-- Show the imported modules in psci.
236−--
237−handleShowImportedModules :: PSCI ()
238−handleShowImportedModules = do
239− PSCiState { psciImportedModules = importedModules } <- PSCI $ lift get
240− psciIO $ showModules importedModules >>= putStrLn
241− return ()
242− where
243− showModules = return . unlines . sort . map showModule
244− showModule (mn, declType, asQ) =
245− "import " ++ case asQ of
246− Just mn' -> "qualified " ++ N.runModuleName mn ++ " as " ++ N.runModuleName mn'
247− Nothing -> N.runModuleName mn ++ " " ++ showDeclType declType
248−
249− showDeclType P.Implicit = ""
250− showDeclType (P.Explicit refs) = refsList refs
251− showDeclType (P.Hiding refs) = " hiding " ++ refsList refs
252− refsList refs = " (" ++ commaList (map showRef refs) ++ ")"
253−
254− showRef :: P.DeclarationRef -> String
255− showRef (P.TypeRef pn dctors) = N.runProperName pn ++ "(" ++ maybe ".." (commaList . map N.runProperName) dctors ++ ")"
256− showRef (P.TypeOpRef ident) = "type (" ++ N.runIdent ident ++ ")"
257− showRef (P.ValueRef ident) = N.runIdent ident
258− showRef (P.TypeClassRef pn) = "class " ++ N.runProperName pn
259− showRef (P.ProperRef pn) = pn
260− showRef (P.TypeInstanceRef ident) = N.runIdent ident
261− showRef (P.ModuleRef name) = "module " ++ N.runModuleName name
262− showRef (P.PositionedDeclarationRef _ _ ref) = showRef ref
263−
264− commaList :: [String] -> String
265− commaList = intercalate ", "
266−
267−-- |
268−-- Imports a module, preserving the initial state on failure.
269−--
270−handleImport :: ImportedModule -> PSCI ()
271−handleImport im = do
272− st <- updateImportedModules im <$> PSCI (lift get)
273− let m = createTemporaryModuleForImports st
274− e <- psciIO . runMake $ make st [m]
275− case e of
276− Left errs -> PSCI $ printErrors errs
277− Right _ -> do
278− PSCI $ lift $ put st
279− return ()
280−
281−-- |
282−-- Takes a value and prints its type
283−--
284−handleTypeOf :: P.Expr -> PSCI ()
285−handleTypeOf val = do
286− st <- PSCI $ lift get
287− let m = createTemporaryModule False st val
288− e <- psciIO . runMake $ make st [m]
289− case e of
290− Left errs -> PSCI $ printErrors errs
291− Right env' ->
292− case M.lookup (P.ModuleName [P.ProperName "$PSCI"], P.Ident "it") (P.names env') of
293− Just (ty, _, _) -> PSCI . outputStrLn . P.prettyPrintType $ ty
294− Nothing -> PSCI $ outputStrLn "Could not find type"
295−
296−-- |
297−-- Browse a module and displays its signature (if module exists).
298−--
299−handleBrowse :: P.ModuleName -> PSCI ()
300−handleBrowse moduleName = do
301− st <- PSCI $ lift get
302− env <- psciIO . runMake $ make st []
303− case env of
304− Left errs -> PSCI $ printErrors errs
305− Right env' ->
306− if isModInEnv moduleName st
307− then PSCI $ printModuleSignatures moduleName env'
308− else case lookupUnQualifiedModName moduleName st of
309− Just unQualifiedName ->
310− if isModInEnv unQualifiedName st
311− then PSCI $ printModuleSignatures unQualifiedName env'
312− else failNotInEnv moduleName
313− Nothing ->
314− failNotInEnv moduleName
315− where
316− isModInEnv modName =
317− any ((== modName) . P.getModuleName . snd) . psciLoadedModules
318− failNotInEnv modName =
319− PSCI $ outputStrLn $ "Module '" ++ N.runModuleName modName ++ "' is not valid."
320− lookupUnQualifiedModName quaModName st =
321− (\(modName,_,_) -> modName) <$> find ( \(_, _, mayQuaName) -> mayQuaName == Just quaModName) (psciImportedModules st)
322−
323−-- |
324−-- Takes a value and prints its kind
325−--
326−handleKindOf :: P.Type -> PSCI ()
327−handleKindOf typ = do
328− st <- PSCI $ lift get
329− let m = createTemporaryModuleForKind st typ
330− mName = P.ModuleName [P.ProperName "$PSCI"]
331− e <- psciIO . runMake $ make st [m]
332− case e of
333− Left errs -> PSCI $ printErrors errs
334− Right env' ->
335− case M.lookup (P.Qualified (Just mName) $ P.ProperName "IT") (P.typeSynonyms env') of
336− Just (_, typ') -> do
337− let chk = (P.emptyCheckState env') { P.checkCurrentModule = Just mName }
338− k = check (P.kindOf typ') chk
339−
340− check :: StateT P.CheckState (ExceptT P.MultipleErrors (Writer P.MultipleErrors)) a -> P.CheckState -> Either P.MultipleErrors (a, P.CheckState)
341− check sew = fst . runWriter . runExceptT . runStateT sew
342− case k of
343− Left errStack -> PSCI . outputStrLn . P.prettyPrintMultipleErrors False $ errStack
344− Right (kind, _) -> PSCI . outputStrLn . P.prettyPrintKind $ kind
345− Nothing -> PSCI $ outputStrLn "Could not find kind"
346−
347−-- Misc
348−
349−-- |
350−-- Attempts to read initial commands from '.psci' in the present working
351−-- directory then the user's home
352−--
353−loadUserConfig :: IO (Maybe [Command])
354−loadUserConfig = onFirstFileMatching readCommands pathGetters
355− where
356− pathGetters = [getCurrentDirectory, getHomeDirectory]
357− readCommands :: IO FilePath -> IO (Maybe [Command])
358− readCommands path = do
359− configFile <- (</> ".psci") <$> path
360− exists <- doesFileExist configFile
361− if exists
362− then do
363− ls <- lines <$> readFile configFile
364− case traverse parseCommand ls of
365− Left err -> print err >> exitFailure
366− Right cs -> return $ Just cs
367− else
368− return Nothing
369−
370−-- | Checks if the Console module is defined
371−consoleIsDefined :: [P.Module] -> Bool
372−consoleIsDefined = any ((== P.ModuleName (map P.ProperName [ "Control", "Monad", "Eff", "Console" ])) . P.getModuleName)
psci/PSCi/Completion.hsdeleted−226
@@ -1,226 +0,0 @@
1−{-# LANGUAGE DataKinds #-}
2−
3−module PSCi.Completion where
4−
5−import Prelude ()
6−import Prelude.Compat
7−
8−import Data.Maybe (mapMaybe)
9−import Data.List (nub, nubBy, sortBy, isPrefixOf, stripPrefix)
10−import Data.Char (isUpper)
11−import Data.Function (on)
12−
13−import Control.Arrow (second)
14−import Control.Monad.Trans.Reader (asks, runReaderT, ReaderT)
15−import Control.Monad.Trans.State.Strict
16−
17−import System.Console.Haskeline
18−
19−import qualified Language.PureScript as P
20−import qualified Language.PureScript.Names as N
21−
22−import qualified PSCi.Directive as D
23−import PSCi.Types
24−
25−-- Completions may read the state, but not modify it.
26−type CompletionM = ReaderT PSCiState IO
27−
28−-- Lift a `CompletionM` action to a `StateT PSCiState IO` one.
29−liftCompletionM :: CompletionM a -> StateT PSCiState IO a
30−liftCompletionM act = StateT (\s -> (\a -> (a, s)) <$> runReaderT act s)
31−
32−-- Haskeline completions
33−
34−data CompletionContext
35− = CtxDirective String
36− | CtxFilePath String
37− | CtxModule
38− | CtxIdentifier
39− | CtxType
40− | CtxFixed String
41− deriving (Show, Read)
42−
43−-- |
44−-- Loads module, function, and file completions.
45−--
46−completion :: CompletionFunc (StateT PSCiState IO)
47−completion = liftCompletionM . completion'
48−
49−completion' :: CompletionFunc CompletionM
50−completion' = completeWordWithPrev Nothing " \t\n\r" findCompletions
51−
52−-- |
53−-- Decide what kind of completion we need based on input. This function expects
54−-- a list of complete words (to the left of the cursor) as the first argument,
55−-- and the current word as the second argument.
56−completionContext :: [String] -> String -> [CompletionContext]
57−completionContext [] _ = [CtxDirective "", CtxIdentifier, CtxFixed "import"]
58−completionContext ws w | headSatisfies (":" `isPrefixOf`) ws = completeDirective ws w
59−completionContext ws w | headSatisfies (== "import") ws = completeImport ws w
60−completionContext _ _ = [CtxIdentifier]
61−
62−completeDirective :: [String] -> String -> [CompletionContext]
63−completeDirective ws w =
64− case ws of
65− [] -> [CtxDirective w]
66− [dir] -> case D.directivesFor <$> stripPrefix ":" dir of
67− -- only offer completions if the directive is unambiguous
68− Just [dir'] -> directiveArg w dir'
69− _ -> []
70−
71− -- All directives take exactly one argument. If we haven't yet matched,
72− -- that means one argument has already been supplied. So don't complete
73− -- any others.
74− _ -> []
75−
76−directiveArg :: String -> Directive -> [CompletionContext]
77−directiveArg _ Browse = [CtxModule]
78−directiveArg w Load = [CtxFilePath w]
79−directiveArg w Foreign = [CtxFilePath w]
80−directiveArg _ Quit = []
81−directiveArg _ Reset = []
82−directiveArg _ Help = []
83−directiveArg _ Show = map CtxFixed replQueryStrings
84−directiveArg _ Type = [CtxIdentifier]
85−directiveArg _ Kind = [CtxType]
86−
87−completeImport :: [String] -> String -> [CompletionContext]
88−completeImport ws w' =
89− case (ws, w') of
90− (["import"], w) | headSatisfies isUpper w -> [CtxModule]
91− (["import"], _) -> [CtxModule, CtxFixed "qualified"]
92− (["import", "qualified"], _) -> [CtxModule]
93− _ -> []
94−
95−headSatisfies :: (a -> Bool) -> [a] -> Bool
96−headSatisfies p str =
97− case str of
98− (c:_) -> p c
99− _ -> False
100−
101−-- | Callback for Haskeline's `completeWordWithPrev`.
102−-- Expects:
103−-- * Line contents to the left of the word, reversed
104−-- * Word to be completed
105−findCompletions :: String -> String -> CompletionM [Completion]
106−findCompletions prev word = do
107− let ctx = completionContext (words (reverse prev)) word
108− completions <- concat <$> traverse getCompletions ctx
109− return $ sortBy directivesFirst completions
110− where
111− getCompletions :: CompletionContext -> CompletionM [Completion]
112− getCompletions = fmap (mapMaybe (either (prefixedBy word) Just)) . getCompletion
113−
114− prefixedBy :: String -> String -> Maybe Completion
115− prefixedBy w cand = if w `isPrefixOf` cand
116− then Just (simpleCompletion cand)
117− else Nothing
118−
119−getCompletion :: CompletionContext -> CompletionM [Either String Completion]
120−getCompletion ctx =
121− case ctx of
122− CtxFilePath f -> map Right <$> listFiles f
123− CtxModule -> map Left <$> getModuleNames
124− CtxIdentifier -> map Left <$> ((++) <$> getIdentNames <*> getDctorNames)
125− CtxType -> map Left <$> getTypeNames
126− CtxFixed str -> return [Left str]
127− CtxDirective d -> return (map Left (completeDirectives d))
128−
129− where
130− completeDirectives :: String -> [String]
131− completeDirectives = map (':' :) . D.directiveStringsFor
132−
133−
134−getLoadedModules :: CompletionM [P.Module]
135−getLoadedModules = asks (map snd . psciLoadedModules)
136−
137−getImportedModules :: CompletionM [ImportedModule]
138−getImportedModules = asks psciImportedModules
139−
140−getModuleNames :: CompletionM [String]
141−getModuleNames = moduleNames <$> getLoadedModules
142−
143−mapLoadedModulesAndQualify :: (a -> String) -> (P.Module -> [(a, P.Declaration)]) -> CompletionM [String]
144−mapLoadedModulesAndQualify sho f = do
145− ms <- getLoadedModules
146− let argPairs = do m <- ms
147− fm <- f m
148− return (m, fm)
149− concat <$> traverse (uncurry (getAllQualifications sho)) argPairs
150−
151−getIdentNames :: CompletionM [String]
152−getIdentNames = mapLoadedModulesAndQualify P.showIdent identNames
153−
154−getDctorNames :: CompletionM [String]
155−getDctorNames = mapLoadedModulesAndQualify P.runProperName dctorNames
156−
157−getTypeNames :: CompletionM [String]
158−getTypeNames = mapLoadedModulesAndQualify P.runProperName typeDecls
159−
160−-- | Given a module and a declaration in that module, return all possible ways
161−-- it could have been referenced given the current PSCiState - including fully
162−-- qualified, qualified using an alias, and unqualified.
163−getAllQualifications :: (a -> String) -> P.Module -> (a, P.Declaration) -> CompletionM [String]
164−getAllQualifications sho m (declName, decl) = do
165− imports <- getAllImportsOf m
166− let fullyQualified = qualifyWith (Just (P.getModuleName m))
167− let otherQuals = nub (concatMap qualificationsUsing imports)
168− return $ fullyQualified : otherQuals
169− where
170− qualifyWith mMod = P.showQualified sho (P.Qualified mMod declName)
171− referencedBy refs = P.isExported (Just refs) decl
172−
173− qualificationsUsing (_, importType, asQ') =
174− let q = qualifyWith asQ'
175− in case importType of
176− P.Implicit -> [q]
177− P.Explicit refs -> [q | referencedBy refs]
178− P.Hiding refs -> [q | not $ referencedBy refs]
179−
180−
181−-- | Returns all the ImportedModule values referring to imports of a particular
182−-- module.
183−getAllImportsOf :: P.Module -> CompletionM [ImportedModule]
184−getAllImportsOf = asks . allImportsOf
185−
186−nubOnFst :: Eq a => [(a, b)] -> [(a, b)]
187−nubOnFst = nubBy ((==) `on` fst)
188−
189−typeDecls :: P.Module -> [(N.ProperName 'N.TypeName, P.Declaration)]
190−typeDecls = mapMaybe getTypeName . filter P.isDataDecl . P.exportedDeclarations
191− where
192− getTypeName :: P.Declaration -> Maybe (N.ProperName 'N.TypeName, P.Declaration)
193− getTypeName d@(P.TypeSynonymDeclaration name _ _) = Just (name, d)
194− getTypeName d@(P.DataDeclaration _ name _ _) = Just (name, d)
195− getTypeName (P.PositionedDeclaration _ _ d) = getTypeName d
196− getTypeName _ = Nothing
197−
198−identNames :: P.Module -> [(N.Ident, P.Declaration)]
199−identNames = nubOnFst . concatMap getDeclNames . P.exportedDeclarations
200− where
201− getDeclNames :: P.Declaration -> [(P.Ident, P.Declaration)]
202− getDeclNames d@(P.ValueDeclaration ident _ _ _) = [(ident, d)]
203− getDeclNames d@(P.TypeDeclaration ident _ ) = [(ident, d)]
204− getDeclNames d@(P.ExternDeclaration ident _) = [(ident, d)]
205− getDeclNames d@(P.TypeClassDeclaration _ _ _ ds) = map (second (const d)) $ concatMap getDeclNames ds
206− getDeclNames (P.PositionedDeclaration _ _ d) = getDeclNames d
207− getDeclNames _ = []
208−
209−dctorNames :: P.Module -> [(N.ProperName 'N.ConstructorName, P.Declaration)]
210−dctorNames = nubOnFst . concatMap go . P.exportedDeclarations
211− where
212− go :: P.Declaration -> [(N.ProperName 'N.ConstructorName, P.Declaration)]
213− go decl@(P.DataDeclaration _ _ _ ctors) = map (\n -> (n, decl)) (map fst ctors)
214− go (P.PositionedDeclaration _ _ d) = go d
215− go _ = []
216−
217−moduleNames :: [P.Module] -> [String]
218−moduleNames ms = nub [P.runModuleName moduleName | P.Module _ _ moduleName _ _ <- ms]
219−
220−directivesFirst :: Completion -> Completion -> Ordering
221−directivesFirst (Completion _ d1 _) (Completion _ d2 _) = go d1 d2
222− where
223− go (':' : xs) (':' : ys) = compare xs ys
224− go (':' : _) _ = LT
225− go _ (':' : _) = GT
226− go xs ys = compare xs ys
psci/PSCi/Directive.hsdeleted−119
@@ -1,119 +0,0 @@
1−-----------------------------------------------------------------------------
2−--
3−-- Module : Directive
4−-- Copyright :
5−-- License : MIT
6−--
7−-- Maintainer :
8−-- Stability : experimental
9−-- Portability :
10−--
11−-- |
12−-- Directives for PSCI.
13−--
14−-----------------------------------------------------------------------------
15−
16−module PSCi.Directive where
17−
18−import Prelude ()
19−import Prelude.Compat
20−
21−
22−import Data.Maybe (fromJust, listToMaybe)
23−import Data.List (isPrefixOf)
24−import Data.Tuple (swap)
25−
26−import PSCi.Types
27−
28−-- |
29−-- List of all avaliable directives.
30−--
31−directives :: [Directive]
32−directives = map fst directiveStrings
33−
34−-- |
35−-- A mapping of directives to the different strings that can be used to invoke
36−-- them.
37−--
38−directiveStrings :: [(Directive, [String])]
39−directiveStrings =
40− [ (Help , ["?", "help"])
41− , (Quit , ["quit"])
42− , (Reset , ["reset"])
43− , (Browse , ["browse"])
44− , (Load , ["load", "module"])
45− , (Foreign, ["foreign"])
46− , (Type , ["type"])
47− , (Kind , ["kind"])
48− , (Show , ["show"])
49− ]
50−
51−-- |
52−-- Like directiveStrings, but the other way around.
53−--
54−directiveStrings' :: [(String, Directive)]
55−directiveStrings' = concatMap go directiveStrings
56− where
57− go (dir, strs) = map (\s -> (s, dir)) strs
58−
59−-- |
60−-- List of all directive strings.
61−--
62−strings :: [String]
63−strings = concatMap snd directiveStrings
64−
65−-- |
66−-- Returns all possible string representations of a directive.
67−--
68−stringsFor :: Directive -> [String]
69−stringsFor d = fromJust (lookup d directiveStrings)
70−
71−-- |
72−-- Returns the default string representation of a directive.
73−--
74−stringFor :: Directive -> String
75−stringFor = head . stringsFor
76−
77−-- |
78−-- Returns the list of directives which could be expanded from the string
79−-- argument, together with the string alias that matched.
80−--
81−directivesFor' :: String -> [(Directive, String)]
82−directivesFor' str = go directiveStrings'
83− where
84− go = map swap . filter ((str `isPrefixOf`) . fst)
85−
86−directivesFor :: String -> [Directive]
87−directivesFor = map fst . directivesFor'
88−
89−directiveStringsFor :: String -> [String]
90−directiveStringsFor = map snd . directivesFor'
91−
92−parseDirective :: String -> Maybe Directive
93−parseDirective = listToMaybe . directivesFor
94−
95−-- |
96−-- True if the given directive takes an argument, false otherwise.
97−hasArgument :: Directive -> Bool
98−hasArgument Help = False
99−hasArgument Quit = False
100−hasArgument Reset = False
101−hasArgument _ = True
102−
103−-- |
104−-- The help menu.
105−--
106−help :: [(Directive, String, String)]
107−help =
108− [ (Help, "", "Show this help menu")
109− , (Quit, "", "Quit PSCi")
110− , (Reset, "", "Discard all imported modules and declared bindings")
111− , (Browse, "<module>", "See all functions in <module>")
112− , (Load, "<file>", "Load <file> for importing")
113− , (Foreign, "<file>", "Load foreign module <file>")
114− , (Type, "<expr>", "Show the type of <expr>")
115− , (Kind, "<type>", "Show the kind of <type>")
116− , (Show, "import", "Show all imported modules")
117− , (Show, "loaded", "Show all loaded modules")
118− ]
119−
psci/PSCi/IO.hsdeleted−68
@@ -1,68 +0,0 @@
1−-----------------------------------------------------------------------------
2−--
3−-- Module : IO
4−-- Copyright : (c) 2013-14 Phil Freeman, (c) 2014 Gary Burgess, and other contributors
5−-- License : MIT
6−--
7−-- Maintainer : Phil Freeman <paf31@cantab.net>
8−-- Stability : experimental
9−-- Portability :
10−--
11−-- |
12−--
13−-----------------------------------------------------------------------------
14−
15−module PSCi.IO where
16−
17−import Prelude ()
18−import Prelude.Compat
19−
20−import System.Directory (createDirectoryIfMissing, getHomeDirectory, findExecutable, doesFileExist)
21−import System.FilePath (takeDirectory, (</>), isPathSeparator)
22−import Control.Monad.Trans.Maybe (MaybeT(..), runMaybeT)
23−import Control.Monad (msum)
24−import Control.Monad.IO.Class (MonadIO, liftIO)
25−import System.Console.Haskeline (outputStrLn, InputT)
26−
27−mkdirp :: FilePath -> IO ()
28−mkdirp = createDirectoryIfMissing True . takeDirectory
29−
30−-- File helpers
31−
32−onFirstFileMatching :: Monad m => (b -> m (Maybe a)) -> [b] -> m (Maybe a)
33−onFirstFileMatching f pathVariants = runMaybeT . msum $ map (MaybeT . f) pathVariants
34−
35−-- |
36−-- Locates the node executable.
37−-- Checks for either @nodejs@ or @node@.
38−--
39−findNodeProcess :: IO (Maybe String)
40−findNodeProcess = onFirstFileMatching findExecutable names
41− where names = ["nodejs", "node"]
42−
43−-- |
44−-- Grabs the filename where the history is stored.
45−--
46−getHistoryFilename :: IO FilePath
47−getHistoryFilename = do
48− home <- getHomeDirectory
49− let filename = home </> ".purescript" </> "psci_history"
50− mkdirp filename
51− return filename
52−
53−
54−-- |
55−-- Expands tilde in path.
56−--
57−expandTilde :: FilePath -> IO FilePath
58−expandTilde ('~':p:rest) | isPathSeparator p = (</> rest) <$> getHomeDirectory
59−expandTilde p = return p
60−
61−
62−whenFileExists :: MonadIO m => FilePath -> (FilePath -> InputT m ()) -> InputT m ()
63−whenFileExists filePath f = do
64− absPath <- liftIO $ expandTilde filePath
65− exists <- liftIO $ doesFileExist absPath
66− if exists
67− then f absPath
68− else outputStrLn $ "Couldn't locate: " ++ filePath
psci/PSCi/Message.hsdeleted−53
@@ -1,53 +0,0 @@
1−module PSCi.Message where
2−
3−
4−import Data.List (intercalate)
5−import qualified PSCi.Directive as D
6−import PSCi.Types
7−
8−-- Messages
9−
10−-- |
11−-- The help message.
12−--
13−helpMessage :: String
14−helpMessage = "The following commands are available:\n\n " ++
15− intercalate "\n " (map line D.help) ++
16− "\n\n" ++ extraHelp
17− where
18− line :: (Directive, String, String) -> String
19− line (dir, arg, desc) =
20− let cmd = ':' : D.stringFor dir
21− in unwords [ cmd
22− , replicate (11 - length cmd) ' '
23− , arg
24− , replicate (11 - length arg) ' '
25− , desc
26− ]
27−
28− extraHelp =
29− "Further information is available on the PureScript wiki:\n" ++
30− " --> https://github.com/purescript/purescript/wiki/psci"
31−
32−
33−-- |
34−-- The welcome prologue.
35−--
36−prologueMessage :: String
37−prologueMessage = intercalate "\n"
38− [ " ____ ____ _ _ "
39− , "| _ \\ _ _ _ __ ___/ ___| ___ _ __(_)_ __ | |_ "
40− , "| |_) | | | | '__/ _ \\___ \\ / __| '__| | '_ \\| __|"
41− , "| __/| |_| | | | __/___) | (__| | | | |_) | |_ "
42− , "|_| \\__,_|_| \\___|____/ \\___|_| |_| .__/ \\__|"
43− , " |_| "
44− , ""
45− , ":? shows help"
46− ]
47−
48−-- |
49−-- The quit message.
50−--
51−quitMessage :: String
52−quitMessage = "See ya!"
53−
psci/PSCi/Module.hsdeleted−106
@@ -1,106 +0,0 @@
1−module PSCi.Module where
2−
3−import Prelude ()
4−import Prelude.Compat
5−
6−import qualified Language.PureScript as P
7−import PSCi.Types
8−import System.FilePath (pathSeparator)
9−import Control.Monad
10−
11−-- | The name of the PSCI support module
12−supportModuleName :: P.ModuleName
13−supportModuleName = P.ModuleName [P.ProperName "$PSCI", P.ProperName "Support"]
14−
15−-- | Support module, contains code to evaluate terms
16−supportModule :: P.Module
17−supportModule =
18− case P.parseModulesFromFiles id [("", code)] of
19− Right [(_, P.Module ss cs _ ds exps)] -> P.Module ss cs supportModuleName ds exps
20− _ -> P.internalError "Support module could not be parsed"
21− where
22− code :: String
23− code = unlines
24− [ "module S where"
25− , ""
26− , "import Prelude"
27− , "import Control.Monad.Eff"
28− , "import Control.Monad.Eff.Console"
29− , "import Control.Monad.Eff.Unsafe"
30− , ""
31− , "class Eval a where"
32− , " eval :: a -> Eff (console :: CONSOLE) Unit"
33− , ""
34− , "instance evalShow :: (Show a) => Eval a where"
35− , " eval = print"
36− , ""
37− , "instance evalEff :: (Eval a) => Eval (Eff eff a) where"
38− , " eval x = unsafeInterleaveEff x >>= eval"
39− ]
40−
41−-- Module Management
42−
43−-- |
44−-- Loads a file for use with imports.
45−--
46−loadModule :: FilePath -> IO (Either String [P.Module])
47−loadModule filename = do
48− content <- readFile filename
49− return $ either (Left . P.prettyPrintMultipleErrors False) (Right . map snd) $ P.parseModulesFromFiles id [(filename, content)]
50−
51−-- |
52−-- Load all modules.
53−--
54−loadAllModules :: [FilePath] -> IO (Either P.MultipleErrors [(FilePath, P.Module)])
55−loadAllModules files = do
56− filesAndContent <- forM files $ \filename -> do
57− content <- readFile filename
58− return (filename, content)
59− return $ P.parseModulesFromFiles id filesAndContent
60−
61−
62−-- |
63−-- Makes a volatile module to execute the current expression.
64−--
65−createTemporaryModule :: Bool -> PSCiState -> P.Expr -> P.Module
66−createTemporaryModule exec PSCiState{psciImportedModules = imports, psciLetBindings = lets} val =
67− let
68− moduleName = P.ModuleName [P.ProperName "$PSCI"]
69− trace = P.Var (P.Qualified (Just supportModuleName) (P.Ident "eval"))
70− mainValue = P.App trace (P.Var (P.Qualified Nothing (P.Ident "it")))
71− itDecl = P.ValueDeclaration (P.Ident "it") P.Public [] $ Right val
72− mainDecl = P.ValueDeclaration (P.Ident "$main") P.Public [] $ Right mainValue
73− decls = if exec then [itDecl, mainDecl] else [itDecl]
74− in
75− P.Module (P.internalModuleSourceSpan "<internal>") [] moduleName ((importDecl `map` imports) ++ lets ++ decls) Nothing
76−
77−
78−-- |
79−-- Makes a volatile module to hold a non-qualified type synonym for a fully-qualified data type declaration.
80−--
81−createTemporaryModuleForKind :: PSCiState -> P.Type -> P.Module
82−createTemporaryModuleForKind PSCiState{psciImportedModules = imports, psciLetBindings = lets} typ =
83− let
84− moduleName = P.ModuleName [P.ProperName "$PSCI"]
85− itDecl = P.TypeSynonymDeclaration (P.ProperName "IT") [] typ
86− in
87− P.Module (P.internalModuleSourceSpan "<internal>") [] moduleName ((importDecl `map` imports) ++ lets ++ [itDecl]) Nothing
88−
89−-- |
90−-- Makes a volatile module to execute the current imports.
91−--
92−createTemporaryModuleForImports :: PSCiState -> P.Module
93−createTemporaryModuleForImports PSCiState{psciImportedModules = imports} =
94− let
95− moduleName = P.ModuleName [P.ProperName "$PSCI"]
96− in
97− P.Module (P.internalModuleSourceSpan "<internal>") [] moduleName (importDecl `map` imports) Nothing
98−
99−importDecl :: ImportedModule -> P.Declaration
100−importDecl (mn, declType, asQ) = P.ImportDeclaration mn declType asQ False
101−
102−indexFile :: FilePath
103−indexFile = ".psci_modules" ++ pathSeparator : "index.js"
104−
105−modulesDir :: FilePath
106−modulesDir = ".psci_modules" ++ pathSeparator : "node_modules"
psci/PSCi/Option.hsdeleted−57
@@ -1,57 +0,0 @@
1−module PSCi.Option (
2− getOpt
3−) where
4−
5−import Prelude ()
6−import Prelude.Compat
7−
8−import Options.Applicative as Opts
9−import Data.Version (showVersion)
10−
11−import PSCi.Types
12−import qualified Paths_purescript as Paths
13−
14−-- Parse Command line option
15−
16−multiLineMode :: Parser Bool
17−multiLineMode = switch $
18− long "multi-line-mode"
19− <> short 'm'
20− <> Opts.help "Run in multi-line mode (use ^D to terminate commands)"
21−
22−inputFile :: Parser FilePath
23−inputFile = strArgument $
24− metavar "FILE"
25− <> Opts.help "Optional .purs files to load on start"
26−
27−inputForeignFile :: Parser FilePath
28−inputForeignFile = strOption $
29− short 'f'
30− <> long "ffi"
31− <> help "The input .js file(s) providing foreign import implementations"
32−
33−nodeFlagsFlag :: Parser [String]
34−nodeFlagsFlag = option parser $
35− long "node-opts"
36− <> metavar "NODE_OPTS"
37− <> value []
38− <> Opts.help "Flags to pass to node, separated by spaces"
39− where
40− parser = words <$> str
41−
42−psciOptions :: Parser PSCiOptions
43−psciOptions = PSCiOptions <$> multiLineMode
44− <*> many inputFile
45− <*> many inputForeignFile
46− <*> nodeFlagsFlag
47−
48−version :: Parser (a -> a)
49−version = abortOption (InfoMsg (showVersion Paths.version)) $ long "version" <> Opts.help "Show the version number" <> hidden
50−
51−getOpt :: IO PSCiOptions
52−getOpt = execParser opts
53− where
54− opts = info (version <*> helper <*> psciOptions) infoModList
55− infoModList = fullDesc <> headerInfo <> footerInfo
56− headerInfo = header "psci - Interactive mode for PureScript"
57− footerInfo = footer $ "psci " ++ showVersion Paths.version
psci/PSCi/Parser.hsdeleted−140
@@ -1,140 +0,0 @@
1−-----------------------------------------------------------------------------
2−--
3−-- Module : Parser
4−-- Copyright : (c) Phil Freeman 2014
5−-- License : MIT
6−--
7−-- Maintainer : Phil Freeman <paf31@cantab.net>
8−-- Stability : experimental
9−-- Portability :
10−--
11−-- |
12−-- Parser for PSCI.
13−--
14−-----------------------------------------------------------------------------
15−
16−module PSCi.Parser
17− ( parseCommand
18− ) where
19−
20−import Prelude ()
21−import Prelude.Compat hiding (lex)
22−
23−import Data.Char (isSpace)
24−import Data.List (intercalate)
25−
26−import Text.Parsec hiding ((<|>))
27−
28−import qualified Language.PureScript as P
29−import Language.PureScript.Parser.Common (mark, same)
30−
31−import qualified PSCi.Directive as D
32−import PSCi.Types
33−
34−-- |
35−-- Parses PSCI metacommands or expressions input from the user.
36−--
37−parseCommand :: String -> Either String Command
38−parseCommand cmdString =
39− case cmdString of
40− (':' : cmd) -> parseDirective cmd
41− _ -> parseRest psciCommand cmdString
42−
43−parseRest :: P.TokenParser a -> String -> Either String a
44−parseRest p s = either (Left . show) Right $ do
45− ts <- P.lex "" s
46− P.runTokenParser "" (p <* eof) ts
47−
48−psciCommand :: P.TokenParser Command
49−psciCommand = choice (map try parsers)
50− where
51− parsers =
52− [ psciLet
53− , psciImport
54− , psciOtherDeclaration
55− , psciExpression
56− ]
57−
58−trim :: String -> String
59−trim = trimEnd . trimStart
60−
61−trimStart :: String -> String
62−trimStart = dropWhile isSpace
63−
64−trimEnd :: String -> String
65−trimEnd = reverse . trimStart . reverse
66−
67−parseDirective :: String -> Either String Command
68−parseDirective cmd =
69− case D.directivesFor' dstr of
70− [(d, _)] -> commandFor d
71− [] -> Left "Unrecognized directive. Type :? for help."
72− ds -> Left ("Ambiguous directive. Possible matches: " ++
73− intercalate ", " (map snd ds) ++ ". Type :? for help.")
74− where
75− (dstr, arg) = break isSpace cmd
76−
77− commandFor d = case d of
78− Help -> return ShowHelp
79− Quit -> return QuitPSCi
80− Reset -> return ResetState
81− Browse -> BrowseModule <$> parseRest P.moduleName arg
82− Load -> return $ LoadFile (trim arg)
83− Foreign -> return $ LoadForeign (trim arg)
84− Show -> ShowInfo <$> parseReplQuery' (trim arg)
85− Type -> TypeOf <$> parseRest P.parseValue arg
86− Kind -> KindOf <$> parseRest P.parseType arg
87−
88−-- |
89−-- Parses expressions entered at the PSCI repl.
90−--
91−psciExpression :: P.TokenParser Command
92−psciExpression = Expression <$> P.parseValue
93−
94−-- |
95−-- PSCI version of @let@.
96−-- This is essentially let from do-notation.
97−-- However, since we don't support the @Eff@ monad,
98−-- we actually want the normal @let@.
99−--
100−psciLet :: P.TokenParser Command
101−psciLet = Decls <$> (P.reserved "let" *> P.indented *> manyDecls)
102− where
103− manyDecls :: P.TokenParser [P.Declaration]
104− manyDecls = mark (many1 (same *> P.parseLocalDeclaration))
105−
106−-- | Imports must be handled separately from other declarations, so that
107−-- :show import works, for example.
108−psciImport :: P.TokenParser Command
109−psciImport = do
110− (mn, declType, asQ, _) <- P.parseImportDeclaration'
111− return $ Import (mn, declType, asQ)
112−
113−-- | Any other declaration that we don't need a 'special case' parser for
114−-- (like let or import declarations).
115−psciOtherDeclaration :: P.TokenParser Command
116−psciOtherDeclaration = Decls . (:[]) <$> do
117− decl <- discardPositionInfo <$> P.parseDeclaration
118− if acceptable decl
119− then return decl
120− else fail "this kind of declaration is not supported in psci"
121−
122−discardPositionInfo :: P.Declaration -> P.Declaration
123−discardPositionInfo (P.PositionedDeclaration _ _ d) = d
124−discardPositionInfo d = d
125−
126−acceptable :: P.Declaration -> Bool
127−acceptable P.DataDeclaration{} = True
128−acceptable P.TypeSynonymDeclaration{} = True
129−acceptable P.ExternDeclaration{} = True
130−acceptable P.ExternDataDeclaration{} = True
131−acceptable P.TypeClassDeclaration{} = True
132−acceptable P.TypeInstanceDeclaration{} = True
133−acceptable _ = False
134−
135−parseReplQuery' :: String -> Either String ReplQuery
136−parseReplQuery' str =
137− case parseReplQuery str of
138− Nothing -> Left ("Don't know how to show " ++ str ++ ". Try one of: " ++
139− intercalate ", " replQueryStrings ++ ".")
140− Just query -> Right query
psci/PSCi/Printer.hsdeleted−131
@@ -1,131 +0,0 @@
1−{-# LANGUAGE RecordWildCards #-}
2−{-# LANGUAGE DataKinds #-}
3−
4−module PSCi.Printer where
5−
6−import Prelude ()
7−import Prelude.Compat
8−
9−import qualified Language.PureScript as P
10−import qualified Text.PrettyPrint.Boxes as Box
11−import qualified Data.Map as M
12−import System.Console.Haskeline
13−import Data.Maybe (mapMaybe)
14−import Data.List (intersperse)
15−import Control.Monad.IO.Class (MonadIO)
16−
17−-- Printers
18−
19−-- |
20−-- Pretty print a module's signatures
21−--
22−printModuleSignatures :: MonadIO m => P.ModuleName -> P.Environment -> InputT m ()
23−printModuleSignatures moduleName (P.Environment {..}) =
24− -- get relevant components of a module from environment
25− let moduleNamesIdent = (filter ((== moduleName) . fst) . M.keys) names
26− moduleTypeClasses = (filter (\(P.Qualified maybeName _) -> maybeName == Just moduleName) . M.keys) typeClasses
27− moduleTypes = (filter (\(P.Qualified maybeName _) -> maybeName == Just moduleName) . M.keys) types
28−
29− in
30− -- print each component
31− (outputStr . unlines . map trimEnd . lines . Box.render . Box.vsep 1 Box.left)
32− [ printModule's (mapMaybe (showTypeClass . findTypeClass typeClasses)) moduleTypeClasses -- typeClasses
33− , printModule's (mapMaybe (showType typeClasses dataConstructors typeSynonyms . findType types)) moduleTypes -- types
34− , printModule's (map (showNameType . findNameType names)) moduleNamesIdent -- functions
35− ]
36−
37− where printModule's showF = Box.vsep 1 Box.left . showF
38−
39− findNameType :: M.Map (P.ModuleName, P.Ident) (P.Type, P.NameKind, P.NameVisibility) -> (P.ModuleName, P.Ident) -> (P.Ident, Maybe (P.Type, P.NameKind, P.NameVisibility))
40− findNameType envNames m@(_, mIdent) = (mIdent, M.lookup m envNames)
41−
42− showNameType :: (P.Ident, Maybe (P.Type, P.NameKind, P.NameVisibility)) -> Box.Box
43− showNameType (mIdent, Just (mType, _, _)) = Box.text (P.showIdent mIdent ++ " :: ") Box.<> P.typeAsBox mType
44− showNameType _ = P.internalError "The impossible happened in printModuleSignatures."
45−
46− findTypeClass
47− :: M.Map (P.Qualified (P.ProperName 'P.ClassName)) ([(String, Maybe P.Kind)], [(P.Ident, P.Type)], [P.Constraint])
48− -> P.Qualified (P.ProperName 'P.ClassName)
49− -> (P.Qualified (P.ProperName 'P.ClassName), Maybe ([(String, Maybe P.Kind)], [(P.Ident, P.Type)], [P.Constraint]))
50− findTypeClass envTypeClasses name = (name, M.lookup name envTypeClasses)
51−
52− showTypeClass
53− :: (P.Qualified (P.ProperName 'P.ClassName), Maybe ([(String, Maybe P.Kind)], [(P.Ident, P.Type)], [P.Constraint]))
54− -> Maybe Box.Box
55− showTypeClass (_, Nothing) = Nothing
56− showTypeClass (P.Qualified _ name, Just (vars, body, constrs)) =
57− let constraints =
58− if null constrs
59− then Box.text ""
60− else Box.text "("
61− Box.<> Box.hcat Box.left (intersperse (Box.text ", ") $ map (\(P.Qualified _ pn, lt) -> Box.text (P.runProperName pn) Box.<+> Box.hcat Box.left (map P.typeAtomAsBox lt)) constrs)
62− Box.<> Box.text ") <= "
63− className =
64− Box.text (P.runProperName name)
65− Box.<> Box.text (concatMap ((' ':) . fst) vars)
66− classBody =
67− Box.vcat Box.top (map (\(i, t) -> Box.text (P.showIdent i ++ " ::") Box.<+> P.typeAsBox t) body)
68−
69− in
70− Just $
71− (Box.text "class "
72− Box.<> constraints
73− Box.<> className
74− Box.<+> if null body then Box.text "" else Box.text "where")
75− Box.// Box.moveRight 2 classBody
76−
77−
78− findType
79− :: M.Map (P.Qualified (P.ProperName 'P.TypeName)) (P.Kind, P.TypeKind)
80− -> P.Qualified (P.ProperName 'P.TypeName)
81− -> (P.Qualified (P.ProperName 'P.TypeName), Maybe (P.Kind, P.TypeKind))
82− findType envTypes name = (name, M.lookup name envTypes)
83−
84− showType
85− :: M.Map (P.Qualified (P.ProperName 'P.ClassName)) ([(String, Maybe P.Kind)], [(P.Ident, P.Type)], [P.Constraint])
86− -> M.Map (P.Qualified (P.ProperName 'P.ConstructorName)) (P.DataDeclType, P.ProperName 'P.TypeName, P.Type, [P.Ident])
87− -> M.Map (P.Qualified (P.ProperName 'P.TypeName)) ([(String, Maybe P.Kind)], P.Type)
88− -> (P.Qualified (P.ProperName 'P.TypeName), Maybe (P.Kind, P.TypeKind))
89− -> Maybe Box.Box
90− showType typeClassesEnv dataConstructorsEnv typeSynonymsEnv (n@(P.Qualified modul name), typ) =
91− case (typ, M.lookup n typeSynonymsEnv) of
92− (Just (_, P.TypeSynonym), Just (typevars, dtType)) ->
93− if M.member (fmap P.coerceProperName n) typeClassesEnv
94− then
95− Nothing
96− else
97− Just $
98− Box.text ("type " ++ P.runProperName name ++ concatMap ((' ':) . fst) typevars)
99− Box.// Box.moveRight 2 (Box.text "=" Box.<+> P.typeAsBox dtType)
100−
101− (Just (_, P.DataType typevars pt), _) ->
102− let prefix =
103− case pt of
104− [(dtProperName,_)] ->
105− case M.lookup (P.Qualified modul dtProperName) dataConstructorsEnv of
106− Just (dataDeclType, _, _, _) -> P.showDataDeclType dataDeclType
107− _ -> "data"
108− _ -> "data"
109−
110− in
111− Just $ Box.text (prefix ++ " " ++ P.runProperName name ++ concatMap ((' ':) . fst) typevars) Box.// printCons pt
112−
113− _ ->
114− Nothing
115−
116− where printCons pt =
117− Box.moveRight 2 $
118− Box.vcat Box.left $
119− mapFirstRest (Box.text "=" Box.<+>) (Box.text "|" Box.<+>) $
120− map (\(cons,idents) -> (Box.text (P.runProperName cons) Box.<> Box.hcat Box.left (map prettyPrintType idents))) pt
121−
122− prettyPrintType t = Box.text " " Box.<> P.typeAtomAsBox t
123−
124− mapFirstRest _ _ [] = []
125− mapFirstRest f g (x:xs) = f x : map g xs
126−
127− trimEnd = reverse . dropWhile (== ' ') . reverse
128−
129−-- | Pretty-print errors
130−printErrors :: MonadIO m => P.MultipleErrors -> InputT m ()
131−printErrors = outputStrLn . P.prettyPrintMultipleErrors False
psci/PSCi/Types.hsdeleted−218
@@ -1,218 +0,0 @@
1−-----------------------------------------------------------------------------
2−--
3−-- Module : Types
4−-- Copyright : (c) Phil Freeman 2014
5−-- License : MIT
6−--
7−-- Maintainer : Phil Freeman <paf31@cantab.net>
8−-- Stability : experimental
9−-- Portability :
10−--
11−-- |
12−-- Type declarations and associated basic functions for PSCI.
13−--
14−-----------------------------------------------------------------------------
15−
16−module PSCi.Types where
17−
18−import Prelude ()
19−import Prelude.Compat
20−
21−import Control.Arrow (second)
22−import Data.Map (Map)
23−import qualified Data.Map as Map
24−import qualified Language.PureScript as P
25−
26−data PSCiOptions = PSCiOptions
27− { psciMultiLineMode :: Bool
28− , psciInputFile :: [FilePath]
29− , psciForeignInputFiles :: [FilePath]
30− , psciInputNodeFlags :: [String]
31− }
32−
33−-- |
34−-- The PSCI state.
35−-- Holds a list of imported modules, loaded files, and partial let bindings.
36−-- The let bindings are partial,
37−-- because it makes more sense to apply the binding to the final evaluated expression.
38−--
39−data PSCiState = PSCiState
40− { psciImportedModules :: [ImportedModule]
41− , _psciLoadedModules :: Map FilePath [P.Module]
42− , psciForeignFiles :: Map P.ModuleName FilePath
43− , psciLetBindings :: [P.Declaration]
44− , psciNodeFlags :: [String]
45− }
46−
47−initialPSCiState :: PSCiState
48−initialPSCiState =
49− PSCiState [] Map.empty Map.empty [] []
50−
51−mkPSCiState :: [ImportedModule]
52− -> [(FilePath, P.Module)]
53− -> Map P.ModuleName FilePath
54− -> [P.Declaration]
55− -> [String]
56− -> PSCiState
57−mkPSCiState imported loaded foreigns lets nodeFlags =
58− (initialPSCiState
59− |> each imported updateImportedModules
60− |> updateModules loaded)
61− { psciForeignFiles = foreigns
62− , psciLetBindings = lets
63− , psciNodeFlags = nodeFlags
64− }
65− where
66− x |> f = f x
67− each xs f st = foldl (flip f) st xs
68−
69−-- Public psci state accessors
70−
71−-- | Get the imported filenames as a list.
72−psciImportedFilenames :: PSCiState -> [FilePath]
73−psciImportedFilenames = Map.keys . _psciLoadedModules
74−
75−-- | Get the loaded modules as a list.
76−psciLoadedModules :: PSCiState -> [(FilePath, P.Module)]
77−psciLoadedModules = collect . Map.toList . _psciLoadedModules
78− where
79− collect :: [(k, [v])] -> [(k, v)]
80− collect vss = [ (k, v) | (k, vs) <- vss, v <- vs ]
81−
82−-- | All of the data that is contained by an ImportDeclaration in the AST.
83−-- That is:
84−--
85−-- * A module name, the name of the module which is being imported
86−-- * An ImportDeclarationType which specifies whether there is an explicit
87−-- import list, a hiding list, or neither.
88−-- * If the module is imported qualified, its qualified name in the importing
89−-- module. Otherwise, Nothing.
90−--
91−type ImportedModule = (P.ModuleName, P.ImportDeclarationType, Maybe P.ModuleName)
92−
93−psciImportedModuleNames :: PSCiState -> [P.ModuleName]
94−psciImportedModuleNames (PSCiState{psciImportedModules = is}) =
95− map (\(mn, _, _) -> mn) is
96−
97−allImportsOf :: P.Module -> PSCiState -> [ImportedModule]
98−allImportsOf m (PSCiState{psciImportedModules = is}) =
99− filter isImportOfThis is
100− where
101− name = P.getModuleName m
102− isImportOfThis (name', _, _) = name == name'
103−
104−-- State helpers
105−
106−-- |
107−-- Updates the state to have more imported modules.
108−--
109−updateImportedModules :: ImportedModule -> PSCiState -> PSCiState
110−updateImportedModules im st = st { psciImportedModules = im : psciImportedModules st }
111−
112−-- |
113−-- Updates the state to have more loaded modules (available for import, but
114−-- not necessarily imported).
115−--
116−updateModules :: [(FilePath, P.Module)] -> PSCiState -> PSCiState
117−updateModules modules st =
118− st { _psciLoadedModules = Map.union (go modules) (_psciLoadedModules st) }
119− where
120− go = Map.fromListWith (++) . map (second (:[]))
121−
122−-- |
123−-- Updates the state to have more let bindings.
124−--
125−updateLets :: [P.Declaration] -> PSCiState -> PSCiState
126−updateLets ds st = st { psciLetBindings = psciLetBindings st ++ ds }
127−
128−-- |
129−-- Updates the state to have more let bindings.
130−--
131−updateForeignFiles :: Map P.ModuleName FilePath -> PSCiState -> PSCiState
132−updateForeignFiles fs st = st { psciForeignFiles = psciForeignFiles st `Map.union` fs }
133−
134−-- |
135−-- Valid Meta-commands for PSCI
136−--
137−data Command
138− -- |
139− -- A purescript expression
140− --
141− = Expression P.Expr
142− -- |
143− -- Show the help (ie, list of directives)
144− --
145− | ShowHelp
146− -- |
147− -- Import a module from a loaded file
148− --
149− | Import ImportedModule
150− -- |
151− -- Browse a module
152− --
153− | BrowseModule P.ModuleName
154− -- |
155− -- Load a file for use with importing
156− --
157− | LoadFile FilePath
158− -- |
159− -- Load a foreign module
160− --
161− | LoadForeign FilePath
162− -- |
163− -- Exit PSCI
164− --
165− | QuitPSCi
166− -- |
167− -- Reset the state of the REPL
168− --
169− | ResetState
170− -- |
171− -- Add some declarations to the current evaluation context.
172− --
173− | Decls [P.Declaration]
174− -- |
175− -- Find the type of an expression
176− --
177− | TypeOf P.Expr
178− -- |
179− -- Find the kind of an expression
180− --
181− | KindOf P.Type
182− -- |
183− -- Shows information about the current state of the REPL
184− --
185− | ShowInfo ReplQuery
186−
187−data ReplQuery
188− = QueryLoaded
189− | QueryImport
190− deriving (Eq, Show)
191−
192−-- | A list of all ReplQuery values.
193−replQueries :: [ReplQuery]
194−replQueries = [QueryLoaded, QueryImport]
195−
196−replQueryStrings :: [String]
197−replQueryStrings = map showReplQuery replQueries
198−
199−showReplQuery :: ReplQuery -> String
200−showReplQuery QueryLoaded = "loaded"
201−showReplQuery QueryImport = "import"
202−
203−parseReplQuery :: String -> Maybe ReplQuery
204−parseReplQuery "loaded" = Just QueryLoaded
205−parseReplQuery "import" = Just QueryImport
206−parseReplQuery _ = Nothing
207−
208−data Directive
209− = Help
210− | Quit
211− | Reset
212− | Browse
213− | Load
214− | Foreign
215− | Type
216− | Kind
217− | Show
218− deriving (Eq, Show)
psci/main/Main.hsdeleted−6
@@ -1,6 +0,0 @@
1−module Main where
2−
3−import PSCi
4−
5−main :: IO ()
6−main = runPSCi
psgo.cabalnew file+145
@@ -0,0 +1,145 @@
1+cabal-version: 1.12
2+
3+-- This file has been generated from package.yaml by hpack version 0.35.0.
4+--
5+-- see: https://github.com/sol/hpack
6+
7+name: psgo
8+version: 0.1.0.0
9+description: Please see the README on Github at <https://github.com/andyarvanitis/purescript-native#readme>
10+homepage: https://github.com/andyarvanitis/purescript-native#readme
11+bug-reports: https://github.com/andyarvanitis/purescript-native/issues
12+author: Andy Arvanitis
13+maintainer: example@example.com
14+copyright: 2018 Andy Arvanitis
15+license: BSD3
16+license-file: LICENSE
17+build-type: Simple
18+extra-source-files:
19+ README.md
20+ ChangeLog.md
21+ stack.yaml
22+ support/ffi-loader.go
23+ support/go.mod.ffi-loader
24+ support/go.mod.output
25+ support/go.mod.working
26+
27+source-repository head
28+ type: git
29+ location: https://github.com/andyarvanitis/purescript-native
30+
31+library
32+ exposed-modules:
33+ CodeGen.IL
34+ CodeGen.IL.Common
35+ CodeGen.IL.Optimizer
36+ CodeGen.IL.Optimizer.Common
37+ CodeGen.IL.Optimizer.Inliner
38+ CodeGen.IL.Optimizer.MagicDo
39+ CodeGen.IL.Optimizer.TCO
40+ CodeGen.IL.Printer
41+ Tests
42+ other-modules:
43+ Paths_psgo
44+ hs-source-dirs:
45+ src
46+ default-extensions:
47+ ConstraintKinds
48+ DataKinds
49+ DeriveFunctor
50+ EmptyDataDecls
51+ FlexibleContexts
52+ KindSignatures
53+ LambdaCase
54+ MultiParamTypeClasses
55+ NoImplicitPrelude
56+ PatternGuards
57+ PatternSynonyms
58+ RankNTypes
59+ RecordWildCards
60+ OverloadedStrings
61+ ScopedTypeVariables
62+ TupleSections
63+ ViewPatterns
64+ build-depends:
65+ aeson >=1.0 && <1.5
66+ , base >=4.7 && <5
67+ , base-compat >=0.6.0
68+ , bytestring >=0.10.8.2 && <0.11
69+ , containers
70+ , directory
71+ , file-embed
72+ , filemanip
73+ , filepath
74+ , gitrev
75+ , monad-parallel >=0.7.2.2 && <0.8
76+ , mtl >=2.1.0 && <2.3.0
77+ , pattern-arrows >=0.0.2 && <0.1
78+ , process
79+ , protolude >=0.1.6
80+ , purescript
81+ , safe >=0.3.9 && <0.4
82+ , text
83+ , transformers >=0.3.0 && <0.6
84+ default-language: Haskell2010
85+
86+executable psgo
87+ main-is: Main.hs
88+ other-modules:
89+ Paths_psgo
90+ hs-source-dirs:
91+ app
92+ ghc-options: -threaded -rtsopts -with-rtsopts=-N
93+ build-depends:
94+ aeson >=1.0 && <1.5
95+ , base >=4.7 && <5
96+ , base-compat >=0.6.0
97+ , bytestring >=0.10.8.2 && <0.11
98+ , containers
99+ , directory
100+ , file-embed
101+ , filemanip
102+ , filepath
103+ , gitrev
104+ , monad-parallel >=0.7.2.2 && <0.8
105+ , mtl >=2.1.0 && <2.3.0
106+ , pattern-arrows >=0.0.2 && <0.1
107+ , process
108+ , protolude >=0.1.6
109+ , psgo
110+ , purescript
111+ , safe >=0.3.9 && <0.4
112+ , text
113+ , transformers >=0.3.0 && <0.6
114+ default-language: Haskell2010
115+
116+test-suite psgo-test
117+ type: exitcode-stdio-1.0
118+ main-is: Spec.hs
119+ other-modules:
120+ Paths_psgo
121+ hs-source-dirs:
122+ test
123+ ghc-options: -threaded -rtsopts -with-rtsopts=-N
124+ build-depends:
125+ aeson >=1.0 && <1.5
126+ , base >=4.7 && <5
127+ , base-compat >=0.6.0
128+ , bytestring >=0.10.8.2 && <0.11
129+ , containers
130+ , directory
131+ , file-embed
132+ , filemanip
133+ , filepath
134+ , gitrev
135+ , monad-parallel >=0.7.2.2 && <0.8
136+ , mtl >=2.1.0 && <2.3.0
137+ , pattern-arrows >=0.0.2 && <0.1
138+ , process
139+ , protolude >=0.1.6
140+ , psgo
141+ , purescript
142+ , safe >=0.3.9 && <0.4
143+ , text
144+ , transformers >=0.3.0 && <0.6
145+ default-language: Haskell2010
purescript.cabaldeleted−420
@@ -1,420 +0,0 @@
1−name: purescript
2−version: 0.8.4.0
3−cabal-version: >=1.8
4−build-type: Simple
5−license: MIT
6−license-file: LICENSE
7−copyright: (c) 2013-15 Phil Freeman, (c) 2014-15 Gary Burgess
8−maintainer: Phil Freeman <paf31@cantab.net>
9−stability: experimental
10−synopsis: PureScript Programming Language Compiler
11−description: A small strongly, statically typed programming language with expressive types, inspired by Haskell and compiling to Javascript.
12−category: Language
13−Homepage: http://www.purescript.org/
14−author: Phil Freeman <paf31@cantab.net>,
15− Gary Burgess <gary.burgess@gmail.com>,
16− Hardy Jones <jones3.hardy@gmail.com>,
17− Harry Garrood <harry@garrood.me>,
18− Christoph Hegemann <christoph.hegemann1337@gmail.com>
19−
20−tested-with: GHC==7.10.3
21−
22−extra-source-files: examples/passing/*.purs
23− , examples/failing/*.purs
24− , examples/docs/bower_components/purescript-prelude/src/*.purs
25− , examples/docs/bower.json
26− , examples/docs/LICENSE
27− , examples/docs/src/*.purs
28− , tests/support/setup.js
29− , tests/support/package.json
30− , tests/support/prelude/bower.json
31− , tests/support/prelude/src/*.purs
32− , tests/support/prelude/src/*.js
33− , tests/support/prelude/LICENSE
34− , tests/support/bower.json
35− , tests/support/setup-win.cmd
36− , tests/support/flattened/*.purs
37− , tests/support/flattened/*.js
38− , tests/support/psci/*.purs
39− , tests/support/pscide/src/*.purs
40− , tests/support/pscide/src/*.js
41− , tests/support/pscide/src/*.fail
42− , stack.yaml
43− , stack-lts-5.yaml
44− , stack-nightly.yaml
45− , README.md
46− , INSTALL.md
47− , CONTRIBUTORS.md
48− , CONTRIBUTING.md
49− , pcc/include/*.hh
50−
51−source-repository head
52− type: git
53− location: https://github.com/purescript/purescript.git
54−
55−library
56− build-depends: base >=4.8 && <5,
57− base-compat >=0.6.0,
58− lifted-base >= 0.2.3 && < 0.2.4,
59− monad-control >= 1.0.0.0 && < 1.1,
60− transformers-base >= 0.4.0 && < 0.5,
61− containers -any,
62− unordered-containers -any,
63− dlist -any,
64− directory >= 1.2,
65− filepath -any,
66− mtl >= 2.1.0 && < 2.3.0,
67− parsec -any,
68− transformers >= 0.3.0 && < 0.6,
69− transformers-compat >= 0.3.0,
70− utf8-string >= 1 && < 2,
71− pattern-arrows >= 0.0.2 && < 0.1,
72− time -any,
73− boxes >= 0.1.4 && < 0.2.0,
74− aeson >= 0.8 && < 0.12,
75− vector -any,
76− bower-json >= 0.8,
77− aeson-better-errors >= 0.8,
78− bytestring -any,
79− text -any,
80− split -any,
81− language-javascript == 0.6.*,
82− syb -any,
83− Glob >= 0.7 && < 0.8,
84− process >= 1.2.0 && < 1.5,
85− safe >= 0.3.9 && < 0.4,
86− semigroups >= 0.16.2 && < 0.19,
87− parallel >= 3.2 && < 3.3,
88− sourcemap >= 0.1.6,
89− stm >= 0.2.4.0,
90− regex-tdfa -any,
91− edit-distance -any,
92− fsnotify >= 0.2.1,
93− monad-logger >= 0.3 && < 0.4,
94− pipes >= 4.0.0 && < 4.2.0 ,
95− pipes-http -any,
96− http-types -any
97−
98− exposed-modules: Language.PureScript
99− Language.PureScript.AST
100− Language.PureScript.AST.Binders
101− Language.PureScript.AST.Declarations
102− Language.PureScript.AST.Operators
103− Language.PureScript.AST.Literals
104− Language.PureScript.AST.SourcePos
105− Language.PureScript.AST.Traversals
106− Language.PureScript.AST.Exported
107− Language.PureScript.Bundle
108− Language.PureScript.Crash
109− Language.PureScript.Externs
110− Language.PureScript.CodeGen
111− Language.PureScript.CodeGen.JS
112− Language.PureScript.CodeGen.JS.AST
113− Language.PureScript.CodeGen.JS.Common
114− Language.PureScript.CodeGen.JS.Optimizer
115− Language.PureScript.CodeGen.JS.Optimizer.Blocks
116− Language.PureScript.CodeGen.JS.Optimizer.Common
117− Language.PureScript.CodeGen.JS.Optimizer.Inliner
118− Language.PureScript.CodeGen.JS.Optimizer.MagicDo
119− Language.PureScript.CodeGen.JS.Optimizer.TCO
120− Language.PureScript.CodeGen.JS.Optimizer.Unused
121−
122− Language.PureScript.CodeGen.Cpp
123− Language.PureScript.CodeGen.Cpp.AST
124− Language.PureScript.CodeGen.Cpp.Common
125− Language.PureScript.CodeGen.Cpp.File
126− Language.PureScript.CodeGen.Cpp.Optimizer
127− Language.PureScript.CodeGen.Cpp.Optimizer.Blocks
128− Language.PureScript.CodeGen.Cpp.Optimizer.Common
129− Language.PureScript.CodeGen.Cpp.Optimizer.Inliner
130− Language.PureScript.CodeGen.Cpp.Optimizer.MagicDo
131− Language.PureScript.CodeGen.Cpp.Optimizer.TCO
132− Language.PureScript.CodeGen.Cpp.Optimizer.Unused
133− Language.PureScript.CodeGen.Cpp.Types
134− Language.PureScript.Pretty.Cpp
135−
136− Language.PureScript.Constants
137− Language.PureScript.CoreFn
138− Language.PureScript.CoreFn.Ann
139− Language.PureScript.CoreFn.Binders
140− Language.PureScript.CoreFn.Desugar
141− Language.PureScript.CoreFn.Expr
142− Language.PureScript.CoreFn.Meta
143− Language.PureScript.CoreFn.Module
144− Language.PureScript.CoreFn.Traversals
145− Language.PureScript.Comments
146− Language.PureScript.Environment
147− Language.PureScript.Errors
148− Language.PureScript.Errors.JSON
149− Language.PureScript.Kinds
150− Language.PureScript.Linter
151− Language.PureScript.Linter.Exhaustive
152− Language.PureScript.Linter.Imports
153− Language.PureScript.Make
154− Language.PureScript.ModuleDependencies
155− Language.PureScript.Names
156− Language.PureScript.Options
157− Language.PureScript.Parser
158− Language.PureScript.Parser.Lexer
159− Language.PureScript.Parser.Common
160− Language.PureScript.Parser.Declarations
161− Language.PureScript.Parser.JS
162− Language.PureScript.Parser.Kinds
163− Language.PureScript.Parser.State
164− Language.PureScript.Parser.Types
165− Language.PureScript.Pretty
166− Language.PureScript.Pretty.Common
167− Language.PureScript.Pretty.JS
168− Language.PureScript.Pretty.Kinds
169− Language.PureScript.Pretty.Types
170− Language.PureScript.Pretty.Values
171− Language.PureScript.Renamer
172− Language.PureScript.Sugar
173− Language.PureScript.Sugar.BindingGroups
174− Language.PureScript.Sugar.CaseDeclarations
175− Language.PureScript.Sugar.DoNotation
176− Language.PureScript.Sugar.Names
177− Language.PureScript.Sugar.Names.Env
178− Language.PureScript.Sugar.Names.Imports
179− Language.PureScript.Sugar.Names.Exports
180− Language.PureScript.Sugar.ObjectWildcards
181− Language.PureScript.Sugar.Operators
182− Language.PureScript.Sugar.Operators.Common
183− Language.PureScript.Sugar.Operators.Expr
184− Language.PureScript.Sugar.Operators.Binders
185− Language.PureScript.Sugar.Operators.Types
186− Language.PureScript.Sugar.TypeClasses
187− Language.PureScript.Sugar.TypeClasses.Deriving
188− Language.PureScript.Sugar.TypeDeclarations
189− Language.PureScript.Traversals
190− Language.PureScript.TypeChecker
191− Language.PureScript.TypeChecker.Entailment
192− Language.PureScript.TypeChecker.Kinds
193− Language.PureScript.TypeChecker.Monad
194− Language.PureScript.TypeChecker.Rows
195− Language.PureScript.TypeChecker.Skolems
196− Language.PureScript.TypeChecker.Subsumption
197− Language.PureScript.TypeChecker.Synonyms
198− Language.PureScript.TypeChecker.Types
199− Language.PureScript.TypeChecker.Unify
200− Language.PureScript.TypeClassDictionaries
201− Language.PureScript.Types
202−
203− Language.PureScript.Docs
204− Language.PureScript.Docs.Convert
205− Language.PureScript.Docs.Convert.Single
206− Language.PureScript.Docs.Convert.ReExports
207− Language.PureScript.Docs.Render
208− Language.PureScript.Docs.Types
209− Language.PureScript.Docs.RenderedCode
210− Language.PureScript.Docs.RenderedCode.Types
211− Language.PureScript.Docs.RenderedCode.Render
212− Language.PureScript.Docs.AsMarkdown
213− Language.PureScript.Docs.ParseAndBookmark
214− Language.PureScript.Docs.Utils.MonoidExtras
215−
216− Language.PureScript.Publish
217− Language.PureScript.Publish.Utils
218− Language.PureScript.Publish.ErrorsWarnings
219− Language.PureScript.Publish.BoxesHelpers
220−
221− Language.PureScript.Ide
222− Language.PureScript.Ide.Command
223− Language.PureScript.Ide.Externs
224− Language.PureScript.Ide.Error
225− Language.PureScript.Ide.Pursuit
226− Language.PureScript.Ide.Completion
227− Language.PureScript.Ide.Matcher
228− Language.PureScript.Ide.Filter
229− Language.PureScript.Ide.Types
230− Language.PureScript.Ide.State
231− Language.PureScript.Ide.CaseSplit
232− Language.PureScript.Ide.SourceFile
233− Language.PureScript.Ide.Watcher
234− Language.PureScript.Ide.Reexports
235− Language.PureScript.Ide.Imports
236− Language.PureScript.Ide.Util
237− Language.PureScript.Ide.Rebuild
238−
239− Control.Monad.Logger
240− Control.Monad.Supply
241− Control.Monad.Supply.Class
242−
243− System.IO.UTF8
244−
245− extensions: DataKinds
246− exposed: True
247− buildable: True
248− hs-source-dirs: src
249− other-modules: Paths_purescript
250− ghc-options: -Wall -O2
251−
252−executable psc
253− build-depends: base >=4 && <5, base-compat >=0.6.0,
254− containers -any, directory -any, filepath -any,
255− mtl -any, optparse-applicative >= 0.12.1, parsec -any, purescript -any,
256− time -any, transformers -any, transformers-compat -any, Glob >= 0.7 && < 0.8,
257− aeson >= 0.8 && < 0.12, bytestring -any, utf8-string >= 1 && < 2
258− main-is: Main.hs
259− buildable: True
260− hs-source-dirs: psc
261− other-modules: Paths_purescript
262− ghc-options: -Wall -O2 -fno-warn-unused-do-bind -threaded -rtsopts "-with-rtsopts=-N"
263−
264−executable psci
265− build-depends: base >=4 && <5, containers -any, directory -any, filepath -any,
266− mtl -any, optparse-applicative >= 0.12.1, parsec -any,
267− haskeline >= 0.7.0.0, purescript -any, transformers -any,
268− transformers-compat -any, process -any, time -any, Glob -any, base-compat >=0.6.0,
269− boxes >= 0.1.4 && < 0.2.0
270−
271− main-is: Main.hs
272− buildable: True
273− hs-source-dirs: psci psci/main
274− other-modules: PSCi
275− PSCi.Types
276− PSCi.Parser
277− PSCi.Directive
278− PSCi.Completion
279− PSCi.IO
280− PSCi.Message
281− PSCi.Option
282− PSCi.Module
283− PSCi.Printer
284− Paths_purescript
285− ghc-options: -Wall -O2
286−
287−executable psc-docs
288− build-depends: base >=4 && <5, purescript -any,
289− optparse-applicative >= 0.12.1, process -any, mtl -any,
290− split -any, ansi-wl-pprint -any, directory -any,
291− filepath -any, Glob -any, transformers -any,
292− transformers-compat -any
293− main-is: Main.hs
294− other-modules: Paths_purescript
295− buildable: True
296− hs-source-dirs: psc-docs
297− other-modules: Ctags
298− Etags
299− Tags
300− ghc-options: -Wall -O2
301−
302−executable psc-publish
303− build-depends: base >=4 && <5, purescript -any, bytestring -any, aeson -any, optparse-applicative -any
304− main-is: Main.hs
305− other-modules: Paths_purescript
306− buildable: True
307− hs-source-dirs: psc-publish
308− ghc-options: -Wall -O2
309−
310−executable psc-hierarchy
311− build-depends: base >=4 && <5, purescript -any, optparse-applicative >= 0.12.1,
312− process -any, mtl -any, parsec -any, filepath -any, directory -any,
313− Glob -any
314− main-is: Main.hs
315− other-modules: Paths_purescript
316− buildable: True
317− hs-source-dirs: hierarchy
318− other-modules:
319− ghc-options: -Wall -O2
320−
321−executable psc-bundle
322− main-is: Main.hs
323− other-modules: Paths_purescript
324− other-extensions:
325− build-depends: base >=4 && <5,
326− purescript -any,
327− filepath -any,
328− directory -any,
329− mtl -any,
330− transformers -any,
331− transformers-compat -any,
332− optparse-applicative >= 0.12.1,
333− Glob -any
334− ghc-options: -Wall -O2
335− hs-source-dirs: psc-bundle
336−
337−executable psc-ide-server
338− main-is: Main.hs
339− other-modules: Paths_purescript
340− other-extensions:
341− build-depends: base >=4 && <5
342− , purescript -any
343− , directory -any
344− , filepath -any
345− , monad-logger -any
346− , mtl -any
347− , transformers -any
348− , transformers-compat -any
349− , network -any
350− , optparse-applicative >= 0.12.1
351− , stm -any
352− , text -any
353− , base-compat >=0.6.0
354− ghc-options: -Wall -O2 -threaded
355− hs-source-dirs: psc-ide-server
356−
357−executable psc-ide-client
358− main-is: Main.hs
359− other-modules: Paths_purescript
360− other-extensions:
361− build-depends: base >=4 && <5
362− , mtl -any
363− , text -any
364− , optparse-applicative >= 0.12.1
365− , network -any
366− , base-compat >=0.6.0
367− ghc-options: -Wall -O2
368− hs-source-dirs: psc-ide-client
369−
370−executable pcc
371− build-depends: base >=4 && <5, containers -any, directory -any, filepath -any,
372− file-embed -any,
373− bytestring -any,
374− mtl -any, optparse-applicative >= 0.10.0, parsec -any, purescript -any,
375− time -any, transformers -any, transformers-compat -any
376− main-is: Main.hs
377− buildable: True
378− hs-source-dirs: pcc
379− other-modules:
380− ghc-options: -Wall -O2 -fno-warn-unused-do-bind
381−
382−test-suite tests
383− build-depends: base >=4 && <5, containers -any, directory -any,
384− filepath -any, mtl -any, parsec -any, purescript -any,
385− transformers -any, process -any, transformers-compat -any, time -any,
386− Glob -any, aeson-better-errors -any, bytestring -any, aeson -any,
387− base-compat -any, haskeline >= 0.7.0.0, optparse-applicative -any,
388− boxes -any, HUnit -any, hspec -any, hspec-discover -any, stm -any, text -any,
389− vector -any, utf8-string -any
390− ghc-options: -Wall
391− type: exitcode-stdio-1.0
392− main-is: Main.hs
393− other-modules: TestUtils
394− TestCompiler
395− TestDocs
396− TestPscPublish
397− TestPsci
398− TestPscIde
399− PscIdeSpec
400− Language.PureScript.Ide.FilterSpec
401− Language.PureScript.Ide.ImportsSpec
402− Language.PureScript.Ide.Imports.IntegrationSpec
403− Language.PureScript.Ide.Integration
404− Language.PureScript.Ide.MatcherSpec
405− Language.PureScript.Ide.RebuildSpec
406− Language.PureScript.Ide.ReexportsSpec
407− Language.PureScript.IdeSpec
408− PSCi.Completion
409− PSCi.Directive
410− PSCi.Module
411− PSCi.Types
412− buildable: True
413− hs-source-dirs: tests psci
414−
415−test-suite pcc-tests
416− build-depends: base >=4 && <5, directory -any, filepath -any, process -any
417− type: exitcode-stdio-1.0
418− main-is: TestMain.hs
419− buildable: True
420− hs-source-dirs: pcc
src/CodeGen/IL.hsnew file+321
@@ -0,0 +1,321 @@
1+-- | This module generates code in the core imperative representation from
2+-- elaborated PureScript code.
3+module CodeGen.IL
4+ ( module AST
5+ , module Common
6+ , moduleToIL
7+ ) where
8+
9+import Prelude.Compat
10+import Protolude (ordNub)
11+
12+import Control.Arrow ((&&&))
13+import Control.Monad (forM, liftM, replicateM, void)
14+import Control.Monad.Supply.Class
15+
16+import Data.List ((\\), delete, intersect, nub)
17+import qualified Data.Foldable as F
18+import qualified Data.Map as M
19+import Data.Maybe (fromMaybe, isNothing, mapMaybe)
20+import Data.Monoid ((<>))
21+import Data.String (fromString)
22+import Data.Text (Text)
23+import qualified Data.Text as T
24+
25+import Language.PureScript.AST.SourcePos
26+import Language.PureScript.CoreImp.AST (AST)
27+import qualified Language.PureScript.CoreImp.AST as AST
28+import Language.PureScript.CoreFn
29+import Language.PureScript.Crash
30+import Language.PureScript.Names
31+import Language.PureScript.Options
32+import Language.PureScript.PSString (PSString, mkString)
33+import Language.PureScript.Traversals (sndM)
34+import qualified Language.PureScript.Constants as C
35+
36+import System.FilePath.Posix ((</>))
37+
38+import CodeGen.IL.Common as Common
39+import CodeGen.IL.Optimizer
40+import CodeGen.IL.Printer
41+
42+data DeclType = ModuleDecl | LetDecl | RecLetDecl deriving (Eq)
43+
44+-- | Generate code in the simplified intermediate representation for all declarations in a
45+-- module.
46+moduleToIL
47+ :: forall m
48+ -- . (Monad m, MonadReader Options m, MonadSupply m, MonadError MultipleErrors m)
49+ . (Monad m, MonadSupply m)
50+ => Module Ann
51+ -> Text
52+ -> m (Text, [Text], [AST], Text, Text)
53+moduleToIL (Module _ coms mn _ imps _ foreigns decls) project =
54+ do
55+ ilDecls <- mapM (bindToIL ModuleDecl) decls
56+ optimized <- traverse (traverse (optimize modName')) ilDecls
57+ let optimized' = concat optimized
58+ values = annotValue <$> optimized'
59+ foreigns' = moduleIdentToIL <$> foreigns
60+ interface = interfaceSource modName values foreigns
61+ imports = nub . concat $ importToIL <$> optimized'
62+ implHeader = implHeaderSource modName imports project
63+ implFooter = implFooterSource (runModuleName mn) foreigns
64+ return $ (interface, foreigns', optimized', implHeader, implFooter)
65+ where
66+ modName = moduleNameToIL mn
67+ modName' = AST.Var Nothing modName
68+
69+ annotValue :: AST -> (Text, Bool)
70+ annotValue (AST.Function _ (Just name) [] (AST.Block _ [AST.Return _ ret]))
71+ | isLiteral ret = (name, True)
72+ annotValue (AST.Function _ (Just name) [] _) = (name, False)
73+ annotValue _ = error "Unexpected top-level value form"
74+
75+ -- | Extracts all declaration names from a binding group.
76+ getNames :: Bind Ann -> [Ident]
77+ getNames (NonRec _ ident _) = [ident]
78+ getNames (Rec vals) = map (snd . fst) vals
79+
80+ -- | Generates IL code for a module import
81+ --
82+ importToIL :: AST -> [Text]
83+ importToIL = AST.everything (++) modRef
84+ where
85+ modRef (AST.Indexer _ (AST.Var _ _) (AST.Var _ mname))
86+ | not $ T.null mname = [extract mname]
87+ modRef _ = []
88+ extract :: Text -> Text
89+ extract = T.replace "_" "." . T.dropWhileEnd (=='_')
90+
91+ -- |
92+ -- Generate code in the simplified intermediate representation for a declaration
93+ --
94+ bindToIL :: DeclType -> Bind Ann -> m [AST]
95+ bindToIL dt (NonRec ann ident val) = return <$> nonRecToIL dt ann ident val
96+ bindToIL dt (Rec vals) = forM vals (uncurry . uncurry $ nonRecToIL dt')
97+ where
98+ dt' = if dt == LetDecl then RecLetDecl else dt
99+
100+ -- | Generate code in the simplified intermediate representation for a single non-recursive
101+ -- declaration.
102+ --
103+ -- The main purpose of this function is to handle code generation for comments.
104+ nonRecToIL :: DeclType -> Ann -> Ident -> Expr Ann -> m AST
105+ nonRecToIL dt a i e@(extractAnn -> (_, com, _, _)) | not (null com) = do
106+ -- withoutComment <- asks optionsNoComments
107+ let withoutComment = False
108+ if withoutComment
109+ then nonRecToIL dt a i (modifyAnn removeComments e)
110+ else AST.Comment Nothing com <$> nonRecToIL dt a i (modifyAnn removeComments e)
111+ nonRecToIL ModuleDecl (ss, _, _, _) ident val = do
112+ il <- valueToIL val
113+ pure $ AST.Function Nothing (Just $ moduleIdentToIL ident) [] (AST.Block Nothing [AST.Return Nothing il])
114+ nonRecToIL RecLetDecl (ss, _, _, _) ident val = do
115+ ilExpr <- valueToIL val
116+ pure $ AST.Assignment Nothing (AST.Var Nothing $ identToIL ident) ilExpr
117+ nonRecToIL _ (ss, _, _, _) ident val = do
118+ il <- valueToIL val
119+ pure $ AST.VariableIntroduction Nothing (identToIL ident) (Just il)
120+
121+ -- | Generate code in the simplified intermediate representation for a variable based on a
122+ -- PureScript identifier.
123+ var :: Ident -> AST
124+ var = AST.Var Nothing . identToIL
125+
126+ accessorString :: PSString -> AST -> AST
127+ accessorString prop = AST.Indexer Nothing (AST.StringLiteral Nothing prop)
128+
129+ -- | Generate code in the simplified intermediate representation for a value or expression.
130+
131+ valueToIL :: Expr Ann -> m AST
132+ valueToIL (Literal (pos, _, _, _) l) = literalToValueIL pos l
133+ valueToIL (Accessor _ prop val) =
134+ accessorString prop <$> valueToIL val
135+ valueToIL (ObjectUpdate _ o ps) = do
136+ obj <- valueToIL o
137+ updates <- mapM (sndM valueToIL) ps
138+ obj' <- freshName'
139+ let objVar = AST.Var Nothing obj'
140+ copy = AST.VariableIntroduction Nothing obj' (Just $ copyDict obj)
141+ assign (k, v) = AST.Assignment Nothing (accessorString k objVar) v
142+ sts = copy : (assign <$> updates) ++ [AST.Return Nothing objVar]
143+ return $ AST.App Nothing (AST.Function Nothing Nothing [] (AST.Block Nothing sts)) []
144+ valueToIL (Abs _ arg val) = do
145+ ret <- valueToIL val
146+ let ilArg = case arg of
147+ UnusedIdent -> []
148+ _ -> [identToIL arg]
149+ return $ AST.Function Nothing Nothing ilArg (AST.Block Nothing [AST.Return Nothing ret])
150+ valueToIL e@App{} = do
151+ let (f, args) = unApp e []
152+ args' <- mapM valueToIL args
153+ fn <- valueToIL f
154+ case f of
155+ Var (_, _, _, Just IsNewtype) _ -> return (head args')
156+ _ -> flip (foldl (\fn a -> AST.App Nothing fn [a])) args' <$> valueToIL f
157+ where
158+ unApp :: Expr Ann -> [Expr Ann] -> (Expr Ann, [Expr Ann])
159+ unApp (App _ val arg) args = unApp val (arg : args)
160+ unApp other args = (other, args)
161+ valueToIL (Var _ ident) = return $ varToIL ident
162+ valueToIL (Case (ss, _, _, _) values binders) = do
163+ vals <- mapM valueToIL values
164+ bindersToIL ss binders vals
165+ valueToIL (Let _ ds val) = do
166+ let recurs = concatMap getNames $ filter isRec ds
167+ recurDs = (\v -> AST.VariableIntroduction Nothing (identToIL v) Nothing) <$> recurs
168+ ds' <- concat <$> mapM (bindToIL LetDecl) ds
169+ ret <- valueToIL val
170+ return $ AST.App Nothing (AST.Function Nothing Nothing [] (AST.Block Nothing (recurDs ++ ds' ++ [AST.Return Nothing ret]))) []
171+ where
172+ isRec :: Bind Ann -> Bool
173+ isRec (Rec _) = True
174+ isRec _ = False
175+ valueToIL (Constructor (_, _, _, Just IsNewtype) _ (ProperName ctor) _) = error "IsNewtype"
176+ valueToIL (Constructor _ _ (ProperName ctor) fields) =
177+ let body = AST.ObjectLiteral Nothing $ (mkString ctor, AST.BooleanLiteral Nothing True) :
178+ ((\field -> (mkString (identToIL field), var field)) `map` fields)
179+ fn = foldr (\f inner -> AST.Function Nothing Nothing [identToIL f] (AST.Block Nothing [AST.Return Nothing inner])) body fields
180+ in return fn
181+
182+
183+ iife :: Text -> [AST] -> AST
184+ iife v exprs = AST.App Nothing (AST.Function Nothing Nothing [] (AST.Block Nothing $ exprs ++ [AST.Return Nothing $ AST.Var Nothing v])) []
185+
186+ literalToValueIL :: SourceSpan -> Literal (Expr Ann) -> m AST
187+ literalToValueIL ss (NumericLiteral (Left i)) = return $ AST.NumericLiteral (Just ss) (Left i)
188+ literalToValueIL ss (NumericLiteral (Right n)) = return $ AST.NumericLiteral (Just ss) (Right n)
189+ literalToValueIL ss (StringLiteral s) = return $ AST.StringLiteral (Just ss) s
190+ literalToValueIL ss (CharLiteral c) = return $ AST.StringLiteral (Just ss) (fromString [c])
191+ literalToValueIL ss (BooleanLiteral b) = return $ AST.BooleanLiteral (Just ss) b
192+ literalToValueIL ss (ArrayLiteral xs) = AST.ArrayLiteral (Just ss) <$> mapM valueToIL xs
193+ literalToValueIL ss (ObjectLiteral ps) = AST.ObjectLiteral (Just ss) <$> mapM (sndM valueToIL) ps
194+
195+ -- | Generate code in the simplified intermediate representation for a reference to a
196+ -- variable.
197+ varToIL :: Qualified Ident -> AST
198+ varToIL (Qualified Nothing ident) = var ident
199+ varToIL qual = qualifiedToIL id qual
200+
201+ -- | Generate code in the simplified intermediate representation for a reference to a
202+ -- variable that may have a qualified name.
203+ qualifiedToIL :: (a -> Ident) -> Qualified a -> AST
204+ qualifiedToIL f (Qualified (Just (ModuleName mn')) a) | mn' == C.prim = AST.Var Nothing . moduleIdentToIL $ f a
205+ qualifiedToIL f (Qualified (Just mn') a) | mn /= mn' = AST.Indexer Nothing (AST.Var Nothing . moduleIdentToIL $ f a) (AST.Var Nothing (moduleNameToIL mn'))
206+ qualifiedToIL f (Qualified _ a) = AST.Indexer Nothing (AST.Var Nothing . moduleIdentToIL $ f a) (AST.Var Nothing "")
207+
208+ -- foreignIdent :: Ident -> AST
209+ -- foreignIdent ident = accessorString (mkString $ runIdent ident) (AST.Var Nothing "$foreign")
210+
211+ -- | Generate code in the simplified intermediate representation for pattern match binders
212+ -- and guards.
213+ bindersToIL :: SourceSpan -> [CaseAlternative Ann] -> [AST] -> m AST
214+ bindersToIL ss binders vals = do
215+ valNames <- replicateM (length vals) freshName'
216+ let assignments = zipWith (AST.VariableIntroduction Nothing) valNames (map Just vals)
217+ ils <- forM binders $ \(CaseAlternative bs result) -> do
218+ ret <- guardsToIL result
219+ go valNames ret bs
220+ return $ AST.App Nothing (AST.Function Nothing Nothing [] (AST.Block Nothing (assignments ++ concat ils ++ [AST.Throw Nothing (AST.StringLiteral Nothing $ mkString failedPatternMessage)])))
221+ []
222+ where
223+ go :: [Text] -> [AST] -> [Binder Ann] -> m [AST]
224+ go _ done [] = return done
225+ go (v:vs) done' (b:bs) = do
226+ done'' <- go vs done' bs
227+ binderToIL v done'' b
228+ go _ _ _ = internalError "Invalid arguments to bindersToIL"
229+
230+ failedPatternMessage :: Text
231+ failedPatternMessage = "Failed pattern match at " <> runModuleName mn <> " " <> displayStartEndPos ss
232+
233+ guardsToIL :: Either [(Guard Ann, Expr Ann)] (Expr Ann) -> m [AST]
234+ guardsToIL (Left gs) = traverse genGuard gs where
235+ genGuard (cond, val) = do
236+ cond' <- valueToIL cond
237+ val' <- valueToIL val
238+ return
239+ (AST.IfElse Nothing (AST.Binary Nothing AST.EqualTo cond' (AST.BooleanLiteral Nothing True))
240+ (AST.Block Nothing [AST.Return Nothing val']) Nothing)
241+
242+ guardsToIL (Right v) = return . AST.Return Nothing <$> valueToIL v
243+
244+ -- | Generate code in the simplified intermediate representation for a pattern match
245+ -- binder.
246+ binderToIL :: Text -> [AST] -> Binder Ann -> m [AST]
247+ binderToIL _ done NullBinder{} = return done
248+ binderToIL varName done (LiteralBinder _ l) =
249+ literalToBinderIL varName done l
250+ binderToIL varName done (VarBinder _ ident) =
251+ return (AST.VariableIntroduction Nothing (identToIL ident) (Just (AST.Var Nothing varName)) : done)
252+ binderToIL varName done (ConstructorBinder (_, _, _, Just IsNewtype) _ _ [b]) =
253+ binderToIL varName done b
254+ binderToIL varName done (ConstructorBinder (_, _, _, Just (IsConstructor ctorType fields)) _ (Qualified _ (ProperName ctor)) bs) = do
255+ il <- go (zip fields bs) done
256+ return $ case ctorType of
257+ ProductType -> il
258+ SumType ->
259+ [AST.IfElse Nothing (AST.InstanceOf Nothing (AST.Var Nothing varName) (AST.StringLiteral Nothing (mkString ctor)))
260+ (AST.Block Nothing il)
261+ Nothing]
262+ where
263+ go :: [(Ident, Binder Ann)] -> [AST] -> m [AST]
264+ go [] done' = return done'
265+ go ((field, binder) : remain) done' = do
266+ argVar <- freshName'
267+ done'' <- go remain done'
268+ il <- binderToIL argVar done'' binder
269+ return (AST.VariableIntroduction Nothing argVar (Just $ accessorString (mkString $ identToIL field) $ AST.Var Nothing varName) : il)
270+
271+ binderToIL _ _ ConstructorBinder{} =
272+ internalError "binderToIL: Invalid ConstructorBinder in binderToIL"
273+ binderToIL varName done (NamedBinder _ ident binder) = do
274+ il <- binderToIL varName done binder
275+ return (AST.VariableIntroduction Nothing (identToIL ident) (Just (AST.Var Nothing varName)) : il)
276+
277+ literalToBinderIL :: Text -> [AST] -> Literal (Binder Ann) -> m [AST]
278+ literalToBinderIL varName done (NumericLiteral num) =
279+ return [AST.IfElse Nothing (AST.Binary Nothing AST.EqualTo (AST.Var Nothing varName) (AST.NumericLiteral Nothing num)) (AST.Block Nothing done) Nothing]
280+ literalToBinderIL varName done (CharLiteral c) =
281+ return [AST.IfElse Nothing (AST.Binary Nothing AST.EqualTo (AST.Var Nothing varName) (AST.StringLiteral Nothing (fromString [c]))) (AST.Block Nothing done) Nothing]
282+ literalToBinderIL varName done (StringLiteral str) =
283+ return [AST.IfElse Nothing (AST.Binary Nothing AST.EqualTo (AST.Var Nothing varName) (AST.StringLiteral Nothing str)) (AST.Block Nothing done) Nothing]
284+ literalToBinderIL varName done (BooleanLiteral True) =
285+ return [AST.IfElse Nothing (AST.Binary Nothing AST.EqualTo (AST.Var Nothing varName) (AST.BooleanLiteral Nothing True)) (AST.Block Nothing done) Nothing]
286+ literalToBinderIL varName done (BooleanLiteral False) =
287+ return [AST.IfElse Nothing (AST.Binary Nothing AST.EqualTo (AST.Var Nothing varName) (AST.BooleanLiteral Nothing False)) (AST.Block Nothing done) Nothing]
288+ -- return [AST.IfElse Nothing (AST.Unary Nothing AST.Not (AST.Var Nothing varName)) (AST.Block Nothing done) Nothing]
289+ literalToBinderIL varName done (ObjectLiteral bs) = go done bs
290+ where
291+ go :: [AST] -> [(PSString, Binder Ann)] -> m [AST]
292+ go done' [] = return done'
293+ go done' ((prop, binder):bs') = do
294+ propVar <- freshName'
295+ done'' <- go done' bs'
296+ il <- binderToIL propVar done'' binder
297+ return (AST.VariableIntroduction Nothing propVar (Just (accessorString prop (AST.Var Nothing varName))) : il)
298+ literalToBinderIL varName done (ArrayLiteral bs) = do
299+ il <- go done 0 bs
300+ return [AST.IfElse Nothing (AST.Binary Nothing AST.EqualTo
301+ (arrayLength $ AST.Var Nothing varName)
302+ (AST.NumericLiteral Nothing (Left (fromIntegral $ length bs))))
303+ (AST.Block Nothing il) Nothing]
304+ where
305+ go :: [AST] -> Integer -> [Binder Ann] -> m [AST]
306+ go done' _ [] = return done'
307+ go done' index (binder:bs') = do
308+ elVar <- freshName'
309+ done'' <- go done' (index + 1) bs'
310+ il <- binderToIL elVar done'' binder
311+ return (AST.VariableIntroduction Nothing elVar (Just (AST.Indexer Nothing (AST.NumericLiteral Nothing (Left index)) (AST.Var Nothing varName))) : il)
312+
313+emptyAnn :: Ann
314+emptyAnn = (SourceSpan "" (SourcePos 0 0) (SourcePos 0 0), [], Nothing, Nothing)
315+
316+arrayLength :: AST -> AST
317+arrayLength a = AST.App Nothing (AST.Var Nothing arrayLengthFn) [a]
318+-- arrayLength a = AST.Var Nothing (arrayLengthFn <> "(" <> prettyPrintIL1 a <> ")")
319+
320+copyDict :: AST -> AST
321+copyDict a = AST.App Nothing (AST.Var Nothing copyDictFn) [a]
src/CodeGen/IL/Common.hsnew file+196
@@ -0,0 +1,196 @@
1+-- | Common code generation utility functions
2+module CodeGen.IL.Common where
3+
4+import Prelude.Compat
5+
6+import Control.Monad.Supply.Class (MonadSupply, freshName)
7+import Data.Char
8+import Data.Maybe (maybe)
9+import Data.Monoid ((<>))
10+import Data.Text (Text)
11+import qualified Data.Text as T
12+
13+import Language.PureScript.Crash
14+import Language.PureScript.Names
15+
16+import qualified Language.PureScript.Constants as C
17+
18+moduleNameToIL :: ModuleName -> Text
19+moduleNameToIL (ModuleName mn) =
20+ let name = T.replace "." "_" mn
21+ in if nameIsILBuiltIn name then (name <> moduleRenamerMarker) else name
22+
23+moduleNameToIL' :: ModuleName -> Text
24+moduleNameToIL' (ModuleName mn) = T.replace "_" "." mn
25+
26+-- | Convert an 'Ident' into a valid IL identifier:
27+--
28+-- * Alphanumeric characters are kept unmodified.
29+--
30+-- * Reserved IL identifiers are wrapped with '_'.
31+--
32+identToIL :: Ident -> Text
33+identToIL UnusedIdent = unusedName
34+identToIL (Ident "$__unused") = unusedName
35+identToIL (Ident name) | name == C.undefined = undefinedName -- Note: done in Printer.hs too
36+identToIL (Ident name) = properToIL name
37+identToIL (GenIdent _ _) = internalError "GenIdent in identToIL"
38+
39+moduleIdentToIL :: Ident -> Text
40+moduleIdentToIL UnusedIdent = unusedName
41+moduleIdentToIL (Ident name) | name == C.undefined = undefinedName
42+moduleIdentToIL (Ident name) = moduleProperToIL name
43+moduleIdentToIL (GenIdent _ _) = internalError "GenIdent in identToIL"
44+
45+undefinedName :: Text
46+undefinedName = "Undefined"
47+
48+unusedName :: Text
49+unusedName = "_"
50+
51+properToIL :: Text -> Text
52+properToIL name
53+ | nameIsILReserved name = "ˉ" <> name
54+ | otherwise = T.concatMap identCharToText name
55+
56+-- | Attempts to find a human-readable name for a symbol, if none has been specified returns the
57+-- ordinal value.
58+identCharToText :: Char -> Text
59+identCharToText 'ṩ' = "_ṩ"
60+identCharToText c | isAlphaNum c = T.singleton c
61+identCharToText '_' = "_"
62+identCharToText '\'' = "ꞌ" -- lowercase saltillo
63+identCharToText c = error (show (ord c)) -- TODO: should never occur now(?)
64+
65+moduleProperToIL :: Text -> Text
66+moduleProperToIL = T.concatMap identCharToText
67+
68+-- | Checks whether an identifier name is reserved in IL.
69+nameIsILReserved :: Text -> Bool
70+nameIsILReserved name =
71+ name `elem` ilAnyReserved
72+
73+-- | Checks whether a name matches a built-in value in IL.
74+nameIsILBuiltIn :: Text -> Bool
75+nameIsILBuiltIn name =
76+ name `elem`
77+ [ "Any"
78+ , "Apply"
79+ , "Contains"
80+ , "CopyDict"
81+ , "Dict"
82+ , "EffFn"
83+ , "Fn"
84+ , "Foreign"
85+ , "Get"
86+ , "Index"
87+ , "Is"
88+ , "Length"
89+ , "Once"
90+ , "Run"
91+ , "Undefined"
92+ ]
93+
94+ilAnyReserved :: [Text]
95+ilAnyReserved =
96+ concat
97+ [ ilKeywords
98+ , ilLiterals
99+ ]
100+
101+ilKeywords :: [Text]
102+ilKeywords =
103+ [ "break"
104+ , "case"
105+ , "chan"
106+ , "const"
107+ , "continue"
108+ , "default"
109+ , "defer"
110+ , "else"
111+ , "fallthrough"
112+ , "for"
113+ , "func"
114+ , "go"
115+ , "goto"
116+ , "if"
117+ , "import"
118+ , "interface"
119+ , "map"
120+ , "package"
121+ , "range"
122+ , "return"
123+ , "select"
124+ , "struct"
125+ , "switch"
126+ , "type"
127+ , "var"
128+ ]
129+
130+ilLiterals :: [Text]
131+ilLiterals =
132+ [ "init"
133+ , "nil"
134+ , "int"
135+ , "int8"
136+ , "int16"
137+ , "int32"
138+ , "int64"
139+ , "uint"
140+ , "uint8"
141+ , "uint16"
142+ , "uint32"
143+ , "uint64"
144+ , "uintptr"
145+ , "float32"
146+ , "float64"
147+ , "complex64"
148+ , "complex128"
149+ , "byte"
150+ , "rune"
151+ , "string"
152+ ]
153+
154+withPrefix :: Text -> Text
155+withPrefix s = "Ꞌ" <> s -- uppercase saltillo
156+
157+anyType :: Text
158+anyType = "Any"
159+
160+dictType :: Text
161+dictType = "Dict"
162+
163+arrayType :: Text
164+arrayType = "[]" <> anyType
165+
166+uncurriedFnType :: Int -> Text
167+uncurriedFnType i = "Fn" <> (T.pack . show $ i)
168+
169+int :: Text
170+int = "int"
171+
172+float :: Text
173+float = "float64"
174+
175+bool :: Text
176+bool = "bool"
177+
178+string :: Text
179+string = "string"
180+
181+arrayLengthFn :: Text
182+arrayLengthFn = "Length"
183+
184+indexFn :: Text
185+indexFn = "Index"
186+
187+copyDictFn :: Text
188+copyDictFn = "CopyDict"
189+
190+freshName' :: MonadSupply m => m Text
191+freshName' = do
192+ name <- freshName
193+ return $ T.replace "$" "ṩ" name
194+
195+moduleRenamerMarker :: Text
196+moduleRenamerMarker = "__"
src/CodeGen/IL/Optimizer.hsnew file+81
@@ -0,0 +1,81 @@
1+-- | This module optimizes code in the intermediate representation.
2+module CodeGen.IL.Optimizer (optimize) where
3+
4+import Prelude.Compat
5+
6+import Control.Monad.Supply.Class (MonadSupply)
7+import Data.Text (Text)
8+import Language.PureScript.CoreImp.AST
9+import Language.PureScript.CoreImp.Optimizer.Blocks
10+import Language.PureScript.CoreImp.Optimizer.Common hiding (isDict)
11+import Language.PureScript.CoreImp.Optimizer.Inliner (etaConvert, evaluateIifes, inlineVariables, unThunk)
12+import Language.PureScript.CoreImp.Optimizer.Unused
13+
14+import CodeGen.IL.Common (unusedName)
15+import CodeGen.IL.Optimizer.Inliner
16+import CodeGen.IL.Optimizer.MagicDo
17+import CodeGen.IL.Optimizer.TCO
18+
19+import qualified Language.PureScript.Constants as C
20+
21+-- | Apply a series of optimizer passes to simplified IL code
22+optimize :: MonadSupply m => AST -> AST -> m AST
23+optimize mn il = do
24+ il' <- untilFixedPoint (inlineFnComposition . inlineUnsafeCoerce . inlineUnsafePartial . tidyUp) il
25+ il'' <- untilFixedPoint (return . ignoreUnusedResults . inlineCommonValues . inlineCommonOperators . tidyUp) . tco mn . inlineST
26+ =<< untilFixedPoint (return . magicDoST)
27+ =<< untilFixedPoint (return . magicDoEff)
28+ =<< untilFixedPoint (return . magicDoEffect) il'
29+ untilFixedPoint (return . collapseVarDeclarations) il''
30+ where
31+ tidyUp :: AST -> AST
32+ tidyUp = applyAll
33+ [ collapseNestedBlocks
34+ , collapseNestedIfs
35+ , collapseIfChecks
36+ , removeCodeAfterReturnStatements
37+ , unThunk
38+ , etaConvert
39+ , evaluateIifes
40+ , inlineVariables
41+ ]
42+
43+untilFixedPoint :: (Monad m, Eq a) => (a -> m a) -> a -> m a
44+untilFixedPoint f = go
45+ where
46+ go a = do
47+ a' <- f a
48+ if a' == a then return a' else go a'
49+
50+collapseIfChecks :: AST -> AST
51+collapseIfChecks = everywhere collapse where
52+ collapse :: AST -> AST
53+ collapse (IfElse _ (Binary _ EqualTo (BooleanLiteral _ True) (BooleanLiteral _ True)) (Block _ [exprs]) _) = exprs
54+ collapse (IfElse _ (Binary _ EqualTo (Indexer _ (Var _ prop) (Var _ val)) (BooleanLiteral _ True)) (Block _ [exprs]) _)
55+ | prop == "otherwise" && val == "Data_Boolean" = exprs
56+ collapse exprs = exprs
57+
58+collapseVarDeclarations :: AST -> AST
59+collapseVarDeclarations = everywhere collapse where
60+ collapse :: AST -> AST
61+ collapse (Block ss sts) = Block ss (go Nothing sts)
62+ collapse s = s
63+
64+ go :: Maybe Text -> [AST] -> [AST]
65+ go _ [] = []
66+ go Nothing (decl@(VariableIntroduction _ var (Just _)) : sts) = decl : go (Just var) (go Nothing sts)
67+ go (Just var') ((VariableIntroduction ss var (Just val)) : sts)
68+ | var == var' = (Assignment ss (Var Nothing var) val) : go (Just var') sts
69+ go var' (s:sts) = s : go var' sts
70+
71+ignoreUnusedResults :: AST -> AST
72+ignoreUnusedResults = everywhere $ removeFromBlock go
73+ where
74+ go :: [AST] -> [AST]
75+ go [] = []
76+ go (VariableIntroduction ss var (Just s) : sts)
77+ | not $ any (everything (||) (isUsed var)) sts = sts'
78+ where
79+ sts' | App{} <- s = s : (go sts)
80+ | otherwise = go sts
81+ go (s:sts) = s : go sts
src/CodeGen/IL/Optimizer/Common.hsnew file+18
@@ -0,0 +1,18 @@
1+-- | Common functions used by the various optimizer phases
2+module CodeGen.IL.Optimizer.Common where
3+
4+import Prelude.Compat
5+
6+import Data.Text (Text)
7+
8+import Language.PureScript.CoreImp.AST
9+import Language.PureScript.PSString (PSString, decodeString)
10+
11+isDict :: (Text, PSString) -> AST -> Bool
12+isDict (moduleName, dictName) (Indexer _ (Var _ x) (Var _ y)) =
13+ Just x == decodeString dictName && y == moduleName
14+isDict _ _ = False
15+
16+isDict' :: [(Text, PSString)] -> AST -> Bool
17+isDict' xs il = any (`isDict` il) xs
18+
src/CodeGen/IL/Optimizer/Inliner.hsnew file+435
@@ -0,0 +1,435 @@
1+-- | This module performs basic inlining of known functions
2+module CodeGen.IL.Optimizer.Inliner
3+ ( inlineCommonValues
4+ , inlineCommonOperators
5+ , inlineFnComposition
6+ , inlineUnsafeCoerce
7+ , inlineUnsafePartial
8+ ) where
9+
10+import Prelude.Compat
11+
12+import Control.Monad.Supply.Class (MonadSupply)
13+
14+import Data.Either (rights)
15+import Data.Maybe (fromMaybe)
16+import Data.String (IsString, fromString)
17+import Data.Text (Text)
18+import qualified Data.Text as T
19+
20+import Language.PureScript.PSString (PSString, decodeString, mkString)
21+import Language.PureScript.CoreImp.AST
22+import Language.PureScript.CoreImp.Optimizer.Common hiding (isDict, isDict')
23+import Language.PureScript.AST (SourceSpan(..))
24+import qualified Language.PureScript.Constants as C
25+
26+import CodeGen.IL.Common
27+import CodeGen.IL.Optimizer.Common
28+
29+-- TODO: Potential bug:
30+-- Shouldn't just inline this case: { var x = 0; x.toFixed(10); }
31+-- Needs to be: { 0..toFixed(10); }
32+-- Probably needs to be fixed in pretty-printer instead.
33+shouldInline :: AST -> Bool
34+shouldInline (Var _ _) = True
35+shouldInline (NumericLiteral _ _) = True
36+shouldInline (StringLiteral _ _) = True
37+shouldInline (BooleanLiteral _ _) = True
38+shouldInline (Indexer _ index val) = shouldInline index && shouldInline val
39+shouldInline _ = False
40+
41+inlineCommonValues :: AST -> AST
42+inlineCommonValues = everywhere convert
43+ where
44+ convert :: AST -> AST
45+ convert (App ss fn [dict])
46+ | isDict' [semiringNumber, semiringInt] dict && isDict fnZero fn = NumericLiteral ss (Left 0)
47+ | isDict' [semiringNumber, semiringInt] dict && isDict fnOne fn = NumericLiteral ss (Left 1)
48+ | isDict boundedBoolean dict && isDict fnBottom fn = BooleanLiteral ss False
49+ | isDict boundedBoolean dict && isDict fnTop fn = BooleanLiteral ss True
50+ convert (App ss (App _ fn [dict]) [x])
51+ | isDict ringInt dict && isDict fnNegate fn = Unary ss Negate (unbox x $ snd ringInt)
52+ convert (App ss (App _ (App _ fn [dict]) [x]) [y])
53+ | isDict semiringInt dict && isDict fnAdd fn = intOp ss Add semiringInt x y
54+ | isDict semiringInt dict && isDict fnMultiply fn = intOp ss Multiply semiringInt x y
55+ | isDict ringInt dict && isDict fnSubtract fn = intOp ss Subtract ringInt x y
56+ convert other = other
57+ fnZero = (C.dataSemiring, C.zero)
58+ fnOne = (C.dataSemiring, C.one)
59+ fnBottom = (C.dataBounded, C.bottom)
60+ fnTop = (C.dataBounded, C.top)
61+ fnAdd = (C.dataSemiring, C.add)
62+ fnMultiply = (C.dataSemiring, C.mul)
63+ fnSubtract = (C.dataRing, C.sub)
64+ fnNegate = (C.dataRing, C.negate)
65+ intOp ss op (_, d) x y = Binary ss op (unbox x d) (unbox y d)
66+
67+inlineCommonOperators :: AST -> AST
68+inlineCommonOperators = everywhereTopDown $ applyAll $
69+ [ binary semiringNumber opAdd Add
70+ , binary semiringNumber opMul Multiply
71+
72+ , binary ringNumber opSub Subtract
73+ , unary ringNumber opNegate Negate
74+
75+ , binary euclideanRingNumber opDiv Divide
76+
77+ -- , binary eqNumber opEq EqualTo
78+ -- , binary eqNumber opNotEq NotEqualTo
79+ , binary eqInt opEq EqualTo
80+ , binary eqInt opNotEq NotEqualTo
81+ , binary eqString opEq EqualTo
82+ , binary eqString opNotEq NotEqualTo
83+ , binary eqChar opEq EqualTo
84+ , binary eqChar opNotEq NotEqualTo
85+ , binary eqBoolean opEq EqualTo
86+ , binary eqBoolean opNotEq NotEqualTo
87+
88+ , binary ordBoolean opLessThan LessThan
89+ , binary ordBoolean opLessThanOrEq LessThanOrEqualTo
90+ , binary ordBoolean opGreaterThan GreaterThan
91+ , binary ordBoolean opGreaterThanOrEq GreaterThanOrEqualTo
92+ , binary ordChar opLessThan LessThan
93+ , binary ordChar opLessThanOrEq LessThanOrEqualTo
94+ , binary ordChar opGreaterThan GreaterThan
95+ , binary ordChar opGreaterThanOrEq GreaterThanOrEqualTo
96+ , binary ordInt opLessThan LessThan
97+ , binary ordInt opLessThanOrEq LessThanOrEqualTo
98+ , binary ordInt opGreaterThan GreaterThan
99+ , binary ordInt opGreaterThanOrEq GreaterThanOrEqualTo
100+ , binary ordNumber opLessThan LessThan
101+ , binary ordNumber opLessThanOrEq LessThanOrEqualTo
102+ , binary ordNumber opGreaterThan GreaterThan
103+ , binary ordNumber opGreaterThanOrEq GreaterThanOrEqualTo
104+ , binary ordString opLessThan LessThan
105+ , binary ordString opLessThanOrEq LessThanOrEqualTo
106+ , binary ordString opGreaterThan GreaterThan
107+ , binary ordString opGreaterThanOrEq GreaterThanOrEqualTo
108+
109+ , binary semigroupString opAppend Add
110+
111+ , binary heytingAlgebraBoolean opConj And
112+ , binary heytingAlgebraBoolean opDisj Or
113+ , unary heytingAlgebraBoolean opNot Not
114+
115+ , binary' C.dataIntBits C.or BitwiseOr
116+ , binary' C.dataIntBits C.and BitwiseAnd
117+ , binary' C.dataIntBits C.xor BitwiseXor
118+ , binary' C.dataIntBits C.shl ShiftLeft
119+ , binary' C.dataIntBits C.shr ShiftRight
120+ , unary' C.dataIntBits C.complement BitwiseNot
121+
122+ , inlineNonClassFunction (isModFn (C.dataFunction, C.apply)) $ \f x -> App Nothing f [x]
123+ , inlineNonClassFunction (isModFn (C.dataFunction, C.applyFlipped)) $ \x f -> App Nothing f [x]
124+ , inlineUnsafeIndex (isModFnWithDict (C.dataArray, C.unsafeIndex)) $ flip (Indexer Nothing)
125+ ] ++
126+ [ fn | i <- [0..10], fn <- [ mkFn i, runFn i ] ] ++
127+ [ fn | i <- [0..10], fn <- [ mkEffFn C.controlMonadEffUncurried C.mkEffFn i, runEffFn C.controlMonadEffUncurried C.runEffFn i ] ] ++
128+ [ fn | i <- [0..10], fn <- [ mkEffFn C.effectUncurried C.mkEffectFn i, runEffFn C.effectUncurried C.runEffectFn i ] ]
129+ where
130+ binary :: (Text, PSString) -> (Text, PSString) -> BinaryOperator -> AST -> AST
131+ binary dict@(_, d) fns op = convert where
132+ convert :: AST -> AST
133+ convert (App ss (App _ (App _ fn [dict']) [x]) [y])
134+ | isDict dict dict' && isDict fns fn = Binary ss op (unbox x d) (unbox y d)
135+ convert other = other
136+ binary' :: Text -> PSString -> BinaryOperator -> AST -> AST
137+ binary' moduleName opString op = convert where
138+ convert :: AST -> AST
139+ convert (App ss (App _ fn [x]) [y]) | isDict (moduleName, opString) fn = Binary ss op (unbox x mn) (unbox y mn)
140+ convert other = other
141+ mn :: PSString
142+ mn = mkString moduleName
143+ unary :: (Text, PSString) -> (Text, PSString) -> UnaryOperator -> AST -> AST
144+ unary dicts@(_, d) fns op = convert where
145+ convert :: AST -> AST
146+ convert (App ss (App _ fn [dict']) [x]) | isDict dicts dict' && isDict fns fn = Unary ss op (unbox x d)
147+ convert other = other
148+ unary' :: Text -> PSString -> UnaryOperator -> AST -> AST
149+ unary' moduleName fnName op = convert where
150+ convert :: AST -> AST
151+ convert (App ss fn [x]) | isDict (moduleName, fnName) fn = Unary ss op (unbox x fnName)
152+ convert other = other
153+
154+ mkFn :: Int -> AST -> AST
155+ mkFn = mkFn' C.dataFunctionUncurried C.mkFn $ \ss1 ss2 ss3 args il ->
156+ Function ss1 Nothing args (Block ss2 [Return ss3 il])
157+
158+ mkEffFn :: Text -> Text -> Int -> AST -> AST
159+ mkEffFn modName fnName = mkFn' modName fnName $ \ss1 ss2 ss3 args il ->
160+ Function ss1 Nothing args (Block ss2 [Return ss3 (App ss3 il [])])
161+
162+ mkFn' :: Text -> Text -> (Maybe SourceSpan -> Maybe SourceSpan -> Maybe SourceSpan -> [Text] -> AST -> AST) -> Int -> AST -> AST
163+ mkFn' modName fnName res 0 = convert where
164+ convert :: AST -> AST
165+ convert (App _ mkFnN [Function s1 Nothing [_] (Block s2 [Return s3 il])]) | isNFn modName fnName 0 mkFnN =
166+ res s1 s2 s3 [] il
167+ convert other = other
168+ mkFn' modName fnName res n = convert where
169+ convert :: AST -> AST
170+ convert orig@(App ss mkFnN [fn]) | isNFn modName fnName n mkFnN =
171+ case collectArgs n [] fn of
172+ Just (args, [Return ss' ret]) -> res ss ss ss' args ret
173+ _ -> orig
174+ convert other = other
175+ collectArgs :: Int -> [Text] -> AST -> Maybe ([Text], [AST])
176+ collectArgs 1 acc (Function _ Nothing [oneArg] (Block _ il)) | length acc == n - 1 = Just (reverse (oneArg : acc), il)
177+ collectArgs m acc (Function _ Nothing [oneArg] (Block _ [Return _ ret])) = collectArgs (m - 1) (oneArg : acc) ret
178+ collectArgs _ _ _ = Nothing
179+
180+ isNFn :: Text -> Text -> Int -> AST -> Bool
181+ isNFn expectMod prefix n (Indexer _ (Var _ name) (Var _ modName)) | modName == expectMod =
182+ name == fromString (T.unpack prefix <> show n)
183+ isNFn _ _ _ _ = False
184+
185+ runFn :: Int -> AST -> AST
186+ runFn = runFn' C.dataFunctionUncurried C.runFn (\ss f args ->
187+ let len = length args
188+ typ = mkString $ uncurriedFnType len in
189+ if len > 0
190+ then App ss (App Nothing (StringLiteral Nothing typ) [f]) args
191+ else App ss f args)
192+ runEffFn :: Text -> Text -> Int -> AST -> AST
193+ runEffFn modName fnName = runFn' modName fnName $ \ss fn acc ->
194+ let typ = mkString . uncurriedFnType $ length acc in
195+ Function ss Nothing [] (Block ss [Return ss (App ss (App Nothing (StringLiteral Nothing typ) [fn]) acc)])
196+
197+ runFn' :: Text -> Text -> (Maybe SourceSpan -> AST -> [AST] -> AST) -> Int -> AST -> AST
198+ runFn' modName runFnName res n = convert where
199+ convert :: AST -> AST
200+ convert il = fromMaybe il $ go n [] il
201+
202+ go :: Int -> [AST] -> AST -> Maybe AST
203+ go 0 acc (App ss runFnN [fn]) | isNFn modName runFnName n runFnN && length acc == n =
204+ Just $ res ss fn acc
205+ go m acc (App _ lhs [arg]) = go (m - 1) (arg : acc) lhs
206+ go _ _ _ = Nothing
207+
208+ inlineNonClassFunction :: (AST -> Bool) -> (AST -> AST -> AST) -> AST -> AST
209+ inlineNonClassFunction p f = convert where
210+ convert :: AST -> AST
211+ convert (App _ (App _ op' [x]) [y]) | p op' = f x y
212+ convert other = other
213+
214+ inlineUnsafeIndex :: (AST -> Bool) -> (AST -> AST -> AST) -> AST -> AST
215+ inlineUnsafeIndex p _ = convert where
216+ convert :: AST -> AST
217+ convert (App _ (App ss op' [x]) [y@NumericLiteral{}])
218+ | p op' = Indexer ss y x
219+ convert (App _ (App ss op' [x]) [y])
220+ | p op' = App ss (Var Nothing indexFn) [x, y]
221+ convert other = other
222+
223+ isModFn :: (Text, PSString) -> AST -> Bool
224+ isModFn (m, op) (Indexer _ (Var _ op') (Var _ m')) =
225+ m == m' && decodeString op == Just op'
226+ isModFn _ _ = False
227+
228+ isModFnWithDict :: (Text, PSString) -> AST -> Bool
229+ isModFnWithDict (m, op) (App _ (Indexer _ (Var _ op') (Var _ m')) [Var _ _]) =
230+ m == m' && decodeString op == Just op'
231+ isModFnWithDict _ _ = False
232+
233+-- (f <<< g $ x) = f (g x)
234+-- (f <<< g) = \x -> f (g x)
235+inlineFnComposition :: forall m. MonadSupply m => AST -> m AST
236+inlineFnComposition = everywhereTopDownM convert where
237+ convert :: AST -> m AST
238+ convert (App s1 (App s2 (App _ (App _ fn [dict']) [x]) [y]) [z])
239+ | isFnCompose dict' fn = return $ App s1 x [App s2 y [z]]
240+ | isFnComposeFlipped dict' fn = return $ App s2 y [App s1 x [z]]
241+ convert app@(App ss (App _ (App _ fn [dict']) _) _)
242+ | isFnCompose dict' fn || isFnComposeFlipped dict' fn = mkApps ss <$> goApps app <*> freshName'
243+ convert other = return other
244+
245+ mkApps :: Maybe SourceSpan -> [Either AST (Text, AST)] -> Text -> AST
246+ mkApps ss fns a = App ss (Function ss Nothing [] (Block ss $ vars <> [Return Nothing comp])) []
247+ where
248+ vars = uncurry (VariableIntroduction ss) . fmap Just <$> rights fns
249+ comp = Function ss Nothing [a] (Block ss [Return Nothing apps])
250+ apps = foldr (\fn acc -> App ss (mkApp fn) [acc]) (Var ss a) fns
251+
252+ mkApp :: Either AST (Text, AST) -> AST
253+ mkApp = either id $ \(name, arg) -> Var (getSourceSpan arg) name
254+
255+ goApps :: AST -> m [Either AST (Text, AST)]
256+ goApps (App _ (App _ (App _ fn [dict']) [x]) [y])
257+ | isFnCompose dict' fn = mappend <$> goApps x <*> goApps y
258+ | isFnComposeFlipped dict' fn = mappend <$> goApps y <*> goApps x
259+ goApps app@(App {}) = pure . Right . (,app) <$> freshName'
260+ goApps other = pure [Left other]
261+
262+ isFnCompose :: AST -> AST -> Bool
263+ isFnCompose dict' fn = isDict semigroupoidFn dict' && isDict fnCompose fn
264+
265+ isFnComposeFlipped :: AST -> AST -> Bool
266+ isFnComposeFlipped dict' fn = isDict semigroupoidFn dict' && isDict fnComposeFlipped fn
267+
268+ fnCompose :: forall a b. (IsString a, IsString b) => (a, b)
269+ fnCompose = (C.controlSemigroupoid, C.compose)
270+
271+ fnComposeFlipped :: forall a b. (IsString a, IsString b) => (a, b)
272+ fnComposeFlipped = (C.controlSemigroupoid, C.composeFlipped)
273+
274+inlineUnsafeCoerce :: AST -> AST
275+inlineUnsafeCoerce = everywhereTopDown convert where
276+ convert (App _ (Indexer _ (Var _ unsafeCoerceFn) (Var _ unsafeCoerce)) [ comp ])
277+ | unsafeCoerceFn == C.unsafeCoerceFn && unsafeCoerce == C.unsafeCoerce
278+ = comp
279+ convert other = other
280+
281+inlineUnsafePartial :: AST -> AST
282+inlineUnsafePartial = everywhereTopDown convert where
283+ convert (App ss fn [ comp ])
284+ | isDict fnUnsafePartial fn
285+ = App ss comp []
286+ where
287+ fnUnsafePartial :: forall a b. (IsString a, IsString b) => (a, b)
288+ fnUnsafePartial = (C.partialUnsafe, C.unsafePartial)
289+ convert other = other
290+
291+semiringNumber :: forall a b. (IsString a, IsString b) => (a, b)
292+semiringNumber = (C.dataSemiring, C.semiringNumber)
293+
294+semiringInt :: forall a b. (IsString a, IsString b) => (a, b)
295+semiringInt = (C.dataSemiring, C.semiringInt)
296+
297+ringNumber :: forall a b. (IsString a, IsString b) => (a, b)
298+ringNumber = (C.dataRing, C.ringNumber)
299+
300+ringInt :: forall a b. (IsString a, IsString b) => (a, b)
301+ringInt = (C.dataRing, C.ringInt)
302+
303+euclideanRingNumber :: forall a b. (IsString a, IsString b) => (a, b)
304+euclideanRingNumber = (C.dataEuclideanRing, C.euclideanRingNumber)
305+
306+-- eqNumber :: forall a b. (IsString a, IsString b) => (a, b)
307+-- eqNumber = (C.dataEq, C.eqNumber)
308+
309+eqInt :: forall a b. (IsString a, IsString b) => (a, b)
310+eqInt = (C.dataEq, C.eqInt)
311+
312+eqString :: forall a b. (IsString a, IsString b) => (a, b)
313+eqString = (C.dataEq, C.eqString)
314+
315+eqChar :: forall a b. (IsString a, IsString b) => (a, b)
316+eqChar = (C.dataEq, C.eqChar)
317+
318+eqBoolean :: forall a b. (IsString a, IsString b) => (a, b)
319+eqBoolean = (C.dataEq, C.eqBoolean)
320+
321+ordBoolean :: forall a b. (IsString a, IsString b) => (a, b)
322+ordBoolean = (C.dataOrd, C.ordBoolean)
323+
324+ordNumber :: forall a b. (IsString a, IsString b) => (a, b)
325+ordNumber = (C.dataOrd, C.ordNumber)
326+
327+ordInt :: forall a b. (IsString a, IsString b) => (a, b)
328+ordInt = (C.dataOrd, C.ordInt)
329+
330+ordString :: forall a b. (IsString a, IsString b) => (a, b)
331+ordString = (C.dataOrd, C.ordString)
332+
333+ordChar :: forall a b. (IsString a, IsString b) => (a, b)
334+ordChar = (C.dataOrd, C.ordChar)
335+
336+semigroupString :: forall a b. (IsString a, IsString b) => (a, b)
337+semigroupString = (C.dataSemigroup, C.semigroupString)
338+
339+boundedBoolean :: forall a b. (IsString a, IsString b) => (a, b)
340+boundedBoolean = (C.dataBounded, C.boundedBoolean)
341+
342+heytingAlgebraBoolean :: forall a b. (IsString a, IsString b) => (a, b)
343+heytingAlgebraBoolean = (C.dataHeytingAlgebra, C.heytingAlgebraBoolean)
344+
345+semigroupoidFn :: forall a b. (IsString a, IsString b) => (a, b)
346+semigroupoidFn = (C.controlSemigroupoid, C.semigroupoidFn)
347+
348+opAdd :: forall a b. (IsString a, IsString b) => (a, b)
349+opAdd = (C.dataSemiring, C.add)
350+
351+opMul :: forall a b. (IsString a, IsString b) => (a, b)
352+opMul = (C.dataSemiring, C.mul)
353+
354+opEq :: forall a b. (IsString a, IsString b) => (a, b)
355+opEq = (C.dataEq, C.eq)
356+
357+opNotEq :: forall a b. (IsString a, IsString b) => (a, b)
358+opNotEq = (C.dataEq, C.notEq)
359+
360+opLessThan :: forall a b. (IsString a, IsString b) => (a, b)
361+opLessThan = (C.dataOrd, C.lessThan)
362+
363+opLessThanOrEq :: forall a b. (IsString a, IsString b) => (a, b)
364+opLessThanOrEq = (C.dataOrd, C.lessThanOrEq)
365+
366+opGreaterThan :: forall a b. (IsString a, IsString b) => (a, b)
367+opGreaterThan = (C.dataOrd, C.greaterThan)
368+
369+opGreaterThanOrEq :: forall a b. (IsString a, IsString b) => (a, b)
370+opGreaterThanOrEq = (C.dataOrd, C.greaterThanOrEq)
371+
372+opAppend :: forall a b. (IsString a, IsString b) => (a, b)
373+opAppend = (C.dataSemigroup, C.append)
374+
375+opSub :: forall a b. (IsString a, IsString b) => (a, b)
376+opSub = (C.dataRing, C.sub)
377+
378+opNegate :: forall a b. (IsString a, IsString b) => (a, b)
379+opNegate = (C.dataRing, C.negate)
380+
381+opDiv :: forall a b. (IsString a, IsString b) => (a, b)
382+opDiv = (C.dataEuclideanRing, C.div)
383+
384+opConj :: forall a b. (IsString a, IsString b) => (a, b)
385+opConj = (C.dataHeytingAlgebra, C.conj)
386+
387+opDisj :: forall a b. (IsString a, IsString b) => (a, b)
388+opDisj = (C.dataHeytingAlgebra, C.disj)
389+
390+opNot :: forall a b. (IsString a, IsString b) => (a, b)
391+opNot = (C.dataHeytingAlgebra, C.not)
392+
393+unbox :: AST -> PSString -> AST
394+unbox e d = select . inlineCommonValues $ inlineCommonOperators e
395+ where
396+ select :: AST -> AST
397+ select e' =
398+ case e' of
399+ Var{} -> unbox' e'
400+ App{} -> unbox' e'
401+ Indexer{} -> unbox' e'
402+ _ -> e'
403+ unbox' :: AST -> AST
404+ unbox' e' = maybe e' (\t -> App Nothing (StringLiteral Nothing t) [e']) $ unboxType d
405+
406+unboxType :: PSString -> Maybe PSString
407+unboxType s = do
408+ t <- decodeString s
409+ t' <- unboxType' t
410+ return $ mkString t'
411+ where
412+ unboxType' :: Text -> Maybe Text
413+ unboxType' t
414+ | t == C.eqInt ||
415+ t == C.semiringInt ||
416+ t == C.ringInt ||
417+ t == C.ordInt ||
418+ t == C.dataIntBits
419+ = Just int
420+ | t == C.semiringNumber ||
421+ t == C.ringNumber ||
422+ t == C.ordNumber ||
423+ t == C.euclideanRingNumber
424+ = Just float
425+ | t == C.eqBoolean ||
426+ t == C.ordBoolean ||
427+ t == C.heytingAlgebraBoolean
428+ = Just bool
429+ | t == C.eqChar ||
430+ t == C.eqString ||
431+ t == C.ordChar ||
432+ t == C.ordString ||
433+ t == C.semigroupString
434+ = Just string
435+ | otherwise = Nothing
src/CodeGen/IL/Optimizer/MagicDo.hsnew file+146
@@ -0,0 +1,146 @@
1+-- | This module implements the "Magic Do" optimization, which inlines calls to return
2+-- and bind for the Eff monad, as well as some of its actions.
3+module CodeGen.IL.Optimizer.MagicDo (magicDoEffect, magicDoEff, magicDoST, inlineST) where
4+
5+import Prelude.Compat
6+import Protolude (ordNub)
7+
8+import Data.Maybe (fromJust, isJust)
9+import Data.Text (Text)
10+
11+import Language.PureScript.CoreImp.AST
12+import Language.PureScript.CoreImp.Optimizer.Common hiding (isDict)
13+import Language.PureScript.PSString (PSString, decodeString, mkString)
14+import qualified Language.PureScript.Constants as C
15+
16+import CodeGen.IL.Common (undefinedName, unusedName)
17+import CodeGen.IL.Optimizer.Common
18+
19+-- | Inline type class dictionaries for >>= and return for the Eff monad
20+--
21+-- E.g.
22+--
23+-- Prelude[">>="](dict)(m1)(function(x) {
24+-- return ...;
25+-- })
26+--
27+-- becomes
28+--
29+-- function __do {
30+-- var x = m1();
31+-- ...
32+-- }
33+magicDoEff :: AST -> AST
34+magicDoEff = magicDo C.eff C.effDictionaries
35+
36+magicDoEffect :: AST -> AST
37+magicDoEffect = magicDo C.effect C.effectDictionaries
38+
39+magicDoST :: AST -> AST
40+magicDoST = magicDo C.st C.stDictionaries
41+
42+magicDo :: Text -> C.EffectDictionaries -> AST -> AST
43+magicDo effectModule C.EffectDictionaries{..} = everywhereTopDown convert
44+ where
45+ -- Desugar monomorphic calls to >>= and return for the Eff monad
46+ convert :: AST -> AST
47+ -- Desugar pure
48+ convert (App _ (App _ pure' [val]) []) | isPure pure' = val
49+ -- Desugar discard
50+ convert (App _ (App _ bind [m]) [Function s1 Nothing [unused] (Block s2 il)]) | isDiscard bind && unused == unusedName =
51+ Function s1 Nothing [] $ Block s2 (App s2 m [] : map applyReturns il )
52+ -- Desugar bind
53+ convert (App _ (App _ bind [m]) [Function s1 Nothing [arg] (Block s2 il)]) | isBind bind =
54+ Function s1 Nothing [] $ Block s2 (VariableIntroduction s2 arg (Just (App s2 m [])) : map applyReturns il)
55+ -- Desugar untilE
56+ convert (App s1 (App _ f [arg]) []) | isEffFunc edUntil f =
57+ App s1 (Function s1 Nothing [] (Block s1 [ While s1 (Unary s1 Not (App s1 arg [])) (Block s1 []), Return s1 $ ObjectLiteral s1 []])) []
58+ -- Desugar whileE
59+ convert (App _ (App _ (App s1 f [arg1]) [arg2]) []) | isEffFunc edWhile f =
60+ App s1 (Function s1 Nothing [] (Block s1 [ While s1 (App s1 arg1 []) (Block s1 [ App s1 arg2 [] ]), Return s1 $ ObjectLiteral s1 []])) []
61+ -- -- Inline __do returns
62+ -- convert (Return _ (App _ (Function _ (Just ident) [] body) [])) | ident == fnName = body
63+ -- Inline double applications
64+ convert (App _ (App s1 (Function s2 Nothing [] (Block ss body)) []) []) =
65+ App s1 (Function s2 Nothing [] (Block ss (applyReturns `fmap` body))) []
66+ convert other = other
67+ -- Check if an expression represents a monomorphic call to >>= for the Eff monad
68+ isBind (App _ fn [dict]) | isDict (effectModule, edBindDict) dict && isBindPoly fn = True
69+ isBind _ = False
70+ -- Check if an expression represents a call to @discard@
71+ isDiscard (App _ (App _ fn [dict1]) [dict2])
72+ | isDict (C.controlBind, C.discardUnitDictionary) dict1 &&
73+ isDict (effectModule, edBindDict) dict2 &&
74+ isDiscardPoly fn = True
75+ isDiscard _ = False
76+
77+ -- Check if an expression represents a monomorphic call to pure or return for the Eff applicative
78+ isPure (App _ fn [dict]) | isDict (effectModule, edApplicativeDict) dict && isPurePoly fn = True
79+ isPure _ = False
80+ -- Check if an expression represents the polymorphic >>= function
81+ isBindPoly = isDict (C.controlBind, C.bind)
82+ -- Check if an expression represents the polymorphic pure function
83+ isPurePoly = isDict (C.controlApplicative, C.pure')
84+ -- Check if an expression represents the polymorphic discard function
85+ isDiscardPoly = isDict (C.controlBind, C.discard)
86+ -- Check if an expression represents a function in the Effect module
87+ isEffFunc name (Indexer _ (StringLiteral _ name') (Var _ eff)) = eff == effectModule && name == name'
88+ isEffFunc _ _ = False
89+
90+ applyReturns :: AST -> AST
91+ applyReturns (Return ss ret) = Return ss (App ss ret [])
92+ applyReturns (Block ss ils) = Block ss (map applyReturns ils)
93+ applyReturns (While ss cond il) = While ss cond (applyReturns il)
94+ applyReturns (For ss v lo hi il) = For ss v lo hi (applyReturns il)
95+ applyReturns (ForIn ss v xs il) = ForIn ss v xs (applyReturns il)
96+ applyReturns (IfElse ss cond t f) = IfElse ss cond (applyReturns t) (applyReturns `fmap` f)
97+ applyReturns other = other
98+
99+-- | Inline functions in the ST module
100+inlineST :: AST -> AST
101+inlineST = everywhere convertBlock
102+ where
103+ -- Look for runST blocks and inline the STRefs there.
104+ -- If all STRefs are used in the scope of the same runST, only using { read, write, modify }STRef then
105+ -- we can be more aggressive about inlining, and actually turn STRefs into local variables.
106+ convertBlock (App s1 f [arg]) | isSTFunc C.runST f =
107+ let refs = ordNub . findSTRefsIn $ arg
108+ usages = findAllSTUsagesIn arg
109+ allUsagesAreLocalVars = all (\u -> let v = toVar u in isJust v && fromJust v `elem` refs) usages
110+ localVarsDoNotEscape = all (\r -> length (r `appearingIn` arg) == length (filter (\u -> let v = toVar u in v == Just r) usages)) refs
111+ in App s1 (everywhere (convert (allUsagesAreLocalVars && localVarsDoNotEscape)) arg) []
112+ convertBlock other = other
113+ -- Convert a block in a safe way, preserving object wrappers of references,
114+ -- or in a more aggressive way, turning wrappers into local variables depending on the
115+ -- agg(ressive) parameter.
116+ convert agg (App s1 f [arg]) | isSTFunc C.newSTRef f =
117+ Function s1 Nothing [] (Block s1 [Return s1 $ if agg then arg else ObjectLiteral s1 [(mkString C.stRefValue, arg)]])
118+ convert agg (App _ (App s1 f [ref]) []) | isSTFunc C.readSTRef f =
119+ if agg then ref else Indexer s1 (StringLiteral s1 C.stRefValue) ref
120+ convert agg (App _ (App _ (App s1 f [arg]) [ref]) []) | isSTFunc C.writeSTRef f =
121+ if agg then Assignment s1 ref arg else Assignment s1 (Indexer s1 (StringLiteral s1 C.stRefValue) ref) arg
122+ convert agg (App _ (App _ (App s1 f [func]) [ref]) []) | isSTFunc C.modifySTRef f =
123+ if agg then Assignment s1 ref (App s1 func [ref]) else Assignment s1 (Indexer s1 (StringLiteral s1 C.stRefValue) ref) (App s1 func [Indexer s1 (StringLiteral s1 C.stRefValue) ref])
124+ convert _ other = other
125+ -- Check if an expression represents a function in the ST module
126+ isSTFunc name (Indexer _ (StringLiteral _ name') (Var _ st)) = st == C.st && name == name'
127+ isSTFunc _ _ = False
128+ -- Find all ST Refs initialized in this block
129+ findSTRefsIn = everything (++) isSTRef
130+ where
131+ isSTRef (VariableIntroduction _ ident (Just (App _ (App _ f [_]) []))) | isSTFunc C.newSTRef f = [ident]
132+ isSTRef _ = []
133+ -- Find all STRefs used as arguments to readSTRef, writeSTRef, modifySTRef
134+ findAllSTUsagesIn = everything (++) isSTUsage
135+ where
136+ isSTUsage (App _ (App _ f [ref]) []) | isSTFunc C.readSTRef f = [ref]
137+ isSTUsage (App _ (App _ (App _ f [_]) [ref]) []) | isSTFunc C.writeSTRef f || isSTFunc C.modifySTRef f = [ref]
138+ isSTUsage _ = []
139+ -- Find all uses of a variable
140+ appearingIn ref = everything (++) isVar
141+ where
142+ isVar e@(Var _ v) | v == ref = [e]
143+ isVar _ = []
144+ -- Convert a AST value to a String if it is a Var
145+ toVar (Var _ v) = Just v
146+ toVar _ = Nothing
src/CodeGen/IL/Optimizer/TCO.hsnew file+141
@@ -0,0 +1,141 @@
1+module CodeGen.IL.Optimizer.TCO (tco, tcoLoop) where
2+
3+import Prelude.Compat
4+
5+import Data.Text (Text)
6+import Data.Monoid ((<>))
7+import Language.PureScript.CoreImp.AST
8+import Language.PureScript.AST.SourcePos (SourceSpan)
9+import Safe (headDef, tailSafe)
10+import CodeGen.IL.Common
11+
12+import qualified Language.PureScript.Constants as C
13+
14+tcoLoop :: Text
15+tcoLoop = "ṩtco_loop"
16+
17+tco :: AST -> AST -> AST
18+tco mn = everywhere convert where
19+ tcoVar :: Text -> Text
20+ tcoVar arg = "ṩtco_var_" <> arg
21+
22+ copyVar :: Text -> Text
23+ copyVar arg = "ṩcopy_" <> arg
24+
25+ tcoDone :: Text
26+ tcoDone = "ṩtco_done"
27+
28+ tcoResult :: Text
29+ tcoResult = "ṩtco_result"
30+
31+ convert :: AST -> AST
32+ convert fn@(Function ss (Just name) args _)
33+ | isTailRecursive name body'
34+ = replace (toLoop name outerArgs innerArgs body')
35+ where
36+ innerArgs = headDef [] argss
37+ outerArgs = concat . reverse $ tailSafe argss
38+ (argss, body', replace) = collectAllFunctionArgs [] id fn
39+ convert (Assignment ss (Var _ name) fn@(Function _ Nothing _ _))
40+ | isTailRecursive name body'
41+ = Assignment ss (Var ss name) (replace (toLoop name outerArgs innerArgs body'))
42+ where
43+ innerArgs = headDef [] argss
44+ outerArgs = concat . reverse $ tailSafe argss
45+ (argss, body', replace) = collectAllFunctionArgs [] id fn
46+ convert js = js
47+
48+ collectAllFunctionArgs :: [[Text]] -> (AST -> AST) -> AST -> ([[Text]], AST, AST -> AST)
49+ collectAllFunctionArgs allArgs f (Function s1 ident args (Block s2 (body@(Return _ _):_))) =
50+ collectAllFunctionArgs (args : allArgs) (\b -> f (Function s1 ident (map copyVar args) (Block s2 [b]))) body
51+ collectAllFunctionArgs allArgs f (Function ss ident args body@(Block _ _)) =
52+ (args : allArgs, body, f . Function ss ident (map copyVar args))
53+ collectAllFunctionArgs allArgs f (Return s1 (Function s2 ident args (Block s3 [body]))) =
54+ collectAllFunctionArgs (args : allArgs) (\b -> f (Return s1 (Function s2 ident (map copyVar args) (Block s3 [b])))) body
55+ collectAllFunctionArgs allArgs f (Return s1 (Function s2 ident args body@(Block _ _))) =
56+ (args : allArgs, body, f . Return s1 . Function s2 ident (map copyVar args))
57+ collectAllFunctionArgs allArgs f body = (allArgs, body, f)
58+
59+ isTailRecursive :: Text -> AST -> Bool
60+ isTailRecursive ident js = countSelfReferences js > 0 && allInTailPosition js where
61+ countSelfReferences = everything (+) match where
62+ match :: AST -> Int
63+ match (Var _ ident') | ident == ident' = 1
64+ match _ = 0
65+
66+ allInTailPosition (Return _ expr)
67+ | isSelfCall ident expr = countSelfReferences expr == 1
68+ | otherwise = countSelfReferences expr == 0
69+ allInTailPosition (While _ js1 body)
70+ = countSelfReferences js1 == 0 && allInTailPosition body
71+ allInTailPosition (For _ _ js1 js2 body)
72+ = countSelfReferences js1 == 0 && countSelfReferences js2 == 0 && allInTailPosition body
73+ allInTailPosition (ForIn _ _ js1 body)
74+ = countSelfReferences js1 == 0 && allInTailPosition body
75+ allInTailPosition (IfElse _ js1 body el)
76+ = countSelfReferences js1 == 0 && allInTailPosition body && all allInTailPosition el
77+ allInTailPosition (Block _ body)
78+ = all allInTailPosition body
79+ allInTailPosition (Throw _ js1)
80+ = countSelfReferences js1 == 0
81+ allInTailPosition (ReturnNoResult _)
82+ = True
83+ allInTailPosition (VariableIntroduction _ _ js1)
84+ = all ((== 0) . countSelfReferences) js1
85+ allInTailPosition (Assignment _ _ js1)
86+ = countSelfReferences js1 == 0
87+ allInTailPosition (Comment _ _ js1)
88+ = allInTailPosition js1
89+ allInTailPosition _
90+ = False
91+
92+ toLoop :: Text -> [Text] -> [Text] -> AST -> AST
93+ toLoop ident outerArgs innerArgs js =
94+ Block rootSS $
95+ concatMap (\arg -> [ VariableIntroduction rootSS (tcoVar arg) . Just $
96+ Var rootSS (copyVar arg) ]) (outerArgs ++ innerArgs) ++
97+ [ Assignment rootSS (Var rootSS $ "var " <> tcoDone) $ BooleanLiteral Nothing False
98+ , VariableIntroduction rootSS tcoResult Nothing
99+ , Assignment rootSS (Var rootSS $ "var " <> tcoLoop) (Function rootSS (Just tcoLoop) (outerArgs ++ innerArgs) (Block rootSS [loopify js]))
100+ , While rootSS (Unary Nothing Not (Var rootSS tcoDone))
101+ (Block rootSS
102+ [(Assignment rootSS (Var rootSS tcoResult) (App rootSS (Var rootSS tcoLoop) ((map (Var rootSS . tcoVar) outerArgs) ++ (map (Var rootSS . copyVar) innerArgs))))])
103+ , Return rootSS (Var rootSS tcoResult)
104+ ]
105+ where
106+ rootSS = Nothing
107+
108+ loopify :: AST -> AST
109+ loopify (Return ss ret)
110+ | isSelfCall ident ret =
111+ let
112+ allArgumentValues = concat $ collectArgs [] ret
113+ in
114+ Block ss $
115+ zipWith (\val arg ->
116+ Assignment ss (Var ss (tcoVar arg)) val) allArgumentValues outerArgs
117+ ++ zipWith (\val arg ->
118+ Assignment ss (Var ss (copyVar arg)) val) (drop (length outerArgs) allArgumentValues) innerArgs
119+ ++ [ ReturnNoResult ss ]
120+ | otherwise = Block ss [ markDone ss, Return ss ret ]
121+ loopify (ReturnNoResult ss) = Block ss [ markDone ss, ReturnNoResult ss ]
122+ loopify (While ss cond body) = While ss cond (loopify body)
123+ loopify (For ss i js1 js2 body) = For ss i js1 js2 (loopify body)
124+ loopify (ForIn ss i js1 body) = ForIn ss i js1 (loopify body)
125+ loopify (IfElse ss cond body el) = IfElse ss cond (loopify body) (fmap loopify el)
126+ loopify (Block ss body) = Block ss (map loopify body)
127+ loopify other = other
128+
129+ markDone :: Maybe SourceSpan -> AST
130+ markDone ss = Assignment ss (Var ss tcoDone) (BooleanLiteral ss True)
131+
132+ collectArgs :: [[AST]] -> AST -> [[AST]]
133+ collectArgs acc (App _ fn args') = collectArgs (args' : acc) fn
134+ collectArgs acc _ = acc
135+
136+ isSelfCall :: Text -> AST -> Bool
137+ isSelfCall ident (App _ (Var _ ident') _) = ident == ident'
138+ isSelfCall ident (App _ (Indexer _ (Var _ ident') (Var _ mn')) _) = mn' == "" && ident == ident'
139+ isSelfCall ident (App _ (Indexer _ (Var _ ident') mn') _) = mn' == mn && ident == ident'
140+ isSelfCall ident (App _ fn _) = isSelfCall ident fn
141+ isSelfCall _ _ = False
src/CodeGen/IL/Printer.hsnew file+527
@@ -0,0 +1,527 @@
1+-- | Pretty printer for the AST
2+module CodeGen.IL.Printer
3+ ( prettyPrintIL
4+ , prettyPrintIL1
5+ , prettyPrintILWithSourceMaps
6+ , interfaceSource
7+ , implHeaderSource
8+ , implFooterSource
9+ , isLiteral
10+ , modLabel
11+ , modPrefix
12+ , ffiLoader
13+ ) where
14+
15+import Prelude.Compat
16+
17+import Control.Arrow ((<+>))
18+import Control.Monad (forM, mzero)
19+import Control.Monad.State (StateT, evalStateT)
20+import Control.PatternArrows
21+import Data.List (filter, (\\))
22+import qualified Control.Arrow as A
23+
24+import Data.Maybe (fromMaybe)
25+import Data.Monoid ((<>))
26+import Data.Text (Text)
27+import qualified Data.Text as T
28+
29+import Language.PureScript.AST (SourceSpan(..))
30+import Language.PureScript.CoreImp.AST
31+import Language.PureScript.Comments
32+import Language.PureScript.Crash
33+import Language.PureScript.Names (Ident, runIdent)
34+import Language.PureScript.Pretty.Common
35+import Language.PureScript.PSString (PSString, decodeString, mkString)
36+
37+import CodeGen.IL.Common
38+import CodeGen.IL.Optimizer.TCO (tcoLoop)
39+
40+import qualified Language.PureScript.Constants as C
41+
42+-- TODO (Christoph): Get rid of T.unpack / pack
43+
44+literals :: (Emit gen) => Pattern PrinterState AST gen
45+literals = mkPattern' match'
46+ where
47+ match' :: (Emit gen) => AST -> StateT PrinterState Maybe gen
48+ match' il = (addMapping' (getSourceSpan il) <>) <$> match il
49+
50+ match :: (Emit gen) => AST -> StateT PrinterState Maybe gen
51+ match (NumericLiteral _ n) = return $ emit $ T.pack $ either show show n
52+ match (StringLiteral _ s) = return $ emit $ stringLiteral s
53+ match (BooleanLiteral _ True) = return $ emit "true"
54+ match (BooleanLiteral _ False) = return $ emit "false"
55+ match (ArrayLiteral _ xs) = mconcat <$> sequence
56+ [ return . emit $ arrayType <> "{"
57+ , intercalate (emit ", ") <$> forM xs prettyPrintIL'
58+ , return $ emit "}"
59+ ]
60+ -- match (ObjectLiteral _ []) = return $ emit "std::initializer_list<std::pair<const string, boxed>>{}"
61+ match (ObjectLiteral _ ps) = mconcat <$> sequence
62+ [ return . emit $ dictType <> "{"
63+ , withIndent $ do
64+ ils <- forM ps $ \(key, value) -> do
65+ value' <- prettyPrintIL' value
66+ return $ objectPropertyToString key <> value'
67+ return $ intercalate (emit " ") $ map (<> emit ",") ils
68+ , return $ emit "}"
69+ ]
70+ where
71+ objectPropertyToString :: (Emit gen) => PSString -> gen
72+ objectPropertyToString s = emit $ stringLiteral s <> ": "
73+ match (Block _ sts) = mconcat <$> sequence
74+ [ return $ emit "{\n"
75+ , withIndent $ prettyStatements sts
76+ , return $ emit "\n"
77+ , currentIndent
78+ , return $ emit "}"
79+ ]
80+ match (Var _ ident) | ident == C.undefined = return $ emit undefinedName
81+ match (Var _ ident) = return $ emit ident
82+ match (VariableIntroduction _ ident value) = mconcat <$> sequence
83+ [ return . emit $ varDecl <> " " <> ident <> " " <> anyType
84+ , maybe (return mempty) (fmap (emit " = " <>) . prettyPrintIL') value
85+ ]
86+ match (Assignment _ target value) = mconcat <$> sequence
87+ [ prettyPrintIL' target
88+ , return $ emit " = "
89+ , prettyPrintIL' value
90+ ]
91+ match (App _ val []) = mconcat <$> sequence
92+ [ return $ emit "Run("
93+ , prettyPrintIL' val
94+ , return $ emit ")"
95+ ]
96+ match (App _ (StringLiteral _ u) [arg])
97+ | Just ty <- decodeString u = mconcat <$> sequence
98+ [ prettyPrintIL' arg
99+ , return $ emit ".("
100+ , return $ emit ty
101+ , return $ emit ")"
102+ ]
103+ match (App _ (Var _ fn) [arg]) | fn == arrayLengthFn = mconcat <$> sequence
104+ [ return $ emit fn
105+ , return $ emit "("
106+ , prettyPrintIL' arg
107+ , return $ emit ")"
108+ ]
109+ match (App _ (Var _ fn) args) | fn == indexFn = mconcat <$> sequence
110+ [ return $ emit fn
111+ , return $ emit "("
112+ , intercalate (emit ", ") <$> forM args prettyPrintIL'
113+ , return $ emit ")"
114+ ]
115+ match (App _ (Var _ fn) args) | fn == tcoLoop = mconcat <$> sequence
116+ [ return $ emit fn
117+ , return $ emit "("
118+ , intercalate (emit ", ") <$> forM args prettyPrintIL'
119+ , return $ emit ")"
120+ ]
121+ match (App _ (App Nothing (StringLiteral Nothing fnx) [fn@Function{}]) args)
122+ | Just ftype <- decodeString fnx
123+ , "Fn" `T.isPrefixOf` ftype = mconcat <$> sequence
124+ [ prettyPrintIL' fn
125+ , return $ emit "("
126+ , intercalate (emit ", ") <$> forM args prettyPrintIL'
127+ , return $ emit ")"
128+ ]
129+ match (App _ (App Nothing (StringLiteral Nothing fnx) [fn]) args)
130+ | Just ftype <- decodeString fnx
131+ , "Fn" `T.isPrefixOf` ftype = mconcat <$> sequence
132+ [ prettyPrintIL' fn
133+ , return $ emit ".("
134+ , return $ emit ftype
135+ , return $ emit ")("
136+ , intercalate (emit ", ") <$> forM args prettyPrintIL'
137+ , return $ emit ")"
138+ ]
139+ match app@(App{})
140+ | (val, args) <- unApp app []
141+ , length args > 1
142+ = mconcat <$> sequence
143+ [ return $ emit "Apply("
144+ , prettyPrintIL' val
145+ , return $ emit ", "
146+ , intercalate (emit ", ") <$> forM args prettyPrintIL'
147+ , return $ emit ")"
148+ ]
149+ match (App _ val args) = mconcat <$> sequence
150+ [ return $ emit "Apply("
151+ , prettyPrintIL' val
152+ , return $ emit ", "
153+ , intercalate (emit ", ") <$> forM args prettyPrintIL'
154+ , return $ emit ")"
155+ ]
156+ match (Function _ (Just name) [] (Block _ [Return _ ret]))
157+ | isComplexLiteral ret = mconcat <$> sequence
158+ [ return $ emit "\n"
159+ , return . emit $ varDecl <> " " <> initName name <> " Once\n"
160+ , prettyPrintIL' $ VariableIntroduction Nothing (valueName name) Nothing
161+ , return $ emit "\n\n"
162+ , return $ emit "func "
163+ , return . emit $ withPrefix name
164+ , return . emit $ "() " <> anyType <> " "
165+ , return $ emit "{\n"
166+ , withIndent $ do
167+ indentString <- currentIndent
168+ return $ indentString <> (emit $ initName name <> ".Do(func() {\n") <>
169+ indentString <> indentString <> (emit $ valueName name <> " = ")
170+ , withIndent $ do
171+ case ret of
172+ Function _ Nothing args body -> mconcat <$> sequence
173+ [ return $ emit "func("
174+ , return . emit $ intercalate ", " (renderArg anyType <$> args)
175+ , return . emit $ ") " <> anyType <> " "
176+ , prettyPrintIL' body
177+ ]
178+ _ -> do
179+ prettyPrintIL' ret
180+ , return $ emit "\n"
181+ , withIndent $ do
182+ indentString <- currentIndent
183+ return $ indentString <> (emit $ "})\n" <> "return " <> valueName name <>"\n")
184+ , return $ emit "}\n\n"
185+ ]
186+ match (Function _ (Just name) [] ret) = mconcat <$> sequence
187+ [ return $ emit "func "
188+ , return . emit $ withPrefix name
189+ , return . emit $ "() " <> anyType <> " "
190+ , prettyPrintIL' ret
191+ ]
192+ match (Function _ _ args ret) = mconcat <$> sequence
193+ [ return $ emit "func("
194+ , return . emit $ intercalate ", " (renderArg anyType <$> args)
195+ , return . emit $ ") " <> anyType <> " "
196+ , prettyPrintIL' ret
197+ ]
198+ match (Indexer _ (Var _ name) (Var _ "")) = mconcat <$> sequence
199+ [ prettyPrintIL' (Var Nothing $ withPrefix name)
200+ , return $ emit "()"
201+ ]
202+ match (Indexer _ (Var _ name) val) = mconcat <$> sequence
203+ [ prettyPrintIL' val
204+ , return $ emit "."
205+ , prettyPrintIL' (Var Nothing $ withPrefix name)
206+ , return $ emit "()"
207+ ]
208+ match (Indexer _ prop@StringLiteral{} val@ObjectLiteral{}) = mconcat <$> sequence
209+ [ prettyPrintIL' val
210+ , return $ emit "["
211+ , prettyPrintIL' prop
212+ , return $ emit "]"
213+ ]
214+ match (Indexer _ prop@StringLiteral{} val) = mconcat <$> sequence
215+ [ prettyPrintIL' val
216+ , return $ emit ".("
217+ , return $ emit dictType
218+ , return $ emit ")["
219+ , prettyPrintIL' prop
220+ , return $ emit "]"
221+ ]
222+ match (Indexer _ index val@ArrayLiteral{}) = mconcat <$> sequence
223+ [ prettyPrintIL' val
224+ , return $ emit "["
225+ , prettyPrintIL' index
226+ , return $ emit "]"
227+ ]
228+ match (Indexer _ index val) = mconcat <$> sequence
229+ [ prettyPrintIL' val
230+ , return $ emit ".("
231+ , return $ emit arrayType
232+ , return $ emit ")["
233+ , prettyPrintIL' index
234+ , return $ emit "]"
235+ ]
236+ match (InstanceOf _ val ty) = mconcat <$> sequence
237+ [ return $ emit "Is("
238+ , prettyPrintIL' val
239+ , return $ emit ", "
240+ , prettyPrintIL' ty
241+ , return $ emit ")"
242+ ]
243+ match (While _ cond sts) = mconcat <$> sequence
244+ [ return $ emit "for "
245+ , prettyPrintIL' cond
246+ , return $ emit " "
247+ , prettyPrintIL' sts
248+ ]
249+ match (For _ ident start end sts) = mconcat <$> sequence
250+ [ return $ emit $ "for var " <> ident <> " = "
251+ , prettyPrintIL' start
252+ , return $ emit $ "; " <> ident <> " < "
253+ , prettyPrintIL' end
254+ , return $ emit $ "; " <> ident <> "++ "
255+ , prettyPrintIL' sts
256+ ]
257+ match (ForIn _ ident obj sts) = mconcat <$> sequence
258+ [ return $ emit $ "for var " <> ident <> " in "
259+ , prettyPrintIL' obj
260+ , return $ emit " "
261+ , prettyPrintIL' sts
262+ ]
263+ match (IfElse _ (Binary _ EqualTo cond@Binary{} (BooleanLiteral Nothing True)) thens elses) = mconcat <$> sequence
264+ [ return $ emit "if "
265+ , prettyPrintIL' cond
266+ , return $ emit " "
267+ , prettyPrintIL' thens
268+ , maybe (return mempty) (fmap (emit " else " <>) . prettyPrintIL') elses
269+ ]
270+ match (IfElse _ (Binary _ EqualTo cond@Binary{} (BooleanLiteral Nothing False)) thens elses) = mconcat <$> sequence
271+ [ return $ emit "if !("
272+ , prettyPrintIL' cond
273+ , return $ emit ") "
274+ , prettyPrintIL' thens
275+ , maybe (return mempty) (fmap (emit " else " <>) . prettyPrintIL') elses
276+ ]
277+ match (IfElse _ cond thens elses) = mconcat <$> sequence
278+ [ return $ emit "if "
279+ , prettyPrintIL' cond
280+ , return $ emit " "
281+ , prettyPrintIL' thens
282+ , maybe (return mempty) (fmap (emit " else " <>) . prettyPrintIL') elses
283+ ]
284+ match (Return _ value) = mconcat <$> sequence
285+ [ return $ emit "return "
286+ , prettyPrintIL' value
287+ ]
288+ match (ReturnNoResult _) = return . emit $ "return " <> undefinedName
289+ -- match (Throw _ _) = return mempty
290+ match (Throw _ value) = mconcat <$> sequence
291+ [ return $ emit "panic("
292+ , prettyPrintIL' value
293+ , return $ emit ")"
294+ ]
295+ match (Comment _ com il) = mconcat <$> sequence
296+ [ return $ emit "\n"
297+ , mconcat <$> forM com comment
298+ , prettyPrintIL' il
299+ ]
300+ match _ = mzero
301+
302+ comment :: (Emit gen) => Comment -> StateT PrinterState Maybe gen
303+ comment (LineComment com) = fmap mconcat $ sequence $
304+ [ currentIndent
305+ , return $ emit "//" <> emit com <> emit "\n"
306+ ]
307+ comment (BlockComment com) = fmap mconcat $ sequence $
308+ [ currentIndent
309+ , return $ emit "/**\n"
310+ ] ++
311+ map asLine (T.lines com) ++
312+ [ currentIndent
313+ , return $ emit " */\n"
314+ , currentIndent
315+ ]
316+ where
317+ asLine :: (Emit gen) => Text -> StateT PrinterState Maybe gen
318+ asLine s = do
319+ i <- currentIndent
320+ return $ i <> emit " * " <> (emit . removeComments) s <> emit "\n"
321+
322+ removeComments :: Text -> Text
323+ removeComments t =
324+ case T.stripPrefix "*/" t of
325+ Just rest -> removeComments rest
326+ Nothing -> case T.uncons t of
327+ Just (x, xs) -> x `T.cons` removeComments xs
328+ Nothing -> ""
329+
330+unary' :: (Emit gen) => UnaryOperator -> (AST -> Text) -> Operator PrinterState AST gen
331+unary' op mkStr = Wrap match (<>)
332+ where
333+ match :: (Emit gen) => Pattern PrinterState AST (gen, AST)
334+ match = mkPattern match'
335+ where
336+ match' (Unary _ op' val) | op' == op = Just (emit $ mkStr val, val)
337+ match' _ = Nothing
338+
339+unary :: (Emit gen) => UnaryOperator -> Text -> Operator PrinterState AST gen
340+unary op str = unary' op (const str)
341+
342+negateOperator :: (Emit gen) => Operator PrinterState AST gen
343+negateOperator = unary' Negate (\v -> if isNegate v then "- " else "-")
344+ where
345+ isNegate (Unary _ Negate _) = True
346+ isNegate _ = False
347+
348+binary :: (Emit gen) => BinaryOperator -> Text -> Operator PrinterState AST gen
349+binary op str = AssocL match (\v1 v2 -> v1 <> emit (" " <> str <> " ") <> v2)
350+ where
351+ match :: Pattern PrinterState AST (AST, AST)
352+ match = mkPattern match'
353+ where
354+ match' (Binary _ op' v1 v2) | op' == op = Just (v1, v2)
355+ match' _ = Nothing
356+
357+isLiteral :: AST -> Bool
358+isLiteral Function{} = True
359+isLiteral NumericLiteral{} = True
360+isLiteral StringLiteral{} = True
361+isLiteral BooleanLiteral{} = True
362+isLiteral ObjectLiteral{} = True
363+isLiteral ArrayLiteral{} = True
364+isLiteral _ = False
365+
366+isComplexLiteral :: AST -> Bool
367+-- isComplexLiteral Function{} = True
368+isComplexLiteral ObjectLiteral{} = True
369+isComplexLiteral ArrayLiteral{} = True
370+isComplexLiteral _ = False
371+
372+unApp :: AST -> [AST] -> (AST, [AST])
373+unApp (App _ val [arg]) args = unApp val (arg : args)
374+unApp other args = (other, args)
375+
376+prettyStatements :: (Emit gen) => [AST] -> StateT PrinterState Maybe gen
377+prettyStatements sts = do
378+ ils <- forM sts prettyPrintIL'
379+ indentString <- currentIndent
380+ return $ intercalate (emit "\n") $ map (indentString <>) ils
381+
382+-- | Generate a pretty-printed string representing a collection of C++ expressions at the same indentation level
383+prettyPrintILWithSourceMaps :: [AST] -> (Text, [SMap])
384+prettyPrintILWithSourceMaps il =
385+ let StrPos (_, s, mp) = (fromMaybe (internalError "Incomplete pattern") . flip evalStateT (PrinterState 0) . prettyStatements) il
386+ in (s, mp)
387+
388+prettyPrintIL :: [AST] -> Text
389+prettyPrintIL = maybe (internalError "Incomplete pattern") runPlainString . flip evalStateT (PrinterState 0) . prettyStatements
390+
391+-- | Generate an indented, pretty-printed string representing a C++ expression
392+prettyPrintIL' :: (Emit gen) => AST -> StateT PrinterState Maybe gen
393+prettyPrintIL' = A.runKleisli $ runPattern matchValue
394+ where
395+ matchValue :: (Emit gen) => Pattern PrinterState AST gen
396+ matchValue = buildPrettyPrinter operators (literals <+> fmap parensPos matchValue)
397+ operators :: (Emit gen) => OperatorTable PrinterState AST gen
398+ operators =
399+ OperatorTable [ [ unary New "?" ]
400+ , [ unary Not "!"
401+ , unary BitwiseNot "~"
402+ , unary Positive "+"
403+ , negateOperator ]
404+ , [ binary Multiply "*"
405+ , binary Divide "/"
406+ , binary Modulus "%" ]
407+ , [ binary Add "+"
408+ , binary Subtract "-" ]
409+ , [ binary ShiftLeft "<<"
410+ , binary ShiftRight ">>" ]
411+ , [ binary LessThan "<"
412+ , binary LessThanOrEqualTo "<="
413+ , binary GreaterThan ">"
414+ , binary GreaterThanOrEqualTo ">=" ]
415+ , [ binary EqualTo "=="
416+ , binary NotEqualTo "!=" ]
417+ , [ binary BitwiseAnd "&" ]
418+ , [ binary BitwiseXor "^" ]
419+ , [ binary BitwiseOr "|" ]
420+ , [ binary And "&&" ]
421+ , [ binary Or "||" ]
422+ ]
423+
424+prettyPrintIL1 :: AST -> Text
425+prettyPrintIL1 = maybe (internalError "Incomplete pattern") runPlainString . flip evalStateT (PrinterState 0) . prettyPrintIL'
426+
427+stringLiteral :: PSString -> Text
428+stringLiteral pss | Just s <- decodeString pss = stringLiteral' s
429+ where
430+ stringLiteral' :: Text -> Text
431+ stringLiteral' s = "\"" <> T.concatMap encodeChar s <> "\""
432+ encodeChar :: Char -> Text
433+ encodeChar '\0' = "\\x00"
434+ encodeChar '\b' = "\\b"
435+ encodeChar '\t' = "\\t"
436+ encodeChar '\n' = "\\n"
437+ encodeChar '\v' = "\\v"
438+ encodeChar '\f' = "\\f"
439+ encodeChar '\r' = "\\r"
440+ encodeChar '"' = "\\\""
441+ encodeChar '\\' = "\\\\"
442+ encodeChar c = T.singleton $ c
443+stringLiteral _ = "\"\\uFFFD\""
444+
445+interfaceSource :: Text -> [(Text,Bool)] -> [Ident] -> Text
446+interfaceSource _ _ _ = ""
447+
448+implHeaderSource :: Text -> [Text] -> Text -> Text
449+implHeaderSource mn imports otherPrefix =
450+ "// Code generated by psgo. DO NOT EDIT.\n\n" <>
451+ "package " <> (if mn == "Main" || mn == "Test_Main" then "main" else mn) <> "\n\n" <>
452+ "import . \"" <> runtime <> "\"\n" <>
453+ (if mn == "Main" || mn == "Test_Main"
454+ then "import _ \"" <> otherPrefix <> "/" <> ffiLoader <> "\"\n"
455+ else "\n") <>
456+ "import (\n" <>
457+ (T.concat $ formatImport <$> imports) <> ")\n\n" <>
458+ "type _ = Any\n\n"
459+ where
460+ formatImport :: Text -> Text
461+ formatImport s =
462+ "\t\"" <> otherPrefix <> "/" <> modPrefix <> "/" <> moduleRenamer s <> "\"\n"
463+ moduleRenamer :: Text -> Text
464+ moduleRenamer s
465+ | (s', sfx) <- T.breakOn moduleRenamerMarker s,
466+ not $ T.null sfx = s'
467+ moduleRenamer s = s
468+
469+implFooterSource :: Text -> [Ident] -> Text
470+implFooterSource mn foreigns =
471+ "\n\n\n" <>
472+ (if null foreigns
473+ then ""
474+ else ("// Foreign values\n\n" <>
475+ "var " <> foreignDict <> " = "<> foreignMod <> "(\"" <> mn <> "\")\n\n" <>
476+ (T.concat $ (\foreign' ->
477+ let name = moduleIdentToIL foreign' in
478+ varDecl <> " " <> initName name <> " Once\n" <>
479+ varDecl <> " " <> valueName name <> " " <> anyType <> "\n\n" <>
480+ "func " <>
481+ withPrefix name <>
482+ "() Any { \n" <>
483+ " " <> initName name <> ".Do(func() {\n" <>
484+ " " <> valueName name <> " = " <>
485+ "Get(" <> foreignDict <> ", " <>
486+ (stringLiteral . mkString $ runIdent foreign') <> ")\n" <>
487+ " })\n" <>
488+ " return " <> valueName name <> "\n" <>
489+ "}\n\n") <$> foreigns))) <>
490+ if mn == "Main" || mn == "Test.Main" then mainSource else "\n"
491+ where
492+ mainSource :: Text
493+ mainSource = "\
494+ \func main() {\n\
495+ \ Run(Ꞌmain())\n\
496+ \}\n\n\
497+ \"
498+
499+varDecl :: Text
500+varDecl = "var"
501+
502+renderArg :: Text -> Text -> Text
503+renderArg decl arg = arg <> " " <> decl
504+
505+foreignMod :: Text
506+foreignMod = "Foreign"
507+
508+foreignDict :: Text
509+foreignDict = "foreign"
510+
511+modLabel :: Text
512+modLabel = "purescript-native"
513+
514+modPrefix :: Text
515+modPrefix = modLabel <> "/output"
516+
517+runtime :: Text
518+runtime = "github.com/" <> modLabel <> "/go-runtime"
519+
520+ffiLoader :: Text
521+ffiLoader = modLabel <> "/ffi-loader"
522+
523+initName :: Text -> Text
524+initName s = "ᛌ" <> s <> "_once"
525+
526+valueName :: Text -> Text
527+valueName s = "ᛧ" <> s
src/Control/Monad/Logger.hsdeleted−72
@@ -1,72 +0,0 @@
1−-----------------------------------------------------------------------------
2−--
3−-- Module : Control.Monad.Logger
4−-- Author : Phil Freeman
5−-- License : MIT (http://opensource.org/licenses/MIT)
6−--
7−-- Maintainer : Phil Freeman <paf31@cantab.net>
8−-- Stability : experimental
9−-- Portability :
10−--
11−-- | A replacement for WriterT IO which uses mutable references.
12−--
13−-----------------------------------------------------------------------------
14−
15−{-# LANGUAGE FlexibleInstances #-}
16−{-# LANGUAGE MultiParamTypeClasses #-}
17−{-# LANGUAGE TypeFamilies #-}
18−
19−module Control.Monad.Logger where
20−
21−import Prelude ()
22−import Prelude.Compat
23−
24−import Data.IORef
25−
26−import Control.Monad (ap)
27−import Control.Monad.IO.Class
28−import Control.Monad.Writer.Class
29−import Control.Monad.Base (MonadBase(..))
30−import Control.Monad.Trans.Control (MonadBaseControl(..))
31−
32−-- | A replacement for WriterT IO which uses mutable references.
33−newtype Logger w a = Logger { runLogger :: IORef w -> IO a }
34−
35−-- | Run a Logger computation, starting with an empty log.
36−runLogger' :: (Monoid w) => Logger w a -> IO (a, w)
37−runLogger' l = do
38− r <- newIORef mempty
39− a <- runLogger l r
40− w <- readIORef r
41− return (a, w)
42−
43−instance Functor (Logger w) where
44− fmap f (Logger l) = Logger $ \r -> fmap f (l r)
45−
46−instance (Monoid w) => Applicative (Logger w) where
47− pure = Logger . const . pure
48− (<*>) = ap
49−
50−instance (Monoid w) => Monad (Logger w) where
51− return = pure
52− Logger l >>= f = Logger $ \r -> l r >>= \a -> runLogger (f a) r
53−
54−instance (Monoid w) => MonadIO (Logger w) where
55− liftIO = Logger . const
56−
57−instance (Monoid w) => MonadWriter w (Logger w) where
58− tell w = Logger $ \r -> atomicModifyIORef' r $ \w' -> (mappend w' w, ())
59− listen l = Logger $ \r -> do
60− (a, w) <- liftIO (runLogger' l)
61− atomicModifyIORef' r $ \w' -> (mappend w' w, (a, w))
62− pass l = Logger $ \r -> do
63− ((a, f), w) <- liftIO (runLogger' l)
64− atomicModifyIORef' r $ \w' -> (mappend w' (f w), a)
65−
66−instance (Monoid w) => MonadBase IO (Logger w) where
67− liftBase = liftIO
68−
69−instance (Monoid w) => MonadBaseControl IO (Logger w) where
70− type StM (Logger w) a = a
71− liftBaseWith f = Logger $ \r -> liftBaseWith $ \q -> f (q . flip runLogger r)
72− restoreM = return
src/Control/Monad/Supply.hsdeleted−45
@@ -1,45 +0,0 @@
1−-----------------------------------------------------------------------------
2−--
3−-- Module : Control.Monad.Supply
4−-- Copyright : (c) Phil Freeman 2014
5−-- License : MIT
6−--
7−-- Maintainer : Phil Freeman <paf31@cantab.net>
8−-- Stability : experimental
9−-- Portability :
10−--
11−-- |
12−-- Fresh variable supply
13−--
14−-----------------------------------------------------------------------------
15−
16−{-# LANGUAGE GeneralizedNewtypeDeriving #-}
17−
18−module Control.Monad.Supply where
19−
20−import Prelude ()
21−import Prelude.Compat
22−
23−import Data.Functor.Identity
24−
25−import Control.Monad.State
26−import Control.Monad.Error.Class (MonadError(..))
27−import Control.Monad.Reader
28−import Control.Monad.Writer
29−
30−newtype SupplyT m a = SupplyT { unSupplyT :: StateT Integer m a }
31− deriving (Functor, Applicative, Monad, MonadTrans, MonadError e, MonadWriter w, MonadReader r)
32−
33−runSupplyT :: Integer -> SupplyT m a -> m (a, Integer)
34−runSupplyT n = flip runStateT n . unSupplyT
35−
36−evalSupplyT :: (Functor m) => Integer -> SupplyT m a -> m a
37−evalSupplyT n = fmap fst . runSupplyT n
38−
39−type Supply = SupplyT Identity
40−
41−runSupply :: Integer -> Supply a -> (a, Integer)
42−runSupply n = runIdentity . runSupplyT n
43−
44−evalSupply :: Integer -> Supply a -> a
45−evalSupply n = runIdentity . evalSupplyT n
src/Control/Monad/Supply/Class.hsdeleted−24
@@ -1,24 +0,0 @@
1−{-# LANGUAGE MultiParamTypeClasses #-}
2−
3−-- |
4−-- A class for monads supporting a supply of fresh names
5−--
6−module Control.Monad.Supply.Class where
7−
8−import Control.Monad.Supply
9−import Control.Monad.State
10−
11−class (Monad m) => MonadSupply m where
12− fresh :: m Integer
13−
14−instance (Monad m) => MonadSupply (SupplyT m) where
15− fresh = SupplyT $ do
16− n <- get
17− put (n + 1)
18− return n
19−
20−instance (MonadSupply m) => MonadSupply (StateT s m) where
21− fresh = lift fresh
22−
23−freshName :: (MonadSupply m) => m String
24−freshName = fmap (('$' :) . show) fresh
src/Language/PureScript.hsdeleted−48
@@ -1,48 +0,0 @@
1−-----------------------------------------------------------------------------
2−--
3−-- Module : Language.PureScript
4−-- Copyright : (c) 2013-14 Phil Freeman, (c) 2014 Gary Burgess, and other contributors
5−-- License : MIT
6−--
7−-- Maintainer : Phil Freeman <paf31@cantab.net>
8−-- Stability : experimental
9−-- Portability :
10−--
11−-- |
12−-- The main compiler module
13−--
14−-----------------------------------------------------------------------------
15−
16−{-# LANGUAGE FlexibleContexts #-}
17−{-# LANGUAGE ScopedTypeVariables #-}
18−
19−module Language.PureScript
20− ( module P
21− , version
22− ) where
23−
24−import Data.Version (Version)
25−
26−import Language.PureScript.AST as P
27−import Language.PureScript.Crash as P
28−import Language.PureScript.Comments as P
29−import Language.PureScript.Environment as P
30−import Language.PureScript.Errors as P hiding (indent)
31−import Language.PureScript.Kinds as P
32−import Language.PureScript.Linter as P
33−import Language.PureScript.Make as P
34−import Language.PureScript.ModuleDependencies as P
35−import Language.PureScript.Names as P
36−import Language.PureScript.Options as P
37−import Language.PureScript.Parser as P
38−import Language.PureScript.Pretty as P
39−import Language.PureScript.Renamer as P
40−import Language.PureScript.Sugar as P
41−import Control.Monad.Supply as P
42−import Language.PureScript.TypeChecker as P
43−import Language.PureScript.Types as P
44−
45−import qualified Paths_purescript as Paths
46−
47−version :: Version
48−version = Paths.version
src/Language/PureScript/AST.hsdeleted−14
@@ -1,14 +0,0 @@
1−-- |
2−-- The initial PureScript AST
3−--
4−module Language.PureScript.AST (
5− module AST
6−) where
7−
8−import Language.PureScript.AST.Binders as AST
9−import Language.PureScript.AST.Declarations as AST
10−import Language.PureScript.AST.Exported as AST
11−import Language.PureScript.AST.Literals as AST
12−import Language.PureScript.AST.Operators as AST
13−import Language.PureScript.AST.SourcePos as AST
14−import Language.PureScript.AST.Traversals as AST
src/Language/PureScript/AST/Binders.hsdeleted−81
@@ -1,81 +0,0 @@
1−-- |
2−-- Case binders
3−--
4−module Language.PureScript.AST.Binders where
5−
6−import Language.PureScript.AST.SourcePos
7−import Language.PureScript.AST.Literals
8−import Language.PureScript.Names
9−import Language.PureScript.Comments
10−import Language.PureScript.Types
11−
12−-- |
13−-- Data type for binders
14−--
15−data Binder
16− -- |
17− -- Wildcard binder
18− --
19− = NullBinder
20− -- |
21− -- A binder which matches a literal
22− --
23− | LiteralBinder (Literal Binder)
24− -- |
25− -- A binder which binds an identifier
26− --
27− | VarBinder Ident
28− -- |
29− -- A binder which matches a data constructor
30− --
31− | ConstructorBinder (Qualified (ProperName 'ConstructorName)) [Binder]
32− -- |
33− -- A operator alias binder. During the rebracketing phase of desugaring,
34− -- this data constructor will be removed.
35− --
36− | OpBinder (Qualified Ident)
37− -- |
38− -- Binary operator application. During the rebracketing phase of desugaring,
39− -- this data constructor will be removed.
40− --
41− | BinaryNoParensBinder Binder Binder Binder
42− -- |
43− -- Explicit parentheses. During the rebracketing phase of desugaring, this
44− -- data constructor will be removed.
45− --
46− -- Note: although it seems this constructor is not used, it _is_ useful,
47− -- since it prevents certain traversals from matching.
48− --
49− | ParensInBinder Binder
50− -- |
51− -- A binder which binds its input to an identifier
52− --
53− | NamedBinder Ident Binder
54− -- |
55− -- A binder with source position information
56− --
57− | PositionedBinder SourceSpan [Comment] Binder
58− -- |
59− -- A binder with a type annotation
60− --
61− | TypedBinder Type Binder
62− deriving (Show, Read, Eq)
63−
64−-- |
65−-- Collect all names introduced in binders in an expression
66−--
67−binderNames :: Binder -> [Ident]
68−binderNames = go []
69− where
70− go ns (LiteralBinder b) = lit ns b
71− go ns (VarBinder name) = name : ns
72− go ns (ConstructorBinder _ bs) = foldl go ns bs
73− go ns (BinaryNoParensBinder b1 b2 b3) = foldl go ns [b1, b2, b3]
74− go ns (ParensInBinder b) = go ns b
75− go ns (NamedBinder name b) = go (name : ns) b
76− go ns (PositionedBinder _ _ b) = go ns b
77− go ns (TypedBinder _ b) = go ns b
78− go ns _ = ns
79− lit ns (ObjectLiteral bs) = foldl go ns (map snd bs)
80− lit ns (ArrayLiteral bs) = foldl go ns bs
81− lit ns _ = ns
src/Language/PureScript/AST/Declarations.hsdeleted−477
@@ -1,477 +0,0 @@
1−{-# LANGUAGE ScopedTypeVariables #-}
2−{-# LANGUAGE TemplateHaskell #-}
3−{-# LANGUAGE LambdaCase #-}
4−
5−-- |
6−-- Data types for modules and declarations
7−--
8−module Language.PureScript.AST.Declarations where
9−
10−import Prelude ()
11−import Prelude.Compat
12−
13−import Data.Aeson.TH
14−import Data.List (nub, (\\))
15−import Data.Maybe (mapMaybe)
16−
17−import qualified Data.Map as M
18−
19−import Control.Monad.Identity
20−
21−import Language.PureScript.AST.Binders
22−import Language.PureScript.AST.Literals
23−import Language.PureScript.AST.Operators
24−import Language.PureScript.AST.SourcePos
25−import Language.PureScript.Types
26−import Language.PureScript.Names
27−import Language.PureScript.Kinds
28−import Language.PureScript.TypeClassDictionaries
29−import Language.PureScript.Comments
30−import Language.PureScript.Environment
31−
32−-- |
33−-- A module declaration, consisting of comments about the module, a module name,
34−-- a list of declarations, and a list of the declarations that are
35−-- explicitly exported. If the export list is Nothing, everything is exported.
36−--
37−data Module = Module SourceSpan [Comment] ModuleName [Declaration] (Maybe [DeclarationRef])
38− deriving (Show, Read)
39−
40−-- | Return a module's name.
41−getModuleName :: Module -> ModuleName
42−getModuleName (Module _ _ name _ _) = name
43−
44−-- |
45−-- Add an import declaration for a module if it does not already explicitly import it.
46−--
47−addDefaultImport :: ModuleName -> Module -> Module
48−addDefaultImport toImport m@(Module ss coms mn decls exps) =
49− if isExistingImport `any` decls || mn == toImport then m
50− else Module ss coms mn (ImportDeclaration toImport Implicit Nothing False : decls) exps
51− where
52− isExistingImport (ImportDeclaration mn' _ _ _) | mn' == toImport = True
53− isExistingImport (PositionedDeclaration _ _ d) = isExistingImport d
54− isExistingImport _ = False
55−
56−-- |
57−-- An item in a list of explicit imports or exports
58−--
59−data DeclarationRef
60− -- |
61− -- A type constructor with data constructors
62− --
63− = TypeRef (ProperName 'TypeName) (Maybe [ProperName 'ConstructorName])
64− -- |
65− -- A type operator
66− --
67− | TypeOpRef Ident
68− -- |
69− -- A value
70− --
71− | ValueRef Ident
72− -- |
73− -- A type class
74− --
75− | TypeClassRef (ProperName 'ClassName)
76− -- |
77− -- A type class instance, created during typeclass desugaring (name, class name, instance types)
78− --
79− | TypeInstanceRef Ident
80− -- |
81− -- A module, in its entirety
82− --
83− | ModuleRef ModuleName
84− -- |
85− -- An unspecified ProperName ref. This will be replaced with a TypeClassRef
86− -- or TypeRef during name desugaring.
87− | ProperRef String
88− -- |
89− -- A declaration reference with source position information
90− --
91− | PositionedDeclarationRef SourceSpan [Comment] DeclarationRef
92− deriving (Show, Read)
93−
94−instance Eq DeclarationRef where
95− (TypeRef name dctors) == (TypeRef name' dctors') = name == name' && dctors == dctors'
96− (TypeOpRef name) == (TypeOpRef name') = name == name'
97− (ValueRef name) == (ValueRef name') = name == name'
98− (TypeClassRef name) == (TypeClassRef name') = name == name'
99− (TypeInstanceRef name) == (TypeInstanceRef name') = name == name'
100− (ModuleRef name) == (ModuleRef name') = name == name'
101− (ProperRef name) == (ProperRef name') = name == name'
102− (PositionedDeclarationRef _ _ r) == r' = r == r'
103− r == (PositionedDeclarationRef _ _ r') = r == r'
104− _ == _ = False
105−
106−isModuleRef :: DeclarationRef -> Bool
107−isModuleRef (PositionedDeclarationRef _ _ r) = isModuleRef r
108−isModuleRef (ModuleRef _) = True
109−isModuleRef _ = False
110−
111−-- |
112−-- Finds duplicate values in a list of declaration refs. The returned values
113−-- are the duplicate refs with data constructors elided, and then a separate
114−-- list of duplicate data constructors.
115−--
116−findDuplicateRefs :: [DeclarationRef] -> ([DeclarationRef], [ProperName 'ConstructorName])
117−findDuplicateRefs refs =
118− let positionless = stripPosInfo `map` refs
119− simplified = simplifyTypeRefs `map` positionless
120− dupeRefs = nub $ simplified \\ nub simplified
121− dupeCtors = concat $ flip mapMaybe positionless $ \case
122− TypeRef _ (Just dctors) ->
123− let dupes = dctors \\ nub dctors
124− in if null dupes then Nothing else Just dupes
125− _ -> Nothing
126− in (dupeRefs, dupeCtors)
127− where
128− stripPosInfo (PositionedDeclarationRef _ _ ref) = stripPosInfo ref
129− stripPosInfo other = other
130− simplifyTypeRefs (TypeRef pn _) = TypeRef pn Nothing
131− simplifyTypeRefs other = other
132−
133−-- |
134−-- The data type which specifies type of import declaration
135−--
136−data ImportDeclarationType
137− -- |
138− -- An import with no explicit list: `import M`.
139− --
140− = Implicit
141− -- |
142− -- An import with an explicit list of references to import: `import M (foo)`
143− --
144− | Explicit [DeclarationRef]
145− -- |
146− -- An import with a list of references to hide: `import M hiding (foo)`
147− --
148− | Hiding [DeclarationRef]
149− deriving (Eq, Show, Read)
150−
151−isImplicit :: ImportDeclarationType -> Bool
152−isImplicit Implicit = True
153−isImplicit _ = False
154−
155−isExplicit :: ImportDeclarationType -> Bool
156−isExplicit (Explicit _) = True
157−isExplicit _ = False
158−
159−-- |
160−-- The data type of declarations
161−--
162−data Declaration
163− -- |
164− -- A data type declaration (data or newtype, name, arguments, data constructors)
165− --
166− = DataDeclaration DataDeclType (ProperName 'TypeName) [(String, Maybe Kind)] [(ProperName 'ConstructorName, [Type])]
167− -- |
168− -- A minimal mutually recursive set of data type declarations
169− --
170− | DataBindingGroupDeclaration [Declaration]
171− -- |
172− -- A type synonym declaration (name, arguments, type)
173− --
174− | TypeSynonymDeclaration (ProperName 'TypeName) [(String, Maybe Kind)] Type
175− -- |
176− -- A type declaration for a value (name, ty)
177− --
178− | TypeDeclaration Ident Type
179− -- |
180− -- A value declaration (name, top-level binders, optional guard, value)
181− --
182− | ValueDeclaration Ident NameKind [Binder] (Either [(Guard, Expr)] Expr)
183− -- |
184− -- A minimal mutually recursive set of value declarations
185− --
186− | BindingGroupDeclaration [(Ident, NameKind, Expr)]
187− -- |
188− -- A foreign import declaration (name, type)
189− --
190− | ExternDeclaration Ident Type
191− -- |
192− -- A data type foreign import (name, kind)
193− --
194− | ExternDataDeclaration (ProperName 'TypeName) Kind
195− -- |
196− -- A fixity declaration (fixity data, operator name, value the operator is an alias for)
197− --
198− | FixityDeclaration Fixity String (Maybe (Qualified FixityAlias))
199− -- |
200− -- A module import (module name, qualified/unqualified/hiding, optional "qualified as" name)
201− -- TODO: also a boolean specifying whether the old `qualified` syntax was used, so a warning can be raised in desugaring (remove for 0.9)
202− --
203− | ImportDeclaration ModuleName ImportDeclarationType (Maybe ModuleName) Bool
204− -- |
205− -- A type class declaration (name, argument, implies, member declarations)
206− --
207− | TypeClassDeclaration (ProperName 'ClassName) [(String, Maybe Kind)] [Constraint] [Declaration]
208− -- |
209− -- A type instance declaration (name, dependencies, class name, instance types, member
210− -- declarations)
211− --
212− | TypeInstanceDeclaration Ident [Constraint] (Qualified (ProperName 'ClassName)) [Type] TypeInstanceBody
213− -- |
214− -- A declaration with source position information
215− --
216− | PositionedDeclaration SourceSpan [Comment] Declaration
217− deriving (Show, Read)
218−
219−data FixityAlias
220− = AliasValue Ident
221− | AliasConstructor (ProperName 'ConstructorName)
222− | AliasType (ProperName 'TypeName)
223− deriving (Eq, Ord, Show, Read)
224−
225−foldFixityAlias
226− :: (Ident -> a)
227− -> (ProperName 'ConstructorName -> a)
228− -> (ProperName 'TypeName -> a)
229− -> FixityAlias
230− -> a
231−foldFixityAlias f _ _ (AliasValue name) = f name
232−foldFixityAlias _ g _ (AliasConstructor name) = g name
233−foldFixityAlias _ _ h (AliasType name) = h name
234−
235−-- | The members of a type class instance declaration
236−data TypeInstanceBody
237− -- | This is a derived instance
238− = DerivedInstance
239− -- | This is a regular (explicit) instance
240− | ExplicitInstance [Declaration]
241− deriving (Show, Read)
242−
243−mapTypeInstanceBody :: ([Declaration] -> [Declaration]) -> TypeInstanceBody -> TypeInstanceBody
244−mapTypeInstanceBody f = runIdentity . traverseTypeInstanceBody (Identity . f)
245−
246−-- | A traversal for TypeInstanceBody
247−traverseTypeInstanceBody :: (Applicative f) => ([Declaration] -> f [Declaration]) -> TypeInstanceBody -> f TypeInstanceBody
248−traverseTypeInstanceBody _ DerivedInstance = pure DerivedInstance
249−traverseTypeInstanceBody f (ExplicitInstance ds) = ExplicitInstance <$> f ds
250−
251−-- |
252−-- Test if a declaration is a value declaration
253−--
254−isValueDecl :: Declaration -> Bool
255−isValueDecl ValueDeclaration{} = True
256−isValueDecl (PositionedDeclaration _ _ d) = isValueDecl d
257−isValueDecl _ = False
258−
259−-- |
260−-- Test if a declaration is a data type or type synonym declaration
261−--
262−isDataDecl :: Declaration -> Bool
263−isDataDecl DataDeclaration{} = True
264−isDataDecl TypeSynonymDeclaration{} = True
265−isDataDecl (PositionedDeclaration _ _ d) = isDataDecl d
266−isDataDecl _ = False
267−
268−-- |
269−-- Test if a declaration is a module import
270−--
271−isImportDecl :: Declaration -> Bool
272−isImportDecl ImportDeclaration{} = True
273−isImportDecl (PositionedDeclaration _ _ d) = isImportDecl d
274−isImportDecl _ = False
275−
276−-- |
277−-- Test if a declaration is a data type foreign import
278−--
279−isExternDataDecl :: Declaration -> Bool
280−isExternDataDecl ExternDataDeclaration{} = True
281−isExternDataDecl (PositionedDeclaration _ _ d) = isExternDataDecl d
282−isExternDataDecl _ = False
283−
284−-- |
285−-- Test if a declaration is a fixity declaration
286−--
287−isFixityDecl :: Declaration -> Bool
288−isFixityDecl FixityDeclaration{} = True
289−isFixityDecl (PositionedDeclaration _ _ d) = isFixityDecl d
290−isFixityDecl _ = False
291−
292−-- |
293−-- Test if a declaration is a foreign import
294−--
295−isExternDecl :: Declaration -> Bool
296−isExternDecl ExternDeclaration{} = True
297−isExternDecl (PositionedDeclaration _ _ d) = isExternDecl d
298−isExternDecl _ = False
299−
300−-- |
301−-- Test if a declaration is a type class instance declaration
302−--
303−isTypeClassInstanceDeclaration :: Declaration -> Bool
304−isTypeClassInstanceDeclaration TypeInstanceDeclaration{} = True
305−isTypeClassInstanceDeclaration (PositionedDeclaration _ _ d) = isTypeClassInstanceDeclaration d
306−isTypeClassInstanceDeclaration _ = False
307−
308−-- |
309−-- Test if a declaration is a type class declaration
310−--
311−isTypeClassDeclaration :: Declaration -> Bool
312−isTypeClassDeclaration TypeClassDeclaration{} = True
313−isTypeClassDeclaration (PositionedDeclaration _ _ d) = isTypeClassDeclaration d
314−isTypeClassDeclaration _ = False
315−
316−-- |
317−-- Recursively flatten data binding groups in the list of declarations
318−flattenDecls :: [Declaration] -> [Declaration]
319−flattenDecls = concatMap flattenOne
320− where flattenOne :: Declaration -> [Declaration]
321− flattenOne (DataBindingGroupDeclaration decls) = concatMap flattenOne decls
322− flattenOne d = [d]
323−
324−-- |
325−-- A guard is just a boolean-valued expression that appears alongside a set of binders
326−--
327−type Guard = Expr
328−
329−-- |
330−-- Data type for expressions and terms
331−--
332−data Expr
333− -- |
334− -- A literal value
335− --
336− = Literal (Literal Expr)
337− -- |
338− -- A prefix -, will be desugared
339− --
340− | UnaryMinus Expr
341− -- |
342− -- Binary operator application. During the rebracketing phase of desugaring, this data constructor
343− -- will be removed.
344− --
345− | BinaryNoParens Expr Expr Expr
346− -- |
347− -- Explicit parentheses. During the rebracketing phase of desugaring, this data constructor
348− -- will be removed.
349− --
350− -- Note: although it seems this constructor is not used, it _is_ useful, since it prevents
351− -- certain traversals from matching.
352− --
353− | Parens Expr
354− -- |
355− -- Operator section. This will be removed during desugaring and replaced with lambda.
356− --
357− | OperatorSection Expr (Either Expr Expr)
358− -- |
359− -- An object property getter (e.g. `_.x`). This will be removed during
360− -- desugaring and expanded into a lambda that reads a property from an object.
361− --
362− | ObjectGetter String
363− -- |
364− -- An record property accessor expression
365− --
366− | Accessor String Expr
367− -- |
368− -- Partial record update
369− --
370− | ObjectUpdate Expr [(String, Expr)]
371− -- |
372− -- Function introduction
373− --
374− | Abs (Either Ident Binder) Expr
375− -- |
376− -- Function application
377− --
378− | App Expr Expr
379− -- |
380− -- Variable
381− --
382− | Var (Qualified Ident)
383− -- |
384− -- Conditional (if-then-else expression)
385− --
386− | IfThenElse Expr Expr Expr
387− -- |
388− -- A data constructor
389− --
390− | Constructor (Qualified (ProperName 'ConstructorName))
391− -- |
392− -- A case expression. During the case expansion phase of desugaring, top-level binders will get
393− -- desugared into case expressions, hence the need for guards and multiple binders per branch here.
394− --
395− | Case [Expr] [CaseAlternative]
396− -- |
397− -- A value with a type annotation
398− --
399− | TypedValue Bool Expr Type
400− -- |
401− -- A let binding
402− --
403− | Let [Declaration] Expr
404− -- |
405− -- A do-notation block
406− --
407− | Do [DoNotationElement]
408− -- |
409− -- An application of a typeclass dictionary constructor. The value should be
410− -- an ObjectLiteral.
411− --
412− | TypeClassDictionaryConstructorApp (Qualified (ProperName 'ClassName)) Expr
413− -- |
414− -- A placeholder for a type class dictionary to be inserted later. At the end of type checking, these
415− -- placeholders will be replaced with actual expressions representing type classes dictionaries which
416− -- can be evaluated at runtime. The constructor arguments represent (in order): whether or not to look
417− -- at superclass implementations when searching for a dictionary, the type class name and
418− -- instance type, and the type class dictionaries in scope.
419− --
420− | TypeClassDictionary Constraint (M.Map (Maybe ModuleName) (M.Map (Qualified (ProperName 'ClassName)) (M.Map (Qualified Ident) TypeClassDictionaryInScope)))
421− -- |
422− -- A typeclass dictionary accessor, the implementation is left unspecified until CoreFn desugaring.
423− --
424− | TypeClassDictionaryAccessor (Qualified (ProperName 'ClassName)) Ident
425− -- |
426− -- A placeholder for a superclass dictionary to be turned into a TypeClassDictionary during typechecking
427− --
428− | SuperClassDictionary (Qualified (ProperName 'ClassName)) [Type]
429− -- |
430− -- A placeholder for an anonymous function argument
431− --
432− | AnonymousArgument
433− -- |
434− -- A value with source position information
435− --
436− | PositionedValue SourceSpan [Comment] Expr
437− deriving (Show, Read)
438−
439−-- |
440−-- An alternative in a case statement
441−--
442−data CaseAlternative = CaseAlternative
443− { -- |
444− -- A collection of binders with which to match the inputs
445− --
446− caseAlternativeBinders :: [Binder]
447− -- |
448− -- The result expression or a collect of guarded expressions
449− --
450− , caseAlternativeResult :: Either [(Guard, Expr)] Expr
451− } deriving (Show, Read)
452−
453−-- |
454−-- A statement in a do-notation block
455−--
456−data DoNotationElement
457− -- |
458− -- A monadic value without a binder
459− --
460− = DoNotationValue Expr
461− -- |
462− -- A monadic value with a binder
463− --
464− | DoNotationBind Binder Expr
465− -- |
466− -- A let statement, i.e. a pure value with a binder
467− --
468− | DoNotationLet [Declaration]
469− -- |
470− -- A do notation element with source position information
471− --
472− | PositionedDoNotationElement SourceSpan [Comment] DoNotationElement
473− deriving (Show, Read)
474−
475−$(deriveJSON (defaultOptions { sumEncoding = ObjectWithSingleField }) ''DeclarationRef)
476−$(deriveJSON (defaultOptions { sumEncoding = ObjectWithSingleField }) ''ImportDeclarationType)
477−$(deriveJSON (defaultOptions { sumEncoding = ObjectWithSingleField }) ''FixityAlias)
src/Language/PureScript/AST/Exported.hsdeleted−157
@@ -1,157 +0,0 @@
1−module Language.PureScript.AST.Exported
2− ( exportedDeclarations
3− , isExported
4− ) where
5−
6−import Control.Category ((>>>))
7−import Data.Maybe (mapMaybe)
8−
9−import Language.PureScript.AST.Declarations
10−import Language.PureScript.Types
11−import Language.PureScript.Names
12−
13−-- |
14−-- Return a list of all declarations which are exported from a module.
15−-- This function descends into data declarations to filter out unexported
16−-- data constructors, and also filters out type instance declarations if
17−-- they refer to classes or types which are not themselves exported.
18−--
19−-- Note that this function assumes that the module has already had its imports
20−-- desugared using 'Language.PureScript.Sugar.Names.desugarImports'. It will
21−-- produce incorrect results if this is not the case - for example, type class
22−-- instances will be incorrectly removed in some cases.
23−--
24−exportedDeclarations :: Module -> [Declaration]
25−exportedDeclarations (Module _ _ mn decls exps) = go decls
26− where
27− go = flattenDecls
28− >>> filter (isExported exps)
29− >>> map (filterDataConstructors exps)
30− >>> filterInstances mn exps
31−
32−-- |
33−-- Filter out all data constructors from a declaration which are not exported.
34−-- If the supplied declaration is not a data declaration, this function returns
35−-- it unchanged.
36−--
37−filterDataConstructors :: Maybe [DeclarationRef] -> Declaration -> Declaration
38−filterDataConstructors exps (DataDeclaration dType tyName tyArgs dctors) =
39− DataDeclaration dType tyName tyArgs $
40− filter (isDctorExported tyName exps . fst) dctors
41−filterDataConstructors exps (PositionedDeclaration srcSpan coms d) =
42− PositionedDeclaration srcSpan coms (filterDataConstructors exps d)
43−filterDataConstructors _ other = other
44−
45−-- |
46−-- Filter out all the type instances from a list of declarations which
47−-- reference a type or type class which is both local and not exported.
48−--
49−-- Note that this function assumes that the module has already had its imports
50−-- desugared using "Language.PureScript.Sugar.Names.desugarImports". It will
51−-- produce incorrect results if this is not the case - for example, type class
52−-- instances will be incorrectly removed in some cases.
53−--
54−filterInstances
55− :: ModuleName
56− -> Maybe [DeclarationRef]
57− -> [Declaration]
58− -> [Declaration]
59−filterInstances _ Nothing = id
60−filterInstances mn (Just exps) =
61− let refs = Left `map` mapMaybe typeClassName exps
62− ++ Right `map` mapMaybe typeName exps
63− in filter (all (visibleOutside refs) . typeInstanceConstituents)
64− where
65− -- Given a Qualified ProperName, and a list of all exported types and type
66− -- classes, returns whether the supplied Qualified ProperName is visible
67− -- outside this module. This is true if one of the following hold:
68− --
69− -- * the name is defined in the same module and is exported,
70− -- * the name is defined in a different module (and must be exported from
71− -- that module; the code would fail to compile otherwise).
72− visibleOutside
73− :: [Either (ProperName 'ClassName) (ProperName 'TypeName)]
74− -> Either (Qualified (ProperName 'ClassName)) (Qualified (ProperName 'TypeName))
75− -> Bool
76− visibleOutside refs q
77− | either checkQual checkQual q = True
78− | otherwise = either (Left . disqualify) (Right . disqualify) q `elem` refs
79−
80− -- Check that a qualified name is qualified for a different module
81− checkQual :: Qualified a -> Bool
82− checkQual q = isQualified q && not (isQualifiedWith mn q)
83−
84− typeName :: DeclarationRef -> Maybe (ProperName 'TypeName)
85− typeName (TypeRef n _) = Just n
86− typeName (PositionedDeclarationRef _ _ r) = typeName r
87− typeName _ = Nothing
88−
89− typeClassName :: DeclarationRef -> Maybe (ProperName 'ClassName)
90− typeClassName (TypeClassRef n) = Just n
91− typeClassName (PositionedDeclarationRef _ _ r) = typeClassName r
92− typeClassName _ = Nothing
93−
94−-- |
95−-- Get all type and type class names referenced by a type instance declaration.
96−--
97−typeInstanceConstituents :: Declaration -> [Either (Qualified (ProperName 'ClassName)) (Qualified (ProperName 'TypeName))]
98−typeInstanceConstituents (TypeInstanceDeclaration _ constraints className tys _) =
99− Left className : (concatMap fromConstraint constraints ++ concatMap fromType tys)
100− where
101−
102− fromConstraint (name, tys') = Left name : concatMap fromType tys'
103− fromType = everythingOnTypes (++) go
104−
105− -- Note that type synonyms are disallowed in instance declarations, so
106− -- we don't need to handle them here.
107− go (TypeConstructor n) = [Right n]
108− go (ConstrainedType cs _) = concatMap fromConstraint cs
109− go _ = []
110−
111−typeInstanceConstituents (PositionedDeclaration _ _ d) = typeInstanceConstituents d
112−typeInstanceConstituents _ = []
113−
114−
115−-- |
116−-- Test if a declaration is exported, given a module's export list. Note that
117−-- this function does not account for type instance declarations of
118−-- non-exported types, or non-exported data constructors. Therefore, you should
119−-- prefer 'exportedDeclarations' to this function, where possible.
120−--
121−isExported :: Maybe [DeclarationRef] -> Declaration -> Bool
122−isExported Nothing _ = True
123−isExported _ TypeInstanceDeclaration{} = True
124−isExported exps (PositionedDeclaration _ _ d) = isExported exps d
125−isExported (Just exps) decl = any (matches decl) exps
126− where
127− matches (TypeDeclaration ident _) (ValueRef ident') = ident == ident'
128− matches (ValueDeclaration ident _ _ _) (ValueRef ident') = ident == ident'
129− matches (ExternDeclaration ident _) (ValueRef ident') = ident == ident'
130− matches (DataDeclaration _ ident _ _) (TypeRef ident' _) = ident == ident'
131− matches (ExternDataDeclaration ident _) (TypeRef ident' _) = ident == ident'
132− matches (TypeSynonymDeclaration ident _ _) (TypeRef ident' _) = ident == ident'
133− matches (TypeClassDeclaration ident _ _ _) (TypeClassRef ident') = ident == ident'
134−
135− matches (DataDeclaration _ ident _ _) (ProperRef ident') = runProperName ident == ident'
136− matches (TypeClassDeclaration ident _ _ _) (ProperRef ident') = runProperName ident == ident'
137−
138− matches (FixityDeclaration _ name (Just (Qualified _ (AliasValue _)))) (ValueRef ident') = name == runIdent ident'
139− matches (FixityDeclaration _ name (Just (Qualified _ (AliasConstructor _)))) (ValueRef ident') = name == runIdent ident'
140− matches (FixityDeclaration _ name (Just (Qualified _ (AliasType _)))) (TypeOpRef ident') = name == runIdent ident'
141−
142− matches (PositionedDeclaration _ _ d) r = d `matches` r
143− matches d (PositionedDeclarationRef _ _ r) = d `matches` r
144− matches _ _ = False
145−
146−-- |
147−-- Test if a data constructor for a given type is exported, given a module's
148−-- export list. Prefer 'exportedDeclarations' to this function, where possible.
149−--
150−isDctorExported :: ProperName 'TypeName -> Maybe [DeclarationRef] -> ProperName 'ConstructorName -> Bool
151−isDctorExported _ Nothing _ = True
152−isDctorExported ident (Just exps) ctor = test `any` exps
153− where
154− test (PositionedDeclarationRef _ _ d) = test d
155− test (TypeRef ident' Nothing) = ident == ident'
156− test (TypeRef ident' (Just ctors)) = ident == ident' && ctor `elem` ctors
157− test _ = False
src/Language/PureScript/AST/Literals.hsdeleted−37
@@ -1,37 +0,0 @@
1−{-# LANGUAGE DeriveFunctor #-}
2−
3−-- |
4−-- The core functional representation for literal values.
5−--
6−module Language.PureScript.AST.Literals where
7−
8−-- |
9−-- Data type for literal values. Parameterised so it can be used for Exprs and
10−-- Binders.
11−--
12−data Literal a
13− -- |
14− -- A numeric literal
15− --
16− = NumericLiteral (Either Integer Double)
17− -- |
18− -- A string literal
19− --
20− | StringLiteral String
21− -- |
22− -- A character literal
23− --
24− | CharLiteral Char
25− -- |
26− -- A boolean literal
27− --
28− | BooleanLiteral Bool
29− -- |
30− -- An array literal
31− --
32− | ArrayLiteral [a]
33− -- |
34− -- An object literal
35− --
36− | ObjectLiteral [(String, a)]
37− deriving (Eq, Ord, Show, Read, Functor)
src/Language/PureScript/AST/Operators.hsdeleted−51
@@ -1,51 +0,0 @@
1−{-# LANGUAGE OverloadedStrings #-}
2−
3−-- |
4−-- Operators fixity and associativity
5−--
6−module Language.PureScript.AST.Operators where
7−
8−import Data.Aeson ((.=))
9−import qualified Data.Aeson as A
10−
11−import Language.PureScript.Crash
12−
13−-- |
14−-- A precedence level for an infix operator
15−--
16−type Precedence = Integer
17−
18−-- |
19−-- Associativity for infix operators
20−--
21−data Associativity = Infixl | Infixr | Infix
22− deriving (Show, Read, Eq, Ord)
23−
24−showAssoc :: Associativity -> String
25−showAssoc Infixl = "infixl"
26−showAssoc Infixr = "infixr"
27−showAssoc Infix = "infix"
28−
29−readAssoc :: String -> Associativity
30−readAssoc "infixl" = Infixl
31−readAssoc "infixr" = Infixr
32−readAssoc "infix" = Infix
33−readAssoc _ = internalError "readAssoc: no parse"
34−
35−instance A.ToJSON Associativity where
36− toJSON = A.toJSON . showAssoc
37−
38−instance A.FromJSON Associativity where
39− parseJSON = fmap readAssoc . A.parseJSON
40−
41−-- |
42−-- Fixity data for infix operators
43−--
44−data Fixity = Fixity Associativity Precedence
45− deriving (Show, Read, Eq, Ord)
46−
47−instance A.ToJSON Fixity where
48− toJSON (Fixity associativity precedence) =
49− A.object [ "associativity" .= associativity
50− , "precedence" .= precedence
51− ]
src/Language/PureScript/AST/SourcePos.hsdeleted−83
@@ -1,83 +0,0 @@
1−{-# LANGUAGE ScopedTypeVariables #-}
2−{-# LANGUAGE RecordWildCards #-}
3−{-# LANGUAGE OverloadedStrings #-}
4−
5−-- |
6−-- Source position information
7−--
8−module Language.PureScript.AST.SourcePos where
9−
10−import Prelude ()
11−import Prelude.Compat
12−
13−import Data.Aeson ((.=), (.:))
14−import qualified Data.Aeson as A
15−
16−-- |
17−-- Source position information
18−--
19−data SourcePos = SourcePos
20− { -- |
21− -- Line number
22− --
23− sourcePosLine :: Int
24− -- |
25− -- Column number
26− --
27− , sourcePosColumn :: Int
28− } deriving (Show, Read, Eq, Ord)
29−
30−displaySourcePos :: SourcePos -> String
31−displaySourcePos sp =
32− "line " ++ show (sourcePosLine sp) ++
33− ", column " ++ show (sourcePosColumn sp)
34−
35−instance A.ToJSON SourcePos where
36− toJSON SourcePos{..} =
37− A.toJSON [sourcePosLine, sourcePosColumn]
38−
39−instance A.FromJSON SourcePos where
40− parseJSON arr = do
41− [line, col] <- A.parseJSON arr
42− return $ SourcePos line col
43−
44−data SourceSpan = SourceSpan
45− { -- |
46− -- Source name
47− --
48− spanName :: String
49− -- |
50− -- Start of the span
51− --
52− , spanStart :: SourcePos
53− -- End of the span
54− --
55− , spanEnd :: SourcePos
56− } deriving (Show, Read, Eq, Ord)
57−
58−displayStartEndPos :: SourceSpan -> String
59−displayStartEndPos sp =
60− displaySourcePos (spanStart sp) ++ " - " ++
61− displaySourcePos (spanEnd sp)
62−
63−displaySourceSpan :: SourceSpan -> String
64−displaySourceSpan sp =
65− spanName sp ++ " " ++
66− displayStartEndPos sp
67−
68−instance A.ToJSON SourceSpan where
69− toJSON SourceSpan{..} =
70− A.object [ "name" .= spanName
71− , "start" .= spanStart
72− , "end" .= spanEnd
73− ]
74−
75−instance A.FromJSON SourceSpan where
76− parseJSON = A.withObject "SourceSpan" $ \o ->
77− SourceSpan <$>
78− o .: "name" <*>
79− o .: "start" <*>
80− o .: "end"
81−
82−internalModuleSourceSpan :: String -> SourceSpan
83−internalModuleSourceSpan name = SourceSpan name (SourcePos 0 0) (SourcePos 0 0)
src/Language/PureScript/AST/Traversals.hsdeleted−605
@@ -1,605 +0,0 @@
1−{-# LANGUAGE ScopedTypeVariables #-}
2−
3−-- |
4−-- AST traversal helpers
5−--
6−module Language.PureScript.AST.Traversals where
7−
8−import Prelude ()
9−import Prelude.Compat
10−
11−import Data.Maybe (mapMaybe)
12−import Data.List (mapAccumL)
13−import Data.Foldable (fold)
14−import qualified Data.Set as S
15−
16−import Control.Monad
17−import Control.Arrow ((***), (+++))
18−
19−import Language.PureScript.AST.Binders
20−import Language.PureScript.AST.Literals
21−import Language.PureScript.AST.Declarations
22−import Language.PureScript.Types
23−import Language.PureScript.Traversals
24−import Language.PureScript.Names
25−
26−everywhereOnValues
27− :: (Declaration -> Declaration)
28− -> (Expr -> Expr)
29− -> (Binder -> Binder)
30− -> ( Declaration -> Declaration
31− , Expr -> Expr
32− , Binder -> Binder
33− )
34−everywhereOnValues f g h = (f', g', h')
35− where
36− f' :: Declaration -> Declaration
37− f' (DataBindingGroupDeclaration ds) = f (DataBindingGroupDeclaration (map f' ds))
38− f' (ValueDeclaration name nameKind bs val) = f (ValueDeclaration name nameKind (map h' bs) ((map (g' *** g') +++ g') val))
39− f' (BindingGroupDeclaration ds) = f (BindingGroupDeclaration (map (\(name, nameKind, val) -> (name, nameKind, g' val)) ds))
40− f' (TypeClassDeclaration name args implies ds) = f (TypeClassDeclaration name args implies (map f' ds))
41− f' (TypeInstanceDeclaration name cs className args ds) = f (TypeInstanceDeclaration name cs className args (mapTypeInstanceBody (map f') ds))
42− f' (PositionedDeclaration pos com d) = f (PositionedDeclaration pos com (f' d))
43− f' other = f other
44−
45− g' :: Expr -> Expr
46− g' (Literal l) = g (Literal (lit g' l))
47− g' (UnaryMinus v) = g (UnaryMinus (g' v))
48− g' (BinaryNoParens op v1 v2) = g (BinaryNoParens (g' op) (g' v1) (g' v2))
49− g' (Parens v) = g (Parens (g' v))
50− g' (OperatorSection op (Left v)) = g (OperatorSection (g' op) (Left $ g' v))
51− g' (OperatorSection op (Right v)) = g (OperatorSection (g' op) (Right $ g' v))
52− g' (TypeClassDictionaryConstructorApp name v) = g (TypeClassDictionaryConstructorApp name (g' v))
53− g' (Accessor prop v) = g (Accessor prop (g' v))
54− g' (ObjectUpdate obj vs) = g (ObjectUpdate (g' obj) (map (fmap g') vs))
55− g' (Abs name v) = g (Abs name (g' v))
56− g' (App v1 v2) = g (App (g' v1) (g' v2))
57− g' (IfThenElse v1 v2 v3) = g (IfThenElse (g' v1) (g' v2) (g' v3))
58− g' (Case vs alts) = g (Case (map g' vs) (map handleCaseAlternative alts))
59− g' (TypedValue check v ty) = g (TypedValue check (g' v) ty)
60− g' (Let ds v) = g (Let (map f' ds) (g' v))
61− g' (Do es) = g (Do (map handleDoNotationElement es))
62− g' (PositionedValue pos com v) = g (PositionedValue pos com (g' v))
63− g' other = g other
64−
65− h' :: Binder -> Binder
66− h' (ConstructorBinder ctor bs) = h (ConstructorBinder ctor (map h' bs))
67− h' (BinaryNoParensBinder b1 b2 b3) = h (BinaryNoParensBinder (h' b1) (h' b2) (h' b3))
68− h' (ParensInBinder b) = h (ParensInBinder (h' b))
69− h' (LiteralBinder l) = h (LiteralBinder (lit h' l))
70− h' (NamedBinder name b) = h (NamedBinder name (h' b))
71− h' (PositionedBinder pos com b) = h (PositionedBinder pos com (h' b))
72− h' (TypedBinder t b) = h (TypedBinder t (h' b))
73− h' other = h other
74−
75− lit :: (a -> a) -> Literal a -> Literal a
76− lit go (ArrayLiteral as) = ArrayLiteral (map go as)
77− lit go (ObjectLiteral as) = ObjectLiteral (map (fmap go) as)
78− lit _ other = other
79−
80− handleCaseAlternative :: CaseAlternative -> CaseAlternative
81− handleCaseAlternative ca =
82− ca { caseAlternativeBinders = map h' (caseAlternativeBinders ca)
83− , caseAlternativeResult = (map (g' *** g') +++ g') (caseAlternativeResult ca)
84− }
85−
86− handleDoNotationElement :: DoNotationElement -> DoNotationElement
87− handleDoNotationElement (DoNotationValue v) = DoNotationValue (g' v)
88− handleDoNotationElement (DoNotationBind b v) = DoNotationBind (h' b) (g' v)
89− handleDoNotationElement (DoNotationLet ds) = DoNotationLet (map f' ds)
90− handleDoNotationElement (PositionedDoNotationElement pos com e) = PositionedDoNotationElement pos com (handleDoNotationElement e)
91−
92−everywhereOnValuesTopDownM
93− :: forall m
94− . (Monad m)
95− => (Declaration -> m Declaration)
96− -> (Expr -> m Expr)
97− -> (Binder -> m Binder)
98− -> ( Declaration -> m Declaration
99− , Expr -> m Expr
100− , Binder -> m Binder
101− )
102−everywhereOnValuesTopDownM f g h = (f' <=< f, g' <=< g, h' <=< h)
103− where
104−
105− f' :: Declaration -> m Declaration
106− f' (DataBindingGroupDeclaration ds) = DataBindingGroupDeclaration <$> traverse (f' <=< f) ds
107− f' (ValueDeclaration name nameKind bs val) = ValueDeclaration name nameKind <$> traverse (h' <=< h) bs <*> eitherM (traverse (pairM (g' <=< g) (g' <=< g))) (g' <=< g) val
108− f' (BindingGroupDeclaration ds) = BindingGroupDeclaration <$> traverse (\(name, nameKind, val) -> (,,) name nameKind <$> (g val >>= g')) ds
109− f' (TypeClassDeclaration name args implies ds) = TypeClassDeclaration name args implies <$> traverse (f' <=< f) ds
110− f' (TypeInstanceDeclaration name cs className args ds) = TypeInstanceDeclaration name cs className args <$> traverseTypeInstanceBody (traverse (f' <=< f)) ds
111− f' (PositionedDeclaration pos com d) = PositionedDeclaration pos com <$> (f d >>= f')
112− f' other = f other
113−
114− g' :: Expr -> m Expr
115− g' (Literal l) = Literal <$> lit (g >=> g') l
116− g' (UnaryMinus v) = UnaryMinus <$> (g v >>= g')
117− g' (BinaryNoParens op v1 v2) = BinaryNoParens <$> (g op >>= g') <*> (g v1 >>= g') <*> (g v2 >>= g')
118− g' (Parens v) = Parens <$> (g v >>= g')
119− g' (OperatorSection op (Left v)) = OperatorSection <$> (g op >>= g') <*> (Left <$> (g v >>= g'))
120− g' (OperatorSection op (Right v)) = OperatorSection <$> (g op >>= g') <*> (Right <$> (g v >>= g'))
121− g' (TypeClassDictionaryConstructorApp name v) = TypeClassDictionaryConstructorApp name <$> (g v >>= g')
122− g' (Accessor prop v) = Accessor prop <$> (g v >>= g')
123− g' (ObjectUpdate obj vs) = ObjectUpdate <$> (g obj >>= g') <*> traverse (sndM (g' <=< g)) vs
124− g' (Abs name v) = Abs name <$> (g v >>= g')
125− g' (App v1 v2) = App <$> (g v1 >>= g') <*> (g v2 >>= g')
126− g' (IfThenElse v1 v2 v3) = IfThenElse <$> (g v1 >>= g') <*> (g v2 >>= g') <*> (g v3 >>= g')
127− g' (Case vs alts) = Case <$> traverse (g' <=< g) vs <*> traverse handleCaseAlternative alts
128− g' (TypedValue check v ty) = TypedValue check <$> (g v >>= g') <*> pure ty
129− g' (Let ds v) = Let <$> traverse (f' <=< f) ds <*> (g v >>= g')
130− g' (Do es) = Do <$> traverse handleDoNotationElement es
131− g' (PositionedValue pos com v) = PositionedValue pos com <$> (g v >>= g')
132− g' other = g other
133−
134− h' :: Binder -> m Binder
135− h' (LiteralBinder l) = LiteralBinder <$> lit (h >=> h') l
136− h' (ConstructorBinder ctor bs) = ConstructorBinder ctor <$> traverse (h' <=< h) bs
137− h' (BinaryNoParensBinder b1 b2 b3) = BinaryNoParensBinder <$> (h b1 >>= h') <*> (h b2 >>= h') <*> (h b3 >>= h')
138− h' (ParensInBinder b) = ParensInBinder <$> (h b >>= h')
139− h' (NamedBinder name b) = NamedBinder name <$> (h b >>= h')
140− h' (PositionedBinder pos com b) = PositionedBinder pos com <$> (h b >>= h')
141− h' (TypedBinder t b) = TypedBinder t <$> (h b >>= h')
142− h' other = h other
143−
144− lit :: (a -> m a) -> Literal a -> m (Literal a)
145− lit go (ObjectLiteral as) = ObjectLiteral <$> traverse (sndM go) as
146− lit go (ArrayLiteral as) = ArrayLiteral <$> traverse go as
147− lit _ other = pure other
148−
149− handleCaseAlternative :: CaseAlternative -> m CaseAlternative
150− handleCaseAlternative (CaseAlternative bs val) =
151− CaseAlternative
152− <$> traverse (h' <=< h) bs
153− <*> eitherM (traverse (pairM (g' <=< g) (g' <=< g))) (g' <=< g) val
154−
155− handleDoNotationElement :: DoNotationElement -> m DoNotationElement
156− handleDoNotationElement (DoNotationValue v) = DoNotationValue <$> (g' <=< g) v
157− handleDoNotationElement (DoNotationBind b v) = DoNotationBind <$> (h' <=< h) b <*> (g' <=< g) v
158− handleDoNotationElement (DoNotationLet ds) = DoNotationLet <$> traverse (f' <=< f) ds
159− handleDoNotationElement (PositionedDoNotationElement pos com e) = PositionedDoNotationElement pos com <$> handleDoNotationElement e
160−
161−everywhereOnValuesM
162− :: forall m
163− . (Monad m)
164− => (Declaration -> m Declaration)
165− -> (Expr -> m Expr)
166− -> (Binder -> m Binder)
167− -> ( Declaration -> m Declaration
168− , Expr -> m Expr
169− , Binder -> m Binder
170− )
171−everywhereOnValuesM f g h = (f', g', h')
172− where
173−
174− f' :: Declaration -> m Declaration
175− f' (DataBindingGroupDeclaration ds) = (DataBindingGroupDeclaration <$> traverse f' ds) >>= f
176− f' (ValueDeclaration name nameKind bs val) = (ValueDeclaration name nameKind <$> traverse h' bs <*> eitherM (traverse (pairM g' g')) g' val) >>= f
177− f' (BindingGroupDeclaration ds) = (BindingGroupDeclaration <$> traverse (\(name, nameKind, val) -> (,,) name nameKind <$> g' val) ds) >>= f
178− f' (TypeClassDeclaration name args implies ds) = (TypeClassDeclaration name args implies <$> traverse f' ds) >>= f
179− f' (TypeInstanceDeclaration name cs className args ds) = (TypeInstanceDeclaration name cs className args <$> traverseTypeInstanceBody (traverse f') ds) >>= f
180− f' (PositionedDeclaration pos com d) = (PositionedDeclaration pos com <$> f' d) >>= f
181− f' other = f other
182−
183− g' :: Expr -> m Expr
184− g' (Literal l) = (Literal <$> lit g' l) >>= g
185− g' (UnaryMinus v) = (UnaryMinus <$> g' v) >>= g
186− g' (BinaryNoParens op v1 v2) = (BinaryNoParens <$> g' op <*> g' v1 <*> g' v2) >>= g
187− g' (Parens v) = (Parens <$> g' v) >>= g
188− g' (OperatorSection op (Left v)) = (OperatorSection <$> g' op <*> (Left <$> g' v)) >>= g
189− g' (OperatorSection op (Right v)) = (OperatorSection <$> g' op <*> (Right <$> g' v)) >>= g
190− g' (TypeClassDictionaryConstructorApp name v) = (TypeClassDictionaryConstructorApp name <$> g' v) >>= g
191− g' (Accessor prop v) = (Accessor prop <$> g' v) >>= g
192− g' (ObjectUpdate obj vs) = (ObjectUpdate <$> g' obj <*> traverse (sndM g') vs) >>= g
193− g' (Abs name v) = (Abs name <$> g' v) >>= g
194− g' (App v1 v2) = (App <$> g' v1 <*> g' v2) >>= g
195− g' (IfThenElse v1 v2 v3) = (IfThenElse <$> g' v1 <*> g' v2 <*> g' v3) >>= g
196− g' (Case vs alts) = (Case <$> traverse g' vs <*> traverse handleCaseAlternative alts) >>= g
197− g' (TypedValue check v ty) = (TypedValue check <$> g' v <*> pure ty) >>= g
198− g' (Let ds v) = (Let <$> traverse f' ds <*> g' v) >>= g
199− g' (Do es) = (Do <$> traverse handleDoNotationElement es) >>= g
200− g' (PositionedValue pos com v) = (PositionedValue pos com <$> g' v) >>= g
201− g' other = g other
202−
203− h' :: Binder -> m Binder
204− h' (LiteralBinder l) = (LiteralBinder <$> lit h' l) >>= h
205− h' (ConstructorBinder ctor bs) = (ConstructorBinder ctor <$> traverse h' bs) >>= h
206− h' (BinaryNoParensBinder b1 b2 b3) = (BinaryNoParensBinder <$> h' b1 <*> h' b2 <*> h' b3) >>= h
207− h' (ParensInBinder b) = (ParensInBinder <$> h' b) >>= h
208− h' (NamedBinder name b) = (NamedBinder name <$> h' b) >>= h
209− h' (PositionedBinder pos com b) = (PositionedBinder pos com <$> h' b) >>= h
210− h' (TypedBinder t b) = (TypedBinder t <$> h' b) >>= h
211− h' other = h other
212−
213− lit :: (a -> m a) -> Literal a -> m (Literal a)
214− lit go (ObjectLiteral as) = ObjectLiteral <$> traverse (sndM go) as
215− lit go (ArrayLiteral as) = ArrayLiteral <$> traverse go as
216− lit _ other = pure other
217−
218− handleCaseAlternative :: CaseAlternative -> m CaseAlternative
219− handleCaseAlternative (CaseAlternative bs val) =
220− CaseAlternative
221− <$> traverse h' bs
222− <*> eitherM (traverse (pairM g' g')) g' val
223−
224− handleDoNotationElement :: DoNotationElement -> m DoNotationElement
225− handleDoNotationElement (DoNotationValue v) = DoNotationValue <$> g' v
226− handleDoNotationElement (DoNotationBind b v) = DoNotationBind <$> h' b <*> g' v
227− handleDoNotationElement (DoNotationLet ds) = DoNotationLet <$> traverse f' ds
228− handleDoNotationElement (PositionedDoNotationElement pos com e) = PositionedDoNotationElement pos com <$> handleDoNotationElement e
229−
230−everythingOnValues
231− :: forall r
232− . (r -> r -> r)
233− -> (Declaration -> r)
234− -> (Expr -> r)
235− -> (Binder -> r)
236− -> (CaseAlternative -> r)
237− -> (DoNotationElement -> r)
238− -> ( Declaration -> r
239− , Expr -> r
240− , Binder -> r
241− , CaseAlternative -> r
242− , DoNotationElement -> r
243− )
244−everythingOnValues (<>) f g h i j = (f', g', h', i', j')
245− where
246−
247− f' :: Declaration -> r
248− f' d@(DataBindingGroupDeclaration ds) = foldl (<>) (f d) (map f' ds)
249− f' d@(ValueDeclaration _ _ bs (Right val)) = foldl (<>) (f d) (map h' bs) <> g' val
250− f' d@(ValueDeclaration _ _ bs (Left gs)) = foldl (<>) (f d) (map h' bs ++ concatMap (\(grd, val) -> [g' grd, g' val]) gs)
251− f' d@(BindingGroupDeclaration ds) = foldl (<>) (f d) (map (\(_, _, val) -> g' val) ds)
252− f' d@(TypeClassDeclaration _ _ _ ds) = foldl (<>) (f d) (map f' ds)
253− f' d@(TypeInstanceDeclaration _ _ _ _ (ExplicitInstance ds)) = foldl (<>) (f d) (map f' ds)
254− f' d@(PositionedDeclaration _ _ d1) = f d <> f' d1
255− f' d = f d
256−
257− g' :: Expr -> r
258− g' v@(Literal l) = lit (g v) g' l
259− g' v@(UnaryMinus v1) = g v <> g' v1
260− g' v@(BinaryNoParens op v1 v2) = g v <> g' op <> g' v1 <> g' v2
261− g' v@(Parens v1) = g v <> g' v1
262− g' v@(OperatorSection op (Left v1)) = g v <> g' op <> g' v1
263− g' v@(OperatorSection op (Right v1)) = g v <> g' op <> g' v1
264− g' v@(TypeClassDictionaryConstructorApp _ v1) = g v <> g' v1
265− g' v@(Accessor _ v1) = g v <> g' v1
266− g' v@(ObjectUpdate obj vs) = foldl (<>) (g v <> g' obj) (map (g' . snd) vs)
267− g' v@(Abs _ v1) = g v <> g' v1
268− g' v@(App v1 v2) = g v <> g' v1 <> g' v2
269− g' v@(IfThenElse v1 v2 v3) = g v <> g' v1 <> g' v2 <> g' v3
270− g' v@(Case vs alts) = foldl (<>) (foldl (<>) (g v) (map g' vs)) (map i' alts)
271− g' v@(TypedValue _ v1 _) = g v <> g' v1
272− g' v@(Let ds v1) = foldl (<>) (g v) (map f' ds) <> g' v1
273− g' v@(Do es) = foldl (<>) (g v) (map j' es)
274− g' v@(PositionedValue _ _ v1) = g v <> g' v1
275− g' v = g v
276−
277− h' :: Binder -> r
278− h' b@(LiteralBinder l) = lit (h b) h' l
279− h' b@(ConstructorBinder _ bs) = foldl (<>) (h b) (map h' bs)
280− h' b@(BinaryNoParensBinder b1 b2 b3) = h b <> h' b1 <> h' b2 <> h' b3
281− h' b@(ParensInBinder b1) = h b <> h' b1
282− h' b@(NamedBinder _ b1) = h b <> h' b1
283− h' b@(PositionedBinder _ _ b1) = h b <> h' b1
284− h' b@(TypedBinder _ b1) = h b <> h' b1
285− h' b = h b
286−
287− lit :: r -> (a -> r) -> Literal a -> r
288− lit r go (ArrayLiteral as) = foldl (<>) r (map go as)
289− lit r go (ObjectLiteral as) = foldl (<>) r (map (go . snd) as)
290− lit r _ _ = r
291−
292− i' :: CaseAlternative -> r
293− i' ca@(CaseAlternative bs (Right val)) = foldl (<>) (i ca) (map h' bs) <> g' val
294− i' ca@(CaseAlternative bs (Left gs)) = foldl (<>) (i ca) (map h' bs ++ concatMap (\(grd, val) -> [g' grd, g' val]) gs)
295−
296− j' :: DoNotationElement -> r
297− j' e@(DoNotationValue v) = j e <> g' v
298− j' e@(DoNotationBind b v) = j e <> h' b <> g' v
299− j' e@(DoNotationLet ds) = foldl (<>) (j e) (map f' ds)
300− j' e@(PositionedDoNotationElement _ _ e1) = j e <> j' e1
301−
302−everythingWithContextOnValues
303− :: forall s r
304− . s
305− -> r
306− -> (r -> r -> r)
307− -> (s -> Declaration -> (s, r))
308− -> (s -> Expr -> (s, r))
309− -> (s -> Binder -> (s, r))
310− -> (s -> CaseAlternative -> (s, r))
311− -> (s -> DoNotationElement -> (s, r))
312− -> ( Declaration -> r
313− , Expr -> r
314− , Binder -> r
315− , CaseAlternative -> r
316− , DoNotationElement -> r)
317−everythingWithContextOnValues s0 r0 (<>) f g h i j = (f'' s0, g'' s0, h'' s0, i'' s0, j'' s0)
318− where
319−
320− f'' :: s -> Declaration -> r
321− f'' s d = let (s', r) = f s d in r <> f' s' d
322−
323− f' :: s -> Declaration -> r
324− f' s (DataBindingGroupDeclaration ds) = foldl (<>) r0 (map (f'' s) ds)
325− f' s (ValueDeclaration _ _ bs (Right val)) = foldl (<>) r0 (map (h'' s) bs) <> g'' s val
326− f' s (ValueDeclaration _ _ bs (Left gs)) = foldl (<>) r0 (map (h'' s) bs ++ concatMap (\(grd, val) -> [g'' s grd, g'' s val]) gs)
327− f' s (BindingGroupDeclaration ds) = foldl (<>) r0 (map (\(_, _, val) -> g'' s val) ds)
328− f' s (TypeClassDeclaration _ _ _ ds) = foldl (<>) r0 (map (f'' s) ds)
329− f' s (TypeInstanceDeclaration _ _ _ _ (ExplicitInstance ds)) = foldl (<>) r0 (map (f'' s) ds)
330− f' s (PositionedDeclaration _ _ d1) = f'' s d1
331− f' _ _ = r0
332−
333− g'' :: s -> Expr -> r
334− g'' s v = let (s', r) = g s v in r <> g' s' v
335−
336− g' :: s -> Expr -> r
337− g' s (Literal l) = lit g'' s l
338− g' s (UnaryMinus v1) = g'' s v1
339− g' s (BinaryNoParens op v1 v2) = g'' s op <> g'' s v1 <> g'' s v2
340− g' s (Parens v1) = g'' s v1
341− g' s (OperatorSection op (Left v)) = g'' s op <> g'' s v
342− g' s (OperatorSection op (Right v)) = g'' s op <> g'' s v
343− g' s (TypeClassDictionaryConstructorApp _ v1) = g'' s v1
344− g' s (Accessor _ v1) = g'' s v1
345− g' s (ObjectUpdate obj vs) = foldl (<>) (g'' s obj) (map (g'' s . snd) vs)
346− g' s (Abs _ v1) = g'' s v1
347− g' s (App v1 v2) = g'' s v1 <> g'' s v2
348− g' s (IfThenElse v1 v2 v3) = g'' s v1 <> g'' s v2 <> g'' s v3
349− g' s (Case vs alts) = foldl (<>) (foldl (<>) r0 (map (g'' s) vs)) (map (i'' s) alts)
350− g' s (TypedValue _ v1 _) = g'' s v1
351− g' s (Let ds v1) = foldl (<>) r0 (map (f'' s) ds) <> g'' s v1
352− g' s (Do es) = foldl (<>) r0 (map (j'' s) es)
353− g' s (PositionedValue _ _ v1) = g'' s v1
354− g' _ _ = r0
355−
356− h'' :: s -> Binder -> r
357− h'' s b = let (s', r) = h s b in r <> h' s' b
358−
359− h' :: s -> Binder -> r
360− h' s (LiteralBinder l) = lit h'' s l
361− h' s (ConstructorBinder _ bs) = foldl (<>) r0 (map (h'' s) bs)
362− h' s (BinaryNoParensBinder b1 b2 b3) = h'' s b1 <> h'' s b2 <> h'' s b3
363− h' s (ParensInBinder b) = h'' s b
364− h' s (NamedBinder _ b1) = h'' s b1
365− h' s (PositionedBinder _ _ b1) = h'' s b1
366− h' s (TypedBinder _ b1) = h'' s b1
367− h' _ _ = r0
368−
369− lit :: (s -> a -> r) -> s -> Literal a -> r
370− lit go s (ArrayLiteral as) = foldl (<>) r0 (map (go s) as)
371− lit go s (ObjectLiteral as) = foldl (<>) r0 (map (go s . snd) as)
372− lit _ _ _ = r0
373−
374− i'' :: s -> CaseAlternative -> r
375− i'' s ca = let (s', r) = i s ca in r <> i' s' ca
376−
377− i' :: s -> CaseAlternative -> r
378− i' s (CaseAlternative bs (Right val)) = foldl (<>) r0 (map (h'' s) bs) <> g'' s val
379− i' s (CaseAlternative bs (Left gs)) = foldl (<>) r0 (map (h'' s) bs ++ concatMap (\(grd, val) -> [g'' s grd, g'' s val]) gs)
380−
381− j'' :: s -> DoNotationElement -> r
382− j'' s e = let (s', r) = j s e in r <> j' s' e
383−
384− j' :: s -> DoNotationElement -> r
385− j' s (DoNotationValue v) = g'' s v
386− j' s (DoNotationBind b v) = h'' s b <> g'' s v
387− j' s (DoNotationLet ds) = foldl (<>) r0 (map (f'' s) ds)
388− j' s (PositionedDoNotationElement _ _ e1) = j'' s e1
389−
390−everywhereWithContextOnValuesM
391− :: forall m s
392− . (Monad m)
393− => s
394− -> (s -> Declaration -> m (s, Declaration))
395− -> (s -> Expr -> m (s, Expr))
396− -> (s -> Binder -> m (s, Binder))
397− -> (s -> CaseAlternative -> m (s, CaseAlternative))
398− -> (s -> DoNotationElement -> m (s, DoNotationElement))
399− -> ( Declaration -> m Declaration
400− , Expr -> m Expr
401− , Binder -> m Binder
402− , CaseAlternative -> m CaseAlternative
403− , DoNotationElement -> m DoNotationElement)
404−everywhereWithContextOnValuesM s0 f g h i j = (f'' s0, g'' s0, h'' s0, i'' s0, j'' s0)
405− where
406− f'' s = uncurry f' <=< f s
407−
408− f' s (DataBindingGroupDeclaration ds) = DataBindingGroupDeclaration <$> traverse (f'' s) ds
409− f' s (ValueDeclaration name nameKind bs val) = ValueDeclaration name nameKind <$> traverse (h'' s) bs <*> eitherM (traverse (pairM (g'' s) (g'' s))) (g'' s) val
410− f' s (BindingGroupDeclaration ds) = BindingGroupDeclaration <$> traverse (thirdM (g'' s)) ds
411− f' s (TypeClassDeclaration name args implies ds) = TypeClassDeclaration name args implies <$> traverse (f'' s) ds
412− f' s (TypeInstanceDeclaration name cs className args ds) = TypeInstanceDeclaration name cs className args <$> traverseTypeInstanceBody (traverse (f'' s)) ds
413− f' s (PositionedDeclaration pos com d1) = PositionedDeclaration pos com <$> f'' s d1
414− f' _ other = return other
415−
416− g'' s = uncurry g' <=< g s
417−
418− g' s (Literal l) = Literal <$> lit g'' s l
419− g' s (UnaryMinus v) = UnaryMinus <$> g'' s v
420− g' s (BinaryNoParens op v1 v2) = BinaryNoParens <$> g'' s op <*> g'' s v1 <*> g'' s v2
421− g' s (Parens v) = Parens <$> g'' s v
422− g' s (OperatorSection op (Left v)) = OperatorSection <$> g'' s op <*> (Left <$> g'' s v)
423− g' s (OperatorSection op (Right v)) = OperatorSection <$> g'' s op <*> (Right <$> g'' s v)
424− g' s (TypeClassDictionaryConstructorApp name v) = TypeClassDictionaryConstructorApp name <$> g'' s v
425− g' s (Accessor prop v) = Accessor prop <$> g'' s v
426− g' s (ObjectUpdate obj vs) = ObjectUpdate <$> g'' s obj <*> traverse (sndM (g'' s)) vs
427− g' s (Abs name v) = Abs name <$> g'' s v
428− g' s (App v1 v2) = App <$> g'' s v1 <*> g'' s v2
429− g' s (IfThenElse v1 v2 v3) = IfThenElse <$> g'' s v1 <*> g'' s v2 <*> g'' s v3
430− g' s (Case vs alts) = Case <$> traverse (g'' s) vs <*> traverse (i'' s) alts
431− g' s (TypedValue check v ty) = TypedValue check <$> g'' s v <*> pure ty
432− g' s (Let ds v) = Let <$> traverse (f'' s) ds <*> g'' s v
433− g' s (Do es) = Do <$> traverse (j'' s) es
434− g' s (PositionedValue pos com v) = PositionedValue pos com <$> g'' s v
435− g' _ other = return other
436−
437− h'' s = uncurry h' <=< h s
438−
439− h' s (LiteralBinder l) = LiteralBinder <$> lit h'' s l
440− h' s (ConstructorBinder ctor bs) = ConstructorBinder ctor <$> traverse (h'' s) bs
441− h' s (BinaryNoParensBinder b1 b2 b3) = BinaryNoParensBinder <$> h'' s b1 <*> h'' s b2 <*> h'' s b3
442− h' s (ParensInBinder b) = ParensInBinder <$> h'' s b
443− h' s (NamedBinder name b) = NamedBinder name <$> h'' s b
444− h' s (PositionedBinder pos com b) = PositionedBinder pos com <$> h'' s b
445− h' s (TypedBinder t b) = TypedBinder t <$> h'' s b
446− h' _ other = return other
447−
448− lit :: (s -> a -> m a) -> s -> Literal a -> m (Literal a)
449− lit go s (ArrayLiteral as) = ArrayLiteral <$> traverse (go s) as
450− lit go s (ObjectLiteral as) = ObjectLiteral <$> traverse (sndM (go s)) as
451− lit _ _ other = return other
452−
453− i'' s = uncurry i' <=< i s
454−
455− i' s (CaseAlternative bs val) = CaseAlternative <$> traverse (h'' s) bs <*> eitherM (traverse (pairM (g'' s) (g'' s))) (g'' s) val
456−
457− j'' s = uncurry j' <=< j s
458−
459− j' s (DoNotationValue v) = DoNotationValue <$> g'' s v
460− j' s (DoNotationBind b v) = DoNotationBind <$> h'' s b <*> g'' s v
461− j' s (DoNotationLet ds) = DoNotationLet <$> traverse (f'' s) ds
462− j' s (PositionedDoNotationElement pos com e1) = PositionedDoNotationElement pos com <$> j'' s e1
463−
464−everythingWithScope
465− :: forall r
466− . (Monoid r)
467− => (S.Set Ident -> Declaration -> r)
468− -> (S.Set Ident -> Expr -> r)
469− -> (S.Set Ident -> Binder -> r)
470− -> (S.Set Ident -> CaseAlternative -> r)
471− -> (S.Set Ident -> DoNotationElement -> r)
472− -> ( S.Set Ident -> Declaration -> r
473− , S.Set Ident -> Expr -> r
474− , S.Set Ident -> Binder -> r
475− , S.Set Ident -> CaseAlternative -> r
476− , S.Set Ident -> DoNotationElement -> r
477− )
478−everythingWithScope f g h i j = (f'', g'', h'', i'', \s -> snd . j'' s)
479− where
480− -- Avoid importing Data.Monoid and getting shadowed names above
481− (<>) = mappend
482−
483− f'' :: S.Set Ident -> Declaration -> r
484− f'' s a = f s a <> f' s a
485−
486− f' :: S.Set Ident -> Declaration -> r
487− f' s (DataBindingGroupDeclaration ds) =
488− let s' = S.union s (S.fromList (mapMaybe getDeclIdent ds))
489− in foldMap (f'' s') ds
490− f' s (ValueDeclaration name _ bs (Right val)) =
491− let s' = S.insert name s
492− in foldMap (h'' s') bs <> g'' s' val
493− f' s (ValueDeclaration name _ bs (Left gs)) =
494− let s' = S.insert name s
495− s'' = S.union s' (S.fromList (concatMap binderNames bs))
496− in foldMap (h'' s') bs <> foldMap (\(grd, val) -> g'' s'' grd <> g'' s'' val) gs
497− f' s (BindingGroupDeclaration ds) =
498− let s' = S.union s (S.fromList (map (\(name, _, _) -> name) ds))
499− in foldMap (\(_, _, val) -> g'' s' val) ds
500− f' s (TypeClassDeclaration _ _ _ ds) = foldMap (f'' s) ds
501− f' s (TypeInstanceDeclaration _ _ _ _ (ExplicitInstance ds)) = foldMap (f'' s) ds
502− f' s (PositionedDeclaration _ _ d) = f'' s d
503− f' _ _ = mempty
504−
505− g'' :: S.Set Ident -> Expr -> r
506− g'' s a = g s a <> g' s a
507−
508− g' :: S.Set Ident -> Expr -> r
509− g' s (Literal l) = lit g'' s l
510− g' s (UnaryMinus v1) = g'' s v1
511− g' s (BinaryNoParens op v1 v2) = g'' s op <> g'' s v1 <> g'' s v2
512− g' s (Parens v1) = g'' s v1
513− g' s (OperatorSection op (Left v)) = g'' s op <> g'' s v
514− g' s (OperatorSection op (Right v)) = g'' s op <> g'' s v
515− g' s (TypeClassDictionaryConstructorApp _ v1) = g'' s v1
516− g' s (Accessor _ v1) = g'' s v1
517− g' s (ObjectUpdate obj vs) = g'' s obj <> foldMap (g'' s . snd) vs
518− g' s (Abs (Left name) v1) =
519− let s' = S.insert name s
520− in g'' s' v1
521− g' s (Abs (Right b) v1) =
522− let s' = S.union (S.fromList (binderNames b)) s
523− in g'' s' v1
524− g' s (App v1 v2) = g'' s v1 <> g'' s v2
525− g' s (IfThenElse v1 v2 v3) = g'' s v1 <> g'' s v2 <> g'' s v3
526− g' s (Case vs alts) = foldMap (g'' s) vs <> foldMap (i'' s) alts
527− g' s (TypedValue _ v1 _) = g'' s v1
528− g' s (Let ds v1) =
529− let s' = S.union s (S.fromList (mapMaybe getDeclIdent ds))
530− in foldMap (f'' s') ds <> g'' s' v1
531− g' s (Do es) = fold . snd . mapAccumL j'' s $ es
532− g' s (PositionedValue _ _ v1) = g'' s v1
533− g' _ _ = mempty
534−
535− h'' :: S.Set Ident -> Binder -> r
536− h'' s a = h s a <> h' s a
537−
538− h' :: S.Set Ident -> Binder -> r
539− h' s (LiteralBinder l) = lit h'' s l
540− h' s (ConstructorBinder _ bs) = foldMap (h'' s) bs
541− h' s (BinaryNoParensBinder b1 b2 b3) = foldMap (h'' s) [b1, b2, b3]
542− h' s (ParensInBinder b) = h'' s b
543− h' s (NamedBinder name b1) = h'' (S.insert name s) b1
544− h' s (PositionedBinder _ _ b1) = h'' s b1
545− h' s (TypedBinder _ b1) = h'' s b1
546− h' _ _ = mempty
547−
548− lit :: (S.Set Ident -> a -> r) -> S.Set Ident -> Literal a -> r
549− lit go s (ArrayLiteral as) = foldMap (go s) as
550− lit go s (ObjectLiteral as) = foldMap (go s . snd) as
551− lit _ _ _ = mempty
552−
553− i'' :: S.Set Ident -> CaseAlternative -> r
554− i'' s a = i s a <> i' s a
555−
556− i' :: S.Set Ident -> CaseAlternative -> r
557− i' s (CaseAlternative bs (Right val)) =
558− let s' = S.union s (S.fromList (concatMap binderNames bs))
559− in foldMap (h'' s) bs <> g'' s' val
560− i' s (CaseAlternative bs (Left gs)) =
561− let s' = S.union s (S.fromList (concatMap binderNames bs))
562− in foldMap (h'' s) bs <> foldMap (\(grd, val) -> g'' s' grd <> g'' s' val) gs
563−
564− j'' :: S.Set Ident -> DoNotationElement -> (S.Set Ident, r)
565− j'' s a = let (s', r) = j' s a in (s', j s a <> r)
566−
567− j' :: S.Set Ident -> DoNotationElement -> (S.Set Ident, r)
568− j' s (DoNotationValue v) = (s, g'' s v)
569− j' s (DoNotationBind b v) =
570− let s' = S.union (S.fromList (binderNames b)) s
571− in (s', h'' s b <> g'' s' v)
572− j' s (DoNotationLet ds) =
573− let s' = S.union s (S.fromList (mapMaybe getDeclIdent ds))
574− in (s', foldMap (f'' s') ds)
575− j' s (PositionedDoNotationElement _ _ e1) = j'' s e1
576−
577− getDeclIdent :: Declaration -> Maybe Ident
578− getDeclIdent (PositionedDeclaration _ _ d) = getDeclIdent d
579− getDeclIdent (ValueDeclaration ident _ _ _) = Just ident
580− getDeclIdent (TypeDeclaration ident _) = Just ident
581− getDeclIdent _ = Nothing
582−
583−accumTypes
584− :: (Monoid r)
585− => (Type -> r)
586− -> ( Declaration -> r
587− , Expr -> r
588− , Binder -> r
589− , CaseAlternative -> r
590− , DoNotationElement -> r
591− )
592−accumTypes f = everythingOnValues mappend forDecls forValues (const mempty) (const mempty) (const mempty)
593− where
594− forDecls (DataDeclaration _ _ _ dctors) = mconcat (concatMap (map f . snd) dctors)
595− forDecls (ExternDeclaration _ ty) = f ty
596− forDecls (TypeClassDeclaration _ _ implies _) = mconcat (concatMap (map f . snd) implies)
597− forDecls (TypeInstanceDeclaration _ cs _ tys _) = mconcat (concatMap (map f . snd) cs) `mappend` mconcat (map f tys)
598− forDecls (TypeSynonymDeclaration _ _ ty) = f ty
599− forDecls (TypeDeclaration _ ty) = f ty
600− forDecls _ = mempty
601−
602− forValues (TypeClassDictionary (_, cs) _) = mconcat (map f cs)
603− forValues (SuperClassDictionary _ tys) = mconcat (map f tys)
604− forValues (TypedValue _ _ ty) = f ty
605− forValues _ = mempty
src/Language/PureScript/Bundle.hsdeleted−607
@@ -1,607 +0,0 @@
1−-----------------------------------------------------------------------------
2−--
3−-- Module : psc-bundle
4−-- Copyright : (c) Phil Freeman 2015
5−-- License : MIT
6−--
7−-- Maintainer : Phil Freeman <paf31@cantab.net>
8−-- Stability : experimental
9−-- Portability :
10−--
11−-- | Bundles compiled PureScript modules for the browser.
12−--
13−-- This module takes as input the individual generated modules from 'Language.PureScript.Make' and
14−-- performs dead code elimination, filters empty modules,
15−-- and generates the final Javascript bundle.
16−-----------------------------------------------------------------------------
17−
18−{-# LANGUAGE PatternGuards #-}
19−{-# LANGUAGE FlexibleContexts #-}
20−{-# LANGUAGE ScopedTypeVariables #-}
21−{-# LANGUAGE TupleSections #-}
22−
23−module Language.PureScript.Bundle (
24− bundle
25− , ModuleIdentifier(..)
26− , moduleName
27− , ModuleType(..)
28− , ErrorMessage(..)
29− , printErrorMessage
30− , getExportedIdentifiers
31−) where
32−
33−import Prelude ()
34−import Prelude.Compat
35−
36−import Data.List (nub, stripPrefix)
37−import Data.Maybe (mapMaybe, catMaybes, fromMaybe)
38−import Data.Generics (everything, everywhere, mkQ, mkT)
39−import Data.Graph
40−import Data.Version (showVersion)
41−
42−import qualified Data.Set as S
43−
44−import Control.Monad
45−import Control.Monad.Error.Class
46−import Language.JavaScript.Parser
47−import Language.JavaScript.Parser.AST
48−
49−import qualified Paths_purescript as Paths
50−
51−-- | The type of error messages. We separate generation and rendering of errors using a data
52−-- type, in case we need to match on error types later.
53−data ErrorMessage
54− = UnsupportedModulePath String
55− | InvalidTopLevel
56− | UnableToParseModule String
57− | UnsupportedExport
58− | ErrorInModule ModuleIdentifier ErrorMessage
59− deriving (Show, Read)
60−
61−-- | Modules are either "regular modules" (i.e. those generated by psc) or foreign modules.
62−data ModuleType
63− = Regular
64− | Foreign
65− deriving (Show, Read, Eq, Ord)
66−
67−showModuleType :: ModuleType -> String
68−showModuleType Regular = "Regular"
69−showModuleType Foreign = "Foreign"
70−
71−-- | A module is identified by its module name and its type.
72−data ModuleIdentifier = ModuleIdentifier String ModuleType deriving (Show, Read, Eq, Ord)
73−
74−moduleName :: ModuleIdentifier -> String
75−moduleName (ModuleIdentifier name _) = name
76−
77−-- | A piece of code is identified by its module and its name. These keys are used to label vertices
78−-- in the dependency graph.
79−type Key = (ModuleIdentifier, String)
80−
81−-- | An export is either a "regular export", which exports a name from the regular module we are in,
82−-- or a reexport of a declaration in the corresponding foreign module.
83−--
84−-- Regular exports are labelled, since they might re-export an operator with another name.
85−data ExportType
86− = RegularExport String
87− | ForeignReexport
88− deriving (Show, Eq, Ord)
89−
90−-- | There are four types of module element we are interested in:
91−--
92−-- 1) Require statements
93−-- 2) Member declarations
94−-- 3) Export lists
95−-- 4) Everything else
96−--
97−-- Each is labelled with the original AST node which generated it, so that we can dump it back
98−-- into the output during codegen.
99−data ModuleElement
100− = Require JSStatement String (Either String ModuleIdentifier)
101− | Member JSStatement Bool String JSExpression [Key]
102− | ExportsList [(ExportType, String, JSExpression, [Key])]
103− | Other JSStatement
104− deriving (Show)
105−
106−-- | A module is just a list of elements of the types listed above.
107−data Module = Module ModuleIdentifier [ModuleElement] deriving (Show)
108−
109−-- | Prepare an error message for consumption by humans.
110−printErrorMessage :: ErrorMessage -> [String]
111−printErrorMessage (UnsupportedModulePath s) =
112− [ "A CommonJS module has an unsupported name (" ++ show s ++ ")."
113− , "The following file names are supported:"
114− , " 1) index.js (psc native modules)"
115− , " 2) foreign.js (psc foreign modules)"
116− ]
117−printErrorMessage InvalidTopLevel =
118− [ "Expected a list of source elements at the top level." ]
119−printErrorMessage (UnableToParseModule err) =
120− [ "The module could not be parsed:"
121− , err
122− ]
123−printErrorMessage UnsupportedExport =
124− [ "An export was unsupported. Exports can be defined in one of two ways: "
125− , " 1) exports.name = ..."
126− , " 2) exports = { ... }"
127− ]
128−printErrorMessage (ErrorInModule mid e) =
129− ("Error in module " ++ displayIdentifier mid ++ ":")
130− : ""
131− : map (" " ++) (printErrorMessage e)
132− where
133− displayIdentifier (ModuleIdentifier name ty) =
134− name ++ " (" ++ showModuleType ty ++ ")"
135−
136−-- | Calculate the ModuleIdentifier which a require(...) statement imports.
137−checkImportPath :: Maybe FilePath -> String -> ModuleIdentifier -> S.Set String -> Either String ModuleIdentifier
138−checkImportPath _ "./foreign" m _ =
139− Right (ModuleIdentifier (moduleName m) Foreign)
140−checkImportPath requirePath name _ names
141− | Just name' <- stripPrefix (fromMaybe "../" requirePath) name
142− , name' `S.member` names = Right (ModuleIdentifier name' Regular)
143−checkImportPath _ name _ _ = Left name
144−
145−-- | Compute the dependencies of all elements in a module, and add them to the tree.
146−--
147−-- Members and exports can have dependencies. A dependency is of one of the following forms:
148−--
149−-- 1) module.name or member["name"]
150−--
151−-- where module was imported using
152−--
153−-- var module = require("Module.Name");
154−--
155−-- 2) name
156−--
157−-- where name is the name of a member defined in the current module.
158−withDeps :: Module -> Module
159−withDeps (Module modulePath es) = Module modulePath (map expandDeps es)
160− where
161− -- | Collects all modules which are imported, so that we can identify dependencies of the first type.
162− imports :: [(String, ModuleIdentifier)]
163− imports = mapMaybe toImport es
164− where
165− toImport :: ModuleElement -> Maybe (String, ModuleIdentifier)
166− toImport (Require _ nm (Right mid)) = Just (nm, mid)
167− toImport _ = Nothing
168−
169− -- | Collects all member names in scope, so that we can identify dependencies of the second type.
170− boundNames :: [String]
171− boundNames = mapMaybe toBoundName es
172− where
173− toBoundName :: ModuleElement -> Maybe String
174− toBoundName (Member _ _ nm _ _) = Just nm
175− toBoundName _ = Nothing
176−
177− -- | Calculate dependencies and add them to the current element.
178− expandDeps :: ModuleElement -> ModuleElement
179− expandDeps (Member n f nm decl _) = Member n f nm decl (nub $ dependencies modulePath decl)
180− expandDeps (ExportsList exps) = ExportsList (map expand exps)
181− where
182− expand (ty, nm, n1, _) = (ty, nm, n1, nub (dependencies modulePath n1))
183− expandDeps other = other
184−
185− dependencies :: ModuleIdentifier -> JSExpression -> [(ModuleIdentifier, String)]
186− dependencies m = everything (++) (mkQ [] toReference)
187− where
188− toReference :: JSExpression -> [(ModuleIdentifier, String)]
189− toReference (JSMemberDot mn _ nm)
190− | JSIdentifier _ mn' <- mn
191− , JSIdentifier _ nm' <- nm
192− , Just mid <- lookup mn' imports
193− = [(mid, nm')]
194− toReference (JSMemberSquare mn _ nm _)
195− | JSIdentifier _ mn' <- mn
196− , Just nm' <- fromStringLiteral nm
197− , Just mid <- lookup mn' imports
198− = [(mid, nm')]
199− toReference (JSIdentifier _ nm)
200− | nm `elem` boundNames
201− = [(m, nm)]
202− toReference _ = []
203−
204−-- String literals include the quote chars
205−fromStringLiteral :: JSExpression -> Maybe String
206−fromStringLiteral (JSStringLiteral _ str) = Just $ trimStringQuotes str
207−fromStringLiteral _ = Nothing
208−
209−trimStringQuotes :: String -> String
210−trimStringQuotes str = reverse $ drop 1 $ reverse $ drop 1 $ str
211−
212−commaList :: JSCommaList a -> [a]
213−commaList JSLNil = []
214−commaList (JSLOne x) = [x]
215−commaList (JSLCons l _ x) = commaList l ++ [x]
216−
217−trailingCommaList :: JSCommaTrailingList a -> [a]
218−trailingCommaList (JSCTLComma l _) = commaList l
219−trailingCommaList (JSCTLNone l) = commaList l
220−
221−-- | Attempt to create a Module from a Javascript AST.
222−--
223−-- Each type of module element is matched using pattern guards, and everything else is bundled into the
224−-- Other constructor.
225−toModule :: forall m. (MonadError ErrorMessage m) => Maybe FilePath -> S.Set String -> ModuleIdentifier -> JSAST -> m Module
226−toModule requirePath mids mid top
227− | JSAstProgram smts _ <- top = Module mid <$> traverse toModuleElement smts
228− | otherwise = err InvalidTopLevel
229− where
230− err = throwError . ErrorInModule mid
231−
232− toModuleElement :: JSStatement -> m ModuleElement
233− toModuleElement stmt
234− | Just (importName, importPath) <- matchRequire requirePath mids mid stmt
235− = pure (Require stmt importName importPath)
236− toModuleElement stmt
237− | Just (exported, name, decl) <- matchMember stmt
238− = pure (Member stmt exported name decl [])
239− toModuleElement stmt
240− | Just props <- matchExportsAssignment stmt
241− = (ExportsList <$> traverse toExport (trailingCommaList props))
242− where
243− toExport :: JSObjectProperty -> m (ExportType, String, JSExpression, [Key])
244− toExport (JSPropertyNameandValue name _ [val]) =
245− (,,val,[]) <$> exportType val
246− <*> extractLabel' name
247− toExport _ = err UnsupportedExport
248−
249− exportType :: JSExpression -> m ExportType
250− exportType (JSMemberDot f _ _)
251− | JSIdentifier _ "$foreign" <- f
252− = pure ForeignReexport
253− exportType (JSMemberSquare f _ _ _)
254− | JSIdentifier _ "$foreign" <- f
255− = pure ForeignReexport
256− exportType (JSIdentifier _ s) = pure (RegularExport s)
257− exportType _ = err UnsupportedExport
258−
259− extractLabel' = maybe (err UnsupportedExport) pure . extractLabel
260−
261− toModuleElement other = pure (Other other)
262−
263−-- Get a list of all the exported identifiers from a foreign module.
264−--
265−-- TODO: what if we assign to exports.foo and then later assign to
266−-- module.exports (presumably overwriting exports.foo)?
267−getExportedIdentifiers :: (MonadError ErrorMessage m)
268− => String
269− -> JSAST
270− -> m [String]
271−getExportedIdentifiers mname top
272− | JSAstProgram stmts _ <- top = concat <$> traverse go stmts
273− | otherwise = err InvalidTopLevel
274− where
275− err = throwError . ErrorInModule (ModuleIdentifier mname Foreign)
276−
277− go stmt
278− | Just props <- matchExportsAssignment stmt
279− = traverse toIdent (trailingCommaList props)
280− | Just (True, name, _) <- matchMember stmt
281− = pure [name]
282− | otherwise
283− = pure []
284−
285− toIdent (JSPropertyNameandValue name _ [_]) =
286− extractLabel' name
287− toIdent _ =
288− err UnsupportedExport
289−
290− extractLabel' = maybe (err UnsupportedExport) pure . extractLabel
291−
292−-- Matches JS statements like this:
293−-- var ModuleName = require("file");
294−matchRequire :: Maybe FilePath
295− -> S.Set String
296− -> ModuleIdentifier
297− -> JSStatement
298− -> Maybe (String, Either String ModuleIdentifier)
299−matchRequire requirePath mids mid stmt
300− | JSVariable _ jsInit _ <- stmt
301− , [JSVarInitExpression var varInit] <- commaList jsInit
302− , JSIdentifier _ importName <- var
303− , JSVarInit _ jsInitEx <- varInit
304− , JSMemberExpression req _ argsE _ <- jsInitEx
305− , JSIdentifier _ "require" <- req
306− , [ Just importPath ] <- map fromStringLiteral (commaList argsE)
307− , importPath' <- checkImportPath requirePath importPath mid mids
308− = Just (importName, importPath')
309− | otherwise
310− = Nothing
311−
312−-- Matches JS member declarations.
313−matchMember :: JSStatement -> Maybe (Bool, String, JSExpression)
314−matchMember stmt
315− -- var foo = expr;
316− | JSVariable _ jsInit _ <- stmt
317− , [JSVarInitExpression var varInit] <- commaList jsInit
318− , JSIdentifier _ name <- var
319− , JSVarInit _ decl <- varInit
320− = Just (False, name, decl)
321− -- exports.foo = expr; exports["foo"] = expr;
322− | JSAssignStatement e (JSAssign _) decl _ <- stmt
323− , Just name <- accessor e
324− = Just (True, name, decl)
325− | otherwise
326− = Nothing
327− where
328− accessor :: JSExpression -> Maybe String
329− accessor (JSMemberDot exports _ nm)
330− | JSIdentifier _ "exports" <- exports
331− , JSIdentifier _ name <- nm
332− = Just name
333− accessor (JSMemberSquare exports _ nm _)
334− | JSIdentifier _ "exports" <- exports
335− , Just name <- fromStringLiteral nm
336− = Just name
337− accessor _ = Nothing
338−
339−-- Matches assignments to module.exports, like this:
340−-- module.exports = { ... }
341−matchExportsAssignment :: JSStatement -> Maybe JSObjectPropertyList
342−matchExportsAssignment stmt
343− | JSAssignStatement e (JSAssign _) decl _ <- stmt
344− , JSMemberDot module' _ exports <- e
345− , JSIdentifier _ "module" <- module'
346− , JSIdentifier _ "exports" <- exports
347− , JSObjectLiteral _ props _ <- decl
348− = Just props
349− | otherwise
350− = Nothing
351−
352−extractLabel :: JSPropertyName -> Maybe String
353−extractLabel (JSPropertyString _ nm) = Just (trimStringQuotes nm)
354−extractLabel (JSPropertyIdent _ nm) = Just nm
355−extractLabel _ = Nothing
356−
357−-- | Eliminate unused code based on the specified entry point set.
358−compile :: [Module] -> [ModuleIdentifier] -> [Module]
359−compile modules [] = modules
360−compile modules entryPoints = filteredModules
361− where
362− (graph, _, vertexFor) = graphFromEdges verts
363−
364− -- | The vertex set
365− verts :: [(ModuleElement, Key, [Key])]
366− verts = do
367− Module mid els <- modules
368− concatMap (toVertices mid) els
369− where
370− -- | Create a set of vertices for a module element.
371− --
372− -- Some special cases worth commenting on:
373− --
374− -- 1) Regular exports which simply export their own name do not count as dependencies.
375− -- Regular exports which rename and reexport an operator do count, however.
376− --
377− -- 2) Require statements don't contribute towards dependencies, since they effectively get
378− -- inlined wherever they are used inside other module elements.
379− toVertices :: ModuleIdentifier -> ModuleElement -> [(ModuleElement, Key, [Key])]
380− toVertices p m@(Member _ _ nm _ deps) = [(m, (p, nm), deps)]
381− toVertices p m@(ExportsList exps) = mapMaybe toVertex exps
382− where
383− toVertex (ForeignReexport, nm, _, ks) = Just (m, (p, nm), ks)
384− toVertex (RegularExport nm, nm1, _, ks) | nm /= nm1 = Just (m, (p, nm1), ks)
385− toVertex _ = Nothing
386− toVertices _ _ = []
387−
388− -- | The set of vertices whose connected components we are interested in keeping.
389− entryPointVertices :: [Vertex]
390− entryPointVertices = catMaybes $ do
391− (_, k@(mid, _), _) <- verts
392− guard $ mid `elem` entryPoints
393− return (vertexFor k)
394−
395− -- | The set of vertices reachable from an entry point
396− reachableSet :: S.Set Vertex
397− reachableSet = S.fromList (concatMap (reachable graph) entryPointVertices)
398−
399− filteredModules :: [Module]
400− filteredModules = map filterUsed modules
401− where
402− filterUsed :: Module -> Module
403− filterUsed (Module mid ds) = Module mid (map filterExports (go ds))
404− where
405− go :: [ModuleElement] -> [ModuleElement]
406− go [] = []
407− go (d : rest)
408− | not (isDeclUsed d) = go rest
409− | otherwise = d : go rest
410−
411− -- | Filter out the exports for members which aren't used.
412− filterExports :: ModuleElement -> ModuleElement
413− filterExports (ExportsList exps) = ExportsList (filter (\(_, nm, _, _) -> isKeyUsed (mid, nm)) exps)
414− filterExports me = me
415−
416− isDeclUsed :: ModuleElement -> Bool
417− isDeclUsed (Member _ _ nm _ _) = isKeyUsed (mid, nm)
418− isDeclUsed _ = True
419−
420− isKeyUsed :: Key -> Bool
421− isKeyUsed k
422− | Just me <- vertexFor k = me `S.member` reachableSet
423− | otherwise = False
424−
425−-- | Topologically sort the module dependency graph, so that when we generate code, modules can be
426−-- defined in the right order.
427−sortModules :: [Module] -> [Module]
428−sortModules modules = map (\v -> case nodeFor v of (n, _, _) -> n) (reverse (topSort graph))
429− where
430− (graph, nodeFor, _) = graphFromEdges $ do
431− m@(Module mid els) <- modules
432− return (m, mid, mapMaybe getKey els)
433−
434− getKey :: ModuleElement -> Maybe ModuleIdentifier
435− getKey (Require _ _ (Right mi)) = Just mi
436− getKey _ = Nothing
437−
438−-- | A module is empty if it contains no exported members (in other words,
439−-- if the only things left after dead code elimination are module imports and
440−-- "other" foreign code).
441−--
442−-- If a module is empty, we don't want to generate code for it.
443−isModuleEmpty :: Module -> Bool
444−isModuleEmpty (Module _ els) = all isElementEmpty els
445− where
446− isElementEmpty :: ModuleElement -> Bool
447− isElementEmpty (ExportsList exps) = null exps
448− isElementEmpty Require{} = True
449− isElementEmpty (Other _) = True
450− isElementEmpty _ = False
451−
452−-- | Generate code for a set of modules, including a call to main().
453−--
454−-- Modules get defined on the global PS object, as follows:
455−--
456−-- var PS = { };
457−-- (function(exports) {
458−-- ...
459−-- })(PS["Module.Name"] = PS["Module.Name"] || {});
460−--
461−-- In particular, a module and its foreign imports share the same namespace inside PS.
462−-- This saves us from having to generate unique names for a module and its foreign imports,
463−-- and is safe since a module shares a namespace with its foreign imports in PureScript as well
464−-- (so there is no way to have overlaps in code generated by psc).
465−codeGen :: Maybe String -- ^ main module
466− -> String -- ^ namespace
467− -> [Module] -- ^ input modules
468− -> String
469−codeGen optionsMainModule optionsNamespace ms = renderToString (JSAstProgram (prelude : concatMap moduleToJS ms ++ maybe [] runMain optionsMainModule) JSNoAnnot)
470− where
471− moduleToJS :: Module -> [JSStatement]
472− moduleToJS (Module mn ds) = wrap (moduleName mn) (indent (concatMap declToJS ds))
473− where
474− declToJS :: ModuleElement -> [JSStatement]
475− declToJS (Member n _ _ _ _) = [n]
476− declToJS (Other n) = [n]
477− declToJS (Require _ nm req) =
478− [
479− JSVariable lfsp
480− (cList [
481− JSVarInitExpression (JSIdentifier sp nm)
482− (JSVarInit sp $ either require (moduleReference sp . moduleName) req )
483− ]) (JSSemi JSNoAnnot)
484− ]
485− declToJS (ExportsList exps) = map toExport exps
486−
487− where
488− toExport :: (ExportType, String, JSExpression, [Key]) -> JSStatement
489− toExport (_, nm, val, _) =
490− JSAssignStatement
491− (JSMemberSquare (JSIdentifier lfsp "exports") JSNoAnnot
492− (str nm) JSNoAnnot)
493− (JSAssign sp)
494− val
495− (JSSemi JSNoAnnot)
496−
497− -- comma lists are reverse-consed
498− cList :: [a] -> JSCommaList a
499− cList [] = JSLNil
500− cList [x] = JSLOne x
501− cList l = go $ reverse l
502− where
503− go [x] = JSLOne x
504− go (h:t)= JSLCons (go t) JSNoAnnot h
505− go [] = error "Invalid case in comma-list"
506−
507− indent :: [JSStatement] -> [JSStatement]
508− indent = everywhere (mkT squash)
509− where
510− squash JSNoAnnot = (JSAnnot (TokenPn 0 0 2) [])
511− squash (JSAnnot pos ann) = JSAnnot (keepCol pos) (map splat ann)
512−
513− splat (CommentA pos s) = CommentA (keepCol pos) s
514− splat (WhiteSpace pos w) = WhiteSpace (keepCol pos) w
515− splat ann = ann
516−
517− keepCol (TokenPn _ _ c) = TokenPn 0 0 (if c >= 0 then c + 2 else 2)
518−
519− prelude :: JSStatement
520− prelude = JSVariable (JSAnnot tokenPosnEmpty [ CommentA tokenPosnEmpty $ "// Generated by psc-bundle " ++ showVersion Paths.version
521− , WhiteSpace tokenPosnEmpty "\n" ])
522− (cList [
523− JSVarInitExpression (JSIdentifier sp optionsNamespace)
524− (JSVarInit sp (emptyObj sp))
525− ]) (JSSemi JSNoAnnot)
526−
527− require :: String -> JSExpression
528− require mn =
529− JSMemberExpression (JSIdentifier JSNoAnnot "require") JSNoAnnot (cList [ str mn ]) JSNoAnnot
530−
531− moduleReference :: JSAnnot -> String -> JSExpression
532− moduleReference a mn =
533− JSMemberSquare (JSIdentifier a optionsNamespace) JSNoAnnot
534− (str mn) JSNoAnnot
535−
536− str :: String -> JSExpression
537− str s = JSStringLiteral JSNoAnnot $ "\"" ++ s ++ "\""
538−
539−
540− emptyObj :: JSAnnot -> JSExpression
541− emptyObj a = JSObjectLiteral a (JSCTLNone JSLNil) JSNoAnnot
542−
543− wrap :: String -> [JSStatement] -> [JSStatement]
544− wrap mn ds =
545− [
546− JSMethodCall (JSExpressionParen lf (JSFunctionExpression JSNoAnnot JSIdentNone JSNoAnnot
547− (JSLOne (JSIdentName JSNoAnnot "exports")) JSNoAnnot
548− (JSBlock sp (lfHead ds) lf)) -- \n not quite in right place
549− JSNoAnnot)
550− JSNoAnnot
551− (JSLOne (JSAssignExpression (moduleReference JSNoAnnot mn) (JSAssign sp)
552− (JSExpressionBinary (moduleReference sp mn) (JSBinOpOr sp) (emptyObj sp))))
553− JSNoAnnot
554− (JSSemi JSNoAnnot)
555− ]
556− where
557− lfHead (h:t) = (addAnn (WhiteSpace tokenPosnEmpty "\n ") h) : t
558− lfHead x = x
559−
560− addAnn :: CommentAnnotation -> JSStatement -> JSStatement
561− addAnn a (JSExpressionStatement (JSStringLiteral ann s) _) =
562− (JSExpressionStatement (JSStringLiteral (appendAnn a ann) s) (JSSemi JSNoAnnot))
563− addAnn _ x = x
564−
565− appendAnn a JSNoAnnot = (JSAnnot tokenPosnEmpty [a])
566− appendAnn a (JSAnnot _ anns) = JSAnnot tokenPosnEmpty (a:anns ++ [WhiteSpace tokenPosnEmpty " "])
567−
568− runMain :: String -> [JSStatement]
569− runMain mn =
570− [JSMethodCall
571− (JSMemberDot (moduleReference lf mn) JSNoAnnot
572− (JSIdentifier JSNoAnnot "main"))
573− JSNoAnnot (cList []) JSNoAnnot (JSSemi JSNoAnnot)]
574−
575− lf :: JSAnnot
576− lf = JSAnnot tokenPosnEmpty [ WhiteSpace tokenPosnEmpty "\n" ]
577−
578−
579− lfsp :: JSAnnot
580− lfsp = JSAnnot tokenPosnEmpty [ WhiteSpace tokenPosnEmpty "\n " ]
581−
582− sp :: JSAnnot
583− sp = JSAnnot tokenPosnEmpty [ WhiteSpace tokenPosnEmpty " " ]
584−
585−-- | The bundling function.
586−-- This function performs dead code elimination, filters empty modules
587−-- and generates and prints the final Javascript bundle.
588−bundle :: (MonadError ErrorMessage m)
589− => [(ModuleIdentifier, String)] -- ^ The input modules. Each module should be javascript rendered from 'Language.PureScript.Make' or @psc@.
590− -> [ModuleIdentifier] -- ^ Entry points. These module identifiers are used as the roots for dead-code elimination
591− -> Maybe String -- ^ An optional main module.
592− -> String -- ^ The namespace (e.g. PS).
593− -> Maybe FilePath -- ^ The require path prefix
594− -> m String
595−bundle inputStrs entryPoints mainModule namespace requirePath = do
596− input <- forM inputStrs $ \(ident, js) -> do
597− ast <- either (throwError . ErrorInModule ident . UnableToParseModule) pure $ parse js (moduleName ident)
598− return (ident, ast)
599−
600− let mids = S.fromList (map (moduleName . fst) input)
601−
602− modules <- traverse (fmap withDeps . uncurry (toModule requirePath mids)) input
603−
604− let compiled = compile modules entryPoints
605− sorted = sortModules (filter (not . isModuleEmpty) compiled)
606−
607− return (codeGen mainModule namespace sorted)
src/Language/PureScript/CodeGen.hsdeleted−20
@@ -1,20 +0,0 @@
1−-----------------------------------------------------------------------------
2−--
3−-- Module : Language.PureScript.CodeGen
4−-- Copyright : (c) Phil Freeman 2013
5−-- License : MIT
6−--
7−-- Maintainer : Phil Freeman <paf31@cantab.net>
8−-- Stability : experimental
9−-- Portability :
10−--
11−-- |
12−-- A collection of modules related to code generation:
13−--
14−-- [@Language.PureScript.CodeGen.JS@] Code generator for Javascript
15−--
16−-----------------------------------------------------------------------------
17−
18−module Language.PureScript.CodeGen (module C) where
19−
20−import Language.PureScript.CodeGen.JS as C
src/Language/PureScript/CodeGen/Cpp.hsdeleted−870
@@ -1,870 +0,0 @@
1−---------------------------------------------------------------------------------------------------
2−--
3−-- Module : Language.PureScript.CodeGen.Cpp
4−-- Copyright : (c) 2013-15 Phil Freeman, Andy Arvanitis, and other contributors
5−-- License : MIT
6−--
7−-- Maintainer : Andy Arvanitis <andy.arvanitis@gmail.com>
8−-- Stability : experimental
9−-- Portability :
10−--
11−-- |
12−-- This module generates code in the simplified C++1x intermediate representation from
13−-- Purescript code.
14−--
15−---------------------------------------------------------------------------------------------------
16−{-# LANGUAGE GADTs #-}
17−{-# LANGUAGE ViewPatterns #-}
18−{-# LANGUAGE FlexibleContexts #-}
19−{-# LANGUAGE ScopedTypeVariables #-}
20−{-# LANGUAGE PatternGuards #-}
21−
22−module Language.PureScript.CodeGen.Cpp
23− ( module AST
24− , module Common
25− , moduleToCpp
26− , P.prettyPrintCpp
27− ) where
28−
29−import Data.Char (isLetter)
30−import Data.List
31−import Data.Function (on)
32−import Data.Maybe (catMaybes)
33−import qualified Data.Map as M
34−
35−import Control.Monad (forM, replicateM)
36−import Control.Monad.Reader (MonadReader)
37−import Control.Monad.Supply.Class
38−import Language.PureScript.AST.SourcePos
39−import Language.PureScript.CodeGen.Cpp.AST as AST
40−import Language.PureScript.CodeGen.Cpp.Common as Common
41−import Language.PureScript.CodeGen.Cpp.File
42−import Language.PureScript.CodeGen.Cpp.Optimizer
43−import Language.PureScript.CodeGen.Cpp.Optimizer.TCO
44−import Language.PureScript.CodeGen.Cpp.Types
45−import Language.PureScript.Comments
46−import Language.PureScript.CoreFn
47−import Language.PureScript.Names
48−import Language.PureScript.Options
49−import Language.PureScript.Sugar.TypeClasses (superClassDictionaryNames)
50−import Language.PureScript.Traversals (sndM)
51−
52−import qualified Language.PureScript.Constants as C
53−import qualified Language.PureScript.Environment as E
54−import qualified Language.PureScript.Pretty.Cpp as P
55−import qualified Language.PureScript.Types as T
56−
57−-- |
58−-- Generate code in the simplified C++1x intermediate representation for all declarations in a
59−-- module.
60−--
61−---------------------------------------------------------------------------------------------------
62−moduleToCpp :: forall m. (Applicative m, Monad m, MonadReader Options m, MonadSupply m)
63− => E.Environment -> Module Ann -> m [Cpp]
64−---------------------------------------------------------------------------------------------------
65−moduleToCpp env (Module _ mn imps _ foreigns decls) = do
66− cppImports <-
67− traverse (pure . runModuleName) .
68− delete (ModuleName [ProperName C.prim]) . (\\ [mn]) $
69− (snd <$> imps)
70− let cppImports' = "PureScript" : cppImports
71− cppDecls <- concat <$> mapM (bindToCpp [CppTopLevel]) decls
72− cppDecls' <- traverse optimize cppDecls
73− foreignWrappers <- curriedForeigns
74− let optimized = cppDecls' ++ foreignWrappers
75− let moduleHeader =
76− fileBegin mn "HH" ++
77− P.linebreak ++
78− ((\i -> CppInclude i i) <$> cppImports') ++
79− (if not (null foreigns)
80− then [CppInclude [] (runModuleName mn ++ "_ffi")]
81− else []) ++
82− P.linebreak ++
83− [ CppNamespace (runModuleName mn) $
84− (CppUseNamespace <$> cppImports') ++
85− P.linebreak ++
86− dataCtors ++
87− toHeader optimized ++
88− toHeaderFns optimized
89− ] ++
90− P.linebreak ++
91− fileEnd mn "HH"
92− let bodyCpps = toBodyDecl optimized ++ toBody optimized
93− moduleBody =
94− CppInclude (runModuleName mn) (runModuleName mn) :
95− P.linebreak ++
96− (if null bodyCpps
97− then []
98− else [ CppNamespace (runModuleName mn) $
99− (CppUseNamespace <$> cppImports') ++
100− P.linebreak ++ bodyCpps ]) ++
101− P.linebreak ++
102− (if isMain mn
103− then [nativeMain] ++ P.linebreak
104− else [])
105− return $ moduleHeader ++ CppEndOfHeader : moduleBody
106− where
107− -- |
108− -- Generate code in the simplified C++1x intermediate representation for a declaration
109− --
110− -------------------------------------------------------------------------------------------------
111− bindToCpp :: [CppValueQual] -> Bind Ann -> m [Cpp]
112− -------------------------------------------------------------------------------------------------
113− bindToCpp qs (NonRec ann ident val) = return <$> declToCpp qs (ann, ident) val
114− bindToCpp qs (Rec vals) = forM vals (uncurry $ declToCpp (CppRecursive:qs))
115−
116− -- |
117− -- Desugar a declaration into a variable introduction or named function
118− -- declaration.
119− -------------------------------------------------------------------------------------------------
120− declToCpp :: [CppValueQual] -> (Ann, Ident) -> Expr Ann -> m Cpp
121− -------------------------------------------------------------------------------------------------
122− declToCpp _ (_, ident) e@(Abs (_, _, _, Just IsTypeClassConstructor) _ _) =
123− let className = identToCpp ident
124− (supers, members) = span (C.__superclass_ `isPrefixOf`) (identToCpp <$> (fst $ unAbs e []))
125− in return $ CppStruct className [CppEnum Nothing Nothing (sort supers ++ members)]
126−
127− declToCpp _ (_, Op _) (Var (_, _, Nothing, _) _) =
128− return CppNoOp -- skip operator aliases
129−
130− declToCpp vqs (_, ident) (Abs (_, com, ty, _) arg body) = do
131− fn <- if argcnt > 1 && CppTopLevel `elem` vqs
132− then do
133− argNames <- replicateM (argcnt - length args' - 1) freshName
134− let args'' = zip argNames (repeat aty)
135− block <- asReturnBlock <$> valueToCpp
136− (if null argNames
137− then snd abs'
138− else curriedApp
139− (tail argNames)
140− (App
141− nullAnn
142− (snd abs')
143− (Var nullAnn . Qualified Nothing . Ident $ head argNames)))
144− return $ CppNamespace ""
145− [ CppFunction
146− name
147− (arg' : args' ++ args'')
148− rty
149− (vqs ++ if isAccessor (snd abs') then [CppInline] else [])
150− (convertNestedLambdas $ convertDictIndexers block)
151− , CppFunction
152− (curriedName name)
153− [arg']
154− rty
155− []
156− (asReturnBlock $
157− curriedLambda
158− (fst <$> args' ++ args'')
159− (CppApp (CppVar name)
160− (CppVar . fst <$> (arg' : args' ++ args''))))
161− ]
162− else do
163− block <- valueToCpp body
164− return $ CppFunction
165− name
166− [arg']
167− rty
168− (vqs ++ if isIndexer block then [CppInline] else [])
169− (convertNestedLambdas . asReturnBlock $ convertDictIndexers block)
170− return (CppComment com fn)
171− where
172− ty' | Just t <- ty = Just t
173− | Just (t, _, _) <- M.lookup (mn, ident) (E.names env) = Just t
174− | otherwise = Nothing
175− argcnt = maybe 0 countArgs ty'
176− name = identToCpp ident
177− aty = Just $ CppAny [CppConst, CppRef]
178− rty = Just $ CppAny []
179− arg' = (identToCpp arg, aty)
180− args' = (\i -> (identToCpp i, aty)) <$> fst abs'
181− abs' = unAbs body []
182− isAccessor :: Expr Ann -> Bool
183− isAccessor Accessor{} = True
184− isAccessor _ = False
185− isIndexer :: Cpp -> Bool
186− isIndexer (CppIndexer (CppStringLiteral _) (CppVar _)) = True
187− isIndexer _ = False
188− classes = qualifiedToCpp (Ident . runProperName) . fst <$>
189− maybe [] extractConstraints ty'
190− dictClasses = zip (CppVar . fst <$> arg' : args') classes
191− convertDictIndexers = everywhereOnCpp (dictIndexerToEnum dictClasses)
192−
193− declToCpp _ (_, ident) (Constructor _ _ (ProperName _) []) =
194− return $
195− CppFunction
196− (identToCpp ident)
197− []
198− (Just $ CppAny [])
199− [CppInline]
200− (asReturnBlock $
201− CppDataLiteral [CppAccessor (CppVar $ identToCpp ident) (CppVar "data")])
202−
203− declToCpp _ (_, ident) (Constructor _ _ (ProperName _) fields) =
204− return . CppNamespace "" $
205− [ CppFunction
206− name
207− (farg <$> fields')
208− (Just $ CppAny [])
209− [CppInline]
210− (asReturnBlock $
211− CppDataLiteral $
212− CppAccessor (CppVar name) (CppVar "data") : (CppVar <$> fields'))
213− ] ++
214− if length fields > 1
215− then
216− [ CppFunction
217− (curriedName name)
218− (farg <$> f)
219− (Just $ CppAny [])
220− []
221− (CppBlock (fieldLambdas fs))
222− ]
223− else
224− []
225− where
226− name = identToCpp ident
227− fields' = identToCpp <$> fields
228− (f, fs) | (f' : fs') <- fields' = ([f'], fs')
229− | otherwise = ([], [])
230− farg = \x -> (x, Just $ CppAny [CppConst, CppRef])
231− fieldLambdas flds
232− | (f' : fs') <- flds = [ CppReturn . maybeRemCaps $
233− CppLambda
234− [CppCaptureAll]
235− (farg <$> [f'])
236− (Just $ CppAny [])
237− (CppBlock $ fieldLambdas fs') ]
238− | otherwise = [CppReturn $ CppApp (CppVar name) (CppVar <$> fields')]
239−
240− declToCpp qs (_, ident) e
241− | Just ty <- exprType e,
242− CppTopLevel `elem` qs,
243− argcnt <- countArgs ty,
244− argcnt > 0 = do
245− argNames <- replicateM argcnt freshName
246− block <- valueToCpp $
247− curriedApp
248− (tail argNames)
249− (App nullAnn e (Var nullAnn . Qualified Nothing . Ident $ head argNames))
250− let fn' = CppFunction
251− (curriedName name)
252− [(head argNames, Just $ CppAny [CppConst, CppRef])]
253− rty
254− []
255− (asReturnBlock $
256− curriedLambda
257− (tail argNames)
258− (CppApp (CppVar name)
259− (CppVar <$> argNames)))
260− return $ CppNamespace "" $
261− [ CppFunction
262− name
263− (zip argNames $ repeat aty)
264− rty
265− []
266− (asReturnBlock block)
267− ] ++ if argcnt > 1
268− then [fn']
269− else []
270− where
271− name = identToCpp ident
272− aty = Just $ CppAny [CppConst, CppRef]
273− rty = Just $ CppAny []
274−
275− declToCpp _ (_, ident) val = do
276− val' <- valueToCpp val
277− return $
278− CppVariableIntroduction
279− (identToCpp ident, Just $ CppAny [CppConst])
280− []
281− (Just val')
282−
283− -------------------------------------------------------------------------------------------------
284− exprType :: Expr Ann -> Maybe T.Type
285− -------------------------------------------------------------------------------------------------
286− exprType (Var (_, _, Just ty, _) _) = Just ty
287− exprType (App (_, _, Just ty, _) _ _) = Just ty
288− exprType (Case (_, _, Just ty, _) _ _) = Just ty
289− exprType (Let (_, _, Just ty, _) _ _) = Just ty
290− exprType _ = Nothing
291−
292− -------------------------------------------------------------------------------------------------
293− fnToLambda :: Cpp -> Cpp
294− -------------------------------------------------------------------------------------------------
295− fnToLambda (CppFunction name args _ qs body) =
296− CppVariableIntroduction
297− (name, Just $ CppAny [CppConst])
298− (filter (==CppStatic) qs)
299− (Just $ CppLambda cs args (Just $ CppAny []) body)
300− where
301− cs | (not . null) (qs `intersect` [CppInline, CppStatic]) = []
302− | otherwise = [CppCaptureAll]
303− fnToLambda (CppComment com cpp) = CppComment com (fnToLambda cpp)
304− fnToLambda _ = error "Not a function!"
305−
306− -------------------------------------------------------------------------------------------------
307− convertNestedLambdas :: Cpp -> Cpp
308− -------------------------------------------------------------------------------------------------
309− convertNestedLambdas = everywhereOnCpp go
310− where
311− go :: Cpp -> Cpp
312− go f@(CppFunction {}) = maybeRemCaps $ fnToLambda f
313− go (CppLambda _ args rtyp body) = maybeRemCaps $ CppLambda [CppCaptureAll] args rtyp body
314− go cpp = cpp
315−
316− -------------------------------------------------------------------------------------------------
317− convertRecursiveFns :: [Cpp] -> [Cpp]
318− -------------------------------------------------------------------------------------------------
319− convertRecursiveFns cpps
320− | not $ null fns = dict : (accessor topdict <$> fns) ++ (everywhereOnCpp removeRec <$> cpps)
321− where
322− fns :: [(String, Cpp)]
323− fns = toelem <$> concatMap (everythingOnCpp (++) recursive) cpps
324−
325− recursive :: Cpp -> [Cpp]
326− recursive cpp'@(CppFunction _ _ _ qs _) | CppRecursive `elem` qs = [cpp']
327− recursive _ = []
328−
329− removeRec :: Cpp -> Cpp
330− removeRec(CppFunction _ _ _ qs _) | CppRecursive `elem` qs = CppNoOp
331− removeRec cpp' = cpp'
332−
333− dict :: Cpp
334− dict = CppVariableIntroduction
335− (topdict, Just $ CppAny [CppConst])
336− []
337− (Just $ CppObjectLiteral fns)
338−
339− accessor :: String -> (String, Cpp) -> Cpp
340− accessor dictname (name, _) =
341− CppVariableIntroduction
342− (name, Just $ CppAny [CppConst])
343− []
344− (Just accessed)
345− where
346− dict' = CppVar dictname
347− accessed = CppApp (CppIndexer (CppStringLiteral name) dict') [dict']
348−
349− toelem :: Cpp -> (String, Cpp)
350− toelem (CppFunction name args rtyp _ (CppBlock body)) =
351− (name, withdict . maybeRemCaps $ CppLambda
352− [CppCaptureAll]
353− args
354− rtyp
355− (CppBlock $ (accessor localdict <$> fns) ++ body))
356− toelem _ = error "not a function"
357−
358− withdict :: Cpp -> Cpp
359− withdict cpp' = maybeRemCaps $ CppLambda
360− [CppCaptureAll]
361− [(localdict, Just $ CppAny [CppConst, CppRef])]
362− (Just $ CppAny [])
363− (asReturnBlock cpp')
364− topdict :: String
365− topdict = "__dict__"
366− localdict :: String
367− localdict = "_dict_"
368−
369− convertRecursiveFns cpps = cpps
370−
371− -- |
372− -- Generate code in the simplified C++1x intermediate representation for a value or expression.
373− --
374− -------------------------------------------------------------------------------------------------
375− valueToCpp :: Expr Ann -> m Cpp
376− -------------------------------------------------------------------------------------------------
377− valueToCpp (Var (_, _, _, Just (IsConstructor _ [])) ident) =
378− return $ CppApp (varToCpp ident) []
379−
380− valueToCpp (Var (_, _, _, Just (IsConstructor _ [_])) ident) =
381− return $ varToCpp ident
382−
383− valueToCpp (Var (_, _, _, Just (IsConstructor _ _)) ident) =
384− return . curriedName' $ varToCpp ident
385−
386− valueToCpp (Var (_, _, Just ty, _) ident@(Qualified (Just _) _))
387− | countArgs ty > 1 =
388− return . curriedName' $ varToCpp ident
389−
390− valueToCpp (Var _ ident) =
391− return $ varToCpp ident
392−
393− valueToCpp (Literal _ (NumericLiteral n)) =
394− return (CppNumericLiteral n)
395−
396− valueToCpp (Literal _ (StringLiteral s)) =
397− return (CppStringLiteral s)
398−
399− valueToCpp (Literal _ (CharLiteral c)) =
400− return (CppCharLiteral c)
401−
402− valueToCpp (Literal _ (BooleanLiteral b)) =
403− return (CppBooleanLiteral b)
404−
405− valueToCpp (Literal _ (ArrayLiteral xs)) =
406− CppArrayLiteral <$> mapM valueToCpp xs
407−
408− valueToCpp (Literal _ (ObjectLiteral ps)) =
409− CppObjectLiteral <$> sortBy (compare `on` fst) <$> mapM (sndM valueToCpp) ps
410−
411− valueToCpp (Accessor _ prop val) =
412− CppIndexer <$> pure (CppStringLiteral prop) <*> valueToCpp val
413−
414− -- TODO: use a more efficient way of copying/updating the map?
415− valueToCpp (ObjectUpdate (_, _, Just ty, _) obj ps) = do
416− obj' <- valueToCpp obj
417− updatedFields <- mapM (sndM valueToCpp) ps
418− let origKeys = (allKeys ty) \\ (fst <$> updatedFields)
419− origFields = (\key -> (key, CppIndexer (CppStringLiteral key) obj')) <$> origKeys
420− return $ CppObjectLiteral . sortBy (compare `on` fst) $ origFields ++ updatedFields
421− where
422− allKeys :: T.Type -> [String]
423− allKeys (T.TypeApp (T.TypeConstructor _) r@(T.RCons {})) = fst <$> (fst $ T.rowToList r)
424− allKeys (T.ForAll _ t _) = allKeys t
425− allKeys _ = error $ show "Not a recognized row type"
426−
427− valueToCpp (ObjectUpdate _ _ _) = error $ "Bad Type in object update!"
428−
429− valueToCpp (Abs _ arg body) = do
430− cpp <- valueToCpp body
431− let cpp' = convertNestedLambdas cpp
432− return $
433− CppLambda
434− []
435− [(identToCpp arg, Just $ CppAny [CppConst, CppRef])]
436− (Just $ CppAny [])
437− (asReturnBlock cpp')
438− valueToCpp e@App{} = do
439− let (f, args) = unApp e []
440− args' <- mapM valueToCpp args
441− case f of
442− Var (_, _, _, Just IsNewtype) _ -> return (head args')
443− Var (_, _, _, Just (IsConstructor _ fields)) ident
444− | length args == length fields ->
445− return $ CppApp (uncurried' $ qualifiedToCpp id ident) args'
446− Var (_, _, _, Just IsTypeClassConstructor) (Qualified mn' (Ident classname)) ->
447− let Just (_, constraints, fns) = findClass (Qualified mn' (ProperName classname)) in
448− return . CppObjectLiteral $
449− zip
450− ((sort $ superClassDictionaryNames constraints) ++ (fst <$> fns))
451− args'
452− Var ann (Qualified (Just mn') ident)
453− | argcnt <- maybe 0 countArgs ty,
454− argcnt > 1 -> do
455− f' <- valueToCpp f
456− let (uncurriedArgs, curriedArgs) =
457− if length args' >= argcnt
458− then splitAt argcnt args'
459− else ([], args')
460− fn' =
461− if null uncurriedArgs
462− then curriedName' f'
463− else CppApp (uncurried' f') uncurriedArgs
464− return $ foldl (\fn a -> CppApp fn [a]) fn' curriedArgs
465− where
466− ty | (_, _, Just t, _) <- ann = Just t
467− | Just (t, _, _) <- M.lookup (mn', ident) (E.names env) = Just t
468− | otherwise = Nothing
469− _ ->
470− flip (foldl (\fn a -> CppApp fn [a])) args' <$> valueToCpp f
471−
472− valueToCpp (Case (maybeSpan, _, ty, _) values binders) = do
473− vals <- mapM valueToCpp values
474− bindersToCpp maybeSpan ty binders vals
475−
476− valueToCpp (Let _ ds val) = do
477− ds' <- concat <$> mapM (bindToCpp []) ds
478− ret <- valueToCpp val
479− let ds'' = tco defaultOptions <$> ds'
480− let rs = if hasRecursion ds''
481− then convertRecursiveFns ds''
482− else ds''
483− let cpps = convertNestedLambdas <$> rs
484− return $ CppApp
485− (CppLambda [] [] Nothing (CppBlock (cpps ++ [CppReturn ret])))
486− []
487− where
488− hasRecursion :: [Cpp] -> Bool
489− hasRecursion cpps' = any (everythingOnCpp (||) hasRecursiveRef) cpps'
490− where
491− fnames :: [String]
492− fnames = concatMap (everythingOnCpp (++) fname) cpps'
493−
494− fname :: Cpp -> [String]
495− fname (CppFunction name _ _ _ _) = [name]
496− fname _ = []
497−
498− hasRecursiveRef :: Cpp -> Bool
499− hasRecursiveRef (CppFunction _ _ _ _ body) = everythingOnCpp (||) ref body
500− hasRecursiveRef _ = False
501−
502− ref :: Cpp -> Bool
503− ref (CppVar name) | name `elem` fnames = True
504− ref _ = False
505−
506− valueToCpp Constructor{} = return CppNoOp
507−
508− -- |
509− -- Generate code in the simplified C++1x intermediate representation for a reference to a
510− -- variable.
511− --
512− -------------------------------------------------------------------------------------------------
513− varToCpp :: Qualified Ident -> Cpp
514− -------------------------------------------------------------------------------------------------
515− varToCpp (Qualified Nothing ident) = CppVar (identToCpp ident)
516− varToCpp qual = qualifiedToCpp id qual
517−
518− -- |
519− -- Generate code in the simplified C++1x intermediate representation for pattern match binders
520− -- and guards.
521− --
522− -------------------------------------------------------------------------------------------------
523− bindersToCpp :: Maybe SourceSpan -> Maybe T.Type -> [CaseAlternative Ann] -> [Cpp] -> m Cpp
524− -------------------------------------------------------------------------------------------------
525− bindersToCpp maybeSpan _ binders vals = do
526− valNames <- replicateM (length vals) freshName
527− let assignments = zipWith mkVarDecl valNames (map Just vals)
528− cpps <- forM binders $ \(CaseAlternative bs result) -> do
529− ret <- guardsToCpp result
530− go valNames ret bs
531− return $
532− CppApp
533− (CppLambda
534− []
535− []
536− (Just $ CppAny [])
537− (CppBlock (assignments ++ concat cpps ++ [failedPatternError valNames])))
538− []
539− where
540− mkVarDecl :: String -> Maybe Cpp -> Cpp
541− mkVarDecl name = CppVariableIntroduction (name, Nothing) []
542− go :: [String] -> [Cpp] -> [Binder Ann] -> m [Cpp]
543− go _ done [] = return done
544− go (v:vs) done' (b:bs) = do
545− done'' <- go vs done' bs
546− binderToCpp v done'' b
547− go _ _ _ = error "Invalid arguments to bindersToCpp"
548−
549− failedPatternError :: [String] -> Cpp
550− failedPatternError _ =
551− CppThrow $ CppApp (CppVar "runtime_error") [CppStringLiteral errorMessage]
552−
553− errorMessage :: String
554− errorMessage = "Failed pattern match" ++
555− maybe "" (((" at " ++ runModuleName mn ++ " ") ++) . displayStartEndPos) maybeSpan ++
556− ": "
557−
558− guardsToCpp :: Either [(Guard Ann, Expr Ann)] (Expr Ann) -> m [Cpp]
559− guardsToCpp (Left gs) = forM gs $ \(cond, val) -> do
560− cond' <- valueToCpp cond
561− done <- valueToCpp val
562− return $ CppIfElse cond' (asReturnBlock done) Nothing
563− guardsToCpp (Right v) = return . CppReturn <$> valueToCpp v
564−
565− -- |
566− -- Generate code in the simplified C++1x intermediate representation for a pattern match
567− -- binder.
568− --
569− -------------------------------------------------------------------------------------------------
570− binderToCpp :: String -> [Cpp] -> Binder Ann -> m [Cpp]
571− -------------------------------------------------------------------------------------------------
572− binderToCpp _ done (NullBinder{}) = return done
573−
574− binderToCpp varName done (LiteralBinder _ l) =
575− literalToBinderCpp varName done l
576−
577− binderToCpp varName done (VarBinder _ ident) =
578− return $
579− CppVariableIntroduction
580− (identToCpp ident, Just $ CppAny [CppConst])
581− []
582− (Just $ CppVar varName)
583− : done
584−
585− binderToCpp varName done (ConstructorBinder (_, _, _, Just IsNewtype) _ _ [b]) =
586− binderToCpp varName done b
587−
588− binderToCpp varName done (ConstructorBinder (_, _, _, Just (IsConstructor ctorType fields))
589− _
590− (Qualified mn' (ProperName ctor))
591− bs) = do
592− cpps <- go (zip fields bs) done
593− return $
594− case ctorType of
595− ProductType -> cpps
596− SumType ->
597− [ CppIfElse
598− (CppBinary
599− Equal
600− (CppIndexer
601− (CppVar ctorKey)
602− (CppCast dataType $ CppVar varName))
603− ctorCpp)
604− (CppBlock cpps)
605− Nothing]
606− where
607− go :: [(Ident, Binder Ann)] -> [Cpp] -> m [Cpp]
608− go [] done' = return done'
609− go ((field, binder) : remain) done' = do
610− argVar <- freshName
611− done'' <- go remain done'
612− cpps <- binderToCpp argVar done'' binder
613− return $
614− CppVariableIntroduction
615− (argVar, Nothing)
616− []
617− (Just $ CppIndexer
618− (fieldToIndex field)
619− (CppCast dataType $ CppVar varName))
620− : cpps
621− fieldToIndex :: Ident -> Cpp
622− fieldToIndex = CppNumericLiteral . Left . (+1) . read . dropWhile isLetter . runIdent
623− ctor' :: Cpp
624− ctor' = CppAccessor (CppVar . identToCpp $ Ident ctor) (CppVar "data")
625− ctorCpp :: Cpp
626− ctorCpp | Just mn'' <- mn', mn'' /= mn = CppAccessor ctor' (CppVar $ moduleNameToCpp mn'')
627− | otherwise = ctor'
628−
629− binderToCpp _ _ b@(ConstructorBinder{}) =
630− error $ "Invalid ConstructorBinder in binderToCpp: " ++ show b
631−
632− binderToCpp varName done (NamedBinder _ ident binder) = do
633− cpp <- binderToCpp varName done binder
634− return $
635− CppVariableIntroduction
636− (identToCpp ident, Just $ CppAny [CppConst])
637− []
638− (Just $ CppVar varName)
639− : cpp
640−
641− -------------------------------------------------------------------------------------------------
642− literalToBinderCpp :: String -> [Cpp] -> Literal (Binder Ann) -> m [Cpp]
643− -------------------------------------------------------------------------------------------------
644− literalToBinderCpp varName done (NumericLiteral num) =
645− return [ CppIfElse
646− (CppBinary Equal (CppVar varName) (CppNumericLiteral num))
647− (CppBlock done)
648− Nothing ]
649−
650− literalToBinderCpp varName done (CharLiteral c) =
651− return [ CppIfElse
652− (CppBinary Equal (CppVar varName) (CppCharLiteral c))
653− (CppBlock done)
654− Nothing ]
655−
656− literalToBinderCpp varName done (StringLiteral str) =
657− return [ CppIfElse
658− (CppBinary Equal (CppVar varName) (CppStringLiteral str))
659− (CppBlock done)
660− Nothing ]
661−
662− literalToBinderCpp varName done (BooleanLiteral True) =
663− return [ CppIfElse
664− (CppVar varName)
665− (CppBlock done)
666− Nothing ]
667−
668− literalToBinderCpp varName done (BooleanLiteral False) =
669− return [ CppIfElse
670− (CppUnary
671− CppNot
672− (CppVar varName))
673− (CppBlock done)
674− Nothing ]
675−
676− literalToBinderCpp varName done (ObjectLiteral bs) = go done bs
677− where
678− go :: [Cpp] -> [(String, Binder Ann)] -> m [Cpp]
679− go done' [] = return done'
680− go done' ((prop, binder):bs') = do
681− propVar <- freshName
682− done'' <- go done' bs'
683− cpp <- binderToCpp propVar done'' binder
684− return $
685− CppVariableIntroduction
686− (propVar, Nothing)
687− []
688− (Just $ CppIndexer
689− (CppStringLiteral prop)
690− (CppVar varName))
691− : cpp
692−
693− literalToBinderCpp varName done (ArrayLiteral bs) = do
694− cpp <- go done 0 bs
695− let cond =
696− case length bs of
697− 0 -> CppBinary
698− Dot
699− (CppCast arrayType $ CppVar varName)
700− (CppApp (CppVar "empty") [])
701− n -> let var = CppCast arrayType $ CppVar varName
702− in CppBinary
703− Equal
704− (CppBinary Dot var (CppApp (CppVar "size") []))
705− (CppNumericLiteral (Left (fromIntegral n)))
706− return [ CppIfElse cond (CppBlock cpp) Nothing ]
707− where
708− go :: [Cpp] -> Integer -> [Binder Ann] -> m [Cpp]
709− go done' _ [] = return done'
710− go done' index (binder:bs') = do
711− elVar <- freshName
712− done'' <- go done' (index + 1) bs'
713− cpp <- binderToCpp elVar done'' binder
714− return $
715− CppVariableIntroduction
716− (elVar, Nothing)
717− []
718− (Just $ CppIndexer
719− (CppNumericLiteral (Left index))
720− (CppVar varName))
721− : cpp
722−
723− -------------------------------------------------------------------------------------------------
724− unApp :: Expr Ann -> [Expr Ann] -> (Expr Ann, [Expr Ann])
725− -------------------------------------------------------------------------------------------------
726− unApp (App _ val arg) args = unApp val (arg : args)
727− unApp other args = (other, args)
728−
729− -------------------------------------------------------------------------------------------------
730− unAbs :: Expr Ann -> [Ident] -> ([Ident], Expr Ann)
731− -------------------------------------------------------------------------------------------------
732− unAbs (Abs _ arg val) args = unAbs val (args ++ [arg])
733− unAbs other args = (args, other)
734−
735− -------------------------------------------------------------------------------------------------
736− qualifiedToCpp :: (a -> Ident) -> Qualified a -> Cpp
737− -------------------------------------------------------------------------------------------------
738− qualifiedToCpp f (Qualified (Just (ModuleName [ProperName mn'])) a)
739− | mn' == C.prim = CppVar . runIdent $ f a
740− qualifiedToCpp f (Qualified (Just mn') a)
741− | mn /= mn' = CppAccessor (CppVar . identToCpp $ f a) (CppVar (moduleNameToCpp mn'))
742− qualifiedToCpp f (Qualified _ a) = CppVar $ identToCpp (f a)
743−
744− -- |
745− -- Find a class in scope by name, retrieving its list of constraints, function names and types.
746− --
747− -------------------------------------------------------------------------------------------------
748− findClass :: Qualified (ProperName 'ClassName) -> Maybe ([String], [T.Constraint], [(String, T.Type)])
749− -------------------------------------------------------------------------------------------------
750− findClass name
751− | Just (params, fns, constraints) <- M.lookup name (E.typeClasses env),
752− fns' <- (\(i,t) -> (runIdent i, t)) <$> fns
753− = Just (fst <$> params, constraints, (sortBy (compare `on` normalizedName . fst) fns'))
754− findClass _ = Nothing
755−
756− -------------------------------------------------------------------------------------------------
757− dataCtors :: [Cpp]
758− -------------------------------------------------------------------------------------------------
759− dataCtors = [CppNamespace "data"
760− [CppEnum Nothing (Just intType) . ("_" :) .
761− catMaybes . map modCtor . M.keys $ E.dataConstructors env]]
762− where
763− modCtor :: Qualified (ProperName a) -> Maybe String
764− modCtor (Qualified (Just mn') (ProperName name)) | mn' == mn = Just name
765− modCtor _ = Nothing
766−
767− -------------------------------------------------------------------------------------------------
768− curriedForeigns :: m [Cpp]
769− -------------------------------------------------------------------------------------------------
770− curriedForeigns = concat <$> mapM go allForeigns
771− where
772− go (ident, ty)
773− | argcnt <- countArgs ty,
774− argcnt > 1 = do
775− let name = identToCpp ident
776− argNames <- replicateM argcnt freshName
777− return $
778− [ CppFunction
779− (curriedName name)
780− [(head argNames, Just $ CppAny [CppConst, CppRef])]
781− (Just $ CppAny [])
782− []
783− (asReturnBlock $
784− curriedLambda
785− (tail argNames)
786− (CppApp (CppVar name)
787− (CppVar <$> argNames)))
788− ]
789− go _ = return []
790−
791− allForeigns :: [(Ident, T.Type)]
792− allForeigns = map (\((_, ident), (ty, _, _)) -> (ident, ty)) .
793− filter (\((mn', _), (_, kind, _)) -> mn' == mn && kind == E.External) .
794− M.toList $ E.names env
795−
796−---------------------------------------------------------------------------------------------------
797−asReturnBlock :: Cpp -> Cpp
798−---------------------------------------------------------------------------------------------------
799−asReturnBlock cpp = CppBlock [CppReturn cpp]
800−
801−---------------------------------------------------------------------------------------------------
802−curriedLambda :: [String] -> Cpp -> Cpp
803−---------------------------------------------------------------------------------------------------
804−curriedLambda args ret = foldr (\arg ret' -> CppLambda
805− [CppCaptureAll]
806− [(arg, Just $ CppAny [CppConst, CppRef])]
807− (Just $ CppAny [])
808− (asReturnBlock ret')
809− ) ret args
810−
811−---------------------------------------------------------------------------------------------------
812−curriedApp :: [String] -> Expr Ann -> Expr Ann
813−---------------------------------------------------------------------------------------------------
814−curriedApp args vals = foldl (\val arg -> App
815− nullAnn
816− val
817− (Var nullAnn . Qualified Nothing $ Ident arg))
818− vals args
819−
820−---------------------------------------------------------------------------------------------------
821−countArgs :: T.Type -> Int
822−---------------------------------------------------------------------------------------------------
823−countArgs = go 0
824− where
825− go argcnt (T.ForAll _ t _) = go argcnt t
826− go argcnt (T.TypeApp (T.TypeApp fn _) t) | fn == E.tyFunction = go (argcnt + 1) t
827− go argcnt (T.ConstrainedType ts t) = go (argcnt + length ts) t
828− go argcnt _ = argcnt
829−
830−---------------------------------------------------------------------------------------------------
831−extractConstraints :: T.Type -> [T.Constraint]
832−---------------------------------------------------------------------------------------------------
833−extractConstraints = go []
834− where
835− go cs (T.ForAll _ t _) = go cs t
836− go cs (T.TypeApp (T.TypeApp fn _) t) | fn == E.tyFunction = go cs t
837− go cs (T.ConstrainedType ts t) = go (cs ++ ts) t
838− go cs _ = cs
839−
840−---------------------------------------------------------------------------------------------------
841−dictIndexerToEnum :: [(Cpp,Cpp)] -> Cpp -> Cpp
842−---------------------------------------------------------------------------------------------------
843−dictIndexerToEnum repls (CppIndexer (CppStringLiteral prop) dict)
844− | Just cls <- lookup dict repls =
845− CppBinary Dot
846− (CppIndexer
847− (CppAccessor (CppVar . identToCpp $ Ident prop) cls)
848− (CppCast mapType dict))
849− (CppVar "second")
850−dictIndexerToEnum _ cpp = cpp
851−
852−---------------------------------------------------------------------------------------------------
853−curriedName :: String -> String
854−---------------------------------------------------------------------------------------------------
855−curriedName name@('$' : _) = name
856−curriedName name = '$' : name
857−
858−---------------------------------------------------------------------------------------------------
859−uncurried' :: Cpp -> Cpp
860−---------------------------------------------------------------------------------------------------
861−uncurried' (CppVar ('$':name)) = CppVar name
862−uncurried' (CppAccessor a b) = CppAccessor (uncurried' a) b
863−uncurried' cpp = cpp
864−
865−---------------------------------------------------------------------------------------------------
866−curriedName' :: Cpp -> Cpp
867−---------------------------------------------------------------------------------------------------
868−curriedName' (CppVar name) = CppVar (curriedName name)
869−curriedName' (CppAccessor a b) = CppAccessor (curriedName' a) b
870−curriedName' cpp = cpp
src/Language/PureScript/CodeGen/Cpp/AST.hsdeleted−375
@@ -1,375 +0,0 @@
1−-----------------------------------------------------------------------------
2−--
3−-- Module : Language.PureScript.CodeGen.Cpp.AST
4−-- Copyright : (c) 2013-15 Phil Freeman, Andy Arvanitis, and other contributors
5−-- License : MIT
6−--
7−-- Maintainer : Andy Arvanitis
8−-- Stability : experimental
9−-- Portability :
10−--
11−-- |
12−-- Data types for the intermediate simplified-C++11 AST
13−--
14−-----------------------------------------------------------------------------
15−
16−{-# LANGUAGE DeriveDataTypeable #-}
17−{-# LANGUAGE CPP #-}
18−
19−module Language.PureScript.CodeGen.Cpp.AST where
20−
21−#if __GLASGOW_HASKELL__ < 710
22−import Control.Applicative (Applicative, (<$>), (<*>))
23−import Data.Traversable (traverse)
24−#endif
25−import Control.Monad.Identity
26−import Data.Data
27−import Language.PureScript.Comments
28−import Language.PureScript.CodeGen.Cpp.Types
29−import Language.PureScript.Traversals
30−
31−-- |
32−-- Built-in unary operators
33−--
34−data CppUnaryOp
35− -- |
36− -- Numeric negation
37− --
38− = CppNegate
39− -- |
40− -- Boolean negation
41− --
42− | CppNot
43− -- |
44− -- Bitwise negation
45− --
46− | CppBitwiseNot
47− -- |
48− -- Numeric unary \'plus\'
49− --
50− | CppPositive
51− -- |
52− -- Constructor
53− --
54− | CppNew
55− deriving (Show, Read, Eq)
56−
57−-- |
58−-- Built-in binary operators
59−--
60−data BinaryOp
61− -- |
62− -- Numeric addition
63− --
64− = Add
65− -- |
66− -- Numeric subtraction
67− --
68− | Subtract
69− -- |
70− -- Numeric multiplication
71− --
72− | Multiply
73− -- |
74− -- Numeric division
75− --
76− | Divide
77− -- |
78− -- Remainder
79− --
80− | Modulus
81− -- |
82− -- TODO: revisit this
83− --
84− | Dot
85− -- |
86− -- Generic equality test
87− --
88− | Equal
89− -- |
90− -- Generic inequality test
91− --
92− | NotEqual
93− -- |
94− -- Numeric less-than
95− --
96− | LessThan
97− -- |
98− -- Numeric less-than-or-equal
99− --
100− | LessThanOrEqual
101− -- |
102− -- Numeric greater-than
103− --
104− | GreaterThan
105− -- |
106− -- Numeric greater-than-or-equal
107− --
108− | GreaterThanOrEqual
109− -- |
110− -- Boolean and
111− --
112− | And
113− -- |
114− -- Boolean or
115− --
116− | Or
117− -- |
118− -- Bitwise and
119− --
120− | BitwiseAnd
121− -- |
122− -- Bitwise or
123− --
124− | BitwiseOr
125− -- |
126− -- Bitwise xor
127− --
128− | BitwiseXor
129− -- |
130− -- Bitwise left shift
131− --
132− | ShiftLeft
133− -- |
134− -- Bitwise right shift
135− --
136− | ShiftRight
137− --
138− deriving (Show, Read, Eq)
139−
140−-- |
141−-- Data type for simplified C++11 expressions
142−--
143−data Cpp
144− -- |
145− -- A numeric literal
146− --
147− = CppNumericLiteral (Either Integer Double)
148− -- |
149− -- A string literal
150− --
151− | CppStringLiteral String
152− -- |
153− -- A character literal
154− --
155− | CppCharLiteral Char
156− -- |
157− -- A boolean literal
158− --
159− | CppBooleanLiteral Bool
160− -- |
161− -- A unary operator application
162− --
163− | CppUnary CppUnaryOp Cpp
164− -- |
165− -- A binary operator application
166− --
167− | CppBinary BinaryOp Cpp Cpp
168− -- |
169− -- An array literal
170− --
171− | CppArrayLiteral [Cpp]
172− -- |
173− -- A data literal
174− --
175− | CppDataLiteral [Cpp]
176− -- |
177− -- An enum definition (optional name, optional type)
178− --
179− | CppEnum (Maybe String) (Maybe CppType) [String]
180− -- |
181− -- An array indexer expression
182− --
183− | CppIndexer Cpp Cpp
184− -- |
185− -- An object literal
186− --
187− | CppObjectLiteral [(String, Cpp)]
188− -- |
189− -- An general property accessor expression (property, expr)
190− --
191− | CppAccessor Cpp Cpp
192− -- |
193− -- A function introduction (name, arguments, return type, qualifiers, body)
194− --
195− | CppFunction String [(String, Maybe CppType)] (Maybe CppType) [CppValueQual] Cpp
196− -- |
197− -- A lambda introduction (arguments, return type, body)
198− --
199− | CppLambda [CppCaptureType] [(String, Maybe CppType)] (Maybe CppType) Cpp
200− -- |
201− -- Value type cast
202− --
203− | CppCast CppType Cpp
204− -- |
205− -- Function application
206− --
207− | CppApp Cpp [Cpp]
208− -- |
209− -- Variable
210− --
211− | CppVar String
212− -- |
213− -- A block of expressions in braces
214− --
215− | CppBlock [Cpp]
216− -- |
217− -- A C++ namespace
218− --
219− | CppNamespace String [Cpp]
220− -- |
221− -- An C++ struct declaration (name, members)
222− --
223− | CppStruct String [Cpp]
224− -- |
225− -- A C++ #include
226− --
227− | CppInclude String String
228− -- |
229− -- A C++ using namespace declaration
230− --
231− | CppUseNamespace String
232− -- |
233− -- Type alias, e.g. "using T = U" (new name and template types, original type)
234− --
235− | CppTypeAlias (String,[(String, Int)]) CppType String
236− -- |
237− -- A variable introduction and optional initialization
238− --
239− | CppVariableIntroduction (String, Maybe CppType) [CppValueQual] (Maybe Cpp)
240− -- |
241− -- A variable assignment
242− --
243− | CppAssignment Cpp Cpp
244− -- |
245− -- While loop
246− --
247− | CppWhile Cpp Cpp
248− -- |
249− -- If-then-else statement
250− --
251− | CppIfElse Cpp Cpp (Maybe Cpp)
252− -- |
253− -- Switch statement
254− --
255− | CppSwitch Cpp [(Cpp, Cpp)]
256− -- |
257− -- Return statement
258− --
259− | CppReturn Cpp
260− -- |
261− -- Throw statement
262− --
263− | CppThrow Cpp
264− -- |
265− -- Continue statement
266− --
267− | CppContinue
268− -- |
269− -- Empty statement/expression
270− --
271− | CppNoOp
272− -- |
273− -- Marker for header/source split
274− --
275− | CppEndOfHeader
276− -- |
277− -- Raw C++11 (generated when parsing fails for an inline foreign import declaration)
278− --
279− | CppRaw String
280− -- |
281− -- Commented C++11
282− --
283− | CppComment [Comment] Cpp
284− deriving (Show, Read, Eq)
285−
286−--
287−-- Traversals
288−--
289−
290−everywhereOnCpp :: (Cpp -> Cpp) -> Cpp -> Cpp
291−everywhereOnCpp f = go
292− where
293− go :: Cpp -> Cpp
294− go (CppUnary op j) = f (CppUnary op (go j))
295− go (CppBinary op j1 j2) = f (CppBinary op (go j1) (go j2))
296− go (CppArrayLiteral cpp) = f (CppArrayLiteral (map go cpp))
297− go (CppDataLiteral cpp) = f (CppDataLiteral (map go cpp))
298− go (CppIndexer j1 j2) = f (CppIndexer (go j1) (go j2))
299− go (CppObjectLiteral cpp) = f (CppObjectLiteral (map (fmap go) cpp))
300− go (CppAccessor prop j) = f (CppAccessor (go prop) (go j))
301− go (CppFunction name args rty qs j) = f (CppFunction name args rty qs (go j))
302− go (CppLambda cps args rty j) = f (CppLambda cps args rty (go j))
303− go (CppCast t cpp) = f (CppCast t (go cpp))
304− go (CppApp j cpp) = f (CppApp (go j) (map go cpp))
305− go (CppBlock cpp) = f (CppBlock (map go cpp))
306− go (CppNamespace name cpp) = f (CppNamespace name (map go cpp))
307− go (CppStruct name cpp) = f (CppStruct name (map go cpp))
308− go (CppVariableIntroduction name qs j) = f (CppVariableIntroduction name qs (fmap go j))
309− go (CppAssignment j1 j2) = f (CppAssignment (go j1) (go j2))
310− go (CppWhile j1 j2) = f (CppWhile (go j1) (go j2))
311− go (CppIfElse j1 j2 j3) = f (CppIfElse (go j1) (go j2) (fmap go j3))
312− go (CppSwitch cpp cpps) = f (CppSwitch (go cpp) (map (fmap go) cpps))
313− go (CppReturn cpp) = f (CppReturn (go cpp))
314− go (CppThrow cpp) = f (CppThrow (go cpp))
315− go (CppComment com j) = f (CppComment com (go j))
316− go other = f other
317−
318−everywhereOnCppTopDown :: (Cpp -> Cpp) -> Cpp -> Cpp
319−everywhereOnCppTopDown f = runIdentity . everywhereOnCppTopDownM (Identity . f)
320−
321−everywhereOnCppTopDownM :: (Applicative m, Monad m) => (Cpp -> m Cpp) -> Cpp -> m Cpp
322−everywhereOnCppTopDownM f = f >=> go
323− where
324− f' = f >=> go
325− go (CppUnary op j) = CppUnary op <$> f' j
326− go (CppBinary op j1 j2) = CppBinary op <$> f' j1 <*> f' j2
327− go (CppArrayLiteral cpp) = CppArrayLiteral <$> traverse f' cpp
328− go (CppDataLiteral cpp) = CppDataLiteral <$> traverse f' cpp
329− go (CppIndexer j1 j2) = CppIndexer <$> f' j1 <*> f' j2
330− go (CppObjectLiteral cpp) = CppObjectLiteral <$> traverse (sndM f') cpp
331− go (CppAccessor prop j) = CppAccessor prop <$> f' j
332− go (CppFunction name args rty qs j) = CppFunction name args rty qs <$> f' j
333− go (CppLambda cps args rty j) = CppLambda cps args rty <$> f' j
334− go (CppCast t cpp) = CppCast t <$> f' cpp
335− go (CppApp j cpp) = CppApp <$> f' j <*> traverse f' cpp
336− go (CppBlock cpp) = CppBlock <$> traverse f' cpp
337− go (CppNamespace name cpp) = CppNamespace name <$> traverse f' cpp
338− go (CppStruct name cpp) = CppStruct name <$> traverse f' cpp
339− go (CppVariableIntroduction name qs j) = CppVariableIntroduction name qs <$> traverse f' j
340− go (CppAssignment j1 j2) = CppAssignment <$> f' j1 <*> f' j2
341− go (CppWhile j1 j2) = CppWhile <$> f' j1 <*> f' j2
342− go (CppIfElse j1 j2 j3) = CppIfElse <$> f' j1 <*> f' j2 <*> traverse f' j3
343− go (CppSwitch cpp cpps) = CppSwitch <$> f' cpp <*> traverse (sndM f') cpps
344− go (CppReturn j) = CppReturn <$> f' j
345− go (CppThrow j) = CppThrow <$> f' j
346− go (CppComment com j) = CppComment com <$> f' j
347− go other = f other
348−
349−everythingOnCpp :: (r -> r -> r) -> (Cpp -> r) -> Cpp -> r
350−everythingOnCpp (<>) f = go
351− where
352− go j@(CppUnary _ j1) = f j <> go j1
353− go j@(CppBinary _ j1 j2) = f j <> go j1 <> go j2
354− go j@(CppArrayLiteral cpp) = foldl (<>) (f j) (map go cpp)
355− go j@(CppDataLiteral cpp) = foldl (<>) (f j) (map go cpp)
356− go j@(CppIndexer j1 j2) = f j <> go j1 <> go j2
357− go j@(CppObjectLiteral cpp) = foldl (<>) (f j) (map (go . snd) cpp)
358− go j@(CppAccessor j1 j2) = f j <> go j1 <> go j2
359− go j@(CppFunction _ _ _ _ j1) = f j <> go j1
360− go j@(CppLambda _ _ _ j1) = f j <> go j1
361− go j@(CppCast _ cpp) = f j <> go cpp
362− go j@(CppApp j1 cpp) = foldl (<>) (f j <> go j1) (map go cpp)
363− go j@(CppBlock cpp) = foldl (<>) (f j) (map go cpp)
364− go j@(CppNamespace _ cpp) = foldl (<>) (f j) (map go cpp)
365− go j@(CppStruct _ cpp) = foldl (<>) (f j) (map go cpp)
366− go j@(CppVariableIntroduction _ _ (Just j1)) = f j <> go j1
367− go j@(CppAssignment j1 j2) = f j <> go j1 <> go j2
368− go j@(CppWhile j1 j2) = f j <> go j1 <> go j2
369− go j@(CppIfElse j1 j2 Nothing) = f j <> go j1 <> go j2
370− go j@(CppIfElse j1 j2 (Just j3)) = f j <> go j1 <> go j2 <> go j3
371− go j@(CppSwitch cpp cpps) = foldl (<>) (f j <> go cpp) (map (go . snd) cpps)
372− go j@(CppReturn j1) = f j <> go j1
373− go j@(CppThrow j1) = f j <> go j1
374− go j@(CppComment _ j1) = f j <> go j1
375− go other = f other
src/Language/PureScript/CodeGen/Cpp/Common.hsdeleted−203
@@ -1,203 +0,0 @@
1−-----------------------------------------------------------------------------
2−--
3−-- Module : Language.PureScript.CodeGen.Common
4−-- Copyright : (c) 2013-15 Phil Freeman, Andy Arvanitis, and other contributors
5−-- License : MIT
6−--
7−-- Maintainer : Andy Arvanitis
8−-- Stability : experimental
9−-- Portability :
10−--
11−-- |
12−-- Common code generation utility functions
13−--
14−-----------------------------------------------------------------------------
15−
16−{-# LANGUAGE PatternGuards #-}
17−
18−module Language.PureScript.CodeGen.Cpp.Common where
19−
20−import Data.Char
21−import Data.List (intercalate)
22−
23−import Language.PureScript.Names
24−
25−-- |
26−-- Convert an Ident into a valid C++11 identifier:
27−--
28−-- * Alphanumeric characters are kept unmodified.
29−--
30−-- * Reserved C++11 identifiers are wrapped with '_'
31−--
32−-- * Symbols are wrapped with '_' between a symbol name or their ordinal value.
33−--
34−identToCpp :: Ident -> String
35−identToCpp (Ident name) | nameIsCppReserved name = '_' : name ++ "_"
36−identToCpp (Ident name@('$' : s)) | all isDigit s = name
37−identToCpp (Ident name) = concatMap identCharToString name
38−identToCpp (Op op) = concatMap identCharToString op
39−
40−-- |
41−-- Test if a string is a valid Cpp identifier without escaping.
42−--
43−identNeedsEscaping :: String -> Bool
44−identNeedsEscaping s = s /= identToCpp (Ident s)
45−
46−-- |
47−-- Attempts to find a human-readable name for a symbol, if none has been specified returns the
48−-- ordinal value.
49−--
50−identCharToString :: Char -> String
51−identCharToString c | isAlphaNum c = [c]
52−identCharToString '_' = "_"
53−identCharToString '.' = "_dot_"
54−identCharToString '$' = "_dollar_"
55−identCharToString '~' = "_tilde_"
56−identCharToString '=' = "_eq_"
57−identCharToString '<' = "_less_"
58−identCharToString '>' = "_greater_"
59−identCharToString '!' = "_bang_"
60−identCharToString '#' = "_hash_"
61−identCharToString '%' = "_percent_"
62−identCharToString '^' = "_up_"
63−identCharToString '&' = "_amp_"
64−identCharToString '|' = "_bar_"
65−identCharToString '*' = "_times_"
66−identCharToString '/' = "_div_"
67−identCharToString '+' = "_plus_"
68−identCharToString '-' = "_minus_"
69−identCharToString ':' = "_colon_"
70−identCharToString '\\' = "_bslash_"
71−identCharToString '?' = "_qmark_"
72−identCharToString '@' = "_at_"
73−identCharToString '\'' = "_prime_"
74−identCharToString c = '_' : show (ord c) ++ "_"
75−
76−-- |
77−-- Checks whether an identifier name is reserved in C++11.
78−--
79−nameIsCppReserved :: String -> Bool
80−nameIsCppReserved name =
81− name `elem` [ "alignas"
82− , "alignof"
83− , "and"
84− , "and_eq"
85− , "any"
86− , "asm"
87− , "assert"
88− , "auto"
89− , "bitand"
90− , "bitor"
91− , "bool"
92− , "boost"
93− , "break"
94− , "case"
95− , "cast"
96− , "catch"
97− , "char"
98− , "char16_t"
99− , "char32_t"
100− , "class"
101− , "compl"
102− , "concept"
103− , "const"
104− , "constexpr"
105− , "const_cast"
106− , "continue"
107− , "constructor"
108− , "decltype"
109− , "default"
110− , "delete"
111− , "do"
112− , "double"
113− , "dynamic_cast"
114− , "else"
115− , "enum"
116− , "explicit"
117− , "export"
118− , "extern"
119− , "false"
120− , "final"
121− , "float"
122− , "for"
123− , "friend"
124− , "goto"
125− , "if"
126− , "import"
127− , "inline"
128− , "int"
129− , "list"
130− , "long"
131− , "mutable"
132− , "namespace"
133− , "new"
134− , "nil"
135− , "noexcept"
136− , "not"
137− , "not_eq"
138− , "NULL"
139− , "null"
140− , "nullptr"
141− , "nullptr_t"
142− , "operator"
143− , "or"
144− , "or_eq"
145− , "override"
146− , "param"
147− , "private"
148− , "protected"
149− , "public"
150− , "PureScript"
151− , "register"
152− , "reinterpret_cast"
153− , "requires"
154− , "return"
155− , "runtime_error"
156− , "shared_list"
157− , "short"
158− , "signed"
159− , "sizeof"
160− , "static"
161− , "static_assert"
162− , "static_cast"
163− , "std"
164− , "string"
165− , "struct"
166− , "switch"
167− , "template"
168− , "this"
169− , "thread_local"
170− , "throw"
171− , "true"
172− , "try"
173− , "typedef"
174− , "typeid"
175− , "typename"
176− , "typeof"
177− , "union"
178− , "unsigned"
179− , "using"
180− , "virtual"
181− , "void"
182− , "volatile"
183− , "wchar_t"
184− , "while"
185− , "xor"
186− , "xor_eq" ] || properNameIsCppReserved name
187−
188−normalizedName :: String -> String
189−normalizedName ('_' : s) | last s == '_', s' <- init s, nameIsCppReserved s' = s'
190−normalizedName s = s
191−
192−moduleNameToCpp :: ModuleName -> String
193−moduleNameToCpp (ModuleName pns) =
194− let name = intercalate "_" (runProperName `map` pns)
195− in if properNameIsCppReserved name then '_' : name ++ "_" else name
196−
197−-- |
198−-- Checks whether a proper name is reserved in C++11.
199−--
200−properNameIsCppReserved :: String -> Bool
201−properNameIsCppReserved name =
202− name `elem` [ "Private"
203− , "PureScript" ]
src/Language/PureScript/CodeGen/Cpp/File.hsdeleted−179
@@ -1,179 +0,0 @@
1−-----------------------------------------------------------------------------
2−--
3−-- Module : Language.PureScript.CodeGen.File
4−-- Copyright : (c) 2013-15 Phil Freeman, Andy Arvanitis, and other contributors
5−-- License : MIT
6−--
7−-- Maintainer : Andy Arvanitis <andy.arvanitis@gmail.com>
8−-- Stability : experimental
9−-- Portability :
10−--
11−-- |
12−-- File generation utility functions
13−--
14−-----------------------------------------------------------------------------
15−
16−{-# LANGUAGE PatternGuards #-}
17−
18−module Language.PureScript.CodeGen.Cpp.File where
19−
20−import Data.Maybe
21−
22−import Language.PureScript.CodeGen.Cpp.AST
23−import Language.PureScript.CodeGen.Cpp.Types
24−import Language.PureScript.Names
25−
26−import qualified Language.PureScript.Pretty.Cpp as P
27−
28−---------------------------------------------------------------------------------------------------
29−toHeader :: [Cpp] -> [Cpp]
30−---------------------------------------------------------------------------------------------------
31−toHeader = catMaybes . map go
32− where
33− go :: Cpp -> Maybe Cpp
34− go (CppNamespace name cpps)
35− | cpps'@(_:_) <- toHeader cpps = Just (CppNamespace name cpps')
36− | otherwise = Nothing
37− go cpp@(CppUseNamespace{}) = Just cpp
38− go (CppFunction _ _ _ qs _)
39− | CppInline `elem` qs = Nothing
40− go (CppFunction _ [(_, atyp)] _ _ (CppBlock [CppReturn (CppApp _ [_])])) | atyp == Just CppAuto
41− = Nothing
42− go (CppFunction name args rtyp qs _) =
43− let args' = (\(_,t) -> ("", t)) <$> args in
44− Just (CppFunction name args' rtyp qs CppNoOp)
45− go (CppVariableIntroduction _ _ (Just CppNumericLiteral {})) =
46− Nothing
47− go (CppVariableIntroduction _ _ (Just CppStringLiteral {})) =
48− Nothing
49− go (CppVariableIntroduction _ _ (Just CppBooleanLiteral {})) =
50− Nothing
51− -- Generate thunks for top-level values
52− go (CppVariableIntroduction (name, _) _ (Just _)) =
53− Just $ CppVariableIntroduction (name, Just $ CppAny [CppConst]) [CppExtern] Nothing
54− go cpp@(CppStruct {}) =
55− Just cpp
56− go (CppComment comms cpp')
57− | Just cpp <- go cpp' = Just $ case cpp of CppFunction {} -> cpp
58− _ -> CppComment comms cpp
59− go _ = Nothing
60−
61−---------------------------------------------------------------------------------------------------
62−toHeaderFns :: [Cpp] -> [Cpp]
63−---------------------------------------------------------------------------------------------------
64−toHeaderFns = catMaybes . map go
65− where
66− go :: Cpp -> Maybe Cpp
67− go (CppNamespace name cpps)
68− | cpps'@(_:_) <- toHeaderFns cpps = Just (CppNamespace name cpps')
69− | otherwise = Nothing
70− go cpp@(CppFunction _ _ _ qs _)
71− | CppInline `elem` qs = Just cpp
72− go (CppFunction name [(_, atyp)] _ _ (CppBlock [CppReturn (CppApp cpp [_])]))
73− | atyp == Just CppAuto
74− = Just (CppVariableIntroduction (name, Nothing) [] (Just cpp))
75− go cpp@(CppVariableIntroduction _ _ (Just CppNumericLiteral {})) =
76− Just cpp
77− go cpp@(CppVariableIntroduction _ _ (Just CppStringLiteral {})) =
78− Just cpp
79− go cpp@(CppVariableIntroduction _ _ (Just CppBooleanLiteral {})) =
80− Just cpp
81− go (CppComment comms cpp') | Just cpp <- go cpp' = Just (CppComment comms cpp)
82− go _ = Nothing
83−
84−---------------------------------------------------------------------------------------------------
85−toBodyDecl :: [Cpp] -> [Cpp]
86−---------------------------------------------------------------------------------------------------
87−toBodyDecl = catMaybes . map go
88− where
89− go :: Cpp -> Maybe Cpp
90− go (CppComment comms cpp') | Just commented <- go cpp' = Just (CppComment comms commented)
91− go _ = Nothing
92−
93−---------------------------------------------------------------------------------------------------
94−toBody :: [Cpp] -> [Cpp]
95−---------------------------------------------------------------------------------------------------
96−toBody = catMaybes . map go
97− where
98− go :: Cpp -> Maybe Cpp
99− go (CppNamespace name cpps)
100− | cpps'@(_:_) <- toBody cpps = Just (CppNamespace name cpps')
101− | otherwise = Nothing
102− go cpp@(CppUseNamespace{}) = Just cpp
103− go (CppFunction _ _ _ qs _)
104− | CppInline `elem` qs = Nothing
105− go cpp@(CppFunction {}) = Just cpp
106− go (CppVariableIntroduction _ _ (Just CppNumericLiteral {})) =
107− Nothing
108− go (CppVariableIntroduction _ _ (Just CppStringLiteral {})) =
109− Nothing
110− go (CppVariableIntroduction _ _ (Just CppBooleanLiteral {})) =
111− Nothing
112− -- Generate thunks for top-level values
113− go (CppVariableIntroduction (name, _) _ (Just cpp)) =
114− Just $ CppVariableIntroduction (name, Just $ CppAny [CppConst]) [] (Just lambda)
115− where
116− val = CppVariableIntroduction ("_value_", Just $ CppAny [CppConst]) [CppStatic] (Just $ addCaptures cpp)
117− block = CppBlock [val, CppReturn (CppVar "_value_")]
118− lambda = CppLambda [] [("", Just $ thunkMarkerType)] (Just $ CppAny [CppConst, CppRef]) block
119− addCaptures :: Cpp -> Cpp
120− addCaptures (CppObjectLiteral objs) = CppObjectLiteral (objlam <$> objs)
121− where
122− objlam :: (String, Cpp) -> (String, Cpp)
123− objlam (name', (CppLambda _ args rty body)) = (name' , CppLambda [] args rty $ addCaptures body)
124− objlam obj = obj
125− addCaptures (CppApp (CppLambda _ [] rty body) []) = CppApp (CppLambda [] [] rty (addCaptures body)) []
126− addCaptures cpps' = everywhereOnCpp addCapture cpps'
127− where
128− addCapture :: Cpp -> Cpp
129− addCapture (CppLambda _ args rty body) = maybeRemCaps $ CppLambda [CppCaptureAll] args rty body
130− addCapture cpp' = cpp'
131− go (CppComment comms cpp') | Just commented <- go cpp' = Just (CppComment comms commented)
132− go _ = Nothing
133−
134−-------------------------------------------------------------------------------------------------
135−maybeRemCaps :: Cpp -> Cpp
136−-------------------------------------------------------------------------------------------------
137−maybeRemCaps (CppLambda [CppCaptureAll] args rtyp body@(CppBlock [CppReturn CppNumericLiteral{}]))
138− = CppLambda [] args rtyp body
139−maybeRemCaps (CppLambda [CppCaptureAll] args rtyp body@(CppBlock [CppReturn CppStringLiteral{}]))
140− = CppLambda [] args rtyp body
141−maybeRemCaps (CppLambda [CppCaptureAll] args rtyp body@(CppBlock [CppReturn CppCharLiteral{}]))
142− = CppLambda [] args rtyp body
143−maybeRemCaps (CppLambda [CppCaptureAll] args rtyp body@(CppBlock [CppReturn CppBooleanLiteral{}]))
144− = CppLambda [] args rtyp body
145−maybeRemCaps (CppLambda [CppCaptureAll] args rtyp body@(CppBlock [CppReturn CppAccessor{}]))
146− = CppLambda [] args rtyp body
147−maybeRemCaps (CppLambda [CppCaptureAll] args rtyp body@(CppBlock [CppReturn (CppVar "unit")])) -- TODO: not really safe
148− = CppLambda [] args rtyp body
149−maybeRemCaps cpp = cpp
150−
151−---------------------------------------------------------------------------------------------------
152−
153−fileBegin :: ModuleName -> String -> [Cpp]
154−fileBegin mn suffix = [CppRaw ("#ifndef " ++ fileModName mn suffix),
155− CppRaw ("#define " ++ fileModName mn suffix)]
156−
157−fileEnd :: ModuleName -> String -> [Cpp]
158−fileEnd mn suffix = [CppRaw ("#endif // " ++ fileModName mn suffix)]
159−
160−fileModName :: ModuleName -> String -> String
161−fileModName mn suffix = P.dotsTo '_' (runModuleName mn ++ '_' : suffix)
162−
163−isMain :: ModuleName -> Bool
164−isMain (ModuleName [ProperName "Main"]) = True
165−isMain _ = False
166−
167−nativeMain :: Cpp
168−nativeMain = CppFunction "main"
169− [ ([], Just $ CppPrimitive "int")
170− , ([], Just $ CppPrimitive "char *[]")
171− ]
172− (Just $ CppPrimitive "int")
173− []
174− (CppBlock [ CppUseNamespace "Main"
175− , CppApp (CppApp (CppAccessor (CppVar "main") (CppVar "Main"))
176− [CppVar unthunkMarkerValue])
177− []
178− , CppReturn (CppNumericLiteral (Left 0))
179− ])
src/Language/PureScript/CodeGen/Cpp/Optimizer.hsdeleted−93
@@ -1,93 +0,0 @@
1−-----------------------------------------------------------------------------
2−--
3−-- Module : Language.PureScript.CodeGen.Cpp.Optimizer
4−-- Copyright : (c) 2013-15 Phil Freeman, Andy Arvanitis, and other contributors
5−-- License : MIT
6−--
7−-- Maintainer : Andy Arvanitis
8−-- Stability : experimental
9−-- Portability :
10−--
11−-- |
12−-- This module optimizes code in the simplified-C++11 intermediate representation.
13−--
14−-- The following optimizations are supported:
15−--
16−-- * Collapsing nested blocks
17−--
18−-- * Tail call elimination
19−--
20−-- * Inlining of (>>=) and ret for the Eff monad
21−--
22−-- * Removal of unnecessary thunks
23−--
24−-- * Eta conversion
25−--
26−-- * Inlining variables
27−--
28−-- * Inline Prelude.($), Prelude.(#), Prelude.(++), Prelude.(!!)
29−--
30−-- * Inlining primitive C++11 operators
31−--
32−-----------------------------------------------------------------------------
33−
34−{-# LANGUAGE FlexibleContexts #-}
35−{-# LANGUAGE CPP #-}
36−
37−module Language.PureScript.CodeGen.Cpp.Optimizer (
38− optimize
39−) where
40−
41−#if __GLASGOW_HASKELL__ < 710
42−import Control.Applicative (Applicative)
43−#endif
44−import Control.Monad.Reader (MonadReader, ask, asks)
45−import Control.Monad.Supply.Class (MonadSupply)
46−
47−import Language.PureScript.CodeGen.Cpp.AST
48−import Language.PureScript.Options
49−import qualified Language.PureScript.Constants as C
50−
51−import Language.PureScript.CodeGen.Cpp.Optimizer.Blocks
52−import Language.PureScript.CodeGen.Cpp.Optimizer.Common
53−import Language.PureScript.CodeGen.Cpp.Optimizer.Inliner
54−import Language.PureScript.CodeGen.Cpp.Optimizer.MagicDo
55−import Language.PureScript.CodeGen.Cpp.Optimizer.TCO
56−import Language.PureScript.CodeGen.Cpp.Optimizer.Unused
57−
58−-- |
59−-- Apply a series of optimizer passes to simplified C++11 code
60−--
61−optimize :: (Monad m, MonadReader Options m, Applicative m, MonadSupply m) => Cpp -> m Cpp
62−optimize cpp = do
63− noOpt <- asks optionsNoOptimizations
64− if noOpt then return cpp else optimize' cpp
65−
66−optimize' :: (Monad m, MonadReader Options m, Applicative m, MonadSupply m) => Cpp -> m Cpp
67−optimize' cpp = do
68− opts <- ask
69− untilFixedPoint (inlineFnComposition . applyAll
70− [ collapseNestedBlocks
71− , collapseNestedIfs
72− , collapseIfElses
73− , tco opts
74− , magicDo opts
75− , removeCodeAfterReturnStatements
76− , removeCodeAfterContinueStatements
77− , removeUnusedArg
78− , unThunk
79− , etaConvert
80− , evaluateIifes
81− , inlineVariables
82− , inlineValues
83− , inlineOperator (C.prelude, (C.$)) $ \f x -> CppApp f [x]
84− , inlineOperator (C.prelude, (C.#)) $ \x f -> CppApp f [x]
85− , inlineOperator (C.dataArrayUnsafe, C.unsafeIndex) $ flip CppIndexer
86− , inlineCommonOperators ]) cpp
87−
88−untilFixedPoint :: (Monad m, Eq a) => (a -> m a) -> a -> m a
89−untilFixedPoint f = go
90− where
91− go a = do
92− a' <- f a
93− if a' == a then return a' else go a'
src/Language/PureScript/CodeGen/Cpp/Optimizer/Blocks.hsdeleted−83
@@ -1,83 +0,0 @@
1−-----------------------------------------------------------------------------
2−--
3−-- Module : Language.PureScript.CodeGen.Cpp.Optimizer.Blocks
4−-- Copyright : (c) Phil Freeman 2013-14
5−-- License : MIT
6−--
7−-- Maintainer : Andy Arvanitis <andy.arvanitis@gmail.com>
8−-- Stability : experimental
9−-- Portability :
10−--
11−-- |
12−-- Optimizer steps for simplifying C++ blocks
13−--
14−-----------------------------------------------------------------------------
15−
16−module Language.PureScript.CodeGen.Cpp.Optimizer.Blocks
17− ( collapseNestedBlocks
18− , collapseNestedIfs
19− , collapseIfElses
20− ) where
21−
22−import Language.PureScript.CodeGen.Cpp.AST
23−import qualified Language.PureScript.Constants as C
24−
25−-- |
26−-- Collapse blocks which appear nested directly below another block
27−--
28−collapseNestedBlocks :: Cpp -> Cpp
29−collapseNestedBlocks = everywhereOnCpp collapse
30− where
31− collapse :: Cpp -> Cpp
32− collapse (CppBlock sts) = CppBlock (concatMap go sts)
33− collapse cpp = cpp
34− go :: Cpp -> [Cpp]
35− go (CppBlock sts) = sts
36− go s = [s]
37−
38−collapseNestedIfs :: Cpp -> Cpp
39−collapseNestedIfs = everywhereOnCpp collapse
40− where
41− collapse :: Cpp -> Cpp
42− collapse (CppIfElse cond1 (CppBlock [CppIfElse cond2 body Nothing]) Nothing) =
43− CppIfElse (CppBinary And cond1 cond2) body Nothing
44− collapse cpp = cpp
45−
46−collapseIfElses :: Cpp -> Cpp
47−collapseIfElses = everywhereOnCpp collapse
48− where
49− collapse :: Cpp -> Cpp
50− collapse (CppBlock cpps) = CppBlock (go cpps)
51− where
52− go (st'@(CppIfElse (CppBinary Equal a _) _ Nothing) : sts') =
53− if length (fst cpps') > 1
54− then CppSwitch a (mkCases <$> fst cpps') : snd cpps'
55− else st' : sts'
56− where
57− cpps' = span (isIntEq a) (st' : sts')
58− isIntEq :: Cpp -> Cpp -> Bool
59− isIntEq a (CppIfElse (CppBinary Equal a' (CppNumericLiteral (Left _))) (CppBlock [CppReturn _]) Nothing)
60− | a == a' = True
61− isIntEq a (CppIfElse (CppBinary Equal a' (CppCharLiteral _)) (CppBlock [CppReturn _]) Nothing)
62− | a == a' = True
63− isIntEq a (CppIfElse (CppBinary Equal a' (CppBooleanLiteral _)) (CppBlock [CppReturn _]) Nothing)
64− | a == a' = True
65− isIntEq _ _ = False
66− mkCases :: Cpp -> (Cpp, Cpp)
67− mkCases (CppIfElse (CppBinary Equal _ b') (CppBlock [body]) Nothing) = (b', body)
68− mkCases (CppIfElse (CppUnary CppNot _) (CppBlock [body]) Nothing) = (CppBooleanLiteral False, body)
69− mkCases (CppIfElse _ (CppBlock [body]) Nothing) = (CppBooleanLiteral True, body)
70− mkCases _ = error ""
71− go ((CppIfElse cond1 body1 Nothing) : (CppIfElse cond2 body2 Nothing) : _)
72− | returns body1 && returns body2 &&
73− (CppUnary CppNot cond1 == cond2 ||
74− CppUnary CppNot cond2 == cond1) = [CppIfElse cond1 body1 (Just body2)]
75− where
76− returns :: Cpp -> Bool
77− returns (CppBlock rets@(_:_)) | CppReturn{} <- last rets = True
78− returns CppReturn{} = True
79− returns _ = False
80− go (cpp' : cpps') = cpp' : go cpps'
81− go cpp' = cpp'
82− collapse (CppIfElse (CppAccessor (CppVar "otherwise") (CppVar mn')) body _) | mn' == C.prelude = body
83− collapse cpp = cpp
src/Language/PureScript/CodeGen/Cpp/Optimizer/Common.hsdeleted−75
@@ -1,75 +0,0 @@
1−-----------------------------------------------------------------------------
2−--
3−-- Module : Language.PureScript.CodeGen.Cpp.Optimizer.Common
4−-- Copyright : (c) 2013-15 Phil Freeman, Andy Arvanitis, and other contributors
5−-- License : MIT
6−--
7−-- Maintainer : Andy Arvanitis
8−-- Stability : experimental
9−-- Portability :
10−--
11−-- |
12−-- Common functions used by the various optimizer phases
13−--
14−-----------------------------------------------------------------------------
15−
16−module Language.PureScript.CodeGen.Cpp.Optimizer.Common where
17−
18−import Data.Maybe (fromMaybe)
19−
20−import Language.PureScript.CodeGen.Cpp.AST
21−
22−applyAll :: [a -> a] -> a -> a
23−applyAll = foldl1 (.)
24−
25−replaceIdent :: String -> Cpp -> Cpp -> Cpp
26−replaceIdent var1 cpp = everywhereOnCpp replace
27− where
28− replace (CppVar var2) | var1 == var2 = cpp
29− replace other = other
30−
31−replaceIdents :: [(String, Cpp)] -> Cpp -> Cpp
32−replaceIdents vars = everywhereOnCpp replace
33− where
34− replace v@(CppVar var) = fromMaybe v $ lookup var vars
35− replace other = other
36−
37−isReassigned :: String -> Cpp -> Bool
38−isReassigned var1 = everythingOnCpp (||) check
39− where
40− check :: Cpp -> Bool
41− check (CppFunction _ args _ _ _) | var1 `elem` (map fst args) = True
42− check (CppVariableIntroduction arg _ _) | var1 == fst arg = True
43− check (CppAssignment (CppVar arg) _) | var1 == arg = True
44− check _ = False
45−
46−isRebound :: Cpp -> Cpp -> Bool
47−isRebound cpp d = any (\v -> isReassigned v d || isUpdated v d) (everythingOnCpp (++) variablesOf cpp)
48− where
49− variablesOf (CppVar var) = [var]
50− variablesOf _ = []
51−
52−isUsed :: String -> Cpp -> Bool
53−isUsed var1 = everythingOnCpp (||) check
54− where
55− check :: Cpp -> Bool
56− check (CppVar var2) | var1 == var2 = True
57− check (CppAssignment target _) | var1 == targetVariable target = True
58− check _ = False
59−
60−targetVariable :: Cpp -> String
61−targetVariable (CppVar var) = var
62−targetVariable (CppAccessor _ tgt) = targetVariable tgt
63−targetVariable (CppIndexer _ tgt) = targetVariable tgt
64−targetVariable _ = error "Invalid argument to targetVariable"
65−
66−isUpdated :: String -> Cpp -> Bool
67−isUpdated var1 = everythingOnCpp (||) check
68− where
69− check :: Cpp -> Bool
70− check (CppAssignment target _) | var1 == targetVariable target = True
71− check _ = False
72−
73−removeFromBlock :: ([Cpp] -> [Cpp]) -> Cpp -> Cpp
74−removeFromBlock go (CppBlock sts) = CppBlock (go sts)
75−removeFromBlock _ cpp = cpp
src/Language/PureScript/CodeGen/Cpp/Optimizer/Inliner.hsdeleted−344
@@ -1,344 +0,0 @@
1−-----------------------------------------------------------------------------
2−--
3−-- Module : Language.PureScript.CodeGen.Cpp.Optimizer.Inliner
4−-- Copyright : (c) 2013-15 Phil Freeman, Andy Arvanitis, and other contributors
5−-- License : MIT
6−--
7−-- Maintainer : Andy Arvanitis
8−-- Stability : experimental
9−-- Portability :
10−--
11−-- |
12−-- This module provides basic inlining capabilities
13−--
14−-----------------------------------------------------------------------------
15−
16−{-# LANGUAGE CPP #-}
17−
18−module Language.PureScript.CodeGen.Cpp.Optimizer.Inliner (
19− inlineVariables,
20− inlineValues,
21− inlineOperator,
22− inlineCommonOperators,
23− inlineFnComposition,
24− etaConvert,
25− unThunk,
26− evaluateIifes
27−) where
28−
29−#if __GLASGOW_HASKELL__ < 710
30−import Control.Applicative (Applicative)
31−#endif
32−import Control.Monad.Supply.Class (MonadSupply, freshName)
33−import Language.PureScript.CodeGen.Cpp.Types
34−import Language.PureScript.CodeGen.Cpp.AST
35−import Language.PureScript.CodeGen.Cpp.Common
36−import Language.PureScript.CodeGen.Cpp.Optimizer.Common
37−import Language.PureScript.Names
38−import qualified Language.PureScript.Constants as C
39−
40−-- TODO: Potential bug:
41−-- Shouldn't just inline this case: { var x = 0; x.toFixed(10); }
42−-- Needs to be: { 0..toFixed(10); }
43−-- Probably needs to be fixed in pretty-printer instead.
44−shouldInline :: Cpp -> Bool
45−shouldInline (CppVar _) = True
46−shouldInline (CppNumericLiteral _) = True
47−shouldInline (CppStringLiteral _) = True
48−shouldInline (CppBooleanLiteral _) = True
49−shouldInline (CppAccessor _ val) = shouldInline val
50−shouldInline (CppIndexer index val) = shouldInline index && shouldInline val
51−shouldInline (CppCast _ val) = shouldInline val
52−shouldInline _ = False
53−
54−etaConvert :: Cpp -> Cpp
55−etaConvert = everywhereOnCpp convert
56− where
57− convert :: Cpp -> Cpp
58− convert (CppBlock [CppReturn (CppApp (CppLambda _ idents _ block@(CppBlock body)) args)])
59− | all shouldInline args &&
60− not (any (`isRebound` block) (map (CppVar . fst) idents)) &&
61− not (any (`isRebound` block) args)
62− = CppBlock (map (replaceIdents (zip (map fst idents) args)) body)
63− convert (CppLambda _ [] _ (CppBlock [CppReturn (CppApp fn [])])) = fn
64− convert cpp = cpp
65−
66−unThunk :: Cpp -> Cpp
67−unThunk = everywhereOnCpp convert
68− where
69− convert :: Cpp -> Cpp
70− convert (CppBlock []) = CppBlock []
71− convert (CppBlock cpps) =
72− case last cpps of
73− CppReturn (CppApp (CppLambda _ [] _ (CppBlock body)) []) -> CppBlock $ init cpps ++ body
74− _ -> CppBlock cpps
75− convert cpp = cpp
76−
77−evaluateIifes :: Cpp -> Cpp
78−evaluateIifes = everywhereOnCpp convert
79− where
80− convert :: Cpp -> Cpp
81− convert (CppApp (CppLambda _ [] _ (CppBlock [CppReturn ret])) []) = ret
82− convert (CppReturn cpp@(CppApp _ _))
83− | (f, args@(_:_)) <- unApp cpp [],
84− CppApp (CppLambda _ [] _ (CppBlock cpps)) [] <- f,
85− CppReturn ret <- last cpps = CppBlock $ init cpps ++ [CppReturn $foldl (\fn a -> CppApp fn [a]) ret args]
86− where
87− unApp :: Cpp -> [Cpp] -> (Cpp, [Cpp])
88− unApp (CppApp f [arg]) args = unApp f (arg : args)
89− unApp other args = (other, args)
90− convert cpp = cpp
91−
92−inlineVariables :: Cpp -> Cpp
93−inlineVariables = everywhereOnCpp $ removeFromBlock go
94− where
95− go :: [Cpp] -> [Cpp]
96− go [] = []
97− go (CppVariableIntroduction (var, _) _ (Just cpp) : sts)
98− | shouldInline cpp && not (any (isReassigned var) sts) && not (any (isRebound cpp) sts) && not (any (isUpdated var) sts) =
99− go (map (replaceIdent var cpp) sts)
100− go (s:sts) = s : go sts
101−
102−inlineValues :: Cpp -> Cpp
103−inlineValues = everywhereOnCpp convert
104− where
105− convert :: Cpp -> Cpp
106− convert (CppApp fn [dict]) | isDict semiringNumber dict && isFn fnZero fn = CppNumericLiteral (Left 0)
107− | isDict semiringNumber dict && isFn fnOne fn = CppNumericLiteral (Left 1)
108− | isDict semiringInt dict && isFn fnZero fn = CppNumericLiteral (Left 0)
109− | isDict semiringInt dict && isFn fnOne fn = CppNumericLiteral (Left 1)
110− | isDict boundedBoolean dict && isFn fnBottom fn = CppBooleanLiteral False
111− | isDict boundedBoolean dict && isFn fnTop fn = CppBooleanLiteral True
112− convert (CppApp fn [dict, x, y])
113− | isDict semiringInt dict && isFn fnAdd fn = CppBinary Add x y
114− | isDict semiringInt dict && isFn fnMultiply fn = CppBinary Multiply x y
115− | isDict moduloSemiringInt dict && isFn fnDivide fn = CppBinary Divide x y
116− | isDict ringInt dict && isFn fnSubtract fn = CppBinary Subtract x y
117− convert (CppApp (CppApp (CppApp fn [dict]) [x]) [y])
118− | isDict semiringInt dict && isFn fnAdd fn = CppBinary Add x y
119− | isDict semiringInt dict && isFn fnMultiply fn = CppBinary Multiply x y
120− | isDict moduloSemiringInt dict && isFn fnDivide fn = CppBinary Divide x y
121− | isDict ringInt dict && isFn fnSubtract fn = CppBinary Subtract x y
122−
123− convert other = other
124− fnZero = (C.prelude, C.zero)
125− fnOne = (C.prelude, C.one)
126− fnBottom = (C.prelude, C.bottom)
127− fnTop = (C.prelude, C.top)
128− fnAdd = (C.prelude, (C.+))
129− fnDivide = (C.prelude, (C./))
130− fnMultiply = (C.prelude, (C.*))
131− fnSubtract = (C.prelude, (C.-))
132−
133−inlineOperator :: (String, String) -> (Cpp -> Cpp -> Cpp) -> Cpp -> Cpp
134−inlineOperator (m, op) f = everywhereOnCpp convert
135− where
136− convert :: Cpp -> Cpp
137− convert (CppApp op' [x, y]) | isOp op' = f x y
138− convert (CppApp (CppApp op' [x]) [y]) | isOp op' = f x y
139− convert other = other
140− isOp (CppAccessor (CppVar longForm) (CppVar m')) = m == m' && longForm == identToCpp (Op op)
141− isOp (CppIndexer (CppStringLiteral op') (CppVar m')) = m == m' && op == op'
142− isOp _ = False
143−
144−inlineCommonOperators :: Cpp -> Cpp
145−inlineCommonOperators = applyAll $
146− [ binary semiringNumber (C.+) Add
147− , binary semiringNumber (C.*) Multiply
148−
149− , binary ringNumber (C.-) Subtract
150− , unary ringNumber C.negate CppNegate
151− , binary ringInt (C.-) Subtract
152− , unary ringInt C.negate CppNegate
153−
154− , binary moduloSemiringNumber (C./) Divide
155− , binary moduloSemiringInt C.mod Modulus
156−
157− , binary eqNumber (C.==) Equal
158− , binary eqNumber (C./=) NotEqual
159− , binary eqInt (C.==) Equal
160− , binary eqInt (C./=) NotEqual
161− , binary eqString (C.==) Equal
162− , binary eqString (C./=) NotEqual
163− , binary eqBoolean (C.==) Equal
164− , binary eqBoolean (C./=) NotEqual
165−
166− , binary ordNumber (C.<) LessThan
167− , binary ordNumber (C.>) GreaterThan
168− , binary ordNumber (C.<=) LessThanOrEqual
169− , binary ordNumber (C.>=) GreaterThanOrEqual
170− , binary ordInt (C.<) LessThan
171− , binary ordInt (C.>) GreaterThan
172− , binary ordInt (C.<=) LessThanOrEqual
173− , binary ordInt (C.>=) GreaterThanOrEqual
174−
175− , binary semigroupString (C.<>) Add
176− , binary semigroupString (C.++) Add
177−
178− , binary booleanAlgebraBoolean (C.&&) And
179− , binary booleanAlgebraBoolean (C.||) Or
180− , binaryFunction booleanAlgebraBoolean C.conj And
181− , binaryFunction booleanAlgebraBoolean C.disj Or
182− , unary booleanAlgebraBoolean C.not CppNot
183−
184− , binary' C.dataIntBits (C..|.) BitwiseOr
185− , binary' C.dataIntBits (C..&.) BitwiseAnd
186− , binary' C.dataIntBits (C..^.) BitwiseXor
187− , binary' C.dataIntBits C.shl ShiftLeft
188− , binary' C.dataIntBits C.shr ShiftRight
189− -- , binary' C.dataIntBits C.zshr ZeroFillShiftRight
190− , unary' C.dataIntBits C.complement CppBitwiseNot
191− ] -- ++ -- DISABLE mkFn/runFn inlining
192− -- [ fn | i <- [0..10], fn <- [ mkFn i, runFn i ] ]
193− where
194− binary :: (String, String) -> String -> BinaryOp -> Cpp -> Cpp
195− binary dict opString op = everywhereOnCpp convert
196− where
197− convert :: Cpp -> Cpp
198− convert (CppApp fn [dict', CppStringLiteral x, CppStringLiteral y])
199− | isDict dict dict' && isPreludeFn opString fn = CppStringLiteral (x ++ y)
200− convert (CppApp fn [dict', x, y]) | isDict dict dict' && isPreludeFn opString fn = CppBinary op x y
201− convert (CppApp (CppApp (CppApp fn [dict']) [CppStringLiteral x]) [CppStringLiteral y])
202− | isDict dict dict' && isPreludeFn opString fn = CppStringLiteral (x ++ y)
203− convert (CppApp (CppApp (CppApp fn [dict']) [x]) [y]) | isDict dict dict' && isPreludeFn opString fn = CppBinary op x y
204− convert other = other
205− binary' :: String -> String -> BinaryOp -> Cpp -> Cpp
206− binary' moduleName opString op = everywhereOnCpp convert
207− where
208− convert :: Cpp -> Cpp
209− convert (CppApp fn [x, y]) | isFn (moduleName, opString) fn = CppBinary op x y
210− convert (CppApp (CppApp fn [x]) [y]) | isFn (moduleName, opString) fn = CppBinary op x y
211− convert other = other
212− binaryFunction :: (String, String) -> String -> BinaryOp -> Cpp -> Cpp
213− binaryFunction dict fnName op = everywhereOnCpp convert
214− where
215− convert :: Cpp -> Cpp
216− convert (CppApp fn [dict', x, y]) | isPreludeFn fnName fn && isDict dict dict' = CppBinary op x y
217− convert (CppApp (CppApp (CppApp fn [dict']) [x]) [y]) | isPreludeFn fnName fn && isDict dict dict' = CppBinary op x y
218− convert other = other
219− unary :: (String, String) -> String -> CppUnaryOp -> Cpp -> Cpp
220− unary dict fnName op = everywhereOnCpp convert
221− where
222− convert :: Cpp -> Cpp
223− convert (CppApp fn [dict', x]) | isPreludeFn fnName fn && isDict dict dict' = CppUnary op x
224− convert (CppApp (CppApp fn [dict']) [x]) | isPreludeFn fnName fn && isDict dict dict' = CppUnary op x
225− convert other = other
226− unary' :: String -> String -> CppUnaryOp -> Cpp -> Cpp
227− unary' moduleName fnName op = everywhereOnCpp convert
228− where
229− convert :: Cpp -> Cpp
230− convert (CppApp fn [x]) | isFn (moduleName, fnName) fn = CppUnary op x
231− convert other = other
232− -- mkFn :: Int -> Cpp -> Cpp
233− -- mkFn 0 = everywhereOnCpp convert
234− -- where
235− -- convert :: Cpp -> Cpp
236− -- convert (CppApp mkFnN [CppLambda caps [_] _ (CppBlock cpp)]) | isNFn C.mkFn 0 mkFnN =
237− -- CppLambda caps [] Nothing (CppBlock cpp)
238− -- convert other = other
239− -- mkFn n = everywhereOnCpp convert
240− -- where
241− -- convert :: Cpp -> Cpp
242− -- convert orig@(CppApp mkFnN [fn]) | isNFn C.mkFn n mkFnN =
243− -- case collectArgs n [] fn of
244− -- Just (args, cpp) -> CppLambda [CppCaptureAll] args Nothing (CppBlock cpp)
245− -- Nothing -> orig
246− -- convert other = other
247− -- collectArgs :: Int -> [(String, Maybe CppType)] -> Cpp -> Maybe ([(String, Maybe CppType)], [Cpp])
248− -- collectArgs 1 acc (CppLambda _ [oneArg] _ (CppBlock cpp)) | length acc == n - 1 = Just (reverse (oneArg : acc), cpp)
249− -- collectArgs m acc (CppLambda _ [oneArg] _ (CppBlock [CppReturn ret])) = collectArgs (m - 1) (oneArg : acc) ret
250− -- collectArgs _ _ _ = Nothing
251− --
252− -- isNFn :: String -> Int -> Cpp -> Bool
253− -- isNFn prefix n (CppVar name) = name == (prefix ++ show n)
254− -- isNFn prefix n (CppAccessor (CppVar name) (CppVar dataFunction)) | dataFunction == C.dataFunction = name == (prefix ++ show n)
255− -- isNFn _ _ _ = False
256− --
257− -- runFn :: Int -> Cpp -> Cpp
258− -- runFn n = everywhereOnCpp convert
259− -- where
260− -- convert :: Cpp -> Cpp
261− -- convert cpp = fromMaybe cpp $ go n [] cpp
262− --
263− -- go :: Int -> [Cpp] -> Cpp -> Maybe Cpp
264− -- go 0 acc (CppApp runFnN [fn]) | isNFn C.runFn n runFnN && length acc == n = Just (CppApp fn acc)
265− -- go m acc (CppApp lhs [arg]) = go (m - 1) (arg : acc) lhs
266− -- go _ _ _ = Nothing
267−
268−-- (f <<< g $ x) = f (g x)
269−-- (f <<< g) = \x -> f (g x)
270−inlineFnComposition :: (Applicative m, MonadSupply m) => Cpp -> m Cpp
271−inlineFnComposition = everywhereOnCppTopDownM convert
272− where
273− convert :: (MonadSupply m) => Cpp -> m Cpp
274− convert (CppApp fn [dict', x, y]) | isFnCompose dict' fn = do
275− arg <- freshName
276− return $ CppLambda [CppCaptureAll] [(arg, Just (CppAny [CppConst, CppRef]))] (Just $ CppAny []) (CppBlock [CppReturn $ CppApp x [CppApp y [CppVar arg]]])
277− convert (CppApp (CppApp (CppApp (CppApp fn [dict']) [x]) [y]) [z]) | isFnCompose dict' fn =
278− return $ CppApp x [CppApp y [z]]
279− convert (CppApp (CppApp (CppApp fn [dict']) [x]) [y]) | isFnCompose dict' fn = do
280− arg <- freshName
281− return $ CppLambda [CppCaptureAll] [(arg, Just (CppAny [CppConst, CppRef]))] (Just $ CppAny []) (CppBlock [CppReturn $ CppApp x [CppApp y [CppVar arg]]])
282− convert other = return other
283− isFnCompose :: Cpp -> Cpp -> Bool
284− isFnCompose dict' fn = isDict semigroupoidFn dict' && (isPreludeFn (C.<<<) fn || isPreludeFn (C.compose) fn)
285−
286−isDict :: (String, String) -> Cpp -> Bool
287−isDict (moduleName, dictName) (CppAccessor (CppVar x) (CppVar y)) = x == dictName && y == moduleName
288−isDict _ _ = False
289−
290−isFn :: (String, String) -> Cpp -> Bool
291−isFn (moduleName, fnName) (CppAccessor (CppVar x) (CppVar y)) = x == (identToCpp (Ident fnName)) && y == moduleName
292−isFn (moduleName, fnName) (CppIndexer (CppStringLiteral x) (CppVar y)) = x == fnName && y == moduleName
293−isFn _ _ = False
294−
295−isPreludeFn :: String -> Cpp -> Bool
296−isPreludeFn fnName = isFn (C.prelude, fnName)
297−
298−semiringNumber :: (String, String)
299−semiringNumber = (C.prelude, C.semiringNumber)
300−
301−semiringInt :: (String, String)
302−semiringInt = (C.prelude, C.semiringInt)
303−
304−ringNumber :: (String, String)
305−ringNumber = (C.prelude, C.ringNumber)
306−
307−ringInt :: (String, String)
308−ringInt = (C.prelude, C.ringInt)
309−
310−moduloSemiringNumber :: (String, String)
311−moduloSemiringNumber = (C.prelude, C.moduloSemiringNumber)
312−
313−moduloSemiringInt :: (String, String)
314−moduloSemiringInt = (C.prelude, C.moduloSemiringInt)
315−
316−eqNumber :: (String, String)
317−eqNumber = (C.prelude, C.eqNumber)
318−
319−eqInt :: (String, String)
320−eqInt = (C.prelude, C.eqInt)
321−
322−eqString :: (String, String)
323−eqString = (C.prelude, C.eqNumber)
324−
325−eqBoolean :: (String, String)
326−eqBoolean = (C.prelude, C.eqNumber)
327−
328−ordNumber :: (String, String)
329−ordNumber = (C.prelude, C.ordNumber)
330−
331−ordInt :: (String, String)
332−ordInt = (C.prelude, C.ordInt)
333−
334−semigroupString :: (String, String)
335−semigroupString = (C.prelude, C.semigroupString)
336−
337−boundedBoolean :: (String, String)
338−boundedBoolean = (C.prelude, C.boundedBoolean)
339−
340−booleanAlgebraBoolean :: (String, String)
341−booleanAlgebraBoolean = (C.prelude, C.booleanAlgebraBoolean)
342−
343−semigroupoidFn :: (String, String)
344−semigroupoidFn = (C.prelude, C.semigroupoidFn)
src/Language/PureScript/CodeGen/Cpp/Optimizer/MagicDo.hsdeleted−125
@@ -1,125 +0,0 @@
1−-----------------------------------------------------------------------------
2−--
3−-- Module : Language.PureScript.CodeGen.Cpp.Optimizer.MagicDo
4−-- Copyright : (c) Phil Freeman 2013-14
5−-- License : MIT
6−--
7−-- Maintainer : Andy Arvanitis <andy.arvanitis@gmail.com>
8−-- Stability : experimental
9−-- Portability :
10−--
11−-- |
12−-- This module implements the "Magic Do" optimization, which inlines calls to return
13−-- and bind for the Eff monad, as well as some of its actions.
14−--
15−-----------------------------------------------------------------------------
16−
17−module Language.PureScript.CodeGen.Cpp.Optimizer.MagicDo (
18− magicDo
19−) where
20−
21−import Language.PureScript.CodeGen.Cpp.AST
22−import Language.PureScript.CodeGen.Cpp.Common
23−import Language.PureScript.CodeGen.Cpp.Types
24−import Language.PureScript.Names
25−import Language.PureScript.Options
26−import qualified Language.PureScript.Constants as C
27−
28−magicDo :: Options -> Cpp -> Cpp
29−magicDo opts | optionsNoMagicDo opts = id
30− | otherwise = magicDo'
31−
32−-- |
33−-- Inline type class dictionaries for >>= and return for the Eff monad
34−--
35−-- E.g.
36−--
37−-- Prelude[">>="](dict)(m1)(function(x) {
38−-- return ...;
39−-- })
40−--
41−-- becomes
42−--
43−-- function __do {
44−-- var x = m1();
45−-- ...
46−-- }
47−--
48−magicDo' :: Cpp -> Cpp
49−magicDo' = everywhereOnCpp undo . everywhereOnCppTopDown convert
50− where
51− -- The name of the function block which is added to denote a do block
52− fnName = "__do"
53− -- Desugar monomorphic calls to >>= and return for the Eff monad
54− convert :: Cpp -> Cpp
55− -- Desugar return
56− convert (CppApp (CppApp ret [effDict, val]) []) | isRetPoly ret && isEffDict C.monadEffDictionary effDict = val
57− convert (CppApp (CppApp ret [val]) []) | isReturn ret = val
58− -- Desugar pure
59− convert (CppApp (CppApp pure' [effDict, val]) []) | isPurePoly pure' && isEffDict C.applicativeEffDictionary effDict = val
60− convert (CppApp (CppApp pure' [val]) []) | isPure pure' = val
61− -- Desugar >>
62− convert (CppApp bind [effDict, m, CppLambda _ [] rty (CppBlock cpp)]) | isBindPoly bind && isEffDict C.bindEffDictionary effDict =
63− CppFunction fnName [] rty [] $ CppBlock (CppApp m [] : map applyReturns cpp )
64− convert (CppApp (CppApp bind [m]) [CppLambda _ [] rty (CppBlock cpp)]) | isBind bind =
65− CppFunction fnName [] rty [] $ CppBlock (CppApp m [] : map applyReturns cpp )
66− -- Desugar >>=
67− convert (CppApp bind [effDict, m, CppLambda _ [arg] rty (CppBlock cpp)]) | isBindPoly bind && isEffDict C.bindEffDictionary effDict =
68− CppFunction fnName [] rty [] $ CppBlock (CppVariableIntroduction arg [] (Just (CppApp m [])) : map applyReturns cpp)
69− convert (CppApp (CppApp bind [m]) [CppLambda _ [arg] rty (CppBlock cpp)]) | isBind bind =
70− CppFunction fnName [] rty [] $ CppBlock (CppVariableIntroduction arg [] (Just (CppApp m [])) : map applyReturns cpp)
71− -- Desugar untilE
72− convert (CppApp (CppApp f [arg]) []) | isEffFunc C.untilE f =
73− CppApp (CppLambda [CppCaptureAll] [] (Just $ CppAny []) (CppBlock [ CppWhile (CppUnary CppNot (CppApp arg [])) (CppBlock []), CppReturn $ CppObjectLiteral []])) []
74− -- Desugar whileE
75− convert (CppApp (CppApp f [arg1, arg2]) []) | isEffFunc C.whileE f =
76− CppApp (CppLambda [CppCaptureAll] [] (Just $ CppAny []) (CppBlock [ CppWhile (CppApp arg1 []) (CppBlock [ CppApp arg2 [] ]), CppReturn $ CppObjectLiteral []])) []
77− convert (CppApp (CppApp (CppApp f [arg1]) [arg2]) []) | isEffFunc C.whileE f =
78− CppApp (CppLambda [CppCaptureAll] [] (Just $ CppAny []) (CppBlock [ CppWhile (CppApp arg1 []) (CppBlock [ CppApp arg2 [] ]), CppReturn $ CppObjectLiteral []])) []
79− convert other = other
80− -- Check if an expression represents a monomorphic call to >>= for the Eff monad
81− isBind (CppApp bindPoly [effDict]) | isBindPoly bindPoly && isEffDict C.bindEffDictionary effDict = True
82− isBind _ = False
83− -- Check if an expression represents a monomorphic call to return for the Eff monad
84− isReturn (CppApp retPoly [effDict]) | isRetPoly retPoly && isEffDict C.monadEffDictionary effDict = True
85− isReturn _ = False
86− -- Check if an expression represents a monomorphic call to pure for the Eff applicative
87− isPure (CppApp purePoly [effDict]) | isPurePoly purePoly && isEffDict C.applicativeEffDictionary effDict = True
88− isPure _ = False
89− -- Check if an expression represents the polymorphic >>= function
90− isBindPoly (CppAccessor (CppVar prop) (CppVar prelude)) = prelude == C.prelude && (prop `elem` map identToCpp [Ident C.bind, Op (C.>>=)])
91− isBindPoly (CppIndexer (CppStringLiteral bind) (CppVar prelude)) = prelude == C.prelude && (bind `elem` [C.bind, (C.>>=)])
92− isBindPoly _ = False
93− -- Check if an expression represents the polymorphic return function
94− isRetPoly (CppAccessor (CppVar returnEscaped) (CppVar prelude)) = prelude == C.prelude && returnEscaped == C.returnEscaped
95− isRetPoly (CppIndexer (CppStringLiteral return') (CppVar prelude)) = prelude == C.prelude && return' == C.return
96− isRetPoly _ = False
97− -- Check if an expression represents the polymorphic pure function
98− isPurePoly (CppAccessor (CppVar pure') (CppVar prelude)) = prelude == C.prelude && pure' == C.pure'
99− isPurePoly (CppIndexer (CppStringLiteral pure') (CppVar prelude)) = prelude == C.prelude && pure' == C.pure'
100− isPurePoly _ = False
101− -- Check if an expression represents a function in the Ef module
102− isEffFunc name (CppAccessor (CppVar name') (CppVar eff)) = eff == C.eff && name == name'
103− isEffFunc _ _ = False
104− -- Check if an expression represents the Monad Eff dictionary
105− isEffDict name (CppVar ident) | ident == name = True
106− isEffDict name (CppAccessor (CppVar prop) (CppVar eff)) = eff == C.eff && prop == name
107− isEffDict _ _ = False
108− -- Remove __do function applications which remain after desugaring
109− undo :: Cpp -> Cpp
110− undo (CppReturn (CppApp (CppFunction ident [] _ _ body) [])) | ident == fnName = body
111− undo (CppFunction ident [] rty _ body) | ident == fnName = CppLambda [CppCaptureAll] [] rty body
112− undo other = other
113−
114− applyReturns :: Cpp -> Cpp
115− applyReturns (CppReturn ret) = CppReturn (CppApp ret [])
116− applyReturns (CppBlock cpps) = CppBlock (map applyReturns cpps)
117− applyReturns (CppWhile cond cpp) = CppWhile cond (applyReturns cpp)
118− applyReturns (CppIfElse cond t f) = CppIfElse cond (applyReturns t) (applyReturns `fmap` f)
119− applyReturns other = other
120−
121−-- |
122−-- Inline functions in the ST module
123−--
124−-- TODO: various issues in C++ backend -- revisit later
125−--
src/Language/PureScript/CodeGen/Cpp/Optimizer/TCO.hsdeleted−149
@@ -1,149 +0,0 @@
1−-----------------------------------------------------------------------------
2−--
3−-- Module : Language.PureScript.CodeGen.Cpp.Optimizer.TCO
4−-- Copyright : (c) 2013-15 Phil Freeman, Andy Arvanitis, and other contributors
5−-- License : MIT
6−--
7−-- Maintainer : Andy Arvanitis
8−-- Stability : experimental
9−-- Portability :
10−--
11−-- |
12−-- This module implements tail call elimination.
13−--
14−-----------------------------------------------------------------------------
15−
16−module Language.PureScript.CodeGen.Cpp.Optimizer.TCO (tco) where
17−
18−import Data.List
19−import Data.Monoid
20−
21−import Language.PureScript.Options
22−import Language.PureScript.CodeGen.Cpp.Types
23−import Language.PureScript.CodeGen.Cpp.AST
24−
25−-- |
26−-- Eliminate tail calls
27−--
28−tco :: Options -> Cpp -> Cpp
29−tco opts | optionsNoTco opts = id
30− | otherwise = tco'
31−
32−tco' :: Cpp -> Cpp
33−tco' = everywhereOnCpp convert
34− where
35− tcoVar :: String -> String
36− tcoVar arg = "__tco_" ++ arg
37−
38− copyVar :: String -> String
39− copyVar arg = "__copy_" ++ arg
40−
41− copyVar' :: (String, Maybe CppType) -> (String, Maybe CppType)
42− copyVar' (arg, t) = (copyVar arg, t)
43−
44− convert :: Cpp -> Cpp
45−
46− convert cpp@(CppVariableIntroduction (name, ty) qs (Just fn@CppLambda {})) =
47− let
48− (argss, body', replace) = collectAllFunctionArgs [] id fn
49− in case () of
50− _ | isTailCall name body' ->
51− let
52− allArgs = fst <$> (concat $ reverse argss)
53− in
54− CppVariableIntroduction (name, ty) qs (Just (replace (toLoop name allArgs body')))
55− | otherwise -> cpp
56−
57− convert fn@(CppFunction name (_:_) _ _ _) =
58− let
59− (argss, body', replace) = collectAllFunctionArgs [] id fn
60− in case () of
61− _ | isTailCall name body' ->
62− let
63− allArgs = fst <$> (concat $ reverse argss)
64− in
65− replace (toLoop name allArgs body')
66− | otherwise -> fn
67−
68− convert cpp = cpp
69−
70− collectAllFunctionArgs :: [[(String, Maybe CppType)]] -> (Cpp -> Cpp) -> Cpp -> ([[(String, Maybe CppType)]], Cpp, Cpp -> Cpp)
71− collectAllFunctionArgs allArgs f (CppFunction ident args rty qs (CppBlock (body@(CppReturn _):_))) =
72− collectAllFunctionArgs (args : allArgs) (\b -> f (CppFunction ident (map copyVar' args) rty qs (CppBlock [b]))) body
73− collectAllFunctionArgs allArgs f (CppFunction ident args rty qs body@(CppBlock _)) =
74− (args : allArgs, body, f . CppFunction ident (map copyVar' args) rty qs)
75− collectAllFunctionArgs allArgs f (CppReturn (CppLambda cs args rty (CppBlock [body]))) =
76− collectAllFunctionArgs (args : allArgs) (\b -> f (CppReturn (CppLambda cs (map copyVar' args) rty (CppBlock [b])))) body
77− collectAllFunctionArgs allArgs f (CppReturn (CppLambda cs args rty body@(CppBlock _))) =
78− (args : allArgs, body, f . CppReturn . CppLambda cs (map copyVar' args) rty)
79− collectAllFunctionArgs allArgs f body = (allArgs, body, f)
80−
81− isTailCall :: String -> Cpp -> Bool
82− isTailCall ident cpp =
83− let
84− numSelfCalls = everythingOnCpp (+) countSelfCalls cpp
85− numSelfCallsInTailPosition = everythingOnCpp (+) countSelfCallsInTailPosition cpp
86− numSelfCallsUnderFunctions = everythingOnCpp (+) countSelfCallsUnderFunctions cpp
87− numSelfCallWithFnArgs = everythingOnCpp (+) countSelfCallsWithFnArgs cpp
88− in
89− numSelfCalls > 0
90− && numSelfCalls == numSelfCallsInTailPosition
91− && numSelfCallsUnderFunctions == 0
92− && numSelfCallWithFnArgs == 0
93− where
94− countSelfCalls :: Cpp -> Int
95− countSelfCalls (CppApp (CppVar ident') _) | ident == ident' = 1
96− countSelfCalls _ = 0
97−
98− countSelfCallsInTailPosition :: Cpp -> Int
99− countSelfCallsInTailPosition (CppReturn ret) | isSelfCall ident ret = 1
100− countSelfCallsInTailPosition _ = 0
101−
102− countSelfCallsUnderFunctions :: Cpp -> Int
103− countSelfCallsUnderFunctions (CppFunction _ _ _ _ cpp') = everythingOnCpp (+) countSelfCalls cpp'
104− countSelfCallsUnderFunctions (CppLambda _ (_:_) _ cpp') = everythingOnCpp (+) countSelfCalls cpp'
105− countSelfCallsUnderFunctions _ = 0
106−
107− countSelfCallsWithFnArgs :: Cpp -> Int
108− countSelfCallsWithFnArgs ret = if isSelfCallWithFnArgs ident ret [] then 1 else 0
109−
110− toLoop :: String -> [String] -> Cpp -> Cpp
111− toLoop ident allArgs cpp = CppBlock $
112− map (\arg -> CppVariableIntroduction (arg, Just $ CppAny []) [] (Just (CppVar (copyVar arg)))) allArgs ++
113− [ CppWhile (CppBooleanLiteral True) (CppBlock loop) ]
114− where
115− loop :: [Cpp]
116− loop = case everywhereOnCpp loopify cpp of
117− CppReturn (CppApp (CppLambda _ [] _ (CppBlock cpps')) []) -> nub cpps' -- elim dup var intros
118− CppBlock cpps' -> nub cpps'
119− cpp' -> [cpp']
120− loopify :: Cpp -> Cpp
121− loopify (CppReturn ret) | isSelfCall ident ret =
122− let
123− allArgumentValues = concat $ collectSelfCallArgs [] ret
124− in
125− CppBlock $ zipWith (\val arg ->
126− CppVariableIntroduction (tcoVar arg, Just $ CppAny []) [] (Just val)) allArgumentValues allArgs
127− ++ map (\arg ->
128− CppAssignment (CppVar arg) (CppVar (tcoVar arg))) allArgs
129− ++ [ CppContinue ]
130− loopify other = other
131− collectSelfCallArgs :: [[Cpp]] -> Cpp -> [[Cpp]]
132− collectSelfCallArgs allArgumentValues (CppApp fn args') = collectSelfCallArgs (args' : allArgumentValues) fn
133− collectSelfCallArgs allArgumentValues _ = allArgumentValues
134−
135− isSelfCall :: String -> Cpp -> Bool
136− isSelfCall ident (CppApp (CppVar ident') _) = ident == ident'
137− isSelfCall ident (CppApp fn _) = isSelfCall ident fn
138− isSelfCall _ _ = False
139−
140− isSelfCallWithFnArgs :: String -> Cpp -> [Cpp] -> Bool
141− isSelfCallWithFnArgs ident (CppVar ident') args | ident == ident' && any hasFunction args = True
142− isSelfCallWithFnArgs ident (CppApp fn args) acc = isSelfCallWithFnArgs ident fn (args ++ acc)
143− isSelfCallWithFnArgs _ _ _ = False
144−
145− hasFunction :: Cpp -> Bool
146− hasFunction = getAny . everythingOnCpp mappend (Any . isFunction)
147− where
148− isFunction (CppFunction {}) = True
149− isFunction _ = False
src/Language/PureScript/CodeGen/Cpp/Optimizer/Unused.hsdeleted−45
@@ -1,45 +0,0 @@
1−-----------------------------------------------------------------------------
2−--
3−-- Module : Language.PureScript.CodeGen.Cpp.Optimizer.Unused
4−-- Copyright : (c) Phil Freeman 2013-14
5−-- License : MIT
6−--
7−-- Maintainer : Phil Freeman <paf31@cantab.net>
8−-- Stability : experimental
9−-- Portability :
10−--
11−-- |
12−-- Removes unused variables
13−--
14−-----------------------------------------------------------------------------
15−
16−module Language.PureScript.CodeGen.Cpp.Optimizer.Unused where
17−
18−import Language.PureScript.CodeGen.Cpp.AST
19−import Language.PureScript.CodeGen.Cpp.Optimizer.Common
20−
21−import qualified Language.PureScript.Constants as C
22−
23−removeCodeAfterReturnStatements :: Cpp -> Cpp
24−removeCodeAfterReturnStatements = everywhereOnCpp (removeFromBlock go)
25− where
26− go :: [Cpp] -> [Cpp]
27− go cpps | not (any isCppReturn cpps) = cpps
28− | otherwise = let (body, ret : _) = span (not . isCppReturn) cpps in body ++ [ret]
29− isCppReturn (CppReturn _) = True
30− isCppReturn _ = False
31−
32−removeCodeAfterContinueStatements :: Cpp -> Cpp
33−removeCodeAfterContinueStatements = everywhereOnCpp (removeFromBlock go)
34− where
35− go :: [Cpp] -> [Cpp]
36− go cpps | not (any isCppContinue cpps) = cpps
37− | otherwise = let (body, ret : _) = span (not . isCppContinue) cpps in body ++ [ret]
38− isCppContinue = (== CppContinue)
39−
40−removeUnusedArg :: Cpp -> Cpp
41−removeUnusedArg = everywhereOnCpp convert
42− where
43− convert (CppFunction name [(arg,atyp)] rtyp qs body)
44− | arg == C.__unused = CppFunction name [("",atyp)] rtyp qs body
45− convert cpp = cpp
src/Language/PureScript/CodeGen/Cpp/Types.hsdeleted−128
@@ -1,128 +0,0 @@
1−-----------------------------------------------------------------------------
2−--
3−-- Module : Language.PureScript.CodeGen.Cpp.Types
4−-- Copyright : (c) Andy Arvanitis 2015
5−-- License : MIT
6−--
7−-- Maintainer : Andy Arvanitis <andy.arvanitis@gmail.com>
8−-- Stability : experimental
9−-- Portability :
10−--
11−-- |
12−-- Types for native C++11 translation
13−--
14−-----------------------------------------------------------------------------
15−
16−{-# LANGUAGE PatternGuards #-}
17−{-# LANGUAGE DeriveDataTypeable #-}
18−
19−module Language.PureScript.CodeGen.Cpp.Types where
20−
21−import Data.List
22−
23−import Language.PureScript.CodeGen.Cpp.Common
24−import Language.PureScript.Names
25−import qualified Language.PureScript.Constants as C
26−
27−-- import Debug.Trace
28−
29−data CppType = CppPrimitive String | CppAuto | CppAny [CppTypeQual]
30− deriving (Show, Read, Eq)
31−
32−data CppTypeQual = CppConst | CppRef
33− deriving (Show, Read, Eq)
34−
35−-- |
36−-- Value C++11 qualifiers
37−--
38−data CppValueQual
39− -- |
40− -- C++ static qualifier
41− --
42− = CppStatic
43− -- |
44− -- Inline function
45− --
46− | CppInline
47− -- |
48− -- C++11+ constant expression "constexpr"
49− --
50− | CppConstExpr
51− -- |
52− -- Extern value
53− --
54− | CppExtern
55− -- |
56− -- Function or lambda is involved in recursion
57− --
58− | CppRecursive
59− -- |
60− -- Function or lambda is involved in recursion
61− --
62− | CppTopLevel
63− deriving (Show, Read, Eq)
64−
65−-- |
66−-- C++ lambda capture list
67−--
68−data CppCaptureType = CppCaptureAll
69− deriving (Show, Read, Eq)
70−
71−runType :: CppType -> String
72−runType (CppPrimitive t) = t
73−runType CppAuto = "auto"
74−runType (CppAny qs)
75− | CppConst `elem` qs = "const " ++ (runType . CppAny $ delete CppConst qs)
76− | CppRef `elem` qs = runType (CppAny $ delete CppRef qs) ++ "&"
77− | otherwise = "any"
78−
79−runValueQual :: CppValueQual -> String
80−runValueQual CppStatic = "static"
81−runValueQual CppInline = "inline"
82−runValueQual CppConstExpr = "constexpr"
83−runValueQual CppExtern = "extern"
84−runValueQual CppRecursive = ""
85−runValueQual CppTopLevel = ""
86−
87−runCaptureType :: CppCaptureType -> String
88−runCaptureType CppCaptureAll = "="
89−
90−-- TODO: move or remove this
91−--
92−qualifiedToStr :: ModuleName -> (a -> Ident) -> Qualified a -> String
93−qualifiedToStr _ f (Qualified (Just (ModuleName [ProperName mn])) a) | mn == C.prim = runIdent $ f a
94−qualifiedToStr m f (Qualified (Just m') a) | m /= m' = moduleNameToCpp m' ++ "::" ++ identToCpp (f a)
95−qualifiedToStr _ f (Qualified _ a) = identToCpp (f a)
96−
97−boolType :: CppType
98−boolType = CppPrimitive "bool"
99−
100−intType :: CppType
101−intType = CppPrimitive "long"
102−
103−doubleType :: CppType
104−doubleType = CppPrimitive "double"
105−
106−stringType :: CppType
107−stringType = CppPrimitive "string"
108−
109−charType :: CppType
110−charType = CppPrimitive "char"
111−
112−mapType :: CppType
113−mapType = CppPrimitive "any::map"
114−
115−dataType :: CppType
116−dataType = CppPrimitive "any::data"
117−
118−arrayType :: CppType
119−arrayType = CppPrimitive "any::array"
120−
121−thunkMarkerType :: CppType
122−thunkMarkerType = CppPrimitive "any::as_thunk"
123−
124−unthunkMarkerValue :: String
125−unthunkMarkerValue = "any::unthunk"
126−
127−ctorKey :: String
128−ctorKey = "constructor"
src/Language/PureScript/CodeGen/JS.hsdeleted−452

This diff is too big to show here.

src/Language/PureScript/CodeGen/JS/AST.hsdeleted−404

This diff is too big to show here.

src/Language/PureScript/CodeGen/JS/Common.hsdeleted−231

This diff is too big to show here.

src/Language/PureScript/CodeGen/JS/Optimizer.hsdeleted−83

This diff is too big to show here.

src/Language/PureScript/CodeGen/JS/Optimizer/Blocks.hsdeleted−42

This diff is too big to show here.

src/Language/PureScript/CodeGen/JS/Optimizer/Common.hsdeleted−81

This diff is too big to show here.

src/Language/PureScript/CodeGen/JS/Optimizer/Inliner.hsdeleted−368

This diff is too big to show here.

src/Language/PureScript/CodeGen/JS/Optimizer/MagicDo.hsdeleted−134

This diff is too big to show here.

src/Language/PureScript/CodeGen/JS/Optimizer/TCO.hsdeleted−130

This diff is too big to show here.

src/Language/PureScript/CodeGen/JS/Optimizer/Unused.hsdeleted−46

This diff is too big to show here.

src/Language/PureScript/Comments.hsdeleted−15

This diff is too big to show here.

src/Language/PureScript/Constants.hsdeleted−373

This diff is too big to show here.

src/Language/PureScript/CoreFn.hsdeleted−15

This diff is too big to show here.

src/Language/PureScript/CoreFn/Ann.hsdeleted−37

This diff is too big to show here.

src/Language/PureScript/CoreFn/Binders.hsdeleted−42

This diff is too big to show here.

src/Language/PureScript/CoreFn/Desugar.hsdeleted−278

This diff is too big to show here.

src/Language/PureScript/CoreFn/Expr.hsdeleted−121

This diff is too big to show here.

src/Language/PureScript/CoreFn/Meta.hsdeleted−40

This diff is too big to show here.

src/Language/PureScript/CoreFn/Module.hsdeleted−31

This diff is too big to show here.

src/Language/PureScript/CoreFn/Traversals.hsdeleted−75

This diff is too big to show here.

src/Language/PureScript/Crash.hsdeleted−9

This diff is too big to show here.

src/Language/PureScript/Docs.hsdeleted−14

This diff is too big to show here.

src/Language/PureScript/Docs/AsMarkdown.hsdeleted−142

This diff is too big to show here.

src/Language/PureScript/Docs/Convert.hsdeleted−194

This diff is too big to show here.

src/Language/PureScript/Docs/Convert/ReExports.hsdeleted−475

This diff is too big to show here.

src/Language/PureScript/Docs/Convert/Single.hsdeleted−235

This diff is too big to show here.

src/Language/PureScript/Docs/ParseAndBookmark.hsdeleted−100

This diff is too big to show here.

src/Language/PureScript/Docs/Render.hsdeleted−136

This diff is too big to show here.

src/Language/PureScript/Docs/RenderedCode.hsdeleted−11

This diff is too big to show here.

src/Language/PureScript/Docs/RenderedCode/Render.hsdeleted−200

This diff is too big to show here.

src/Language/PureScript/Docs/RenderedCode/Types.hsdeleted−197

This diff is too big to show here.

src/Language/PureScript/Docs/Types.hsdeleted−590

This diff is too big to show here.

src/Language/PureScript/Docs/Utils/MonoidExtras.hsdeleted−9

This diff is too big to show here.

src/Language/PureScript/Environment.hsdeleted−274

This diff is too big to show here.

src/Language/PureScript/Errors.hsdeleted−1377

This diff is too big to show here.

src/Language/PureScript/Errors/JSON.hsdeleted−80

This diff is too big to show here.

src/Language/PureScript/Externs.hsdeleted−208

This diff is too big to show here.

src/Language/PureScript/Ide.hsdeleted−242

This diff is too big to show here.

src/Language/PureScript/Ide/CaseSplit.hsdeleted−162

This diff is too big to show here.

src/Language/PureScript/Ide/Command.hsdeleted−157

This diff is too big to show here.

src/Language/PureScript/Ide/Completion.hsdeleted−32

This diff is too big to show here.

src/Language/PureScript/Ide/Error.hsdeleted−57

This diff is too big to show here.

src/Language/PureScript/Ide/Externs.hsdeleted−114

This diff is too big to show here.

src/Language/PureScript/Ide/Filter.hsdeleted−127

This diff is too big to show here.

src/Language/PureScript/Ide/Imports.hsdeleted−355

This diff is too big to show here.

src/Language/PureScript/Ide/Matcher.hsdeleted−131

This diff is too big to show here.

src/Language/PureScript/Ide/Pursuit.hsdeleted−79

This diff is too big to show here.

src/Language/PureScript/Ide/Rebuild.hsdeleted

Binary file not shown.

src/Language/PureScript/Ide/Reexports.hsdeleted−91

This diff is too big to show here.

src/Language/PureScript/Ide/SourceFile.hsdeleted−121

This diff is too big to show here.

src/Language/PureScript/Ide/State.hsdeleted−98

This diff is too big to show here.

src/Language/PureScript/Ide/Types.hsdeleted−238

This diff is too big to show here.

src/Language/PureScript/Ide/Util.hsdeleted−65

This diff is too big to show here.

src/Language/PureScript/Ide/Watcher.hsdeleted−55

This diff is too big to show here.

src/Language/PureScript/Kinds.hsdeleted−57

This diff is too big to show here.

src/Language/PureScript/Linter.hsdeleted−114

This diff is too big to show here.

src/Language/PureScript/Linter/Exhaustive.hsdeleted−314

This diff is too big to show here.

src/Language/PureScript/Linter/Imports.hsdeleted−344

This diff is too big to show here.

src/Language/PureScript/Make.hsdeleted−475

This diff is too big to show here.

src/Language/PureScript/ModuleDependencies.hsdeleted−96

This diff is too big to show here.

src/Language/PureScript/Names.hsdeleted−143

This diff is too big to show here.

src/Language/PureScript/Options.hsdeleted−52

This diff is too big to show here.

src/Language/PureScript/Parser.hsdeleted−36

This diff is too big to show here.

src/Language/PureScript/Parser/Common.hsdeleted−122

This diff is too big to show here.

src/Language/PureScript/Parser/Declarations.hsdeleted−571

This diff is too big to show here.

src/Language/PureScript/Parser/JS.hsdeleted−60

This diff is too big to show here.

src/Language/PureScript/Parser/Kinds.hsdeleted−48

This diff is too big to show here.

src/Language/PureScript/Parser/Lexer.hsdeleted−526

This diff is too big to show here.

src/Language/PureScript/Parser/State.hsdeleted−30

This diff is too big to show here.

src/Language/PureScript/Parser/Types.hsdeleted−118

This diff is too big to show here.

src/Language/PureScript/Pretty.hsdeleted−29

This diff is too big to show here.

src/Language/PureScript/Pretty/Common.hsdeleted−167

This diff is too big to show here.

src/Language/PureScript/Pretty/Cpp.hsdeleted−540

This diff is too big to show here.

src/Language/PureScript/Pretty/JS.hsdeleted−323

This diff is too big to show here.

src/Language/PureScript/Pretty/Kinds.hsdeleted−59

This diff is too big to show here.

src/Language/PureScript/Pretty/Types.hsdeleted−151

This diff is too big to show here.

src/Language/PureScript/Pretty/Values.hsdeleted−187

This diff is too big to show here.

src/Language/PureScript/Publish.hsdeleted−402

This diff is too big to show here.

src/Language/PureScript/Publish/BoxesHelpers.hsdeleted−41

This diff is too big to show here.

src/Language/PureScript/Publish/ErrorsWarnings.hsdeleted−403

This diff is too big to show here.

src/Language/PureScript/Publish/Utils.hsdeleted−38

This diff is too big to show here.

src/Language/PureScript/Renamer.hsdeleted−197

This diff is too big to show here.

src/Language/PureScript/Sugar.hsdeleted−78

This diff is too big to show here.

src/Language/PureScript/Sugar/BindingGroups.hsdeleted−227

This diff is too big to show here.

src/Language/PureScript/Sugar/CaseDeclarations.hsdeleted−191

This diff is too big to show here.

src/Language/PureScript/Sugar/DoNotation.hsdeleted−65

This diff is too big to show here.

src/Language/PureScript/Sugar/Names.hsdeleted−413

This diff is too big to show here.

src/Language/PureScript/Sugar/Names/Env.hsdeleted−279

This diff is too big to show here.

src/Language/PureScript/Sugar/Names/Exports.hsdeleted−304

This diff is too big to show here.

src/Language/PureScript/Sugar/Names/Imports.hsdeleted−326

This diff is too big to show here.

src/Language/PureScript/Sugar/ObjectWildcards.hsdeleted−95

This diff is too big to show here.

src/Language/PureScript/Sugar/Operators.hsdeleted−332

This diff is too big to show here.

src/Language/PureScript/Sugar/Operators/Binders.hsdeleted−27

This diff is too big to show here.

src/Language/PureScript/Sugar/Operators/Common.hsdeleted−84

This diff is too big to show here.

src/Language/PureScript/Sugar/Operators/Expr.hsdeleted−48

This diff is too big to show here.

src/Language/PureScript/Sugar/Operators/Types.hsdeleted−28

This diff is too big to show here.

src/Language/PureScript/Sugar/TypeClasses.hsdeleted−334

This diff is too big to show here.

src/Language/PureScript/Sugar/TypeClasses/Deriving.hsdeleted−416

This diff is too big to show here.

src/Language/PureScript/Sugar/TypeDeclarations.hsdeleted−73

This diff is too big to show here.

src/Language/PureScript/Traversals.hsdeleted−42

This diff is too big to show here.

src/Language/PureScript/TypeChecker.hsdeleted−462

This diff is too big to show here.

src/Language/PureScript/TypeChecker/Entailment.hsdeleted−217

This diff is too big to show here.

src/Language/PureScript/TypeChecker/Kinds.hsdeleted−271

This diff is too big to show here.

src/Language/PureScript/TypeChecker/Monad.hsdeleted−253

This diff is too big to show here.

src/Language/PureScript/TypeChecker/Rows.hsdeleted−72

This diff is too big to show here.

src/Language/PureScript/TypeChecker/Skolems.hsdeleted−142

This diff is too big to show here.

src/Language/PureScript/TypeChecker/Subsumption.hsdeleted−102

This diff is too big to show here.

src/Language/PureScript/TypeChecker/Synonyms.hsdeleted−63

This diff is too big to show here.

src/Language/PureScript/TypeChecker/Types.hsdeleted−750

This diff is too big to show here.

src/Language/PureScript/TypeChecker/Unify.hsdeleted−229

This diff is too big to show here.

src/Language/PureScript/TypeClassDictionaries.hsdeleted−45

This diff is too big to show here.

src/Language/PureScript/Types.hsdeleted−336

This diff is too big to show here.

src/System/IO/UTF8.hsdeleted−25

This diff is too big to show here.

src/Tests.hsnew file+141

This diff is too big to show here.

stack-lts-5.yamldeleted−7

This diff is too big to show here.

stack-nightly.yamldeleted−6

This diff is too big to show here.

stack.nixnew file+23

This diff is too big to show here.

stack.yamlmode 120000 → 100644+24−1

This diff is too big to show here.

support/ffi-loader.gonew file+30

This diff is too big to show here.

support/go.mod.ffi-loadernew file+2

This diff is too big to show here.

support/go.mod.outputnew file+2

This diff is too big to show here.

support/go.mod.workingnew file+1

This diff is too big to show here.

test/Spec.hsnew file+2

This diff is too big to show here.

tests/Language/PureScript/Ide/FilterSpec.hsdeleted−63

This diff is too big to show here.

tests/Language/PureScript/Ide/Imports/IntegrationSpec.hsdeleted−101

This diff is too big to show here.

tests/Language/PureScript/Ide/ImportsSpec.hsdeleted−125

This diff is too big to show here.

tests/Language/PureScript/Ide/Integration.hsdeleted−252

This diff is too big to show here.

tests/Language/PureScript/Ide/MatcherSpec.hsdeleted−56

This diff is too big to show here.

tests/Language/PureScript/Ide/RebuildSpec.hsdeleted−62

This diff is too big to show here.

tests/Language/PureScript/Ide/ReexportsSpec.hsdeleted−78

This diff is too big to show here.

tests/Language/PureScript/IdeSpec.hsdeleted−35

This diff is too big to show here.

tests/Main.hsdeleted−54

This diff is too big to show here.

tests/PscIdeSpec.hsdeleted−1

This diff is too big to show here.

tests/TestCompiler.hsdeleted−194

This diff is too big to show here.

tests/TestDocs.hsdeleted−303

This diff is too big to show here.

tests/TestPscIde.hsdeleted−7

This diff is too big to show here.

tests/TestPscPublish.hsdeleted−78

This diff is too big to show here.

tests/TestPsci.hsdeleted−159

This diff is too big to show here.

tests/TestUtils.hsdeleted−65

This diff is too big to show here.

tests/support/.gitignoredeleted−2

This diff is too big to show here.

tests/support/bower.jsondeleted−11

This diff is too big to show here.

tests/support/flattened/Control-Monad-Eff-Class.pursdeleted−24

This diff is too big to show here.

tests/support/flattened/Control-Monad-Eff-Console.jsdeleted−18

This diff is too big to show here.

tests/support/flattened/Control-Monad-Eff-Console.pursdeleted−18

This diff is too big to show here.

tests/support/flattened/Control-Monad-Eff-Unsafe.jsdeleted−8

This diff is too big to show here.

tests/support/flattened/Control-Monad-Eff-Unsafe.pursdeleted−10

This diff is too big to show here.

tests/support/flattened/Control-Monad-Eff.jsdeleted−62

This diff is too big to show here.

tests/support/flattened/Control-Monad-Eff.pursdeleted−67

This diff is too big to show here.

tests/support/flattened/Control-Monad-ST.jsdeleted−38

This diff is too big to show here.

tests/support/flattened/Control-Monad-ST.pursdeleted−42

This diff is too big to show here.

tests/support/flattened/Data-Function.jsdeleted−233

This diff is too big to show here.

tests/support/flattened/Data-Function.pursdeleted−113

This diff is too big to show here.

tests/support/flattened/Prelude.jsdeleted−228

This diff is too big to show here.

tests/support/flattened/Prelude.pursdeleted−872

This diff is too big to show here.

tests/support/flattened/Test-Assert.jsdeleted−27

This diff is too big to show here.

tests/support/flattened/Test-Assert.pursdeleted−46

This diff is too big to show here.

tests/support/package.jsondeleted−7

This diff is too big to show here.

tests/support/preludedeleted−1

This diff is too big to show here.

tests/support/psci/Sample.pursdeleted

No changes to the content.

tests/support/pscide/.gitignoredeleted−7

This diff is too big to show here.

tests/support/pscide/src/ImportsSpec.pursdeleted−5

This diff is too big to show here.

tests/support/pscide/src/ImportsSpec1.pursdeleted−32

This diff is too big to show here.

tests/support/pscide/src/Main.pursdeleted−7

This diff is too big to show here.

tests/support/pscide/src/RebuildSpecDep.pursdeleted−3

This diff is too big to show here.

tests/support/pscide/src/RebuildSpecSingleModule.faildeleted−3

This diff is too big to show here.

tests/support/pscide/src/RebuildSpecSingleModule.pursdeleted−4

This diff is too big to show here.

tests/support/pscide/src/RebuildSpecWithDeps.pursdeleted−5

This diff is too big to show here.

tests/support/pscide/src/RebuildSpecWithForeign.jsdeleted−3

This diff is too big to show here.

tests/support/pscide/src/RebuildSpecWithForeign.pursdeleted−3

This diff is too big to show here.

tests/support/pscide/src/RebuildSpecWithMissingForeign.faildeleted−3

This diff is too big to show here.

tests/support/setup-win.cmddeleted−3

This diff is too big to show here.

tests/support/setup.jsdeleted−22

This diff is too big to show here.

travis/after.shdeleted−13

This diff is too big to show here.

travis/configure.shdeleted−17

This diff is too big to show here.

travis/test-install.shdeleted−18

This diff is too big to show here.