#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   // Define a variable 'x' that will be used in our expression
   auto variableX = uc.DefineVariable("x As Int");

   // Parse an expression that will result in an unsigned 8-bit integer (0-255)
   auto parsedExpr = uc.Parse("x + 125", "Int8u");

   cout << "x | Int8u (0 to 255) | Int8 (-128 to 127)" << endl;
   cout << "------------------------------------------" << endl;

   for (int x = 1; x <= 5; x++) {
      variableX.ValueInt32(x);

      // Evaluate the expression to get a pointer to the result
      auto resultPtr = parsedExpr.EvaluateVoid();

      // Get the raw unsigned result
      auto unsignedResult = uc.ValueAt(resultPtr, "Int8u");

      // Use ValueAt to *re-interpret* the same memory as a signed byte
      auto signedResult = uc.ValueAt(resultPtr, "Int8");

      cout << x << " | " << unsignedResult << " | " << signedResult << endl;
   }

   // Clean up the created items
   parsedExpr.Release();
   variableX.Release();
}