Skip to content

Commit

Permalink
Closes #276 macro plugins (#331)
Browse files Browse the repository at this point in the history
* Plugin tests work

* Macro system working

* Plugins solved in core

* Plugins done in elchemy-core

* resolve full functions arity

* Better vars in meta and mod when crashing

* core

* core change

* core change test

* fix test of test-project

* better .gitignore

* better .gitignore in core

* fix bump

* 0.7.0-0

* 0.7.0-0 / 2018-05-11
================

  * fix bump
  * better .gitignore in core
  * better .gitignore
  * fix test of test-project
  * core change test
  * core change
  * core
  * Better vars in meta and mod when crashing
  * resolve full functions arity
  * Plugins done in elchemy-core
  * Plugins solved in core
  * Macro system working
  * Plugin tests work

* release from wherever

* 0.7.0-1

* 0.7.0-2

* 0.7.0-2 / 2018-05-11
================

  * 0.7.0-1
  * release from wherever

* Proper dev release

* remove docs

* Core update to 7.0.1

* 0.7.0

* 0.7.0 / 2018-05-14
================

  * Core update to 7.0.1
  * remove docs
  * Proper dev release

* remove docs

* Configurable elchemy path exec for dev mode

* strip meta as a helper in core

* 0.7.1

* 0.7.1 / 2018-05-15
================

* remove docs

* Remove restore docs
  • Loading branch information
wende authored May 16, 2018
1 parent 9184d75 commit 0c971f3
Show file tree
Hide file tree
Showing 24 changed files with 658 additions and 284 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ example/
stable/
_book/
.elixir_ls/
.vscode/
test_project/
23 changes: 19 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,38 @@ test-all:
make test
make test-std
make compile-elixir # Change to compile-elixir-and-test when let..in fixed completely
make test-project

test-project:
rm -rf test_project
mix new test_project
cd test_project && (yes | ../elchemy init) && ../elchemy compile elm lib && cp -r ../elchemy-core/lib lib/elm-deps && mix test

cd test_project ; \
(yes | ../elchemy init) ;\
../elchemy compile elm lib ;\
cp -r ../elchemy-core/lib lib/elm-deps ;\
cp -r ../elchemy-core/elm lib/elm-deps-elixir-files ;\
mix test

test-std:
cd elchemy-core/ && rm -rf .elchemy && mix test
cd elchemy-core/ && mix test

compile-std:
cd elchemy-core && rm -rf .elchemy
make compile-std-incremental

compile-std-incremental:
make compile
cd elchemy-core && rm -rf .elchemy && ../elchemy compile elm lib
cd elchemy-core && ../elchemy compile elm lib

compile-std-watch:
find elchemy-core -name "*.elm" | grep -v ".#" | grep -v "elm-stuff" | entr make compile-std

compile-std-tests-watch:
find elchemy-core \( -name "*.elm" -or -name '*.ex*' \) | grep -v "elchemy.ex" | grep -v ".#" | grep -v "elm-stuff" | entr bash -c "make compile && make compile-std && make test-std"

compile-incremental-std-tests-watch:
find elchemy-core \( -name "*.elm" -or -name '*.ex*' \) | grep -v "elchemy.ex" | grep -v ".#" | grep -v "elm-stuff" | entr bash -c "make compile && make compile-std-incremental && make test-std"

tests-watch:
find . -name "*.elm" | grep -v ".#" | grep -v "elm-stuff" | entr ./node_modules/.bin/elm-test

Expand Down
15 changes: 10 additions & 5 deletions bump.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,34 @@ fi
if git diff-index --quiet HEAD --; then
CHANGELOG=`git changelog -x --tag VER`
npm version $1
SEMVER='[0-9][0-9]*\.[0-9][0-9]*\.[0-9]*'
SEMVER='[0-9][0-9]*\.[0-9][0-9]*\.[0-9]*-*[0-9]*'
VER=`npm ls | grep -o elchemy@$SEMVER | grep -o $SEMVER`
CHANGELOG=${CHANGELOG/VER/$VER}
echo "$CHANGELOG"

