• 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

修订版0cb2292a98b637165644cd19cf47133202a2dd79 (tree)
时间2022-02-28 13:57:22
作者Corbin <cds@corb...>
CommiterCorbin

Log Message

Call jelly from RPython.

That was a headache, but it appears to work.

更改概述

差异

--- a/cammy-rpy/builder.nix
+++ b/cammy-rpy/builder.nix
@@ -1,4 +1,5 @@
1-{ nixpkgs ? import <nixpkgs> {} }:
1+entrypoint: exe: enableJIT:
2+{ nixpkgs ? import <nixpkgs> {}, jelly ? null }:
23 let
34 inherit (nixpkgs.pkgs)
45 fetchFromGitLab stdenv
@@ -14,7 +15,6 @@ let
1415 sha256 = "03cshgvh8qcsyac4q4vf0sbvcm1m2ikgwycwip4cc7sw9pzpw6a3";
1516 };
1617 in
17-entrypoint: exe: enableJIT:
1818 let
1919 opt = if enableJIT then "jit" else "2";
2020 in stdenv.mkDerivation {
@@ -33,6 +33,8 @@ entrypoint: exe: enableJIT:
3333 pypyPackages.pytest libffi
3434 ];
3535
36+ JELLY_PATH = "${jelly}/bin/jelly";
37+
3638 buildPhase = ''
3739 source $stdenv/setup
3840 mkdir -p ./rpython/_cache
--- /dev/null
+++ b/cammy-rpy/cammylib/jelly.py
@@ -0,0 +1,33 @@
1+import os
2+
3+from rpython.rlib.rfile import create_fdopen_rfile
4+
5+from cammylib.parser import parse
6+
7+jelly_path = os.environ["JELLY_PATH"]
8+
9+def jellify(sexp):
10+ """
11+ Optimize a Cammy expression.
12+ """
13+
14+ rin, win = os.pipe()
15+ rout, wout = os.pipe()
16+ # NB: We must close all four pipe FDs in both processes.
17+ pid = os.fork()
18+ if pid:
19+ os.close(rin)
20+ with create_fdopen_rfile(win, mode="w") as handle:
21+ handle.write(sexp.asStr())
22+ os.close(wout)
23+ with create_fdopen_rfile(rout, mode="r") as handle:
24+ # NB: jelly doesn't return a trail.
25+ return parse(handle.read())[0]
26+ else:
27+ os.dup2(rin, 0)
28+ os.dup2(wout, 1)
29+ os.close(rin)
30+ os.close(win)
31+ os.close(rout)
32+ os.close(wout)
33+ os.execv(jelly_path, ["jelly"])
--- a/cammy-rpy/draw.nix
+++ b/cammy-rpy/draw.nix
@@ -1,5 +1,4 @@
1-{ nixpkgs ? import <nixpkgs> {} }:
21 let
3- makeBuilder = import ./builder.nix { inherit nixpkgs; };
2+ makeBuilder = import ./builder.nix;
43 in
54 makeBuilder ./draw.py "cammy-draw" false # true
--- a/cammy-rpy/frame.nix
+++ b/cammy-rpy/frame.nix
@@ -1,5 +1,4 @@
1-{ nixpkgs ? import <nixpkgs> {} }:
21 let
3- makeBuilder = import ./builder.nix { inherit nixpkgs; };
2+ makeBuilder = import ./builder.nix;
43 in
54 makeBuilder ./frame.py "cammy-frame" false
--- a/cammy-rpy/repl.nix
+++ b/cammy-rpy/repl.nix
@@ -1,5 +1,4 @@
1-{ nixpkgs ? import <nixpkgs> {} }:
21 let
3- makeBuilder = import ./builder.nix { inherit nixpkgs; };
2+ makeBuilder = import ./builder.nix;
43 in
54 makeBuilder ./repl.py "cammy-repl" false
--- a/cammy-rpy/repl.py
+++ b/cammy-rpy/repl.py
@@ -7,6 +7,7 @@ from rpython.rlib.rfile import create_stdio
77
88 from cammylib.arrows import buildArrow, BuildProblem
99 from cammylib.hive import Hive, MissingAtom
10+from cammylib.jelly import jellify
1011 from cammylib.parser import parse
1112 from cammylib.types import ConstraintStore, TypeExtractor, UnificationFailed
1213
@@ -37,6 +38,8 @@ def repl(hive, stdin, stdout):
3738 print "Canonicalized:", sexp.asStr()
3839 except MissingAtom as ma:
3940 print "Couldn't canonicalize S-expression; missing atom:", ma.atom
41+ sexp = jellify(sexp)
42+ print "Jellified:", sexp.asStr()
4043 try:
4144 arrow = buildArrow(sexp)
4245 print "Arrow:", arrow
--- a/cammy-rpy/weave.nix
+++ b/cammy-rpy/weave.nix
@@ -1,5 +1,4 @@
1-{ nixpkgs ? import <nixpkgs> {} }:
21 let
3- makeBuilder = import ./builder.nix { inherit nixpkgs; };
2+ makeBuilder = import ./builder.nix;
43 in
54 makeBuilder ./weave.py "cammy-weave" false
--- a/default.nix
+++ b/default.nix
@@ -4,10 +4,10 @@ let
44 frame = import ./frame { inherit nixpkgs; };
55 jelly = (import jelly/Cargo.nix { pkgs = nixpkgs; }).rootCrate.build;
66 movelist = import ./movelist { inherit nixpkgs; };
7- cammy-draw = import ./cammy-rpy/draw.nix { inherit nixpkgs; };
8- cammy-frame = import ./cammy-rpy/frame.nix { inherit nixpkgs; };
9- cammy-repl = import ./cammy-rpy/repl.nix { inherit nixpkgs; };
10- cammy-weave = import ./cammy-rpy/weave.nix { inherit nixpkgs; };
7+ cammy-draw = import ./cammy-rpy/draw.nix { inherit nixpkgs jelly; };
8+ cammy-frame = import ./cammy-rpy/frame.nix { inherit nixpkgs jelly; };
9+ cammy-repl = import ./cammy-rpy/repl.nix { inherit nixpkgs jelly; };
10+ cammy-weave = import ./cammy-rpy/weave.nix { inherit nixpkgs jelly; };
1111 eggs = builtins.attrValues (removeAttrs (import ./eggs.nix {
1212 inherit pkgs;
1313 stdenv = pkgs.stdenv;
--- a/todo.txt
+++ b/todo.txt
@@ -1,18 +1,17 @@
11 * Literate Cammy
2- * RPython modules will go in cammy-rpy/cammylib/
3- * RPython entrypoints will go in cammy-rpy/
4- * Write filterSource expressions to grab only one entrypoint + modules
5- * cammy-rpy/builder.nix
6- * Nix expressions also go in cammy-rpy/ next to entrypoints
72 * Entrypoints:
8- * cammy-repl $HIVE: REPL session with a hive
9- * cammy-weave $HIVE: document a hive
3+ - cammy-repl $HIVE: REPL session with a hive
4+ - cammy-weave $HIVE: document a hive
105 * cammy-tangle $HIVE: take an expression on stdin, return framed optimized
116 expression on stdout
127 * cammy-frame $HIVE | jelly
13- * cammy-draw ...: take an expression and canvas params, make a PNG
14- * cammy-frame $HIVE: take an expression on stdin, return framed expression
8+ - cammy-draw ...: take an expression and canvas params, make a PNG
9+ - cammy-frame $HIVE: take an expression on stdin, return framed expression
1510 on stdout
11+ * cammy-jelly $EXPR: print an optimized expression on stdout
12+ * $EXPR is a path!
13+ * This is wholly due to RPython issues
14+ * When $EXPR is "-", read from stdin
1615 * REPL improvements
1716 * allow mid-functor newlines
1817 * jellification
@@ -58,3 +57,4 @@
5857 * Moore machines: For state type Q and input type S, Q × S -> Q
5958 * Moore transducers: [Q × S, Q] -> [Q × S, Q]
6059 * Mealy machines: For state type Q, input type S, and output type L, Q × S -> Q × L
60+* Jets