diff --git a/mylittlepony.cabal b/mylittlepony.cabal index 390f55657..b9e107b71 100644 --- a/mylittlepony.cabal +++ b/mylittlepony.cabal @@ -26,7 +26,6 @@ executable encorec , MultiParamTypeClasses , StandaloneDeriving , TypeSynonymInstances - , NamedFieldPuns , FunctionalDependencies , CPP , ScopedTypeVariables diff --git a/src/back/CodeGen/Preprocessor.hs b/src/back/CodeGen/Preprocessor.hs index 2dd4609e2..da660a3f9 100644 --- a/src/back/CodeGen/Preprocessor.hs +++ b/src/back/CodeGen/Preprocessor.hs @@ -13,8 +13,8 @@ preprocess :: A.Program -> A.Program preprocess = injectTraitsToClasses . giveClosuresUniqueNames injectTraitsToClasses :: A.Program -> A.Program -injectTraitsToClasses p@A.Program{A.classes} = - p{A.classes = map injectTraitsToClass classes} +injectTraitsToClasses p = + Util.mapProgramClass p injectTraitsToClass where injectTraitsToClass :: A.ClassDecl -> A.ClassDecl injectTraitsToClass c@A.Class{A.cname, A.ccapability} = diff --git a/src/ir/AST/Util.hs b/src/ir/AST/Util.hs index e1a58014e..7b07201ef 100644 --- a/src/ir/AST/Util.hs +++ b/src/ir/AST/Util.hs @@ -4,7 +4,17 @@ {-| Utility functions for "AST.AST". -} -module AST.Util(foldr, foldrAll, filter, extend, extendAccum, extendAccumProgram, extractTypes, freeVariables) where +module AST.Util( + foldr + , foldrAll + , filter + , extend + , extendAccum + , extendAccumProgram + , extractTypes + , freeVariables + , mapProgramClass + ) where import qualified Data.List as List import Prelude hiding (foldr, filter) @@ -229,6 +239,14 @@ extendAccum f acc0 e = in f acc1 (putChildren childResults e) +mapProgramClass :: Program -> (ClassDecl -> ClassDecl) -> Program +mapProgramClass p@Program{classes, imports} f = + p{classes = map f classes, imports = map i2i imports} + where + i2i i@PulledImport{iprogram} = i{iprogram = p2p iprogram} + i2i _ = error "Non desugared imports" + p2p p@Program{classes} = p{classes = map f classes} + extendAccumProgram :: (acc -> Expr -> (acc, Expr)) -> acc -> Program -> (acc, Program) extendAccumProgram f acc0 p@Program{functions, traits, classes} = diff --git a/src/tests/encore/modules/Makefile b/src/tests/encore/modules/Makefile index 8cceeacaf..f7326a380 100644 --- a/src/tests/encore/modules/Makefile +++ b/src/tests/encore/modules/Makefile @@ -3,20 +3,18 @@ ENCOREC=$(ROOT_PATH)/release/encorec #INGORE=Lib.enc -#OUTFILES=$(shell ls *.out) -OUTFILES=Importer.out DeepImporter.out FarImporter.out DupImporter.out Qualified.out \ - VectorTest.out CallImported.out StdLib.out PassiveImport.out - #ENCORE_SOURCES=$(shell ls *.enc) ENCORE_SOURCES=Importer.enc DeepImporter.enc FarImporter.enc DupImporter.enc Qualified.enc \ VectorTest.enc CallImported.enc StdLib.enc PassiveImport.enc +ENCORE_SOURCES += trait_import.enc + ENCORE_TARGETS=$(ENCORE_SOURCES:.enc=) #test: embed_tl.o test: - @$(foreach PROG,$(ENCORE_TARGETS), make -Bqk $(PROG) || make -Bk $(PROG) || true;) - @echo + @$(foreach PROG,$(ENCORE_TARGETS), make -Bqk $(PROG) || make -Bk $(PROG) || true;) + @echo @echo Module tests: @./test.sh $(ENCORE_TARGETS) diff --git a/src/tests/encore/modules/trait_import.enc b/src/tests/encore/modules/trait_import.enc new file mode 100644 index 000000000..7bad7675e --- /dev/null +++ b/src/tests/encore/modules/trait_import.enc @@ -0,0 +1,10 @@ +import trait_import_module + +class Main { + def main() : void { + print 1; + } +} + +passive class Foo : Reagent { +} diff --git a/src/tests/encore/modules/trait_import.out b/src/tests/encore/modules/trait_import.out new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/src/tests/encore/modules/trait_import.out @@ -0,0 +1 @@ +1 diff --git a/src/tests/encore/modules/trait_import_module.enc b/src/tests/encore/modules/trait_import_module.enc new file mode 100644 index 000000000..3807acabb --- /dev/null +++ b/src/tests/encore/modules/trait_import_module.enc @@ -0,0 +1,8 @@ +trait Reagent { + def react() : void { + (); + } +} + +passive class Foo2 : Reagent { +}