<commit_before>#include <stdio.h>
#include <node.h>
#include <v8.h>
#include <string>
#include "Types.h"
#include "JuliaExecEnv.h"

using namespace std;
using namespace v8;

static JuliaExecEnv *J = 0;

void returnNull(const FunctionCallbackInfo<Value> &args,Isolate *I)
{
   args.GetReturnValue().SetNull();
}

void returnString(const FunctionCallbackInfo<Value> &args,Isolate *I,const string &s)
{
   args.GetReturnValue().Set(String::NewFromUtf8(I,s.c_str()));
}

void callback(const FunctionCallbackInfo<Value>& args,Isolate *I,const Local<Function> &cb,int argc,Local<Value> *argv)
{
  cb->Call(I->GetCurrentContext()->Global(),argc,argv);
}

Local<Value> buildPrimitive(const nj::Primitive &primitive)
{
   Isolate *I = Isolate::GetCurrent();
   EscapableHandleScope scope(I);

   switch(primitive.type()->getId())
   {
      case nj::null_type:
      {
         Local<Value> dest = Null(I);

         return scope.Escape(dest);
      }
      break;
      case nj::boolean_type:
      {
         Local<Value> dest = Boolean::New(I,primitive.toBoolean());

         return scope.Escape(dest);
      }
      break;
      case nj::char_type:
      {
         Local<Value> dest = String::NewFromUtf8(I,primitive.toString().c_str());

         return scope.Escape(dest);
      }
      break;
      case nj::int64_type:
      case nj::int32_type:
      case nj::int16_type:
      {
         Local<Value> dest = Number::New(I,primitive.toInt());

         return scope.Escape(dest);
      }
      break;
      case nj::uint64_type:
      case nj::uint32_type:
      case nj::uint16_type:
      case nj::uchar_type:
      {
         Local<Value> dest = Number::New(I,primitive.toUInt());

         return scope.Escape(dest);
      }
      break;
      case nj::float64_type:
      case nj::float32_type:
      {
         Local<Value> dest = Number::New(I,primitive.toFloat());

         return scope.Escape(dest);
      }
      break;
      case nj::string_type:
      {
         Local<Value> dest = String::NewFromUtf8(I,primitive.toString().c_str());

         return scope.Escape(dest);
      }
      break;
   }

   return scope.Escape(Array::New(I,0));
}

template<typename V,typename E> Local<Array> buildArray(const shared_ptr<nj::Value> &value)
{
   Isolate *I = Isolate::GetCurrent();
   EscapableHandleScope scope(I);
   const nj::Array<V,E> &array = static_cast<const nj::Array<V,E>&>(*value);

   if(array.size() == 0) return Local<Array>();
   if(array.dims().size() == 1)
   {
      size_t size0 = array.dims()[0];
      double *p = array.ptr();
      Local<Array> dest = Array::New(I,size0);

      for(size_t i = 0;i < size0;i++) dest->Set(i,Number::New(I,p[i]));
      return scope.Escape(dest);
   }
   else if(array.dims().size() == 2)
   {
      size_t size0 = array.dims()[0];
      size_t size1 = array.dims()[1];
      double *p = array.ptr();
      Local<Array> dest = Array::New(I,size0);

      for(size_t i = 0;i < size0;i++)
      {
         Local<Array> row  = Array::New(I,size1);

         dest->Set(i,row);
         for(size_t j = 0;j < size1;j++) row->Set(j,Number::New(I,p[size0*j + i]));
      }
      return scope.Escape(dest);
   }
   return scope.Escape(Array::New(I,0));
}

Local<Array> buildArray(const shared_ptr<nj::Value> &value)
{
   const nj::Array_t *array_type = static_cast<const nj::Array_t*>(value->type());
   const nj::Type *element_type = array_type->getElementType();
   Isolate *I = Isolate::GetCurrent();
   EscapableHandleScope scope(I);

   switch(element_type->getId())
   {
      case nj::float64_type:
         return scope.Escape(buildArray<double,nj::Float64_t>(value));
      break;
   }

   return scope.Escape(Array::New(I,0));
}

