<commit_before>package main

import (
	"flag"
	"fmt"
	"io/ioutil"
	"os"
	"plaid/check"
	"plaid/codegen"
	"plaid/debug"
	"plaid/libs"
	"plaid/parser"
	"plaid/vm"
)

func main() {
	showAST := flag.Bool("ast", false, "output abstract syntax tree")
	showCheck := flag.Bool("check", false, "output type checker results")
	showIR := flag.Bool("ir", false, "output intermediate representation")
	showBC := flag.Bool("bytecode", false, "output bytecode")
	showOut := flag.Bool("out", false, "run program and print output")
	flag.Parse()

	for _, filename := range flag.Args() {
		processFile(filename, *showAST, *showCheck, *showIR, *showBC, *showOut)
	}
}

func processFile(filename string, showAST bool, showCheck bool, showIR bool, showBC bool, showOut bool) {
	buf, err := ioutil.ReadFile(filename)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}

	src := string(buf)
	ast, err := parser.Parse(src)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}

	if showAST {
		fmt.Println(ast.String())
	}

	if showCheck || showIR || showBC || showOut {
		scope := check.Check(ast, libs.IO, libs.Conv)
		if len(scope.Errors()) > 0 {
			for i, err := range scope.Errors() {
				fmt.Printf("%4d %s\n", i, err)
			}
			os.Exit(1)
		} else if showCheck {
			fmt.Println(debug.PrettyTree(scope))
		}

		if showIR || showBC || showOut {
			ir := codegen.Transform(ast, libs.IO, libs.Conv)

			if showIR {
				fmt.Println(ir.String())
			}

			if showBC || showOut {
				mod := codegen.Generate(ir)

				if showBC {
					fmt.Println(debug.PrettyTree(mod.Root))
				}

				if showOut {<commit_msg>use new Scope methods<commit_after>package main

import (
	"flag"
	"fmt"
	"io/ioutil"
	"os"
	"plaid/check"
	"plaid/codegen"
	"plaid/debug"
	"plaid/libs"
	"plaid/parser"
	"plaid/vm"
)

func main() {
	showAST := flag.Bool("ast", false, "output abstract syntax tree")
	showCheck := flag.Bool("check", false, "output type checker results")
	showIR := flag.Bool("ir", false, "output intermediate representation")
	showBC := flag.Bool("bytecode", false, "output bytecode")
	showOut := flag.Bool("out", false, "run program and print output")
	flag.Parse()

	for _, filename := range flag.Args() {
		processFile(filename, *showAST, *showCheck, *showIR, *showBC, *showOut)
	}
}

func processFile(filename string, showAST bool, showCheck bool, showIR bool, showBC bool, showOut bool) {
	buf, err := ioutil.ReadFile(filename)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}

	src := string(buf)
	ast, err := parser.Parse(src)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}

	if showAST {
		fmt.Println(ast.String())
	}

	if showCheck || showIR || showBC || showOut {
		scope := check.Check(ast, libs.IO, libs.Conv)
		if scope.HasErrors() {
			for i, err := range scope.GetErrors() {
				fmt.Printf("%4d %s\n", i, err)
			}
			os.Exit(1)
		} else if showCheck {
			fmt.Println(debug.PrettyTree(scope))
		}

		if showIR || showBC || showOut {
			ir := codegen.Transform(ast, libs.IO, libs.Conv)

			if showIR {
				fmt.Println(ir.String())
			}

			if showBC || showOut {
				mod := codegen.Generate(ir)

				if showBC {
					fmt.Println(debug.PrettyTree(mod.Root))
				}

				if showOut {
{'fraction_non_alphanumeric': 0.1648420394119487, 'fraction_numerical': 0.0028151391929934315, 'mean_word_length': 3.5948275862068964, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '1126036', 'n_tokens_mistral': 1326, 'n_tokens_neox': 1206, 'n_words': 282}