Skip to content

Commit d7ba043

Browse files
committed
inline native constants
1 parent a574149 commit d7ba043

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

frege/compiler/GenJava7.fr

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1743,7 +1743,10 @@ methCode g (sym@SymV {nativ = Just item}) si = [
17431743
JComment ((nice sym g) ++ " " ++ show sym.strsig ++ " " ++ show sym.rkind),
17441744
JComment (nicer sym.typ g),
17451745
JComment item] ++
1746-
(if arity > 0 then defs else [member])
1746+
(if arity > 0 then defs
1747+
else if wrapped g sym || niKind item != NIStatic
1748+
then [member]
1749+
else [])
17471750
where
17481751
rjt = tauJT g rty
17491752
rArgs = evalArgDef attrFinal si.argSigs argNames
@@ -2421,6 +2424,11 @@ instSym pos sym sigma = do
24212424
U.logmsg TRACEG pos (text ("instSym: " ++ show bind))
24222425
stio bind
24232426
SymV {name = Local {}, expr = Just _} = U.fatal sym.pos (text ("instSym: " ++ nicer sym g))
2427+
SymV {depth = 0, nativ = Just item}
2428+
| not (wrapped g sym),
2429+
niKind item == NIStatic = do
2430+
let bind = nativeCall g sym []
2431+
return model.{jex = bind.jex, jtype = wjt}
24242432
SymV {name, depth = 0, rkind} -> do
24252433
let
24262434
-- mode = jtRmode wjt

frege/compiler/tc/Methods.fr

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,13 @@ sanity SymV{pos, name, typ, nativ = Just item, pur, throwing, over}
236236
| otherwise = do
237237
g <- getST
238238
case isMutable g tau of
239-
Just (p, r) -> goodMutable g phantom p r tau >> return ()
239+
Just (p, r) -> do
240+
goodMutable g phantom p r tau
241+
case phantom of
242+
-- warn if we have a mutable result of a non-function
243+
Nothing | null args = U.warn pos (msgdoc("note that the java expression "
244+
++ item ++ " is supposed to be constant."))
245+
other = return ()
240246
Nothing -> case U.instTauSym tau g of
241247
Just SymT{nativ = Just nt, pur = pureType}
242248
| !pureType = case phantom of
@@ -390,7 +396,8 @@ sanity SymV{pos, name, typ, nativ = Just item, pur, throwing, over}
390396
++ nicer tau g ++ " is illegal, "
391397
++ "a pure native type must not be wrapped in Mutable."))
392398
return Nothing
393-
else return (Just r)
399+
else do
400+
return (Just r)
394401
| otherwise = do
395402
U.error (getpos r) (msgdoc ("The type "
396403
++ nicer tau g ++ " is illegal, "
@@ -440,7 +447,9 @@ isEither t = case Tau.flat t of
440447
[TCon{name}, a, b] | name == eitherName = Just (a, b)
441448
_ -> Nothing
442449

443-
--- check if _tau_ is (Mutable a b) and return Just (a,b) if this is so.
450+
--- > isMutable g tau
451+
--- Checks if _tau_ is @(Mutable a b)@ and return @Just (a,b)@ if this is so.
452+
--- If _tau_ is a native mutable only type, it returns @Just (RealWorld, tau)@
444453
isMutable g t = case Tau.flat t of
445454
[TCon{name}, a, b] | name == mutableName = Just (a, b)
446455
_ -> case U.instTauSym t g of

0 commit comments

Comments
 (0)