High Level View of translation

* File Reader
* Lexer
* Parser
* PyNodes

    -> 
    -> PyNodes into transform.py emits out iiNodes

* iiNodes

Transform:
    - Used to convert from PyNode to a "crepr" as a "single" step
    - Now converts PyNode to iiNodes


-----------------------------------

-----------------------------------


-----------------------------------
IINODES.PY:

    class iiOpNode(iiNode):
        tag = "iiopnode"
        def __init__(self):
            pass

        def __json__(self):
            return ["op", self.tag ]

IINODES.PY:

    class iiOpPlus(iiOpNode):
        tag = "plus"

    ... (etc)

IINODES.PY:

    def iiOperator(operator):
        result = None
        if operator=="op_plus":
            result = iiOpPlus()

        if operator=="op_minus":
            result = iiOpMinus()

        if operator=="op_times":
            result = iiOpMultiply()

        if operator=="op_divide":
            result = iiOpDivide()

        if operator=="or_operator":
            result = iiOpBooleanOr()

        if operator=="and_operator":
            result = iiOpBooleanAnd()

        if operator=="not_operator":
            result = iiOpBooleanNot()

        if result:
            return result

        raise ValueError("Cannot represent operator", repr(func))


-----------------------------------

TRANSFORM.PY

    def crepr_op(py_op):
        assert isinstance(py_op, nodes.PyOperator) or isinstance(py_op, nodes.PyBoolOperator)
        try:
            result = iiOperator(operator=py_op.tag)
        except ValueError:
            raise CannotConvert("Cannot represent operator", py_op.tag)
        return result


TRANSFORM.PY
    def convert_bool_operator_function(opfunc):
        print("CONVERT - convert_bool_operator_function", repr(opfunc))
        assert isinstance(opfunc, nodes.PyBoolOperator)

        func = opfunc.tag
        arg1 = opfunc.argv[0]

        if not isinstance(opfunc, nodes.PyNotOperator):
            arg2 = opfunc.argv[1]
        else:
            arg2 = None

        crepr_arg1 = convert_arg(arg1)
        if arg2:
            crepr_arg2 = convert_arg(arg2)
        else:
            crepr_arg2 = None

        print("crepr_arg1", repr(crepr_arg1))

        if arg2:
            print("crepr_arg2", repr(crepr_arg2))
            result = ["op", crepr_op(opfunc).tag , crepr_arg1, crepr_arg2] # FIXME: Needs improving
        else:
            result = ["op", crepr_op(opfunc).tag, crepr_arg1] # FIXME: Needs improving
        print(repr(result))
        return result



TRANSFORM.PY

    def convert_operator_function(opfunc):
        print("CONVERT - convert_operator_function", repr(opfunc))
        assert isinstance(opfunc, nodes.PyOperator)

        func = opfunc.tag
        arg1 = opfunc.arg1
        arg2 = opfunc.arg2

        crepr_arg1 = convert_arg(arg1)
        crepr_arg2 = convert_arg(arg2)
        print("crepr_arg1", repr(crepr_arg1))
        print("crepr_arg2", repr(crepr_arg2))

        result = ["op", crepr_op(opfunc).tag , crepr_arg1, crepr_arg2] # FIXME: Needs improving
        print(repr(result))
        return result

        #todo("Cannot yet convert operator functions")
        #raise CannotConvert("Cannot convert operator function :" + repr(arg))


