Skip to content

Commit bf10614

Browse files
author
Stephan Brandauer
committed
Coding Conventions
This commit expands the coding conventions and implements part of them for the whole code base.
1 parent f36de95 commit bf10614

29 files changed

+1342
-1311
lines changed

CONTRIBUTING.md

+35-11
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,38 @@ If you submit a pull request without tests, to a project with tests, you're
7171
guaranteed to get a grumpy project maintainer telling you to go away and write
7272
some.
7373

74-
### Respect conventions
75-
76-
You might love tabs in your source code. You might
77-
really, really love them. But if re submitting a pull request to a project that
78-
uses spaces, you're going have to suck it up and use them.
79-
80-
Aside from coding style, projects might have more subtle conventions that it
81-
makes sense to follow. Perhaps private functions never have docstrings, or
82-
perhaps commit messages are always written in the imperative, present tense. Try
83-
to ensure your contributions to the project don't stand out as
84-
unusual.
74+
### Code formatting
75+
76+
We have not been enforcing any rules before, but we are now. All new
77+
Haskell code has to adhere to these conventions. No excuses.
78+
79+
- No snake cases anywhere. We use camel case.
80+
- Type signatures on top level functions.
81+
- We strongly recommend using `hlint`, but without the "Eta reduce" warning (run `hlint --ignore="Eta reduce" File.hs`).
82+
83+
#### Indentation
84+
85+
##### Bad
86+
```
87+
foo = do ..
88+
..
89+
return ()
90+
```
91+
##### Good
92+
93+
```
94+
foo = do
95+
..
96+
..
97+
return ()
98+
```
99+
100+
##### Rationale
101+
102+
If the name of the function changes, in the bad version you need to
103+
change all code in the body, too. This hides who has actually written
104+
the code (and why). *This also holds for `case` expressions (do a line
105+
break after `of`) and `if-then-else`.* When implementing a function,
106+
the same might apply: starting the implementation in the same line
107+
might cause git history problems. However, for functions, this choice
108+
remains up to the programmer.

