<commit_before>package scala.meta.internal
package interpreter

import scala.util.matching._
import scala.meta._
import scala.meta.semantic._
import scala.meta.internal.{ ast => i }
import scala.meta.dialects.Scala211

import scala.collection.immutable.ListMap
import scala.meta.internal.interpreter.environment._

object Interpreter {
  def eval(term: Term)(implicit c: Context): Any = {
    val (Object(v, tpe, fields), env) =
      eval(term, Env(List(ListMap[i.Term.Name, Object]()), ListMap[i.Term.Name, Object]()))
    v
  }

  def eval(term: Tree, env: Env)(implicit c: Context): (Object, Env) = {
    term match {
      case i.Term.Block(stats) =>
        stats.foldLeft((Object((), t"Unit"), env))((res, stat) => eval(stat, res._2))

      case nme @ i.Term.Name(_) =>
        (env.lookup(nme), env)

      // TODO dispatch to pattern matching in an elegant way
      case i.Defn.Val(mods, List(i.Pat.Var.Term(name)), tpe, body) =>
        val (res, newEnv) = eval(body, env)
        // TODO depends of the context (method body or template)
        (Object((), t"Unit"), newEnv.push(name, res))

      // ASK Eugene if we can replace them with one!
      case i.Lit.Int(v) =>
        (Object(v, t"Int"), env)
      case i.Lit.String(v) =>
        (Object(v, t"String"), env)
      case i.Lit.Bool(v) =>
        (Object(v, t"Boolean"), env)

      // TODO introduce a method in the interpreter!
      case i.Term.ApplyInfix(lhs, op, _, args) =>
        val method = lhs.tpe.members.filter(_.name == op).head
        val (lhsV, newEnv) = eval(lhs, env)<commit_msg>Support for tuples.<commit_after>package scala.meta.internal
package interpreter

import scala.util.matching._
import scala.meta._
import scala.meta.semantic._
import scala.meta.internal.{ ast => i }
import scala.meta.dialects.Scala211

import scala.collection.immutable.ListMap
import scala.meta.internal.interpreter.environment._

object Interpreter {
  def eval(term: Term)(implicit c: Context): Any = {
    val (Object(v, tpe, fields), env) =
      eval(term, Env(List(ListMap[i.Term.Name, Object]()), ListMap[i.Term.Name, Object]()))
    v
  }

  def eval(term: Tree, env: Env)(implicit c: Context): (Object, Env) = {
    term match {
      case i.Term.Block(stats) =>
        stats.foldLeft((Object((), t"Unit"), env))((res, stat) => eval(stat, res._2))

      case nme @ i.Term.Name(_) =>
        (env.lookup(nme), env)

      // TODO dispatch to pattern matching in an elegant way
      case i.Defn.Val(mods, List(i.Pat.Var.Term(name)), tpe, body) =>
        val (res, newEnv) = eval(body, env)
        // TODO depends of the context (method body or template)
        (Object((), t"Unit"), newEnv.push(name, res))

      // ASK Eugene if we can replace them with one!
      case i.Lit.Int(v) =>
        (Object(v, t"Int"), env)
      case i.Lit.String(v) =>
        (Object(v, t"String"), env)
      case i.Lit.Bool(v) =>
        (Object(v, t"Boolean"), env)

      case i.Term.Tuple(terms) =>
        val (res, env1) = evalSeq(terms, env)
        (Object((res.head.ref, res.tail.head.ref), t"(AnyRef, AnyRef)"), env1) // TODO other cases

      // TODO introduce a method in the interpreter!
      case i.Term.ApplyInfix(lhs, op, _, args) =>
        val method = lhs.tpe.members.filter(_.name == op).head
        val (lhsV, newEnv) = eval(lhs, env)
{'fraction_non_alphanumeric': 0.15895432692307693, 'fraction_numerical': 0.0030048076923076925, 'mean_word_length': 2.898126463700234, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 22, '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': '5395468', 'n_tokens_mistral': 1164, 'n_tokens_neox': 1134, 'n_words': 294}