Error Message Include File Name (#70) and Minor Fix #154

Closed
ychenfo wants to merge 19 commits from ast_filename_location into master
59 changed files with 1256 additions and 600 deletions

169
Cargo.lock generated
View File

@ -4,9 +4,9 @@ version = 3
[[package]] [[package]]
name = "ahash" name = "ahash"
version = "0.7.4" version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43bb833f0bf979d8475d38fbf09ed3b8a55e1885fe93ad3f93239fc6a4f17b98" checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47"
dependencies = [ dependencies = [
"getrandom", "getrandom",
"once_cell", "once_cell",
@ -77,9 +77,9 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.0.70" version = "1.0.72"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d26a6ce4b6a484fa3edb70f7efa6fc430fd2b87285fe8b84304fd0936faa0dc0" checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee"
[[package]] [[package]]
name = "cfg-if" name = "cfg-if"
@ -201,12 +201,6 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "dtoa"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56899898ce76aaf4a0f24d914c97ea6ed976d42fec6ad33fcbb0a1103e07b2b0"
[[package]] [[package]]
name = "either" name = "either"
version = "1.6.1" version = "1.6.1"
@ -316,8 +310,9 @@ dependencies = [
[[package]] [[package]]
name = "inkwell" name = "inkwell"
version = "0.1.0" version = "0.1.0-beta.4"
source = "git+https://github.com/TheDan64/inkwell?branch=master#d018ee22e4b5241dec2bc32ca67f3d4caaecee47" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2223d0eba0ae6d40a3e4680c6a3209143471e1f38b41746ea309aa36dde9f90b"
dependencies = [ dependencies = [
"either", "either",
"inkwell_internals", "inkwell_internals",
@ -330,8 +325,9 @@ dependencies = [
[[package]] [[package]]
name = "inkwell_internals" name = "inkwell_internals"
version = "0.3.0" version = "0.5.0"
source = "git+https://github.com/TheDan64/inkwell?branch=master#d018ee22e4b5241dec2bc32ca67f3d4caaecee47" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c7090af3d300424caa81976b8c97bca41cd70e861272c072e188ae082fb49f9"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -340,9 +336,9 @@ dependencies = [
[[package]] [[package]]
name = "insta" name = "insta"
version = "1.8.0" version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "15226a375927344c78d39dc6b49e2d5562a5b0705e26a589093c6792e52eed8e" checksum = "86c4e56d571b4cc829f0ce71506bd865a90369eeab5f3d3657ba96230beb8012"
dependencies = [ dependencies = [
"console", "console",
"lazy_static", "lazy_static",
@ -355,27 +351,27 @@ dependencies = [
[[package]] [[package]]
name = "instant" name = "instant"
version = "0.1.10" version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bee0328b1209d157ef001c94dd85b4f8f64139adb0eac2659f4b08382b2f474d" checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
] ]
[[package]] [[package]]
name = "itertools" name = "itertools"
version = "0.10.1" version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69ddb889f9d0d08a67338271fa9b62996bc788c7796a5c18cf057420aaed5eaf" checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3"
dependencies = [ dependencies = [
"either", "either",
] ]
[[package]] [[package]]
name = "itoa" name = "itoa"
version = "0.4.8" version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35"
[[package]] [[package]]
name = "lalrpop" name = "lalrpop"
@ -417,15 +413,15 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.102" version = "0.2.112"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2a5ac8f984bfcf3a823267e5fde638acc3325f6496633a5da6bb6eb2171e103" checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125"
[[package]] [[package]]
name = "libloading" name = "libloading"
version = "0.7.1" version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0cf036d15402bea3c5d4de17b3fce76b3e4a56ebc1f577be0e7a72f7c607cf0" checksum = "afe203d669ec979b7128619bae5a63b7b42e9203c1b29146079ee05e2f604b52"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"winapi", "winapi",
@ -439,9 +435,9 @@ checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3"
[[package]] [[package]]
name = "llvm-sys" name = "llvm-sys"
version = "120.2.1" version = "130.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4a810627ac62b396f5fd2214ba9bbd8748d4d6efdc4d2c1c1303ea7a75763ce" checksum = "183612ff1acd400cd4faeb1cbf7cc725a868a46282e5c7b112ec5f0a5a49fae7"
dependencies = [ dependencies = [
"cc", "cc",
"lazy_static", "lazy_static",
@ -476,9 +472,9 @@ checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a"
[[package]] [[package]]
name = "memoffset" name = "memoffset"
version = "0.6.4" version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59accc507f1338036a0477ef61afdae33cde60840f4dfe481319ce3ad116ddf9" checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce"
dependencies = [ dependencies = [
"autocfg", "autocfg",
] ]
@ -501,7 +497,6 @@ version = "0.1.0"
dependencies = [ dependencies = [
"fxhash", "fxhash",
"lazy_static", "lazy_static",
"num-bigint 0.4.2",
"parking_lot", "parking_lot",
"string-interner", "string-interner",
] ]
@ -516,8 +511,6 @@ dependencies = [
"insta", "insta",
"itertools", "itertools",
"nac3parser", "nac3parser",
"num-bigint 0.3.3",
"num-traits",
"parking_lot", "parking_lot",
"rayon", "rayon",
"test-case", "test-case",
@ -533,8 +526,6 @@ dependencies = [
"lalrpop-util", "lalrpop-util",
"log", "log",
"nac3ast", "nac3ast",
"num-bigint 0.4.2",
"num-traits",
"phf", "phf",
"unic-emoji-char", "unic-emoji-char",
"unic-ucd-ident", "unic-ucd-ident",
@ -557,52 +548,11 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54"
[[package]]
name = "num-bigint"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f6f7833f2cbf2360a6cfd58cd41a53aa7a90bd4c202f5b1c7dd2ed73c57b2c3"
dependencies = [
"autocfg",
"num-integer",
"num-traits",
]
[[package]]
name = "num-bigint"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74e768dff5fb39a41b3bcd30bb25cf989706c90d028d1ad71971987aa309d535"
dependencies = [
"autocfg",
"num-integer",
"num-traits",
]
[[package]]
name = "num-integer"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db"
dependencies = [
"autocfg",
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290"
dependencies = [
"autocfg",
]
[[package]] [[package]]
name = "num_cpus" name = "num_cpus"
version = "1.13.0" version = "1.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1"
dependencies = [ dependencies = [
"hermit-abi", "hermit-abi",
"libc", "libc",
@ -610,9 +560,9 @@ dependencies = [
[[package]] [[package]]
name = "once_cell" name = "once_cell"
version = "1.8.0" version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5"
[[package]] [[package]]
name = "parking_lot" name = "parking_lot"
@ -738,9 +688,9 @@ checksum = "db8bcd96cb740d03149cbad5518db9fd87126a10ab519c011893b1754134c468"
[[package]] [[package]]
name = "ppv-lite86" name = "ppv-lite86"
version = "0.2.10" version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" checksum = "ed0cfbc8191465bed66e1718596ee0b0b35d5ee1f41c5df2189d0fe8bde535ba"
[[package]] [[package]]
name = "precomputed-hash" name = "precomputed-hash"
@ -756,9 +706,9 @@ checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5"
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.29" version = "1.0.34"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9f5105d4fdaab20335ca9565e106a5d9b82b6219b5ba735731124ac6711d23d" checksum = "2f84e92c0f7c9d58328b85a78557813e4bd845130db68d7184635344399423b1"
dependencies = [ dependencies = [
"unicode-xid", "unicode-xid",
] ]
@ -813,9 +763,9 @@ dependencies = [
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.9" version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
] ]
@ -939,15 +889,15 @@ dependencies = [
[[package]] [[package]]
name = "rustversion" name = "rustversion"
version = "1.0.5" version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61b3909d758bb75c79f23d4736fac9433868679d3ad2ea7a61e3c25cfda9a088" checksum = "f2cc38e8fa666e2de3c4aba7edeb5ffc5246c1c2ed0e3d17e560aeeba736b23f"
[[package]] [[package]]
name = "ryu" name = "ryu"
version = "1.0.5" version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f"
[[package]] [[package]]
name = "scopeguard" name = "scopeguard"
@ -975,18 +925,18 @@ dependencies = [
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.130" version = "1.0.132"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913" checksum = "8b9875c23cf305cd1fd7eb77234cbb705f21ea6a72c637a5c6db5fe4b8e7f008"
dependencies = [ dependencies = [
"serde_derive", "serde_derive",
] ]
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.130" version = "1.0.132"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7bc1a1ab1961464eae040d96713baa5a724a8152c1222492465b54322ec508b" checksum = "ecc0db5cb2556c0e558887d9bbdcf6ac4471e83ff66cf696e5419024d1606276"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -995,9 +945,9 @@ dependencies = [
[[package]] [[package]]
name = "serde_json" name = "serde_json"
version = "1.0.68" version = "1.0.73"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f690853975602e1bfe1ccbf50504d67174e3bcf340f23b5ea9992e0587a52d8" checksum = "bcbd0344bc6533bc7ec56df11d42fb70f1b912351c0825ccb7211b59d8af7cf5"
dependencies = [ dependencies = [
"itoa", "itoa",
"ryu", "ryu",
@ -1006,21 +956,21 @@ dependencies = [
[[package]] [[package]]
name = "serde_yaml" name = "serde_yaml"
version = "0.8.21" version = "0.8.23"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8c608a35705a5d3cdc9fbe403147647ff34b921f8e833e49306df898f9b20af" checksum = "a4a521f2940385c165a24ee286aa8599633d162077a54bdcae2a6fd5a7bfa7a0"
dependencies = [ dependencies = [
"dtoa",
"indexmap", "indexmap",
"ryu",
"serde", "serde",
"yaml-rust", "yaml-rust",
] ]
[[package]] [[package]]
name = "similar" name = "similar"
version = "1.3.0" version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ad1d488a557b235fc46dae55512ffbfc429d2482b08b4d9435ab07384ca8aec" checksum = "2e24979f63a11545f5f2c60141afe249d4f19f84581ea2138065e400941d83d3"
[[package]] [[package]]
name = "siphasher" name = "siphasher"
@ -1030,9 +980,9 @@ checksum = "533494a8f9b724d33625ab53c6c4800f7cc445895924a8ef649222dcb76e938b"
[[package]] [[package]]
name = "smallvec" name = "smallvec"
version = "1.6.1" version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" checksum = "1ecab6c735a6bb4139c0caafd0cc3635748bbb3acf4550e8138122099251f309"
[[package]] [[package]]
name = "string-interner" name = "string-interner"
@ -1047,21 +997,22 @@ dependencies = [
[[package]] [[package]]
name = "string_cache" name = "string_cache"
version = "0.8.1" version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ddb1139b5353f96e429e1a5e19fbaf663bddedaa06d1dbd49f82e352601209a" checksum = "923f0f39b6267d37d23ce71ae7235602134b250ace715dd2c90421998ddac0c6"
dependencies = [ dependencies = [
"lazy_static", "lazy_static",
"new_debug_unreachable", "new_debug_unreachable",
"parking_lot",
"phf_shared 0.8.0", "phf_shared 0.8.0",
"precomputed-hash", "precomputed-hash",
] ]
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.76" version = "1.0.83"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6f107db402c2c2055242dbf4d2af0e69197202e9faacbef9571bbe47f5a1b84" checksum = "23a1dfb999630e338648c83e91c59a4e9fb7620f520c3194b6b89e276f2f1959"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1105,9 +1056,9 @@ dependencies = [
[[package]] [[package]]
name = "test-case" name = "test-case"
version = "1.2.0" version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b114ece25254e97bf48dd4bfc2a12bad0647adacfe4cae1247a9ca6ad302cec" checksum = "c7cad0a06f9a61e94355aa3b3dc92d85ab9c83406722b1ca5e918d4297c12c23"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"proc-macro2", "proc-macro2",

View File

@ -10,4 +10,3 @@ members = [
[profile.release] [profile.release]
debug = true debug = true

View File

@ -2,11 +2,11 @@
"nodes": { "nodes": {
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1638887115, "lastModified": 1640264129,
"narHash": "sha256-emjtIeqyJ84Eb3X7APJruTrwcfnHQKs55XGljj62prs=", "narHash": "sha256-gfTFmZhnHE9G+Tr0fdMmo6p/FHi5QpkO9oPPYSu6JO0=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "1bd4bbd49bef217a3d1adea43498270d6e779d65", "rev": "1158f3463912d54cc981d61213839ec6c02570d3",
"type": "github" "type": "github"
}, },
"original": { "original": {

View File

@ -16,7 +16,6 @@
}) })
]; ];
}; };
cargoSha256 = "sha256-otKLhr58HYMjVXAof6AdObNpggPnvK6qOl7I+4LWIP8=";
msys2-python-tar = pkgs.fetchurl { msys2-python-tar = pkgs.fetchurl {
url = "https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-python-3.9.7-4-any.pkg.tar.zst"; url = "https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-python-3.9.7-4-any.pkg.tar.zst";
sha256 = "0iwlgbk4b457yn9djwqswid55xhyyi35qymz1lfh42xwdpxdm47c"; sha256 = "0iwlgbk4b457yn9djwqswid55xhyyi35qymz1lfh42xwdpxdm47c";
@ -54,7 +53,7 @@
pkgs.rustPlatform.buildRustPackage { pkgs.rustPlatform.buildRustPackage {
name = "nac3artiq"; name = "nac3artiq";
src = self; src = self;
inherit cargoSha256; cargoLock = { lockFile = ./Cargo.lock; };
nativeBuildInputs = [ pkgs.python3 llvm-nac3 ]; nativeBuildInputs = [ pkgs.python3 llvm-nac3 ];
buildInputs = [ pkgs.python3 llvm-nac3 ]; buildInputs = [ pkgs.python3 llvm-nac3 ];
cargoBuildFlags = [ "--package" "nac3artiq" ]; cargoBuildFlags = [ "--package" "nac3artiq" ];
@ -67,15 +66,76 @@
''; '';
} }
); );
# LLVM PGO support
llvm-nac3-instrumented = pkgs.callPackage "${self}/llvm" {
stdenv = pkgs.llvmPackages_13.stdenv;
extraCmakeFlags = [ "-DLLVM_BUILD_INSTRUMENTED=IR" ];
};
nac3artiq-instrumented = pkgs.python3Packages.toPythonModule (
pkgs.rustPlatform.buildRustPackage {
name = "nac3artiq-instrumented";
src = self;
cargoLock = { lockFile = ./Cargo.lock; };
nativeBuildInputs = [ pkgs.python3 llvm-nac3-instrumented ];
buildInputs = [ pkgs.python3 llvm-nac3-instrumented ];
cargoBuildFlags = [ "--package" "nac3artiq" "--features" "init-llvm-profile" ];
doCheck = false;
configurePhase =
''
export CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUSTFLAGS="-C link-arg=-L${pkgs.llvmPackages_13.compiler-rt}/lib/linux -C link-arg=-lclang_rt.profile-x86_64"
'';
installPhase =
''
TARGET_DIR=$out/${pkgs.python3Packages.python.sitePackages}
mkdir -p $TARGET_DIR
cp target/x86_64-unknown-linux-gnu/release/libnac3artiq.so $TARGET_DIR/nac3artiq.so
'';
}
);
nac3artiq-profile = pkgs.stdenvNoCC.mkDerivation {
name = "nac3artiq-profile";
src = self;
buildInputs = [ (pkgs.python3.withPackages(ps: [ ps.numpy nac3artiq-instrumented ])) pkgs.lld_13 pkgs.llvmPackages_13.libllvm ];
phases = [ "buildPhase" "installPhase" ];
# TODO: get more representative code.
buildPhase = "python $src/nac3artiq/demo/demo.py";
installPhase =
''
mkdir $out
llvm-profdata merge -o $out/llvm.profdata /build/llvm/build/profiles/*
'';
};
llvm-nac3-pgo = pkgs.callPackage "${self}/llvm" {
stdenv = pkgs.llvmPackages_13.stdenv;
extraCmakeFlags = [ "-DLLVM_PROFDATA_FILE=${nac3artiq-profile}/llvm.profdata" ];
};
nac3artiq-pgo = pkgs.python3Packages.toPythonModule (
pkgs.rustPlatform.buildRustPackage {
name = "nac3artiq-pgo";
src = self;
cargoLock = { lockFile = ./Cargo.lock; };
nativeBuildInputs = [ pkgs.python3 llvm-nac3-pgo ];
buildInputs = [ pkgs.python3 llvm-nac3-pgo ];
cargoBuildFlags = [ "--package" "nac3artiq" ];
cargoTestFlags = [ "--package" "nac3ast" "--package" "nac3parser" "--package" "nac3core" "--package" "nac3artiq" ];
installPhase =
''
TARGET_DIR=$out/${pkgs.python3Packages.python.sitePackages}
mkdir -p $TARGET_DIR
cp target/x86_64-unknown-linux-gnu/release/libnac3artiq.so $TARGET_DIR/nac3artiq.so
'';
}
);
}; };
packages.x86_64-w64-mingw32 = rec { packages.x86_64-w64-mingw32 = rec {
llvm-nac3 = pkgs-mingw.callPackage "${self}/llvm" { inherit (pkgs) llvmPackages_12; }; llvm-nac3 = pkgs-mingw.callPackage "${self}/llvm" { inherit (pkgs) llvmPackages_13; };
nac3artiq = pkgs-mingw.python3Packages.toPythonModule ( nac3artiq = pkgs-mingw.python3Packages.toPythonModule (
pkgs-mingw.rustPlatform.buildRustPackage { pkgs-mingw.rustPlatform.buildRustPackage {
name = "nac3artiq"; name = "nac3artiq";
src = self; src = self;
inherit cargoSha256; cargoLock = { lockFile = ./Cargo.lock; };
nativeBuildInputs = [ pkgs.zip ]; nativeBuildInputs = [ pkgs.zip ];
buildInputs = [ pkgs-mingw.zlib ]; buildInputs = [ pkgs-mingw.zlib ];
configurePhase = configurePhase =
@ -113,8 +173,8 @@
name = "nac3-dev-shell"; name = "nac3-dev-shell";
buildInputs = with pkgs; [ buildInputs = with pkgs; [
packages.x86_64-linux.llvm-nac3 packages.x86_64-linux.llvm-nac3
clang_12 clang_13
lld_12 lld_13
cargo cargo
cargo-insta cargo-insta
rustc rustc

View File

@ -7,17 +7,18 @@
, libbfd , libbfd
, ncurses , ncurses
, zlib , zlib
, llvmPackages_12 , which
, llvmPackages_13
, debugVersion ? false , debugVersion ? false
, enableManpages ? false , enableManpages ? false
, enableSharedLibraries ? false , enableSharedLibraries ? false
, enablePolly ? false , extraCmakeFlags ? []
}: }:
let let
inherit (lib) optional optionals optionalString; inherit (lib) optional optionals optionalString;
release_version = "12.0.1"; release_version = "13.0.0";
candidate = ""; # empty or "rcN" candidate = ""; # empty or "rcN"
dash-candidate = lib.optionalString (candidate != "") "-${candidate}"; dash-candidate = lib.optionalString (candidate != "") "-${candidate}";
version = "${release_version}${dash-candidate}"; # differentiating these (variables) is important for RCs version = "${release_version}${dash-candidate}"; # differentiating these (variables) is important for RCs
@ -34,16 +35,12 @@ in stdenv.mkDerivation (rec {
pname = "llvm"; pname = "llvm";
inherit version; inherit version;
src = fetch pname "1pzx9zrmd7r3481sbhwvkms68fwhffpp4mmz45dgrkjpyl2q96kx"; src = fetch pname "sha256-QI0RcIZD6oJvUZ/3l2H838EtZBolECKe7EWecvgWMCA=";
polly_src = fetch "polly" "1yfm9ixda4a2sx7ak5vswijx4ydk5lv1c1xh39xmd2kh299y4m12";
unpackPhase = '' unpackPhase = ''
unpackFile $src unpackFile $src
mv llvm-${release_version}* llvm mv llvm-${release_version}* llvm
sourceRoot=$PWD/llvm sourceRoot=$PWD/llvm
'' + optionalString enablePolly ''
unpackFile $polly_src
mv polly-* $sourceRoot/tools/polly
''; '';
outputs = [ "out" "lib" "dev" "python" ]; outputs = [ "out" "lib" "dev" "python" ];
@ -56,17 +53,18 @@ in stdenv.mkDerivation (rec {
propagatedBuildInputs = optionals (stdenv.buildPlatform == stdenv.hostPlatform) [ ncurses ] propagatedBuildInputs = optionals (stdenv.buildPlatform == stdenv.hostPlatform) [ ncurses ]
++ [ zlib ]; ++ [ zlib ];
checkInputs = [ which ];
patches = [ patches = [
./gnu-install-dirs.patch ./gnu-install-dirs.patch
# On older CPUs (e.g. Hydra/wendy) we'd be getting an error in this test. # Fix random compiler crashes: https://bugs.llvm.org/show_bug.cgi?id=50611
(fetchpatch { (fetchpatch {
name = "uops-CMOV16rm-noreg.diff"; url = "https://raw.githubusercontent.com/archlinux/svntogit-packages/4764a4f8c920912a2bfd8b0eea57273acfe0d8a8/trunk/no-strict-aliasing-DwarfCompileUnit.patch";
url = "https://github.com/llvm/llvm-project/commit/9e9f991ac033.diff"; sha256 = "18l6mrvm2vmwm77ckcnbjvh6ybvn72rhrb799d4qzwac4x2ifl7g";
sha256 = "sha256:12s8vr6ibri8b48h2z38f3afhwam10arfiqfy4yg37bmc054p5hi";
stripLen = 1; stripLen = 1;
}) })
./llvm-future-riscv-abi.diff ./llvm-future-riscv-abi.diff
] ++ lib.optional enablePolly ./gnu-install-dirs-polly.patch; ];
postPatch = optionalString stdenv.isDarwin '' postPatch = optionalString stdenv.isDarwin ''
substituteInPlace cmake/modules/AddLLVM.cmake \ substituteInPlace cmake/modules/AddLLVM.cmake \
@ -85,8 +83,7 @@ in stdenv.mkDerivation (rec {
substituteInPlace unittests/IR/CMakeLists.txt \ substituteInPlace unittests/IR/CMakeLists.txt \
--replace "PassBuilderCallbacksTest.cpp" "" --replace "PassBuilderCallbacksTest.cpp" ""
rm unittests/IR/PassBuilderCallbacksTest.cpp rm unittests/IR/PassBuilderCallbacksTest.cpp
# TODO: Fix failing tests: rm test/tools/llvm-objcopy/ELF/mirror-permissions-unix.test
rm test/DebugInfo/X86/vla-multi.ll
'' + optionalString stdenv.hostPlatform.isMusl '' '' + optionalString stdenv.hostPlatform.isMusl ''
patch -p1 -i ${../../TLI-musl.patch} patch -p1 -i ${../../TLI-musl.patch}
substituteInPlace unittests/Support/CMakeLists.txt \ substituteInPlace unittests/Support/CMakeLists.txt \
@ -139,7 +136,7 @@ in stdenv.mkDerivation (rec {
"-DCAN_TARGET_i386=false" "-DCAN_TARGET_i386=false"
] ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ ] ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
"-DCMAKE_CROSSCOMPILING=True" "-DCMAKE_CROSSCOMPILING=True"
"-DLLVM_TABLEGEN=${llvmPackages_12.tools.llvm}/bin/llvm-tblgen" "-DLLVM_TABLEGEN=${llvmPackages_13.tools.llvm}/bin/llvm-tblgen"
( (
let let
nativeCC = pkgsBuildBuild.targetPackages.stdenv.cc; nativeCC = pkgsBuildBuild.targetPackages.stdenv.cc;
@ -153,7 +150,7 @@ in stdenv.mkDerivation (rec {
]; ];
in "-DCROSS_TOOLCHAIN_FLAGS_NATIVE:list=${lib.concatStringsSep ";" nativeToolchainFlags}" in "-DCROSS_TOOLCHAIN_FLAGS_NATIVE:list=${lib.concatStringsSep ";" nativeToolchainFlags}"
) )
]; ] ++ extraCmakeFlags;
postBuild = '' postBuild = ''
rm -fR $out rm -fR $out

View File

@ -1,105 +0,0 @@
diff --git a/tools/polly/CMakeLists.txt b/tools/polly/CMakeLists.txt
index ca7c04c565bb..6ed5db5dd4f8 100644
--- a/tools/polly/CMakeLists.txt
+++ b/tools/polly/CMakeLists.txt
@@ -2,7 +2,11 @@
if (NOT DEFINED LLVM_MAIN_SRC_DIR)
project(Polly)
cmake_minimum_required(VERSION 3.13.4)
+endif()
+
+include(GNUInstallDirs)
+if (NOT DEFINED LLVM_MAIN_SRC_DIR)
# Where is LLVM installed?
find_package(LLVM CONFIG REQUIRED)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LLVM_CMAKE_DIR})
@@ -122,13 +126,13 @@ include_directories(
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
install(DIRECTORY include/
- DESTINATION include
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING
PATTERN "*.h"
)
install(DIRECTORY ${POLLY_BINARY_DIR}/include/
- DESTINATION include
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING
PATTERN "*.h"
PATTERN "CMakeFiles" EXCLUDE
diff --git a/tools/polly/cmake/CMakeLists.txt b/tools/polly/cmake/CMakeLists.txt
index 7cc129ba2e90..137be25e4b80 100644
--- a/tools/polly/cmake/CMakeLists.txt
+++ b/tools/polly/cmake/CMakeLists.txt
@@ -79,18 +79,18 @@ file(GENERATE
# Generate PollyConfig.cmake for the install tree.
unset(POLLY_EXPORTS)
-set(POLLY_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
+set(POLLY_INSTALL_PREFIX "")
set(POLLY_CONFIG_LLVM_CMAKE_DIR "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}")
-set(POLLY_CONFIG_CMAKE_DIR "${POLLY_INSTALL_PREFIX}/${POLLY_INSTALL_PACKAGE_DIR}")
-set(POLLY_CONFIG_LIBRARY_DIRS "${POLLY_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}")
+set(POLLY_CONFIG_CMAKE_DIR "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_PREFIX}/${POLLY_INSTALL_PACKAGE_DIR}")
+set(POLLY_CONFIG_LIBRARY_DIRS "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX}")
if (POLLY_BUNDLED_ISL)
set(POLLY_CONFIG_INCLUDE_DIRS
- "${POLLY_INSTALL_PREFIX}/include"
- "${POLLY_INSTALL_PREFIX}/include/polly"
+ "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_LIBDIR}"
+ "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_LIBDIR}/polly"
)
else()
set(POLLY_CONFIG_INCLUDE_DIRS
- "${POLLY_INSTALL_PREFIX}/include"
+ "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_INCLUDEDIR}"
${ISL_INCLUDE_DIRS}
)
endif()
@@ -100,12 +100,12 @@ endif()
foreach(tgt IN LISTS POLLY_CONFIG_EXPORTED_TARGETS)
get_target_property(tgt_type ${tgt} TYPE)
if (tgt_type STREQUAL "EXECUTABLE")
- set(tgt_prefix "bin/")
+ set(tgt_prefix "${CMAKE_INSTALL_BINDIR}/")
else()
- set(tgt_prefix "lib/")
+ set(tgt_prefix "${CMAKE_INSTALL_LIBDIR}/")
endif()
- set(tgt_path "${CMAKE_INSTALL_PREFIX}/${tgt_prefix}$<TARGET_FILE_NAME:${tgt}>")
+ set(tgt_path "${tgt_prefix}$<TARGET_FILE_NAME:${tgt}>")
file(RELATIVE_PATH tgt_path ${POLLY_CONFIG_CMAKE_DIR} ${tgt_path})
if (NOT tgt_type STREQUAL "INTERFACE_LIBRARY")
diff --git a/tools/polly/cmake/polly_macros.cmake b/tools/polly/cmake/polly_macros.cmake
index 518a09b45a42..bd9d6f5542ad 100644
--- a/tools/polly/cmake/polly_macros.cmake
+++ b/tools/polly/cmake/polly_macros.cmake
@@ -44,8 +44,8 @@ macro(add_polly_library name)
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LLVMPolly")
install(TARGETS ${name}
EXPORT LLVMExports
- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX})
endif()
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
endmacro(add_polly_library)
diff --git a/tools/polly/lib/External/CMakeLists.txt b/tools/polly/lib/External/CMakeLists.txt
index 8991094d92c7..178d8ad606bb 100644
--- a/tools/polly/lib/External/CMakeLists.txt
+++ b/tools/polly/lib/External/CMakeLists.txt
@@ -275,7 +275,7 @@ if (POLLY_BUNDLED_ISL)
install(DIRECTORY
${ISL_SOURCE_DIR}/include/
${ISL_BINARY_DIR}/include/
- DESTINATION include/polly
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/polly
FILES_MATCHING
PATTERN "*.h"
PATTERN "CMakeFiles" EXCLUDE

View File

@ -1,8 +1,8 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt
index 277d0fe54d7b..af69c8be8745 100644 index 135036f509d2..265c36f8211b 100644
--- a/CMakeLists.txt --- a/CMakeLists.txt
+++ b/CMakeLists.txt +++ b/CMakeLists.txt
@@ -256,15 +256,21 @@ if (CMAKE_BUILD_TYPE AND @@ -270,15 +270,21 @@ if (CMAKE_BUILD_TYPE AND
message(FATAL_ERROR "Invalid value for CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") message(FATAL_ERROR "Invalid value for CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
endif() endif()
@ -25,7 +25,7 @@ index 277d0fe54d7b..af69c8be8745 100644
# They are used as destination of target generators. # They are used as destination of target generators.
set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin) set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin)
set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}) set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX})
@@ -567,9 +573,9 @@ option (LLVM_ENABLE_SPHINX "Use Sphinx to generate llvm documentation." OFF) @@ -581,9 +587,9 @@ option (LLVM_ENABLE_SPHINX "Use Sphinx to generate llvm documentation." OFF)
option (LLVM_ENABLE_OCAMLDOC "Build OCaml bindings documentation." ON) option (LLVM_ENABLE_OCAMLDOC "Build OCaml bindings documentation." ON)
option (LLVM_ENABLE_BINDINGS "Build bindings." ON) option (LLVM_ENABLE_BINDINGS "Build bindings." ON)
@ -37,7 +37,7 @@ index 277d0fe54d7b..af69c8be8745 100644
CACHE STRING "OCamldoc-generated HTML documentation install directory") CACHE STRING "OCamldoc-generated HTML documentation install directory")
option (LLVM_BUILD_EXTERNAL_COMPILER_RT option (LLVM_BUILD_EXTERNAL_COMPILER_RT
@@ -1027,7 +1033,7 @@ endif() @@ -1048,7 +1054,7 @@ endif()
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
install(DIRECTORY include/llvm include/llvm-c install(DIRECTORY include/llvm include/llvm-c
@ -46,7 +46,7 @@ index 277d0fe54d7b..af69c8be8745 100644
COMPONENT llvm-headers COMPONENT llvm-headers
FILES_MATCHING FILES_MATCHING
PATTERN "*.def" PATTERN "*.def"
@@ -1038,7 +1044,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) @@ -1059,7 +1065,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
) )
install(DIRECTORY ${LLVM_INCLUDE_DIR}/llvm ${LLVM_INCLUDE_DIR}/llvm-c install(DIRECTORY ${LLVM_INCLUDE_DIR}/llvm ${LLVM_INCLUDE_DIR}/llvm-c
@ -55,7 +55,7 @@ index 277d0fe54d7b..af69c8be8745 100644
COMPONENT llvm-headers COMPONENT llvm-headers
FILES_MATCHING FILES_MATCHING
PATTERN "*.def" PATTERN "*.def"
@@ -1052,13 +1058,13 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) @@ -1073,13 +1079,13 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
if (LLVM_INSTALL_MODULEMAPS) if (LLVM_INSTALL_MODULEMAPS)
install(DIRECTORY include/llvm include/llvm-c install(DIRECTORY include/llvm include/llvm-c
@ -72,11 +72,11 @@ index 277d0fe54d7b..af69c8be8745 100644
RENAME "module.extern.modulemap" RENAME "module.extern.modulemap"
) )
diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake
index 97c9980c7de3..409e8b615f75 100644 index 9c2b85374307..5531ceeb2eeb 100644
--- a/cmake/modules/AddLLVM.cmake --- a/cmake/modules/AddLLVM.cmake
+++ b/cmake/modules/AddLLVM.cmake +++ b/cmake/modules/AddLLVM.cmake
@@ -804,9 +804,9 @@ macro(add_llvm_library name) @@ -818,9 +818,9 @@ macro(add_llvm_library name)
get_target_export_arg(${name} LLVM export_to_llvmexports ${umbrella})
install(TARGETS ${name} install(TARGETS ${name}
${export_to_llvmexports} ${export_to_llvmexports}
- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} - LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name}
@ -88,7 +88,7 @@ index 97c9980c7de3..409e8b615f75 100644
if (NOT LLVM_ENABLE_IDE) if (NOT LLVM_ENABLE_IDE)
add_llvm_install_targets(install-${name} add_llvm_install_targets(install-${name}
@@ -1022,7 +1022,7 @@ function(process_llvm_pass_plugins) @@ -1036,7 +1036,7 @@ function(process_llvm_pass_plugins)
"set(LLVM_STATIC_EXTENSIONS ${LLVM_STATIC_EXTENSIONS})") "set(LLVM_STATIC_EXTENSIONS ${LLVM_STATIC_EXTENSIONS})")
install(FILES install(FILES
${llvm_cmake_builddir}/LLVMConfigExtensions.cmake ${llvm_cmake_builddir}/LLVMConfigExtensions.cmake
@ -97,7 +97,7 @@ index 97c9980c7de3..409e8b615f75 100644
COMPONENT cmake-exports) COMPONENT cmake-exports)
set(ExtensionDef "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def") set(ExtensionDef "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def")
@@ -1242,7 +1242,7 @@ macro(add_llvm_example name) @@ -1250,7 +1250,7 @@ macro(add_llvm_example name)
endif() endif()
add_llvm_executable(${name} ${ARGN}) add_llvm_executable(${name} ${ARGN})
if( LLVM_BUILD_EXAMPLES ) if( LLVM_BUILD_EXAMPLES )
@ -106,7 +106,7 @@ index 97c9980c7de3..409e8b615f75 100644
endif() endif()
set_target_properties(${name} PROPERTIES FOLDER "Examples") set_target_properties(${name} PROPERTIES FOLDER "Examples")
endmacro(add_llvm_example name) endmacro(add_llvm_example name)
@@ -1854,7 +1854,7 @@ function(llvm_install_library_symlink name dest type) @@ -1868,7 +1868,7 @@ function(llvm_install_library_symlink name dest type)
set(full_name ${CMAKE_${type}_LIBRARY_PREFIX}${name}${CMAKE_${type}_LIBRARY_SUFFIX}) set(full_name ${CMAKE_${type}_LIBRARY_PREFIX}${name}${CMAKE_${type}_LIBRARY_SUFFIX})
set(full_dest ${CMAKE_${type}_LIBRARY_PREFIX}${dest}${CMAKE_${type}_LIBRARY_SUFFIX}) set(full_dest ${CMAKE_${type}_LIBRARY_PREFIX}${dest}${CMAKE_${type}_LIBRARY_SUFFIX})
@ -115,8 +115,8 @@ index 97c9980c7de3..409e8b615f75 100644
if(WIN32 AND "${type}" STREQUAL "SHARED") if(WIN32 AND "${type}" STREQUAL "SHARED")
set(output_dir bin) set(output_dir bin)
endif() endif()
@@ -1871,7 +1871,7 @@ function(llvm_install_library_symlink name dest type) @@ -1879,7 +1879,7 @@ function(llvm_install_library_symlink name dest type)
endif()
endfunction() endfunction()
-function(llvm_install_symlink name dest) -function(llvm_install_symlink name dest)
@ -124,7 +124,7 @@ index 97c9980c7de3..409e8b615f75 100644
cmake_parse_arguments(ARG "ALWAYS_GENERATE" "COMPONENT" "" ${ARGN}) cmake_parse_arguments(ARG "ALWAYS_GENERATE" "COMPONENT" "" ${ARGN})
foreach(path ${CMAKE_MODULE_PATH}) foreach(path ${CMAKE_MODULE_PATH})
if(EXISTS ${path}/LLVMInstallSymlink.cmake) if(EXISTS ${path}/LLVMInstallSymlink.cmake)
@@ -1894,7 +1894,7 @@ function(llvm_install_symlink name dest) @@ -1902,7 +1902,7 @@ function(llvm_install_symlink name dest)
set(full_dest ${dest}${CMAKE_EXECUTABLE_SUFFIX}) set(full_dest ${dest}${CMAKE_EXECUTABLE_SUFFIX})
install(SCRIPT ${INSTALL_SYMLINK} install(SCRIPT ${INSTALL_SYMLINK}
@ -133,7 +133,7 @@ index 97c9980c7de3..409e8b615f75 100644
COMPONENT ${component}) COMPONENT ${component})
if (NOT LLVM_ENABLE_IDE AND NOT ARG_ALWAYS_GENERATE) if (NOT LLVM_ENABLE_IDE AND NOT ARG_ALWAYS_GENERATE)
@@ -1977,7 +1977,8 @@ function(add_llvm_tool_symlink link_name target) @@ -1985,7 +1985,8 @@ function(add_llvm_tool_symlink link_name target)
endif() endif()
if ((TOOL_IS_TOOLCHAIN OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY) AND LLVM_BUILD_TOOLS) if ((TOOL_IS_TOOLCHAIN OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY) AND LLVM_BUILD_TOOLS)
@ -143,12 +143,12 @@ index 97c9980c7de3..409e8b615f75 100644
endif() endif()
endif() endif()
endfunction() endfunction()
@@ -2100,9 +2101,9 @@ function(llvm_setup_rpath name) @@ -2114,9 +2115,9 @@ function(llvm_setup_rpath name)
# Since BUILD_SHARED_LIBS is only recommended for use by developers,
if (APPLE) # hardcode the rpath to build/install lib dir first in this mode.
set(_install_name_dir INSTALL_NAME_DIR "@rpath") # FIXME: update this when there is better solution.
- set(_install_rpath "@loader_path/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) - set(_install_rpath "${LLVM_LIBRARY_OUTPUT_INTDIR}" "${CMAKE_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir})
+ set(_install_rpath "@loader_path/../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) + set(_install_rpath "${LLVM_LIBRARY_OUTPUT_INTDIR}" "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir})
elseif(UNIX) elseif(UNIX)
- set(_install_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) - set(_install_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir})
+ set(_install_rpath "\$ORIGIN/../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) + set(_install_rpath "\$ORIGIN/../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir})
@ -185,16 +185,18 @@ index e80c3b5c1cac..482f6d715ef5 100644
# '/.' indicates: copy the contents of the directory directly into # '/.' indicates: copy the contents of the directory directly into
diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt
index 505dc9a29d70..36e6c63af3f4 100644 index 51b6a4fdc284..4adc2acfc074 100644
--- a/cmake/modules/CMakeLists.txt --- a/cmake/modules/CMakeLists.txt
+++ b/cmake/modules/CMakeLists.txt +++ b/cmake/modules/CMakeLists.txt
@@ -1,4 +1,4 @@ @@ -1,6 +1,6 @@
include(LLVMDistributionSupport)
-set(LLVM_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm) -set(LLVM_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm)
+set(LLVM_INSTALL_PACKAGE_DIR ${LLVM_INSTALL_CMAKE_DIR} CACHE STRING "Path for CMake subdirectory (defaults to 'cmake/llvm')") +set(LLVM_INSTALL_PACKAGE_DIR ${LLVM_INSTALL_CMAKE_DIR} CACHE STRING "Path for CMake subdirectory (defaults to 'cmake/llvm')")
set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}") set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}")
# First for users who use an installed LLVM, create the LLVMExports.cmake file. # First for users who use an installed LLVM, create the LLVMExports.cmake file.
@@ -107,13 +107,13 @@ foreach(p ${_count}) @@ -109,13 +109,13 @@ foreach(p ${_count})
set(LLVM_CONFIG_CODE "${LLVM_CONFIG_CODE} set(LLVM_CONFIG_CODE "${LLVM_CONFIG_CODE}
get_filename_component(LLVM_INSTALL_PREFIX \"\${LLVM_INSTALL_PREFIX}\" PATH)") get_filename_component(LLVM_INSTALL_PREFIX \"\${LLVM_INSTALL_PREFIX}\" PATH)")
endforeach(p) endforeach(p)
@ -212,32 +214,32 @@ index 505dc9a29d70..36e6c63af3f4 100644
# Generate a default location for lit # Generate a default location for lit
if (LLVM_INSTALL_UTILS AND LLVM_BUILD_UTILS) if (LLVM_INSTALL_UTILS AND LLVM_BUILD_UTILS)
diff --git a/cmake/modules/LLVMInstallSymlink.cmake b/cmake/modules/LLVMInstallSymlink.cmake diff --git a/cmake/modules/LLVMInstallSymlink.cmake b/cmake/modules/LLVMInstallSymlink.cmake
index 09fed8085c23..aa79f192abf0 100644 index 3e6a2c9a2648..52e14d955c60 100644
--- a/cmake/modules/LLVMInstallSymlink.cmake --- a/cmake/modules/LLVMInstallSymlink.cmake
+++ b/cmake/modules/LLVMInstallSymlink.cmake +++ b/cmake/modules/LLVMInstallSymlink.cmake
@@ -10,7 +10,7 @@ function(install_symlink name target outdir) @@ -4,7 +4,7 @@
set(LINK_OR_COPY copy)
endif()
function(install_symlink name target outdir)
set(DESTDIR $ENV{DESTDIR})
- set(bindir "${DESTDIR}${CMAKE_INSTALL_PREFIX}/${outdir}/") - set(bindir "${DESTDIR}${CMAKE_INSTALL_PREFIX}/${outdir}/")
+ set(bindir "${DESTDIR}${outdir}/") + set(bindir "${DESTDIR}${outdir}/")
message(STATUS "Creating ${name}") message(STATUS "Creating ${name}")
diff --git a/docs/CMake.rst b/docs/CMake.rst diff --git a/docs/CMake.rst b/docs/CMake.rst
index bb821b417ad9..6a528f7c2ad3 100644 index f1ac2c7d4934..c6e1469b5e13 100644
--- a/docs/CMake.rst --- a/docs/CMake.rst
+++ b/docs/CMake.rst +++ b/docs/CMake.rst
@@ -196,7 +196,7 @@ CMake manual, or execute ``cmake --help-variable VARIABLE_NAME``. @@ -202,7 +202,7 @@ CMake manual, or execute ``cmake --help-variable VARIABLE_NAME``.
**LLVM_LIBDIR_SUFFIX**:STRING **LLVM_LIBDIR_SUFFIX**:STRING
Extra suffix to append to the directory where libraries are to be Extra suffix to append to the directory where libraries are to be
installed. On a 64-bit architecture, one could use ``-DLLVM_LIBDIR_SUFFIX=64`` installed. On a 64-bit architecture, one could use ``-DLLVM_LIBDIR_SUFFIX=64``
- to install libraries to ``/usr/lib64``. - to install libraries to ``/usr/lib64``.
+ to install libraries to ``/usr/lib64``. See also ``CMAKE_INSTALL_LIBDIR``. + to install libraries to ``/usr/lib64``. See also ``CMAKE_INSTALL_LIBDIR``.
**CMAKE_C_FLAGS**:STRING Rarely-used CMake variables
Extra flags to use when compiling C source files. ---------------------------
@@ -550,8 +550,8 @@ LLVM-specific variables @@ -551,8 +551,8 @@ LLVM-specific variables
**LLVM_INSTALL_DOXYGEN_HTML_DIR**:STRING **LLVM_INSTALL_DOXYGEN_HTML_DIR**:STRING
The path to install Doxygen-generated HTML documentation to. This path can The path to install Doxygen-generated HTML documentation to. This path can
@ -246,47 +248,9 @@ index bb821b417ad9..6a528f7c2ad3 100644
+ either be absolute or relative to the ``CMAKE_INSTALL_PREFIX``. Defaults to + either be absolute or relative to the ``CMAKE_INSTALL_PREFIX``. Defaults to
+ `${CMAKE_INSTALL_DOCDIR}/${project}/doxygen-html`. + `${CMAKE_INSTALL_DOCDIR}/${project}/doxygen-html`.
**LLVM_ENABLE_SPHINX**:BOOL **LLVM_LINK_LLVM_DYLIB**:BOOL
If specified, CMake will search for the ``sphinx-build`` executable and will make If enabled, tools will be linked with the libLLVM shared library. Defaults
@@ -582,13 +582,33 @@ LLVM-specific variables @@ -792,9 +792,11 @@ the ``cmake`` command or by setting it directly in ``ccmake`` or ``cmake-gui``).
**LLVM_INSTALL_SPHINX_HTML_DIR**:STRING
The path to install Sphinx-generated HTML documentation to. This path can
- either be absolute or relative to the CMAKE_INSTALL_PREFIX. Defaults to
- `share/doc/llvm/html`.
+ either be absolute or relative to the ``CMAKE_INSTALL_PREFIX``. Defaults to
+ `${CMAKE_INSTALL_DOCDIR}/${project}/html`.
**LLVM_INSTALL_OCAMLDOC_HTML_DIR**:STRING
The path to install OCamldoc-generated HTML documentation to. This path can
- either be absolute or relative to the CMAKE_INSTALL_PREFIX. Defaults to
- `share/doc/llvm/ocaml-html`.
+ either be absolute or relative to the ``CMAKE_INSTALL_PREFIX``. Defaults to
+ `${CMAKE_INSTALL_DOCDIR}/${project}/ocaml-html`.
+
+**CMAKE_INSTALL_BINDIR**:STRING
+ The path to install binary tools, relative to the ``CMAKE_INSTALL_PREFIX``.
+ Defaults to `bin`.
+
+**CMAKE_INSTALL_LIBDIR**:STRING
+ The path to install libraries, relative to the ``CMAKE_INSTALL_PREFIX``.
+ Defaults to `lib`.
+
+**CMAKE_INSTALL_INCLUDEDIR**:STRING
+ The path to install header files, relative to the ``CMAKE_INSTALL_PREFIX``.
+ Defaults to `include`.
+
+**CMAKE_INSTALL_DOCDIR**:STRING
+ The path to install documentation, relative to the ``CMAKE_INSTALL_PREFIX``.
+ Defaults to `share/doc`.
+
+**CMAKE_INSTALL_MANDIR**:STRING
+ The path to install manpage files, relative to the ``CMAKE_INSTALL_PREFIX``.
+ Defaults to `share/man`.
**LLVM_CREATE_XCODE_TOOLCHAIN**:BOOL
macOS Only: If enabled CMake will generate a target named
@@ -786,9 +806,11 @@ the ``cmake`` command or by setting it directly in ``ccmake`` or ``cmake-gui``).
This file is available in two different locations. This file is available in two different locations.
@ -377,11 +341,11 @@ index 1a2f04552d13..44fa7d3eec6b 100644
} }
diff --git a/tools/lto/CMakeLists.txt b/tools/lto/CMakeLists.txt diff --git a/tools/lto/CMakeLists.txt b/tools/lto/CMakeLists.txt
index 2963f97cad88..69d66c9c9ca1 100644 index 0af29ad762c5..37b99b83e35c 100644
--- a/tools/lto/CMakeLists.txt --- a/tools/lto/CMakeLists.txt
+++ b/tools/lto/CMakeLists.txt +++ b/tools/lto/CMakeLists.txt
@@ -25,7 +25,7 @@ add_llvm_library(LTO SHARED INSTALL_WITH_TOOLCHAIN ${SOURCES} DEPENDS @@ -33,7 +33,7 @@ add_llvm_library(${LTO_LIBRARY_NAME} ${LTO_LIBRARY_TYPE} INSTALL_WITH_TOOLCHAIN
intrinsics_gen) ${SOURCES} DEPENDS intrinsics_gen)
install(FILES ${LLVM_MAIN_INCLUDE_DIR}/llvm-c/lto.h install(FILES ${LLVM_MAIN_INCLUDE_DIR}/llvm-c/lto.h
- DESTINATION include/llvm-c - DESTINATION include/llvm-c

View File

@ -16,7 +16,9 @@ nac3parser = { path = "../nac3parser" }
nac3core = { path = "../nac3core" } nac3core = { path = "../nac3core" }
[dependencies.inkwell] [dependencies.inkwell]
git = "https://github.com/TheDan64/inkwell" version = "0.1.0-beta.4"
branch = "master"
default-features = false default-features = false
features = ["llvm12-0", "target-x86", "target-arm", "target-riscv", "no-libffi-linking"] features = ["llvm13-0", "target-x86", "target-arm", "target-riscv", "no-libffi-linking"]
[features]
init-llvm-profile = []

View File

@ -57,7 +57,7 @@ impl<'b> CodeGenerator for ArtiqCodeGenerator<'b> {
}); });
let max = ctx let max = ctx
.builder .builder
.build_call(smax, &[old_end, now], "smax") .build_call(smax, &[old_end.into(), now.into()], "smax")
.try_as_basic_value() .try_as_basic_value()
.left() .left()
.unwrap(); .unwrap();
@ -165,7 +165,7 @@ impl<'b> CodeGenerator for ArtiqCodeGenerator<'b> {
}); });
let max = ctx let max = ctx
.builder .builder
.build_call(smax, &[end_val, outer_end_val], "smax") .build_call(smax, &[end_val.into(), outer_end_val.into()], "smax")
.try_as_basic_value() .try_as_basic_value()
.left() .left()
.unwrap(); .unwrap();

View File

@ -91,16 +91,18 @@ impl Nac3 {
) -> PyResult<()> { ) -> PyResult<()> {
let (module_name, source_file) = Python::with_gil(|py| -> PyResult<(String, String)> { let (module_name, source_file) = Python::with_gil(|py| -> PyResult<(String, String)> {
let module: &PyAny = module.extract(py)?; let module: &PyAny = module.extract(py)?;
let os_mod = PyModule::import(py, "os")?;
let path_fun = os_mod.getattr("path")?.getattr("abspath")?;
Ok(( Ok((
module.getattr("__name__")?.extract()?, module.getattr("__name__")?.extract()?,
module.getattr("__file__")?.extract()?, path_fun.call1((module.getattr("__file__")?,))?.extract()?
)) ))
})?; })?;
let source = fs::read_to_string(source_file).map_err(|e| { let source = fs::read_to_string(&source_file).map_err(|e| {
exceptions::PyIOError::new_err(format!("failed to read input file: {}", e)) exceptions::PyIOError::new_err(format!("failed to read input file: {}", e))
})?; })?;
let parser_result = parser::parse_program(&source) let parser_result = parser::parse_program(&source, source_file.into())
.map_err(|e| exceptions::PySyntaxError::new_err(format!("parse error: {}", e)))?; .map_err(|e| exceptions::PySyntaxError::new_err(format!("parse error: {}", e)))?;
for mut stmt in parser_result.into_iter() { for mut stmt in parser_result.into_iter() {
@ -437,7 +439,7 @@ impl Nac3 {
let (name, def_id, ty) = composer let (name, def_id, ty) = composer
.register_top_level(stmt.clone(), Some(resolver.clone()), path.clone()) .register_top_level(stmt.clone(), Some(resolver.clone()), path.clone())
.unwrap(); .map_err(|e| exceptions::PyRuntimeError::new_err(format!("nac3 compilation failure: {}", e)))?;
let id = *name_to_pyid.get(&name).unwrap(); let id = *name_to_pyid.get(&name).unwrap();
id_to_def.insert(id, def_id); id_to_def.insert(id, def_id);
if let Some(ty) = ty { if let Some(ty) = ty {
@ -476,7 +478,7 @@ impl Nac3 {
arg_names.join(", ") arg_names.join(", ")
) )
}; };
let mut synthesized = parse_program(&synthesized).unwrap(); let mut synthesized = parse_program(&synthesized, Default::default()).unwrap();
let resolver = Arc::new(Resolver(Arc::new(InnerResolver { let resolver = Arc::new(Resolver(Arc::new(InnerResolver {
id_to_type: self.builtins_ty.clone().into(), id_to_type: self.builtins_ty.clone().into(),
id_to_def: self.builtins_def.clone().into(), id_to_def: self.builtins_def.clone().into(),
@ -515,7 +517,9 @@ impl Nac3 {
); );
let signature = store.add_cty(signature); let signature = store.add_cty(signature);
composer.start_analysis(true).unwrap(); composer.start_analysis(true).map_err(|e| exceptions::PyRuntimeError::new_err(format!(
"nac3 compilation failure: {}", e
)))?;
let top_level = Arc::new(composer.make_top_level_context()); let top_level = Arc::new(composer.make_top_level_context());
let instance = { let instance = {
let defs = top_level.definitions.read(); let defs = top_level.definitions.read();
@ -683,8 +687,18 @@ impl Nac3 {
} }
} }
#[cfg(feature = "init-llvm-profile")]
extern "C" {
fn __llvm_profile_initialize();
}
#[pymodule] #[pymodule]
fn nac3artiq(_py: Python, m: &PyModule) -> PyResult<()> { fn nac3artiq(_py: Python, m: &PyModule) -> PyResult<()> {
#[cfg(feature = "init-llvm-profile")]
unsafe {
__llvm_profile_initialize();
}
Target::initialize_all(&InitializationConfig::default()); Target::initialize_all(&InitializationConfig::default());
m.add_class::<Nac3>()?; m.add_class::<Nac3>()?;
Ok(()) Ok(())

View File

@ -332,7 +332,7 @@ impl TimeFns for ExternTimeFns {
.get_function("at_mu") .get_function("at_mu")
.unwrap_or_else(|| ctx.module.add_function("at_mu", ctx.ctx.void_type().fn_type(&[ctx.ctx.i64_type().into()], false), None)); .unwrap_or_else(|| ctx.module.add_function("at_mu", ctx.ctx.void_type().fn_type(&[ctx.ctx.i64_type().into()], false), None));
ctx.builder ctx.builder
.build_call(at_mu, &[t], "at_mu"); .build_call(at_mu, &[t.into()], "at_mu");
} }
fn emit_delay_mu<'ctx, 'a>(&self, ctx: &mut CodeGenContext<'ctx, 'a>, dt: BasicValueEnum<'ctx>) { fn emit_delay_mu<'ctx, 'a>(&self, ctx: &mut CodeGenContext<'ctx, 'a>, dt: BasicValueEnum<'ctx>) {
@ -341,7 +341,7 @@ impl TimeFns for ExternTimeFns {
.get_function("delay_mu") .get_function("delay_mu")
.unwrap_or_else(|| ctx.module.add_function("delay_mu", ctx.ctx.void_type().fn_type(&[ctx.ctx.i64_type().into()], false), None)); .unwrap_or_else(|| ctx.module.add_function("delay_mu", ctx.ctx.void_type().fn_type(&[ctx.ctx.i64_type().into()], false), None));
ctx.builder ctx.builder
.build_call(delay_mu, &[dt], "delay_mu"); .build_call(delay_mu, &[dt.into()], "delay_mu");
} }
} }

View File

@ -10,7 +10,6 @@ constant-optimization = ["fold"]
fold = [] fold = []
[dependencies] [dependencies]
num-bigint = "0.4.0"
lazy_static = "1.4.0" lazy_static = "1.4.0"
parking_lot = "0.11.1" parking_lot = "0.11.1"
string-interner = "0.13.0" string-interner = "0.13.0"

View File

@ -1,12 +1,10 @@
use num_bigint::BigInt;
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub enum Constant { pub enum Constant {
None, None,
Bool(bool), Bool(bool),
Str(String), Str(String),
Bytes(Vec<u8>), Bytes(Vec<u8>),
Int(BigInt), Int(Option<i64>),
Tuple(Vec<Constant>), Tuple(Vec<Constant>),
Float(f64), Float(f64),
Complex { real: f64, imag: f64 }, Complex { real: f64, imag: f64 },
@ -28,9 +26,14 @@ impl From<bool> for Constant {
Self::Bool(b) Self::Bool(b)
} }
} }
impl From<BigInt> for Constant { impl From<i32> for Constant {
fn from(i: BigInt) -> Constant { fn from(i: i32) -> Constant {
Self::Int(i) Self::Int(Some(i as i64))
}
}
impl From<i64> for Constant {
fn from(i: i64) -> Constant {
Self::Int(Some(i))
} }
} }
@ -124,7 +127,7 @@ mod tests {
use crate::fold::Fold; use crate::fold::Fold;
use crate::*; use crate::*;
let location = Location::new(0, 0); let location = Location::new(0, 0, Default::default());
let custom = (); let custom = ();
let ast = Located { let ast = Located {
location, location,
@ -136,7 +139,7 @@ mod tests {
location, location,
custom, custom,
node: ExprKind::Constant { node: ExprKind::Constant {
value: BigInt::from(1).into(), value: 1.into(),
kind: None, kind: None,
}, },
}, },
@ -144,7 +147,7 @@ mod tests {
location, location,
custom, custom,
node: ExprKind::Constant { node: ExprKind::Constant {
value: BigInt::from(2).into(), value: 2.into(),
kind: None, kind: None,
}, },
}, },
@ -158,7 +161,7 @@ mod tests {
location, location,
custom, custom,
node: ExprKind::Constant { node: ExprKind::Constant {
value: BigInt::from(3).into(), value: 3.into(),
kind: None, kind: None,
}, },
}, },
@ -166,7 +169,7 @@ mod tests {
location, location,
custom, custom,
node: ExprKind::Constant { node: ExprKind::Constant {
value: BigInt::from(4).into(), value: 4.into(),
kind: None, kind: None,
}, },
}, },
@ -174,7 +177,7 @@ mod tests {
location, location,
custom, custom,
node: ExprKind::Constant { node: ExprKind::Constant {
value: BigInt::from(5).into(), value: 5.into(),
kind: None, kind: None,
}, },
}, },
@ -194,12 +197,12 @@ mod tests {
custom, custom,
node: ExprKind::Constant { node: ExprKind::Constant {
value: Constant::Tuple(vec![ value: Constant::Tuple(vec![
BigInt::from(1).into(), 1.into(),
BigInt::from(2).into(), 2.into(),
Constant::Tuple(vec![ Constant::Tuple(vec![
BigInt::from(3).into(), 3.into(),
BigInt::from(4).into(), 4.into(),
BigInt::from(5).into(), 5.into(),
]) ])
]), ]),
kind: None kind: None

View File

@ -9,6 +9,6 @@ mod impls;
mod location; mod location;
pub use ast_gen::*; pub use ast_gen::*;
pub use location::Location; pub use location::{Location, FileName};
pub type Suite<U = ()> = Vec<Stmt<U>>; pub type Suite<U = ()> = Vec<Stmt<U>>;

View File

@ -1,17 +1,32 @@
//! Datatypes to support source location information. //! Datatypes to support source location information.
use crate::ast_gen::StrRef;
use std::fmt; use std::fmt;
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct FileName(StrRef);
impl Default for FileName {
fn default() -> Self {
FileName("unknown".into())
}
}
impl From<String> for FileName {
fn from(s: String) -> Self {
FileName(s.into())
}
}
/// A location somewhere in the sourcecode. /// A location somewhere in the sourcecode.
#[derive(Clone, Copy, Debug, Default, PartialEq)] #[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct Location { pub struct Location {
row: usize, row: usize,
column: usize, column: usize,
file: FileName
} }
impl fmt::Display for Location { impl fmt::Display for Location {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "line {} column {}", self.row, self.column) write!(f, "{}:{}:{}", self.file.0, self.row, self.column)
} }
} }
@ -47,8 +62,8 @@ impl Location {
} }
impl Location { impl Location {
pub fn new(row: usize, column: usize) -> Self { pub fn new(row: usize, column: usize, file: FileName) -> Self {
Location { row, column } Location { row, column, file }
} }
pub fn row(&self) -> usize { pub fn row(&self) -> usize {

View File

@ -5,8 +5,6 @@ authors = ["M-Labs"]
edition = "2018" edition = "2018"
[dependencies] [dependencies]
num-bigint = "0.3"
num-traits = "0.2"
itertools = "0.10.1" itertools = "0.10.1"
crossbeam = "0.8.1" crossbeam = "0.8.1"
parking_lot = "0.11.1" parking_lot = "0.11.1"
@ -14,10 +12,9 @@ rayon = "1.5.1"
nac3parser = { path = "../nac3parser" } nac3parser = { path = "../nac3parser" }
[dependencies.inkwell] [dependencies.inkwell]
git = "https://github.com/TheDan64/inkwell" version = "0.1.0-beta.4"
branch = "master"
default-features = false default-features = false
features = ["llvm12-0", "target-x86", "target-arm", "target-riscv", "no-libffi-linking"] features = ["llvm13-0", "target-x86", "target-arm", "target-riscv", "no-libffi-linking"]
[dev-dependencies] [dev-dependencies]
test-case = "1.2.0" test-case = "1.2.0"

View File

@ -115,7 +115,7 @@ impl<'ctx, 'a> CodeGenContext<'ctx, 'a> {
let ty = self.ctx.bool_type(); let ty = self.ctx.bool_type();
ty.const_int(if *v { 1 } else { 0 }, false).into() ty.const_int(if *v { 1 } else { 0 }, false).into()
} }
Constant::Int(v) => { Constant::Int(Some(val)) => {
let ty = if self.unifier.unioned(ty, self.primitives.int32) { let ty = if self.unifier.unioned(ty, self.primitives.int32) {
self.ctx.i32_type() self.ctx.i32_type()
} else if self.unifier.unioned(ty, self.primitives.int64) { } else if self.unifier.unioned(ty, self.primitives.int64) {
@ -123,8 +123,7 @@ impl<'ctx, 'a> CodeGenContext<'ctx, 'a> {
} else { } else {
unreachable!(); unreachable!();
}; };
let val: i64 = v.try_into().unwrap(); ty.const_int(*val as u64, false).into()
ty.const_int(val as u64, false).into()
} }
Constant::Float(v) => { Constant::Float(v) => {
assert!(self.unifier.unioned(ty, self.primitives.float)); assert!(self.unifier.unioned(ty, self.primitives.float));
@ -411,7 +410,7 @@ pub fn gen_call<'ctx, 'a, G: CodeGenerator + ?Sized>(
format!("{}:{}", id, old_key) format!("{}:{}", id, old_key)
}; };
param_vals = param_vals =
real_params.into_iter().map(|p| p.to_basic_value_enum(ctx)).collect_vec(); real_params.into_iter().map(|p| p.to_basic_value_enum(ctx).into()).collect_vec();
instance_to_symbol.get(&key).cloned() instance_to_symbol.get(&key).cloned()
} }
TopLevelDef::Class { .. } => { TopLevelDef::Class { .. } => {
@ -427,7 +426,7 @@ pub fn gen_call<'ctx, 'a, G: CodeGenerator + ?Sized>(
if let Some(obj) = &obj { if let Some(obj) = &obj {
args.insert(0, FuncArg { name: "self".into(), ty: obj.0, default_value: None }); args.insert(0, FuncArg { name: "self".into(), ty: obj.0, default_value: None });
} }
let params = args.iter().map(|arg| ctx.get_llvm_type(arg.ty)).collect_vec(); let params = args.iter().map(|arg| ctx.get_llvm_type(arg.ty).into()).collect_vec();
let fun_ty = if ctx.unifier.unioned(fun.0.ret, ctx.primitives.none) { let fun_ty = if ctx.unifier.unioned(fun.0.ret, ctx.primitives.none) {
ctx.ctx.void_type().fn_type(&params, false) ctx.ctx.void_type().fn_type(&params, false)
} else { } else {

View File

@ -351,7 +351,7 @@ pub fn gen_func<'ctx, G: CodeGenerator + ?Sized>(
let params = args let params = args
.iter() .iter()
.map(|arg| { .map(|arg| {
get_llvm_type(context, &mut unifier, top_level_ctx.as_ref(), &mut type_cache, arg.ty) get_llvm_type(context, &mut unifier, top_level_ctx.as_ref(), &mut type_cache, arg.ty).into()
}) })
.collect_vec(); .collect_vec();

View File

@ -74,7 +74,7 @@ fn test_primitives() {
d = a if c == 1 else 0 d = a if c == 1 else 0
return d return d
"}; "};
let statements = parse_program(source).unwrap(); let statements = parse_program(source, Default::default()).unwrap();
let composer: TopLevelComposer = Default::default(); let composer: TopLevelComposer = Default::default();
let mut unifier = composer.unifier.clone(); let mut unifier = composer.unifier.clone();
@ -193,12 +193,12 @@ fn test_simple_call() {
a = foo(a) a = foo(a)
return a * 2 return a * 2
"}; "};
let statements_1 = parse_program(source_1).unwrap(); let statements_1 = parse_program(source_1, Default::default()).unwrap();
let source_2 = indoc! { " let source_2 = indoc! { "
return a + 1 return a + 1
"}; "};
let statements_2 = parse_program(source_2).unwrap(); let statements_2 = parse_program(source_2, Default::default()).unwrap();
let composer: TopLevelComposer = Default::default(); let composer: TopLevelComposer = Default::default();
let mut unifier = composer.unifier.clone(); let mut unifier = composer.unifier.clone();

View File

@ -298,10 +298,10 @@ pub fn parse_type_annotation<T>(
if let Name { id, .. } = &value.node { if let Name { id, .. } = &value.node {
subscript_name_handle(id, slice, unifier) subscript_name_handle(id, slice, unifier)
} else { } else {
Err("unsupported type expression".into()) Err(format!("unsupported type expression at {}", expr.location))
} }
} }
_ => Err("unsupported type expression".into()), _ => Err(format!("unsupported type expression at {}", expr.location)),
} }
} }

View File

@ -214,7 +214,7 @@ pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo {
}); });
let val = ctx let val = ctx
.builder .builder
.build_call(round_intrinsic, &[arg], "round") .build_call(round_intrinsic, &[arg.into()], "round")
.try_as_basic_value() .try_as_basic_value()
.left() .left()
.unwrap(); .unwrap();
@ -251,7 +251,7 @@ pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo {
}); });
let val = ctx let val = ctx
.builder .builder
.build_call(round_intrinsic, &[arg], "round") .build_call(round_intrinsic, &[arg.into()], "round")
.try_as_basic_value() .try_as_basic_value()
.left() .left()
.unwrap(); .unwrap();
@ -431,7 +431,7 @@ pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo {
}); });
let val = ctx let val = ctx
.builder .builder
.build_call(floor_intrinsic, &[arg], "floor") .build_call(floor_intrinsic, &[arg.into()], "floor")
.try_as_basic_value() .try_as_basic_value()
.left() .left()
.unwrap(); .unwrap();
@ -468,7 +468,7 @@ pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo {
}); });
let val = ctx let val = ctx
.builder .builder
.build_call(floor_intrinsic, &[arg], "floor") .build_call(floor_intrinsic, &[arg.into()], "floor")
.try_as_basic_value() .try_as_basic_value()
.left() .left()
.unwrap(); .unwrap();
@ -505,7 +505,7 @@ pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo {
}); });
let val = ctx let val = ctx
.builder .builder
.build_call(ceil_intrinsic, &[arg], "ceil") .build_call(ceil_intrinsic, &[arg.into()], "ceil")
.try_as_basic_value() .try_as_basic_value()
.left() .left()
.unwrap(); .unwrap();
@ -542,7 +542,7 @@ pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo {
}); });
let val = ctx let val = ctx
.builder .builder
.build_call(ceil_intrinsic, &[arg], "ceil") .build_call(ceil_intrinsic, &[arg.into()], "ceil")
.try_as_basic_value() .try_as_basic_value()
.left() .left()
.unwrap(); .unwrap();

View File

@ -162,14 +162,22 @@ impl TopLevelComposer {
match &ast.node { match &ast.node {
ast::StmtKind::ClassDef { name: class_name, body, .. } => { ast::StmtKind::ClassDef { name: class_name, body, .. } => {
if self.keyword_list.contains(class_name) { if self.keyword_list.contains(class_name) {
return Err("cannot use keyword as a class name".into()); return Err(format!(
"cannot use keyword `{}` as a class name (at {})",
class_name,
ast.location
));
} }
if !defined_names.insert({ if !defined_names.insert({
let mut n = mod_path.clone(); let mut n = mod_path.clone();
n.push_str(&class_name.to_string()); n.push_str(&class_name.to_string());
n n
}) { }) {
return Err("duplicate definition of class".into()); return Err(format!(
"duplicate definition of class `{}` (at {})",
class_name,
ast.location
));
} }
let class_name = *class_name; let class_name = *class_name;
@ -212,7 +220,11 @@ impl TopLevelComposer {
contains_constructor = true; contains_constructor = true;
} }
if self.keyword_list.contains(method_name) { if self.keyword_list.contains(method_name) {
return Err("cannot use keyword as a method name".into()); return Err(format!(
"cannot use keyword `{}` as a method name (at {})",
method_name,
b.location
));
} }
let global_class_method_name = { let global_class_method_name = {
let mut n = mod_path.clone(); let mut n = mod_path.clone();
@ -226,7 +238,11 @@ impl TopLevelComposer {
n n
}; };
if !defined_names.insert(global_class_method_name.clone()) { if !defined_names.insert(global_class_method_name.clone()) {
return Err("duplicate class method definition".into()); return Err(format!(
"class method `{}` defined twice (at {})",
&global_class_method_name[mod_path.len()..],
b.location
));
} }
let method_def_id = self.definition_ast_list.len() + { let method_def_id = self.definition_ast_list.len() + {
// plus 1 here since we already have the class def // plus 1 here since we already have the class def
@ -283,12 +299,16 @@ impl TopLevelComposer {
// return Err("cannot use keyword as a top level function name".into()); // return Err("cannot use keyword as a top level function name".into());
// } // }
let global_fun_name = { let global_fun_name = {
let mut n = mod_path; let mut n = mod_path.clone();
n.push_str(&name.to_string()); n.push_str(&name.to_string());
n n
}; };
if !defined_names.insert(global_fun_name.clone()) { if !defined_names.insert(global_fun_name.clone()) {
return Err("duplicate top level function define".into()); return Err(format!(
"top level function `{}` defined twice (at {})",
&global_fun_name[mod_path.len()..],
ast.location
));
} }
let fun_name = *name; let fun_name = *name;
@ -314,7 +334,10 @@ impl TopLevelComposer {
)) ))
} }
_ => Err("only registrations of top level classes/functions are supported".into()), _ => Err(format!(
"registrations of constructs other than top level classes/functions are not supported (at {})",
ast.location
)),
} }
} }
@ -376,7 +399,10 @@ impl TopLevelComposer {
if !is_generic { if !is_generic {
is_generic = true; is_generic = true;
} else { } else {
return Err("Only single Generic[...] can be in bases".into()); return Err(format!(
"only single Generic[...] is allowed (at {})",
b.location
));
} }
let type_var_list: Vec<&ast::Expr<()>>; let type_var_list: Vec<&ast::Expr<()>>;
@ -414,7 +440,10 @@ impl TopLevelComposer {
}) })
}; };
if !all_unique_type_var { if !all_unique_type_var {
return Err("expect unique type variables".into()); return Err(format!(
"duplicate type variable occurs (at {})",
slice.location
));
} }
// add to TopLevelDef // add to TopLevelDef
@ -479,9 +508,11 @@ impl TopLevelComposer {
} }
if has_base { if has_base {
return Err("a class def can only have at most one base class \ return Err(format!(
declaration and one generic declaration" "a class definition can only have at most one base class \
.into()); declaration and one generic declaration (at {})",
b.location
));
} }
has_base = true; has_base = true;
@ -499,7 +530,10 @@ impl TopLevelComposer {
if let TypeAnnotation::CustomClass { .. } = &base_ty { if let TypeAnnotation::CustomClass { .. } = &base_ty {
class_ancestors.push(base_ty); class_ancestors.push(base_ty);
} else { } else {
return Err("class base declaration can only be custom class".into()); return Err(format!(
"class base declaration can only be custom class (at {})",
b.location,
));
} }
} }
} }
@ -668,14 +702,14 @@ impl TopLevelComposer {
let arg_types = { let arg_types = {
// make sure no duplicate parameter // make sure no duplicate parameter
let mut defined_paramter_name: HashSet<_> = HashSet::new(); let mut defined_paramter_name: HashSet<_> = HashSet::new();
let have_unique_fuction_parameter_name = args.args.iter().all(|x| { for x in args.args.iter() {
defined_paramter_name.insert(x.node.arg) if !defined_paramter_name.insert(x.node.arg) || keyword_list.contains(&x.node.arg) {
&& !keyword_list.contains(&x.node.arg) return Err(format!(
}); "top level function must have unique parameter names \
if !have_unique_fuction_parameter_name { and names should not be the same as the keywords (at {})",
return Err("top level function must have unique parameter names \ x.location
and names thould not be the same as the keywords" ));
.into()); }
} }
let arg_with_default: Vec<(&ast::Located<ast::ArgData<()>>, Option<&ast::Expr>)> = args let arg_with_default: Vec<(&ast::Located<ast::ArgData<()>>, Option<&ast::Expr>)> = args
@ -754,7 +788,7 @@ impl TopLevelComposer {
&type_annotation, &type_annotation,
primitives_store, primitives_store,
unifier unifier
).map_err(|err| format!("{} at {}", err, x.location))?; ).map_err(|err| format!("{} (at {})", err, x.location))?;
v v
}) })
} }
@ -825,7 +859,7 @@ impl TopLevelComposer {
)); ));
unifier unifier
.unify(*dummy_ty, function_ty) .unify(*dummy_ty, function_ty)
.map_err(|old| format!("{} at {}", old, function_ast.location))?; .map_err(|old| format!("{} (at {})", old, function_ast.location))?;
} else { } else {
unreachable!("must be both function"); unreachable!("must be both function");
} }
@ -902,20 +936,22 @@ impl TopLevelComposer {
// check method parameters cannot have same name // check method parameters cannot have same name
let mut defined_paramter_name: HashSet<_> = HashSet::new(); let mut defined_paramter_name: HashSet<_> = HashSet::new();
let zelf: StrRef = "self".into(); let zelf: StrRef = "self".into();
let have_unique_fuction_parameter_name = args.args.iter().all(|x| { for x in args.args.iter() {
defined_paramter_name.insert(x.node.arg) if !defined_paramter_name.insert(x.node.arg)
&& (!keyword_list.contains(&x.node.arg) || x.node.arg == zelf) || (keyword_list.contains(&x.node.arg) && x.node.arg != zelf) {
}); return Err(format!(
if !have_unique_fuction_parameter_name { "top level function must have unique parameter names \
return Err("class method must have unique parameter names \ and names should not be the same as the keywords (at {})",
and names thould not be the same as the keywords" x.location
.into()); ))
}
} }
if name == &"__init__".into() && !defined_paramter_name.contains(&zelf) { if name == &"__init__".into() && !defined_paramter_name.contains(&zelf) {
return Err("__init__ function must have a `self` parameter".into()); return Err(format!("__init__ method must have a `self` parameter (at {})", b.location));
} }
if !defined_paramter_name.contains(&zelf) { if !defined_paramter_name.contains(&zelf) {
return Err("currently does not support static method".into()); return Err(format!("class method must have a `self` parameter (at {})", b.location));
} }
let mut result = Vec::new(); let mut result = Vec::new();
@ -981,12 +1017,12 @@ impl TopLevelComposer {
None => None, None => None,
Some(default) => { Some(default) => {
if name == "self".into() { if name == "self".into() {
return Err(format!("`self` parameter cannot take default value at {}", x.location)); return Err(format!("`self` parameter cannot take default value (at {})", x.location));
} }
Some({ Some({
let v = Self::parse_parameter_default_value(default, class_resolver)?; let v = Self::parse_parameter_default_value(default, class_resolver)?;
Self::check_default_param_type(&v, &type_ann, primitives, unifier) Self::check_default_param_type(&v, &type_ann, primitives, unifier)
.map_err(|err| format!("{} at {}", err, x.location))?; .map_err(|err| format!("{} (at {})", err, x.location))?;
v v
}) })
} }
@ -1090,7 +1126,7 @@ impl TopLevelComposer {
}; };
class_fields_def.push((*attr, dummy_field_type, mutable)); class_fields_def.push((*attr, dummy_field_type, mutable));
let annotation = parse_ast_to_type_annotation_kinds( let parsed_annotation = parse_ast_to_type_annotation_kinds(
class_resolver, class_resolver,
temp_def_list, temp_def_list,
unifier, unifier,
@ -1100,30 +1136,42 @@ impl TopLevelComposer {
)?; )?;
// find type vars within this return type annotation // find type vars within this return type annotation
let type_vars_within = let type_vars_within =
get_type_var_contained_in_type_annotation(&annotation); get_type_var_contained_in_type_annotation(&parsed_annotation);
// handle the class type var and the method type var // handle the class type var and the method type var
for type_var_within in type_vars_within { for type_var_within in type_vars_within {
if let TypeAnnotation::TypeVar(t) = type_var_within { if let TypeAnnotation::TypeVar(t) = type_var_within {
if !class_type_vars_def.contains(&t) { if !class_type_vars_def.contains(&t) {
return Err("class fields can only use type \ return Err(format!(
vars declared as class generic type vars" "class fields can only use type \
.into()); vars declared as class generic type vars (at {})",
annotation.location
));
} }
} else { } else {
unreachable!("must be type var annotation"); unreachable!("must be type var annotation");
} }
} }
type_var_to_concrete_def.insert(dummy_field_type, annotation); type_var_to_concrete_def.insert(dummy_field_type, parsed_annotation);
} else { } else {
return Err("same class fields defined twice".into()); return Err(format!(
"same class fields `{}` defined twice (at {})",
attr,
target.location
));
} }
} else { } else {
return Err("unsupported statement type in class definition body".into()); return Err(format!(
"unsupported statement type in class definition body (at {})",
target.location
));
} }
} }
ast::StmtKind::Pass { .. } => {} ast::StmtKind::Pass { .. } => {}
ast::StmtKind::Expr { value: _, .. } => {} // typically a docstring; ignoring all expressions matches CPython behavior ast::StmtKind::Expr { value: _, .. } => {} // typically a docstring; ignoring all expressions matches CPython behavior
_ => return Err("unsupported statement type in class definition body".into()), _ => return Err(format!(
"unsupported statement in class definition body (at {})",
b.location
)),
} }
} }
Ok(()) Ok(())
@ -1186,7 +1234,10 @@ impl TopLevelComposer {
type_var_to_concrete_def, type_var_to_concrete_def,
); );
if !ok { if !ok {
return Err("method has same name as ancestors' method, but incompatible type".into()); return Err(format!(
"method {} has same name as ancestors' method, but incompatible type",
class_method_name
));
} }
// mark it as added // mark it as added
is_override.insert(*class_method_name); is_override.insert(*class_method_name);
@ -1294,7 +1345,7 @@ impl TopLevelComposer {
)); ));
self.unifier self.unifier
.unify(constructor.unwrap(), contor_type) .unify(constructor.unwrap(), contor_type)
.map_err(|old| format!("{} at {}", old, ast.as_ref().unwrap().location))?; .map_err(|old| format!("{} (at {})", old, ast.as_ref().unwrap().location))?;
// class field instantiation check // class field instantiation check
if let (Some(init_id), false) = (init_id, fields.is_empty()) { if let (Some(init_id), false) = (init_id, fields.is_empty()) {
@ -1308,9 +1359,10 @@ impl TopLevelComposer {
for (f, _, _) in fields { for (f, _, _) in fields {
if !all_inited.contains(f) { if !all_inited.contains(f) {
return Err(format!( return Err(format!(
"fields `{}` of class `{}` not fully initialized", "fields `{}` of class `{}` not fully initialized in the initializer (at {})",
f, f,
class_name class_name,
body[0].location,
)); ));
} }
} }
@ -1510,7 +1562,7 @@ impl TopLevelComposer {
&mut |id| format!("tvar{}", id), &mut |id| format!("tvar{}", id),
); );
return Err(format!( return Err(format!(
"expected return type of `{}` in function `{}` at {}", "expected return type of `{}` in function `{}` (at {})",
ret_str, ret_str,
name, name,
ast.as_ref().unwrap().location ast.as_ref().unwrap().location

View File

@ -412,13 +412,23 @@ pub fn parse_parameter_default_value(default: &ast::Expr, resolver: &(dyn Symbol
fn handle_constant(val: &Constant, loc: &Location) -> Result<SymbolValue, String> { fn handle_constant(val: &Constant, loc: &Location) -> Result<SymbolValue, String> {
match val { match val {
Constant::Int(v) => { Constant::Int(v) => {
if let Ok(v) = v.try_into() { match v {
Ok(SymbolValue::I32(v)) Some(v) => {
} else { if let Ok(v) = (*v).try_into() {
Err(format!( Ok(SymbolValue::I32(v))
"integer value out of range at {}", } else {
loc Err(format!(
)) "integer value out of range at {}",
loc
))
}
},
None => {
Err(format!(
"integer value out of range at {}",
loc
))
}
} }
} }
Constant::Float(v) => Ok(SymbolValue::Double(*v)), Constant::Float(v) => Ok(SymbolValue::Double(*v)),
@ -439,8 +449,8 @@ pub fn parse_parameter_default_value(default: &ast::Expr, resolver: &(dyn Symbol
} => { } => {
if args.len() == 1 { if args.len() == 1 {
match &args[0].node { match &args[0].node {
ast::ExprKind::Constant { value: Constant::Int(v), .. } => ast::ExprKind::Constant { value: Constant::Int(Some(v)), .. } =>
Ok(SymbolValue::I64(v.try_into().unwrap())), Ok(SymbolValue::I64(*v)),
_ => Err(format!("only allow constant integer here at {}", default.location)) _ => Err(format!("only allow constant integer here at {}", default.location))
} }
} else { } else {

View File

@ -103,7 +103,7 @@ fn test_simple_register(source: Vec<&str>) {
let mut composer: TopLevelComposer = Default::default(); let mut composer: TopLevelComposer = Default::default();
for s in source { for s in source {
let ast = parse_program(s).unwrap(); let ast = parse_program(s, Default::default()).unwrap();
let ast = ast[0].clone(); let ast = ast[0].clone();
composer.register_top_level(ast, None, "".into()).unwrap(); composer.register_top_level(ast, None, "".into()).unwrap();
@ -149,7 +149,7 @@ fn test_simple_function_analyze(source: Vec<&str>, tys: Vec<&str>, names: Vec<&s
Arc::new(Resolver(internal_resolver.clone())) as Arc<dyn SymbolResolver + Send + Sync>; Arc::new(Resolver(internal_resolver.clone())) as Arc<dyn SymbolResolver + Send + Sync>;
for s in source { for s in source {
let ast = parse_program(s).unwrap(); let ast = parse_program(s, Default::default()).unwrap();
let ast = ast[0].clone(); let ast = ast[0].clone();
let (id, def_id, ty) = let (id, def_id, ty) =
@ -333,7 +333,7 @@ fn test_simple_function_analyze(source: Vec<&str>, tys: Vec<&str>, names: Vec<&s
pass pass
"} "}
], ],
vec!["application of type vars to generic class is not currently supported"]; vec!["application of type vars to generic class is not currently supported (at unknown:4:24)"];
"err no type var in generic app" "err no type var in generic app"
)] )]
#[test_case( #[test_case(
@ -389,7 +389,7 @@ fn test_simple_function_analyze(source: Vec<&str>, tys: Vec<&str>, names: Vec<&s
def __init__(): def __init__():
pass pass
"}], "}],
vec!["__init__ function must have a `self` parameter"]; vec!["__init__ method must have a `self` parameter (at unknown:2:5)"];
"err no self_1" "err no self_1"
)] )]
#[test_case( #[test_case(
@ -411,7 +411,7 @@ fn test_simple_function_analyze(source: Vec<&str>, tys: Vec<&str>, names: Vec<&s
"} "}
], ],
vec!["a class def can only have at most one base class declaration and one generic declaration"]; vec!["a class definition can only have at most one base class declaration and one generic declaration (at unknown:1:24)"];
"err multiple inheritance" "err multiple inheritance"
)] )]
#[test_case( #[test_case(
@ -436,7 +436,7 @@ fn test_simple_function_analyze(source: Vec<&str>, tys: Vec<&str>, names: Vec<&s
pass pass
"} "}
], ],
vec!["method has same name as ancestors' method, but incompatible type"]; vec!["method fun has same name as ancestors' method, but incompatible type"];
"err_incompatible_inheritance_method" "err_incompatible_inheritance_method"
)] )]
#[test_case( #[test_case(
@ -479,7 +479,7 @@ fn test_simple_function_analyze(source: Vec<&str>, tys: Vec<&str>, names: Vec<&s
pass pass
"} "}
], ],
vec!["duplicate definition of class"]; vec!["duplicate definition of class `A` (at unknown:1:1)"];
"class same name" "class same name"
)] )]
fn test_analyze(source: Vec<&str>, res: Vec<&str>) { fn test_analyze(source: Vec<&str>, res: Vec<&str>) {
@ -499,7 +499,7 @@ fn test_analyze(source: Vec<&str>, res: Vec<&str>) {
Arc::new(Resolver(internal_resolver.clone())) as Arc<dyn SymbolResolver + Send + Sync>; Arc::new(Resolver(internal_resolver.clone())) as Arc<dyn SymbolResolver + Send + Sync>;
for s in source { for s in source {
let ast = parse_program(s).unwrap(); let ast = parse_program(s, Default::default()).unwrap();
let ast = ast[0].clone(); let ast = ast[0].clone();
let (id, def_id, ty) = { let (id, def_id, ty) = {
@ -683,7 +683,7 @@ fn test_inference(source: Vec<&str>, res: Vec<&str>) {
Arc::new(Resolver(internal_resolver.clone())) as Arc<dyn SymbolResolver + Send + Sync>; Arc::new(Resolver(internal_resolver.clone())) as Arc<dyn SymbolResolver + Send + Sync>;
for s in source { for s in source {
let ast = parse_program(s).unwrap(); let ast = parse_program(s, Default::default()).unwrap();
let ast = ast[0].clone(); let ast = ast[0].clone();
let (id, def_id, ty) = { let (id, def_id, ty) = {

View File

@ -70,7 +70,10 @@ pub fn parse_ast_to_type_annotation_kinds<T>(
if let TopLevelDef::Class { type_vars, .. } = &*def_read { if let TopLevelDef::Class { type_vars, .. } = &*def_read {
type_vars.clone() type_vars.clone()
} else { } else {
return Err("function cannot be used as a type".into()); return Err(format!(
"function cannot be used as a type (at {})",
expr.location
));
} }
} else { } else {
locked.get(&obj_id).unwrap().clone() locked.get(&obj_id).unwrap().clone()
@ -79,8 +82,9 @@ pub fn parse_ast_to_type_annotation_kinds<T>(
// check param number here // check param number here
if !type_vars.is_empty() { if !type_vars.is_empty() {
return Err(format!( return Err(format!(
"expect {} type variable parameter but got 0", "expect {} type variable parameter but got 0 (at {})",
type_vars.len() type_vars.len(),
expr.location,
)); ));
} }
Ok(TypeAnnotation::CustomClass { id: obj_id, params: vec![] }) Ok(TypeAnnotation::CustomClass { id: obj_id, params: vec![] })
@ -88,10 +92,13 @@ pub fn parse_ast_to_type_annotation_kinds<T>(
if let TypeEnum::TVar { .. } = unifier.get_ty(ty).as_ref() { if let TypeEnum::TVar { .. } = unifier.get_ty(ty).as_ref() {
Ok(TypeAnnotation::TypeVar(ty)) Ok(TypeAnnotation::TypeVar(ty))
} else { } else {
Err("not a type variable identifier".into()) Err(format!(
"not a type variable identifier at {}",
expr.location
))
} }
} else { } else {
Err("name cannot be parsed as a type annotation".into()) Err(format!("unknown type annotation at {}", expr.location))
} }
}; };
@ -100,7 +107,7 @@ pub fn parse_ast_to_type_annotation_kinds<T>(
if vec!["virtual".into(), "Generic".into(), "list".into(), "tuple".into()] if vec!["virtual".into(), "Generic".into(), "list".into(), "tuple".into()]
.contains(id) .contains(id)
{ {
return Err("keywords cannot be class name".into()); return Err(format!("keywords cannot be class name (at {})", expr.location));
} }
let obj_id = resolver let obj_id = resolver
.get_identifier_def(*id) .get_identifier_def(*id)
@ -126,13 +133,14 @@ pub fn parse_ast_to_type_annotation_kinds<T>(
}; };
if type_vars.len() != params_ast.len() { if type_vars.len() != params_ast.len() {
return Err(format!( return Err(format!(
"expect {} type parameters but got {}", "expect {} type parameters but got {} (at {})",
type_vars.len(), type_vars.len(),
params_ast.len() params_ast.len(),
params_ast[0].location,
)); ));
} }
let result = params_ast let result = params_ast
.into_iter() .iter()
.map(|x| { .map(|x| {
parse_ast_to_type_annotation_kinds( parse_ast_to_type_annotation_kinds(
resolver, resolver,
@ -154,9 +162,11 @@ pub fn parse_ast_to_type_annotation_kinds<T>(
if no_type_var { if no_type_var {
result result
} else { } else {
return Err("application of type vars to generic class \ return Err(format!(
is not currently supported" "application of type vars to generic class \
.into()); is not currently supported (at {})",
params_ast[0].location
));
} }
}; };
Ok(TypeAnnotation::CustomClass { id: obj_id, params: param_type_infos }) Ok(TypeAnnotation::CustomClass { id: obj_id, params: param_type_infos })
@ -206,24 +216,27 @@ pub fn parse_ast_to_type_annotation_kinds<T>(
matches!(&value.node, ast::ExprKind::Name { id, .. } if id == &"tuple".into()) matches!(&value.node, ast::ExprKind::Name { id, .. } if id == &"tuple".into())
} => } =>
{ {
if let ast::ExprKind::Tuple { elts, .. } = &slice.node { let tup_elts = {
let type_annotations = elts if let ast::ExprKind::Tuple { elts, .. } = &slice.node {
.iter() elts.as_slice()
.map(|e| { } else {
parse_ast_to_type_annotation_kinds( std::slice::from_ref(slice.as_ref())
resolver, }
top_level_defs, };
unifier, let type_annotations = tup_elts
primitives, .iter()
e, .map(|e| {
locked.clone(), parse_ast_to_type_annotation_kinds(
) resolver,
}) top_level_defs,
.collect::<Result<Vec<_>, _>>()?; unifier,
Ok(TypeAnnotation::Tuple(type_annotations)) primitives,
} else { e,
Err("Expect multiple elements for tuple".into()) locked.clone(),
} )
})
.collect::<Result<Vec<_>, _>>()?;
Ok(TypeAnnotation::Tuple(type_annotations))
} }
// custom class // custom class
@ -231,11 +244,11 @@ pub fn parse_ast_to_type_annotation_kinds<T>(
if let ast::ExprKind::Name { id, .. } = &value.node { if let ast::ExprKind::Name { id, .. } = &value.node {
class_name_handle(id, slice, unifier, locked) class_name_handle(id, slice, unifier, locked)
} else { } else {
Err("unsupported expression type for class name".into()) Err(format!("unsupported expression type for class name at {}", value.location))
} }
} }
_ => Err("unsupported expression for type annotation".into()), _ => Err(format!("unsupported expression for type annotation at {}", expr.location)),
} }
} }

View File

@ -680,11 +680,8 @@ impl<'a> Inferencer<'a> {
if let ExprKind::Constant { value: ast::Constant::Int(val), kind } = if let ExprKind::Constant { value: ast::Constant::Int(val), kind } =
&args[0].node &args[0].node
{ {
let int64: Result<i64, _> = val.try_into(); let custom = Some(self.primitives.int64);
let custom; if val.is_none() {
if int64.is_ok() {
custom = Some(self.primitives.int64);
} else {
return Err("Integer out of bound".into()); return Err("Integer out of bound".into());
} }
return Ok(Located { return Ok(Located {
@ -777,12 +774,17 @@ impl<'a> Inferencer<'a> {
match constant { match constant {
ast::Constant::Bool(_) => Ok(self.primitives.bool), ast::Constant::Bool(_) => Ok(self.primitives.bool),
ast::Constant::Int(val) => { ast::Constant::Int(val) => {
let int32: Result<i32, _> = val.try_into(); match val {
// int64 would be handled separately in functions Some(val) => {
if int32.is_ok() { let int32: Result<i32, _> = (*val).try_into();
Ok(self.primitives.int32) // int64 is handled separately in functions
} else { if int32.is_ok() {
Err("Integer out of bound".into()) Ok(self.primitives.int32)
} else {
Err("Integer out of bound".into())
}
},
None => Err("Integer out of bound".into())
} }
} }
ast::Constant::Float(_) => Ok(self.primitives.float), ast::Constant::Float(_) => Ok(self.primitives.float),
@ -907,7 +909,11 @@ impl<'a> Inferencer<'a> {
} }
ast::ExprKind::Constant { value: ast::Constant::Int(val), .. } => { ast::ExprKind::Constant { value: ast::Constant::Int(val), .. } => {
// the index is a constant, so value can be a sequence. // the index is a constant, so value can be a sequence.
let ind: i32 = val.try_into().map_err(|_| "Index must be int32".to_string())?; let ind: Option<i32> = match val {
Some(val) => (*val).try_into().ok(),
None => None,
};
let ind = ind.ok_or_else(|| "Index must be int32".to_string())?;
let map = once((ind, ty)).collect(); let map = once((ind, ty)).collect();
let seq = self.unifier.add_sequence(map); let seq = self.unifier.add_sequence(map);
self.constrain(value.custom.unwrap(), seq, &value.location)?; self.constrain(value.custom.unwrap(), seq, &value.location)?;

View File

@ -461,7 +461,7 @@ fn test_basic(source: &str, mapping: HashMap<&str, &str>, virtuals: &[(&str, &st
defined_identifiers.insert("virtual".into()); defined_identifiers.insert("virtual".into());
let mut inferencer = env.get_inferencer(); let mut inferencer = env.get_inferencer();
inferencer.defined_identifiers = defined_identifiers.clone(); inferencer.defined_identifiers = defined_identifiers.clone();
let statements = parse_program(source).unwrap(); let statements = parse_program(source, Default::default()).unwrap();
let statements = statements let statements = statements
.into_iter() .into_iter()
.map(|v| inferencer.fold_stmt(v)) .map(|v| inferencer.fold_stmt(v))
@ -603,7 +603,7 @@ fn test_primitive_magic_methods(source: &str, mapping: HashMap<&str, &str>) {
defined_identifiers.insert("virtual".into()); defined_identifiers.insert("virtual".into());
let mut inferencer = env.get_inferencer(); let mut inferencer = env.get_inferencer();
inferencer.defined_identifiers = defined_identifiers.clone(); inferencer.defined_identifiers = defined_identifiers.clone();
let statements = parse_program(source).unwrap(); let statements = parse_program(source, Default::default()).unwrap();
let statements = statements let statements = statements
.into_iter() .into_iter()
.map(|v| inferencer.fold_stmt(v)) .map(|v| inferencer.fold_stmt(v))

View File

@ -14,8 +14,6 @@ lalrpop = "0.19.6"
nac3ast = { path = "../nac3ast" } nac3ast = { path = "../nac3ast" }
lalrpop-util = "0.19.6" lalrpop-util = "0.19.6"
log = "0.4.1" log = "0.4.1"
num-bigint = "0.4.0"
num-traits = "0.2"
unic-emoji-char = "0.9" unic-emoji-char = "0.9"
unic-ucd-ident = "0.9" unic-ucd-ident = "0.9"
unicode_names2 = "0.4" unicode_names2 = "0.4"

View File

@ -3,14 +3,12 @@
//! This means source code is translated into separate tokens. //! This means source code is translated into separate tokens.
pub use super::token::Tok; pub use super::token::Tok;
use crate::ast::Location; use crate::ast::{Location, FileName};
use crate::error::{LexicalError, LexicalErrorType}; use crate::error::{LexicalError, LexicalErrorType};
use num_bigint::BigInt;
use num_traits::identities::Zero;
use num_traits::Num;
use std::char; use std::char;
use std::cmp::Ordering; use std::cmp::Ordering;
use std::str::FromStr; use std::str::FromStr;
use std::num::IntErrorKind;
use unic_emoji_char::is_emoji_presentation; use unic_emoji_char::is_emoji_presentation;
use unic_ucd_ident::{is_xid_continue, is_xid_start}; use unic_ucd_ident::{is_xid_continue, is_xid_start};
@ -113,8 +111,8 @@ pub type Spanned = (Location, Tok, Location);
pub type LexResult = Result<Spanned, LexicalError>; pub type LexResult = Result<Spanned, LexicalError>;
#[inline] #[inline]
pub fn make_tokenizer(source: &str) -> impl Iterator<Item = LexResult> + '_ { pub fn make_tokenizer(source: &str, file: FileName) -> impl Iterator<Item = LexResult> + '_ {
make_tokenizer_located(source, Location::new(0, 0)) make_tokenizer_located(source, Location::new(0, 0, file))
} }
pub fn make_tokenizer_located( pub fn make_tokenizer_located(
@ -287,10 +285,18 @@ where
fn lex_number_radix(&mut self, start_pos: Location, radix: u32) -> LexResult { fn lex_number_radix(&mut self, start_pos: Location, radix: u32) -> LexResult {
let value_text = self.radix_run(radix); let value_text = self.radix_run(radix);
let end_pos = self.get_pos(); let end_pos = self.get_pos();
let value = BigInt::from_str_radix(&value_text, radix).map_err(|e| LexicalError { let value = match i64::from_str_radix(&value_text, radix) {
error: LexicalErrorType::OtherError(format!("{:?}", e)), Ok(value) => Some(value),
location: start_pos, Err(e) => {
})?; match e.kind() {
IntErrorKind::PosOverflow | IntErrorKind::NegOverflow => None,
_ => return Err(LexicalError {
error: LexicalErrorType::OtherError(format!("{:?}", e)),
location: start_pos,
}),
}
}
};
Ok((start_pos, Tok::Int { value }, end_pos)) Ok((start_pos, Tok::Int { value }, end_pos))
} }
@ -353,8 +359,14 @@ where
Ok((start_pos, Tok::Complex { real: 0.0, imag }, end_pos)) Ok((start_pos, Tok::Complex { real: 0.0, imag }, end_pos))
} else { } else {
let end_pos = self.get_pos(); let end_pos = self.get_pos();
let value = value_text.parse::<BigInt>().unwrap(); // assumption: value_text contains a valid integer.
if start_is_zero && !value.is_zero() { // parse should only fail because of overflow.
let value = value_text.parse::<i64>().ok();
let nonzero = match value {
Some(value) => value != 0i64,
None => true
};
if start_is_zero && nonzero {
return Err(LexicalError { return Err(LexicalError {
error: LexicalErrorType::OtherError("Invalid Token".to_owned()), error: LexicalErrorType::OtherError("Invalid Token".to_owned()),
location: self.get_pos(), location: self.get_pos(),
@ -1320,15 +1332,15 @@ where
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::{make_tokenizer, NewlineHandler, Tok}; use super::{make_tokenizer, NewlineHandler, Tok};
use num_bigint::BigInt;
const WINDOWS_EOL: &str = "\r\n"; const WINDOWS_EOL: &str = "\r\n";
const MAC_EOL: &str = "\r"; const MAC_EOL: &str = "\r";
const UNIX_EOL: &str = "\n"; const UNIX_EOL: &str = "\n";
pub fn lex_source(source: &str) -> Vec<Tok> { pub fn lex_source(source: &str) -> Vec<Tok> {
let lexer = make_tokenizer(source); let lexer = make_tokenizer(source, Default::default());
lexer.map(|x| x.unwrap().1).collect() lexer.map(|x| x.unwrap().1).collect()
} }
@ -1449,16 +1461,16 @@ class Foo(A, B):
tokens, tokens,
vec![ vec![
Tok::Int { Tok::Int {
value: BigInt::from(47), value: Some(47i64),
}, },
Tok::Int { Tok::Int {
value: BigInt::from(13), value: Some(13i64),
}, },
Tok::Int { Tok::Int {
value: BigInt::from(0), value: Some(0i64),
}, },
Tok::Int { Tok::Int {
value: BigInt::from(123), value: Some(123i64),
}, },
Tok::Float { value: 0.2 }, Tok::Float { value: 0.2 },
Tok::Complex { Tok::Complex {
@ -1481,7 +1493,7 @@ class Foo(A, B):
fn $name() { fn $name() {
let source = format!(r"99232 # {}", $eol); let source = format!(r"99232 # {}", $eol);
let tokens = lex_source(&source); let tokens = lex_source(&source);
assert_eq!(tokens, vec![Tok::Int { value: BigInt::from(99232) }, Tok::Newline]); assert_eq!(tokens, vec![Tok::Int { value: Some(99232i64) }, Tok::Newline]);
} }
)* )*
} }
@ -1504,9 +1516,9 @@ class Foo(A, B):
assert_eq!( assert_eq!(
tokens, tokens,
vec![ vec![
Tok::Int { value: BigInt::from(123) }, Tok::Int { value: Some(123i64) },
Tok::Newline, Tok::Newline,
Tok::Int { value: BigInt::from(456) }, Tok::Int { value: Some(456i64) },
Tok::Newline, Tok::Newline,
] ]
) )
@ -1533,15 +1545,15 @@ class Foo(A, B):
}, },
Tok::Equal, Tok::Equal,
Tok::Int { Tok::Int {
value: BigInt::from(99) value: Some(99i64)
}, },
Tok::Plus, Tok::Plus,
Tok::Int { Tok::Int {
value: BigInt::from(2) value: Some(2i64)
}, },
Tok::Minus, Tok::Minus,
Tok::Int { Tok::Int {
value: BigInt::from(0) value: Some(0i64)
}, },
Tok::Newline, Tok::Newline,
] ]
@ -1568,7 +1580,7 @@ class Foo(A, B):
Tok::Newline, Tok::Newline,
Tok::Indent, Tok::Indent,
Tok::Return, Tok::Return,
Tok::Int { value: BigInt::from(99) }, Tok::Int { value: Some(99i64) },
Tok::Newline, Tok::Newline,
Tok::Dedent, Tok::Dedent,
] ]
@ -1611,7 +1623,7 @@ class Foo(A, B):
Tok::Newline, Tok::Newline,
Tok::Indent, Tok::Indent,
Tok::Return, Tok::Return,
Tok::Int { value: BigInt::from(99) }, Tok::Int { value: Some(99i64) },
Tok::Newline, Tok::Newline,
Tok::Dedent, Tok::Dedent,
Tok::Dedent, Tok::Dedent,
@ -1649,7 +1661,7 @@ class Foo(A, B):
Tok::Newline, Tok::Newline,
Tok::Indent, Tok::Indent,
Tok::Return, Tok::Return,
Tok::Int { value: BigInt::from(99) }, Tok::Int { value: Some(99i64) },
Tok::Newline, Tok::Newline,
Tok::Dedent, Tok::Dedent,
Tok::Dedent, Tok::Dedent,
@ -1687,9 +1699,9 @@ class Foo(A, B):
}, },
Tok::Equal, Tok::Equal,
Tok::Lsqb, Tok::Lsqb,
Tok::Int { value: BigInt::from(1) }, Tok::Int { value: Some(1i64) },
Tok::Comma, Tok::Comma,
Tok::Int { value: BigInt::from(2) }, Tok::Int { value: Some(2i64) },
Tok::Rsqb, Tok::Rsqb,
Tok::Newline, Tok::Newline,
] ]

View File

@ -7,7 +7,7 @@
use std::iter; use std::iter;
use crate::ast; use crate::ast::{self, FileName};
use crate::error::ParseError; use crate::error::ParseError;
use crate::lexer; use crate::lexer;
pub use crate::mode::Mode; pub use crate::mode::Mode;
@ -20,8 +20,8 @@ use crate::python;
*/ */
/// Parse a full python program, containing usually multiple lines. /// Parse a full python program, containing usually multiple lines.
pub fn parse_program(source: &str) -> Result<ast::Suite, ParseError> { pub fn parse_program(source: &str, file: FileName) -> Result<ast::Suite, ParseError> {
parse(source, Mode::Module).map(|top| match top { parse(source, Mode::Module, file).map(|top| match top {
ast::Mod::Module { body, .. } => body, ast::Mod::Module { body, .. } => body,
_ => unreachable!(), _ => unreachable!(),
}) })
@ -31,18 +31,17 @@ pub fn parse_program(source: &str) -> Result<ast::Suite, ParseError> {
/// ///
/// # Example /// # Example
/// ``` /// ```
/// extern crate num_bigint;
/// use nac3parser::{parser, ast}; /// use nac3parser::{parser, ast};
/// let expr = parser::parse_expression("1 + 2").unwrap(); /// let expr = parser::parse_expression("1 + 2").unwrap();
/// ///
/// assert_eq!( /// assert_eq!(
/// expr, /// expr,
/// ast::Expr { /// ast::Expr {
/// location: ast::Location::new(1, 3), /// location: ast::Location::new(1, 3, Default::default()),
/// custom: (), /// custom: (),
/// node: ast::ExprKind::BinOp { /// node: ast::ExprKind::BinOp {
/// left: Box::new(ast::Expr { /// left: Box::new(ast::Expr {
/// location: ast::Location::new(1, 1), /// location: ast::Location::new(1, 1, Default::default()),
/// custom: (), /// custom: (),
/// node: ast::ExprKind::Constant { /// node: ast::ExprKind::Constant {
/// value: ast::Constant::Int(1.into()), /// value: ast::Constant::Int(1.into()),
@ -51,7 +50,7 @@ pub fn parse_program(source: &str) -> Result<ast::Suite, ParseError> {
/// }), /// }),
/// op: ast::Operator::Add, /// op: ast::Operator::Add,
/// right: Box::new(ast::Expr { /// right: Box::new(ast::Expr {
/// location: ast::Location::new(1, 5), /// location: ast::Location::new(1, 5, Default::default()),
/// custom: (), /// custom: (),
/// node: ast::ExprKind::Constant { /// node: ast::ExprKind::Constant {
/// value: ast::Constant::Int(2.into()), /// value: ast::Constant::Int(2.into()),
@ -64,15 +63,15 @@ pub fn parse_program(source: &str) -> Result<ast::Suite, ParseError> {
/// ///
/// ``` /// ```
pub fn parse_expression(source: &str) -> Result<ast::Expr, ParseError> { pub fn parse_expression(source: &str) -> Result<ast::Expr, ParseError> {
parse(source, Mode::Expression).map(|top| match top { parse(source, Mode::Expression, Default::default()).map(|top| match top {
ast::Mod::Expression { body } => *body, ast::Mod::Expression { body } => *body,
_ => unreachable!(), _ => unreachable!(),
}) })
} }
// Parse a given source code // Parse a given source code
pub fn parse(source: &str, mode: Mode) -> Result<ast::Mod, ParseError> { pub fn parse(source: &str, mode: Mode, file: FileName) -> Result<ast::Mod, ParseError> {
let lxr = lexer::make_tokenizer(source); let lxr = lexer::make_tokenizer(source, file);
let marker_token = (Default::default(), mode.to_marker(), Default::default()); let marker_token = (Default::default(), mode.to_marker(), Default::default());
let tokenizer = iter::once(Ok(marker_token)).chain(lxr); let tokenizer = iter::once(Ok(marker_token)).chain(lxr);
@ -87,42 +86,42 @@ mod tests {
#[test] #[test]
fn test_parse_empty() { fn test_parse_empty() {
let parse_ast = parse_program("").unwrap(); let parse_ast = parse_program("", Default::default()).unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }
#[test] #[test]
fn test_parse_print_hello() { fn test_parse_print_hello() {
let source = String::from("print('Hello world')"); let source = String::from("print('Hello world')");
let parse_ast = parse_program(&source).unwrap(); let parse_ast = parse_program(&source, Default::default()).unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }
#[test] #[test]
fn test_parse_print_2() { fn test_parse_print_2() {
let source = String::from("print('Hello world', 2)"); let source = String::from("print('Hello world', 2)");
let parse_ast = parse_program(&source).unwrap(); let parse_ast = parse_program(&source, Default::default()).unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }
#[test] #[test]
fn test_parse_kwargs() { fn test_parse_kwargs() {
let source = String::from("my_func('positional', keyword=2)"); let source = String::from("my_func('positional', keyword=2)");
let parse_ast = parse_program(&source).unwrap(); let parse_ast = parse_program(&source, Default::default()).unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }
#[test] #[test]
fn test_parse_if_elif_else() { fn test_parse_if_elif_else() {
let source = String::from("if 1: 10\nelif 2: 20\nelse: 30"); let source = String::from("if 1: 10\nelif 2: 20\nelse: 30");
let parse_ast = parse_program(&source).unwrap(); let parse_ast = parse_program(&source, Default::default()).unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }
#[test] #[test]
fn test_parse_lambda() { fn test_parse_lambda() {
let source = "lambda x, y: x * y"; // lambda(x, y): x * y"; let source = "lambda x, y: x * y"; // lambda(x, y): x * y";
let parse_ast = parse_program(&source).unwrap(); let parse_ast = parse_program(&source, Default::default()).unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }
@ -130,7 +129,7 @@ mod tests {
fn test_parse_tuples() { fn test_parse_tuples() {
let source = "a, b = 4, 5"; let source = "a, b = 4, 5";
insta::assert_debug_snapshot!(parse_program(&source).unwrap()); insta::assert_debug_snapshot!(parse_program(&source, Default::default()).unwrap());
} }
#[test] #[test]
@ -141,7 +140,7 @@ class Foo(A, B):
pass pass
def method_with_default(self, arg='default'): def method_with_default(self, arg='default'):
pass"; pass";
insta::assert_debug_snapshot!(parse_program(&source).unwrap()); insta::assert_debug_snapshot!(parse_program(&source, Default::default()).unwrap());
} }
#[test] #[test]
@ -184,7 +183,7 @@ while i < 2: # nac3: 4
# nac3: if1 # nac3: if1
if 1: # nac3: if2 if 1: # nac3: if2
3"; 3";
insta::assert_debug_snapshot!(parse_program(&source).unwrap()); insta::assert_debug_snapshot!(parse_program(&source, Default::default()).unwrap());
} }
#[test] #[test]
@ -197,7 +196,7 @@ while test: # nac3: while3
# nac3: simple assign0 # nac3: simple assign0
a = 3 # nac3: simple assign1 a = 3 # nac3: simple assign1
"; ";
insta::assert_debug_snapshot!(parse_program(&source).unwrap()); insta::assert_debug_snapshot!(parse_program(&source, Default::default()).unwrap());
} }
#[test] #[test]
@ -216,7 +215,7 @@ if a: # nac3: small2
for i in a: # nac3: for1 for i in a: # nac3: for1
pass pass
"; ";
insta::assert_debug_snapshot!(parse_program(&source).unwrap()); insta::assert_debug_snapshot!(parse_program(&source, Default::default()).unwrap());
} }
#[test] #[test]
@ -225,6 +224,6 @@ for i in a: # nac3: for1
if a: # nac3: something if a: # nac3: something
a = 3 a = 3
"; ";
assert!(parse_program(&source).is_err()); assert!(parse_program(&source, Default::default()).is_err());
} }
} }

View File

@ -14,7 +14,6 @@ use crate::lexer;
use crate::config_comment_helper::*; use crate::config_comment_helper::*;
use lalrpop_util::ParseError; use lalrpop_util::ParseError;
use num_bigint::BigInt;
grammar; grammar;
@ -920,7 +919,7 @@ Factor: ast::Expr = {
match (&op, &e.node) { match (&op, &e.node) {
(ast::Unaryop::USub, ast::ExprKind::Constant { value: Constant::Int(val), kind }) => { (ast::Unaryop::USub, ast::ExprKind::Constant { value: Constant::Int(val), kind }) => {
ast::ExprKind::Constant { ast::ExprKind::Constant {
value: Constant::Int(-val), value: if let Some(val) = val { Constant::Int(Some(-val)) } else { Constant::Int(None) },
kind: kind.clone() kind: kind.clone()
} }
} }
@ -1362,7 +1361,7 @@ extern {
"True" => lexer::Tok::True, "True" => lexer::Tok::True,
"False" => lexer::Tok::False, "False" => lexer::Tok::False,
"None" => lexer::Tok::None, "None" => lexer::Tok::None,
int => lexer::Tok::Int { value: <BigInt> }, int => lexer::Tok::Int { value: <Option<i64>> },
float => lexer::Tok::Float { value: <f64> }, float => lexer::Tok::Float { value: <f64> },
complex => lexer::Tok::Complex { real: <f64>, imag: <f64> }, complex => lexer::Tok::Complex { real: <f64>, imag: <f64> },
string => lexer::Tok::String { value: <String>, is_fstring: <bool> }, string => lexer::Tok::String { value: <String>, is_fstring: <bool> },

View File

@ -1,11 +1,16 @@
--- ---
source: parser/src/fstring.rs source: nac3parser/src/fstring.rs
assertion_line: 327
expression: parse_ast expression: parse_ast
--- ---
Located { Located {
location: Location { location: Location {
row: 0, row: 0,
column: 0, column: 0,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: JoinedStr { node: JoinedStr {
@ -14,6 +19,9 @@ Located {
location: Location { location: Location {
row: 0, row: 0,
column: 0, column: 0,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
@ -27,6 +35,9 @@ Located {
location: Location { location: Location {
row: 0, row: 0,
column: 0, column: 0,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
@ -40,6 +51,9 @@ Located {
location: Location { location: Location {
row: 0, row: 0,
column: 0, column: 0,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: FormattedValue { node: FormattedValue {
@ -47,6 +61,9 @@ Located {
location: Location { location: Location {
row: 1, row: 1,
column: 2, column: 2,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {

View File

@ -1,11 +1,16 @@
--- ---
source: parser/src/fstring.rs source: nac3parser/src/fstring.rs
assertion_line: 335
expression: parse_ast expression: parse_ast
--- ---
Located { Located {
location: Location { location: Location {
row: 0, row: 0,
column: 0, column: 0,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: JoinedStr { node: JoinedStr {
@ -14,6 +19,9 @@ Located {
location: Location { location: Location {
row: 0, row: 0,
column: 0, column: 0,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
@ -27,6 +35,9 @@ Located {
location: Location { location: Location {
row: 0, row: 0,
column: 0, column: 0,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
@ -40,6 +51,9 @@ Located {
location: Location { location: Location {
row: 0, row: 0,
column: 0, column: 0,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
@ -53,6 +67,9 @@ Located {
location: Location { location: Location {
row: 0, row: 0,
column: 0, column: 0,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: FormattedValue { node: FormattedValue {
@ -60,6 +77,9 @@ Located {
location: Location { location: Location {
row: 1, row: 1,
column: 2, column: 2,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -75,6 +95,9 @@ Located {
location: Location { location: Location {
row: 0, row: 0,
column: 0, column: 0,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
@ -88,6 +111,9 @@ Located {
location: Location { location: Location {
row: 0, row: 0,
column: 0, column: 0,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
@ -101,6 +127,9 @@ Located {
location: Location { location: Location {
row: 0, row: 0,
column: 0, column: 0,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
@ -114,6 +143,9 @@ Located {
location: Location { location: Location {
row: 0, row: 0,
column: 0, column: 0,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: FormattedValue { node: FormattedValue {
@ -121,6 +153,9 @@ Located {
location: Location { location: Location {
row: 1, row: 1,
column: 2, column: 2,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {

View File

@ -1,11 +1,16 @@
--- ---
source: parser/src/fstring.rs source: nac3parser/src/fstring.rs
assertion_line: 343
expression: parse_ast expression: parse_ast
--- ---
Located { Located {
location: Location { location: Location {
row: 0, row: 0,
column: 0, column: 0,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: JoinedStr { node: JoinedStr {
@ -14,6 +19,9 @@ Located {
location: Location { location: Location {
row: 0, row: 0,
column: 0, column: 0,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
@ -27,6 +35,9 @@ Located {
location: Location { location: Location {
row: 0, row: 0,
column: 0, column: 0,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
@ -40,6 +51,9 @@ Located {
location: Location { location: Location {
row: 0, row: 0,
column: 0, column: 0,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: FormattedValue { node: FormattedValue {
@ -47,6 +61,9 @@ Located {
location: Location { location: Location {
row: 1, row: 1,
column: 2, column: 2,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -60,6 +77,9 @@ Located {
location: Location { location: Location {
row: 0, row: 0,
column: 0, column: 0,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {

View File

@ -1,11 +1,16 @@
--- ---
source: parser/src/fstring.rs source: nac3parser/src/fstring.rs
assertion_line: 319
expression: "parse_fstring(\"\").unwrap()" expression: "parse_fstring(\"\").unwrap()"
--- ---
Located { Located {
location: Location { location: Location {
row: 0, row: 0,
column: 0, column: 0,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {

View File

@ -1,11 +1,16 @@
--- ---
source: parser/src/fstring.rs source: nac3parser/src/fstring.rs
assertion_line: 298
expression: parse_ast expression: parse_ast
--- ---
Located { Located {
location: Location { location: Location {
row: 0, row: 0,
column: 0, column: 0,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: JoinedStr { node: JoinedStr {
@ -14,6 +19,9 @@ Located {
location: Location { location: Location {
row: 0, row: 0,
column: 0, column: 0,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: FormattedValue { node: FormattedValue {
@ -21,6 +29,9 @@ Located {
location: Location { location: Location {
row: 1, row: 1,
column: 2, column: 2,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -36,6 +47,9 @@ Located {
location: Location { location: Location {
row: 0, row: 0,
column: 0, column: 0,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: FormattedValue { node: FormattedValue {
@ -43,6 +57,9 @@ Located {
location: Location { location: Location {
row: 1, row: 1,
column: 3, column: 3,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -58,6 +75,9 @@ Located {
location: Location { location: Location {
row: 0, row: 0,
column: 0, column: 0,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {

View File

@ -1,5 +1,6 @@
--- ---
source: parser/src/fstring.rs source: nac3parser/src/fstring.rs
assertion_line: 382
expression: parse_ast expression: parse_ast
--- ---
@ -7,6 +8,9 @@ Located {
location: Location { location: Location {
row: 0, row: 0,
column: 0, column: 0,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: FormattedValue { node: FormattedValue {
@ -14,6 +18,9 @@ Located {
location: Location { location: Location {
row: 1, row: 1,
column: 5, column: 5,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Compare { node: Compare {
@ -21,11 +28,16 @@ Located {
location: Location { location: Location {
row: 1, row: 1,
column: 2, column: 2,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
value: Int( value: Int(
42, Some(
42,
),
), ),
kind: None, kind: None,
}, },
@ -38,11 +50,16 @@ Located {
location: Location { location: Location {
row: 1, row: 1,
column: 8, column: 8,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
value: Int( value: Int(
42, Some(
42,
),
), ),
kind: None, kind: None,
}, },

View File

@ -1,11 +1,16 @@
--- ---
source: parser/src/fstring.rs source: nac3parser/src/fstring.rs
assertion_line: 306
expression: parse_ast expression: parse_ast
--- ---
Located { Located {
location: Location { location: Location {
row: 0, row: 0,
column: 0, column: 0,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: FormattedValue { node: FormattedValue {
@ -13,6 +18,9 @@ Located {
location: Location { location: Location {
row: 1, row: 1,
column: 2, column: 2,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -26,6 +34,9 @@ Located {
location: Location { location: Location {
row: 0, row: 0,
column: 0, column: 0,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: FormattedValue { node: FormattedValue {
@ -33,6 +44,9 @@ Located {
location: Location { location: Location {
row: 1, row: 1,
column: 2, column: 2,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {

View File

@ -1,5 +1,6 @@
--- ---
source: parser/src/fstring.rs source: nac3parser/src/fstring.rs
assertion_line: 375
expression: parse_ast expression: parse_ast
--- ---
@ -7,6 +8,9 @@ Located {
location: Location { location: Location {
row: 0, row: 0,
column: 0, column: 0,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: FormattedValue { node: FormattedValue {
@ -14,6 +18,9 @@ Located {
location: Location { location: Location {
row: 1, row: 1,
column: 4, column: 4,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Compare { node: Compare {
@ -21,11 +28,16 @@ Located {
location: Location { location: Location {
row: 1, row: 1,
column: 2, column: 2,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
value: Int( value: Int(
1, Some(
1,
),
), ),
kind: None, kind: None,
}, },
@ -38,11 +50,16 @@ Located {
location: Location { location: Location {
row: 1, row: 1,
column: 7, column: 7,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
value: Int( value: Int(
2, Some(
2,
),
), ),
kind: None, kind: None,
}, },

View File

@ -1,11 +1,16 @@
--- ---
source: parser/src/fstring.rs source: nac3parser/src/fstring.rs
assertion_line: 314
expression: parse_ast expression: parse_ast
--- ---
Located { Located {
location: Location { location: Location {
row: 0, row: 0,
column: 0, column: 0,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: FormattedValue { node: FormattedValue {
@ -13,6 +18,9 @@ Located {
location: Location { location: Location {
row: 1, row: 1,
column: 2, column: 2,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -26,6 +34,9 @@ Located {
location: Location { location: Location {
row: 0, row: 0,
column: 0, column: 0,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {

View File

@ -1,11 +1,16 @@
--- ---
source: parser/src/fstring.rs source: nac3parser/src/fstring.rs
assertion_line: 389
expression: parse_ast expression: parse_ast
--- ---
Located { Located {
location: Location { location: Location {
row: 0, row: 0,
column: 0, column: 0,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: JoinedStr { node: JoinedStr {
@ -14,6 +19,9 @@ Located {
location: Location { location: Location {
row: 0, row: 0,
column: 0, column: 0,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
@ -27,6 +35,9 @@ Located {
location: Location { location: Location {
row: 0, row: 0,
column: 0, column: 0,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
@ -40,6 +51,9 @@ Located {
location: Location { location: Location {
row: 0, row: 0,
column: 0, column: 0,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: FormattedValue { node: FormattedValue {
@ -47,6 +61,9 @@ Located {
location: Location { location: Location {
row: 1, row: 1,
column: 2, column: 2,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {

View File

@ -1,11 +1,16 @@
--- ---
source: parser/src/fstring.rs source: nac3parser/src/fstring.rs
assertion_line: 396
expression: parse_ast expression: parse_ast
--- ---
Located { Located {
location: Location { location: Location {
row: 0, row: 0,
column: 0, column: 0,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: JoinedStr { node: JoinedStr {
@ -14,6 +19,9 @@ Located {
location: Location { location: Location {
row: 0, row: 0,
column: 0, column: 0,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
@ -27,6 +35,9 @@ Located {
location: Location { location: Location {
row: 0, row: 0,
column: 0, column: 0,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
@ -40,6 +51,9 @@ Located {
location: Location { location: Location {
row: 0, row: 0,
column: 0, column: 0,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: FormattedValue { node: FormattedValue {
@ -47,6 +61,9 @@ Located {
location: Location { location: Location {
row: 1, row: 1,
column: 2, column: 2,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {

View File

@ -1,11 +1,16 @@
--- ---
source: parser/src/fstring.rs source: nac3parser/src/fstring.rs
assertion_line: 403
expression: parse_ast expression: parse_ast
--- ---
Located { Located {
location: Location { location: Location {
row: 0, row: 0,
column: 0, column: 0,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: FormattedValue { node: FormattedValue {
@ -13,6 +18,9 @@ Located {
location: Location { location: Location {
row: 1, row: 1,
column: 2, column: 2,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Yield { node: Yield {

View File

@ -1,6 +1,7 @@
--- ---
source: nac3parser/src/parser.rs source: nac3parser/src/parser.rs
expression: parse_program(&source).unwrap() assertion_line: 218
expression: "parse_program(&source, Default::default()).unwrap()"
--- ---
[ [
@ -8,6 +9,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 1, row: 1,
column: 1, column: 1,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: If { node: If {
@ -15,6 +19,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 1, row: 1,
column: 4, column: 4,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -27,6 +34,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 1, row: 1,
column: 7, column: 7,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Expr { node: Expr {
@ -34,6 +44,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 1, row: 1,
column: 7, column: 7,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -55,6 +68,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 2, row: 2,
column: 1, column: 1,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: If { node: If {
@ -62,6 +78,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 2, row: 2,
column: 4, column: 4,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -74,6 +93,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 2, row: 2,
column: 7, column: 7,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Expr { node: Expr {
@ -81,6 +103,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 2, row: 2,
column: 7, column: 7,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -102,6 +127,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 3, row: 3,
column: 1, column: 1,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: If { node: If {
@ -109,6 +137,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 3, row: 3,
column: 4, column: 4,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -121,6 +152,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 4, row: 4,
column: 5, column: 5,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Expr { node: Expr {
@ -128,6 +162,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 4, row: 4,
column: 5, column: 5,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -142,6 +179,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 4, row: 4,
column: 8, column: 8,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Expr { node: Expr {
@ -149,6 +189,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 4, row: 4,
column: 10, column: 10,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: BinOp { node: BinOp {
@ -156,6 +199,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 4, row: 4,
column: 8, column: 8,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -168,11 +214,16 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 4, row: 4,
column: 12, column: 12,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
value: Int( value: Int(
3, Some(
3,
),
), ),
kind: None, kind: None,
}, },
@ -195,6 +246,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 5, row: 5,
column: 1, column: 1,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Assign { node: Assign {
@ -203,6 +257,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 5, row: 5,
column: 1, column: 1,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -215,11 +272,16 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 5, row: 5,
column: 5, column: 5,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
value: Int( value: Int(
3, Some(
3,
),
), ),
kind: None, kind: None,
}, },
@ -232,6 +294,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 5, row: 5,
column: 8, column: 8,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Expr { node: Expr {
@ -239,6 +304,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 5, row: 5,
column: 10, column: 10,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: BinOp { node: BinOp {
@ -246,6 +314,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 5, row: 5,
column: 8, column: 8,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -258,11 +329,16 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 5, row: 5,
column: 12, column: 12,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
value: Int( value: Int(
3, Some(
3,
),
), ),
kind: None, kind: None,
}, },
@ -276,6 +352,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 5, row: 5,
column: 15, column: 15,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Assign { node: Assign {
@ -284,6 +363,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 5, row: 5,
column: 15, column: 15,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -296,6 +378,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 5, row: 5,
column: 19, column: 19,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -313,6 +398,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 8, row: 8,
column: 1, column: 1,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Assign { node: Assign {
@ -321,6 +409,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 8, row: 8,
column: 1, column: 1,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -333,11 +424,16 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 8, row: 8,
column: 6, column: 6,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
value: Int( value: Int(
3, Some(
3,
),
), ),
kind: None, kind: None,
}, },
@ -354,6 +450,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 9, row: 9,
column: 1, column: 1,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: If { node: If {
@ -361,6 +460,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 9, row: 9,
column: 4, column: 4,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -373,6 +475,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 10, row: 10,
column: 5, column: 5,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Expr { node: Expr {
@ -380,6 +485,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 10, row: 10,
column: 5, column: 5,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -401,6 +509,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 11, row: 11,
column: 1, column: 1,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: For { node: For {
@ -408,6 +519,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 11, row: 11,
column: 5, column: 5,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -419,6 +533,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 11, row: 11,
column: 10, column: 10,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -431,6 +548,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 12, row: 12,
column: 5, column: 5,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Pass { node: Pass {

View File

@ -1,6 +1,7 @@
--- ---
source: nac3parser/src/parser.rs source: nac3parser/src/parser.rs
expression: parse_program(&source).unwrap() assertion_line: 186
expression: "parse_program(&source, Default::default()).unwrap()"
--- ---
[ [
@ -8,6 +9,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 1, row: 1,
column: 1, column: 1,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: AnnAssign { node: AnnAssign {
@ -15,6 +19,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 1, row: 1,
column: 1, column: 1,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -26,6 +33,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 1, row: 1,
column: 4, column: 4,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -44,6 +54,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 2, row: 2,
column: 1, column: 1,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: For { node: For {
@ -51,6 +64,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 3, row: 3,
column: 5, column: 5,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -62,6 +78,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 3, row: 3,
column: 11, column: 11,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Tuple { node: Tuple {
@ -70,11 +89,16 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 3, row: 3,
column: 11, column: 11,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
value: Int( value: Int(
1, Some(
1,
),
), ),
kind: None, kind: None,
}, },
@ -83,6 +107,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 3, row: 3,
column: 15, column: 15,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
@ -101,6 +128,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 4, row: 4,
column: 5, column: 5,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: AnnAssign { node: AnnAssign {
@ -108,6 +138,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 4, row: 4,
column: 5, column: 5,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -119,6 +152,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 4, row: 4,
column: 8, column: 8,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -144,6 +180,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 5, row: 5,
column: 1, column: 1,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: While { node: While {
@ -151,6 +190,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 7, row: 7,
column: 9, column: 9,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Compare { node: Compare {
@ -158,6 +200,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 7, row: 7,
column: 7, column: 7,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -173,11 +218,16 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 7, row: 7,
column: 11, column: 11,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
value: Int( value: Int(
2, Some(
2,
),
), ),
kind: None, kind: None,
}, },
@ -190,6 +240,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 9, row: 9,
column: 5, column: 5,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Pass { node: Pass {
@ -202,6 +255,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 12, row: 12,
column: 5, column: 5,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Expr { node: Expr {
@ -209,6 +265,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 12, row: 12,
column: 7, column: 7,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: BinOp { node: BinOp {
@ -216,11 +275,16 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 12, row: 12,
column: 5, column: 5,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
value: Int( value: Int(
1, Some(
1,
),
), ),
kind: None, kind: None,
}, },
@ -230,11 +294,16 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 12, row: 12,
column: 9, column: 9,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
value: Int( value: Int(
2, Some(
2,
),
), ),
kind: None, kind: None,
}, },
@ -252,6 +321,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 13, row: 13,
column: 5, column: 5,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: If { node: If {
@ -259,11 +331,16 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 15, row: 15,
column: 8, column: 8,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
value: Int( value: Int(
1, Some(
1,
),
), ),
kind: None, kind: None,
}, },
@ -273,6 +350,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 16, row: 16,
column: 9, column: 9,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Expr { node: Expr {
@ -280,11 +360,16 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 16, row: 16,
column: 9, column: 9,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
value: Int( value: Int(
3, Some(
3,
),
), ),
kind: None, kind: None,
}, },

View File

@ -1,6 +1,7 @@
--- ---
source: nac3parser/src/parser.rs source: nac3parser/src/parser.rs
expression: parse_program(&source).unwrap() assertion_line: 143
expression: "parse_program(&source, Default::default()).unwrap()"
--- ---
[ [
@ -8,6 +9,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 1, row: 1,
column: 1, column: 1,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: ClassDef { node: ClassDef {
@ -17,6 +21,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 1, row: 1,
column: 11, column: 11,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -28,6 +35,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 1, row: 1,
column: 14, column: 14,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -42,6 +52,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 2, row: 2,
column: 2, column: 2,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: FunctionDef { node: FunctionDef {
@ -53,6 +66,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 2, row: 2,
column: 15, column: 15,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: ArgData { node: ArgData {
@ -73,6 +89,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 3, row: 3,
column: 3, column: 3,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Pass { node: Pass {
@ -90,6 +109,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 4, row: 4,
column: 2, column: 2,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: FunctionDef { node: FunctionDef {
@ -101,6 +123,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 4, row: 4,
column: 26, column: 26,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: ArgData { node: ArgData {
@ -113,6 +138,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 4, row: 4,
column: 32, column: 32,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: ArgData { node: ArgData {
@ -131,6 +159,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 4, row: 4,
column: 37, column: 37,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
@ -147,6 +178,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 5, row: 5,
column: 3, column: 3,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Pass { node: Pass {

View File

@ -1,11 +1,16 @@
--- ---
source: parser/src/parser.rs source: nac3parser/src/parser.rs
assertion_line: 150
expression: parse_ast expression: parse_ast
--- ---
Located { Located {
location: Location { location: Location {
row: 1, row: 1,
column: 1, column: 1,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: DictComp { node: DictComp {
@ -13,6 +18,9 @@ Located {
location: Location { location: Location {
row: 1, row: 1,
column: 2, column: 2,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -24,6 +32,9 @@ Located {
location: Location { location: Location {
row: 1, row: 1,
column: 6, column: 6,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -37,6 +48,9 @@ Located {
location: Location { location: Location {
row: 1, row: 1,
column: 13, column: 13,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -48,6 +62,9 @@ Located {
location: Location { location: Location {
row: 1, row: 1,
column: 18, column: 18,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {

View File

@ -1,5 +1,6 @@
--- ---
source: parser/src/parser.rs source: nac3parser/src/parser.rs
assertion_line: 164
expression: parse_ast expression: parse_ast
--- ---
@ -7,6 +8,9 @@ Located {
location: Location { location: Location {
row: 1, row: 1,
column: 1, column: 1,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: ListComp { node: ListComp {
@ -14,6 +18,9 @@ Located {
location: Location { location: Location {
row: 1, row: 1,
column: 2, column: 2,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -27,6 +34,9 @@ Located {
location: Location { location: Location {
row: 1, row: 1,
column: 8, column: 8,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Tuple { node: Tuple {
@ -35,6 +45,9 @@ Located {
location: Location { location: Location {
row: 1, row: 1,
column: 8, column: 8,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -46,6 +59,9 @@ Located {
location: Location { location: Location {
row: 1, row: 1,
column: 11, column: 11,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -61,6 +77,9 @@ Located {
location: Location { location: Location {
row: 1, row: 1,
column: 17, column: 17,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -76,6 +95,9 @@ Located {
location: Location { location: Location {
row: 1, row: 1,
column: 23, column: 23,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -87,6 +109,9 @@ Located {
location: Location { location: Location {
row: 1, row: 1,
column: 28, column: 28,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -99,6 +124,9 @@ Located {
location: Location { location: Location {
row: 1, row: 1,
column: 35, column: 35,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Compare { node: Compare {
@ -106,6 +134,9 @@ Located {
location: Location { location: Location {
row: 1, row: 1,
column: 33, column: 33,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -121,11 +152,16 @@ Located {
location: Location { location: Location {
row: 1, row: 1,
column: 37, column: 37,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
value: Int( value: Int(
5, Some(
5,
),
), ),
kind: None, kind: None,
}, },
@ -137,6 +173,9 @@ Located {
location: Location { location: Location {
row: 1, row: 1,
column: 44, column: 44,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Compare { node: Compare {
@ -144,6 +183,9 @@ Located {
location: Location { location: Location {
row: 1, row: 1,
column: 42, column: 42,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -159,11 +201,16 @@ Located {
location: Location { location: Location {
row: 1, row: 1,
column: 46, column: 46,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
value: Int( value: Int(
10, Some(
10,
),
), ),
kind: None, kind: None,
}, },

View File

@ -1,5 +1,6 @@
--- ---
source: nac3parser/src/parser.rs source: nac3parser/src/parser.rs
assertion_line: 118
expression: parse_ast expression: parse_ast
--- ---
@ -8,6 +9,9 @@ expression: parse_ast
location: Location { location: Location {
row: 1, row: 1,
column: 1, column: 1,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: If { node: If {
@ -15,11 +19,16 @@ expression: parse_ast
location: Location { location: Location {
row: 1, row: 1,
column: 4, column: 4,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
value: Int( value: Int(
1, Some(
1,
),
), ),
kind: None, kind: None,
}, },
@ -29,6 +38,9 @@ expression: parse_ast
location: Location { location: Location {
row: 1, row: 1,
column: 7, column: 7,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Expr { node: Expr {
@ -36,11 +48,16 @@ expression: parse_ast
location: Location { location: Location {
row: 1, row: 1,
column: 7, column: 7,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
value: Int( value: Int(
10, Some(
10,
),
), ),
kind: None, kind: None,
}, },
@ -54,6 +71,9 @@ expression: parse_ast
location: Location { location: Location {
row: 2, row: 2,
column: 1, column: 1,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: If { node: If {
@ -61,11 +81,16 @@ expression: parse_ast
location: Location { location: Location {
row: 2, row: 2,
column: 6, column: 6,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
value: Int( value: Int(
2, Some(
2,
),
), ),
kind: None, kind: None,
}, },
@ -75,6 +100,9 @@ expression: parse_ast
location: Location { location: Location {
row: 2, row: 2,
column: 9, column: 9,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Expr { node: Expr {
@ -82,11 +110,16 @@ expression: parse_ast
location: Location { location: Location {
row: 2, row: 2,
column: 9, column: 9,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
value: Int( value: Int(
20, Some(
20,
),
), ),
kind: None, kind: None,
}, },
@ -100,6 +133,9 @@ expression: parse_ast
location: Location { location: Location {
row: 3, row: 3,
column: 7, column: 7,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Expr { node: Expr {
@ -107,11 +143,16 @@ expression: parse_ast
location: Location { location: Location {
row: 3, row: 3,
column: 7, column: 7,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
value: Int( value: Int(
30, Some(
30,
),
), ),
kind: None, kind: None,
}, },

View File

@ -1,5 +1,6 @@
--- ---
source: nac3parser/src/parser.rs source: nac3parser/src/parser.rs
assertion_line: 111
expression: parse_ast expression: parse_ast
--- ---
@ -8,6 +9,9 @@ expression: parse_ast
location: Location { location: Location {
row: 1, row: 1,
column: 1, column: 1,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Expr { node: Expr {
@ -15,6 +19,9 @@ expression: parse_ast
location: Location { location: Location {
row: 1, row: 1,
column: 8, column: 8,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Call { node: Call {
@ -22,6 +29,9 @@ expression: parse_ast
location: Location { location: Location {
row: 1, row: 1,
column: 1, column: 1,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -34,6 +44,9 @@ expression: parse_ast
location: Location { location: Location {
row: 1, row: 1,
column: 10, column: 10,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
@ -49,6 +62,9 @@ expression: parse_ast
location: Location { location: Location {
row: 1, row: 1,
column: 23, column: 23,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: KeywordData { node: KeywordData {
@ -59,11 +75,16 @@ expression: parse_ast
location: Location { location: Location {
row: 1, row: 1,
column: 31, column: 31,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
value: Int( value: Int(
2, Some(
2,
),
), ),
kind: None, kind: None,
}, },

View File

@ -1,5 +1,6 @@
--- ---
source: nac3parser/src/parser.rs source: nac3parser/src/parser.rs
assertion_line: 125
expression: parse_ast expression: parse_ast
--- ---
@ -8,6 +9,9 @@ expression: parse_ast
location: Location { location: Location {
row: 1, row: 1,
column: 1, column: 1,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Expr { node: Expr {
@ -15,6 +19,9 @@ expression: parse_ast
location: Location { location: Location {
row: 1, row: 1,
column: 1, column: 1,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Lambda { node: Lambda {
@ -25,6 +32,9 @@ expression: parse_ast
location: Location { location: Location {
row: 1, row: 1,
column: 8, column: 8,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: ArgData { node: ArgData {
@ -37,6 +47,9 @@ expression: parse_ast
location: Location { location: Location {
row: 1, row: 1,
column: 11, column: 11,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: ArgData { node: ArgData {
@ -56,6 +69,9 @@ expression: parse_ast
location: Location { location: Location {
row: 1, row: 1,
column: 16, column: 16,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: BinOp { node: BinOp {
@ -63,6 +79,9 @@ expression: parse_ast
location: Location { location: Location {
row: 1, row: 1,
column: 14, column: 14,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -75,6 +94,9 @@ expression: parse_ast
location: Location { location: Location {
row: 1, row: 1,
column: 18, column: 18,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {

View File

@ -1,11 +1,16 @@
--- ---
source: parser/src/parser.rs source: nac3parser/src/parser.rs
assertion_line: 157
expression: parse_ast expression: parse_ast
--- ---
Located { Located {
location: Location { location: Location {
row: 1, row: 1,
column: 1, column: 1,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: ListComp { node: ListComp {
@ -13,6 +18,9 @@ Located {
location: Location { location: Location {
row: 1, row: 1,
column: 2, column: 2,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -26,6 +34,9 @@ Located {
location: Location { location: Location {
row: 1, row: 1,
column: 8, column: 8,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -37,6 +48,9 @@ Located {
location: Location { location: Location {
row: 1, row: 1,
column: 13, column: 13,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {

View File

@ -1,5 +1,6 @@
--- ---
source: nac3parser/src/parser.rs source: nac3parser/src/parser.rs
assertion_line: 104
expression: parse_ast expression: parse_ast
--- ---
@ -8,6 +9,9 @@ expression: parse_ast
location: Location { location: Location {
row: 1, row: 1,
column: 1, column: 1,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Expr { node: Expr {
@ -15,6 +19,9 @@ expression: parse_ast
location: Location { location: Location {
row: 1, row: 1,
column: 6, column: 6,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Call { node: Call {
@ -22,6 +29,9 @@ expression: parse_ast
location: Location { location: Location {
row: 1, row: 1,
column: 1, column: 1,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -34,6 +44,9 @@ expression: parse_ast
location: Location { location: Location {
row: 1, row: 1,
column: 8, column: 8,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
@ -47,11 +60,16 @@ expression: parse_ast
location: Location { location: Location {
row: 1, row: 1,
column: 22, column: 22,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
value: Int( value: Int(
2, Some(
2,
),
), ),
kind: None, kind: None,
}, },

View File

@ -1,5 +1,6 @@
--- ---
source: nac3parser/src/parser.rs source: nac3parser/src/parser.rs
assertion_line: 97
expression: parse_ast expression: parse_ast
--- ---
@ -8,6 +9,9 @@ expression: parse_ast
location: Location { location: Location {
row: 1, row: 1,
column: 1, column: 1,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Expr { node: Expr {
@ -15,6 +19,9 @@ expression: parse_ast
location: Location { location: Location {
row: 1, row: 1,
column: 6, column: 6,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Call { node: Call {
@ -22,6 +29,9 @@ expression: parse_ast
location: Location { location: Location {
row: 1, row: 1,
column: 1, column: 1,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -34,6 +44,9 @@ expression: parse_ast
location: Location { location: Location {
row: 1, row: 1,
column: 8, column: 8,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {

View File

@ -1,6 +1,7 @@
--- ---
source: nac3parser/src/parser.rs source: nac3parser/src/parser.rs
expression: parse_program(&source).unwrap() assertion_line: 132
expression: "parse_program(&source, Default::default()).unwrap()"
--- ---
[ [
@ -8,6 +9,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 1, row: 1,
column: 1, column: 1,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Assign { node: Assign {
@ -16,6 +20,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 1, row: 1,
column: 1, column: 1,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Tuple { node: Tuple {
@ -24,6 +31,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 1, row: 1,
column: 1, column: 1,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -35,6 +45,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 1, row: 1,
column: 4, column: 4,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -51,6 +64,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 1, row: 1,
column: 8, column: 8,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Tuple { node: Tuple {
@ -59,11 +75,16 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 1, row: 1,
column: 8, column: 8,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
value: Int( value: Int(
4, Some(
4,
),
), ),
kind: None, kind: None,
}, },
@ -72,11 +93,16 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 1, row: 1,
column: 11, column: 11,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
value: Int( value: Int(
5, Some(
5,
),
), ),
kind: None, kind: None,
}, },

View File

@ -1,6 +1,7 @@
--- ---
source: nac3parser/src/parser.rs source: nac3parser/src/parser.rs
expression: parse_program(&source).unwrap() assertion_line: 199
expression: "parse_program(&source, Default::default()).unwrap()"
--- ---
[ [
@ -8,6 +9,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 1, row: 1,
column: 1, column: 1,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: While { node: While {
@ -15,6 +19,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 4, row: 4,
column: 7, column: 7,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -27,6 +34,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 6, row: 6,
column: 5, column: 5,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Assign { node: Assign {
@ -35,6 +45,9 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 6, row: 6,
column: 5, column: 5,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Name { node: Name {
@ -47,11 +60,16 @@ expression: parse_program(&source).unwrap()
location: Location { location: Location {
row: 6, row: 6,
column: 9, column: 9,
file: FileName(
"unknown",
),
}, },
custom: (), custom: (),
node: Constant { node: Constant {
value: Int( value: Int(
3, Some(
3,
),
), ),
kind: None, kind: None,
}, },

View File

@ -1,6 +1,5 @@
//! Different token definitions. //! Different token definitions.
//! Loosely based on token.h from CPython source: //! Loosely based on token.h from CPython source:
use num_bigint::BigInt;
use std::fmt::{self, Write}; use std::fmt::{self, Write};
use crate::ast; use crate::ast;
@ -8,7 +7,7 @@ use crate::ast;
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub enum Tok { pub enum Tok {
Name { name: ast::StrRef }, Name { name: ast::StrRef },
Int { value: BigInt }, Int { value: Option<i64> },
Float { value: f64 }, Float { value: f64 },
Complex { real: f64, imag: f64 }, Complex { real: f64, imag: f64 },
String { value: String, is_fstring: bool }, String { value: String, is_fstring: bool },
@ -113,7 +112,7 @@ impl fmt::Display for Tok {
use Tok::*; use Tok::*;
match self { match self {
Name { name } => write!(f, "'{}'", ast::get_str_from_ref(&ast::get_str_ref_lock(), *name)), Name { name } => write!(f, "'{}'", ast::get_str_from_ref(&ast::get_str_ref_lock(), *name)),
Int { value } => write!(f, "'{}'", value), Int { value } => if let Some(value) = value { write!(f, "'{}'", value) } else { write!(f, "'#OFL#'") },
Float { value } => write!(f, "'{}'", value), Float { value } => write!(f, "'{}'", value),
Complex { real, imag } => write!(f, "{}j{}", real, imag), Complex { real, imag } => write!(f, "{}j{}", real, imag),
String { value, is_fstring } => { String { value, is_fstring } => {

View File

@ -10,7 +10,6 @@ nac3parser = { path = "../nac3parser" }
nac3core = { path = "../nac3core" } nac3core = { path = "../nac3core" }
[dependencies.inkwell] [dependencies.inkwell]
git = "https://github.com/TheDan64/inkwell" version = "0.1.0-beta.4"
branch = "master"
default-features = false default-features = false
features = ["llvm12-0", "target-x86", "target-arm", "target-riscv", "no-libffi-linking"] features = ["llvm13-0", "target-x86", "target-arm", "target-riscv", "no-libffi-linking"]

View File

@ -35,7 +35,7 @@ fn main() {
Target::initialize_all(&InitializationConfig::default()); Target::initialize_all(&InitializationConfig::default());
let program = match fs::read_to_string(demo_name + ".py") { let program = match fs::read_to_string(demo_name.clone() + ".py") {
Ok(program) => program, Ok(program) => program,
Err(err) => { Err(err) => {
println!("Cannot open input file: {}", err); println!("Cannot open input file: {}", err);
@ -64,7 +64,7 @@ fn main() {
setup_time.duration_since(start).unwrap().as_millis() setup_time.duration_since(start).unwrap().as_millis()
); );
let parser_result = parser::parse_program(&program).unwrap(); let parser_result = parser::parse_program(&program, format!("{}.py", demo_name).into()).unwrap();
let parse_time = SystemTime::now(); let parse_time = SystemTime::now();
println!( println!(
"parse time: {}ms", "parse time: {}ms",