<commit_before>
# pull in external modules
util = require './util'
fs = node?.fs ? require 'fs'
{trace,error} = require '../src/logging'
"use strict"

# things assigned to root will be available outside this module
root = exports ? this.jvm = {}

root.classpath = []
root.show_NYI_natives = false
root.dump_state = false

root.read_classfile = (cls, cb, failure_cb) ->
  cls = cls[1...-1] # Convert Lfoo/bar/Baz; -> foo/bar/Baz.
  for p in root.classpath
    filename = "#{p}/#{cls}.class"
    try
      continue unless fs.existsSync filename
      data = util.bytestr_to_array fs.readFileSync(filename, 'binary')
      cb(data) if data?
      return
    catch e
      failure_cb(()->throw e) # Signifies an error occurred.
      return

  failure_cb (()->throw new Error "Error: No file found for class #{cls}.")

# main function that gets called from the frontend
root.run_class = (rs, class_name, cmdline_args, done_cb) ->
  class_descriptor = "L#{class_name};"
  main_spec = class: class_descriptor, sig: 'main([Ljava/lang/String;)V'
  main_method = null
  run_main = ->
    trace "run_main"
    rs.run_until_finished (->
      rs.async_op (resume_cb, except_cb) ->
        rs.get_bs_cl().initialize_class rs, class_descriptor, ((cls)->
          rs.init_args cmdline_args
          # wrap it in run_until_finished to handle any exceptions correctly
          rs.run_until_finished (-> main_method = cls.method_lookup rs, main_spec), true, (success) ->
            return done_cb?() unless success and main_method?
            rs.run_until_finished (-> main_method.setup_stack(rs)), false, (success) ->
              done_cb?() if success
        ), except_cb
    )

  run_program = ->
    trace "run_program"
    rs.run_until_finished (-> rs.init_threads()), true, (success) ->
      return unless success<commit_msg>Minor fix for missing params.<commit_after>
# pull in external modules
util = require './util'
fs = node?.fs ? require 'fs'
{trace,error} = require '../src/logging'
"use strict"

# things assigned to root will be available outside this module
root = exports ? this.jvm = {}

root.classpath = []
root.show_NYI_natives = false
root.dump_state = false

root.read_classfile = (cls, cb, failure_cb) ->
  cls = cls[1...-1] # Convert Lfoo/bar/Baz; -> foo/bar/Baz.
  for p in root.classpath
    filename = "#{p}/#{cls}.class"
    try
      continue unless fs.existsSync filename
      data = util.bytestr_to_array fs.readFileSync(filename, 'binary')
      cb(data) if data?
      return
    catch e
      failure_cb(()->throw e) # Signifies an error occurred.
      return

  failure_cb (()->throw new Error "Error: No file found for class #{cls}.")

# main function that gets called from the frontend
root.run_class = (rs, class_name, cmdline_args, done_cb) ->
  class_descriptor = "L#{class_name};"
  main_spec = class: class_descriptor, sig: 'main([Ljava/lang/String;)V'
  main_method = null
  run_main = ->
    trace "run_main"
    rs.run_until_finished (->
      rs.async_op (resume_cb, except_cb) ->
        rs.get_bs_cl().initialize_class rs, class_descriptor, ((cls)->
          rs.init_args cmdline_args
          # wrap it in run_until_finished to handle any exceptions correctly
          rs.run_until_finished (-> main_method = cls.method_lookup rs, main_spec), true, (success) ->
            return done_cb?() unless success and main_method?
            rs.run_until_finished (-> main_method.setup_stack(rs)), false, (success) ->
              done_cb?() if success
        ), except_cb
    ), true, (->)

  run_program = ->
    trace "run_program"
    rs.run_until_finished (-> rs.init_threads()), true, (success) ->
      return unless success
{'fraction_non_alphanumeric': 0.125, 'fraction_numerical': 0.0010893246187363835, 'mean_word_length': 3.076581576026637, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 36, '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': '5345630', 'n_tokens_mistral': 1169, 'n_tokens_neox': 1174, 'n_words': 320}