src/back/CCode/Main.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{-# LANGUAGE GADTs,FlexibleInstances,FlexibleContexts,MultiParamTypeClasses,StandaloneDeriving #-}
1+
{-# LANGUAGE FlexibleInstances,FlexibleContexts,MultiParamTypeClasses,StandaloneDeriving #-}
22

33
{-| Provides the CCode data type, a representation of C
44
programs that can be pretty-printed to sometimes-legal C code. The

src/back/CodeGen/CCodeNames.hs

+125-125
Original file line numberDiff line numberDiff line change
@@ -36,35 +36,35 @@ double = Typ "double"
3636
void :: CCode Ty
3737
void = Typ "void"
3838

39-
encore_actor_t :: CCode Ty
40-
encore_actor_t = Typ "encore_actor_t"
39+
encoreActorT :: CCode Ty
40+
encoreActorT = Typ "encore_actor_t"
4141

42-
pony_type_t :: CCode Ty
43-
pony_type_t = Typ "pony_type_t"
42+
ponyTypeT :: CCode Ty
43+
ponyTypeT = Typ "pony_type_t"
4444

45-
pony_actor_t :: CCode Ty
46-
pony_actor_t = Typ "pony_actor_t"
45+
ponyActorT :: CCode Ty
46+
ponyActorT = Typ "pony_actor_t"
4747

48-
pony_actor_type_t :: CCode Ty
49-
pony_actor_type_t = Typ "pony_actor_type_t"
48+
ponyActorTypeT :: CCode Ty
49+
ponyActorTypeT = Typ "pony_actor_type_t"
5050

51-
encore_arg_t :: CCode Ty
52-
encore_arg_t = Typ "encore_arg_t"
51+
encoreArgT :: CCode Ty
52+
encoreArgT = Typ "encore_arg_t"
5353

54-
is_encore_arg_t :: CCode Ty -> Bool
55-
is_encore_arg_t (Typ "encore_arg_t") = True
56-
is_encore_arg_t _ = False
54+
isEncoreArgT :: CCode Ty -> Bool
55+
isEncoreArgT (Typ "encore_arg_t") = True
56+
isEncoreArgT _ = False
5757

58-
pony_msg_t :: CCode Ty
59-
pony_msg_t = Typ "pony_msg_t"
58+
ponyMsgT :: CCode Ty
59+
ponyMsgT = Typ "pony_msg_t"
6060

61-
enc_msg_t :: CCode Ty
62-
enc_msg_t = Typ "encore_fut_msg_t"
61+
encMsgT :: CCode Ty
62+
encMsgT = Typ "encore_fut_msg_t"
6363

64-
task_msg_t = Typ "encore_task_msg_s"
64+
taskMsgT = Typ "encore_task_msg_s"
6565

66-
enc_oneway_msg_t :: CCode Ty
67-
enc_oneway_msg_t = Typ "encore_oneway_msg_t"
66+
encOnewayMsgT :: CCode Ty
67+
encOnewayMsgT = Typ "encore_oneway_msg_t"
6868

6969
closure :: CCode Ty
7070
closure = Ptr $ Typ "closure_t"
@@ -81,170 +81,170 @@ stream = Ptr $ Typ "stream_t"
8181
array :: CCode Ty
8282
array = Ptr $ Typ "array_t"
8383

84-
range_t :: CCode Ty
85-
range_t = Typ "range_t"
84+
rangeT :: CCode Ty
85+
rangeT = Typ "range_t"
8686

8787
range :: CCode Ty
88-
range = Ptr $ range_t
88+
range = Ptr $ rangeT
8989

9090
option :: CCode Ty
9191
option = Ptr $ Typ "option_t"
9292

9393
unit :: CCode Lval
9494
unit = Embed "UNIT"
9595

96-
encore_name :: String -> String -> String
97-
encore_name kind name =
96+
encoreName :: String -> String -> String
97+
encoreName kind name =
9898
let
99-
non_emptys = filter (not . null) ["_enc_", kind, name]
99+
nonEmptys = filter (not . null) ["_enc_", kind, name]
100100
in
101-
concat $ intersperse "_" non_emptys
101+
concat $ intersperse "_" nonEmptys
102102

103-
self_type_field :: CCode Name
104-
self_type_field = Nam $ encore_name "self_type" ""
103+
selfTypeField :: CCode Name
104+
selfTypeField = Nam $ encoreName "self_type" ""
105105

106106
-- | each method is implemented as a function with a `this`
107107
-- pointer. This is the name of that function
108-
method_impl_name :: Ty.Type -> ID.Name -> CCode Name
109-
method_impl_name clazz mname =
110-
Nam $ encore_name "method" $ (Ty.getId clazz) ++ "_" ++ (show mname)
108+
methodImplName :: Ty.Type -> ID.Name -> CCode Name
109+
methodImplName clazz mname =
110+
Nam $ encoreName "method" $ (Ty.getId clazz) ++ "_" ++ (show mname)
111111

112-
arg_name :: ID.Name -> CCode Lval
113-
arg_name name =
114-
Var $ encore_name "arg" (show name)
112+
argName :: ID.Name -> CCode Lval
113+
argName name =
114+
Var $ encoreName "arg" (show name)
115115

116-
field_name :: ID.Name -> CCode Name
117-
field_name name =
118-
Nam $ encore_name "field" (show name)
116+
fieldName :: ID.Name -> CCode Name
117+
fieldName name =
118+
Nam $ encoreName "field" (show name)
119119

120-
global_closure_name :: ID.Name -> CCode Name
121-
global_closure_name funname =
122-
Nam $ encore_name "closure" (show funname)
120+
globalClosureName :: ID.Name -> CCode Name
121+
globalClosureName funname =
122+
Nam $ encoreName "closure" (show funname)
123123

124-
global_function_name :: ID.Name -> CCode Name
125-
global_function_name funname =
126-
Nam $ encore_name "global_fun" (show funname)
124+
globalFunctionName :: ID.Name -> CCode Name
125+
globalFunctionName funname =
126+
Nam $ encoreName "global_fun" (show funname)
127127

128-
closure_fun_name :: String -> CCode Name
129-
closure_fun_name name =
130-
Nam $ encore_name "closure_fun" name
128+
closureFunName :: String -> CCode Name
129+
closureFunName name =
130+
Nam $ encoreName "closure_fun" name
131131

132-
closure_env_name :: String -> CCode Name
133-
closure_env_name name =
134-
Nam $ encore_name "env" name
132+
closureEnvName :: String -> CCode Name
133+
closureEnvName name =
134+
Nam $ encoreName "env" name
135135

136-
closure_trace_name :: String -> CCode Name
137-
closure_trace_name name =
138-
Nam $ encore_name "trace" name
136+
closureTraceName :: String -> CCode Name
137+
closureTraceName name =
138+
Nam $ encoreName "trace" name
139139

140-
task_function_name :: String -> CCode Name
141-
task_function_name name =
142-
Nam $ encore_name "task" name
140+
taskFunctionName :: String -> CCode Name
141+
taskFunctionName name =
142+
Nam $ encoreName "task" name
143143

144-
task_env_name :: String -> CCode Name
145-
task_env_name name =
146-
Nam $ encore_name "task_env" name
144+
taskEnvName :: String -> CCode Name
145+
taskEnvName name =
146+
Nam $ encoreName "task_env" name
147147

148-
task_dependency_name :: String -> CCode Name
149-
task_dependency_name name =
150-
Nam $ encore_name "task_dep" name
148+
taskDependencyName :: String -> CCode Name
149+
taskDependencyName name =
150+
Nam $ encoreName "task_dep" name
151151

152-
task_trace_name :: String -> CCode Name
153-
task_trace_name name =
154-
Nam $ encore_name "task_trace" name
152+
taskTraceName :: String -> CCode Name
153+
taskTraceName name =
154+
Nam $ encoreName "task_trace" name
155155

156-
stream_handle :: CCode Lval
157-
stream_handle = Var "_stream"
156+
streamHandle :: CCode Lval
157+
streamHandle = Var "_stream"
158158

159-
type_var_ref_name :: Ty.Type -> CCode Name
160-
type_var_ref_name ty =
161-
Nam $ encore_name "type" (show ty)
159+
typeVarRefName :: Ty.Type -> CCode Name
160+
typeVarRefName ty =
161+
Nam $ encoreName "type" (show ty)
162162

163-
class_id :: Ty.Type -> CCode Name
164-
class_id ty =
165-
Nam $ encore_name "ID" (Ty.getId ty)
163+
classId :: Ty.Type -> CCode Name
164+
classId ty =
165+
Nam $ encoreName "ID" (Ty.getId ty)
166166

167-
ref_type_id :: Ty.Type -> CCode Name
168-
ref_type_id ty =
169-
Nam $ encore_name "ID" (Ty.getId ty)
167+
refTypeId :: Ty.Type -> CCode Name
168+
refTypeId ty =
169+
Nam $ encoreName "ID" (Ty.getId ty)
170170

171-
trait_method_selector_name = Nam "trait_method_selector"
171+
traitMethodSelectorName = Nam "trait_method_selector"
172172

173173
-- | each class, in C, provides a dispatch function that dispatches
174174
-- messages to the right method calls. This is the name of that
175175
-- function.
176-
class_dispatch_name :: Ty.Type -> CCode Name
177-
class_dispatch_name clazz =
178-
Nam $ encore_name "dispatch" (Ty.getId clazz)
176+
classDispatchName :: Ty.Type -> CCode Name
177+
classDispatchName clazz =
178+
Nam $ encoreName "dispatch" (Ty.getId clazz)
179179

180-
class_trace_fn_name :: Ty.Type -> CCode Name
181-
class_trace_fn_name clazz =
182-
Nam $ encore_name "trace" (Ty.getId clazz)
180+
classTraceFnName :: Ty.Type -> CCode Name
181+
classTraceFnName clazz =
182+
Nam $ encoreName "trace" (Ty.getId clazz)
183183

184-
runtime_type_init_fn_name :: Ty.Type -> CCode Name
185-
runtime_type_init_fn_name clazz =
186-
Nam $ encore_name "type_init" (Ty.getId clazz)
184+
runtimeTypeInitFnName :: Ty.Type -> CCode Name
185+
runtimeTypeInitFnName clazz =
186+
Nam $ encoreName "type_init" (Ty.getId clazz)
187187

188-
fut_msg_type_name :: Ty.Type -> ID.Name -> CCode Name
189-
fut_msg_type_name cls mname =
190-
Nam $ encore_name "fut_msg" ((Ty.getId cls) ++ "_" ++ show mname ++ "_t")
188+
futMsgTypeName :: Ty.Type -> ID.Name -> CCode Name
189+
futMsgTypeName cls mname =
190+
Nam $ encoreName "fut_msg" ((Ty.getId cls) ++ "_" ++ show mname ++ "_t")
191191

192-
one_way_msg_type_name :: Ty.Type -> ID.Name -> CCode Name
193-
one_way_msg_type_name cls mname =
194-
Nam $ encore_name "oneway_msg" ((Ty.getId cls) ++ "_" ++ show mname ++ "_t")
192+
oneWayMsgTypeName :: Ty.Type -> ID.Name -> CCode Name
193+
oneWayMsgTypeName cls mname =
194+
Nam $ encoreName "oneway_msg" ((Ty.getId cls) ++ "_" ++ show mname ++ "_t")
195195

196196
-- | for each method, there's a corresponding message, this is its name
197-
fut_msg_id :: Ty.Type -> ID.Name -> CCode Name
198-
fut_msg_id ref mname =
197+
futMsgId :: Ty.Type -> ID.Name -> CCode Name
198+
futMsgId ref mname =
199199
Nam $ "_ENC__FUT_MSG_" ++ Ty.getId ref ++ "_" ++ show mname
200200

201-
task_msg_id :: CCode Name
202-
task_msg_id = Nam "_ENC__MSG_TASK"
201+
taskMsgId :: CCode Name
202+
taskMsgId = Nam "_ENC__MSG_TASK"
203203

204-
one_way_msg_id :: Ty.Type -> ID.Name -> CCode Name
205-
one_way_msg_id cls mname =
204+
oneWayMsgId :: Ty.Type -> ID.Name -> CCode Name
205+
oneWayMsgId cls mname =
206206
Nam $ "_ENC__ONEWAY_MSG_" ++ Ty.getId cls ++ "_" ++ show mname
207207

208-
type_name_prefix :: Ty.Type -> String
209-
type_name_prefix ref
208+
typeNamePrefix :: Ty.Type -> String
209+
typeNamePrefix ref
210210
| Ty.isActiveClassType ref =
211-
encore_name "active" $ Ty.getId ref
211+
encoreName "active" $ Ty.getId ref
212212
| Ty.isPassiveClassType ref =
213-
encore_name "passive" $ Ty.getId ref
213+
encoreName "passive" $ Ty.getId ref
214214
| Ty.isTraitType ref =
215-
encore_name "trait" $ Ty.getId ref
215+
encoreName "trait" $ Ty.getId ref
216216
| otherwise = error $ "type_name_prefix Type '" ++ show ref ++
217217
"' isnt reference type!"
218218

219-
ref_type_name :: Ty.Type -> CCode Name
220-
ref_type_name ref = Nam $ (type_name_prefix ref) ++ "_t"
219+
refTypeName :: Ty.Type -> CCode Name
220+
refTypeName ref = Nam $ (typeNamePrefix ref) ++ "_t"
221221

222-
class_type_name :: Ty.Type -> CCode Name
223-
class_type_name ref = Nam $ (type_name_prefix ref) ++ "_t"
222+
classTypeName :: Ty.Type -> CCode Name
223+
classTypeName ref = Nam $ (typeNamePrefix ref) ++ "_t"
224224

225-
runtime_type_name :: Ty.Type -> CCode Name
226-
runtime_type_name ref = Nam $ (type_name_prefix ref) ++ "_type"
225+
runtimeTypeName :: Ty.Type -> CCode Name
226+
runtimeTypeName ref = Nam $ (typeNamePrefix ref) ++ "_type"
227227

228-
future_trace_fn :: CCode Name
229-
future_trace_fn = Nam "future_trace"
228+
futureTraceFn :: CCode Name
229+
futureTraceFn = Nam "future_trace"
230230

231-
closure_trace_fn :: CCode Name
232-
closure_trace_fn = Nam "closure_trace"
231+
closureTraceFn :: CCode Name
232+
closureTraceFn = Nam "closure_trace"
233233

234-
array_trace_fn :: CCode Name
235-
array_trace_fn = Nam "array_trace"
234+
arrayTraceFn :: CCode Name
235+
arrayTraceFn = Nam "array_trace"
236236

237-
stream_trace_fn :: CCode Name
238-
stream_trace_fn = Nam "stream_trace"
237+
streamTraceFn :: CCode Name
238+
streamTraceFn = Nam "stream_trace"
239239

240-
future_type_rec_name :: CCode Name
241-
future_type_rec_name = Nam $ "future_type"
240+
futureTypeRecName :: CCode Name
241+
futureTypeRecName = Nam $ "future_type"
242242

243-
closure_type_rec_name :: CCode Name
244-
closure_type_rec_name = Nam $ "closure_type"
243+
closureTypeRecName :: CCode Name
244+
closureTypeRecName = Nam $ "closure_type"
245245

246-
array_type_rec_name :: CCode Name
247-
array_type_rec_name = Nam $ "array_type"
246+
arrayTypeRecName :: CCode Name
247+
arrayTypeRecName = Nam $ "array_type"
248248

249-
range_type_rec_name :: CCode Name
250-
range_type_rec_name = Nam $ "range_type"
249+
rangeTypeRecName :: CCode Name
250+
rangeTypeRecName = Nam $ "range_type"

0 commit comments

Comments
 (0)