<commit_before>package main

import "text/scanner"
import (
	"os"
	"fmt"
	"io"
	"strings"
	"strconv"
)

const (
	Name = scanner.Ident
	
)


//Deal with scoping for variables.
type Variables map[string]Type

type Compiler struct {
	Scope []Variables
	
	Output io.Writer
	Lib io.Writer
	
	Header bool
	Game bool
	NewGame bool
	UpdateGame bool
	DrawGame bool
	
	Scanner *scanner.Scanner
	Scanners []*scanner.Scanner //Multiple files.
	NextToken string
	
	DefinedTypes map[string]Type
	DefinedFunctions map[string]Function
	CurrentFunction Function
	
	//Flags for compiling.
	SoftwareBlockExists bool
	
	GUIExists bool
	GUIMainExists bool
	
	InSwitchCase bool
	SwitchExpression string
	FirstCase bool
	
	InIssueBlock bool
	FirstIssue bool
	
	Fork bool
	
	InOperatorFunction bool
	
	LastDefinedType Type
	LastDefinedFunction Function
	LastDefinedFunctionName string
	
	ExpressionType Type
	
	Unique int
	
	InPackageDir bool
	FileDepth int
	Dirs []string
}

func (ic *Compiler) Tmp(mod string) string {
	ic.Unique++
	return "i_"+mod+fmt.Sprint(ic.Unique)
}

//This function increases the scope of the compiler for example when it reaches an if statement block.
func (ic *Compiler) asm(asm ...interface{}) string {
	var tabs = strings.Repeat("\t", len(ic.Scope)-1)
	var s = ""
	if len(asm) > 0 {
		if strings.Contains(fmt.Sprint(asm[0]), "%") && len(asm) > 1 {
			s = fmt.Sprintf(tabs+fmt.Sprint(asm[0]), asm[1:]...)
		} else {
			s = fmt.Sprint(tabs+fmt.Sprint(asm...))
		}
	}
	s = strings.Replace(s, "\n", "\n"+tabs, -1)
	return s
}

//This function increases the scope of the compiler for example when it reaches an if statement block.
func (ic *Compiler) Library(asm ...interface{}) {
	fmt.Fprintln(ic.Lib, ic.asm(asm...))
}

//This function increases the scope of the compiler for example when it reaches an if statement block.
func (ic *Compiler) Assembly(asm ...interface{}) {
	fmt.Fprintln(ic.Output, ic.asm(asm...))
}


//This function increases the scope of the compiler for example when it reaches an if statement block.
func (c *Compiler) GainScope() {
	c.Scope = append(c.Scope, make(map[string]Type))
}

//This will return the value of a scopped flag.
func (c *Compiler) GetFlag(sort Type) bool {
	for i:=len(c.Scope)-1; i>=0; i-- {
		if _, ok := c.Scope[i][sort.Name]; ok {
			return true
		}
	}
	return false
}

//This will return the value of a scopped flag.
func (c *Compiler) GetScopedFlag(sort Type) bool {
	if _, ok := c.Scope[len(c.Scope)-1][sort.Name]; ok {
		return true
	}
	return false
}

//This will return the type of the variable. UNDEFINED for undefined variables.
func (ic *Compiler) GetVariable(name string) Type {
	for i:=len(ic.Scope)-1; i>=0; i-- {
		if v, ok := ic.Scope[i][name]; ok {
			ic.Scope[i][name+"_use"] = Used
			return v
		}
	}
	
	//Allow table values to be indexed in a method.
	if ic.GetFlag(InMethod) {
		if _, ok := ic.LastDefinedType.Detail.Table[name]; ok {
			var value = ic.IndexUserType(ic.LastDefinedType.Name, name)
			ic.AssembleVar(name, value)
			return ic.ExpressionType
		}
	}
	
	return Undefined
}

//Set the type of a variable, this is akin to creating or assigning a variable.
func (c *Compiler) SetVariable(name string, sort Type) {
	if !strings.Contains(name, "_") {
		c.SetVariable(name+"_use", Unused)
	}
	c.Scope[len(c.Scope)-1][name] = sort
}

//Set the type of a variable, this is akin to creating or assigning a variable.
func (c *Compiler) SetFlag(flag Type) {
	c.Scope[len(c.Scope)-1][flag.Name] = flag
}

func (ic *Compiler) Peek() string {
	return string(ic.Scanner.Peek())
}

