# AVSLib :: 'bool' package :: 'core' module
# Copyright (c) 2005 George Zarkadas (gzarkadas@users.sourceforge.net)

# This program is free software; you can redistribute it and/or modify it under the terms of 
# the GNU General Public License as published by the Free Software Foundation; either 
# version 2 of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
# PURPOSE.  See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along with this program; 
# if not, write to the "Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
# MA  02111-1307  USA"

DefineModule("avslib", "bool", "core")

global __load__ = Eval("""
	LoadModule("avslib", "base", "core")
	""")

# Special functions corresponding to variable operations 
# Use them for constructing expressions for Eval or 
# as building blocks of multi-argument functions.

# Public variants, for library users; 
# transfered from the base module to increase library's modularity

Function Not(val x) { return !x } 
Function And2(val x1, val x2) { return x1 && x2 }
Function Or2(val x1, val x2) { return x1 || x2 }
Function Xor2(val x1, val x2) { return (x1 && !x2) || (!x1 && x2) }

# Number of arguments to the function below has been reduced to 20 for performance.
# If you need more than that it is better to use the array package.

Function And(val x1, val "x2", val "x3", val "x4", val "x5", val "x6", val "x7", \
	val "x8", val "x9", val "x10",val "x11", val "x12", val "x13", val "x14", \
	val "x15", val "x16", val "x17", val "x18", val "x19", val "x20")
{
	_and = x1
	_and = Defined(x2) ? __and2(_and, x2) : _and
	_and = Defined(x3) ? __and2(_and, x3) : _and
	_and = Defined(x4) ? __and2(_and, x4) : _and
	_and = Defined(x5) ? __and2(_and, x5) : _and
	_and = Defined(x6) ? __and2(_and, x6) : _and
	_and = Defined(x7) ? __and2(_and, x7) : _and
	_and = Defined(x8) ? __and2(_and, x8) : _and
	_and = Defined(x9) ? __and2(_and, x9) : _and
	_and = Defined(x10) ? __and2(_and, x10) : _and
	_and = Defined(x11) ? __and2(_and, x11) : _and
	_and = Defined(x12) ? __and2(_and, x12) : _and
	_and = Defined(x13) ? __and2(_and, x13) : _and
	_and = Defined(x14) ? __and2(_and, x14) : _and
	_and = Defined(x15) ? __and2(_and, x15) : _and
	_and = Defined(x16) ? __and2(_and, x16) : _and
	_and = Defined(x17) ? __and2(_and, x17) : _and
	_and = Defined(x18) ? __and2(_and, x18) : _and
	_and = Defined(x19) ? __and2(_and, x19) : _and
	_and = Defined(x20) ? __and2(_and, x20) : _and
	return _and
}

Function Or(val x1, val "x2", val "x3", val "x4", val "x5", val "x6", val "x7", \
	val "x8", val "x9", val "x10",val "x11", val "x12", val "x13", val "x14", \
	val "x15", val "x16", val "x17", val "x18", val "x19", val "x20")
{
	_or = x1
	_or = Defined(x2) ? __or2(_or, x2) : _or
	_or = Defined(x3) ? __or2(_or, x3) : _or
	_or = Defined(x4) ? __or2(_or, x4) : _or
	_or = Defined(x5) ? __or2(_or, x5) : _or
	_or = Defined(x6) ? __or2(_or, x6) : _or
	_or = Defined(x7) ? __or2(_or, x7) : _or
	_or = Defined(x8) ? __or2(_or, x8) : _or
	_or = Defined(x9) ? __or2(_or, x9) : _or
	_or = Defined(x10) ? __or2(_or, x10) : _or
	_or = Defined(x11) ? __or2(_or, x11) : _or
	_or = Defined(x12) ? __or2(_or, x12) : _or
	_or = Defined(x13) ? __or2(_or, x13) : _or
	_or = Defined(x14) ? __or2(_or, x14) : _or
	_or = Defined(x15) ? __or2(_or, x15) : _or
	_or = Defined(x16) ? __or2(_or, x16) : _or
	_or = Defined(x17) ? __or2(_or, x17) : _or
	_or = Defined(x18) ? __or2(_or, x18) : _or
	_or = Defined(x19) ? __or2(_or, x19) : _or
	_or = Defined(x20) ? __or2(_or, x20) : _or
	return _or
}

