4343import Absyn ;
4444import AvlSetCR ;
4545import DAE ;
46+ import Mutable ;
4647import SCode ;
4748import Prefix ;
4849
@@ -408,7 +409,7 @@ public type StructuralParameters = tuple<AvlSetCR.Tree,list<list<DAE.ComponentRe
408409public uniontype Cache
409410 record CACHE
410411 Option < Graph > initialGraph "and the initial environment" ;
411- array < DAE . FunctionTree > functions "set of Option<DAE.Function>; NONE() means instantiation started; SOME() means it's finished" ;
412+ Mutable < DAE . FunctionTree > functions "set of Option<DAE.Function>; NONE() means instantiation started; SOME() means it's finished" ;
412413 StructuralParameters evaluatedParams "ht of prefixed crefs and a stack of evaluated but not yet prefix crefs" ;
413414 Absyn . Path modelName "name of the model being instantiated" ;
414415 Absyn . Program program "send the program around if we don't have a symbol table" ;
@@ -437,10 +438,10 @@ public function emptyCache
437438"returns an empty cache"
438439 output Cache cache;
439440protected
440- array < DAE . FunctionTree > instFuncs;
441+ Mutable < DAE . FunctionTree > instFuncs;
441442 StructuralParameters ht;
442443algorithm
443- instFuncs := arrayCreate( 1 , DAE . AvlTreePathFunction . Tree . EMPTY ());
444+ instFuncs := Mutable . create( DAE . AvlTreePathFunction . Tree . EMPTY ());
444445 ht := (AvlSetCR . EMPTY (),{});
445446 cache := CACHE (NONE (),instFuncs,ht,Absyn . IDENT ("##UNDEFINED##" ),Absyn . dummyProgram);
446447end emptyCache;
@@ -461,7 +462,7 @@ algorithm
461462 ocache := match (cache,var ,cr)
462463 local
463464 Option < Graph > initialGraph;
464- array < DAE . FunctionTree > functions;
465+ Mutable < DAE . FunctionTree > functions;
465466 AvlSetCR . Tree ht;
466467 list< list< DAE . ComponentRef >> st;
467468 list< DAE . ComponentRef > crs;
@@ -502,7 +503,7 @@ public function setCacheClassName
502503algorithm
503504 outCache := match(inCache,p)
504505 local
505- array < DAE . FunctionTree > ef;
506+ Mutable < DAE . FunctionTree > ef;
506507 StructuralParameters ht;
507508 Option < Graph > igraph;
508509 Absyn . Program program;
@@ -537,10 +538,10 @@ public function getCachedInstFunc
537538algorithm
538539 func := match(inCache,path)
539540 local
540- array < DAE . FunctionTree > ef;
541+ Mutable < DAE . FunctionTree > ef;
541542 case (CACHE (functions= ef),_)
542543 equation
543- SOME (func ) = DAE . AvlTreePathFunction . get(arrayGet (ef, 1 ),path);
544+ SOME (func ) = DAE . AvlTreePathFunction . get(Mutable . access (ef),path);
544545 then func ;
545546 end match;
546547end getCachedInstFunc;
@@ -552,9 +553,9 @@ public function checkCachedInstFuncGuard
552553algorithm
553554 _ := match(inCache,path)
554555 local
555- array < DAE . FunctionTree > ef;
556+ Mutable < DAE . FunctionTree > ef;
556557 case (CACHE (functions= ef),_) equation
557- _ = DAE . AvlTreePathFunction . get(arrayGet (ef, 1 ),path);
558+ DAE . AvlTreePathFunction . get(Mutable . access (ef),path);
558559 then ();
559560 end match;
560561end checkCachedInstFuncGuard;
@@ -566,8 +567,8 @@ public function getFunctionTree
566567algorithm
567568 ft := match cache
568569 local
569- array < DAE . FunctionTree > ef;
570- case CACHE (functions = ef) then arrayGet (ef, 1 );
570+ Mutable < DAE . FunctionTree > ef;
571+ case CACHE (functions = ef) then Mutable . access (ef);
571572 else DAE . AvlTreePathFunction . Tree . EMPTY ();
572573 end match;
573574end getFunctionTree;
@@ -581,7 +582,7 @@ This guards against recursive functions."
581582algorithm
582583 outCache := matchcontinue(cache,func )
583584 local
584- array < DAE . FunctionTree > ef;
585+ Mutable < DAE . FunctionTree > ef;
585586 Option < Graph > igraph;
586587 StructuralParameters ht;
587588 Absyn . Path p;
@@ -596,9 +597,9 @@ algorithm
596597
597598 case (CACHE (igraph,ef,ht,p,program),Absyn . FULLYQUALIFIED (_))
598599 equation
599- ef = arrayUpdate (ef,1 , DAE . AvlTreePathFunction . add(arrayGet (ef, 1 ),func ,NONE ()));
600+ Mutable . update (ef,DAE . AvlTreePathFunction . add(Mutable . access (ef),func ,NONE ()));
600601 // print("Func quard [new]: " + Absyn.pathString(func) + "\n");
601- then CACHE (igraph,ef,ht,p,program) ;
602+ then cache ;
602603
603604 // Non-FQ paths mean aliased functions; do not add these to the cache
604605 case (_,_)
@@ -617,16 +618,16 @@ public function addDaeFunction
617618algorithm
618619 outCache := match(inCache,funcs)
619620 local
620- array < DAE . FunctionTree > ef;
621+ Mutable < DAE . FunctionTree > ef;
621622 Option < Graph > igraph;
622623 StructuralParameters ht;
623624 Absyn . Path p;
624625 Absyn . Program program;
625626
626627 case (CACHE (igraph,ef,ht,p,program),_)
627628 equation
628- ef = arrayUpdate (ef,1 , DAEUtil . addDaeFunction(funcs, arrayGet (ef, 1 )));
629- then CACHE (igraph,ef,ht,p,program) ;
629+ Mutable . update (ef,DAEUtil . addDaeFunction(funcs, Mutable . access (ef)));
630+ then inCache ;
630631 else inCache;
631632
632633 end match;
@@ -640,16 +641,16 @@ public function addDaeExtFunction
640641algorithm
641642 outCache := match(inCache,funcs)
642643 local
643- array < DAE . FunctionTree > ef;
644+ Mutable < DAE . FunctionTree > ef;
644645 Option < Graph > igraph;
645646 StructuralParameters ht;
646647 Absyn . Path p;
647648 Absyn . Program program;
648649
649650 case (CACHE (igraph,ef,ht,p,program),_)
650651 equation
651- ef = arrayUpdate (ef,1 , DAEUtil . addDaeExtFunction(funcs, arrayGet (ef, 1 )));
652- then CACHE (igraph,ef,ht,p,program) ;
652+ Mutable . update (ef,DAEUtil . addDaeExtFunction(funcs, Mutable . access (ef)));
653+ then inCache ;
653654 else inCache;
654655
655656 end match;
@@ -672,7 +673,7 @@ public function setProgramInCache
672673algorithm
673674 outCache := match(inCache,program)
674675 local
675- array < DAE . FunctionTree > ef;
676+ Mutable < DAE . FunctionTree > ef;
676677 StructuralParameters ht;
677678 Absyn . Path p;
678679 Option < Graph > ograph;
@@ -685,20 +686,13 @@ end setProgramInCache;
685686public function setCachedFunctionTree
686687 input Cache inCache;
687688 input DAE . FunctionTree inFunctions;
688- output Cache outCache;
689- protected
690- Option < Graph > og;
691- array< DAE . FunctionTree > ef;
692- StructuralParameters ht;
693- Absyn . Path p;
694- Absyn . Program program;
695689algorithm
696- outCache := match ( inCache,inFunctions)
697- case ( CACHE (og, _, ht, p, program), _ )
690+ _ := match inCache
691+ case CACHE ()
698692 equation
699- ef = arrayCreate( 1 , inFunctions);
700- then CACHE (og, ef, ht, p, program );
701- else inCache ;
693+ Mutable . update(inCache . functions , inFunctions);
694+ then ( );
695+ else () ;
702696 end match;
703697end setCachedFunctionTree;
704698
@@ -737,19 +731,21 @@ algorithm
737731end getCachedInitialGraph;
738732
739733public function setCachedInitialGraph "set the initial environment in the cache"
740- input Cache inCache ;
734+ input output Cache cache ;
741735 input Graph g;
742- output Cache outCache;
743736algorithm
744- outCache := match(inCache,g)
737+ cache := match cache
745738 local
746- array < DAE . FunctionTree > ef;
739+ Mutable < DAE . FunctionTree > ef;
747740 StructuralParameters ht;
748741 Absyn . Path p;
749742 Absyn . Program program;
750743
751- case (CACHE (_,ef,ht,p,program),_) then CACHE (SOME (g),ef,ht,p,program);
752- else inCache;
744+ case CACHE ()
745+ algorithm
746+ cache. initialGraph := SOME (g);
747+ then cache;
748+ else cache;
753749
754750 end match;
755751end setCachedInitialGraph;
0 commit comments