~fd/cane-lang

90885ed2bf381bfee06b1c8aaf83bc4bbd70671e — Ersei Saggi 7 months ago 72e0823
switch to flakes; fix flatten action
5 files changed, 223 insertions(+), 22 deletions(-)

M cane-lang/src/stdtypes.rs
A flake.lock
A flake.nix
A rust-toolchain.toml
D shell.nix
M cane-lang/src/stdtypes.rs => cane-lang/src/stdtypes.rs +54 -17
@@ 529,7 529,12 @@ impl Data {
        let mut flattened: LinkedList<Data> = LinkedList::new();
        if self.kind == Types::LIST {
            while let Some(mut item) = self.get_list().0.pop_front() {
                flattened.append(&mut item.val_list.0);
                if item.kind == Types::LIST {
                    item.make_flat();
                    flattened.append(&mut item.val_list.0);
                } else {
                    flattened.push_back(item);
                }
            }
            self.set_list(List::new(flattened));
        }


@@ 846,29 851,61 @@ mod tests {
        list1.val_list.0.push_back(item1);
        list2.val_list.0.push_back(item2);
        list3.val_list.0.push_back(item3);
        list2.val_list.0.push_back(list3);

        list.val_list.0.push_back(list1);
        list.val_list.0.push_back(list2);

        assert!(list.val_list.0.back().unwrap().kind == Types::LIST);

        list.make_flat();

        let list3_test = list.val_list.0.pop_back().unwrap();
        assert!(list3_test.kind == Types::NUMBER);
        assert!(list3_test.val_number.0 == 3);
        let list2_test = list.val_list.0.pop_back().unwrap();
        assert!(list2_test.kind == Types::NUMBER);
        assert!(list2_test.val_number.0 == 2);
        let list1_test = list.val_list.0.pop_back().unwrap();
        assert!(list1_test.kind == Types::NUMBER);
        assert!(list1_test.val_number.0 == 1);
    }

    #[test]
    fn test_flatten_list_string() {
        // To make sure that the flatten function doesn't mangle strings
        let mut list = Data::new(Types::LIST);
        let mut list1 = Data::new(Types::LIST);
        let mut list2 = Data::new(Types::LIST);
        let mut list3 = Data::new(Types::LIST);

        let mut item1 = Data::new(Types::STRING);
        item1.set_string("hi".to_string());
        let mut item2 = Data::new(Types::STRING);
        item2.set_string("there".to_string());
        let mut item3 = Data::new(Types::STRING);
        item3.set_string("tester".to_string());

        list1.val_list.0.push_back(item1);
        list2.val_list.0.push_back(item2);
        list3.val_list.0.push_back(item3);
        list2.val_list.0.push_back(list3);

        list.val_list.0.push_back(list1);
        list.val_list.0.push_back(list2);
        list.val_list.0.push_back(list3);

        assert!(list.val_list.0.back().unwrap().kind == Types::LIST);
        assert!(
            list.val_list
                .0
                .back()
                .unwrap()
                .val_list
                .0
                .back()
                .unwrap()
                .val_number
                .0
                == 3
        );

        list.make_flat();

        assert!(list.val_list.0.back().unwrap().kind == Types::NUMBER);
        assert!(list.val_list.0.back().unwrap().val_number.0 == 3);
        let list3_test = list.val_list.0.pop_back().unwrap();
        assert!(list3_test.kind == Types::STRING);
        assert!(list3_test.val_string == "tester");
        let list2_test = list.val_list.0.pop_back().unwrap();
        assert!(list2_test.kind == Types::STRING);
        assert!(list2_test.val_string == "there");
        let list1_test = list.val_list.0.pop_back().unwrap();
        assert!(list1_test.kind == Types::STRING);
        assert!(list1_test.val_string == "hi");
    }
}

