@@ -24,7 +24,8 @@ nodeInstr_nClass <- nClass(
2424 file.path(" nodeInstr_nC" )),
2525 compileInfo = list (interface = " full" ,
2626 createFromR = TRUE ,
27- exportName = " nodeInstr_nClass"
27+ exportName = " nodeInstr_nClass_new" ,
28+ packageNames = c(uncompiled = " nodeInstr_nClass" , compiled = " nodeInstr_nClass_C" )
2829 )
2930)
3031
@@ -38,15 +39,16 @@ calcInstr_nClass <- nClass(
3839 file.path(" calcInstr_nC" )),
3940 compileInfo = list (interface = " full" ,
4041 createFromR = TRUE ,
41- # The Hincludes should be picked up automatically but I think it's not
42+ # The Hincludes should be picked up automatically but I think it's not
4243 # because it is in the nList type and that is not being scanned for needed nClasses.
4344 # These do need to be in "" not <>, for case of nCompile(...., package=TRUE)
4445 Hincludes = ' "nodeInstr_nClass_c_.h"' ,
4546 # In the format here, needed_units is a list with either objects (nFunction or nClass (generators),
4647 # or names. If names, we will use scoping to look them up and decide what they are.
4748 # The list can mix objects and names of nClasses and nFunctions.
4849 needed_units = list (" nodeInstr_nClass" ),
49- exportName = " calcInstr_nClass"
50+ exportName = " calcInstr_nClass_new" ,
51+ packageNames = c(uncompiled = " calcInstr_nClass" , compiled = " calcInstr_nClass_C" )
5052 )
5153)
5254
@@ -60,7 +62,8 @@ calcInstrList_nClass <- nClass(
6062 compileInfo = list (interface = " full" ,
6163 createFromR = TRUE ,
6264 Hincludes = ' "calcInstr_nClass_c_.h"' ,
63- exportName = " calcInstrList_nClass" ,
65+ exportName = " calcInstrList_nClass_new" ,
66+ packageNames = c(uncompiled = " calcInstrList_nClass" , compiled = " calcInstrList_nClass_C" ),
6467 needed_units = list (" calcInstr_nClass" )
6568 )
6669)
@@ -85,7 +88,9 @@ nodeFxnBase_nClass <- nClass(
8588 file.path(" nodeFxnBase_nC" )),
8689 compileInfo = list (interface = " full" ,
8790 createFromR = FALSE ,
88- exportName = " nodeFxnBase_nClass" )
91+ exportName = " nodeFxnBase_nClass_new" ,
92+ packageNames = c(uncompiled = " nodeFxnBase_nClass" , compiled = " nodeFxnBase_nClass_C" )
93+ )
8994)
9095
9196# nCompile(nodeFxnBase_nClass, control=list(generate_predefined=TRUE))
@@ -118,15 +123,16 @@ modelBase_nClass <- nClass(
118123 cppLiteral(' Rprintf("modelBase_nClass calculate (should not see this)\\ n");' ); return (0 )},
119124 virtual = TRUE
120125 )
121- )
126+ )
122127 ),
123128 # See comment above about needing to ensure a virtual destructor
124129 predefined = quote(system.file(file.path(" include" ," nCompiler" , " predef" ), package = " nCompiler" ) | > file.path(" modelBase_nC" )),
125130 compileInfo = list (interface = " full" ,
126131 createFromR = FALSE ,
127132 Hincludes = c(' "nodeFxnBase_nClass_c_.h"' , ' "calcInstrList_nClass_c_.h"' ), # do we need "<nodeFxnBase_nClass_c_.h>" too?
128133 needed_units = list (" nodeFxnBase_nClass" ," calcInstrList_nClass" ), # do we need nodeFxnBase_nClass here too?
129- exportName = " modelBase_nClass"
134+ exportName = " modelBase_nClass_new" ,
135+ packageNames = c(uncompiled = " modelBase_nClass" , compiled = " modelBase_nClass_C" )
130136 )
131137)
132138
@@ -147,7 +153,7 @@ nm_addModelDollarSign <- function(expr, exceptionNames = character(0)) {
147153 if (expr [[1 ]] == ' $' ){
148154 expr [2 ] <- lapply(expr [2 ], function (listElement ) nm_addModelDollarSign(listElement , exceptionNames ))
149155 return (expr )
150- }
156+ }
151157 if (expr [[1 ]] == ' returnType' )
152158 return (expr )
153159 if (length(expr ) > 1 ) {
@@ -189,8 +195,12 @@ make_node_nClass <- function(varInfo = list(),
189195 CpublicVars <- names(symbolList ) | > lapply(\(x ) eval(substitute(quote(T (symbolList $ NAME )),
190196 list (NAME = as.name(x )))))
191197 names(CpublicVars ) <- names(symbolList )
198+ # This is a kluge to have a model field in the Cpublic_obj,
199+ # needed for uncompiled purposes, and for compiled purposes
200+ # we instead use references to model variables. So
201+ # the declared type here is arbitrary.
192202 initFun <- function (){}
193-
203+
194204 if (numVars > 0 ) {
195205 ctorArgNames <- paste0(names(symbolList ), ' _' )
196206 # List used when generating C++ constructor code to allow direct initializers, necessary for references.
@@ -206,8 +216,10 @@ make_node_nClass <- function(varInfo = list(),
206216
207217 # Rpublic method to set the model pointer/reference.
208218 setModel <- function (model ) {
209- if (! isCompiled())
219+ if (! isCompiled()) {
210220 self $ model <- model
221+ # private$Cpublic_obj$model <- model
222+ }
211223 else
212224 warning(" setModel called on compiled object; no action taken" )
213225 }
@@ -232,9 +244,10 @@ make_node_nClass <- function(varInfo = list(),
232244 )
233245 ) | > structure(names = classname ),
234246 CpublicVars ,
247+ list (model = " RcppList" ),
235248 methods
236249 ),
237- RPUBLIC = list (model = NULL ,
250+ RPUBLIC = list (# model = NULL,
238251 setModel = setModel ),
239252 CLASSNAME = classname ,
240253 BASECLASS = baseclass
@@ -350,6 +363,7 @@ makeModel_nClass <- function(varInfo,
350363 # It is not very easy to set debug onto the initialize function, so
351364 # here is a magic flag.
352365 if (isTRUE(.GlobalEnv $ .debugModelInit )) browser()
366+ super $ initialize()
353367 if (isCompiled())
354368 self $ setup_node_mgmt_from_names(self $ nodeObjNames )
355369 if (! isCompiled()) {
@@ -358,7 +372,7 @@ makeModel_nClass <- function(varInfo,
358372 self [[nodeObj ]]$ setModel(self )
359373 }
360374 }
361-
375+
362376 # First expand any provided or default sizes
363377 # To-Do possibly merge the argument sizes and defaultSizes by element.
364378 if (missing(sizes )) sizes <- self $ defaultSizes
@@ -372,7 +386,7 @@ makeModel_nClass <- function(varInfo,
372386 baseclass <- paste0(" modelClass_<" , classname , " >" )
373387 # CpublicNodeFuns has elements like "node_1 = quote(nodeFxn_1())"
374388 # We provide it in Cpublic to declare C++ member variables with types.
375- # We also place the list itself in the class so that we can look up for uncompiled execution
389+ # We also place the list itself in the class so that we can look up for uncompiled execution
376390 # the objects that need to be created in initialize.
377391 # If we someday make type declarations and initializations more automatic, we can avoid this duplication.
378392 ans <- substitute(
@@ -390,9 +404,9 @@ makeModel_nClass <- function(varInfo,
390404 ),
391405 list (OPDEFS = opDefs ,
392406 # A list of individual elements
393- RPUBLIC = list (initialize = initialize ,
407+ RPUBLIC = list (initialize = initialize ,
394408 nodeObjNames = nodeObjNames ,
395- nodeObjName_2_nodeIndex = nodeObjName_2_nodeIndex ,
409+ nodeObjName_2_nodeIndex = nodeObjName_2_nodeIndex ,
396410 defaultSizes = sizes ,
397411 defaultInits = inits ,
398412 CpublicNodeFuns = CpublicNodeFuns ),
@@ -446,12 +460,12 @@ make_stoch_sim_line <- function(LHSrep, RHSrep) {
446460 if (is.null(sim_code )) stop(" Could not find simulation ('r') function for " , BUGSdistName )
447461 RHSrep [[1 ]] <- sim_code
448462 # scoot all named arguments right 1 position
449- if (length(RHSrep ) > 1 ) {
463+ if (length(RHSrep ) > 1 ) {
450464 for (i in (length(RHSrep )+ 1 ): 3 ) {
451465 RHSrep [i ] <- RHSrep [i - 1 ]
452466 names(RHSrep )[i ] <- names(RHSrep )[i - 1 ]
453- }
454- }
467+ }
468+ }
455469 RHSrep [[2 ]] <- 1
456470 names(RHSrep )[2 ] <- ' '
457471 sim_line <- substitute(
@@ -542,7 +556,7 @@ make_node_methods_from_declInfo <- function(declInfo) {
542556 make_node_method_nFxn(" sim_one" , NULL ),
543557 calc_one = (function (idx ) {DETERMCALC ; return (invisible (0 ))}) | >
544558 make_node_method_nFxn(" calc_one" ),
545- calcDiff_one = (function (idx ) {calc_one(idx );return (invisible (0 ))}) | >
559+ calcDiff_one = (function (idx ) {calc_one(idx );return (invisible (0 ))}) | >
546560 make_node_method_nFxn(" calcDiff_one" ),
547561 getLogProb_one = (function (idx ) {return (0 )}) | >
548562 make_node_method_nFxn(" getLogProb_one" )
@@ -559,7 +573,7 @@ make_node_methods_from_declInfo <- function(declInfo) {
559573 make_node_method_nFxn(" sim_one" , NULL ),
560574 calc_one = (function (idx ) { STOCHCALC ; return (invisible (LOGPROB )) }) | >
561575 make_node_method_nFxn(" calc_one" ),
562- calcDiff_one = (function (idx ) {STOCHCALC_DIFF ; LocalAns_ <- LocalNewLogProb_ - LOGPROB ;
576+ calcDiff_one = (function (idx ) {STOCHCALC_DIFF ; LocalAns_ <- LocalNewLogProb_ - LOGPROB ;
563577 LOGPROB <- LocalNewLogProb_ ; return (invisible (LocalAns_ ))}) | >
564578 make_node_method_nFxn(" calcDiff_one" ),
565579 getLogProb_one = (function (idx ) { return (LOGPROB ) }) | >
0 commit comments