<commit_before>--[[
		Memory Gates
]]

GateActions("Memory")

GateActions["latch"] = {
	name = "Latch (Edge triggered)",
	inputs = { "Data", "Clk" },
	output = function(gate, Data, Clk)
		local clk = (Clk > 0)
		if (gate.PrevValue ~= clk) then
			gate.PrevValue = clk
			if (clk) then
				gate.LatchStore = Data
			end
		end
		return gate.LatchStore or 0
	end,
	reset = function(gate)
		gate.LatchStore = 0
		gate.PrevValue = nil
	end,
	label = function(Out, Data, Clk)
		return "Latch Data:"..Data.."  Clock:"..Clk.." = "..Out
	end
}

GateActions["dlatch"] = {
	name = "D-Latch",
	inputs = { "Data", "Clk" },
	output = function(gate, Data, Clk)
		if (Clk > 0) then
			gate.LatchStore = Data
		end
		return gate.LatchStore or 0
	end,
	reset = function(gate)
		gate.LatchStore = 0
	end,
	label = function(Out, Data, Clk)
		return "D-Latch Data:"..Data.."  Clock:"..Clk.." = "..Out
	end
}

GateActions["srlatch"] = {
	name = "SR-Latch",
	inputs = { "S", "R" },
	output = function(gate, S, R)
		if (S > 0) and (R <= 0) then
			gate.LatchStore = 1
		elseif (S <= 0) and (R > 0) then
			gate.LatchStore = 0
		end
		return gate.LatchStore
	end,
	reset = function(gate)
		gate.LatchStore = 0
	end,
	label = function(Out, S, R)
		return "S:"..S.." R:"..R.." == "..Out
	end
}

GateActions["rslatch"] = {
	name = "RS-Latch",
	inputs = { "S", "R" },
	output = function(gate, S, R)
		if (S > 0) and (R < 1) then
			gate.LatchStore = 1
		elseif (R > 0) then
			gate.LatchStore = 0
		end
		return gate.LatchStore
	end,
	reset = function(gate)
		gate.LatchStore = 0
	end,
	label = function(Out, S, R)
		return "S:"..S.." R:"..R.." == "..Out
	end
}

GateActions["toggle"] = {
	name = "Toggle (Edge triggered)",
	inputs = { "Clk", "OnValue", "OffValue" },
	output = function(gate, Clk, OnValue, OffValue)
		local clk = (Clk > 0)
		if (gate.PrevValue ~= clk) then
			gate.PrevValue = clk
			if (clk) then
				gate.LatchStore = (not gate.LatchStore)
			end
		end

		if (gate.LatchStore) then return OnValue end
		return OffValue
	end,
	reset = function(gate)
		gate.LatchStore = 0
		gate.PrevValue = nil
	end,
	label = function(Out, Clk, OnValue, OffValue)
		return "Off:"..OffValue.."  On:"..OnValue.."  Clock:"..Clk.." = "..Out
	end
}

GateActions["wom4"] = {
	name = "Write Only Memory(4 store)",
	inputs = { "Clk", "AddrWrite", "Data" },
	output = function( gate, Clk, AddrWrite, Data )
		AddrWrite = math.floor(tonumber(AddrWrite))
		if ( Clk > 0 ) then
			if ( AddrWrite >= 0 ) and ( AddrWrite < 4 ) then
				gate.LatchStore[AddrWrite] = Data
			end
		end
		return 0<commit_msg>Toggle (Edge Triggered) now defaults to OffValue fixes #692<commit_after>--[[
		Memory Gates
]]

GateActions("Memory")

GateActions["latch"] = {
	name = "Latch (Edge triggered)",
	inputs = { "Data", "Clk" },
	output = function(gate, Data, Clk)
		local clk = (Clk > 0)
		if (gate.PrevValue ~= clk) then
			gate.PrevValue = clk
			if (clk) then
				gate.LatchStore = Data
			end
		end
		return gate.LatchStore or 0
	end,
	reset = function(gate)
		gate.LatchStore = 0
		gate.PrevValue = nil
	end,
	label = function(Out, Data, Clk)
		return "Latch Data:"..Data.."  Clock:"..Clk.." = "..Out
	end
}

GateActions["dlatch"] = {
	name = "D-Latch",
	inputs = { "Data", "Clk" },
	output = function(gate, Data, Clk)
		if (Clk > 0) then
			gate.LatchStore = Data
		end
		return gate.LatchStore or 0
	end,
	reset = function(gate)
		gate.LatchStore = 0
	end,
	label = function(Out, Data, Clk)
		return "D-Latch Data:"..Data.."  Clock:"..Clk.." = "..Out
	end
}

GateActions["srlatch"] = {
	name = "SR-Latch",
	inputs = { "S", "R" },
	output = function(gate, S, R)
		if (S > 0) and (R <= 0) then
			gate.LatchStore = 1
		elseif (S <= 0) and (R > 0) then
			gate.LatchStore = 0
		end
		return gate.LatchStore
	end,
	reset = function(gate)
		gate.LatchStore = 0
	end,
	label = function(Out, S, R)
		return "S:"..S.." R:"..R.." == "..Out
	end
}

GateActions["rslatch"] = {
	name = "RS-Latch",
	inputs = { "S", "R" },
	output = function(gate, S, R)
		if (S > 0) and (R < 1) then
			gate.LatchStore = 1
		elseif (R > 0) then
			gate.LatchStore = 0
		end
		return gate.LatchStore
	end,
	reset = function(gate)
		gate.LatchStore = 0
	end,
	label = function(Out, S, R)
		return "S:"..S.." R:"..R.." == "..Out
	end
}

GateActions["toggle"] = {
	name = "Toggle (Edge triggered)",
	inputs = { "Clk", "OnValue", "OffValue" },
	output = function(gate, Clk, OnValue, OffValue)
		local clk = (Clk > 0)
		if (gate.PrevValue ~= clk) then
			gate.PrevValue = clk
			if (clk) then
				gate.LatchStore = (not gate.LatchStore)
			end
		end

		if (gate.LatchStore) then return OnValue end
		return OffValue
	end,
	reset = function(gate)
		gate.LatchStore = false
		gate.PrevValue = nil
	end,
	label = function(Out, Clk, OnValue, OffValue)
		return "Off:"..OffValue.."  On:"..OnValue.."  Clock:"..Clk.." = "..Out
	end
}

GateActions["wom4"] = {
	name = "Write Only Memory(4 store)",
	inputs = { "Clk", "AddrWrite", "Data" },
	output = function( gate, Clk, AddrWrite, Data )
		AddrWrite = math.floor(tonumber(AddrWrite))
		if ( Clk > 0 ) then
			if ( AddrWrite >= 0 ) and ( AddrWrite < 4 ) then
				gate.LatchStore[AddrWrite] = Data
			end
		end
		return 0
{'fraction_non_alphanumeric': 0.1723938223938224, 'fraction_numerical': 0.010810810810810811, 'mean_word_length': 2.9884526558891453, 'pattern_counts': {'":': 0, '<': 11, '<?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': '4479854', 'n_tokens_mistral': 2271, 'n_tokens_neox': 2050, 'n_words': 557}