<commit_before>package interp

import (
	"go/build"
	"io/ioutil"
	"log"
	"os"
	"path/filepath"
)

func (interp *Interpreter) importSrcFile(path string) {
	dir := pkgDir(path)
	files, err := ioutil.ReadDir(dir)
	if err != nil {
		log.Fatal(err)
	}
	for _, file := range files {
		name := file.Name()
		if len(name) <= 3 || name[len(name)-3:] != ".go" {
			continue
		}
		if len(name) > 8 && name[len(name)-8:] == "_test.go" {
			continue
		}
		//log.Println("src", name)
		buf, err := ioutil.ReadFile(filepath.Join(dir, name))
		if err != nil {
			log.Fatal(err)
		}
		interp.Eval(string(buf))
	}
}

func pkgDir(path string) string {
	dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
	if err != nil {
		log.Fatal(err)
	}
	dir = filepath.Join(dir, "vendor", path)
	if _, err := os.Stat(dir); err == nil {
		return dir
	}
	dir = filepath.Join(build.Default.GOPATH, "src", path)
	if _, err := os.Stat(dir); err != nil {
		log.Fatal(err)
	}
	return dir
}<commit_msg>src: execute entry point and init functions after all package files are parsed.<commit_after>package interp

import (
	"go/build"
	"io/ioutil"
	"log"
	"os"
	"path/filepath"
)

func (interp *Interpreter) importSrcFile(path string) {
	dir := pkgDir(path)

	files, err := ioutil.ReadDir(dir)
	if err != nil {
		log.Fatal(err)
	}

	initNodes := []*Node{}
	rootNodes := []*Node{}

	// Parse source files
	for _, file := range files {
		name := file.Name()
		if len(name) <= 3 || name[len(name)-3:] != ".go" {
			continue
		}
		if len(name) > 8 && name[len(name)-8:] == "_test.go" {
			continue
		}

		//log.Println("src", name)
		buf, err := ioutil.ReadFile(filepath.Join(dir, name))
		if err != nil {
			log.Fatal(err)
		}

		_, root := interp.Ast(string(buf))
		initNodes = append(initNodes, interp.Cfg(root)...)
		rootNodes = append(rootNodes, root)
		if interp.AstDot {
			root.AstDot(DotX())
		}
	}

	if interp.NoRun {
		return
	}

	// Once all package sources have been parsed, execute entry points then init functions
	for _, n := range rootNodes {
		interp.fsize++
		interp.resizeFrame()
		runCfg(n.start, interp.Frame)
	}

	for _, n := range initNodes {
		Run(n, interp.Frame, nil, nil, nil, nil, true, false)
	}
}

// pkgDir returns the abolute path in filesystem for a package given its name
func pkgDir(path string) string {
	dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
	if err != nil {
		log.Fatal(err)
	}

	dir = filepath.Join(dir, "vendor", path)
	if _, err := os.Stat(dir); err == nil {
		return dir
	}

	dir = filepath.Join(build.Default.GOPATH, "src", path)
	if _, err := os.Stat(dir); err != nil {
		log.Fatal(err)
	}

	return dir
}
{'fraction_non_alphanumeric': 0.172782874617737, 'fraction_numerical': 0.00382262996941896, 'mean_word_length': 3.368948247078464, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1621460', 'n_tokens_mistral': 1110, 'n_tokens_neox': 1023, 'n_words': 248}