Skip to content

Commit

Permalink
Fix: inject traits in imported classes
Browse files Browse the repository at this point in the history
  • Loading branch information
albertnetymk committed Nov 23, 2015
1 parent de456b2 commit 2d928e8
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 10 deletions.
1 change: 0 additions & 1 deletion mylittlepony.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ executable encorec
, MultiParamTypeClasses
, StandaloneDeriving
, TypeSynonymInstances
, NamedFieldPuns
, FunctionalDependencies
, CPP
, ScopedTypeVariables
Expand Down
4 changes: 2 additions & 2 deletions src/back/CodeGen/Preprocessor.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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} =
Expand Down
20 changes: 19 additions & 1 deletion src/ir/AST/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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} =
Expand Down
10 changes: 4 additions & 6 deletions src/tests/encore/modules/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
10 changes: 10 additions & 0 deletions src/tests/encore/modules/trait_import.enc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import trait_import_module

class Main {
def main() : void {
print 1;
}
}

passive class Foo : Reagent {
}
1 change: 1 addition & 0 deletions src/tests/encore/modules/trait_import.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
8 changes: 8 additions & 0 deletions src/tests/encore/modules/trait_import_module.enc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
trait Reagent {
def react() : void {
();
}
}

passive class Foo2 : Reagent {
}

0 comments on commit 2d928e8

Please sign in to comment.