make compile-std

cd elchemy-core

CORE_BRANCH=`git branch | grep \* | cut -d ' ' -f2`
sed -i "" "s/$SEMVER/$VER/g" mix.exs
git pull origin master
git pull origin $CORE_BRANCH
git commit -am "Release $VER"
git tag $VER

if ! [[ $* == *-n* ]]; then
git push origin master $VER
git push origin $CORE_BRANCH $VER
fi

cd ..

ELCHEMY_BRANCH=`git branch | grep \* | cut -d ' ' -f2`
sed -i "" "s/$SEMVER/$VER/g" mix.exs
rm -f elchemy-*.ez
mix archive.build
mix archive.install "elchemy-$VER.ez" --force

git pull origin master
git pull origin $ELCHEMY_BRANCH
sed -i "" "s/$SEMVER/$VER/g" src/Compiler.elm
make compile
make build-docs
Expand All @@ -48,7 +53,7 @@ if git diff-index --quiet HEAD --; then
git commit -am "$CHANGELOG"
git tag $VER
if ! [[ $* == *-n* ]]; then
git push origin master $VER
git push origin $ELCHEMY_BRANCH $VER
hub release create -p -a "elchemy-$VER.ez" $VER
fi
else
Expand Down
2 changes: 1 addition & 1 deletion elchemy
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash


version="0.6.6"
version="0.7.1"
set -e

VERBOSE=false
Expand Down
7 changes: 4 additions & 3 deletions lib/mix/tasks/compile.elchemy.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ defmodule Mix.Tasks.Compile.Elchemy do
project = Mix.Project.config
src = project[:elchemy_path]
dests = project[:elixirc_paths] || ["lib"]
elchemy_executable = project[:elchemy_executable] || "elchemy"

# Crash if elchemy not found globally
unless 0 == Mix.shell.cmd("which elchemy") do
Mix.raise "Elchemy not installed globally. You need to run `npm install elchemy -g`"
unless 0 == Mix.shell.cmd("which #{elchemy_executable}") do
Mix.raise "Elchemy not found under #{elchemy_executable}. You might need to run `npm install elchemy -g`"
end

# Crash if elchemy not found globally
unless dests, do: IO.warn "No 'elixirc_paths' setting found"
if src && dests do
[dest | _] = dests
unless 0 == Mix.shell.cmd("elchemy compile #{src} #{dest}") do
unless 0 == Mix.shell.cmd("#{elchemy_executable} compile #{src} #{dest}") do
Mix.raise "Elchemy failed the compilation with an error\n"
end
end
Expand Down
34 changes: 0 additions & 34 deletions lib/mix/tasks/elchemy.ex

This file was deleted.

11 changes: 1 addition & 10 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule Elchemy.Mixfile do
[app: :elchemy,
name: "Elchemy Compiler",
description: "Mix compiler wrapper around Elchemy project",
version: "0.6.6",
version: "0.7.1",
elixir: "~> 1.4",
description: "",
package: package(),
Expand Down Expand Up @@ -33,15 +33,6 @@ defmodule Elchemy.Mixfile do
[extra_applications: [:logger]]
end

# Dependencies can be Hex packages:
#
# {:my_dep, "~> 0.6.6"}
#
# Or git/path repositories:
#
# {:my_dep, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.6.6"}
#
# Type "mix help deps" for more examples and options
defp deps do
[]
end
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "elchemy",
"version": "0.6.6",
"version": "0.7.1",
"description": "Write Elixir code using Elm-inspired syntax (elm-make compatible)",
"directories": {
"example": "example",
Expand Down
12 changes: 8 additions & 4 deletions src/Compiler.elm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Compiler exposing (version, tree)
-}

import Ast
import ExMeta
import ExAlias
import ExStatement
import Dict exposing (Dict)
Expand All @@ -20,7 +21,7 @@ import Regex exposing (Regex, HowMany(..), regex)
-}
version : String
version =
"0.6.6"
"0.7.1"


