"""It's intended that stuff inu the Interpreter class is specific only to
one single instance of the interpreter; right now, just namespaces.

The init() function is for the traditional one-interpreter-for-the-process
method of execution, the only type supported so far.  It exports an Interpreter
object called the_interpreter, which all sorts of functions in other files
happily use.
"""

import getopt, sys

class Interpreter:
    def __init__(self):
        self.defined_functions = None
        self.builtin_functions = None
        self.builtin_macros = None
        self.DEBUG = 1

def init():
    from builtins import MakeBuiltins
    global the_interper
    the_interper = Interpreter()

    the_interper.defined_functions = {} #Maps name -> LispFunction
    the_interper.builtin_functions, the_interper.builtin_macros = \
            MakeBuiltins(defined_fn_ns=the_interper.defined_functions,
                         interper = the_interper)

    print "interpreter.py: All builtin functions:\n", the_interper.builtin_functions
    print "interpreter.py: All builtin macros:\n", the_interper.builtin_macros
    print "interpreter.py: and no defined_functions yet:", the_interper.defined_functions

def readopts():
    print sys.argv[1:]
    opts, args = getopt.getopt(sys.argv[1:], "dq")
    for flag, value in opts:
        if len(flag)>1 and flag[:2] == "--": 
            #Long option.
            pass
        else: #Short option.  Support -dqh format.
            if 'd' in flag:
                the_interper.DEBUG = 1
            if 'q' in flag:
                the_interper.DEBUG = 0

