[svn:parrot] r42794 - trunk/runtime/parrot/library

fperrad at svn.parrot.org fperrad at svn.parrot.org
Mon Nov 23 17:51:06 UTC 2009


Author: fperrad
Date: Mon Nov 23 17:51:01 2009
New Revision: 42794
URL: https://trac.parrot.org/parrot/changeset/42794

Log:
[distutils] refactor with sprintf

Modified:
   trunk/runtime/parrot/library/distutils.pir

Modified: trunk/runtime/parrot/library/distutils.pir
==============================================================================
--- trunk/runtime/parrot/library/distutils.pir	Sun Nov 22 21:46:49 2009	(r42793)
+++ trunk/runtime/parrot/library/distutils.pir	Mon Nov 23 17:51:01 2009	(r42794)
@@ -37,6 +37,14 @@
 
 L<http://github.com/fperrad/lua-batteries/blob/master/setup.pir>
 
+L<https://trac.parrot.org/languages/browser/bf/trunk/setup.pir>
+
+L<https://trac.parrot.org/languages/browser/chitchat/trunk/setup.pir>
+
+L<https://trac.parrot.org/languages/browser/lolcode/trunk/setup.pir>
+
+L<https://trac.parrot.org/languages/browser/pheme/trunk/setup.pir>
+
 =cut
 
 .sub '__onload' :load :init :anon
@@ -2031,128 +2039,137 @@
 
 .sub '_plumage' :anon
     .param pmc kv :slurpy :named
-    .local pmc data
-    data = new 'Hash'
 
+    .local string name
     $S0 = cwd()
-    $S0 = basename($S0)
+    name = basename($S0)
     $I0 = exists kv['name']
     unless $I0 goto L1
     $S0 = kv['name']
-    $S0 = downcase $S0
+    name = downcase $S0
   L1:
-    data['name'] = $S0
 
-    $S0 = 'ABSTRACT'
+    .local string abstract
+    abstract = 'ABSTRACT'
     $I0 = exists kv['abstract']
     unless $I0 goto L2
-    $S0 = kv['abstract']
+    abstract = kv['abstract']
   L2:
-    data['abstract'] = $S0
 
-    $S0 = 'AUTHORITY'
+    .local string authority
+    authority = 'AUTHORITY'
     $I0 = exists kv['authority']
     unless $I0 goto L3
-    $S0 = kv['authority']
+    authority = kv['authority']
   L3:
-    data['authority'] = $S0
 
-    $S0 = 'HEAD'
+    .local string version
+    version = 'HEAD'
     $I0 = exists kv['version']
     unless $I0 goto L4
-    $S0 = kv['version']
+    version = kv['version']
   L4:
-    data['version'] = $S0
 
-    $S0 = 'LICENSE TYPE'
+    .local string license_type
+    license_type = 'LICENSE TYPE'
     $I0 = exists kv['license_type']
     unless $I0 goto L5
-    $S0 = kv['license_type']
+    license_type = kv['license_type']
   L5:
-    data['license_type'] = $S0
 
-    $S0 = 'LICENSE URI'
+    .local string license_uri
+    license_uri = 'LICENSE URI'
     $I0 = exists kv['license_uri']
     unless $I0 goto L6
-    $S0 = kv['license_uri']
+    license_uri = kv['license_uri']
   L6:
-    data['license_uri'] = $S0
 
-    $S0 = 'COPYRIGHT HOLDER'
+    .local string copyright_holder
+    copyright_holder = 'COPYRIGHT HOLDER'
     $I0 = exists kv['copyright_holder']
     unless $I0 goto L7
-    $S0 = kv['copyright_holder']
+    copyright_holder = kv['copyright_holder']
   L7:
-    data['copyright_holder'] = $S0
 
-    $S0 = 'GENERATED BY'
-    $I0 = exists kv['generated_by']
-    unless $I0 goto L8
-    $S0 = kv['generated_by']
-  L8:
-    data['generated_by'] = $S0
-
-    $S0 = 'DESCRIPTION'
+    .local string description
+    description = 'DESCRIPTION'
     $I0 = exists kv['description']
     unless $I0 goto L9
-    $S0 = kv['description']
+    description = kv['description']
   L9:
-    data['description'] = $S0
 
