Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize the project #1

Merged
merged 15 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
eo-phi-normalizer/src/Language/EO/Phi/Syntax/* linguist-generated=true
61 changes: 61 additions & 0 deletions .github/workflows/ghc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: GHC (build, test, haddock)

# Controls when the workflow will run
on:
push:
branches: [master]
tags: [v*]
pull_request:
branches: [master]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

permissions:
contents: write # to submit Haddock documentation to GitHub Pages

jobs:
build:
name: "Build and test with GHC"
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- name: πŸ“₯ Checkout repository
uses: actions/checkout@v3

- name: 🧰 Setup Stack
uses: freckle/stack-action@v4
with:
fast: ${{ github.ref_name != 'master' }}

haddock:
needs: [build]
if: ${{ github.ref_name == 'master' }}
name: "Build and upload Haddock documentation (master)"
runs-on: ubuntu-latest

steps:
- name: πŸ“₯ Checkout repository
uses: actions/checkout@v3

- name: 🧰 Setup Stack
uses: freckle/stack-action@v4
with:
test: false

- name: πŸ”¨ Build Haddock Documentation (with Stack)
run: |
stack haddock
mkdir -p dist/haddock
mv $(stack path --local-doc-root)/* dist/haddock

- name: πŸš€ Publish Haddock Documentation
uses: JamesIves/github-pages-deploy-action@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
folder: dist/haddock
target-folder: haddock
single-commit: true
41 changes: 41 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
*.bak
eo-phi-normalizer/src/Language/EO/Phi/Syntax/Lex.hs
eo-phi-normalizer/src/Language/EO/Phi/Syntax/Par.hs
eo-phi-normalizer/src/Language/EO/Phi/Syntax/ErrM.hs
eo-phi-normalizer/src/Language/EO/Phi/Syntax/Skel.hs
eo-phi-normalizer/src/Language/EO/Phi/Syntax/Test.hs
eo-phi-normalizer/src/Language/EO/Phi/Syntax/Test
.cache/
.DS_Store
dist
dist-*
cabal-dev
build
*.o
*.hi
*.hie
*.chi
*.chs.h
*.dyn_o
*.dyn_hi
.hpc
.hsenv
.cabal-sandbox/
cabal.sandbox.config
*.prof
*.aux
*.hp
*.eventlog
.stack-work/
cabal.project.local
cabal.project.local~
.HTF/
.ghc.environment.*
docs/site
result
.direnv
venv
__pycache__
*.fdb_latexmk
*.fls
*.log
70 changes: 69 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,69 @@
Command line normalizer of πœ‘-calculus expressions.
# Normalizer for πœ‘-calculus

Command line normalizer of πœ‘-calculus expressions (as produced by the [EO compiler](https://github.com/objectionary/eo)).

## About

This project aims to apply term rewriting techniques to "simplify" an input πœ‘-expression
and prepare it for further optimization passes. The simplification procedure is expected
to be a form of partial evaluation and normalization.
Contrary to traditional normalization in Ξ»-calculus, we aim at rewriting rules that would
help reduce certain metrics of expressions. In particular, we are interested in reducing
attribute access (`t.a`) that amounts to _dynamic dispatch_.

## Usage

You can install the normalizer locally with [Stack](https://docs.haskellstack.org/en/stable/README/):

```sh
git clone https://github.com/objectionary/normalizer.git
cd normalizer
stack install
```

This should install `normalize-phi` executable (usually, to `~/.local/bin/` on Linux and macOS).
You can pass a πœ‘-program (e.g. from a file) to it:

```sh
normalize-phi < FILE
```

The output should be a πœ‘-term after normalization.

```sh
echo "{ Ο† ↦ {}, a ↦ ΞΎ.a }" | normalize-phi
```

```
{ Ο† ↦ { }, a ↦ { } }
```

## Development

The project is developed with the [Stack tool](https://docs.haskellstack.org/en/stable/README/).

For quick local development and testing it is recommended to use `stack`. Clone this project and run `stack build`:

```sh
git clone https://github.com/objectionary/normalizer.git
cd normalizer
stack build
```

The build provides an executable `normalize-phi` which can be used to normalize input expressions:

```sh
stack exec -- normalize-phi < FILE
```

You can also build and run the (default) executable using `stack run`:

```sh
stack run < FILE
```

To run (all) tests, simply use

```sh
stack test
```
2 changes: 2 additions & 0 deletions eo-phi-normalizer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.stack-work/
*~
11 changes: 11 additions & 0 deletions eo-phi-normalizer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Changelog for `eo-phi-normalizer`

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to the
[Haskell Package Versioning Policy](https://pvp.haskell.org/).

## Unreleased

## 0.1.0.0 - YYYY-MM-DD
30 changes: 30 additions & 0 deletions eo-phi-normalizer/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Copyright EO/Polystat Development Team (c) 2023

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

* Neither the name of EO/Polystat Development Team nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

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.
1 change: 1 addition & 0 deletions eo-phi-normalizer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# eo-phi-normalizer
32 changes: 32 additions & 0 deletions eo-phi-normalizer/Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{-# LANGUAGE CPP #-}
-- Source: https://github.com/haskell/cabal/issues/6726#issuecomment-918663262

-- | Custom Setup that runs bnfc to generate the language sub-libraries
-- for the parsers included in Ogma.
module Main (main) where

import Distribution.Simple (defaultMainWithHooks,
hookedPrograms, postConf,
preBuild, simpleUserHooks)
import Distribution.Simple.Program (Program (..), findProgramVersion,
simpleProgram)
import System.Process (system)

-- | Run BNFC on the grammar before the actual build step.
--
-- All options for bnfc are hard-coded here.
main :: IO ()
main = defaultMainWithHooks $ simpleUserHooks
{ hookedPrograms = [ bnfcProgram ]
, postConf = \args flags packageDesc localBuildInfo -> do
#ifndef mingw32_HOST_OS
_ <- system "bnfc -d -p Language.EO.Phi --generic -o src/ grammar/EO/Phi/Syntax.cf"
#endif
postConf simpleUserHooks args flags packageDesc localBuildInfo
}

-- | TODO: This should be in Cabal.Distribution.Simple.Program.Builtin.
bnfcProgram :: Program
bnfcProgram = (simpleProgram "bnfc")
{ programFindVersion = findProgramVersion "--version" id
}
6 changes: 6 additions & 0 deletions eo-phi-normalizer/app/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Main (main) where

import Language.EO.Phi

main :: IO ()
main = defaultMain
113 changes: 113 additions & 0 deletions eo-phi-normalizer/eo-phi-normalizer.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
cabal-version: 2.2

-- This file has been generated from package.yaml by hpack version 0.36.0.
--
-- see: https://github.com/sol/hpack

name: eo-phi-normalizer
version: 0.1.0
description: Please see the README on GitHub at <https://github.com/objectionary/eo-phi-normalizer#readme>
homepage: https://github.com/objectionary/eo-phi-normalizer#readme
bug-reports: https://github.com/objectionary/eo-phi-normalizer/issues
author: EO/Polystat Development Team
maintainer: [email protected]
copyright: 2023 EO/Polystat Development Team
license: BSD-3-Clause
license-file: LICENSE
build-type: Custom
extra-source-files:
README.md
CHANGELOG.md
grammar/EO/Phi/Syntax.cf

source-repository head
type: git
location: https://github.com/objectionary/eo-phi-normalizer

custom-setup
setup-depends:
Cabal >=2.4.0.1 && <4.0
, base >=4.11.0.0 && <5.0
, process >=1.6.3.0

library
exposed-modules:
Language.EO.Phi
Language.EO.Phi.Normalize
Language.EO.Phi.Syntax.Abs
Language.EO.Phi.Syntax.Lex
Language.EO.Phi.Syntax.Par
Language.EO.Phi.Syntax.Print
other-modules:
Paths_eo_phi_normalizer
autogen-modules:
Paths_eo_phi_normalizer
hs-source-dirs:
src
ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -Wno-missing-export-lists
build-tools:
alex >=3.2.4
, happy >=1.19.9
build-tool-depends:
BNFC:bnfc >=2.9.4.1
build-depends:
aeson
, array >=0.5.5.0
, base >=4.7 && <5
, directory
, filepath
, yaml
default-language: Haskell2010

executable normalize-phi
main-is: Main.hs
other-modules:
Paths_eo_phi_normalizer
autogen-modules:
Paths_eo_phi_normalizer
hs-source-dirs:
app
ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -Wno-missing-export-lists -threaded -rtsopts -with-rtsopts=-N
build-tools:
alex >=3.2.4
, happy >=1.19.9
build-tool-depends:
BNFC:bnfc >=2.9.4.1
build-depends:
aeson
, array >=0.5.5.0
, base >=4.7 && <5
, directory
, eo-phi-normalizer
, filepath
, yaml
default-language: Haskell2010

test-suite eo-phi-normalizer-test
type: exitcode-stdio-1.0
main-is: Spec.hs
other-modules:
Language.EO.PhiSpec
Test.EO.Phi
Paths_eo_phi_normalizer
autogen-modules:
Paths_eo_phi_normalizer
hs-source-dirs:
test
ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -Wno-missing-export-lists -threaded -rtsopts -with-rtsopts=-N
build-tools:
alex >=3.2.4
, happy >=1.19.9
build-tool-depends:
BNFC:bnfc >=2.9.4.1
build-depends:
aeson
, array >=0.5.5.0
, base >=4.7 && <5
, directory
, eo-phi-normalizer
, filepath
, hspec
, hspec-discover
, yaml
default-language: Haskell2010
Loading