@@ -70,22 +70,25 @@ export default function generate(program) {
7070 if (gen.size === 0) {
7171 gen.size++;
7272 gen.index++;
73- gen.values.push(f(currentVal));
73+ const result = f(currentVal);
74+ gen.values.push(Array.isArray(result) ? result.join(' ') : result);
7475 currentVal += gen.timestepRange.step;
7576 }
7677 if (gen.timestepRange.step > 0) {
7778 while (currentVal <= gen.timestepRange.end && iterations > 0) {
7879 gen.size++;
7980 gen.index++;
80- gen.values.push(f(currentVal));
81+ const result = f(currentVal);
82+ gen.values.push(Array.isArray(result) ? result.join(' ') : result);
8183 currentVal += gen.timestepRange.step;
8284 iterations--;
8385 }
8486 } else {
8587 while (currentVal >= gen.timestepRange.end && iterations > 0) {
8688 gen.size++;
8789 gen.index++;
88- gen.values.push(f(currentVal));
90+ const result = f(currentVal);
91+ gen.values.push(Array.isArray(result) ? result.join(' ') : result);
8992 currentVal += gen.timestepRange.step;
9093 iterations--;
9194 }
@@ -102,8 +105,21 @@ export default function generate(program) {
102105 const funcName = targetName ( d . name ) ;
103106 const param = targetName ( d . param ) ;
104107 const body = gen ( d . body ) ;
105- const lastStmt = body . pop ( ) ;
106- output . push ( `function ${ funcName } (${ param } ) {\n${ body } \nreturn ${ lastStmt } ;\n} ` ) ;
108+
109+ // check for slices in the body of the function
110+ if ( d . body . kind === "SliceExpr" ) {
111+ const sliceExpressions = d . body . expressions . map ( expr => {
112+ return `${ gen ( expr ) } ` ;
113+ } ) . join ( ", " ) ;
114+
115+ output . push ( `function ${ funcName } (${ param } ) {
116+ return [${ sliceExpressions } ];
117+ }` ) ;
118+ } else {
119+ // handle same as before if not a slice
120+ const lastStmt = body . pop ( ) ;
121+ output . push ( `function ${ funcName } (${ param } ) {\n${ body } \nreturn ${ lastStmt } ;\n} ` ) ;
122+ }
107123 if ( ! instantiatedMutableRanges . has ( param ) ) {
108124 output . push ( `let ${ param } = initializeMutableRange();` ) ;
109125 instantiatedMutableRanges . add ( param )
@@ -129,6 +145,13 @@ export default function generate(program) {
129145 return exprs ;
130146 } ,
131147
148+ //anywhere you see SliceExpr in the code, I added it in ~MS
149+ SliceExpr ( e ) {
150+ const slices = e . expressions . map ( gen ) ;
151+ // join slices with spaces in output
152+ return `[${ slices . join ( ', ' ) } ]` ;
153+ } ,
154+
132155 CondExpr ( e ) {
133156 if ( e . thenBranch ) {
134157 const condleft = gen ( e . leftCond ) ;
0 commit comments