-    $S0 = ''
+    .local string keywords
+    keywords = ''
     $I0 = exists kv['keywords']
     unless $I0 goto L10
     $P1 = kv['keywords']
     $S1 = join "\", \"", $P1
-    $S0 = "\"" . $S1
-    $S0 .= "\""
+    keywords = "\"" . $S1
+    keywords .= "\""
   L10:
-    data['keywords'] = $S0
 
-    $S0 = 'vcs'
+    .local string vcs
+    vcs = 'vcs'
     $I0 = file_exists('CVS')
     unless $I0 goto L21
-    $S0 = 'cvs'
+    vcs = 'cvs'
     goto L29
   L21:
     $I0 = file_exists('.git')
     unless $I0 goto L22
-    $S0 = 'git'
+    vcs = 'git'
     goto L29
   L22:
     $I0 = file_exists('.hg')
     unless $I0 goto L23
-    $S0 = 'hg'
+    vcs = 'hg'
     goto L29
   L23:
     $I0 = file_exists('.svn')
     unless $I0 goto L4
-    $S0 = 'svn'
+    vcs = 'svn'
     goto L29
   L24:
   L29:
-    data['vcs'] = $S0
 
-    $S0 = 'CHECKOUT_URI'
+    .local string checkout_uri
+    checkout_uri = 'CHECKOUT_URI'
     $I0 = exists kv['checkout_uri']
     unless $I0 goto L31
-    $S0 = kv['checkout_uri']
+    checkout_uri = kv['checkout_uri']
   L31:
-    data['checkout_uri'] = $S0
 
-    $S0 = 'BROWSER_URI'
+    .local string browser_uri
+    browser_uri = 'BROWSER_URI'
     $I0 = exists kv['browser_uri']
     unless $I0 goto L32
-    $S0 = kv['browser_uri']
+    browser_uri = kv['browser_uri']
   L32:
-    data['browser_uri'] = $S0
 
-    $S0 = 'PROJECT_URI'
+    .local string project_uri
+    project_uri = 'PROJECT_URI'
     $I0 = exists kv['project_uri']
     unless $I0 goto L33
-    $S0 = kv['project_uri']
+    project_uri = kv['project_uri']
   L33:
-    data['project_uri'] = $S0
+
+    $P0 = new 'FixedStringArray'
+    set $P0, 15
+    $P0[0] = name
+    $P0[1] = abstract
+    $P0[2] = authority
+    $P0[3] = version
+    $P0[4] = license_type
+    $P0[5] = license_uri
+    $P0[6] = copyright_holder
+    $P0[7] = keywords
+    $P0[8] = description
+    $P0[9] = name
+    $P0[10] = vcs
+    $P0[11] = vcs
+    $P0[12] = checkout_uri
+    $P0[13] = browser_uri
+    $P0[14] = project_uri
 
     $S0 = <<'TEMPLATE'
 {
@@ -2161,18 +2178,18 @@
         "uri"      : "https://trac.parrot.org/parrot/wiki/ModuleEcosystem"
     },
     "general"      : {
-        "name"     : "$name",
-        "abstract" : "$abstract",
-        "authority": "$authority",
-        "version"  : "$version",
+        "name"     : "%s",
+        "abstract" : "%s",
+        "authority": "%s",
+        "version"  : "%s",
         "license"  : {
-            "type" : "$license_type",
-            "uri"  : "$license_uri"
+            "type" : "%s",
+            "uri"  : "%s"
         },
-        "copyright_holder" : "$copyright_holder",
-        "generated_by"     : "$generated_by",
-        "keywords"         : [$keywords],
-        "description"      : "$description"
+        "copyright_holder" : "%s",
+        "generated_by"     : "distutils",
+        "keywords"         : [%s],
+        "description"      : "%s"
     },
     "instructions" : {
         "fetch"    : {
@@ -2189,9 +2206,9 @@
         }
     },
     "dependency-info"  : {
-        "provides"     : ["$name"],
+        "provides"     : ["%s"],
         "requires"     : {
-            "fetch"    : ["$vcs"],
+            "fetch"    : ["%s"],
             "build"    : [],
             "test"     : ["perl5"],
             "install"  : [],
@@ -2200,15 +2217,15 @@
     },
     "resources"            : {
         "repository"       : {
-             "type"        : "$vcs",
-             "checkout_uri": "$checkout_uri",
-             "browser_uri" : "$browser_uri",
-             "project_uri" : "$project_uri"
+             "type"        : "%s",
+             "checkout_uri": "%s",
+             "browser_uri" : "%s",
+             "project_uri" : "%s"
         }
     }
 }
 TEMPLATE
