<commit_before>(*make code easier to read*)
structure A = Absyn
structure T = Types
structure E = Envir
structure S = Symbol
(*define return type of trans* functions*)
structure Translate = struct type exp = unit end

signature SEM = 
sig
	(*more meaningful/easier to read types*)
	type venvTable
	type tenvTable
	type expty
	type ty

	val transVar: venvTable * tenvTable * Absyn.var -> expty
	val transExp: venvTable * tenvTable * Absyn.exp -> expty
	val transDec: venvTable * tenvTable * Absyn.dec -> {venv: venvTable, tenv: tenvTable}
	val transTy:   	     	  tenvTable * Absyn.ty -> ty
	val transProg:        			      Absyn.exp -> unit
end

structure Semant :> SEM = 
struct

(*more meaningful/easier to read types*)
type venvTable = E.enventry S.table
type tenvTable = T.ty S.table
type expty = {exp: Translate.exp, ty: T.ty}
type ty = T.ty
val error = ErrorMsg.error
val nestDepth = ref 0
val numBreaks = ref 0

val refCount = ref 0

fun incNumBreaks () = numBreaks := !numBreaks + 1
fun decNumBreaks () = numBreaks := !numBreaks - 1
fun incNestDepth () = nestDepth := !nestDepth + 1
fun decNestDepth () = nestDepth := !nestDepth - 1

fun lookupType (tenv, typSymbol, pos) = 
  (case S.look (tenv, typSymbol) of
    SOME ty => ty
  | NONE => (error pos ("type is not defined: "^(S.name typSymbol)); T.UNIT))


structure MySet = ListSetFn (struct
  type ord_key = A.symbol
  val compare = (fn (_,_) => General.EQUAL)
end)

fun noRepeatName(decList) = 
	let
		fun enterOneDec({name=name, ty=typ, pos=pos}, setSoFar)= MySet.add(setSoFar, name)
	in
		if MySet.numItems(foldr enterOneDec MySet.empty decList) = List.length(decList)
		then true
		else (ErrorMsg.error 0 "Mutually recursive type declarations have repeated names!";false)
	end

fun noRepeatNameFunction(decList) = 
	let
		fun enterOneDec({name=name, params=params, result=result, body=body, pos=pos}, setSoFar) = MySet.add(setSoFar, name)
	in
		if MySet.numItems(foldr enterOneDec MySet.empty decList) = List.length(decList)
		then true
		else (ErrorMsg.error 0 "Mutually recursive function declarations have repeated names!";false)<commit_msg>minor change to repeated name<commit_after>(*make code easier to read*)
structure A = Absyn
structure T = Types
structure E = Envir
structure S = Symbol
(*define return type of trans* functions*)
structure Translate = struct type exp = unit end

signature SEM = 
sig
	(*more meaningful/easier to read types*)
	type venvTable
	type tenvTable
	type expty
	type ty

	val transVar: venvTable * tenvTable * Absyn.var -> expty
	val transExp: venvTable * tenvTable * Absyn.exp -> expty
	val transDec: venvTable * tenvTable * Absyn.dec -> {venv: venvTable, tenv: tenvTable}
	val transTy:   	     	  tenvTable * Absyn.ty -> ty
	val transProg:        			      Absyn.exp -> unit
end

structure Semant :> SEM = 
struct

(*more meaningful/easier to read types*)
type venvTable = E.enventry S.table
type tenvTable = T.ty S.table
type expty = {exp: Translate.exp, ty: T.ty}
type ty = T.ty
val error = ErrorMsg.error
val nestDepth = ref 0
val numBreaks = ref 0

val refCount = ref 0

fun incNumBreaks () = numBreaks := !numBreaks + 1
fun decNumBreaks () = numBreaks := !numBreaks - 1
fun incNestDepth () = nestDepth := !nestDepth + 1
fun decNestDepth () = nestDepth := !nestDepth - 1

fun lookupType (tenv, typSymbol, pos) = 
  (case S.look (tenv, typSymbol) of
    SOME ty => ty
  | NONE => (error pos ("type is not defined: "^(S.name typSymbol)); T.UNIT))


structure MySet = ListSetFn (struct
  type ord_key = A.symbol
  val compare = (fn (_,_) => General.LESS)
end)

fun noRepeatName(decList) = 
	let
		fun enterOneDec({name=name, ty=typ, pos=pos}, setSoFar)= MySet.add(setSoFar, name)
	in
		if MySet.numItems(foldr enterOneDec MySet.empty decList) = List.length(decList)
		then true
		else (ErrorMsg.error 0 "Mutually recursive type declarations have repeated names!";false)
	end

fun noRepeatNameFunction(decList) = 
	let
		fun enterOneDec({name=name, params=params, result=result, body=body, pos=pos}, setSoFar) = MySet.add(setSoFar, name)
	in
		if MySet.numItems(foldr enterOneDec MySet.empty decList) = List.length(decList)
		then true
		else (ErrorMsg.error 0 "Mutually recursive function declarations have repeated names!";false)
{'fraction_non_alphanumeric': 0.10678006142215922, 'fraction_numerical': 0.004252303330970942, 'mean_word_length': 4.070658682634731, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '321642', 'n_tokens_mistral': 1525, 'n_tokens_neox': 1452, 'n_words': 471}