glueStart : String
Expand Down Expand Up @@ -189,17 +190,20 @@ getCode context statements =
let
shadowsBasics =
ExContext.importBasicsWithoutShadowed context

( newC, code ) =
List.foldl aggregateStatements ( context, "" ) statements
in
("# Compiled using Elchemy v" ++ version)
++ "\n"
++ ("defmodule " ++ context.mod ++ " do")
++ glueStart
++ (ind context.indent)
++ shadowsBasics
++ ((List.foldl (aggregateStatements) ( context, "" ) statements)
|> Tuple.second
)
++ code
++ glueEnd
++ ExMeta.metaDefinition { newC | inMeta = True }
++ "\n\n"


parse : String -> String -> List Statement
Expand Down
22 changes: 11 additions & 11 deletions src/ExAlias.elm
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ registerAlias s c =
c


resolveTypeBody : TypeBody -> List Type -> Type
resolveTypeBody typeBody givenArgs =
resolveTypeBody : Context -> TypeBody -> List Type -> Type
resolveTypeBody c typeBody givenArgs =
case typeBody of
SimpleType t ->
t
Expand All @@ -50,9 +50,9 @@ resolveTypeBody typeBody givenArgs =
List.length expectedArgs
in
if arity == expected then
resolveTypes expectedArgs givenArgs return
resolveTypes c expectedArgs givenArgs return
else
wrongArityAlias expected givenArgs name
wrongArityAlias c expected givenArgs name


registerTypeAlias : Context -> Type -> Type -> Context
Expand All @@ -72,7 +72,7 @@ registerTypeAlias c tc t =
ExContext.addAlias c.mod name ali c

ts ->
Debug.crash <| "Wrong type alias declaration " ++ toString ts
ExContext.crash c <| "Wrong type alias declaration " ++ toString ts


registerUnionType : Context -> Type -> List Type -> Context
Expand All @@ -95,7 +95,7 @@ registerUnionType c tc types =
ExContext.addAlias c.mod name ali newC

ts ->
Debug.crash <| "Wrong type declaration " ++ toString ts
ExContext.crash c <| "Wrong type declaration " ++ toString ts


registerFunctionDefinition : Context -> String -> Type -> Context
Expand All @@ -119,7 +119,7 @@ registerTypes types parentAlias c =
=> ExContext.addType c.mod parentAlias name (List.length args) context

any ->
Debug.crash "Type can only start with a tag"
ExContext.crash c "Type can only start with a tag"
in
List.foldl addType ( [], c ) types

Expand All @@ -132,7 +132,7 @@ replaceTypeAliases c t =
mapOrFunUpdate mod default typeName args =
ExContext.getAlias mod typeName c
|> Helpers.filterMaybe (.aliasType >> (==) ExContext.TypeAlias)
|> Maybe.map (\{ typeBody } -> resolveTypeBody typeBody args)
|> Maybe.map (\{ typeBody } -> resolveTypeBody c typeBody args)
|> Maybe.andThen
(\body ->
case body of
Expand Down Expand Up @@ -162,16 +162,16 @@ replaceTypeAliases c t =
ExAst.walkTypeOutwards replaceAlias t


resolveTypes : List Type -> List Type -> Type -> Type
resolveTypes expected given return =
resolveTypes : Context -> List Type -> List Type -> Type -> Type
resolveTypes c expected given return =
let
expectedName n =
case n of
TypeVariable name ->
name

other ->
Debug.crash <|
ExContext.crash c <|
"type can only take variables. "
++ toString other
++ "is incorrect"
Expand Down
Loading

0 comments on commit 0c971f3

Please sign in to comment.