[Rcpp-commits] r904 - pkg/Rcpp/inst/codebloat scripts
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Mar 15 19:40:39 CET 2010
Author: romain
Date: 2010-03-15 19:40:38 +0100 (Mon, 15 Mar 2010)
New Revision: 904
Added:
scripts/codebloat.R
Removed:
pkg/Rcpp/inst/codebloat/codebloat.R
Log:
move the ciodebloat script out of the distribution
Deleted: pkg/Rcpp/inst/codebloat/codebloat.R
===================================================================
--- pkg/Rcpp/inst/codebloat/codebloat.R 2010-03-15 18:33:54 UTC (rev 903)
+++ pkg/Rcpp/inst/codebloat/codebloat.R 2010-03-15 18:40:38 UTC (rev 904)
@@ -1,70 +0,0 @@
-
-#
-# to change the maximum number of arguments to 20
-# move to the root directory of Rcpp and do :
-# Rscript inst/codebloat/codebloat.R 20
-#
-
-target <- commandArgs(TRUE)[1]
-
-typenames <- function( n = 1){
- paste( sprintf( "typename T%d", 1:n ), collapse = ", " )
-}
-
-arguments <- function( n = 1){
- paste( sprintf( "const T%d& t%d", 1:n, 1:n ), collapse = ", " )
-}
-
-parameters <- function( n = 1 ){
- paste( sprintf( "t%d", 1:n ), collapse = ", " )
-}
-
-grow <- function( n = 1 ){
- grow__ <- function( n, m){
- if( m > n ){
- "R_NilValue"
- } else{
- sprintf( "grow( t%d, %s )", m, grow__( n , m+1) )
- }
- }
- grow__( n, 1 ) ;
-}
-
-modify <- function(txt, token, n, fun){
- if( any( grepl( token, txt ) ) ){
- gsub( token, fun(n), txt )
- } else {
- txt
- }
-}
-
-path <- file.path( "src", "Rcpp" )
-for( f in list.files(path, full.names = TRUE) ){
- content <- readLines( f )
- if( any( grepl( "code-bloat", content ) ) ){
- first <- grep( "<code-bloat>", content )
- last <- grep( "</code-bloat>", content )
- code.end <- grep( "^[*]/", content[first:last] )[1] - 2
- code <- content[ first + (2:code.end) ]
-
- result <- lapply( 1:target, function(n){
- txt <- code
- txt <- modify( txt, "TYPENAMES" , n, typenames )
- txt <- modify( txt, "ARGUMENTS" , n, arguments )
- txt <- modify( txt, "PARAMETERS", n, parameters )
- txt <- modify( txt, "GROW" , n, grow )
- txt
- } )
-
- output <- unlist( result )
-
- new.content <- c(
- content[1:(first+code.end+1)],
- output,
- content[last:length(content)] )
-
- cat( new.content, file = f, sep = "\n" )
-
- }
-}
-
Copied: scripts/codebloat.R (from rev 903, pkg/Rcpp/inst/codebloat/codebloat.R)
===================================================================
--- scripts/codebloat.R (rev 0)
+++ scripts/codebloat.R 2010-03-15 18:40:38 UTC (rev 904)
@@ -0,0 +1,70 @@
+
+#
+# to change the maximum number of arguments to 20
+# move to the root directory of Rcpp and do :
+# Rscript inst/codebloat/codebloat.R 20
+#
+
+target <- commandArgs(TRUE)[1]
+
+typenames <- function( n = 1){
+ paste( sprintf( "typename T%d", 1:n ), collapse = ", " )
+}
+
+arguments <- function( n = 1){
+ paste( sprintf( "const T%d& t%d", 1:n, 1:n ), collapse = ", " )
+}
+
+parameters <- function( n = 1 ){
+ paste( sprintf( "t%d", 1:n ), collapse = ", " )
+}
+
+grow <- function( n = 1 ){
+ grow__ <- function( n, m){
+ if( m > n ){
+ "R_NilValue"
+ } else{
+ sprintf( "grow( t%d, %s )", m, grow__( n , m+1) )
+ }
+ }
+ grow__( n, 1 ) ;
+}
+
+modify <- function(txt, token, n, fun){
+ if( any( grepl( token, txt ) ) ){
+ gsub( token, fun(n), txt )
+ } else {
+ txt
+ }
+}
+
+path <- file.path( "src", "Rcpp" )
+for( f in list.files(path, full.names = TRUE) ){
+ content <- readLines( f )
+ if( any( grepl( "code-bloat", content ) ) ){
+ first <- grep( "<code-bloat>", content )
+ last <- grep( "</code-bloat>", content )
+ code.end <- grep( "^[*]/", content[first:last] )[1] - 2
+ code <- content[ first + (2:code.end) ]
+
+ result <- lapply( 1:target, function(n){
+ txt <- code
+ txt <- modify( txt, "TYPENAMES" , n, typenames )
+ txt <- modify( txt, "ARGUMENTS" , n, arguments )
+ txt <- modify( txt, "PARAMETERS", n, parameters )
+ txt <- modify( txt, "GROW" , n, grow )
+ txt
+ } )
+
+ output <- unlist( result )
+
+ new.content <- c(
+ content[1:(first+code.end+1)],
+ output,
+ content[last:length(content)] )
+
+ cat( new.content, file = f, sep = "\n" )
+
+ }
+}
+
More information about the Rcpp-commits
mailing list