Interpreter: Refactor interface and lifetime management

Interpreter is now just a namespace with Run and Disassemble. This hides
all of the implementation details. In addition, the interpreter only used
the Program because of a few details in FunctionDeclarations - scrape that
when constructing a ByteCodeFunction, and we don't need to keep the entire
Program alive, just the ByteCode. Adjust tests to ensure that this works.

Change-Id: I61efe4fe986476afedbd295d3d55b2a326fea4e3
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/219521
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/modules/particles/src/SkParticleAffector.cpp b/modules/particles/src/SkParticleAffector.cpp
index caf9f80..ab22088 100644
--- a/modules/particles/src/SkParticleAffector.cpp
+++ b/modules/particles/src/SkParticleAffector.cpp
@@ -479,10 +479,10 @@
     REFLECTED(SkInterpreterAffector, SkParticleAffector)
 
     void onApply(const SkParticleUpdateParams& params, SkParticleState ps[], int count) override {
-        fInterpreter->setInputs((SkSL::Interpreter::Value*)&params);
         for (int i = 0; i < count; ++i) {
             fRandomValue->setRandom(&ps[i].fRandom);
-            fInterpreter->run(*fMain, (SkSL::Interpreter::Value*)&ps[i].fAge, nullptr);
+            SkSL::Interpreter::Run(fByteCode.get(), fMain, (SkSL::Interpreter::Value*)&ps[i].fAge,
+                                   nullptr, (SkSL::Interpreter::Value*)&params, 2);
         }
     }
 
@@ -501,7 +501,7 @@
     SkString fCode;
 
     // Cached
-    std::unique_ptr<SkSL::Interpreter> fInterpreter;
+    std::unique_ptr<SkSL::ByteCode> fByteCode;
     std::unique_ptr<SkRandomExternalValue> fRandomValue;
     SkSL::ByteCodeFunction* fMain;
 
@@ -523,11 +523,8 @@
             return;
         }
 
-        // These will be replaced with the real inputs in onApply, before running
-        SkParticleUpdateParams defaultInputs = { 0.0f, 0.0f, 0 };
         fMain = byteCode->fFunctions[0].get();
-        fInterpreter.reset(new SkSL::Interpreter(std::move(program), std::move(byteCode),
-                                                 (SkSL::Interpreter::Value*)&defaultInputs));
+        fByteCode = std::move(byteCode);
         fRandomValue = std::move(rand);
     }
 };