• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-cqtcocoa誰得pythonphprubygameguibathyscaphec翻訳計画中(planning stage)omegatframeworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

A categorical programming language


Commit MetaInfo

修订版cc80fa3f9a450a2a7a586b96382519443aea2cc6 (tree)
时间2022-02-23 16:31:12
作者Corbin <cds@corb...>
CommiterCorbin

Log Message

Port cammy-frame to RPython.

Spent more time debugging cammylib than on the main entrypoint. I
suppose that this means that cammylib is reasonably factored.

更改概述

差异

--- a/cammy-rpy/cammylib/hive.py
+++ b/cammy-rpy/cammylib/hive.py
@@ -3,6 +3,13 @@ import os.path
33 from cammylib.parser import parse
44
55
6+class MissingAtom(Exception):
7+ "An atom is missing from a hive."
8+
9+ def __init__(self, atom):
10+ self.atom = atom
11+
12+
613 class Hive(object):
714 "A self-referential collection of S-expressions."
815
@@ -11,12 +18,15 @@ class Hive(object):
1118 self.exprs = {}
1219
1320 def load(self, atom):
14- print "Loading", atom
21+ print("Loading", atom)
1522 filename = atom + ".cammy"
1623 fullpath = os.path.join(self.hivepath, filename)
1724 with open(fullpath, "r") as handle:
18- sexp, trail = parse(handle.read())
19- sexp = sexp.canonicalize(self)
20- self.exprs[atom] = sexp
21- print "Loaded", atom, sexp
22- return sexp
25+ try:
26+ sexp, trail = parse(handle.read())
27+ sexp = sexp.canonicalize(self)
28+ self.exprs[atom] = sexp
29+ print("Loaded", atom, sexp)
30+ return sexp
31+ except IOError:
32+ raise MissingAtom(atom)
--- a/cammy-rpy/cammylib/sexp.py
+++ b/cammy-rpy/cammylib/sexp.py
@@ -1,12 +1,12 @@
11 BASIS_ATOMS = (
22 "id", "ignore", "fst", "snd", "left", "right",
3- "zero", "succ", "nil", "cons", "t", "f", "not", "conj", "disj",
3+ "zero", "succ", "nil", "cons", "t", "f", "not", "conj", "disj", "either",
44 "f-zero", "f-one", "f-pi", "f-sign", "f-floor", "f-negate", "f-recip",
55 "f-lt", "f-add", "f-mul", "f-sqrt", "f-sin", "f-cos", "f-atan2"
66 )
77
88 BASIS_FUNCTORS = (
9- "comp", "pair", "case", "curry", "uncurry", "pr", "fold", "either",
9+ "comp", "pair", "case", "curry", "uncurry", "pr", "fold",
1010 )
1111
1212
--- a/cammy-rpy/draw.nix
+++ b/cammy-rpy/draw.nix
@@ -2,4 +2,4 @@
22 let
33 makeBuilder = import ./builder.nix { inherit nixpkgs; };
44 in
5- makeBuilder ./draw.py "cammy-draw" true
5+ makeBuilder ./draw.py "cammy-draw" false # true
--- /dev/null
+++ b/cammy-rpy/frame.nix
@@ -0,0 +1,5 @@
1+{ nixpkgs ? import <nixpkgs> {} }:
2+let
3+ makeBuilder = import ./builder.nix { inherit nixpkgs; };
4+in
5+ makeBuilder ./frame.py "cammy-frame" false
--- /dev/null
+++ b/cammy-rpy/frame.py
@@ -0,0 +1,24 @@
1+from rpython.rlib.rfile import create_stdio
2+
3+from cammylib.hive import Hive, MissingAtom
4+from cammylib.parser import parse
5+
6+
7+def main(argv):
8+ hivepath = argv[-1]
9+ hive = Hive(hivepath)
10+ stdin, stdout, stderr = create_stdio()
11+ try:
12+ sexp, trail = parse(stdin.read())
13+ stdout.write(sexp.canonicalize(hive).asStr())
14+ stdout.write("\n")
15+ return 0
16+ except MissingAtom as ma:
17+ stderr.write("Missing atom in hive: ")
18+ stderr.write(ma.atom)
19+ stderr.write("\n")
20+ return 1
21+
22+def target(driver, *args):
23+ driver.exe_name = "cammy-frame"
24+ return main, None
--- a/cammy-rpy/repl.py
+++ b/cammy-rpy/repl.py
@@ -3,7 +3,7 @@
33 from rpython.rlib.rfile import create_stdio
44
55 from cammylib.arrows import buildArrow, BuildProblem
6-from cammylib.hive import Hive
6+from cammylib.hive import Hive, MissingAtom
77 from cammylib.parser import parse
88
99 LINE_BUFFER_LENGTH = 1024
@@ -19,8 +19,11 @@ def repl(hive, stdin, stdout):
1919 print "Got:", line
2020 print "S-expression:", sexp.asStr()
2121 print "Trail:", trail
22- sexp = sexp.canonicalize(hive)
23- print "Canonicalized:", sexp.asStr()
22+ try:
23+ sexp = sexp.canonicalize(hive)
24+ print "Canonicalized:", sexp.asStr()
25+ except MissingAtom as ma:
26+ print "Couldn't canonicalize S-expression; missing atom:", ma.atom
2427 try:
2528 arrow = buildArrow(sexp)
2629 print "Arrow:", arrow
@@ -32,10 +35,7 @@ def main(argv):
3235 hivepath = argv[-1]
3336 hive = Hive(hivepath)
3437 stdin, stdout, stderr = create_stdio()
35- try:
36- return repl(hive, stdin, stdout)
37- except:
38- return 1
38+ return repl(hive, stdin, stdout)
3939
4040 def target(driver, *args):
4141 driver.exe_name = "cammy-repl"
--- a/default.nix
+++ b/default.nix
@@ -5,6 +5,7 @@ let
55 jelly = (import jelly/Cargo.nix { pkgs = nixpkgs; }).rootCrate.build;
66 movelist = import ./movelist { inherit nixpkgs; };
77 cammy-draw = import ./cammy-rpy/draw.nix { inherit nixpkgs; };
8+ cammy-frame = import ./cammy-rpy/frame.nix { inherit nixpkgs; };
89 cammy-repl = import ./cammy-rpy/repl.nix { inherit nixpkgs; };
910 eggs = builtins.attrValues (removeAttrs (import ./eggs.nix {
1011 inherit pkgs;
@@ -47,6 +48,7 @@ in pkgs.stdenv.mkDerivation {
4748 makeWrapper ${movelist}/bin/movelist $out/bin/cammy-movelist
4849
4950 makeWrapper ${cammy-draw}/bin/cammy-draw $out/bin/cammy-draw
51+ makeWrapper ${cammy-frame}/bin/cammy-frame $out/bin/cammy-frame
5052 makeWrapper ${cammy-repl}/bin/cammy-repl $out/bin/cammy-repl
5153 '';
5254 }