A flake.lock => flake.lock +130 -0
@@ 0,0 1,130 @@
{
  "nodes": {
    "flake-utils": {
      "inputs": {
        "systems": "systems"
      },
      "locked": {
        "lastModified": 1692799911,
        "narHash": "sha256-3eihraek4qL744EvQXsK1Ha6C3CR7nnT8X2qWap4RNk=",
        "owner": "numtide",
        "repo": "flake-utils",
        "rev": "f9e7cf818399d17d347f847525c5a5a8032e4e44",
        "type": "github"
      },
      "original": {
        "owner": "numtide",
        "repo": "flake-utils",
        "type": "github"
      }
    },
    "flake-utils_2": {
      "inputs": {
        "systems": "systems_2"
      },
      "locked": {
        "lastModified": 1681202837,
        "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=",
        "owner": "numtide",
        "repo": "flake-utils",
        "rev": "cfacdce06f30d2b68473a46042957675eebb3401",
        "type": "github"
      },
      "original": {
        "owner": "numtide",
        "repo": "flake-utils",
        "type": "github"
      }
    },
    "nixpkgs": {
      "locked": {
        "lastModified": 1692734709,
        "narHash": "sha256-SCFnyHCyYjwEmgUsHDDuU0TsbVMKeU1vwkR+r7uS2Rg=",
        "owner": "NixOS",
        "repo": "nixpkgs",
        "rev": "b85ed9dcbf187b909ef7964774f8847d554fab3b",
        "type": "github"
      },
      "original": {
        "owner": "NixOS",
        "ref": "nixos-unstable",
        "repo": "nixpkgs",
        "type": "github"
      }
    },
    "nixpkgs_2": {
      "locked": {
        "lastModified": 1681358109,
        "narHash": "sha256-eKyxW4OohHQx9Urxi7TQlFBTDWII+F+x2hklDOQPB50=",
        "owner": "NixOS",
        "repo": "nixpkgs",
        "rev": "96ba1c52e54e74c3197f4d43026b3f3d92e83ff9",
        "type": "github"
      },
      "original": {
        "owner": "NixOS",
        "ref": "nixpkgs-unstable",
        "repo": "nixpkgs",
        "type": "github"
      }
    },
    "root": {
      "inputs": {
        "flake-utils": "flake-utils",
        "nixpkgs": "nixpkgs",
        "rust-overlay": "rust-overlay"
      }
    },
    "rust-overlay": {
      "inputs": {
        "flake-utils": "flake-utils_2",
        "nixpkgs": "nixpkgs_2"
      },
      "locked": {
        "lastModified": 1692842983,
        "narHash": "sha256-VJkts5gTo4eGMT1IgXhL5tRVkS1TailFKjjVktAuhdk=",
        "owner": "oxalica",
        "repo": "rust-overlay",
        "rev": "8f6d56270ec028a340583111609b12663f5d7490",
        "type": "github"
      },
      "original": {
        "owner": "oxalica",
        "repo": "rust-overlay",
        "type": "github"
      }
    },
    "systems": {
      "locked": {
        "lastModified": 1681028828,
        "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
        "owner": "nix-systems",
        "repo": "default",
        "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
        "type": "github"
      },
      "original": {
        "owner": "nix-systems",
        "repo": "default",
        "type": "github"
      }
    },
    "systems_2": {
      "locked": {
        "lastModified": 1681028828,
        "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
        "owner": "nix-systems",
        "repo": "default",
        "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
        "type": "github"
      },
      "original": {
        "owner": "nix-systems",
        "repo": "default",
        "type": "github"
      }
    }
  },
  "root": "root",
  "version": 7
}

A flake.nix => flake.nix +34 -0
@@ 0,0 1,34 @@
{
  description = "A devShell example";

  inputs = {
    nixpkgs.url      = "github:NixOS/nixpkgs/nixos-unstable";
    rust-overlay.url = "github:oxalica/rust-overlay";
    flake-utils.url  = "github:numtide/flake-utils";
  };

  outputs = { self, nixpkgs, rust-overlay, flake-utils, ... }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        overlays = [ (import rust-overlay) ];
        pkgs = import nixpkgs {
          inherit system overlays;
        };
		rust = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
      in
      with pkgs;
      {
        devShells.default = mkShell {
          buildInputs = [
		    rust
			rustfmt
			rust-analyzer
			wasm-pack
			cargo
			binaryen
			nodePackages.prettier
          ];
        };
      }
    );
}

A rust-toolchain.toml => rust-toolchain.toml +5 -0
@@ 0,0 1,5 @@
[toolchain]
channel = "stable"
components = []
targets = [ "wasm32-unknown-unknown" ]
profile = "default"

D shell.nix => shell.nix +0 -5
@@ 1,5 0,0 @@
let
  pkgs = import (fetchTarball("channel:nixpkgs-unstable")) {};
in pkgs.mkShell {
  buildInputs = [ pkgs.rustfmt pkgs.rust-analyzer pkgs.wasm-pack pkgs.rustup pkgs.pkg-config pkgs.openssl pkgs.binaryen pkgs.nodePackages.prettier ];
}