Commit 53b6fbaa68ee754ade082cfb0c3944ddfd6df0cb
1 parent
66d70ca8
make Smalltalk code pretty
Showing
1 changed file
with
25 additions
and
32 deletions
src/squeaknim.nim
@@ -80,14 +80,13 @@ template setModulename*(s, prefix: string) = | @@ -80,14 +80,13 @@ template setModulename*(s, prefix: string) = | ||
80 | 80 | ||
81 | template writeExternalLibrary*() = | 81 | template writeExternalLibrary*() = |
82 | static: | 82 | static: |
83 | - addf(stCode, """ExternalLibrary subclass: #$1 | ||
84 | - instanceVariableNames: '' | ||
85 | - classVariableNames: '' | ||
86 | - poolDictionaries: '' | ||
87 | - category: '$1'! | ||
88 | - | ||
89 | -!$1 class methodsFor: 'primitives' stamp: 'SqueakNim'! | ||
90 | -""", gPrefix & capitalize(dllName)) | 83 | + addf(stCode, "ExternalLibrary subclass: #$1\C" & |
84 | + "\tinstanceVariableNames: ''\C" & | ||
85 | + "\tclassVariableNames: ''\C" & | ||
86 | + "\tpoolDictionaries: ''\C" & | ||
87 | + "\tcategory: '$1'!\C" & | ||
88 | + "!$1 class methodsFor: 'primitives' stamp: 'SqueakNim'!\C", | ||
89 | + gPrefix & capitalize(dllName)) | ||
91 | 90 | ||
92 | template writeSmallTalkCode*(filename: string) = | 91 | template writeSmallTalkCode*(filename: string) = |
93 | ## You need to invoke this template to write the produced SmallTalk code to | 92 | ## You need to invoke this template to write the produced SmallTalk code to |
@@ -162,9 +161,9 @@ macro exportSt*(body: stmt): stmt = | @@ -162,9 +161,9 @@ macro exportSt*(body: stmt): stmt = | ||
162 | st.addf(" $1: $1", name) | 161 | st.addf(" $1: $1", name) |
163 | apicall.add(mapTypeToC(typ)) | 162 | apicall.add(mapTypeToC(typ)) |
164 | inc counter | 163 | inc counter |
165 | - apicall.add(") module: '" & dllName & "'>\n" & | ||
166 | - "\t^self externalCallFailed.\n!\n\n") | ||
167 | - stCode.add(st & "\n\t\"Generated by NimSqueak\"\n\t" & apicall) | 164 | + apicall.add(") module: '" & dllName & "'>\C" & |
165 | + "\t^self externalCallFailed\C!\C\C") | ||
166 | + stCode.add(st & "\C\t\"Generated by NimSqueak\"\C\t" & apicall) | ||
168 | 167 | ||
169 | macro wrapObject*(typ: stmt): stmt = | 168 | macro wrapObject*(typ: stmt): stmt = |
170 | ## Declares a SmallTalk wrapper class. | 169 | ## Declares a SmallTalk wrapper class. |
@@ -181,26 +180,20 @@ macro wrapObject*(typ: stmt): stmt = | @@ -181,26 +180,20 @@ macro wrapObject*(typ: stmt): stmt = | ||
181 | var fields = "" | 180 | var fields = "" |
182 | for i in 0.. < t.len: | 181 | for i in 0.. < t.len: |
183 | expectKind t[i], nnkSym | 182 | expectKind t[i], nnkSym |
184 | - fields.addf "\t($# '$#')\n", $t[i], mapTypeToC(t[i]) | ||
185 | - | ||
186 | - let st = """ExternalStructure subclass: #$1 | ||
187 | - instanceVariableNames: '' | ||
188 | - classVariableNames: '' | ||
189 | - poolDictionaries: 'FFIConstants' | ||
190 | - category: '$2'! | ||
191 | - | ||
192 | -$1 class | ||
193 | - instanceVariableNames: ''! | ||
194 | - | ||
195 | - !$1 class methodsFor: 'field definition' stamp: 'SqueakNim'! | ||
196 | - fields | ||
197 | - ^#( | ||
198 | -$3 | ||
199 | - )! ! | ||
200 | - | ||
201 | - $1 defineFields. | ||
202 | - | ||
203 | -""" % [name, dllName, fields] | 183 | + fields.addf "\t\t($# '$#')\C", $t[i], mapTypeToC(t[i]) |
184 | + | ||
185 | + let st = ("ExternalStructure subclass: #$1\C" & | ||
186 | + "\tinstanceVariableNames: ''\C" & | ||
187 | + "\tclassVariableNames: ''\C" & | ||
188 | + "\tpoolDictionaries: 'FFIConstants'\C" & | ||
189 | + "\tcategory: '$2'!\C\C" & | ||
190 | + "$1 class\C" & | ||
191 | + "\tinstanceVariableNames: ''!\C\C" & | ||
192 | + "!$1 class methodsFor: 'field definition' stamp: 'SqueakNim'!\C" & | ||
193 | + "\tfields\C" & | ||
194 | + "\t^#(\C" & | ||
195 | + "$3\C" & | ||
196 | + "\t)! !\C" & | ||
197 | + "$1 defineFields.\C!\C\C") % [name, dllName, fields] | ||
204 | stCode.add(st) | 198 | stCode.add(st) |
205 | result = newStmtList() | 199 | result = newStmtList() |
206 | - |