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

Implement alignof (fixes #1) #8

Merged
merged 1 commit into from Jun 16, 2016
File filter...
Filter file types
Jump to file or symbol
Failed to load files and symbols.
+12 −0
Diff settings

Always

Just for now

Implement alignof (fixes #1)

  • Loading branch information...
jjst committed Jun 16, 2016
commit 8530fac1f8bd59da8d342490829bd13be95d909f
Copy path View file
@@ -319,6 +319,18 @@ interpretExpr _ (CSizeofType (CDecl spec declarators _) _) = do
, isMutable = Rust.Immutable
, result = Rust.Call (Rust.Var (Rust.VarName ("std::mem::size_of::<" ++ ty' ++ ">"))) []
}
interpretExpr _ (CAlignofType (CDecl spec declarators _) _) = do
let ([], [], typequals, typespecs, False) = partitionDeclSpecs spec
(_mut, ty) <- cTypeOf typequals typespecs $ case declarators of
[] -> []
[(Just (CDeclr Nothing derived _ _ _), Nothing, Nothing)] -> derived
_ -> error ("interpretExpr: invalid alignof type " ++ show declarators)
let Rust.TypeName ty' = toRustType ty
return Result
{ resultType = IsInt Unsigned WordWidth
, isMutable = Rust.Immutable
, result = Rust.Call (Rust.Var (Rust.VarName ("std::mem::align_of::<" ++ ty' ++ ">"))) []
}
interpretExpr _ (CCall func args _) = do
Result { resultType = IsFunc retTy argTys, result = func' } <- interpretExpr True func
args' <- zipWithM (\ ty arg -> fmap (castTo ty) (interpretExpr True arg)) argTys args
ProTip! Use n and p to navigate between commits in a pull request.