-    $S0 = interpolate($S0, data)
+    $S0 = sprintf $S0, $P0
     print $S0
 .end
 
@@ -2273,17 +2290,13 @@
     .local pmc config
     config = get_config()
 
-    $P0 = new 'Hash'
-
     .local string prefix
     prefix = config['prefix']
-    $P0['prefix'] = prefix
 
     .local string parrot_version
     $S1 = config['VERSION']
     $S2 = config['DEVEL']
     parrot_version = $S1 . $S2
-    $P0['parrot_version'] = parrot_version
 
     .local string name
     $S0 = cwd()
@@ -2292,7 +2305,6 @@
     unless $I0 goto L1
     name = kv['name']
   L1:
-    $P0['name'] = name
 
     .local string version
     $I0 = time
@@ -2310,7 +2322,6 @@
     unless $I0 goto L2
     version = kv['version']
   L2:
-    $P0['version'] = version
 
     .local string license
     $I0 = file_exists('LICENSE')
@@ -2330,22 +2341,33 @@
   L13:
     license = "; no LicenseFile"
   L19:
-    $P0['license'] = license
+
+    $P0 = new 'FixedStringArray'
+    set $P0, 9
+    $P0[0] = name
+    $P0[1] = parrot_version
+    $P0[2] = name
+    $P0[3] = version
+    $P0[4] = prefix
+    $P0[5] = license
+    $P0[6] = parrot_version
+    $P0[7] = name
+    $P0[8] = version
 
     $S0 = <<'TEMPLATE'
 ; generated by distutils.pir for the Inno Setup Script Compiler.
 
 [Setup]
-AppName=Parrot-$name
-AppVerName=Parrot-$parrot_version-$name-$version
+AppName=Parrot-%s
+AppVerName=Parrot-%s-%s-%s
 AppPublisher=Parrot Foundation
 AppPublisherURL=http://www.parrot.org/
-DefaultDirName={sd}$prefix
+DefaultDirName={sd}%s
 DefaultGroupName=Parrot
 AllowNoIcons=yes
-$license
+%s
 OutputDir=.\\
-OutputBaseFilename=setup-parrot-$parrot_version-$name-$version
+OutputBaseFilename=setup-parrot-%s-%s-%s
 Compression=lzma
 SolidCompression=yes
 Uninstallable=no
@@ -2353,7 +2375,7 @@
 [Files]
 TEMPLATE
     .local string script
-    script = interpolate($S0, $P0)
+    script = sprintf $S0, $P0
 
     $I0 = exists kv['dynops']
     if $I0 goto L21
@@ -2443,54 +2465,6 @@
     .return ($S0)
 .end
 
-.include 'cclass.pasm'
-
-.sub 'interpolate' :anon
-    .param string content
-    .param pmc config
-    $P0 = split "\n", content
-    .local string result, line
-    result = ''
-  L1:
-    unless $P0 goto L2
-    line = shift $P0
-    $I9 = length line
-    $I0 = 0
-    $S0 = ''
-  L3:
-    $I1 = index line, '$', $I0
-    if $I1 < 0 goto L4
-  L8:
-    $I2 = $I1 - $I0
-    inc $I1
-    $I3 = find_not_cclass .CCLASS_WORD, line, $I1, $I9
-#    if $I3 < 0 goto L4
-    $S1 = substr line, $I0, $I2
-    $S0 .= $S1
-    $I4 = $I3 - $I1
-    $S1 = substr line, $I1, $I4
-    $I7 = exists config[$S1]
-    unless $I7 goto L5
-    $S2 = config[$S1]
-    $S0 .= $S2
-    goto L6
-  L5:
-    printerr "\tunknown config: "
-    printerr $S1
-    printerr "\n"
-  L6:
-    $I0 = $I3
-    goto L3
-  L4:
-    $S1 = substr line, $I0
-    $S0 .= $S1
-    result .= $S0
-    result .= "\n"
-    goto L1
-  L2:
-    .return (result)
-.end
-
 .sub '_clean_win32_installer' :anon
     .param pmc kv :slurpy :named
 


More information about the parrot-commits mailing list