@@ -99,7 +99,7 @@ function toRegex(n: readonly string[]): RegExp {
9999/**
100100 * Contains the built-in definitions recognized by flowR
101101 */
102- export const DefaultBuiltinConfig : BuiltInDefinitions = [
102+ export const DefaultBuiltinConfig = [
103103 { type : 'constant' , names : [ 'NULL' , 'NA' , 'NaN' , 'NA_integer_' , 'NA_real_' , 'NA_complex_' , 'NA_character_' ] , value : null , assumePrimitive : true } ,
104104 { type : 'constant' , names : [ 'TRUE' , 'T' ] , value : true , assumePrimitive : true } ,
105105 { type : 'constant' , names : [ 'FALSE' , 'F' ] , value : false , assumePrimitive : true } ,
@@ -186,6 +186,7 @@ export const DefaultBuiltinConfig: BuiltInDefinitions = [
186186 names : GgPlotAddons ,
187187 processor : 'builtin:default' ,
188188 config : {
189+ libFn : true ,
189190 forceArgs : 'all' ,
190191 hasUnknownSideEffects : {
191192 type : 'link-to-last-call' ,
@@ -197,6 +198,7 @@ export const DefaultBuiltinConfig: BuiltInDefinitions = [
197198 names : TinyPlotAddons ,
198199 processor : 'builtin:default' ,
199200 config : {
201+ libFn : true ,
200202 forceArgs : 'all' ,
201203 hasUnknownSideEffects : {
202204 type : 'link-to-last-call' ,
@@ -208,6 +210,7 @@ export const DefaultBuiltinConfig: BuiltInDefinitions = [
208210 names : [ 'image_write' , 'image_capture' , 'dev.capture' , 'dev.off' ] ,
209211 processor : 'builtin:default' ,
210212 config : {
213+ libFn : true ,
211214 forceArgs : 'all' ,
212215 hasUnknownSideEffects : {
213216 type : 'link-to-last-call' ,
@@ -217,14 +220,17 @@ export const DefaultBuiltinConfig: BuiltInDefinitions = [
217220 { type : 'function' , names : [ '(' ] , processor : 'builtin:default' , config : { returnsNthArgument : 0 } , assumePrimitive : true } ,
218221 { type : 'function' , names : [ 'load' , 'load_all' , 'setwd' , 'set.seed' ] , processor : 'builtin:default' , config : { hasUnknownSideEffects : true , forceArgs : [ true ] } , assumePrimitive : false } ,
219222 { type : 'function' , names : [ 'body' , 'formals' , 'environment' ] , processor : 'builtin:default' , config : { hasUnknownSideEffects : true , forceArgs : [ true ] } , assumePrimitive : true } ,
220- { type : 'function' , names : [ '.Call' , '.External' , '.C' , '.Fortran' ] , processor : 'builtin:default' , config : { hasUnknownSideEffects : true , forceArgs : [ true ] ,
221- treatAsFnCall : {
222- '.Call' : [ '.NAME' ] ,
223- '.External' : [ '.NAME' ] ,
224- '.C' : [ '.NAME' ] ,
225- '.Fortran' : [ '.NAME' ]
226- }
227- } , assumePrimitive : true } ,
223+ { type : 'function' ,
224+ names : [ '.Call' , '.External' , '.C' , '.Fortran' ] ,
225+ processor : 'builtin:default' ,
226+ config : { hasUnknownSideEffects : true , forceArgs : [ true ] ,
227+ treatAsFnCall : {
228+ '.Call' : [ '.NAME' ] ,
229+ '.External' : [ '.NAME' ] ,
230+ '.C' : [ '.NAME' ] ,
231+ '.Fortran' : [ '.NAME' ]
232+ }
233+ } , assumePrimitive : true } ,
228234 { type : 'function' , names : [ 'eval' ] , processor : 'builtin:eval' , config : { includeFunctionCall : true } , assumePrimitive : true } ,
229235 { type : 'function' , names : [ 'cat' ] , processor : 'builtin:default' , config : { forceArgs : 'all' , hasUnknownSideEffects : { type : 'link-to-last-call' , callName : / ^ s i n k $ / } } , assumePrimitive : false } ,
230236 { type : 'function' , names : [ 'switch' ] , processor : 'builtin:default' , config : { forceArgs : [ true ] } , assumePrimitive : false } ,
@@ -257,8 +263,8 @@ export const DefaultBuiltinConfig: BuiltInDefinitions = [
257263 { type : 'function' , names : [ 'while' ] , processor : 'builtin:while-loop' , config : { } , assumePrimitive : true } ,
258264 { type : 'function' , names : [ 'do.call' ] , processor : 'builtin:apply' , config : { indexOfFunction : 0 , unquoteFunction : true } , assumePrimitive : true } ,
259265 { type : 'function' , names : [ '.Primitive' , '.Internal' ] , processor : 'builtin:apply' , config : { indexOfFunction : 0 , unquoteFunction : true , resolveInEnvironment : 'global' } , assumePrimitive : true } ,
260- { type : 'function' , names : [ 'interference' ] , processor : 'builtin:apply' , config : { unquoteFunction : true , nameOfFunctionArgument : 'propensity_integrand' } , assumePrimitive : false } ,
261- { type : 'function' , names : [ 'ddply' ] , processor : 'builtin:apply' , config : { unquoteFunction : true , indexOfFunction : 2 , nameOfFunctionArgument : '.fun' } , assumePrimitive : false } ,
266+ { type : 'function' , names : [ 'interference' ] , processor : 'builtin:apply' , config : { unquoteFunction : true , nameOfFunctionArgument : 'propensity_integrand' , libFn : true } , assumePrimitive : false } ,
267+ { type : 'function' , names : [ 'ddply' ] , processor : 'builtin:apply' , config : { unquoteFunction : true , indexOfFunction : 2 , nameOfFunctionArgument : '.fun' , libFn : true } , assumePrimitive : false } ,
262268 { type : 'function' , names : [ 'list' ] , processor : 'builtin:list' , config : { } , assumePrimitive : true } ,
263269 { type : 'function' , names : [ 'c' ] , processor : 'builtin:vector' , config : { } , assumePrimitive : true , evalHandler : 'builtin:c' } ,
264270 {
@@ -275,11 +281,9 @@ export const DefaultBuiltinConfig: BuiltInDefinitions = [
275281 {
276282 type : 'function' ,
277283 names : [
278- 'on.exit' , 'sys.on.exit' , 'par' , 'tpar' , 'sink' , 'tinytheme' , 'theme_set' ,
284+ 'on.exit' , 'sys.on.exit' , 'par' , 'tpar' , 'sink' ,
279285 /* library and require is handled above */
280286 'requireNamespace' , 'loadNamespace' , 'attachNamespace' , 'asNamespace' ,
281- /* downloader and installer functions (R, devtools, BiocManager) */
282- 'library.dynam' , 'install.packages' , 'install' , 'install_github' , 'install_gitlab' , 'install_bitbucket' , 'install_url' , 'install_git' , 'install_svn' , 'install_local' , 'install_version' , 'update_packages' ,
283287 /* weird env attachments */
284288 'attach' , 'unname' , 'data' ,
285289 /* file creation/removal */
@@ -289,6 +293,17 @@ export const DefaultBuiltinConfig: BuiltInDefinitions = [
289293 config : { hasUnknownSideEffects : true } ,
290294 assumePrimitive : false
291295 } ,
296+ {
297+ type : 'function' ,
298+ names : [
299+ 'tinytheme' , 'theme_set' ,
300+ /* downloader and installer functions (R, devtools, BiocManager) */
301+ 'library.dynam' , 'install.packages' , 'install' , 'install_github' , 'install_gitlab' , 'install_bitbucket' , 'install_url' , 'install_git' , 'install_svn' , 'install_local' , 'install_version' , 'update_packages' ,
302+ ] ,
303+ processor : 'builtin:default' ,
304+ config : { hasUnknownSideEffects : true , libFn : true } ,
305+ assumePrimitive : false
306+ } ,
292307 /* they are all mapped to `<-` but we separate super assignments */
293308 {
294309 type : 'replacement' ,
@@ -306,17 +321,17 @@ export const DefaultBuiltinConfig: BuiltInDefinitions = [
306321 readIndices : false
307322 }
308323 }
309- ] ;
324+ ] as const satisfies BuiltInDefinitions ;
310325
311326
312327/**
313- *
328+ * Expensive and naive lookup of the default processor for a built-in function name
314329 */
315330export function getDefaultProcessor ( name : string ) : BuiltInMappingName | 'unnamed' | undefined {
316331 if ( name . startsWith ( UnnamedFunctionCallPrefix ) ) {
317332 return 'unnamed' ;
318333 }
319- const fn = DefaultBuiltinConfig . find ( def => ( def . names . includes ( name ) && def . type !== 'constant' )
334+ const fn = DefaultBuiltinConfig . find ( def => ( ( def . names as string [ ] ) . includes ( name ) && def . type !== 'constant' )
320335 || ( def . type === 'replacement' && def . suffixes . flatMap ( d => def . names . map ( n => `${ n } ${ d } ` ) ) . includes ( name ) )
321336 ) as BuiltInFunctionDefinition < 'builtin:default' > | BuiltInReplacementDefinition | undefined ;
322337 return fn ?. type === 'replacement' ? 'builtin:replacement' : fn ?. processor as BuiltInMappingName ;
0 commit comments