From 53b6fbaa68ee754ade082cfb0c3944ddfd6df0cb Mon Sep 17 00:00:00 2001 From: Araq Date: Wed, 4 Mar 2015 23:57:18 +0100 Subject: [PATCH] make Smalltalk code pretty --- src/squeaknim.nim | 57 +++++++++++++++++++++++++-------------------------------- 1 file changed, 25 insertions(+), 32 deletions(-) diff --git a/src/squeaknim.nim b/src/squeaknim.nim index 3d79585..7fed0ca 100644 --- a/src/squeaknim.nim +++ b/src/squeaknim.nim @@ -80,14 +80,13 @@ template setModulename*(s, prefix: string) = template writeExternalLibrary*() = static: - addf(stCode, """ExternalLibrary subclass: #$1 - instanceVariableNames: '' - classVariableNames: '' - poolDictionaries: '' - category: '$1'! - -!$1 class methodsFor: 'primitives' stamp: 'SqueakNim'! -""", gPrefix & capitalize(dllName)) + addf(stCode, "ExternalLibrary subclass: #$1\C" & + "\tinstanceVariableNames: ''\C" & + "\tclassVariableNames: ''\C" & + "\tpoolDictionaries: ''\C" & + "\tcategory: '$1'!\C" & + "!$1 class methodsFor: 'primitives' stamp: 'SqueakNim'!\C", + gPrefix & capitalize(dllName)) template writeSmallTalkCode*(filename: string) = ## You need to invoke this template to write the produced SmallTalk code to @@ -162,9 +161,9 @@ macro exportSt*(body: stmt): stmt = st.addf(" $1: $1", name) apicall.add(mapTypeToC(typ)) inc counter - apicall.add(") module: '" & dllName & "'>\n" & - "\t^self externalCallFailed.\n!\n\n") - stCode.add(st & "\n\t\"Generated by NimSqueak\"\n\t" & apicall) + apicall.add(") module: '" & dllName & "'>\C" & + "\t^self externalCallFailed\C!\C\C") + stCode.add(st & "\C\t\"Generated by NimSqueak\"\C\t" & apicall) macro wrapObject*(typ: stmt): stmt = ## Declares a SmallTalk wrapper class. @@ -181,26 +180,20 @@ macro wrapObject*(typ: stmt): stmt = var fields = "" for i in 0.. < t.len: expectKind t[i], nnkSym - fields.addf "\t($# '$#')\n", $t[i], mapTypeToC(t[i]) - - let st = """ExternalStructure subclass: #$1 - instanceVariableNames: '' - classVariableNames: '' - poolDictionaries: 'FFIConstants' - category: '$2'! - -$1 class - instanceVariableNames: ''! - - !$1 class methodsFor: 'field definition' stamp: 'SqueakNim'! - fields - ^#( -$3 - )! ! - - $1 defineFields. - -""" % [name, dllName, fields] + fields.addf "\t\t($# '$#')\C", $t[i], mapTypeToC(t[i]) + + let st = ("ExternalStructure subclass: #$1\C" & + "\tinstanceVariableNames: ''\C" & + "\tclassVariableNames: ''\C" & + "\tpoolDictionaries: 'FFIConstants'\C" & + "\tcategory: '$2'!\C\C" & + "$1 class\C" & + "\tinstanceVariableNames: ''!\C\C" & + "!$1 class methodsFor: 'field definition' stamp: 'SqueakNim'!\C" & + "\tfields\C" & + "\t^#(\C" & + "$3\C" & + "\t)! !\C" & + "$1 defineFields.\C!\C\C") % [name, dllName, fields] stCode.add(st) result = newStmtList() - -- libgit2 0.22.2