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

Moved qualified name detection from Types to Kinds #1960

Merged
merged 1 commit into from
Oct 23, 2024
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
6 changes: 4 additions & 2 deletions compiler/Acton/CodeGen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,13 @@ methodtable env n = gen env (tableName $ gname env n)
staticwitness env n = gen env (witName n)

methodtable' env (NoQ n) = methodtable env n
methodtable' env n = gen env $ tableName n
methodtable' env n = gen env $ tableName (unalias env n)

tableName (GName m n) = GName m (Derived n suffixMethods)
tableName n = error ("#### tableName " ++ show n)

witName (GName m n) = GName m (Derived n suffixWitness)
witName n = error ("witName " ++ show n)
witName n = error ("#### witName " ++ show n)

newcon env n = gen env (conName $ gname env n)

Expand Down
9 changes: 8 additions & 1 deletion compiler/Acton/Kinds.hs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,9 @@ instance KCheck Expr where
kchk env (BinOp l e1 op e2) = BinOp l <$> kchk env e1 <*> return op <*> kchk env e2
kchk env (CompOp l e ops) = CompOp l <$> kchk env e <*> kchk env ops
kchk env (UnOp l op e) = UnOp l op <$> kchk env e
kchk env (Dot l e n) = Dot l <$> kchk env e <*> return n
kchk env (Dot l e n)
| Just m <- isModule env e = return $ Var l (QName m n)
| otherwise = Dot l <$> kchk env e <*> return n
kchk env (Rest l e n) = Rest l <$> kchk env e <*> return n
kchk env (DotI l e i) = DotI l <$> kchk env e <*> return i
kchk env (RestI l e i) = RestI l <$> kchk env e <*> return i
Expand All @@ -367,6 +369,11 @@ instance KCheck Expr where
kchk env (SetComp l e c) = SetComp l <$> kchk env e <*> kchk env c
kchk env (Paren l e) = Paren l <$> kchk env e

isModule env e = fmap ModName $ mfilter (isMod env) $ fmap reverse $ dotChain e
where dotChain (Var _ (NoQ n)) = Just [n]
dotChain (Dot _ e n) = fmap (n:) (dotChain e)
dotChain _ = Nothing

instance KCheck Pattern where
kchk env (PWild l t) = PWild l <$> (kexp KType env =<< maybeConvTWild t)
kchk env (PVar l n t) = PVar l n <$> (kexp KType env =<< maybeConvTWild t)
Expand Down
8 changes: 0 additions & 8 deletions compiler/Acton/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1232,9 +1232,6 @@ instance Infer Expr where
method NotIn = containsnotKW
infer env (CompOp l e1 ops) = notYet l "Comparison chaining"

infer env d@(Dot l e n)
| Just m <- isModule env e = infer env (Var l (QName m n))

infer env (Dot l x@(Var _ c) n)
| NClass q us te <- cinfo = do (cs0,ts) <- instQBinds env q
let tc = TC c' ts
Expand Down Expand Up @@ -1413,11 +1410,6 @@ tupleTemplate i = do ts <- mapM (const newTVar) [0..i]
p1 = foldl (flip posRow) p (tail ts)
return (TTuple NoLoc p0 k, head ts, TTuple NoLoc p1 k)

isModule env e = fmap ModName $ mfilter (isMod env) $ fmap reverse $ dotChain e
where dotChain (Var _ (NoQ n)) = Just [n]
dotChain (Dot _ e n) = fmap (n:) (dotChain e)
dotChain _ = Nothing


infElems env [] t0 = return ([], [])
infElems env (Elem e : es) t0 = do (cs1,e') <- inferSub env t0 e
Expand Down
4 changes: 4 additions & 0 deletions compiler/test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ compilerTests =
(returnCode, cmdOut, cmdErr) <- readCreateProcessWithExitCode (shell $ "rm -rf ../test/compiler/rebuild-import/out") ""
testBuild "" ExitSuccess False "../test/compiler/rebuild-import/"
testBuild "" ExitSuccess False "../test/compiler/rebuild-import/"
, testCase "mixed dots in qualified name" $ do
(returnCode, cmdOut, cmdErr) <- readCreateProcessWithExitCode (shell $ "rm -rf ../test/compiler/mixed-dots/out") ""
testBuild "" ExitSuccess False "../test/compiler/mixed-dots/"
testBuild "" ExitSuccess False "../test/compiler/mixed-dots/"
, testCase "sub-modules and dashes" $ do
(returnCode, cmdOut, cmdErr) <- readCreateProcessWithExitCode (shell $ "rm -rf ../test/compiler/subdash/out") ""
testBuild "" ExitSuccess False "../test/compiler/subdash/"
Expand Down
Empty file.
12 changes: 12 additions & 0 deletions test/compiler/mixed-dots/README.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
* rebuild
rebuild is a cool Acton project!

** Compile
#+BEGIN_SRC shell
actonc build
#+END_SRC

** Run
#+BEGIN_SRC shell
out/bin/rebuild
#+END_SRC
7 changes: 7 additions & 0 deletions test/compiler/mixed-dots/src/foo.act
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Foo(object):
def __init__(self):
pass

@staticmethod
def new():
return Foo()
5 changes: 5 additions & 0 deletions test/compiler/mixed-dots/src/main.act
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import foo

actor main(env):
f = foo.Foo.new()
env.exit(0)
Loading