diff --git a/flake.lock b/flake.lock index 224dd65b..25bf87df 100644 --- a/flake.lock +++ b/flake.lock @@ -37,7 +37,32 @@ "root": { "inputs": { "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "rpypkgs": "rpypkgs" + } + }, + "rpypkgs": { + "inputs": { + "flake-utils": [ + "flake-utils" + ], + "nixpkgs": [ + "nixpkgs" + ], + "typhon": "typhon" + }, + "locked": { + "lastModified": 1713090744, + "narHash": "sha256-ny32FfhDyvQAx0+hKy1DU7RWLjbx6n3zoBRYHT1w2SE=", + "ref": "refs/heads/master", + "rev": "9a96d9823eef61883f720fc3c600f66e36e4f715", + "revCount": 21, + "type": "git", + "url": "git://git.pf.osdn.net/gitroot/c/co/corbin/rpypkgs.git" + }, + "original": { + "type": "git", + "url": "git://git.pf.osdn.net/gitroot/c/co/corbin/rpypkgs.git" } }, "systems": { @@ -54,6 +79,31 @@ "repo": "default", "type": "github" } + }, + "typhon": { + "inputs": { + "flake-utils": [ + "rpypkgs", + "flake-utils" + ], + "nixpkgs": [ + "rpypkgs", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1707184108, + "narHash": "sha256-641r2pA5/mAGX0Dx6/zEP4UtnbS0S0bfOIrJW37ygvA=", + "owner": "monte-language", + "repo": "typhon", + "rev": "fac865f75da5cba9802d2fe7442bec611bd54af4", + "type": "github" + }, + "original": { + "owner": "monte-language", + "repo": "typhon", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index ebf14b58..1219341a 100644 --- a/flake.nix +++ b/flake.nix @@ -4,9 +4,16 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-22.05"; flake-utils.url = "github:numtide/flake-utils"; + rpypkgs = { + url = "git://git.pf.osdn.net/gitroot/c/co/corbin/rpypkgs.git"; + inputs = { + nixpkgs.follows = "nixpkgs"; + flake-utils.follows = "flake-utils"; + }; + }; }; - outputs = { self, nixpkgs, flake-utils }: + outputs = { self, nixpkgs, flake-utils, rpypkgs }: let noPythonCheck = p: p.overridePythonAttrs (old: { doCheck = false; @@ -34,7 +41,7 @@ }; overlays = [ overlay ]; }; - typhon = import ./nix-support/typhon.nix pkgs; + typhon = import ./nix-support/typhon.nix { inherit pkgs rpypkgs; }; qbe = pkgs.stdenv.mkDerivation { name = "qbe-unstable"; @@ -49,7 +56,7 @@ in { overlays.default = overlay; packages = typhon // { - default = typhon.fullMonte; + default = typhon.monte; }; devShells.default = pkgs.mkShell { packages = with pkgs; [ cachix nix-tree ]; diff --git a/nix-support/bench.nix b/nix-support/bench.nix index 5f79138d..e5652c8c 100644 --- a/nix-support/bench.nix +++ b/nix-support/bench.nix @@ -4,7 +4,7 @@ stdenv.mkDerivation { name = "typhon-bench"; buildInputs = [ typhonVm mast ]; buildPhase = '' - ln -s ${typhonVm}/mt-typhon . + ln -s ${typhonVm}/bin/mt-typhon . ./mt-typhon -l ${mast} -l ${mast}/mast -b ${mast}/loader bench \ ${mast}/mast/bench/{brot,nqueens,primeCount,richards} '';#*/ diff --git a/nix-support/mast.nix b/nix-support/mast.nix index 8056b528..ef678586 100644 --- a/nix-support/mast.nix +++ b/nix-support/mast.nix @@ -10,7 +10,7 @@ let then "-noverify" else ""; in pkgs.runCommand name {} '' - ${typhonVm}/mt-typhon -l ${boot} ${boot}/loader run montec ${flags} ${mt} $out + ${typhonVm}/bin/mt-typhon -l ${boot} ${boot}/loader run montec ${flags} ${mt} $out ''; exts = [ ".mt" ".mt.md" ".asdl" ]; # Compile a whole tree. @@ -33,6 +33,6 @@ let in buildMASTFarm.overrideAttrs (attrs: { # Run the tests in the built tree using the built tree's loader. buildCommand = attrs.buildCommand + '' - ${typhonVm}/mt-typhon -l $out $out/loader test all-tests + ${typhonVm}/bin/mt-typhon -l $out $out/loader test all-tests ''; }) diff --git a/nix-support/monte-script.nix b/nix-support/monte-script.nix index 732e9745..e2d44d63 100644 --- a/nix-support/monte-script.nix +++ b/nix-support/monte-script.nix @@ -87,22 +87,22 @@ let case $OPERATION in ${buildCmds} repl) - $RLWRAP ${typhonVm}/mt-typhon -l ${mast} \ + $RLWRAP ${typhonVm}/bin/mt-typhon -l ${mast} \ ${mast}/loader run tools/repl if [ $? == 1 ]; then echo "Due to a Docker bug, readline-style editing is not currently available in this REPL. Sorry." - ${typhonVm}/mt-typhon -l ${mast} \ + ${typhonVm}/bin/mt-typhon -l ${mast} \ ${mast}/loader run tools/repl fi ;; muffin) shift - ${typhonVm}/mt-typhon -l ${mast} \ + ${typhonVm}/bin/mt-typhon -l ${mast} \ ${mast}/loader run tools/muffin "$@" ;; lint) shift - ${typhonVm}/mt-typhon -l ${mast} ${mast}/loader \ + ${typhonVm}/bin/mt-typhon -l ${mast} ${mast}/loader \ run montec -lint -terse "$@" ;; run|test|bench|dot) @@ -118,7 +118,7 @@ let usage 1 else DEST=''${3:-''${SOURCE%.mt.mast}} - ${typhonVm}/mt-typhon -l ${mast} ${mast}/loader \ + ${typhonVm}/bin/mt-typhon -l ${mast} ${mast}/loader \ run montec -mix "$SOURCE" "$DEST" fi ;; @@ -129,12 +129,12 @@ let else if [[ "$SOURCE" != *.mast ]]; then MASTSOURCE=''${SOURCE%.mt}.mast - ${typhonVm}/mt-typhon -l ${mast} \ + ${typhonVm}/bin/mt-typhon -l ${mast} \ ${mast}/loader run montec -mix "$SOURCE" "$MASTSOURCE" SOURCE=$MASTSOURCE fi if [[ "$SOURCE" == *.mast ]]; then - ${typhonVm}/mt-typhon -l ${mast} -l $PWD \ + ${typhonVm}/bin/mt-typhon -l ${mast} -l $PWD \ ${mast}/loader run ''${SOURCE%.mast} "$@" fi fi @@ -144,7 +144,7 @@ let if [[ -z $SOURCE ]]; then usage 1 else - ${typhonVm}/mt-typhon -l ${mast} \ + ${typhonVm}/bin/mt-typhon -l ${mast} \ ${mast}/loader run tools/dump "$SOURCE" fi ;; @@ -153,7 +153,7 @@ let if [[ -z $SOURCE ]]; then usage 1 else - ${typhonVm}/mt-typhon -l ${mast} \ + ${typhonVm}/bin/mt-typhon -l ${mast} \ ${mast}/loader run format "$SOURCE" fi ;; @@ -171,7 +171,7 @@ let ''; capnpc-script = pkgs.writeScript "capnpc-monte" '' #!${shellForMt} - ${typhonVm}/mt-typhon -l ${mast} \ + exec ${typhonVm}/bin/mt-typhon -l ${mast} \ ${mast}/loader run tools/capnpc "$@" ''; diff --git a/nix-support/montePackage.nix b/nix-support/montePackage.nix index e663d95f..ac98b5f7 100644 --- a/nix-support/montePackage.nix +++ b/nix-support/montePackage.nix @@ -24,7 +24,7 @@ let for srcP in ${lib.concatStringsSep " " pathNames}; do for srcF in `find ./$srcP -name \\*.mt`; do destF=\${srcF%%.mt}.mast - ${typhonVm}/mt-typhon -l ${mast}/mast ${mast}/loader run montec -mix $srcF $destF + ${typhonVm}/bin/mt-typhon -l ${mast}/mast ${mast}/loader run montec -mix $srcF $destF fail=$? if [ $fail -ne 0 ]; then exit $fail @@ -34,7 +34,7 @@ let "; doCheck = doCheck; checkPhase = if doCheck then '' - ${typhonVm}/mt-typhon ${dependencySearchPaths} -l ${mast}/mast -l . ${mast}/loader test ${entrypoint} + ${typhonVm}/bin/mt-typhon ${dependencySearchPaths} -l ${mast}/mast -l . ${mast}/loader test ${entrypoint} '' else null; installPhase = " mkdir -p $out @@ -70,7 +70,7 @@ let for p in ${lib.concatStringsSep " " pathNames}; do LOCALPKGPATHS+=" -l $out/$p" done - ${typhonVm}/mt-typhon ${dependencySearchPaths} \$LOCALPKGPATHS -l ${mast}/mast ${mast}/loader \$OPERATION ${entrypoint} "\$@" + ${typhonVm}/bin/mt-typhon ${dependencySearchPaths} \$LOCALPKGPATHS -l ${mast}/mast ${mast}/loader \$OPERATION ${entrypoint} "\$@" EOF chmod +x $out/bin/${entryPointName} '' else ""); diff --git a/nix-support/typhon.nix b/nix-support/typhon.nix index 517cd848..3b5c382a 100644 --- a/nix-support/typhon.nix +++ b/nix-support/typhon.nix @@ -1,6 +1,6 @@ -nixpkgs: +{ pkgs, rpypkgs }: let - lib = nixpkgs.lib; + lib = pkgs.lib; vmSrc = let loc = part: (toString ./..) + part; in builtins.filterSource (path: type: let p = toString path; @@ -8,19 +8,17 @@ let (type == "directory" || lib.hasSuffix ".py" p)) || p == loc "/typhon" || p == loc "/main.py") ./..; - vmConfig = { - inherit vmSrc; - inherit (nixpkgs) pypy libsodium; - pypyPackages = nixpkgs.pypy.pkgs; - # Want to build Typhon with Clang instead of GCC? Uncomment this next - # line. ~ C. - # stdenv = nixpkgs.clangStdenv; - }; - typhon = with nixpkgs; rec { - typhonVm = callPackage ./vm.nix (vmConfig // { buildJIT = false; }); - typhonVmJIT = callPackage ./vm.nix (vmConfig // { buildJIT = true; }); + typhon = with pkgs; rec { + # Want to build Typhon with Clang instead of GCC? + # Add `stdenv = pkgs.clangStdenv` to either VM. ~ C. + typhonVm = callPackage ./vm.nix { + inherit vmSrc rpypkgs; buildJIT = false; + }; + typhonVmJIT = callPackage ./vm.nix { + inherit vmSrc rpypkgs; buildJIT = true; + }; mast = callPackage ./mast.nix { typhonVm = typhonVmJIT; - pkgs = nixpkgs; }; + pkgs = pkgs; }; typhonDumpMAST = callPackage ./dump.nix {}; # XXX broken for unknown reasons @@ -28,26 +26,24 @@ let monte = callPackage ./monte-script.nix { typhonVm = typhonVmJIT; mast = mast; }; - capnMast = callPackage ./capn.nix { - pkgs = nixpkgs; monte = monte; - }; - fullMast = nixpkgs.symlinkJoin { + capnMast = callPackage ./capn.nix { inherit pkgs monte; }; + fullMast = pkgs.symlinkJoin { name = "mast-full"; paths = [ mast capnMast ]; }; fullMonte = callPackage ./monte-script.nix { typhonVm = typhonVmJIT; mast = fullMast; }; - mtBusybox = monte.override { shellForMt = "${nixpkgs.busybox}/bin/sh"; }; + mtBusybox = monte.override { shellForMt = "${pkgs.busybox}/bin/sh"; }; mtLite = mtBusybox.override { withBuild = false; }; }; typhonDocker = { - mtDocker = nixpkgs.dockerTools.buildImage { + mtDocker = pkgs.dockerTools.buildImage { name = "monte-dev"; tag = "latest"; - contents = [nixpkgs.nix.out nixpkgs.busybox typhon.mtBusybox typhon.typhonVmJIT]; + contents = [pkgs.nix.out pkgs.busybox typhon.mtBusybox typhon.typhonVmJIT]; runAsRoot = '' - #!${nixpkgs.busybox}/bin/sh + #!${pkgs.busybox}/bin/sh mkdir -p /etc tee /etc/profile <<'EOF' echo "Try \`monte repl' for an interactive Monte prompt." @@ -55,11 +51,11 @@ let EOF ''; config = { - Cmd = [ "${nixpkgs.busybox}/bin/sh" "-l" ]; + Cmd = [ "${pkgs.busybox}/bin/sh" "-l" ]; WorkingDir = "/"; }; }; - mtLiteDocker = nixpkgs.dockerTools.buildImage { + mtLiteDocker = pkgs.dockerTools.buildImage { name = "repl"; tag = "latest"; contents = with typhon; [mtLite typhonVmJIT]; diff --git a/nix-support/vm.nix b/nix-support/vm.nix index 6ec73971..a0da971a 100644 --- a/nix-support/vm.nix +++ b/nix-support/vm.nix @@ -1,5 +1,5 @@ -{stdenv, fetchFromGitLab, fetchFromGitHub, lib, libsodium, libuv, libffi, -pkg-config, pypy, pypyPackages, vmSrc, buildJIT}: +{ stdenv, fetchFromGitLab, fetchFromGitHub, libsodium, libuv, libffi, +pypy, system, vmSrc, rpypkgs, buildJIT }: let # https://foss.heptapod.net/pypy/pypy/ @@ -11,29 +11,18 @@ let rev = "90fd9ed34d52181de59cbfff863719472b05418e"; sha256 = "03cshgvh8qcsyac4q4vf0sbvcm1m2ikgwycwip4cc7sw9pzpw6a3"; }; - macropy = pypyPackages.buildPythonPackage rec { - pname = "macropy"; - version = "1.0.4"; - name = "${pname}-${version}"; - src = fetchFromGitHub { - owner = "lihaoyi"; - repo = "macropy"; - rev = "13993ccb08df21a0d63b091dbaae50b9dbb3fe3e"; - sha256 = "12496896c823h0849vnslbdgmn6z9mhfkckqa8sb8k9qqab7pyyl"; - }; - }; - optLevel = if buildJIT then "-Ojit" else "-O2"; - -in -stdenv.mkDerivation { +in rpypkgs.lib.${system}.mkRPythonDerivation { + entrypoint = "main.py"; + binName = "mt-typhon"; + nativeBuildInputs = with rpypkgs.packages.${system}.rpythonPackages; [ macropy ]; + buildInputs = [ libuv libsodium ]; + optLevel = if buildJIT then "jit" else "2"; +} { name = if buildJIT then "typhon-vm" else "typhon-vm-nojit"; src = vmSrc; - buildInputs = [ pypy - pypyPackages.py pypyPackages.pytest - macropy pypySrc - pkg-config libffi libuv libsodium ]; + # XXX really? propagatedBuildInputs = [ libffi libuv libsodium ]; shellHook = '' @@ -52,20 +41,5 @@ stdenv.mkDerivation { trap typhon_cleanup EXIT ''; - buildPhase = '' - source $stdenv/setup - mkdir -p ./rpython/_cache - cp -r ${pypySrc}/rpython . - chmod -R u+w rpython/ - cp -r $src/main.py . - # Do the actual translation. - ${pypy}/bin/pypy -mrpython ${optLevel} main.py - ''; - - installPhase = '' - mkdir $out - cp mt-typhon $out/ - ''; - separateDebugInfo = true; } diff --git a/typhon/objects/data.py b/typhon/objects/data.py index 77a9031c..030a648e 100644 --- a/typhon/objects/data.py +++ b/typhon/objects/data.py @@ -25,7 +25,7 @@ from rpython.rlib.rfloat import DBL_EPSILON, erfc, lgamma from rpython.rlib.rstring import StringBuilder, UnicodeBuilder, replace, split from rpython.rlib.rstruct.ieee import float_pack -from rpython.rlib.unicodedata import unicodedb_6_2_0 as unicodedb +from rpython.rlib.unicodedata import unicodedb_13_0_0 as unicodedb from typhon.atoms import getAtom from typhon.autohelp import autohelp, method @@ -1453,7 +1453,7 @@ def approxDivideInt(self, other): return NAN except OverflowError: # Trade overflow for reduced dynamic range. - negate = self.bi.sign < 0 ^ other < 0 + negate = self.bi.get_sign() < 0 ^ other < 0 return NEG_INF if negate else INF @method("BigInt", "Double", _verb="floorDivide") diff --git a/typhon/quoting.py b/typhon/quoting.py index 1d8d1e94..d58caeca 100644 --- a/typhon/quoting.py +++ b/typhon/quoting.py @@ -14,7 +14,7 @@ from rpython.rlib.jit import elidable from rpython.rlib.rstring import UnicodeBuilder -from rpython.rlib.unicodedata import unicodedb_6_2_0 as unicodedb +from rpython.rlib.unicodedata import unicodedb_13_0_0 as unicodedb escapes = {