include "io.alh"
include "primitives.alh"

Void function user_management():
	String username
	Element user_root
	Element user_frame
	Element output_value
	Element input_value
	
	while (True):
		username = input()
		if (string_startswith(username, "__")):
			username = string_substr(username, 2, string_len(username) - 1)
			dict_delete(read_root(), username)
		else:
			if (bool_not(dict_in(read_root(), username))):
				user_root = create_node()
				user_frame = create_node()
				output_value = create_node()
				input_value = create_node()
				dict_add(user_root, "frame", user_frame)
				dict_add(user_root, "globals", create_node())
				dict_add(user_root, "output", output_value)
				dict_add(user_root, "last_output", output_value)
				dict_add(user_root, "input", input_value)
				dict_add(user_root, "last_input", input_value)
				dict_add(user_frame, "evalstack", create_node())
				dict_add(user_frame, "returnvalue", create_node())
				dict_add(user_frame, "phase", "init")
				dict_add(user_frame, "IP", dict_read(dict_read(read_root(), "__hierarchy"), "__IP"))
				dict_add(user_frame, "symbols", create_node())

				//Add this only at the end, as otherwise the user will already be detected
				dict_add(read_root(), username, user_root)