int buildArgs(Isolate *I,const shared_ptr<vector<shared_ptr<nj::Value>>> &res,int argc,Local<Value> *argv)
{
   int index = 0;

   for(shared_ptr<nj::Value> value: *res)
   {
      if(value.get())
      {
         if(value->isPrimitive())
         {
            const nj::Primitive &primitive = static_cast<const nj::Primitive&>(*value);<commit_msg>Adding Array Types.<commit_after>#include <stdio.h>
#include <node.h>
#include <v8.h>
#include <string>
#include "Types.h"
#include "JuliaExecEnv.h"

using namespace std;
using namespace v8;

static JuliaExecEnv *J = 0;

void returnNull(const FunctionCallbackInfo<Value> &args,Isolate *I)
{
   args.GetReturnValue().SetNull();
}

void returnString(const FunctionCallbackInfo<Value> &args,Isolate *I,const string &s)
{
   args.GetReturnValue().Set(String::NewFromUtf8(I,s.c_str()));
}

void callback(const FunctionCallbackInfo<Value>& args,Isolate *I,const Local<Function> &cb,int argc,Local<Value> *argv)
{
  cb->Call(I->GetCurrentContext()->Global(),argc,argv);
}

Local<Value> buildPrimitive(const nj::Primitive &primitive)
{
   Isolate *I = Isolate::GetCurrent();
   EscapableHandleScope scope(I);

   switch(primitive.type()->getId())
   {
      case nj::null_type:
      {
         Local<Value> dest = Null(I);

         return scope.Escape(dest);
      }
      break;
      case nj::boolean_type:
      {
         Local<Value> dest = Boolean::New(I,primitive.toBoolean());

         return scope.Escape(dest);
      }
      break;
      case nj::char_type:
      {
         Local<Value> dest = String::NewFromUtf8(I,primitive.toString().c_str());

         return scope.Escape(dest);
      }
      break;
      case nj::int64_type:
      case nj::int32_type:
      case nj::int16_type:
      {
         Local<Value> dest = Number::New(I,primitive.toInt());

         return scope.Escape(dest);
      }
      break;
      case nj::uint64_type:
      case nj::uint32_type:
      case nj::uint16_type:
      case nj::uchar_type:
      {
         Local<Value> dest = Number::New(I,primitive.toUInt());

         return scope.Escape(dest);
      }
      break;
      case nj::float64_type:
      case nj::float32_type:
      {
         Local<Value> dest = Number::New(I,primitive.toFloat());

         return scope.Escape(dest);
      }
      break;
      case nj::string_type:
      {
         Local<Value> dest = String::NewFromUtf8(I,primitive.toString().c_str());

         return scope.Escape(dest);
      }
      break;
   }

   return scope.Escape(Array::New(I,0));
}

template<typename V,typename E> Local<Array> buildArray(const shared_ptr<nj::Value> &value)
{
   Isolate *I = Isolate::GetCurrent();
   EscapableHandleScope scope(I);
   const nj::Array<V,E> &array = static_cast<const nj::Array<V,E>&>(*value);

   if(array.size() == 0) return Local<Array>();
   if(array.dims().size() == 1)
   {
      size_t size0 = array.dims()[0];
      V *p = array.ptr();
      Local<Array> dest = Array::New(I,size0);

      for(size_t i = 0;i < size0;i++) dest->Set(i,Number::New(I,p[i]));
      return scope.Escape(dest);
   }
   else if(array.dims().size() == 2)
   {
      size_t size0 = array.dims()[0];
      size_t size1 = array.dims()[1];
      V *p = array.ptr();
      Local<Array> dest = Array::New(I,size0);

      for(size_t i = 0;i < size0;i++)
      {
         Local<Array> row  = Array::New(I,size1);

         dest->Set(i,row);
         for(size_t j = 0;j < size1;j++) row->Set(j,Number::New(I,p[size0*j + i]));
      }
      return scope.Escape(dest);
   }
   return scope.Escape(Array::New(I,0));
}

Local<Array> buildArray(const shared_ptr<nj::Value> &value)
{
   const nj::Array_t *array_type = static_cast<const nj::Array_t*>(value->type());
   const nj::Type *element_type = array_type->getElementType();
   Isolate *I = Isolate::GetCurrent();
   EscapableHandleScope scope(I);

   switch(element_type->getId())
   {
      case nj::float64_type: return scope.Escape(buildArray<double,nj::Float64_t>(value)); break;
      case nj::float32_type: return scope.Escape(buildArray<float,nj::Float32_t>(value)); break;
      case nj::int64_type: return scope.Escape(buildArray<int64_t,nj::Int64_t>(value)); break;
      case nj::int32_type: return scope.Escape(buildArray<int,nj::Int32_t>(value)); break;
      case nj::int16_type: return scope.Escape(buildArray<short,nj::Int16_t>(value)); break;
      case nj::uint64_type: return scope.Escape(buildArray<uint64_t,nj::UInt64_t>(value)); break;
      case nj::uint32_type: return scope.Escape(buildArray<unsigned,nj::UInt32_t>(value)); break;
      case nj::uint16_type: return scope.Escape(buildArray<unsigned short,nj::UInt16_t>(value)); break;
      case nj::char_type: return scope.Escape(buildArray<char,nj::Char_t>(value)); break;
      case nj::uchar_type: return scope.Escape(buildArray<unsigned char,nj::UChar_t>(value)); break;
   }

   return scope.Escape(Array::New(I,0));
}

int buildArgs(Isolate *I,const shared_ptr<vector<shared_ptr<nj::Value>>> &res,int argc,Local<Value> *argv)
{
   int index = 0;

   for(shared_ptr<nj::Value> value: *res)
   {
      if(value.get())
      {
         if(value->isPrimitive())
         {
            const nj::Primitive &primitive = static_cast<const nj::Primitive&>(*value);
{'fraction_non_alphanumeric': 0.164503133393017, 'fraction_numerical': 0.014547896150402865, 'mean_word_length': 3.3111432706222867, 'pattern_counts': {'":': 0, '<': 92, '<?xml version=': 0, '>': 108, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '851684', 'n_tokens_mistral': 3194, 'n_tokens_neox': 3164, 'n_words': 536}