func (c *Compiler) Scan(verify rune) string {
	if c.NextToken != "" {
		var text = c.NextToken
		if verify > 0  && rune(text[0]) != verify {<commit_msg>Don't allow duplicate variable names.<commit_after>package main

import "text/scanner"
import (
	"os"
	"fmt"
	"io"
	"strings"
	"strconv"
)

const (
	Name = scanner.Ident
	
)


//Deal with scoping for variables.
type Variables map[string]Type

type Compiler struct {
	Scope []Variables
	
	Output io.Writer
	Lib io.Writer
	
	Header bool
	Game bool
	NewGame bool
	UpdateGame bool
	DrawGame bool
	
	Scanner *scanner.Scanner
	Scanners []*scanner.Scanner //Multiple files.
	NextToken string
	
	DefinedTypes map[string]Type
	DefinedFunctions map[string]Function
	CurrentFunction Function
	
	//Flags for compiling.
	SoftwareBlockExists bool
	
	GUIExists bool
	GUIMainExists bool
	
	InSwitchCase bool
	SwitchExpression string
	FirstCase bool
	
	InIssueBlock bool
	FirstIssue bool
	
	Fork bool
	
	InOperatorFunction bool
	
	LastDefinedType Type
	LastDefinedFunction Function
	LastDefinedFunctionName string
	
	ExpressionType Type
	
	Unique int
	
	InPackageDir bool
	FileDepth int
	Dirs []string
}

func (ic *Compiler) Tmp(mod string) string {
	ic.Unique++
	return "i_"+mod+fmt.Sprint(ic.Unique)
}

//This function increases the scope of the compiler for example when it reaches an if statement block.
func (ic *Compiler) asm(asm ...interface{}) string {
	var tabs = strings.Repeat("\t", len(ic.Scope)-1)
	var s = ""
	if len(asm) > 0 {
		if strings.Contains(fmt.Sprint(asm[0]), "%") && len(asm) > 1 {
			s = fmt.Sprintf(tabs+fmt.Sprint(asm[0]), asm[1:]...)
		} else {
			s = fmt.Sprint(tabs+fmt.Sprint(asm...))
		}
	}
	s = strings.Replace(s, "\n", "\n"+tabs, -1)
	return s
}

//This function increases the scope of the compiler for example when it reaches an if statement block.
func (ic *Compiler) Library(asm ...interface{}) {
	fmt.Fprintln(ic.Lib, ic.asm(asm...))
}

//This function increases the scope of the compiler for example when it reaches an if statement block.
func (ic *Compiler) Assembly(asm ...interface{}) {
	fmt.Fprintln(ic.Output, ic.asm(asm...))
}


//This function increases the scope of the compiler for example when it reaches an if statement block.
func (c *Compiler) GainScope() {
	c.Scope = append(c.Scope, make(map[string]Type))
}

//This will return the value of a scopped flag.
func (c *Compiler) GetFlag(sort Type) bool {
	for i:=len(c.Scope)-1; i>=0; i-- {
		if _, ok := c.Scope[i][sort.Name]; ok {
			return true
		}
	}
	return false
}

//This will return the value of a scopped flag.
func (c *Compiler) GetScopedFlag(sort Type) bool {
	if _, ok := c.Scope[len(c.Scope)-1][sort.Name]; ok {
		return true
	}
	return false
}

//This will return the type of the variable. UNDEFINED for undefined variables.
func (ic *Compiler) GetVariable(name string) Type {
	for i:=len(ic.Scope)-1; i>=0; i-- {
		if v, ok := ic.Scope[i][name]; ok {
			ic.Scope[i][name+"_use"] = Used
			return v
		}
	}
	
	//Allow table values to be indexed in a method.
	if ic.GetFlag(InMethod) {
		if _, ok := ic.LastDefinedType.Detail.Table[name]; ok {
			var value = ic.IndexUserType(ic.LastDefinedType.Name, name)
			ic.AssembleVar(name, value)
			return ic.ExpressionType
		}
	}
	
	return Undefined
}

//Set the type of a variable, this is akin to creating or assigning a variable.
func (c *Compiler) SetVariable(name string, sort Type) {
	if !strings.Contains(name, "_") {
		c.SetVariable(name+"_use", Unused)
		for i:=len(c.Scope)-1; i>=0; i-- {
			if _, ok := c.Scope[i][name]; ok {
				c.RaiseError("Duplicate variable name!", name)
			}
		}
	}
	c.Scope[len(c.Scope)-1][name] = sort
}

//Set the type of a variable, this is akin to creating or assigning a variable.
func (c *Compiler) SetFlag(flag Type) {
	c.Scope[len(c.Scope)-1][flag.Name] = flag
}

func (ic *Compiler) Peek() string {
	return string(ic.Scanner.Peek())
}

func (c *Compiler) Scan(verify rune) string {
	if c.NextToken != "" {
		var text = c.NextToken
		if verify > 0  && rune(text[0]) != verify {
{'fraction_non_alphanumeric': 0.1301415156725301, 'fraction_numerical': 0.004496759687871975, 'mean_word_length': 3.685254027261462, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, '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': '2830521', 'n_tokens_mistral': 2763, 'n_tokens_neox': 2579, 'n_words': 820}