• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

A categorical programming language


Commit MetaInfo

修订版754f31956d689c9c74b763a2f9d4b7c77009fc1a (tree)
时间2022-05-30 14:32:22
作者Corbin <cds@corb...>
CommiterCorbin

Log Message

Factor out loading all atoms in a hive.

更改概述

差异

--- a/cammy-rpy/cammylib/hive.py
+++ b/cammy-rpy/cammylib/hive.py
@@ -59,6 +59,19 @@ class Hive(object):
5959 except IOError:
6060 raise MissingAtom(atom)
6161
62+ def loadAllAtoms(self):
63+ prefix = len(self.hivepath)
64+ # XXX factor out walking
65+ for dirpath, dirnames, filenames in os.walk(self.hivepath):
66+ for filename in filenames:
67+ if not filename.endswith(".cammy"):
68+ continue
69+ fullpath = os.path.join(dirpath, filename)
70+ suffix = len(fullpath) - 6
71+ assert suffix >= 0, "proven by .endswith() check above"
72+ atom = fullpath[prefix:suffix]
73+ self.load(atom)
74+
6275 def write(self, atom, expr):
6376 filename = atom + ".cammy"
6477 makeDirectoriesForPath(self.hivepath, filename)
--- a/cammy-rpy/comb.py
+++ b/cammy-rpy/comb.py
@@ -1,5 +1,3 @@
1-import os
2-
31 from cammylib.hive import Hive
42 from cammylib.sexp import BASIS_ATOMS, BASIS_FUNCTORS
53
@@ -20,16 +18,8 @@ def dot(graph):
2018
2119 def doComb(hivepath):
2220 hive = Hive(hivepath)
23- prefix = len(hivepath)
24- for dirpath, dirnames, filenames in os.walk(hivepath):
25- for filename in filenames:
26- if not filename.endswith(".cammy"):
27- continue
28- fullpath = os.path.join(dirpath, filename)
29- suffix = len(fullpath) - 6
30- assert suffix >= 0, "proven by .endswith() check above"
31- atom = fullpath[prefix:suffix]
32- hive.load(atom)
21+ hive.loadAllAtoms()
22+
3323 graph = comb(hive.dag)
3424 print dot(graph)
3525 return 0
--- a/cammy-rpy/freeze.py
+++ b/cammy-rpy/freeze.py
@@ -1,5 +1,3 @@
1-import os
2-
31 from rpython.rlib.rfile import create_stdio
42
53 from cammylib.hive import Hive
@@ -11,7 +9,6 @@ from cammylib.sexp import Atom, Functor, sexpDict
119 def freeze(freezer, sexp):
1210 if sexp in freezer:
1311 atom = freezer[sexp]
14- print "sexp in freezer:", atom
1512 return Atom(atom)
1613 elif isinstance(sexp, Functor):
1714 return Functor(sexp.constructor,
@@ -33,17 +30,7 @@ def makeFreezer(hive):
3330
3431 def doFreeze(hivepath):
3532 hive = Hive(hivepath)
36- # XXX load all atoms
37- prefix = len(hivepath)
38- for dirpath, dirnames, filenames in os.walk(hivepath):
39- for filename in filenames:
40- if not filename.endswith(".cammy"):
41- continue
42- fullpath = os.path.join(dirpath, filename)
43- suffix = len(fullpath) - 6
44- assert suffix >= 0, "proven by .endswith() check above"
45- atom = fullpath[prefix:suffix]
46- hive.load(atom)
33+ hive.loadAllAtoms()
4734
4835 stdin, stdout, stderr = create_stdio()
4936
--- a/cammy-rpy/rename.py
+++ b/cammy-rpy/rename.py
@@ -25,24 +25,18 @@ def atomPath(hivepath, atom):
2525
2626 def doRename(hivepath, satom, tatom):
2727 hive = Hive(hivepath)
28- prefix = len(hivepath)
29- for dirpath, dirnames, filenames in os.walk(hivepath):
30- for filename in filenames:
31- if not filename.endswith(".cammy"):
32- continue
33- fullpath = os.path.join(dirpath, filename)
34- suffix = len(fullpath) - 6
35- assert suffix >= 0, "proven by .endswith() check above"
36- atom = fullpath[prefix:suffix]
37- try:
38- hive.load(atom)
39- except MissingAtom as ma:
40- print "Couldn't find", ma.atom, "while trying to load", atom
28+ try:
29+ hive.loadAllAtoms()
30+ except MissingAtom as ma:
31+ print "Couldn't find", ma.atom, "while trying to load all atoms"
32+ return 1
33+
4134 graph = comb(hive.dag)
4235 write = True
4336 if tatom in graph:
4437 print "There is already an expression %s in the hive; doing nothing." % tatom
4538 return 1
39+
4640 callers = [k for k in graph if satom in graph[k]]
4741 for caller in callers:
4842 print "Changing expression %s" % caller