<commit_before>import sys
import os

from   rpython.rlib.rarithmetic import string_to_int as stoi

def mainloop( insts ):
  pc = 0
  rf = [0] * 32

  while pc < len( insts ):

    inst, f0, f1, f2 = insts[ pc ]

    if   inst == 'addiu':
      rd, rs, imm = int(f0[1:]), int(f1[1:]), stoi(f2,base=16)
      rf[ rd ] = rf[ rs ] + imm

    elif inst == 'addu':
      rd, rs, rt  = int(f0[1:]), int(f1[1:]), int(f2[1:])
      rf[ rd ] = rf[ rs ] + rf[ rt ]

    elif inst == 'print':
      _, _, rt = f0, f1, int(f2[1:])
      result = f2 + ' = ' + str( rf[rt] ) + '\n'
      os.write( 1, result )

    pc += 1

#-----------------------------------------------------------------------
# RegisterFile
#-----------------------------------------------------------------------
class RegisterFile( object ):
  def __init__( self ):
    self.regs = [0] * 32
  #def __getitem__( self, idx ):
  #  return self.regs[idx]
  #def __setitem__( self, idx, value ):
  #  self.regs[idx] = value
  def rd( self, idx ):
    return self.regs[idx]
  def wr( self, idx, value ):
    self.regs[idx] = value

#-----------------------------------------------------------------------
# parse
#-----------------------------------------------------------------------
def parse( fp ):
  insts = []
  line  = ''
  last  = None

  for char in fp.read():
    if char == '\n' and line:
      inst, f0, f1, f2 = line.split(' ',3 )
      insts.append([inst, f0, f1, f2])
      line = ''
      last = None
    elif char != ',' and not (last == char == ' '):
      line += char
      last  = char

  return insts

#-----------------------------------------------------------------------
# run
#-----------------------------------------------------------------------
def run(fp):<commit_msg>[rpython] RegFile works with pypy source 72338:d3b83138e0d7<commit_after>import sys
import os

from   rpython.rlib.rarithmetic import string_to_int as stoi

def mainloop( insts ):
  pc = 0
  rf = RegisterFile()

  while pc < len( insts ):

    inst, f0, f1, f2 = insts[ pc ]

    if   inst == 'addiu':
      rd, rs, imm = int(f0[1:]), int(f1[1:]), stoi(f2,base=16)
      rf[ rd ] = rf[ rs ] + imm

    elif inst == 'addu':
      rd, rs, rt  = int(f0[1:]), int(f1[1:]), int(f2[1:])
      rf[ rd ] = rf[ rs ] + rf[ rt ]

    elif inst == 'print':
      _, _, rt = f0, f1, int(f2[1:])
      result = f2 + ' = ' + str( rf[rt] ) + '\n'
      os.write( 1, result )

    pc += 1

#-----------------------------------------------------------------------
# RegisterFile
#-----------------------------------------------------------------------
class RegisterFile( object ):
  def __init__( self ):
    self.regs = [0] * 32
  def __getitem__( self, idx ):
    return self.regs[idx]
  def __setitem__( self, idx, value ):
    self.regs[idx] = value

#-----------------------------------------------------------------------
# parse
#-----------------------------------------------------------------------
def parse( fp ):
  insts = []
  line  = ''
  last  = None

  for char in fp.read():
    if char == '\n' and line:
      inst, f0, f1, f2 = line.split(' ',3 )
      insts.append([inst, f0, f1, f2])
      line = ''
      last = None
    elif char != ',' and not (last == char == ' '):
      line += char
      last  = char

  return insts

#-----------------------------------------------------------------------
# run
#-----------------------------------------------------------------------
def run(fp):
{'fraction_non_alphanumeric': 0.3807312826465467, 'fraction_numerical': 0.024376088218224026, 'mean_word_length': 1.0827794561933535, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '7006182', 'n_tokens_mistral': 1121, 'n_tokens_neox': 1066, 'n_words': 301}