I'm working on a Python module that is acting as an interpreter for an old in-game scripting language. There are a lot of variables I've found I need on the way, and the top of my module looks like this:
from mufdatatypes import *
debugline=0
code=[]
debugline=0 #Line where something interesting starts
currentline=0 #Line where we currently are
infunc=0 #Need to know if we're in a function or not.
iflevel=0 #Need to track how far into ifs we are
inelse=0 #If we're in an if, have we already done an else?
looplevel=0 #Also need to know how many loops deep we're in
instrnum=0
charnum=0
gvarlist=[ "me": mufvariable(dbref(2)) , "loc" : mufvariable(dbref(0)) , "trigger" : mufvariable(dbref(-1)) , "command": mufvariable("") ]
item=''
structstack=[]
This is getting really cluttered. At the beginning of the function that does most of their defining, it looks like this:
def mufcompile(rawcode, primstable):
"""Compiles a source string into a list of instructions"""
global source
global code
global debugline
global currentline
global code #The actual instructions will be stored here.
global infunc #Need to know if we're in a function or not.
global iflevel #Need to track how far into ifs we are.
global inelse #If we're in an if, have we already done an else?
global looplevel #Also need to know how man loops deep we're in.
global addresstable #This will hold a table of function addresses.
global structstack #This list stack will be used to hold status info as we go further down complex statements
global instrnum #Number of instruction. Important for moving the EIP.
global vartable #Table of variables. Dictionary.
global charnum #Character in the line we're at.
global item
I have a feeling I'm doing this in a way that is incorrect, and, perhaps, amusing to someone who actually knows what they're doing with Python. I know that variables can be declared on the spot, but if any functions above the one I'm writing have a reference to these, they won't compile, right? I also am a bit worried about how global global is. Do the modules that import this module have access to those variables? I don't want them to.