def from_file(fname): with open(fname) as f: code_data = reader.load(f) obtype.tokenize(code_data) tac_env = Env() tac_env.feed_code(code_data) tac_env.exec_all(fname) if tac_env.err_occured: print tac_env.err_occured return None else: return separ.to_func(tac_env.tacs)
def _require(env, args): """(require stdio stdlib)""" for arg in args: if not isinstance(arg, obtype.Token) or not arg.symbolp(): raise CompileTimeError, \ 'require -- argument must be symbol: %r' % arg # exec the file in the environment symb = arg.n fname = symb + '.lisp' fpath_b = os.path.join(util.LIB_DIR, fname) if os.path.isfile(fpath_b): # the file is a builtin lib file: run in the env fpath = fpath_b else: fpath_l = os.path.join(util.PWD_DIR, fname) if not os.path.isfile(fpath_l): raise CompileTimeError, \ 'require -- cannot find file %r\nsearch path are: %r' \ % (fname, [fpath_b, fpath_l]) else: # the file is a local lib file: run in the env fpath = fpath_l if fpath in env.libs: continue # already included else: env.libs[fpath] = 1 with open(fpath) as fp: lib_code = reader.load(fp) obtype.tokenize(lib_code) old_fname = env.curr_fname env.exec_all(fname, lib_code) env.curr_fname = old_fname return obtype.Token('void')