forked from M-Labs/nac3
Compare commits
93 Commits
master
...
crash_fix_
Author | SHA1 | Date | |
---|---|---|---|
258aa4c9d6 | |||
b04631e935 | |||
09820e5aed | |||
0ec2ed4d91 | |||
2cb725b7ac | |||
b9259b1907 | |||
096f4b03c0 | |||
a022005183 | |||
325ba0a408 | |||
ae6434696c | |||
3f327113b2 | |||
27d509d70e | |||
a321b13bec | |||
48cb485b89 | |||
837aaa95f1 | |||
a19e9c0bec | |||
5dbe1d3d7d | |||
e9bca3c822 | |||
42d1aad507 | |||
2777a6e05f | |||
05be5e93c4 | |||
85f21060e4 | |||
a308d24caa | |||
1eac111d4c | |||
44199781dc | |||
711c3d3303 | |||
0975264482 | |||
087aded3a3 | |||
f14b32be67 | |||
|
879c66cccf | ||
|
35b6459c58 | ||
e94b25f544 | |||
6972689469 | |||
3fb22c9182 | |||
1e7abf0268 | |||
f5a6d29106 | |||
ca07cb66cd | |||
93e9a6a38a | |||
722e3df086 | |||
ad9ad22cb8 | |||
f66f66b3a4 | |||
6c485bc9dc | |||
089bba96a3 | |||
0e0871bc38 | |||
26187bff0b | |||
86ce513cb5 | |||
c29cbf6ddd | |||
7443c5ea0f | |||
f55b077e60 | |||
e05b0bf5dc | |||
8eda0affc9 | |||
75c53b40a3 | |||
0d10044d66 | |||
23b7f4ef18 | |||
710904f975 | |||
4bf452ec5a | |||
9fdce11efe | |||
f24ef85aed | |||
4a19787f10 | |||
8209c0a475 | |||
4f66bdeda9 | |||
57369896d7 | |||
2edeb31d21 | |||
b8ef44d64e | |||
c3156afebd | |||
388c9b7241 | |||
e52d7fc97a | |||
6ab73a223c | |||
a38cc04444 | |||
1f5826d352 | |||
94eebde4ea | |||
63ec382673 | |||
0ca1a7bedb | |||
201ca3f63d | |||
19182759cd | |||
edd039abdc | |||
3852cc1058 | |||
0600ee8efa | |||
bed33a7421 | |||
0d2b844a2e | |||
8d7e300a4a | |||
10d623e36f | |||
000b128551 | |||
e4581a6d9b | |||
1a82d296e7 | |||
bf067e2481 | |||
ba8ed6c663 | |||
26a4834254 | |||
1ad4b0227c | |||
6288a66dc5 | |||
de4320eefb | |||
a380cd5010 | |||
80631fc92b |
275
Cargo.lock
generated
275
Cargo.lock
generated
@ -234,9 +234,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fixedbitset"
|
name = "fixedbitset"
|
||||||
version = "0.2.0"
|
version = "0.4.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "37ab347416e802de484e4d03c7316c48f1ecb56574dfd4a46a80f173ce1de04d"
|
checksum = "279fb028e20b3c4c320317955b77c5e0c9701f05a1d309905d6fc702cdc5053e"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fxhash"
|
name = "fxhash"
|
||||||
@ -249,9 +249,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "getrandom"
|
name = "getrandom"
|
||||||
version = "0.2.5"
|
version = "0.2.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d39cd93900197114fa1fcb7ae84ca742095eed9442088988ae74fa744e930e77"
|
checksum = "9be70c98951c83b8d2f8f60d7065fa6d5146873094452a1008da8c2f1e4205ad"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"libc",
|
"libc",
|
||||||
@ -278,9 +278,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "indexmap"
|
name = "indexmap"
|
||||||
version = "1.8.0"
|
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 = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223"
|
checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"autocfg",
|
"autocfg",
|
||||||
"hashbrown",
|
"hashbrown",
|
||||||
@ -298,12 +298,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "indoc"
|
name = "indoc"
|
||||||
version = "1.0.4"
|
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 = "e7906a9fababaeacb774f72410e497a1d18de916322e33797bb2cd29baa23c9e"
|
checksum = "05a0bd019339e5d968b37855180087b7b9d512c5046fbd244cf8c95687927d6e"
|
||||||
dependencies = [
|
|
||||||
"unindent",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "indoc-impl"
|
name = "indoc-impl"
|
||||||
@ -320,24 +317,21 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "inkwell"
|
name = "inkwell"
|
||||||
version = "0.1.0-beta.4"
|
version = "0.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "git+https://github.com/TheDan64/inkwell.git#02fb7045f7a952c80bc983e19093c62c6ccffe3d"
|
||||||
checksum = "2223d0eba0ae6d40a3e4680c6a3209143471e1f38b41746ea309aa36dde9f90b"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"either",
|
"either",
|
||||||
"inkwell_internals",
|
"inkwell_internals",
|
||||||
"libc",
|
"libc",
|
||||||
"llvm-sys",
|
"llvm-sys",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"parking_lot",
|
"parking_lot 0.12.0",
|
||||||
"regex",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "inkwell_internals"
|
name = "inkwell_internals"
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "git+https://github.com/TheDan64/inkwell.git#02fb7045f7a952c80bc983e19093c62c6ccffe3d"
|
||||||
checksum = "3c7090af3d300424caa81976b8c97bca41cd70e861272c072e188ae082fb49f9"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@ -378,15 +372,15 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "itoa"
|
name = "itoa"
|
||||||
version = "1.0.1"
|
version = "1.0.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35"
|
checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lalrpop"
|
name = "lalrpop"
|
||||||
version = "0.19.7"
|
version = "0.19.8"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "852b75a095da6b69da8c5557731c3afd06525d4f655a4fc1c799e2ec8bc4dce4"
|
checksum = "b30455341b0e18f276fa64540aff54deafb54c589de6aca68659c63dd2d5d823"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ascii-canvas",
|
"ascii-canvas",
|
||||||
"atty",
|
"atty",
|
||||||
@ -407,9 +401,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lalrpop-util"
|
name = "lalrpop-util"
|
||||||
version = "0.19.7"
|
version = "0.19.8"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d6d265705249fe209280676d8f68887859fa42e1d34f342fc05bd47726a5e188"
|
checksum = "bcf796c978e9b4d983414f4caedc9273aa33ee214c5b887bd55fde84c85d2dc4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"regex",
|
"regex",
|
||||||
]
|
]
|
||||||
@ -422,9 +416,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.121"
|
version = "0.2.126"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "efaa7b300f3b5fe8eb6bf21ce3895e1751d9665086af2d64b42f19701015ff4f"
|
checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libloading"
|
name = "libloading"
|
||||||
@ -444,9 +438,9 @@ checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "llvm-sys"
|
name = "llvm-sys"
|
||||||
version = "130.0.3"
|
version = "140.0.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "95eb03b4f7ae21f48ef7c565a3e3aa22c50616aea64645fb1fd7f6f56b51c274"
|
checksum = "5a4ad24a72823cb06764e04a008d4aedc1be56d2be87aa4212b12a3e9f77bb10"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cc",
|
"cc",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
@ -457,27 +451,28 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lock_api"
|
name = "lock_api"
|
||||||
version = "0.4.6"
|
version = "0.4.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "88943dd7ef4a2e5a4bfa2753aaab3013e34ce2533d1996fb18ef591e315e2b3b"
|
checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
"scopeguard",
|
"scopeguard",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "log"
|
name = "log"
|
||||||
version = "0.4.16"
|
version = "0.4.17"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6389c490849ff5bc16be905ae24bc913a9c8892e19b2341dbc175e14c341c2b8"
|
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "memchr"
|
name = "memchr"
|
||||||
version = "2.4.1"
|
version = "2.5.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a"
|
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "memoffset"
|
name = "memoffset"
|
||||||
@ -495,7 +490,7 @@ dependencies = [
|
|||||||
"inkwell",
|
"inkwell",
|
||||||
"nac3core",
|
"nac3core",
|
||||||
"nac3parser",
|
"nac3parser",
|
||||||
"parking_lot",
|
"parking_lot 0.11.2",
|
||||||
"pyo3",
|
"pyo3",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
]
|
]
|
||||||
@ -506,7 +501,7 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"fxhash",
|
"fxhash",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"parking_lot",
|
"parking_lot 0.11.2",
|
||||||
"string-interner",
|
"string-interner",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -515,12 +510,12 @@ name = "nac3core"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"crossbeam",
|
"crossbeam",
|
||||||
"indoc 1.0.4",
|
"indoc 1.0.6",
|
||||||
"inkwell",
|
"inkwell",
|
||||||
"insta",
|
"insta",
|
||||||
"itertools",
|
"itertools",
|
||||||
"nac3parser",
|
"nac3parser",
|
||||||
"parking_lot",
|
"parking_lot 0.11.2",
|
||||||
"rayon",
|
"rayon",
|
||||||
"regex",
|
"regex",
|
||||||
"test-case",
|
"test-case",
|
||||||
@ -549,7 +544,7 @@ dependencies = [
|
|||||||
"inkwell",
|
"inkwell",
|
||||||
"nac3core",
|
"nac3core",
|
||||||
"nac3parser",
|
"nac3parser",
|
||||||
"parking_lot",
|
"parking_lot 0.11.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -570,9 +565,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "once_cell"
|
name = "once_cell"
|
||||||
version = "1.10.0"
|
version = "1.12.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9"
|
checksum = "7709cef83f0c1f58f666e746a08b21e0085f7440fa6a29cc194d68aac97a4225"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "parking_lot"
|
name = "parking_lot"
|
||||||
@ -582,7 +577,17 @@ checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"instant",
|
"instant",
|
||||||
"lock_api",
|
"lock_api",
|
||||||
"parking_lot_core",
|
"parking_lot_core 0.8.5",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "parking_lot"
|
||||||
|
version = "0.12.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "87f5ec2493a61ac0506c0f4199f99070cbe83857b0337006a30f3e6719b8ef58"
|
||||||
|
dependencies = [
|
||||||
|
"lock_api",
|
||||||
|
"parking_lot_core 0.9.3",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -599,6 +604,19 @@ dependencies = [
|
|||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "parking_lot_core"
|
||||||
|
version = "0.9.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
"redox_syscall",
|
||||||
|
"smallvec",
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "paste"
|
name = "paste"
|
||||||
version = "0.1.18"
|
version = "0.1.18"
|
||||||
@ -618,20 +636,11 @@ dependencies = [
|
|||||||
"proc-macro-hack",
|
"proc-macro-hack",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pest"
|
|
||||||
version = "2.1.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "10f4872ae94d7b90ae48754df22fd42ad52ce740b8f370b03da4835417403e53"
|
|
||||||
dependencies = [
|
|
||||||
"ucd-trie",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "petgraph"
|
name = "petgraph"
|
||||||
version = "0.5.1"
|
version = "0.6.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "467d164a6de56270bd7c4d070df81d07beace25012d5103ced4e9ff08d6afdb7"
|
checksum = "51b305cc4569dd4e8765bab46261f67ef5d4d11a4b6e745100ee5dad8948b46c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"fixedbitset",
|
"fixedbitset",
|
||||||
"indexmap",
|
"indexmap",
|
||||||
@ -716,11 +725,11 @@ checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.36"
|
version = "1.0.39"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029"
|
checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"unicode-xid",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -732,7 +741,7 @@ dependencies = [
|
|||||||
"cfg-if",
|
"cfg-if",
|
||||||
"indoc 0.3.6",
|
"indoc 0.3.6",
|
||||||
"libc",
|
"libc",
|
||||||
"parking_lot",
|
"parking_lot 0.11.2",
|
||||||
"paste",
|
"paste",
|
||||||
"pyo3-build-config",
|
"pyo3-build-config",
|
||||||
"pyo3-macros",
|
"pyo3-macros",
|
||||||
@ -773,9 +782,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "quote"
|
name = "quote"
|
||||||
version = "1.0.16"
|
version = "1.0.18"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b4af2ec4714533fcdf07e886f17025ace8b997b9ce51204ee69b6da831c3da57"
|
checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
]
|
]
|
||||||
@ -812,9 +821,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rayon"
|
name = "rayon"
|
||||||
version = "1.5.1"
|
version = "1.5.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c06aca804d41dbc8ba42dfd964f0d01334eceb64314b9ecf7c5fad5188a06d90"
|
checksum = "bd99e5772ead8baa5215278c9b15bf92087709e9c1b2d1f97cdb5a183c933a7d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"autocfg",
|
"autocfg",
|
||||||
"crossbeam-deque",
|
"crossbeam-deque",
|
||||||
@ -824,31 +833,30 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rayon-core"
|
name = "rayon-core"
|
||||||
version = "1.9.1"
|
version = "1.9.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d78120e2c850279833f1dd3582f730c4ab53ed95aeaaaa862a2a5c71b1656d8e"
|
checksum = "258bcdb5ac6dad48491bb2992db6b7cf74878b0384908af124823d118c99683f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"crossbeam-channel",
|
"crossbeam-channel",
|
||||||
"crossbeam-deque",
|
"crossbeam-deque",
|
||||||
"crossbeam-utils",
|
"crossbeam-utils",
|
||||||
"lazy_static",
|
|
||||||
"num_cpus",
|
"num_cpus",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "redox_syscall"
|
name = "redox_syscall"
|
||||||
version = "0.2.11"
|
version = "0.2.13"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8380fe0152551244f0747b1bf41737e0f8a74f97a14ccefd1148187271634f3c"
|
checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "redox_users"
|
name = "redox_users"
|
||||||
version = "0.4.2"
|
version = "0.4.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7776223e2696f1aa4c6b0170e83212f47296a00424305117d013dfe86fb0fe55"
|
checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"getrandom",
|
"getrandom",
|
||||||
"redox_syscall",
|
"redox_syscall",
|
||||||
@ -857,9 +865,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "regex"
|
name = "regex"
|
||||||
version = "1.5.5"
|
version = "1.5.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1a11647b6b25ff05a515cb92c365cec08801e83423a235b51e231e1808747286"
|
checksum = "d83f127d94bdbcda4c8cc2e50f6f84f4b611f69c902699ca385a39c3a75f9ff1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aho-corasick",
|
"aho-corasick",
|
||||||
"memchr",
|
"memchr",
|
||||||
@ -868,9 +876,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "regex-syntax"
|
name = "regex-syntax"
|
||||||
version = "0.6.25"
|
version = "0.6.26"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
|
checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "remove_dir_all"
|
name = "remove_dir_all"
|
||||||
@ -896,9 +904,9 @@ checksum = "f2cc38e8fa666e2de3c4aba7edeb5ffc5246c1c2ed0e3d17e560aeeba736b23f"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ryu"
|
name = "ryu"
|
||||||
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 = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f"
|
checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "scopeguard"
|
name = "scopeguard"
|
||||||
@ -908,36 +916,24 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "semver"
|
name = "semver"
|
||||||
version = "0.11.0"
|
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 = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6"
|
checksum = "8cb243bdfdb5936c8dc3c45762a19d12ab4550cdc753bc247637d4ec35a040fd"
|
||||||
dependencies = [
|
|
||||||
"semver-parser",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "semver-parser"
|
|
||||||
version = "0.10.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7"
|
|
||||||
dependencies = [
|
|
||||||
"pest",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.136"
|
version = "1.0.137"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789"
|
checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.136"
|
version = "1.0.137"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "08597e7152fcd306f41838ed3e37be9eaeed2b61c42e2117266a554fab4662f9"
|
checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@ -946,9 +942,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_json"
|
name = "serde_json"
|
||||||
version = "1.0.79"
|
version = "1.0.81"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8e8d9fa5c3b304765ce1fd9c4c8a3de2c8db365a5b91be52f186efc675681d95"
|
checksum = "9b7ce2b32a1aed03c558dc61a5cd328f15aff2dbc17daad8fb8af04d2100e15c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"itoa",
|
"itoa",
|
||||||
"ryu",
|
"ryu",
|
||||||
@ -957,9 +953,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_yaml"
|
name = "serde_yaml"
|
||||||
version = "0.8.23"
|
version = "0.8.24"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a4a521f2940385c165a24ee286aa8599633d162077a54bdcae2a6fd5a7bfa7a0"
|
checksum = "707d15895415db6628332b737c838b88c598522e4dc70647e59b72312924aebc"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"ryu",
|
"ryu",
|
||||||
@ -998,26 +994,26 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "string_cache"
|
name = "string_cache"
|
||||||
version = "0.8.3"
|
version = "0.8.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "33994d0838dc2d152d17a62adf608a869b5e846b65b389af7f3dbc1de45c5b26"
|
checksum = "213494b7a2b503146286049378ce02b482200519accc31872ee8be91fa820a08"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"lazy_static",
|
|
||||||
"new_debug_unreachable",
|
"new_debug_unreachable",
|
||||||
"parking_lot",
|
"once_cell",
|
||||||
|
"parking_lot 0.12.0",
|
||||||
"phf_shared 0.10.0",
|
"phf_shared 0.10.0",
|
||||||
"precomputed-hash",
|
"precomputed-hash",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "1.0.89"
|
version = "1.0.95"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ea297be220d52398dcc07ce15a209fce436d361735ac1db700cab3b6cdfb9f54"
|
checksum = "fbaf6116ab8924f39d52792136fb74fd60a80194cf1b1c6ffa6453eef1c3f942"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"unicode-xid",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1070,18 +1066,18 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "thiserror"
|
name = "thiserror"
|
||||||
version = "1.0.30"
|
version = "1.0.31"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417"
|
checksum = "bd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"thiserror-impl",
|
"thiserror-impl",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "thiserror-impl"
|
name = "thiserror-impl"
|
||||||
version = "1.0.30"
|
version = "1.0.31"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b"
|
checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@ -1097,12 +1093,6 @@ dependencies = [
|
|||||||
"crunchy",
|
"crunchy",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ucd-trie"
|
|
||||||
version = "0.1.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unic-char-property"
|
name = "unic-char-property"
|
||||||
version = "0.9.0"
|
version = "0.9.0"
|
||||||
@ -1156,10 +1146,16 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-xid"
|
name = "unicode-ident"
|
||||||
version = "0.2.2"
|
version = "1.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
|
checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-xid"
|
||||||
|
version = "0.2.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode_names2"
|
name = "unicode_names2"
|
||||||
@ -1169,9 +1165,9 @@ checksum = "87d6678d7916394abad0d4b19df4d3802e1fd84abd7d701f39b75ee71b9e8cf1"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unindent"
|
name = "unindent"
|
||||||
version = "0.1.8"
|
version = "0.1.9"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "514672a55d7380da379785a4d70ca8386c8883ff7eaae877be4d2081cebe73d8"
|
checksum = "52fee519a3e570f7df377a06a1a7775cdbfb7aa460be7e08de2b1f0e69973a44"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "version_check"
|
name = "version_check"
|
||||||
@ -1207,6 +1203,49 @@ version = "0.4.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-sys"
|
||||||
|
version = "0.36.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2"
|
||||||
|
dependencies = [
|
||||||
|
"windows_aarch64_msvc",
|
||||||
|
"windows_i686_gnu",
|
||||||
|
"windows_i686_msvc",
|
||||||
|
"windows_x86_64_gnu",
|
||||||
|
"windows_x86_64_msvc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_aarch64_msvc"
|
||||||
|
version = "0.36.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_gnu"
|
||||||
|
version = "0.36.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_msvc"
|
||||||
|
version = "0.36.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_gnu"
|
||||||
|
version = "0.36.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_msvc"
|
||||||
|
version = "0.36.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "yaml-rust"
|
name = "yaml-rust"
|
||||||
version = "0.4.5"
|
version = "0.4.5"
|
||||||
|
43
README.md
43
README.md
@ -1,5 +1,10 @@
|
|||||||
# NAC3
|
<div align="center">
|
||||||
|
|
||||||
|
![icon](https://git.m-labs.hk/M-Labs/nac3/raw/branch/master/nac3.svg)
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
# NAC3
|
||||||
NAC3 is a major, backward-incompatible rewrite of the compiler for the [ARTIQ](https://m-labs.hk/artiq) physics experiment control and data acquisition system. It features greatly improved compilation speeds, a much better type system, and more predictable and transparent operation.
|
NAC3 is a major, backward-incompatible rewrite of the compiler for the [ARTIQ](https://m-labs.hk/artiq) physics experiment control and data acquisition system. It features greatly improved compilation speeds, a much better type system, and more predictable and transparent operation.
|
||||||
|
|
||||||
NAC3 has a modular design and its applicability reaches beyond ARTIQ. The ``nac3core`` module does not contain anything specific to ARTIQ, and can be used in any project that requires compiling Python to machine code.
|
NAC3 has a modular design and its applicability reaches beyond ARTIQ. The ``nac3core`` module does not contain anything specific to ARTIQ, and can be used in any project that requires compiling Python to machine code.
|
||||||
@ -16,40 +21,28 @@ NAC3 is packaged using the [Nix](https://nixos.org) Flakes system. Install Nix 2
|
|||||||
|
|
||||||
After setting up Nix as above, use ``nix shell git+https://github.com/m-labs/artiq.git?ref=nac3`` to get a shell with the NAC3 version of ARTIQ. See the ``examples`` directory in ARTIQ (``nac3`` Git branch) for some samples of NAC3 kernel code.
|
After setting up Nix as above, use ``nix shell git+https://github.com/m-labs/artiq.git?ref=nac3`` to get a shell with the NAC3 version of ARTIQ. See the ``examples`` directory in ARTIQ (``nac3`` Git branch) for some samples of NAC3 kernel code.
|
||||||
|
|
||||||
### Windows (work in progress)
|
### Windows
|
||||||
|
|
||||||
NAC3 ARTIQ packaging for MSYS2/Windows is not yet complete so installation involves many manual steps. It is also less tested and you may encounter problems.
|
Install [MSYS2](https://www.msys2.org/), and open "MSYS2 MinGW x64". Edit ``/etc/pacman.conf`` to add:
|
||||||
|
|
||||||
Install [MSYS2](https://www.msys2.org/) and run the following commands:
|
|
||||||
```
|
```
|
||||||
pacman -S mingw-w64-x86_64-python-h5py mingw-w64-x86_64-python-pyqt5 mingw-w64-x86_64-python-scipy mingw-w64-x86_64-python-prettytable mingw-w64-x86_64-python-pygit2
|
[artiq]
|
||||||
pacman -S mingw-w64-x86_64-python-pip
|
SigLevel = Optional TrustAll
|
||||||
pip install qasync
|
Server = https://lab.m-labs.hk/msys2
|
||||||
pip install pyqtgraph
|
|
||||||
pacman -S patch git
|
|
||||||
git clone https://github.com/m-labs/sipyco
|
|
||||||
cd sipyco
|
|
||||||
git show 20c946aad78872fe60b78d9b57a624d69f3eea47 | patch -p1 -R
|
|
||||||
python setup.py install
|
|
||||||
cd ..
|
|
||||||
git clone -b nac3 https://github.com/m-labs/artiq
|
|
||||||
cd artiq
|
|
||||||
python setup.py install
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Locate a recent build of ``nac3artiq-msys2`` from [Hydra](https://nixbld.m-labs.hk) and download ``nac3artiq.zip``. Then extract the contents in the appropriate location:
|
Then run the following commands:
|
||||||
```
|
```
|
||||||
pacman -S unzip
|
pacman -Syu
|
||||||
wget https://nixbld.m-labs.hk/build/97899/download/1/nac3artiq.zip # edit the build number
|
pacman -S mingw-w64-x86_64-artiq
|
||||||
unzip nac3artiq.zip -d C:/msys64/mingw64/lib/python3.9/site-packages
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Install additional NAC3 dependencies:
|
Install ``lld-msys2`` manually:
|
||||||
```
|
```
|
||||||
pacman -S mingw-w64-x86_64-lld
|
wget https://nixbld.m-labs.hk/build/115527/download/1/ld.lld.exe
|
||||||
|
mv ld.lld.exe C:/msys64/mingw64/bin
|
||||||
```
|
```
|
||||||
|
|
||||||
And you should be good to go.
|
Note: This build of NAC3 cannot be used with Anaconda Python nor the python.org binaries for Windows. Those Python versions are compiled with Visual Studio (MSVC) and their ABI is incompatible with the GNU ABI used in this build. We have no plans to support Visual Studio nor the MSVC ABI. If you need a MSVC build, please install the requisite bloated spyware from Microsoft and compile NAC3 yourself.
|
||||||
|
|
||||||
## For developers
|
## For developers
|
||||||
|
|
||||||
|
8
flake.lock
generated
8
flake.lock
generated
@ -2,16 +2,16 @@
|
|||||||
"nodes": {
|
"nodes": {
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1647992509,
|
"lastModified": 1653354321,
|
||||||
"narHash": "sha256-AG40Nt5OWz0LBs5p457emOuwLKOvTtcv/2fUdnEN3Ws=",
|
"narHash": "sha256-AMUhX1Ch0KMDWCze6KAntwlJ1iFp0fLK2TTW9Mj85WY=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "d2caa9377539e3b5ff1272ac3aa2d15f3081069f",
|
"rev": "b80531b35cbcddcaf74ceb685b3a0847c134cbe1",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"ref": "nixos-21.11",
|
"ref": "release-22.05",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
|
86
flake.nix
86
flake.nix
@ -1,21 +1,27 @@
|
|||||||
{
|
{
|
||||||
description = "The third-generation ARTIQ compiler";
|
description = "The third-generation ARTIQ compiler";
|
||||||
|
|
||||||
inputs.nixpkgs.url = github:NixOS/nixpkgs/nixos-21.11;
|
inputs.nixpkgs.url = github:NixOS/nixpkgs/release-22.05;
|
||||||
|
|
||||||
outputs = { self, nixpkgs }:
|
outputs = { self, nixpkgs }:
|
||||||
let
|
let
|
||||||
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
||||||
in rec {
|
in rec {
|
||||||
packages.x86_64-linux = rec {
|
packages.x86_64-linux = rec {
|
||||||
llvm-nac3 = pkgs.callPackage "${self}/llvm" {};
|
llvm-nac3 = pkgs.callPackage ./nix/llvm {};
|
||||||
nac3artiq = pkgs.python3Packages.toPythonModule (
|
nac3artiq = pkgs.python3Packages.toPythonModule (
|
||||||
pkgs.rustPlatform.buildRustPackage {
|
pkgs.rustPlatform.buildRustPackage rec {
|
||||||
name = "nac3artiq";
|
name = "nac3artiq";
|
||||||
outputs = [ "out" "runkernel" "standalone" ];
|
outputs = [ "out" "runkernel" "standalone" ];
|
||||||
src = self;
|
src = self;
|
||||||
cargoLock = { lockFile = ./Cargo.lock; };
|
cargoLock = {
|
||||||
nativeBuildInputs = [ pkgs.python3 pkgs.llvmPackages_13.clang-unwrapped llvm-nac3 ];
|
lockFile = ./Cargo.lock;
|
||||||
|
outputHashes = {
|
||||||
|
"inkwell-0.1.0" = "sha256-gDHV3RDuBU/l1viV1G1YO4kdTylRUctlxZcocX1hIIo=";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
passthru.cargoLock = cargoLock;
|
||||||
|
nativeBuildInputs = [ pkgs.python3 pkgs.llvmPackages_14.clang-unwrapped pkgs.llvmPackages_14.llvm.out llvm-nac3 ];
|
||||||
buildInputs = [ pkgs.python3 llvm-nac3 ];
|
buildInputs = [ pkgs.python3 llvm-nac3 ];
|
||||||
checkInputs = [ (pkgs.python3.withPackages(ps: [ ps.numpy ])) ];
|
checkInputs = [ (pkgs.python3.withPackages(ps: [ ps.numpy ])) ];
|
||||||
checkPhase =
|
checkPhase =
|
||||||
@ -48,22 +54,22 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
# LLVM PGO support
|
# LLVM PGO support
|
||||||
llvm-nac3-instrumented = pkgs.callPackage "${self}/llvm" {
|
llvm-nac3-instrumented = pkgs.callPackage ./nix/llvm {
|
||||||
stdenv = pkgs.llvmPackages_13.stdenv;
|
stdenv = pkgs.llvmPackages_14.stdenv;
|
||||||
extraCmakeFlags = [ "-DLLVM_BUILD_INSTRUMENTED=IR" ];
|
extraCmakeFlags = [ "-DLLVM_BUILD_INSTRUMENTED=IR" ];
|
||||||
};
|
};
|
||||||
nac3artiq-instrumented = pkgs.python3Packages.toPythonModule (
|
nac3artiq-instrumented = pkgs.python3Packages.toPythonModule (
|
||||||
pkgs.rustPlatform.buildRustPackage {
|
pkgs.rustPlatform.buildRustPackage {
|
||||||
name = "nac3artiq-instrumented";
|
name = "nac3artiq-instrumented";
|
||||||
src = self;
|
src = self;
|
||||||
cargoLock = { lockFile = ./Cargo.lock; };
|
inherit (nac3artiq) cargoLock;
|
||||||
nativeBuildInputs = [ pkgs.python3 pkgs.llvmPackages_13.clang-unwrapped llvm-nac3-instrumented ];
|
nativeBuildInputs = [ pkgs.python3 pkgs.llvmPackages_14.clang-unwrapped pkgs.llvmPackages_14.llvm.out llvm-nac3-instrumented ];
|
||||||
buildInputs = [ pkgs.python3 llvm-nac3-instrumented ];
|
buildInputs = [ pkgs.python3 llvm-nac3-instrumented ];
|
||||||
cargoBuildFlags = [ "--package" "nac3artiq" "--features" "init-llvm-profile" ];
|
cargoBuildFlags = [ "--package" "nac3artiq" "--features" "init-llvm-profile" ];
|
||||||
doCheck = false;
|
doCheck = false;
|
||||||
configurePhase =
|
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"
|
export CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUSTFLAGS="-C link-arg=-L${pkgs.llvmPackages_14.compiler-rt}/lib/linux -C link-arg=-lclang_rt.profile-x86_64"
|
||||||
'';
|
'';
|
||||||
installPhase =
|
installPhase =
|
||||||
''
|
''
|
||||||
@ -75,27 +81,52 @@
|
|||||||
);
|
);
|
||||||
nac3artiq-profile = pkgs.stdenvNoCC.mkDerivation {
|
nac3artiq-profile = pkgs.stdenvNoCC.mkDerivation {
|
||||||
name = "nac3artiq-profile";
|
name = "nac3artiq-profile";
|
||||||
src = self;
|
srcs = [
|
||||||
buildInputs = [ (python3-mimalloc.withPackages(ps: [ ps.numpy nac3artiq-instrumented ])) pkgs.lld_13 pkgs.llvmPackages_13.libllvm ];
|
(pkgs.fetchFromGitHub {
|
||||||
|
owner = "m-labs";
|
||||||
|
repo = "sipyco";
|
||||||
|
rev = "939f84f9b5eef7efbf7423c735d1834783b6140e";
|
||||||
|
sha256 = "sha256-15Nun4EY35j+6SPZkjzZtyH/ncxLS60KuGJjFh5kSTc=";
|
||||||
|
})
|
||||||
|
(pkgs.fetchFromGitHub {
|
||||||
|
owner = "m-labs";
|
||||||
|
repo = "artiq";
|
||||||
|
rev = "dd57fdc530baf926a5f354dc1c2bd90564affd96";
|
||||||
|
sha256 = "sha256-hcqVcToYWkc3oDFkKr9wZUF65ydiSYVHdmiGiu2Mc1c=";
|
||||||
|
})
|
||||||
|
];
|
||||||
|
buildInputs = [
|
||||||
|
(python3-mimalloc.withPackages(ps: [ ps.numpy ps.jsonschema nac3artiq-instrumented ]))
|
||||||
|
pkgs.lld_14
|
||||||
|
pkgs.llvmPackages_14.llvm.out
|
||||||
|
];
|
||||||
phases = [ "buildPhase" "installPhase" ];
|
phases = [ "buildPhase" "installPhase" ];
|
||||||
# TODO: get more representative code.
|
buildPhase =
|
||||||
buildPhase = "python $src/nac3artiq/demo/demo.py";
|
''
|
||||||
|
srcs=($srcs)
|
||||||
|
sipyco=''${srcs[0]}
|
||||||
|
artiq=''${srcs[1]}
|
||||||
|
export PYTHONPATH=$sipyco:$artiq
|
||||||
|
python -m artiq.frontend.artiq_ddb_template $artiq/artiq/examples/nac3devices/nac3devices.json > device_db.py
|
||||||
|
cp $artiq/artiq/examples/nac3devices/nac3devices.py .
|
||||||
|
python -m artiq.frontend.artiq_compile nac3devices.py
|
||||||
|
'';
|
||||||
installPhase =
|
installPhase =
|
||||||
''
|
''
|
||||||
mkdir $out
|
mkdir $out
|
||||||
llvm-profdata merge -o $out/llvm.profdata /build/llvm/build/profiles/*
|
llvm-profdata merge -o $out/llvm.profdata /build/llvm/build/profiles/*
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
llvm-nac3-pgo = pkgs.callPackage "${self}/llvm" {
|
llvm-nac3-pgo = pkgs.callPackage ./nix/llvm {
|
||||||
stdenv = pkgs.llvmPackages_13.stdenv;
|
stdenv = pkgs.llvmPackages_14.stdenv;
|
||||||
extraCmakeFlags = [ "-DLLVM_PROFDATA_FILE=${nac3artiq-profile}/llvm.profdata" ];
|
extraCmakeFlags = [ "-DLLVM_PROFDATA_FILE=${nac3artiq-profile}/llvm.profdata" ];
|
||||||
};
|
};
|
||||||
nac3artiq-pgo = pkgs.python3Packages.toPythonModule (
|
nac3artiq-pgo = pkgs.python3Packages.toPythonModule (
|
||||||
pkgs.rustPlatform.buildRustPackage {
|
pkgs.rustPlatform.buildRustPackage {
|
||||||
name = "nac3artiq-pgo";
|
name = "nac3artiq-pgo";
|
||||||
src = self;
|
src = self;
|
||||||
cargoLock = { lockFile = ./Cargo.lock; };
|
inherit (nac3artiq) cargoLock;
|
||||||
nativeBuildInputs = [ pkgs.python3 pkgs.llvmPackages_13.clang-unwrapped llvm-nac3-pgo ];
|
nativeBuildInputs = [ pkgs.python3 pkgs.llvmPackages_14.clang-unwrapped pkgs.llvmPackages_14.llvm.out llvm-nac3-pgo ];
|
||||||
buildInputs = [ pkgs.python3 llvm-nac3-pgo ];
|
buildInputs = [ pkgs.python3 llvm-nac3-pgo ];
|
||||||
cargoBuildFlags = [ "--package" "nac3artiq" ];
|
cargoBuildFlags = [ "--package" "nac3artiq" ];
|
||||||
cargoTestFlags = [ "--package" "nac3ast" "--package" "nac3parser" "--package" "nac3core" "--package" "nac3artiq" ];
|
cargoTestFlags = [ "--package" "nac3ast" "--package" "nac3parser" "--package" "nac3core" "--package" "nac3artiq" ];
|
||||||
@ -109,27 +140,30 @@
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
packages.x86_64-w64-mingw32 = import ./windows { inherit pkgs; };
|
packages.x86_64-w64-mingw32 = import ./nix/windows { inherit pkgs; };
|
||||||
|
|
||||||
devShell.x86_64-linux = pkgs.mkShell {
|
devShell.x86_64-linux = pkgs.mkShell {
|
||||||
name = "nac3-dev-shell";
|
name = "nac3-dev-shell";
|
||||||
buildInputs = with pkgs; [
|
buildInputs = with pkgs; [
|
||||||
# build dependencies
|
# build dependencies
|
||||||
packages.x86_64-linux.llvm-nac3
|
packages.x86_64-linux.llvm-nac3
|
||||||
llvmPackages_13.clang-unwrapped # IRRT
|
llvmPackages_14.clang-unwrapped # IRRT
|
||||||
|
pkgs.llvmPackages_14.llvm.out # IRRT
|
||||||
cargo
|
cargo
|
||||||
rustc
|
rustc
|
||||||
# runtime dependencies
|
# runtime dependencies
|
||||||
lld_13
|
lld_14
|
||||||
(packages.x86_64-linux.python3-mimalloc.withPackages(ps: [ ps.numpy ]))
|
(packages.x86_64-linux.python3-mimalloc.withPackages(ps: [ ps.numpy ]))
|
||||||
# development tools
|
# development tools
|
||||||
cargo-insta
|
cargo-insta
|
||||||
clippy
|
clippy
|
||||||
rustfmt
|
rustfmt
|
||||||
|
lldb_14
|
||||||
];
|
];
|
||||||
|
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
|
||||||
};
|
};
|
||||||
devShells.x86_64-linux.msys2 = pkgs.mkShell {
|
devShells.x86_64-linux.msys2 = pkgs.mkShell {
|
||||||
name = "nac3-dev-shell";
|
name = "nac3-dev-shell-msys2";
|
||||||
buildInputs = with pkgs; [
|
buildInputs = with pkgs; [
|
||||||
curl
|
curl
|
||||||
pacman
|
pacman
|
||||||
@ -139,14 +173,16 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
hydraJobs = {
|
hydraJobs = {
|
||||||
inherit (packages.x86_64-linux) llvm-nac3 nac3artiq;
|
inherit (packages.x86_64-linux) llvm-nac3 nac3artiq nac3artiq-pgo;
|
||||||
llvm-nac3-msys2 = packages.x86_64-w64-mingw32.llvm-nac3;
|
llvm-nac3-msys2 = packages.x86_64-w64-mingw32.llvm-nac3;
|
||||||
nac3artiq-msys2 = packages.x86_64-w64-mingw32.nac3artiq;
|
nac3artiq-msys2 = packages.x86_64-w64-mingw32.nac3artiq;
|
||||||
|
nac3artiq-msys2-pkg = packages.x86_64-w64-mingw32.nac3artiq-pkg;
|
||||||
|
lld-msys2 = packages.x86_64-w64-mingw32.lld;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
nixConfig = {
|
nixConfig = {
|
||||||
binaryCachePublicKeys = ["nixbld.m-labs.hk-1:5aSRVA5b320xbNvu30tqxVPXpld73bhtOeH6uAjRyHc="];
|
extra-trusted-public-keys = "nixbld.m-labs.hk-1:5aSRVA5b320xbNvu30tqxVPXpld73bhtOeH6uAjRyHc=";
|
||||||
binaryCaches = ["https://nixbld.m-labs.hk" "https://cache.nixos.org"];
|
extra-substituters = "https://nixbld.m-labs.hk";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,381 +0,0 @@
|
|||||||
diff --git a/CMakeLists.txt b/CMakeLists.txt
|
|
||||||
index 135036f509d2..265c36f8211b 100644
|
|
||||||
--- a/CMakeLists.txt
|
|
||||||
+++ b/CMakeLists.txt
|
|
||||||
@@ -270,15 +270,21 @@ if (CMAKE_BUILD_TYPE AND
|
|
||||||
message(FATAL_ERROR "Invalid value for CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
+include(GNUInstallDirs)
|
|
||||||
+
|
|
||||||
set(LLVM_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name (32/64)" )
|
|
||||||
|
|
||||||
-set(LLVM_TOOLS_INSTALL_DIR "bin" CACHE STRING "Path for binary subdirectory (defaults to 'bin')")
|
|
||||||
+set(LLVM_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE STRING
|
|
||||||
+ "Path for binary subdirectory (defaults to 'bin')")
|
|
||||||
mark_as_advanced(LLVM_TOOLS_INSTALL_DIR)
|
|
||||||
|
|
||||||
set(LLVM_UTILS_INSTALL_DIR "${LLVM_TOOLS_INSTALL_DIR}" CACHE STRING
|
|
||||||
"Path to install LLVM utilities (enabled by LLVM_INSTALL_UTILS=ON) (defaults to LLVM_TOOLS_INSTALL_DIR)")
|
|
||||||
mark_as_advanced(LLVM_UTILS_INSTALL_DIR)
|
|
||||||
|
|
||||||
+set(LLVM_INSTALL_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/cmake/llvm" CACHE STRING
|
|
||||||
+ "Path for CMake subdirectory (defaults to lib/cmake/llvm)" )
|
|
||||||
+
|
|
||||||
# They are used as destination of target generators.
|
|
||||||
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})
|
|
||||||
@@ -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_BINDINGS "Build bindings." ON)
|
|
||||||
|
|
||||||
-set(LLVM_INSTALL_DOXYGEN_HTML_DIR "share/doc/llvm/doxygen-html"
|
|
||||||
+set(LLVM_INSTALL_DOXYGEN_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/${project}/doxygen-html"
|
|
||||||
CACHE STRING "Doxygen-generated HTML documentation install directory")
|
|
||||||
-set(LLVM_INSTALL_OCAMLDOC_HTML_DIR "share/doc/llvm/ocaml-html"
|
|
||||||
+set(LLVM_INSTALL_OCAMLDOC_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/${project}/ocaml-html"
|
|
||||||
CACHE STRING "OCamldoc-generated HTML documentation install directory")
|
|
||||||
|
|
||||||
option (LLVM_BUILD_EXTERNAL_COMPILER_RT
|
|
||||||
@@ -1048,7 +1054,7 @@ endif()
|
|
||||||
|
|
||||||
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
|
|
||||||
install(DIRECTORY include/llvm include/llvm-c
|
|
||||||
- DESTINATION include
|
|
||||||
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
|
||||||
COMPONENT llvm-headers
|
|
||||||
FILES_MATCHING
|
|
||||||
PATTERN "*.def"
|
|
||||||
@@ -1059,7 +1065,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
|
|
||||||
)
|
|
||||||
|
|
||||||
install(DIRECTORY ${LLVM_INCLUDE_DIR}/llvm ${LLVM_INCLUDE_DIR}/llvm-c
|
|
||||||
- DESTINATION include
|
|
||||||
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
|
||||||
COMPONENT llvm-headers
|
|
||||||
FILES_MATCHING
|
|
||||||
PATTERN "*.def"
|
|
||||||
@@ -1073,13 +1079,13 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
|
|
||||||
|
|
||||||
if (LLVM_INSTALL_MODULEMAPS)
|
|
||||||
install(DIRECTORY include/llvm include/llvm-c
|
|
||||||
- DESTINATION include
|
|
||||||
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
|
||||||
COMPONENT llvm-headers
|
|
||||||
FILES_MATCHING
|
|
||||||
PATTERN "module.modulemap"
|
|
||||||
)
|
|
||||||
install(FILES include/llvm/module.install.modulemap
|
|
||||||
- DESTINATION include/llvm
|
|
||||||
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/llvm
|
|
||||||
COMPONENT llvm-headers
|
|
||||||
RENAME "module.extern.modulemap"
|
|
||||||
)
|
|
||||||
diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake
|
|
||||||
index 9c2b85374307..5531ceeb2eeb 100644
|
|
||||||
--- a/cmake/modules/AddLLVM.cmake
|
|
||||||
+++ b/cmake/modules/AddLLVM.cmake
|
|
||||||
@@ -818,9 +818,9 @@ macro(add_llvm_library name)
|
|
||||||
get_target_export_arg(${name} LLVM export_to_llvmexports ${umbrella})
|
|
||||||
install(TARGETS ${name}
|
|
||||||
${export_to_llvmexports}
|
|
||||||
- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name}
|
|
||||||
- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name}
|
|
||||||
- RUNTIME DESTINATION bin COMPONENT ${name})
|
|
||||||
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} COMPONENT ${name}
|
|
||||||
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} COMPONENT ${name}
|
|
||||||
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${name})
|
|
||||||
|
|
||||||
if (NOT LLVM_ENABLE_IDE)
|
|
||||||
add_llvm_install_targets(install-${name}
|
|
||||||
@@ -1036,7 +1036,7 @@ function(process_llvm_pass_plugins)
|
|
||||||
"set(LLVM_STATIC_EXTENSIONS ${LLVM_STATIC_EXTENSIONS})")
|
|
||||||
install(FILES
|
|
||||||
${llvm_cmake_builddir}/LLVMConfigExtensions.cmake
|
|
||||||
- DESTINATION ${LLVM_INSTALL_PACKAGE_DIR}
|
|
||||||
+ DESTINATION ${LLVM_INSTALL_CMAKE_DIR}
|
|
||||||
COMPONENT cmake-exports)
|
|
||||||
|
|
||||||
set(ExtensionDef "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def")
|
|
||||||
@@ -1250,7 +1250,7 @@ macro(add_llvm_example name)
|
|
||||||
endif()
|
|
||||||
add_llvm_executable(${name} ${ARGN})
|
|
||||||
if( LLVM_BUILD_EXAMPLES )
|
|
||||||
- install(TARGETS ${name} RUNTIME DESTINATION examples)
|
|
||||||
+ install(TARGETS ${name} RUNTIME DESTINATION ${CMAKE_INSTALL_DOCDIR}/examples)
|
|
||||||
endif()
|
|
||||||
set_target_properties(${name} PROPERTIES FOLDER "Examples")
|
|
||||||
endmacro(add_llvm_example name)
|
|
||||||
@@ -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_dest ${CMAKE_${type}_LIBRARY_PREFIX}${dest}${CMAKE_${type}_LIBRARY_SUFFIX})
|
|
||||||
|
|
||||||
- set(output_dir lib${LLVM_LIBDIR_SUFFIX})
|
|
||||||
+ set(output_dir ${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX})
|
|
||||||
if(WIN32 AND "${type}" STREQUAL "SHARED")
|
|
||||||
set(output_dir bin)
|
|
||||||
endif()
|
|
||||||
@@ -1879,7 +1879,7 @@ function(llvm_install_library_symlink name dest type)
|
|
||||||
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
-function(llvm_install_symlink name dest)
|
|
||||||
+function(llvm_install_symlink name dest output_dir)
|
|
||||||
cmake_parse_arguments(ARG "ALWAYS_GENERATE" "COMPONENT" "" ${ARGN})
|
|
||||||
foreach(path ${CMAKE_MODULE_PATH})
|
|
||||||
if(EXISTS ${path}/LLVMInstallSymlink.cmake)
|
|
||||||
@@ -1902,7 +1902,7 @@ function(llvm_install_symlink name dest)
|
|
||||||
set(full_dest ${dest}${CMAKE_EXECUTABLE_SUFFIX})
|
|
||||||
|
|
||||||
install(SCRIPT ${INSTALL_SYMLINK}
|
|
||||||
- CODE "install_symlink(${full_name} ${full_dest} ${LLVM_TOOLS_INSTALL_DIR})"
|
|
||||||
+ CODE "install_symlink(${full_name} ${full_dest} ${output_dir})"
|
|
||||||
COMPONENT ${component})
|
|
||||||
|
|
||||||
if (NOT LLVM_ENABLE_IDE AND NOT ARG_ALWAYS_GENERATE)
|
|
||||||
@@ -1985,7 +1985,8 @@ function(add_llvm_tool_symlink link_name target)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if ((TOOL_IS_TOOLCHAIN OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY) AND LLVM_BUILD_TOOLS)
|
|
||||||
- llvm_install_symlink(${link_name} ${target})
|
|
||||||
+ GNUInstallDirs_get_absolute_install_dir(output_dir LLVM_TOOLS_INSTALL_DIR)
|
|
||||||
+ llvm_install_symlink(${link_name} ${target} ${output_dir})
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
endfunction()
|
|
||||||
@@ -2114,9 +2115,9 @@ function(llvm_setup_rpath name)
|
|
||||||
# Since BUILD_SHARED_LIBS is only recommended for use by developers,
|
|
||||||
# hardcode the rpath to build/install lib dir first in this mode.
|
|
||||||
# FIXME: update this when there is better solution.
|
|
||||||
- set(_install_rpath "${LLVM_LIBRARY_OUTPUT_INTDIR}" "${CMAKE_INSTALL_PREFIX}/lib${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)
|
|
||||||
- set(_install_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir})
|
|
||||||
+ set(_install_rpath "\$ORIGIN/../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir})
|
|
||||||
if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
|
|
||||||
set_property(TARGET ${name} APPEND_STRING PROPERTY
|
|
||||||
LINK_FLAGS " -Wl,-z,origin ")
|
|
||||||
diff --git a/cmake/modules/AddOCaml.cmake b/cmake/modules/AddOCaml.cmake
|
|
||||||
index 554046b20edf..4d1ad980641e 100644
|
|
||||||
--- a/cmake/modules/AddOCaml.cmake
|
|
||||||
+++ b/cmake/modules/AddOCaml.cmake
|
|
||||||
@@ -144,9 +144,9 @@ function(add_ocaml_library name)
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
if( APPLE )
|
|
||||||
- set(ocaml_rpath "@executable_path/../../../lib${LLVM_LIBDIR_SUFFIX}")
|
|
||||||
+ set(ocaml_rpath "@executable_path/../../../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}")
|
|
||||||
elseif( UNIX )
|
|
||||||
- set(ocaml_rpath "\\$ORIGIN/../../../lib${LLVM_LIBDIR_SUFFIX}")
|
|
||||||
+ set(ocaml_rpath "\\$ORIGIN/../../../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}")
|
|
||||||
endif()
|
|
||||||
list(APPEND ocaml_flags "-ldopt" "-Wl,-rpath,${ocaml_rpath}")
|
|
||||||
|
|
||||||
diff --git a/cmake/modules/AddSphinxTarget.cmake b/cmake/modules/AddSphinxTarget.cmake
|
|
||||||
index e80c3b5c1cac..482f6d715ef5 100644
|
|
||||||
--- a/cmake/modules/AddSphinxTarget.cmake
|
|
||||||
+++ b/cmake/modules/AddSphinxTarget.cmake
|
|
||||||
@@ -90,7 +90,7 @@ function (add_sphinx_target builder project)
|
|
||||||
endif()
|
|
||||||
elseif (builder STREQUAL html)
|
|
||||||
string(TOUPPER "${project}" project_upper)
|
|
||||||
- set(${project_upper}_INSTALL_SPHINX_HTML_DIR "share/doc/${project}/html"
|
|
||||||
+ set(${project_upper}_INSTALL_SPHINX_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/${project}/html"
|
|
||||||
CACHE STRING "HTML documentation install directory for ${project}")
|
|
||||||
|
|
||||||
# '/.' indicates: copy the contents of the directory directly into
|
|
||||||
diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt
|
|
||||||
index 51b6a4fdc284..4adc2acfc074 100644
|
|
||||||
--- a/cmake/modules/CMakeLists.txt
|
|
||||||
+++ b/cmake/modules/CMakeLists.txt
|
|
||||||
@@ -1,6 +1,6 @@
|
|
||||||
include(LLVMDistributionSupport)
|
|
||||||
|
|
||||||
-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_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}")
|
|
||||||
|
|
||||||
# First for users who use an installed LLVM, create the LLVMExports.cmake file.
|
|
||||||
@@ -109,13 +109,13 @@ foreach(p ${_count})
|
|
||||||
set(LLVM_CONFIG_CODE "${LLVM_CONFIG_CODE}
|
|
||||||
get_filename_component(LLVM_INSTALL_PREFIX \"\${LLVM_INSTALL_PREFIX}\" PATH)")
|
|
||||||
endforeach(p)
|
|
||||||
-set(LLVM_CONFIG_INCLUDE_DIRS "\${LLVM_INSTALL_PREFIX}/include")
|
|
||||||
+set(LLVM_CONFIG_INCLUDE_DIRS "\${LLVM_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}")
|
|
||||||
set(LLVM_CONFIG_INCLUDE_DIR "${LLVM_CONFIG_INCLUDE_DIRS}")
|
|
||||||
set(LLVM_CONFIG_MAIN_INCLUDE_DIR "${LLVM_CONFIG_INCLUDE_DIRS}")
|
|
||||||
-set(LLVM_CONFIG_LIBRARY_DIRS "\${LLVM_INSTALL_PREFIX}/lib\${LLVM_LIBDIR_SUFFIX}")
|
|
||||||
+set(LLVM_CONFIG_LIBRARY_DIRS "\${LLVM_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}\${LLVM_LIBDIR_SUFFIX}")
|
|
||||||
set(LLVM_CONFIG_CMAKE_DIR "\${LLVM_INSTALL_PREFIX}/${LLVM_INSTALL_PACKAGE_DIR}")
|
|
||||||
set(LLVM_CONFIG_BINARY_DIR "\${LLVM_INSTALL_PREFIX}")
|
|
||||||
-set(LLVM_CONFIG_TOOLS_BINARY_DIR "\${LLVM_INSTALL_PREFIX}/bin")
|
|
||||||
+set(LLVM_CONFIG_TOOLS_BINARY_DIR "\${LLVM_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}")
|
|
||||||
|
|
||||||
# Generate a default location for lit
|
|
||||||
if (LLVM_INSTALL_UTILS AND LLVM_BUILD_UTILS)
|
|
||||||
diff --git a/cmake/modules/LLVMInstallSymlink.cmake b/cmake/modules/LLVMInstallSymlink.cmake
|
|
||||||
index 3e6a2c9a2648..52e14d955c60 100644
|
|
||||||
--- a/cmake/modules/LLVMInstallSymlink.cmake
|
|
||||||
+++ b/cmake/modules/LLVMInstallSymlink.cmake
|
|
||||||
@@ -4,7 +4,7 @@
|
|
||||||
|
|
||||||
function(install_symlink name target outdir)
|
|
||||||
set(DESTDIR $ENV{DESTDIR})
|
|
||||||
- set(bindir "${DESTDIR}${CMAKE_INSTALL_PREFIX}/${outdir}/")
|
|
||||||
+ set(bindir "${DESTDIR}${outdir}/")
|
|
||||||
|
|
||||||
message(STATUS "Creating ${name}")
|
|
||||||
|
|
||||||
diff --git a/docs/CMake.rst b/docs/CMake.rst
|
|
||||||
index f1ac2c7d4934..c6e1469b5e13 100644
|
|
||||||
--- a/docs/CMake.rst
|
|
||||||
+++ b/docs/CMake.rst
|
|
||||||
@@ -202,7 +202,7 @@ CMake manual, or execute ``cmake --help-variable VARIABLE_NAME``.
|
|
||||||
**LLVM_LIBDIR_SUFFIX**:STRING
|
|
||||||
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``
|
|
||||||
- to install libraries to ``/usr/lib64``.
|
|
||||||
+ to install libraries to ``/usr/lib64``. See also ``CMAKE_INSTALL_LIBDIR``.
|
|
||||||
|
|
||||||
Rarely-used CMake variables
|
|
||||||
---------------------------
|
|
||||||
@@ -551,8 +551,8 @@ LLVM-specific variables
|
|
||||||
|
|
||||||
**LLVM_INSTALL_DOXYGEN_HTML_DIR**:STRING
|
|
||||||
The path to install Doxygen-generated HTML documentation to. This path can
|
|
||||||
- either be absolute or relative to the CMAKE_INSTALL_PREFIX. Defaults to
|
|
||||||
- `share/doc/llvm/doxygen-html`.
|
|
||||||
+ either be absolute or relative to the ``CMAKE_INSTALL_PREFIX``. Defaults to
|
|
||||||
+ `${CMAKE_INSTALL_DOCDIR}/${project}/doxygen-html`.
|
|
||||||
|
|
||||||
**LLVM_LINK_LLVM_DYLIB**:BOOL
|
|
||||||
If enabled, tools will be linked with the libLLVM shared library. Defaults
|
|
||||||
@@ -792,9 +792,11 @@ the ``cmake`` command or by setting it directly in ``ccmake`` or ``cmake-gui``).
|
|
||||||
|
|
||||||
This file is available in two different locations.
|
|
||||||
|
|
||||||
-* ``<INSTALL_PREFIX>/lib/cmake/llvm/LLVMConfig.cmake`` where
|
|
||||||
- ``<INSTALL_PREFIX>`` is the install prefix of an installed version of LLVM.
|
|
||||||
- On Linux typically this is ``/usr/lib/cmake/llvm/LLVMConfig.cmake``.
|
|
||||||
+* ``<LLVM_INSTALL_PACKAGE_DIR>LLVMConfig.cmake`` where
|
|
||||||
+ ``<LLVM_INSTALL_PACKAGE_DIR>`` is the location where LLVM CMake modules are
|
|
||||||
+ installed as part of an installed version of LLVM. This is typically
|
|
||||||
+ ``cmake/llvm/`` within the lib directory. On Linux, this is typically
|
|
||||||
+ ``/usr/lib/cmake/llvm/LLVMConfig.cmake``.
|
|
||||||
|
|
||||||
* ``<LLVM_BUILD_ROOT>/lib/cmake/llvm/LLVMConfig.cmake`` where
|
|
||||||
``<LLVM_BUILD_ROOT>`` is the root of the LLVM build tree. **Note: this is only
|
|
||||||
diff --git a/examples/Bye/CMakeLists.txt b/examples/Bye/CMakeLists.txt
|
|
||||||
index bb96edb4b4bf..678c22fb43c8 100644
|
|
||||||
--- a/examples/Bye/CMakeLists.txt
|
|
||||||
+++ b/examples/Bye/CMakeLists.txt
|
|
||||||
@@ -14,6 +14,6 @@ if (NOT WIN32)
|
|
||||||
BUILDTREE_ONLY
|
|
||||||
)
|
|
||||||
|
|
||||||
- install(TARGETS ${name} RUNTIME DESTINATION examples)
|
|
||||||
+ install(TARGETS ${name} RUNTIME DESTINATION ${CMAKE_INSTALL_DOCDIR}/examples)
|
|
||||||
set_target_properties(${name} PROPERTIES FOLDER "Examples")
|
|
||||||
endif()
|
|
||||||
diff --git a/include/llvm/CMakeLists.txt b/include/llvm/CMakeLists.txt
|
|
||||||
index b46319f24fc8..2feabd1954e4 100644
|
|
||||||
--- a/include/llvm/CMakeLists.txt
|
|
||||||
+++ b/include/llvm/CMakeLists.txt
|
|
||||||
@@ -5,5 +5,5 @@ add_subdirectory(Frontend)
|
|
||||||
# If we're doing an out-of-tree build, copy a module map for generated
|
|
||||||
# header files into the build area.
|
|
||||||
if (NOT "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
|
|
||||||
- configure_file(module.modulemap.build module.modulemap COPYONLY)
|
|
||||||
+ configure_file(module.modulemap.build ${LLVM_INCLUDE_DIR}/module.modulemap COPYONLY)
|
|
||||||
endif (NOT "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
|
|
||||||
diff --git a/tools/llvm-config/BuildVariables.inc.in b/tools/llvm-config/BuildVariables.inc.in
|
|
||||||
index ebe5b73a5c65..70c497be12f5 100644
|
|
||||||
--- a/tools/llvm-config/BuildVariables.inc.in
|
|
||||||
+++ b/tools/llvm-config/BuildVariables.inc.in
|
|
||||||
@@ -23,6 +23,10 @@
|
|
||||||
#define LLVM_CXXFLAGS "@LLVM_CXXFLAGS@"
|
|
||||||
#define LLVM_BUILDMODE "@LLVM_BUILDMODE@"
|
|
||||||
#define LLVM_LIBDIR_SUFFIX "@LLVM_LIBDIR_SUFFIX@"
|
|
||||||
+#define LLVM_INSTALL_BINDIR "@CMAKE_INSTALL_BINDIR@"
|
|
||||||
+#define LLVM_INSTALL_LIBDIR "@CMAKE_INSTALL_LIBDIR@"
|
|
||||||
+#define LLVM_INSTALL_INCLUDEDIR "@CMAKE_INSTALL_INCLUDEDIR@"
|
|
||||||
+#define LLVM_INSTALL_CMAKEDIR "@LLVM_INSTALL_CMAKE_DIR@"
|
|
||||||
#define LLVM_TARGETS_BUILT "@LLVM_TARGETS_BUILT@"
|
|
||||||
#define LLVM_SYSTEM_LIBS "@LLVM_SYSTEM_LIBS@"
|
|
||||||
#define LLVM_BUILD_SYSTEM "@LLVM_BUILD_SYSTEM@"
|
|
||||||
diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp
|
|
||||||
index 1a2f04552d13..44fa7d3eec6b 100644
|
|
||||||
--- a/tools/llvm-config/llvm-config.cpp
|
|
||||||
+++ b/tools/llvm-config/llvm-config.cpp
|
|
||||||
@@ -357,12 +357,26 @@ int main(int argc, char **argv) {
|
|
||||||
("-I" + ActiveIncludeDir + " " + "-I" + ActiveObjRoot + "/include");
|
|
||||||
} else {
|
|
||||||
ActivePrefix = CurrentExecPrefix;
|
|
||||||
- ActiveIncludeDir = ActivePrefix + "/include";
|
|
||||||
- SmallString<256> path(StringRef(LLVM_TOOLS_INSTALL_DIR));
|
|
||||||
- sys::fs::make_absolute(ActivePrefix, path);
|
|
||||||
- ActiveBinDir = std::string(path.str());
|
|
||||||
- ActiveLibDir = ActivePrefix + "/lib" + LLVM_LIBDIR_SUFFIX;
|
|
||||||
- ActiveCMakeDir = ActiveLibDir + "/cmake/llvm";
|
|
||||||
+ {
|
|
||||||
+ SmallString<256> path(StringRef(LLVM_INSTALL_INCLUDEDIR));
|
|
||||||
+ sys::fs::make_absolute(ActivePrefix, path);
|
|
||||||
+ ActiveIncludeDir = std::string(path.str());
|
|
||||||
+ }
|
|
||||||
+ {
|
|
||||||
+ SmallString<256> path(StringRef(LLVM_INSTALL_BINDIR));
|
|
||||||
+ sys::fs::make_absolute(ActivePrefix, path);
|
|
||||||
+ ActiveBinDir = std::string(path.str());
|
|
||||||
+ }
|
|
||||||
+ {
|
|
||||||
+ SmallString<256> path(StringRef(LLVM_INSTALL_LIBDIR LLVM_LIBDIR_SUFFIX));
|
|
||||||
+ sys::fs::make_absolute(ActivePrefix, path);
|
|
||||||
+ ActiveLibDir = std::string(path.str());
|
|
||||||
+ }
|
|
||||||
+ {
|
|
||||||
+ SmallString<256> path(StringRef(LLVM_INSTALL_CMAKEDIR));
|
|
||||||
+ sys::fs::make_absolute(ActivePrefix, path);
|
|
||||||
+ ActiveCMakeDir = std::string(path.str());
|
|
||||||
+ }
|
|
||||||
ActiveIncludeOption = "-I" + ActiveIncludeDir;
|
|
||||||
}
|
|
||||||
|
|
||||||
diff --git a/tools/lto/CMakeLists.txt b/tools/lto/CMakeLists.txt
|
|
||||||
index 0af29ad762c5..37b99b83e35c 100644
|
|
||||||
--- a/tools/lto/CMakeLists.txt
|
|
||||||
+++ b/tools/lto/CMakeLists.txt
|
|
||||||
@@ -33,7 +33,7 @@ add_llvm_library(${LTO_LIBRARY_NAME} ${LTO_LIBRARY_TYPE} INSTALL_WITH_TOOLCHAIN
|
|
||||||
${SOURCES} DEPENDS intrinsics_gen)
|
|
||||||
|
|
||||||
install(FILES ${LLVM_MAIN_INCLUDE_DIR}/llvm-c/lto.h
|
|
||||||
- DESTINATION include/llvm-c
|
|
||||||
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/llvm-c
|
|
||||||
COMPONENT LTO)
|
|
||||||
|
|
||||||
if (APPLE)
|
|
||||||
diff --git a/tools/opt-viewer/CMakeLists.txt b/tools/opt-viewer/CMakeLists.txt
|
|
||||||
index ead73ec13a8f..250362021f17 100644
|
|
||||||
--- a/tools/opt-viewer/CMakeLists.txt
|
|
||||||
+++ b/tools/opt-viewer/CMakeLists.txt
|
|
||||||
@@ -8,7 +8,7 @@ set (files
|
|
||||||
|
|
||||||
foreach (file ${files})
|
|
||||||
install(PROGRAMS ${file}
|
|
||||||
- DESTINATION share/opt-viewer
|
|
||||||
+ DESTINATION ${CMAKE_INSTALL_DATADIR}/opt-viewer
|
|
||||||
COMPONENT opt-viewer)
|
|
||||||
endforeach (file)
|
|
||||||
|
|
||||||
diff --git a/tools/remarks-shlib/CMakeLists.txt b/tools/remarks-shlib/CMakeLists.txt
|
|
||||||
index 865436247270..ce1daa62f6ab 100644
|
|
||||||
--- a/tools/remarks-shlib/CMakeLists.txt
|
|
||||||
+++ b/tools/remarks-shlib/CMakeLists.txt
|
|
||||||
@@ -19,7 +19,7 @@ if(LLVM_ENABLE_PIC)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
install(FILES ${LLVM_MAIN_INCLUDE_DIR}/llvm-c/Remarks.h
|
|
||||||
- DESTINATION include/llvm-c
|
|
||||||
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/llvm-c
|
|
||||||
COMPONENT Remarks)
|
|
||||||
|
|
||||||
if (APPLE)
|
|
56
nac3.svg
Normal file
56
nac3.svg
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<svg
|
||||||
|
id="a"
|
||||||
|
width="128"
|
||||||
|
height="128"
|
||||||
|
viewBox="0 0 95.99999 95.99999"
|
||||||
|
version="1.1"
|
||||||
|
sodipodi:docname="nac3.svg"
|
||||||
|
inkscape:version="1.1.1 (3bf5ae0d25, 2021-09-20)"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg">
|
||||||
|
<defs
|
||||||
|
id="defs11" />
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="namedview9"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1.0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:pageopacity="0.0"
|
||||||
|
inkscape:pagecheckerboard="0"
|
||||||
|
inkscape:document-units="mm"
|
||||||
|
showgrid="false"
|
||||||
|
units="px"
|
||||||
|
width="128px"
|
||||||
|
inkscape:zoom="5.9448568"
|
||||||
|
inkscape:cx="60.472441"
|
||||||
|
inkscape:cy="60.556547"
|
||||||
|
inkscape:window-width="2560"
|
||||||
|
inkscape:window-height="1371"
|
||||||
|
inkscape:window-x="0"
|
||||||
|
inkscape:window-y="32"
|
||||||
|
inkscape:window-maximized="1"
|
||||||
|
inkscape:current-layer="a" />
|
||||||
|
<rect
|
||||||
|
x="40.072601"
|
||||||
|
y="-26.776209"
|
||||||
|
width="55.668747"
|
||||||
|
height="55.668747"
|
||||||
|
transform="matrix(0.71803815,0.69600374,-0.71803815,0.69600374,0,0)"
|
||||||
|
style="fill:#be211e;stroke:#000000;stroke-width:4.37375px;stroke-linecap:round;stroke-linejoin:round"
|
||||||
|
id="rect2" />
|
||||||
|
<line
|
||||||
|
x1="38.00692"
|
||||||
|
y1="63.457153"
|
||||||
|
x2="57.993061"
|
||||||
|
y2="63.457153"
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:4.37269px;stroke-linecap:round;stroke-linejoin:round"
|
||||||
|
id="line4" />
|
||||||
|
<path
|
||||||
|
d="m 48.007301,57.843329 c -1.943097,0 -3.877522,-0.41727 -5.686157,-1.246007 -3.218257,-1.474616 -5.650382,-4.075418 -6.849639,-7.323671 -2.065624,-5.588921 -1.192751,-10.226647 2.575258,-13.827 0.611554,-0.584909 1.518048,-0.773041 2.323689,-0.488206 0.80673,0.286405 1.369495,0.998486 1.447563,1.827234 0.237469,2.549302 2.439719,5.917376 4.28414,6.55273 0.396859,0.13506 0.820953,-0.05859 1.097084,-0.35222 0.339254,-0.360754 0.451065,-0.961893 -1.013597,-3.191372 -2.089851,-3.181137 -4.638728,-8.754903 -0.262407,-15.069853 0.494457,-0.713491 1.384673,-1.068907 2.256469,-0.909156 0.871795,0.161332 1.583757,0.806404 1.752251,1.651189 0.716448,3.591862 2.962357,6.151755 5.199306,8.023138 1.935503,1.61861 4.344688,3.867387 5.435687,7.096643 2.283183,6.758017 -1.202511,14.114988 -8.060822,16.494025 -1.467083,0.509226 -2.98513,0.762536 -4.498836,0.762536 z M 39.358865,40.002192 c -0.304711,0.696206 -0.541636,2.080524 -0.56865,2.237454 -0.330316,1.918771 0.168305,3.803963 0.846157,5.539951 0.856828,2.19436 2.437543,3.942467 4.583411,4.925713 2.143691,0.981675 4.554131,1.097816 6.789992,0.322666 4.571485,-1.586549 6.977584,-6.532238 5.363036,-11.02597 v -5.27e-4 C 55.455481,39.447968 54.023463,38.162043 52.221335,36.65432 50.876945,35.529534 49.409662,33.987726 48.417983,32.135555 48.01343,31.37996 47.79547,30.34303 47.76669,29.413263 c -0.187481,0.669514 -0.212441,2.325923 -0.150396,2.93691 0.179209,1.764456 1.333476,3.644546 2.340611,5.171243 1.311568,1.988179 2.72058,6.037272 0.459681,8.367985 -1.54192,1.58953 -4.038511,2.052034 -5.839973,1.38492 -2.398314,-0.888147 -3.942744,-2.690627 -4.941118,-4.768029 -0.121194,-0.25217 -0.532464,-1.174187 -0.276619,-2.5041 z"
|
||||||
|
id="path6"
|
||||||
|
style="stroke-width:1.09317" />
|
||||||
|
</svg>
|
After Width: | Height: | Size: 3.3 KiB |
@ -16,9 +16,9 @@ nac3parser = { path = "../nac3parser" }
|
|||||||
nac3core = { path = "../nac3core" }
|
nac3core = { path = "../nac3core" }
|
||||||
|
|
||||||
[dependencies.inkwell]
|
[dependencies.inkwell]
|
||||||
version = "0.1.0-beta.4"
|
git = "https://github.com/TheDan64/inkwell.git"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["llvm13-0", "target-x86", "target-arm", "target-riscv", "no-libffi-linking"]
|
features = ["llvm14-0", "target-x86", "target-arm", "target-riscv", "no-libffi-linking"]
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
init-llvm-profile = []
|
init-llvm-profile = []
|
||||||
|
@ -1,10 +1,4 @@
|
|||||||
from min_artiq import *
|
from min_artiq import *
|
||||||
from numpy import int32, int64
|
|
||||||
|
|
||||||
|
|
||||||
@extern
|
|
||||||
def output_int(x: int32):
|
|
||||||
...
|
|
||||||
|
|
||||||
|
|
||||||
@nac3
|
@nac3
|
||||||
|
@ -5,6 +5,7 @@ class EmbeddingMap:
|
|||||||
self.string_map = {}
|
self.string_map = {}
|
||||||
self.string_reverse_map = {}
|
self.string_reverse_map = {}
|
||||||
self.function_map = {}
|
self.function_map = {}
|
||||||
|
self.attributes_writeback = []
|
||||||
|
|
||||||
# preallocate exception names
|
# preallocate exception names
|
||||||
self.preallocate_runtime_exception_names(["RuntimeError",
|
self.preallocate_runtime_exception_names(["RuntimeError",
|
||||||
@ -16,7 +17,8 @@ class EmbeddingMap:
|
|||||||
"CacheError",
|
"CacheError",
|
||||||
"SPIError",
|
"SPIError",
|
||||||
"0:ZeroDivisionError",
|
"0:ZeroDivisionError",
|
||||||
"0:IndexError"])
|
"0:IndexError",
|
||||||
|
"0:UnwrapNoneError"])
|
||||||
|
|
||||||
def preallocate_runtime_exception_names(self, names):
|
def preallocate_runtime_exception_names(self, names):
|
||||||
for i, name in enumerate(names):
|
for i, name in enumerate(names):
|
||||||
|
@ -11,7 +11,7 @@ from embedding_map import EmbeddingMap
|
|||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"Kernel", "KernelInvariant", "virtual",
|
"Kernel", "KernelInvariant", "virtual",
|
||||||
"Option", "Some", "none",
|
"Option", "Some", "none", "UnwrapNoneError",
|
||||||
"round64", "floor64", "ceil64",
|
"round64", "floor64", "ceil64",
|
||||||
"extern", "kernel", "portable", "nac3",
|
"extern", "kernel", "portable", "nac3",
|
||||||
"rpc", "ms", "us", "ns",
|
"rpc", "ms", "us", "ns",
|
||||||
@ -47,7 +47,7 @@ class Option(Generic[T]):
|
|||||||
|
|
||||||
def unwrap(self):
|
def unwrap(self):
|
||||||
if self.is_none():
|
if self.is_none():
|
||||||
raise ValueError("unwrap on none")
|
raise UnwrapNoneError()
|
||||||
return self._nac3_option
|
return self._nac3_option
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
@ -274,5 +274,10 @@ class KernelContextManager:
|
|||||||
def __exit__(self):
|
def __exit__(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@nac3
|
||||||
|
class UnwrapNoneError(Exception):
|
||||||
|
"""raised when unwrapping a none value"""
|
||||||
|
artiq_builtin = True
|
||||||
|
|
||||||
parallel = KernelContextManager()
|
parallel = KernelContextManager()
|
||||||
sequential = KernelContextManager()
|
sequential = KernelContextManager()
|
||||||
|
@ -6,7 +6,7 @@ use nac3core::{
|
|||||||
},
|
},
|
||||||
symbol_resolver::ValueEnum,
|
symbol_resolver::ValueEnum,
|
||||||
toplevel::{DefinitionId, GenCall},
|
toplevel::{DefinitionId, GenCall},
|
||||||
typecheck::typedef::{FunSignature, Type},
|
typecheck::typedef::{FunSignature, FuncArg, Type, TypeEnum}
|
||||||
};
|
};
|
||||||
|
|
||||||
use nac3parser::ast::{Expr, ExprKind, Located, Stmt, StmtKind, StrRef};
|
use nac3parser::ast::{Expr, ExprKind, Located, Stmt, StmtKind, StrRef};
|
||||||
@ -15,7 +15,9 @@ use inkwell::{
|
|||||||
context::Context, module::Linkage, types::IntType, values::BasicValueEnum, AddressSpace,
|
context::Context, module::Linkage, types::IntType, values::BasicValueEnum, AddressSpace,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::timeline::TimeFns;
|
use pyo3::{PyObject, PyResult, Python, types::{PyDict, PyList}};
|
||||||
|
|
||||||
|
use crate::{symbol_resolver::InnerResolver, timeline::TimeFns};
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
collections::hash_map::DefaultHasher,
|
collections::hash_map::DefaultHasher,
|
||||||
@ -66,7 +68,7 @@ impl<'b> CodeGenerator for ArtiqCodeGenerator<'b> {
|
|||||||
) -> Result<Option<BasicValueEnum<'ctx>>, String> {
|
) -> Result<Option<BasicValueEnum<'ctx>>, String> {
|
||||||
let result = gen_call(self, ctx, obj, fun, params)?;
|
let result = gen_call(self, ctx, obj, fun, params)?;
|
||||||
if let Some(end) = self.end.clone() {
|
if let Some(end) = self.end.clone() {
|
||||||
let old_end = self.gen_expr(ctx, &end)?.unwrap().to_basic_value_enum(ctx, self)?;
|
let old_end = self.gen_expr(ctx, &end)?.unwrap().to_basic_value_enum(ctx, self, end.custom.unwrap())?;
|
||||||
let now = self.timeline.emit_now_mu(ctx);
|
let now = self.timeline.emit_now_mu(ctx);
|
||||||
let smax = ctx.module.get_function("llvm.smax.i64").unwrap_or_else(|| {
|
let smax = ctx.module.get_function("llvm.smax.i64").unwrap_or_else(|| {
|
||||||
let i64 = ctx.ctx.i64_type();
|
let i64 = ctx.ctx.i64_type();
|
||||||
@ -86,7 +88,7 @@ impl<'b> CodeGenerator for ArtiqCodeGenerator<'b> {
|
|||||||
ctx.builder.build_store(end_store, max);
|
ctx.builder.build_store(end_store, max);
|
||||||
}
|
}
|
||||||
if let Some(start) = self.start.clone() {
|
if let Some(start) = self.start.clone() {
|
||||||
let start_val = self.gen_expr(ctx, &start)?.unwrap().to_basic_value_enum(ctx, self)?;
|
let start_val = self.gen_expr(ctx, &start)?.unwrap().to_basic_value_enum(ctx, self, start.custom.unwrap())?;
|
||||||
self.timeline.emit_at_mu(ctx, start_val);
|
self.timeline.emit_at_mu(ctx, start_val);
|
||||||
}
|
}
|
||||||
Ok(result)
|
Ok(result)
|
||||||
@ -118,7 +120,7 @@ impl<'b> CodeGenerator for ArtiqCodeGenerator<'b> {
|
|||||||
let old_start = self.start.take();
|
let old_start = self.start.take();
|
||||||
let old_end = self.end.take();
|
let old_end = self.end.take();
|
||||||
let now = if let Some(old_start) = &old_start {
|
let now = if let Some(old_start) = &old_start {
|
||||||
self.gen_expr(ctx, old_start)?.unwrap().to_basic_value_enum(ctx, self)?
|
self.gen_expr(ctx, old_start)?.unwrap().to_basic_value_enum(ctx, self, old_start.custom.unwrap())?
|
||||||
} else {
|
} else {
|
||||||
self.timeline.emit_now_mu(ctx)
|
self.timeline.emit_now_mu(ctx)
|
||||||
};
|
};
|
||||||
@ -172,8 +174,10 @@ impl<'b> CodeGenerator for ArtiqCodeGenerator<'b> {
|
|||||||
};
|
};
|
||||||
// set duration
|
// set duration
|
||||||
let end_expr = self.end.take().unwrap();
|
let end_expr = self.end.take().unwrap();
|
||||||
let end_val =
|
let end_val = self
|
||||||
self.gen_expr(ctx, &end_expr)?.unwrap().to_basic_value_enum(ctx, self)?;
|
.gen_expr(ctx, &end_expr)?
|
||||||
|
.unwrap()
|
||||||
|
.to_basic_value_enum(ctx, self, end_expr.custom.unwrap())?;
|
||||||
|
|
||||||
// inside a sequential block
|
// inside a sequential block
|
||||||
if old_start.is_none() {
|
if old_start.is_none() {
|
||||||
@ -184,7 +188,7 @@ impl<'b> CodeGenerator for ArtiqCodeGenerator<'b> {
|
|||||||
let outer_end_val = self
|
let outer_end_val = self
|
||||||
.gen_expr(ctx, old_end)?
|
.gen_expr(ctx, old_end)?
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_basic_value_enum(ctx, self)?;
|
.to_basic_value_enum(ctx, self, old_end.custom.unwrap())?;
|
||||||
let smax =
|
let smax =
|
||||||
ctx.module.get_function("llvm.smax.i64").unwrap_or_else(|| {
|
ctx.module.get_function("llvm.smax.i64").unwrap_or_else(|| {
|
||||||
let i64 = ctx.ctx.i64_type();
|
let i64 = ctx.ctx.i64_type();
|
||||||
@ -270,8 +274,6 @@ fn gen_rpc_tag<'ctx, 'a>(
|
|||||||
buffer.push(b'l');
|
buffer.push(b'l');
|
||||||
gen_rpc_tag(ctx, *ty, buffer)?;
|
gen_rpc_tag(ctx, *ty, buffer)?;
|
||||||
}
|
}
|
||||||
// we should return an error, this will be fixed after improving error message
|
|
||||||
// as this requires returning an error during codegen
|
|
||||||
_ => return Err(format!("Unsupported type: {:?}", ctx.unifier.stringify(ty))),
|
_ => return Err(format!("Unsupported type: {:?}", ctx.unifier.stringify(ty))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -291,7 +293,7 @@ fn rpc_codegen_callback_fn<'ctx, 'a>(
|
|||||||
let int32 = ctx.ctx.i32_type();
|
let int32 = ctx.ctx.i32_type();
|
||||||
let tag_ptr_type = ctx.ctx.struct_type(&[ptr_type.into(), size_type.into()], false);
|
let tag_ptr_type = ctx.ctx.struct_type(&[ptr_type.into(), size_type.into()], false);
|
||||||
|
|
||||||
let service_id = int32.const_int(fun.1 .0 as u64, false);
|
let service_id = int32.const_int(fun.1.0 as u64, false);
|
||||||
// -- setup rpc tags
|
// -- setup rpc tags
|
||||||
let mut tag = Vec::new();
|
let mut tag = Vec::new();
|
||||||
if obj.is_some() {
|
if obj.is_some() {
|
||||||
@ -361,14 +363,17 @@ fn rpc_codegen_callback_fn<'ctx, 'a>(
|
|||||||
}
|
}
|
||||||
// default value handling
|
// default value handling
|
||||||
for k in keys.into_iter() {
|
for k in keys.into_iter() {
|
||||||
mapping.insert(k.name, ctx.gen_symbol_val(generator, &k.default_value.unwrap()).into());
|
mapping.insert(
|
||||||
|
k.name,
|
||||||
|
ctx.gen_symbol_val(generator, &k.default_value.unwrap(), k.ty).into()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
// reorder the parameters
|
// reorder the parameters
|
||||||
let mut real_params = fun
|
let mut real_params = fun
|
||||||
.0
|
.0
|
||||||
.args
|
.args
|
||||||
.iter()
|
.iter()
|
||||||
.map(|arg| mapping.remove(&arg.name).unwrap().to_basic_value_enum(ctx, generator))
|
.map(|arg| mapping.remove(&arg.name).unwrap().to_basic_value_enum(ctx, generator, arg.ty))
|
||||||
.collect::<Result<Vec<_>, _>>()?;
|
.collect::<Result<Vec<_>, _>>()?;
|
||||||
if let Some(obj) = obj {
|
if let Some(obj) = obj {
|
||||||
if let ValueEnum::Static(obj) = obj.1 {
|
if let ValueEnum::Static(obj) = obj.1 {
|
||||||
@ -486,6 +491,83 @@ fn rpc_codegen_callback_fn<'ctx, 'a>(
|
|||||||
Ok(Some(result))
|
Ok(Some(result))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn attributes_writeback<'ctx, 'a>(
|
||||||
|
ctx: &mut CodeGenContext<'ctx, 'a>,
|
||||||
|
generator: &mut dyn CodeGenerator,
|
||||||
|
inner_resolver: &InnerResolver,
|
||||||
|
host_attributes: PyObject,
|
||||||
|
) -> Result<(), String> {
|
||||||
|
Python::with_gil(|py| -> PyResult<Result<(), String>> {
|
||||||
|
let host_attributes = host_attributes.cast_as::<PyList>(py)?;
|
||||||
|
let top_levels = ctx.top_level.definitions.read();
|
||||||
|
let globals = inner_resolver.global_value_ids.read();
|
||||||
|
let int32 = ctx.ctx.i32_type();
|
||||||
|
let zero = int32.const_zero();
|
||||||
|
let mut values = Vec::new();
|
||||||
|
let mut scratch_buffer = Vec::new();
|
||||||
|
for (_, val) in globals.iter() {
|
||||||
|
let val = val.as_ref(py);
|
||||||
|
let ty = inner_resolver.get_obj_type(py, val, &mut ctx.unifier, &top_levels, &ctx.primitives)?;
|
||||||
|
if let Err(ty) = ty {
|
||||||
|
return Ok(Err(ty))
|
||||||
|
}
|
||||||
|
let ty = ty.unwrap();
|
||||||
|
match &*ctx.unifier.get_ty(ty) {
|
||||||
|
TypeEnum::TObj { fields, obj_id, .. }
|
||||||
|
if *obj_id != ctx.primitives.option.get_obj_id(&ctx.unifier) =>
|
||||||
|
{
|
||||||
|
// we only care about primitive attributes
|
||||||
|
// for non-primitive attributes, they should be in another global
|
||||||
|
let mut attributes = Vec::new();
|
||||||
|
let obj = inner_resolver.get_obj_value(py, val, ctx, generator, ty)?.unwrap();
|
||||||
|
for (name, (field_ty, is_mutable)) in fields.iter() {
|
||||||
|
if !is_mutable {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if gen_rpc_tag(ctx, *field_ty, &mut scratch_buffer).is_ok() {
|
||||||
|
attributes.push(name.to_string());
|
||||||
|
let index = ctx.get_attr_index(ty, *name);
|
||||||
|
values.push((*field_ty, ctx.build_gep_and_load(
|
||||||
|
obj.into_pointer_value(),
|
||||||
|
&[zero, int32.const_int(index as u64, false)])));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !attributes.is_empty() {
|
||||||
|
let pydict = PyDict::new(py);
|
||||||
|
pydict.set_item("obj", val)?;
|
||||||
|
pydict.set_item("fields", attributes)?;
|
||||||
|
host_attributes.append(pydict)?;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
TypeEnum::TList { ty: elem_ty } => {
|
||||||
|
if gen_rpc_tag(ctx, *elem_ty, &mut scratch_buffer).is_ok() {
|
||||||
|
let pydict = PyDict::new(py);
|
||||||
|
pydict.set_item("obj", val)?;
|
||||||
|
host_attributes.append(pydict)?;
|
||||||
|
values.push((ty, inner_resolver.get_obj_value(py, val, ctx, generator, ty)?.unwrap()));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let fun = FunSignature {
|
||||||
|
args: values.iter().enumerate().map(|(i, (ty, _))| FuncArg {
|
||||||
|
name: i.to_string().into(),
|
||||||
|
ty: *ty,
|
||||||
|
default_value: None
|
||||||
|
}).collect(),
|
||||||
|
ret: ctx.primitives.none,
|
||||||
|
vars: Default::default()
|
||||||
|
};
|
||||||
|
let args: Vec<_> = values.into_iter().map(|(_, val)| (None, ValueEnum::Dynamic(val))).collect();
|
||||||
|
if let Err(e) = rpc_codegen_callback_fn(ctx, None, (&fun, DefinitionId(0)), args, generator) {
|
||||||
|
return Ok(Err(e));
|
||||||
|
}
|
||||||
|
Ok(Ok(()))
|
||||||
|
}).unwrap()?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn rpc_codegen_callback() -> Arc<GenCall> {
|
pub fn rpc_codegen_callback() -> Arc<GenCall> {
|
||||||
Arc::new(GenCall::new(Box::new(|ctx, obj, fun, args, generator| {
|
Arc::new(GenCall::new(Box::new(|ctx, obj, fun, args, generator| {
|
||||||
rpc_codegen_callback_fn(ctx, obj, fun, args, generator)
|
rpc_codegen_callback_fn(ctx, obj, fun, args, generator)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
use std::io::Write;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@ -10,6 +11,7 @@ use inkwell::{
|
|||||||
targets::*,
|
targets::*,
|
||||||
OptimizationLevel,
|
OptimizationLevel,
|
||||||
};
|
};
|
||||||
|
use nac3core::codegen::gen_func_impl;
|
||||||
use nac3core::toplevel::builtins::get_exn_constructor;
|
use nac3core::toplevel::builtins::get_exn_constructor;
|
||||||
use nac3core::typecheck::typedef::{TypeEnum, Unifier};
|
use nac3core::typecheck::typedef::{TypeEnum, Unifier};
|
||||||
use nac3parser::{
|
use nac3parser::{
|
||||||
@ -36,6 +38,7 @@ use nac3core::{
|
|||||||
|
|
||||||
use tempfile::{self, TempDir};
|
use tempfile::{self, TempDir};
|
||||||
|
|
||||||
|
use crate::codegen::attributes_writeback;
|
||||||
use crate::{
|
use crate::{
|
||||||
codegen::{rpc_codegen_callback, ArtiqCodeGenerator},
|
codegen::{rpc_codegen_callback, ArtiqCodeGenerator},
|
||||||
symbol_resolver::{InnerResolver, PythonHelper, Resolver, DeferredEvaluationStore},
|
symbol_resolver::{InnerResolver, PythonHelper, Resolver, DeferredEvaluationStore},
|
||||||
@ -63,6 +66,7 @@ pub struct PrimitivePythonId {
|
|||||||
uint32: u64,
|
uint32: u64,
|
||||||
uint64: u64,
|
uint64: u64,
|
||||||
float: u64,
|
float: u64,
|
||||||
|
float64: u64,
|
||||||
bool: u64,
|
bool: u64,
|
||||||
list: u64,
|
list: u64,
|
||||||
tuple: u64,
|
tuple: u64,
|
||||||
@ -326,8 +330,9 @@ impl Nac3 {
|
|||||||
ret: primitive.none,
|
ret: primitive.none,
|
||||||
vars: HashMap::new(),
|
vars: HashMap::new(),
|
||||||
},
|
},
|
||||||
Arc::new(GenCall::new(Box::new(move |ctx, _, _, args, generator| {
|
Arc::new(GenCall::new(Box::new(move |ctx, _, fun, args, generator| {
|
||||||
let arg = args[0].1.clone().to_basic_value_enum(ctx, generator).unwrap();
|
let arg_ty = fun.0.args[0].ty;
|
||||||
|
let arg = args[0].1.clone().to_basic_value_enum(ctx, generator, arg_ty).unwrap();
|
||||||
time_fns.emit_at_mu(ctx, arg);
|
time_fns.emit_at_mu(ctx, arg);
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}))),
|
}))),
|
||||||
@ -343,8 +348,9 @@ impl Nac3 {
|
|||||||
ret: primitive.none,
|
ret: primitive.none,
|
||||||
vars: HashMap::new(),
|
vars: HashMap::new(),
|
||||||
},
|
},
|
||||||
Arc::new(GenCall::new(Box::new(move |ctx, _, _, args, generator| {
|
Arc::new(GenCall::new(Box::new(move |ctx, _, fun, args, generator| {
|
||||||
let arg = args[0].1.clone().to_basic_value_enum(ctx, generator).unwrap();
|
let arg_ty = fun.0.args[0].ty;
|
||||||
|
let arg = args[0].1.clone().to_basic_value_enum(ctx, generator, arg_ty).unwrap();
|
||||||
time_fns.emit_delay_mu(ctx, arg);
|
time_fns.emit_delay_mu(ctx, arg);
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}))),
|
}))),
|
||||||
@ -393,6 +399,7 @@ impl Nac3 {
|
|||||||
uint64: get_attr_id(numpy_mod, "uint64"),
|
uint64: get_attr_id(numpy_mod, "uint64"),
|
||||||
bool: get_attr_id(builtins_mod, "bool"),
|
bool: get_attr_id(builtins_mod, "bool"),
|
||||||
float: get_attr_id(builtins_mod, "float"),
|
float: get_attr_id(builtins_mod, "float"),
|
||||||
|
float64: get_attr_id(numpy_mod, "float64"),
|
||||||
list: get_attr_id(builtins_mod, "list"),
|
list: get_attr_id(builtins_mod, "list"),
|
||||||
tuple: get_attr_id(builtins_mod, "tuple"),
|
tuple: get_attr_id(builtins_mod, "tuple"),
|
||||||
exception: get_attr_id(builtins_mod, "Exception"),
|
exception: get_attr_id(builtins_mod, "Exception"),
|
||||||
@ -476,6 +483,8 @@ impl Nac3 {
|
|||||||
let store_obj = embedding_map.getattr("store_object").unwrap().to_object(py);
|
let store_obj = embedding_map.getattr("store_object").unwrap().to_object(py);
|
||||||
let store_str = embedding_map.getattr("store_str").unwrap().to_object(py);
|
let store_str = embedding_map.getattr("store_str").unwrap().to_object(py);
|
||||||
let store_fun = embedding_map.getattr("store_function").unwrap().to_object(py);
|
let store_fun = embedding_map.getattr("store_function").unwrap().to_object(py);
|
||||||
|
let host_attributes = embedding_map.getattr("attributes_writeback").unwrap().to_object(py);
|
||||||
|
let global_value_ids: Arc<RwLock<HashMap<_, _>>> = Arc::new(RwLock::new(HashMap::new()));
|
||||||
let helper = PythonHelper {
|
let helper = PythonHelper {
|
||||||
id_fn: builtins.getattr("id").unwrap().to_object(py),
|
id_fn: builtins.getattr("id").unwrap().to_object(py),
|
||||||
len_fn: builtins.getattr("len").unwrap().to_object(py),
|
len_fn: builtins.getattr("len").unwrap().to_object(py),
|
||||||
@ -496,13 +505,13 @@ impl Nac3 {
|
|||||||
"KeyError",
|
"KeyError",
|
||||||
"NotImplementedError",
|
"NotImplementedError",
|
||||||
"OverflowError",
|
"OverflowError",
|
||||||
"IOError"
|
"IOError",
|
||||||
|
"UnwrapNoneError",
|
||||||
];
|
];
|
||||||
add_exceptions(&mut composer, &mut builtins_def, &mut builtins_ty, &exception_names);
|
add_exceptions(&mut composer, &mut builtins_def, &mut builtins_ty, &exception_names);
|
||||||
|
|
||||||
let mut module_to_resolver_cache: HashMap<u64, _> = HashMap::new();
|
let mut module_to_resolver_cache: HashMap<u64, _> = HashMap::new();
|
||||||
|
|
||||||
let global_value_ids = Arc::new(RwLock::new(HashSet::<u64>::new()));
|
|
||||||
let mut rpc_ids = vec![];
|
let mut rpc_ids = vec![];
|
||||||
for (stmt, path, module) in self.top_levels.iter() {
|
for (stmt, path, module) in self.top_levels.iter() {
|
||||||
let py_module: &PyAny = module.extract(py)?;
|
let py_module: &PyAny = module.extract(py)?;
|
||||||
@ -615,8 +624,8 @@ impl Nac3 {
|
|||||||
format!("def __modinit__():\n base.{}({})", method_name, arg_names.join(", "))
|
format!("def __modinit__():\n base.{}({})", method_name, arg_names.join(", "))
|
||||||
};
|
};
|
||||||
let mut synthesized =
|
let mut synthesized =
|
||||||
parse_program(&synthesized, "__nac3_synthesized_modinit__".to_string().into()).unwrap();
|
parse_program(&synthesized, "<nac3_synthesized_modinit>".to_string().into()).unwrap();
|
||||||
let resolver = Arc::new(Resolver(Arc::new(InnerResolver {
|
let inner_resolver = Arc::new(InnerResolver {
|
||||||
id_to_type: builtins_ty.clone().into(),
|
id_to_type: builtins_ty.clone().into(),
|
||||||
id_to_def: builtins_def.clone().into(),
|
id_to_def: builtins_def.clone().into(),
|
||||||
pyid_to_def: self.pyid_to_def.clone(),
|
pyid_to_def: self.pyid_to_def.clone(),
|
||||||
@ -633,22 +642,23 @@ impl Nac3 {
|
|||||||
string_store: self.string_store.clone(),
|
string_store: self.string_store.clone(),
|
||||||
exception_ids: self.exception_ids.clone(),
|
exception_ids: self.exception_ids.clone(),
|
||||||
deferred_eval_store: self.deferred_eval_store.clone(),
|
deferred_eval_store: self.deferred_eval_store.clone(),
|
||||||
}))) as Arc<dyn SymbolResolver + Send + Sync>;
|
});
|
||||||
|
let resolver = Arc::new(Resolver(inner_resolver.clone())) as Arc<dyn SymbolResolver + Send + Sync>;
|
||||||
let (_, def_id, _) = composer
|
let (_, def_id, _) = composer
|
||||||
.register_top_level(synthesized.pop().unwrap(), Some(resolver.clone()), "".into())
|
.register_top_level(synthesized.pop().unwrap(), Some(resolver.clone()), "".into())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let signature =
|
let fun_signature =
|
||||||
FunSignature { args: vec![], ret: self.primitive.none, vars: HashMap::new() };
|
FunSignature { args: vec![], ret: self.primitive.none, vars: HashMap::new() };
|
||||||
let mut store = ConcreteTypeStore::new();
|
let mut store = ConcreteTypeStore::new();
|
||||||
let mut cache = HashMap::new();
|
let mut cache = HashMap::new();
|
||||||
let signature =
|
let signature =
|
||||||
store.from_signature(&mut composer.unifier, &self.primitive, &signature, &mut cache);
|
store.from_signature(&mut composer.unifier, &self.primitive, &fun_signature, &mut cache);
|
||||||
let signature = store.add_cty(signature);
|
let signature = store.add_cty(signature);
|
||||||
|
|
||||||
if let Err(e) = composer.start_analysis(true) {
|
if let Err(e) = composer.start_analysis(true) {
|
||||||
// report error of __modinit__ separately
|
// report error of __modinit__ separately
|
||||||
if !e.contains("__nac3_synthesized_modinit__") {
|
if !e.contains("<nac3_synthesized_modinit>") {
|
||||||
return Err(CompileError::new_err(format!(
|
return Err(CompileError::new_err(format!(
|
||||||
"compilation failed\n----------\n{}",
|
"compilation failed\n----------\n{}",
|
||||||
e
|
e
|
||||||
@ -662,7 +672,10 @@ impl Nac3 {
|
|||||||
&mut composer.unifier,
|
&mut composer.unifier,
|
||||||
&self.primitive,
|
&self.primitive,
|
||||||
);
|
);
|
||||||
return Err(CompileError::new_err(msg.unwrap_or(e)));
|
return Err(CompileError::new_err(format!(
|
||||||
|
"compilation failed\n----------\n{}",
|
||||||
|
msg.unwrap_or(e)
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let top_level = Arc::new(composer.make_top_level_context());
|
let top_level = Arc::new(composer.make_top_level_context());
|
||||||
@ -720,12 +733,29 @@ impl Nac3 {
|
|||||||
symbol_name: "__modinit__".to_string(),
|
symbol_name: "__modinit__".to_string(),
|
||||||
body: instance.body,
|
body: instance.body,
|
||||||
signature,
|
signature,
|
||||||
resolver,
|
resolver: resolver.clone(),
|
||||||
store,
|
store,
|
||||||
unifier_index: instance.unifier_id,
|
unifier_index: instance.unifier_id,
|
||||||
calls: instance.calls,
|
calls: instance.calls,
|
||||||
id: 0,
|
id: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let mut store = ConcreteTypeStore::new();
|
||||||
|
let mut cache = HashMap::new();
|
||||||
|
let signature =
|
||||||
|
store.from_signature(&mut composer.unifier, &self.primitive, &fun_signature, &mut cache);
|
||||||
|
let signature = store.add_cty(signature);
|
||||||
|
let attributes_writeback_task = CodeGenTask {
|
||||||
|
subst: Default::default(),
|
||||||
|
symbol_name: "attributes_writeback".to_string(),
|
||||||
|
body: Arc::new(Default::default()),
|
||||||
|
signature,
|
||||||
|
resolver,
|
||||||
|
store,
|
||||||
|
unifier_index: instance.unifier_id,
|
||||||
|
calls: Arc::new(Default::default()),
|
||||||
|
id: 0,
|
||||||
|
};
|
||||||
let isa = self.isa;
|
let isa = self.isa;
|
||||||
let working_directory = self.working_directory.path().to_owned();
|
let working_directory = self.working_directory.path().to_owned();
|
||||||
|
|
||||||
@ -734,38 +764,80 @@ impl Nac3 {
|
|||||||
let membuffer = membuffers.clone();
|
let membuffer = membuffers.clone();
|
||||||
|
|
||||||
let f = Arc::new(WithCall::new(Box::new(move |module| {
|
let f = Arc::new(WithCall::new(Box::new(move |module| {
|
||||||
|
// println!("\n\n--------------\n{}\n--------------\n", module.print_to_string().to_string());
|
||||||
let buffer = module.write_bitcode_to_memory();
|
let buffer = module.write_bitcode_to_memory();
|
||||||
let buffer = buffer.as_slice().into();
|
let buffer = buffer.as_slice().into();
|
||||||
membuffer.lock().push(buffer);
|
membuffer.lock().push(buffer);
|
||||||
})));
|
})));
|
||||||
let size_t = if self.isa == Isa::Host { 64 } else { 32 };
|
let size_t = if self.isa == Isa::Host { 64 } else { 32 };
|
||||||
let thread_names: Vec<String> = (0..4).map(|_| "main".to_string()).collect();
|
print!("input number of thread: ");
|
||||||
|
std::io::stdout().flush().unwrap();
|
||||||
|
let mut buffer = String::with_capacity(2);
|
||||||
|
// std::io::stdin().read_line(&mut buffer)?;
|
||||||
|
// println!("{} as input", buffer);
|
||||||
|
let num_thread = buffer.trim().parse::<i32>().unwrap_or_else(|_| {/* println!("using default (4 thread)"); */4});
|
||||||
|
let thread_names: Vec<String> = (0..num_thread).map(|_| "main".to_string()).collect();
|
||||||
|
// println!("number of threads: {}", thread_names.len());
|
||||||
|
// let thread_names: Vec<String> = (0..4).map(|_| "main".to_string()).collect();
|
||||||
let threads: Vec<_> = thread_names
|
let threads: Vec<_> = thread_names
|
||||||
.iter()
|
.iter()
|
||||||
.map(|s| Box::new(ArtiqCodeGenerator::new(s.to_string(), size_t, self.time_fns)))
|
.map(|s| Box::new(ArtiqCodeGenerator::new(s.to_string(), size_t, self.time_fns)))
|
||||||
.collect();
|
.collect();
|
||||||
|
println!("------0:");
|
||||||
|
// let membuffer = membuffers.clone();
|
||||||
py.allow_threads(|| {
|
py.allow_threads(|| {
|
||||||
let (registry, handles) = WorkerRegistry::create_workers(threads, top_level.clone(), f);
|
let (registry, handles) = WorkerRegistry::create_workers(threads, top_level.clone(), f);
|
||||||
registry.add_task(task);
|
registry.add_task(task);
|
||||||
registry.wait_tasks_complete(handles);
|
registry.wait_tasks_complete(handles);
|
||||||
|
println!("------1:");
|
||||||
|
|
||||||
|
// let mut generator = ArtiqCodeGenerator::new("attributes_writeback".to_string(), size_t, self.time_fns);
|
||||||
|
// let context = inkwell::context::Context::create();
|
||||||
|
// let module = context.create_module("attributes_writeback");
|
||||||
|
// module.add_basic_value_flag(
|
||||||
|
// "Debug Info Version",
|
||||||
|
// inkwell::module::FlagBehavior::Warning,
|
||||||
|
// context.i32_type().const_int(3, false),
|
||||||
|
// );
|
||||||
|
// module.add_basic_value_flag(
|
||||||
|
// "Dwarf Version",
|
||||||
|
// inkwell::module::FlagBehavior::Warning,
|
||||||
|
// context.i32_type().const_int(4, false),
|
||||||
|
// );
|
||||||
|
// let builder = context.create_builder();
|
||||||
|
// let (_, module, _) = gen_func_impl(&context, &mut generator, ®istry, builder, module,
|
||||||
|
// attributes_writeback_task, |generator, ctx| {
|
||||||
|
// attributes_writeback(ctx, generator, inner_resolver.as_ref(), host_attributes)
|
||||||
|
// }).unwrap();
|
||||||
|
// let buffer = module.write_bitcode_to_memory();
|
||||||
|
// let buffer = buffer.as_slice().into();
|
||||||
|
// membuffer.lock().push(buffer);
|
||||||
});
|
});
|
||||||
|
|
||||||
let buffers = membuffers.lock();
|
|
||||||
let context = inkwell::context::Context::create();
|
let context = inkwell::context::Context::create();
|
||||||
|
let buffers = membuffers.lock();
|
||||||
let main = context
|
let main = context
|
||||||
.create_module_from_ir(MemoryBuffer::create_from_memory_range(&buffers[0], "main"))
|
.create_module_from_ir(MemoryBuffer::create_from_memory_range(&buffers[0], "main"))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
// println!(":1: {}", buffers.len());
|
||||||
for buffer in buffers.iter().skip(1) {
|
for buffer in buffers.iter().skip(1) {
|
||||||
let other = context
|
let other = context
|
||||||
.create_module_from_ir(MemoryBuffer::create_from_memory_range(buffer, "main"))
|
.create_module_from_ir(MemoryBuffer::create_from_memory_range(buffer, "main"))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
// println!(":2:");
|
||||||
main.link_in_module(other)
|
main.link_in_module(other)
|
||||||
.map_err(|err| CompileError::new_err(err.to_string()))?;
|
.map_err(|err| CompileError::new_err(err.to_string()))?;
|
||||||
}
|
}
|
||||||
main.link_in_module(load_irrt(&context))
|
// let builder = context.create_builder();
|
||||||
.map_err(|err| CompileError::new_err(err.to_string()))?;
|
// let modinit_return = main.get_function("__modinit__").unwrap().get_last_basic_block().unwrap().get_terminator().unwrap();
|
||||||
|
// builder.position_before(&modinit_return);
|
||||||
|
// builder.build_call(main.get_function("attributes_writeback").unwrap(), &[], "attributes_writeback");
|
||||||
|
|
||||||
|
// main.link_in_module(load_irrt(&context))
|
||||||
|
// .map_err(|err| CompileError::new_err(err.to_string()))?;
|
||||||
|
|
||||||
|
// println!(":3:");
|
||||||
|
|
||||||
let mut function_iter = main.get_first_function();
|
let mut function_iter = main.get_first_function();
|
||||||
while let Some(func) = function_iter {
|
while let Some(func) = function_iter {
|
||||||
@ -775,12 +847,14 @@ impl Nac3 {
|
|||||||
function_iter = func.get_next_function();
|
function_iter = func.get_next_function();
|
||||||
}
|
}
|
||||||
|
|
||||||
let builder = PassManagerBuilder::create();
|
// let builder = PassManagerBuilder::create();
|
||||||
builder.set_optimization_level(OptimizationLevel::Aggressive);
|
// builder.set_optimization_level(OptimizationLevel::Aggressive);
|
||||||
let passes = PassManager::create(());
|
// let passes = PassManager::create(());
|
||||||
builder.set_inliner_with_threshold(255);
|
// builder.set_inliner_with_threshold(255);
|
||||||
builder.populate_module_pass_manager(&passes);
|
// builder.populate_module_pass_manager(&passes);
|
||||||
passes.run_on(&main);
|
// passes.run_on(&main);
|
||||||
|
|
||||||
|
// println!("\n\n==========={}\n=============", main.print_to_string().to_string());
|
||||||
|
|
||||||
let (triple, features) = match isa {
|
let (triple, features) = match isa {
|
||||||
Isa::Host => (
|
Isa::Host => (
|
||||||
@ -827,7 +901,11 @@ impl Nac3 {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(linker_status) = Command::new("ld.lld").args(linker_args).status() {
|
#[cfg(not(windows))]
|
||||||
|
let lld_command = "ld.lld";
|
||||||
|
#[cfg(windows)]
|
||||||
|
let lld_command = "ld.lld.exe";
|
||||||
|
if let Ok(linker_status) = Command::new(lld_command).args(linker_args).status() {
|
||||||
if !linker_status.success() {
|
if !linker_status.success() {
|
||||||
return Err(CompileError::new_err("failed to start linker"));
|
return Err(CompileError::new_err("failed to start linker"));
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ use pyo3::{
|
|||||||
PyAny, PyObject, PyResult, Python,
|
PyAny, PyObject, PyResult, Python,
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
collections::{HashMap, HashSet},
|
collections::HashMap,
|
||||||
sync::{
|
sync::{
|
||||||
Arc,
|
Arc,
|
||||||
atomic::{AtomicBool, Ordering::Relaxed}
|
atomic::{AtomicBool, Ordering::Relaxed}
|
||||||
@ -54,7 +54,7 @@ pub struct InnerResolver {
|
|||||||
pub id_to_pyval: RwLock<HashMap<StrRef, (u64, PyObject)>>,
|
pub id_to_pyval: RwLock<HashMap<StrRef, (u64, PyObject)>>,
|
||||||
pub id_to_primitive: RwLock<HashMap<u64, PrimitiveValue>>,
|
pub id_to_primitive: RwLock<HashMap<u64, PrimitiveValue>>,
|
||||||
pub field_to_val: RwLock<HashMap<(u64, StrRef), Option<(u64, PyObject)>>>,
|
pub field_to_val: RwLock<HashMap<(u64, StrRef), Option<(u64, PyObject)>>>,
|
||||||
pub global_value_ids: Arc<RwLock<HashSet<u64>>>,
|
pub global_value_ids: Arc<RwLock<HashMap<u64, PyObject>>>,
|
||||||
pub class_names: Mutex<HashMap<StrRef, Type>>,
|
pub class_names: Mutex<HashMap<StrRef, Type>>,
|
||||||
pub pyid_to_def: Arc<RwLock<HashMap<u64, DefinitionId>>>,
|
pub pyid_to_def: Arc<RwLock<HashMap<u64, DefinitionId>>>,
|
||||||
pub pyid_to_type: Arc<RwLock<HashMap<u64, Type>>>,
|
pub pyid_to_type: Arc<RwLock<HashMap<u64, Type>>>,
|
||||||
@ -99,7 +99,7 @@ impl StaticValue for PythonValue {
|
|||||||
_: &mut dyn CodeGenerator,
|
_: &mut dyn CodeGenerator,
|
||||||
) -> BasicValueEnum<'ctx> {
|
) -> BasicValueEnum<'ctx> {
|
||||||
ctx.module
|
ctx.module
|
||||||
.get_global(self.id.to_string().as_str())
|
.get_global(format!("{}_const", self.id).as_str())
|
||||||
.map(|val| val.as_pointer_value().into())
|
.map(|val| val.as_pointer_value().into())
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
Python::with_gil(|py| -> PyResult<BasicValueEnum<'ctx>> {
|
Python::with_gil(|py| -> PyResult<BasicValueEnum<'ctx>> {
|
||||||
@ -115,13 +115,7 @@ impl StaticValue for PythonValue {
|
|||||||
&[ctx.ctx.i32_type().const_int(id as u64, false).into()],
|
&[ctx.ctx.i32_type().const_int(id as u64, false).into()],
|
||||||
false,
|
false,
|
||||||
));
|
));
|
||||||
let global2 = ctx.module.add_global(
|
Ok(global.as_pointer_value().into())
|
||||||
struct_type.ptr_type(AddressSpace::Generic),
|
|
||||||
None,
|
|
||||||
format!("{}_const2", self.id).as_str(),
|
|
||||||
);
|
|
||||||
global2.set_initializer(&global.as_pointer_value());
|
|
||||||
Ok(global2.as_pointer_value().into())
|
|
||||||
})
|
})
|
||||||
.unwrap()
|
.unwrap()
|
||||||
})
|
})
|
||||||
@ -131,6 +125,7 @@ impl StaticValue for PythonValue {
|
|||||||
&self,
|
&self,
|
||||||
ctx: &mut CodeGenContext<'ctx, 'a>,
|
ctx: &mut CodeGenContext<'ctx, 'a>,
|
||||||
generator: &mut dyn CodeGenerator,
|
generator: &mut dyn CodeGenerator,
|
||||||
|
expected_ty: Type,
|
||||||
) -> Result<BasicValueEnum<'ctx>, String> {
|
) -> Result<BasicValueEnum<'ctx>, String> {
|
||||||
if let Some(val) = self.resolver.id_to_primitive.read().get(&self.id) {
|
if let Some(val) = self.resolver.id_to_primitive.read().get(&self.id) {
|
||||||
return Ok(match val {
|
return Ok(match val {
|
||||||
@ -150,7 +145,7 @@ impl StaticValue for PythonValue {
|
|||||||
|
|
||||||
Python::with_gil(|py| -> PyResult<BasicValueEnum<'ctx>> {
|
Python::with_gil(|py| -> PyResult<BasicValueEnum<'ctx>> {
|
||||||
self.resolver
|
self.resolver
|
||||||
.get_obj_value(py, self.value.as_ref(py), ctx, generator)
|
.get_obj_value(py, self.value.as_ref(py), ctx, generator, expected_ty)
|
||||||
.map(Option::unwrap)
|
.map(Option::unwrap)
|
||||||
}).map_err(|e| e.to_string())
|
}).map_err(|e| e.to_string())
|
||||||
}
|
}
|
||||||
@ -169,6 +164,16 @@ impl StaticValue for PythonValue {
|
|||||||
let helper = &self.resolver.helper;
|
let helper = &self.resolver.helper;
|
||||||
let ty = helper.type_fn.call1(py, (&self.value,))?;
|
let ty = helper.type_fn.call1(py, (&self.value,))?;
|
||||||
let ty_id: u64 = helper.id_fn.call1(py, (ty,))?.extract(py)?;
|
let ty_id: u64 = helper.id_fn.call1(py, (ty,))?.extract(py)?;
|
||||||
|
// for optimizing unwrap KernelInvariant
|
||||||
|
if ty_id == self.resolver.primitive_ids.option && name == "_nac3_option".into() {
|
||||||
|
let obj = self.value.getattr(py, &name.to_string())?;
|
||||||
|
let id = self.resolver.helper.id_fn.call1(py, (&obj,))?.extract(py)?;
|
||||||
|
if self.id == self.resolver.primitive_ids.none {
|
||||||
|
return Ok(None)
|
||||||
|
} else {
|
||||||
|
return Ok(Some((id, obj)))
|
||||||
|
}
|
||||||
|
}
|
||||||
let def_id = { *self.resolver.pyid_to_def.read().get(&ty_id).unwrap() };
|
let def_id = { *self.resolver.pyid_to_def.read().get(&ty_id).unwrap() };
|
||||||
let mut mutable = true;
|
let mut mutable = true;
|
||||||
let defs = ctx.top_level.definitions.read();
|
let defs = ctx.top_level.definitions.read();
|
||||||
@ -201,6 +206,28 @@ impl StaticValue for PythonValue {
|
|||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_tuple_element<'ctx>(&self, index: u32) -> Option<ValueEnum<'ctx>> {
|
||||||
|
Python::with_gil(|py| -> PyResult<Option<(u64, PyObject)>> {
|
||||||
|
let helper = &self.resolver.helper;
|
||||||
|
let ty = helper.type_fn.call1(py, (&self.value,))?;
|
||||||
|
let ty_id: u64 = helper.id_fn.call1(py, (ty,))?.extract(py)?;
|
||||||
|
assert_eq!(ty_id, self.resolver.primitive_ids.tuple);
|
||||||
|
let tup: &PyTuple = self.value.extract(py)?;
|
||||||
|
let elem = tup.get_item(index as usize);
|
||||||
|
let id = self.resolver.helper.id_fn.call1(py, (elem,))?.extract(py)?;
|
||||||
|
Ok(Some((id, elem.into())))
|
||||||
|
})
|
||||||
|
.unwrap()
|
||||||
|
.map(|(id, obj)| {
|
||||||
|
ValueEnum::Static(Arc::new(PythonValue {
|
||||||
|
id,
|
||||||
|
value: obj,
|
||||||
|
store_obj: self.store_obj.clone(),
|
||||||
|
resolver: self.resolver.clone(),
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InnerResolver {
|
impl InnerResolver {
|
||||||
@ -269,6 +296,8 @@ impl InnerResolver {
|
|||||||
Ok(Ok((primitives.bool, true)))
|
Ok(Ok((primitives.bool, true)))
|
||||||
} else if ty_id == self.primitive_ids.float {
|
} else if ty_id == self.primitive_ids.float {
|
||||||
Ok(Ok((primitives.float, true)))
|
Ok(Ok((primitives.float, true)))
|
||||||
|
} else if ty_id == self.primitive_ids.float64 {
|
||||||
|
Ok(Ok((primitives.float, true)))
|
||||||
} else if ty_id == self.primitive_ids.exception {
|
} else if ty_id == self.primitive_ids.exception {
|
||||||
Ok(Ok((primitives.exception, true)))
|
Ok(Ok((primitives.exception, true)))
|
||||||
} else if ty_id == self.primitive_ids.list {
|
} else if ty_id == self.primitive_ids.list {
|
||||||
@ -503,7 +532,7 @@ impl InnerResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_obj_type(
|
pub fn get_obj_type(
|
||||||
&self,
|
&self,
|
||||||
py: Python,
|
py: Python,
|
||||||
obj: &PyAny,
|
obj: &PyAny,
|
||||||
@ -512,8 +541,8 @@ impl InnerResolver {
|
|||||||
primitives: &PrimitiveStore,
|
primitives: &PrimitiveStore,
|
||||||
) -> PyResult<Result<Type, String>> {
|
) -> PyResult<Result<Type, String>> {
|
||||||
let ty = self.helper.type_fn.call1(py, (obj,)).unwrap();
|
let ty = self.helper.type_fn.call1(py, (obj,)).unwrap();
|
||||||
let ty_id: u64 = self.helper.id_fn.call1(py, (ty.clone(),))?.extract(py)?;
|
let py_obj_id: u64 = self.helper.id_fn.call1(py, (obj,))?.extract(py)?;
|
||||||
if let Some(ty) = self.pyid_to_type.read().get(&ty_id) {
|
if let Some(ty) = self.pyid_to_type.read().get(&py_obj_id) {
|
||||||
return Ok(Ok(*ty))
|
return Ok(Ok(*ty))
|
||||||
}
|
}
|
||||||
let (extracted_ty, inst_check) = match self.get_pyty_obj_type(
|
let (extracted_ty, inst_check) = match self.get_pyty_obj_type(
|
||||||
@ -544,7 +573,7 @@ impl InnerResolver {
|
|||||||
let len: usize = self.helper.len_fn.call1(py, (obj,))?.extract(py)?;
|
let len: usize = self.helper.len_fn.call1(py, (obj,))?.extract(py)?;
|
||||||
if len == 0 {
|
if len == 0 {
|
||||||
assert!(matches!(
|
assert!(matches!(
|
||||||
&*unifier.get_ty(extracted_ty),
|
&*unifier.get_ty(*ty),
|
||||||
TypeEnum::TVar { fields: None, range, .. }
|
TypeEnum::TVar { fields: None, range, .. }
|
||||||
if range.is_empty()
|
if range.is_empty()
|
||||||
));
|
));
|
||||||
@ -620,6 +649,7 @@ impl InnerResolver {
|
|||||||
Ok(Ok(res))
|
Ok(Ok(res))
|
||||||
}
|
}
|
||||||
(TypeEnum::TObj { params, fields, .. }, false) => {
|
(TypeEnum::TObj { params, fields, .. }, false) => {
|
||||||
|
self.pyid_to_type.write().insert(py_obj_id, extracted_ty);
|
||||||
let var_map = params
|
let var_map = params
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(id_var, ty)| {
|
.map(|(id_var, ty)| {
|
||||||
@ -640,7 +670,10 @@ impl InnerResolver {
|
|||||||
if let TypeEnum::TFunc(..) = &*unifier.get_ty(field.1.0) {
|
if let TypeEnum::TFunc(..) = &*unifier.get_ty(field.1.0) {
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
let field_data = obj.getattr(&name)?;
|
let field_data = match obj.getattr(&name) {
|
||||||
|
Ok(d) => d,
|
||||||
|
Err(e) => return Ok(Err(format!("{}", e))),
|
||||||
|
};
|
||||||
let ty = match self
|
let ty = match self
|
||||||
.get_obj_type(py, field_data, unifier, defs, primitives)?
|
.get_obj_type(py, field_data, unifier, defs, primitives)?
|
||||||
{
|
{
|
||||||
@ -673,50 +706,86 @@ impl InnerResolver {
|
|||||||
let extracted_ty = unifier.subst(extracted_ty, &var_map).unwrap_or(extracted_ty);
|
let extracted_ty = unifier.subst(extracted_ty, &var_map).unwrap_or(extracted_ty);
|
||||||
Ok(Ok(extracted_ty))
|
Ok(Ok(extracted_ty))
|
||||||
};
|
};
|
||||||
instantiate_obj()
|
let result = instantiate_obj();
|
||||||
|
// update/remove the cache according to the result
|
||||||
|
match result {
|
||||||
|
Ok(Ok(ty)) => self.pyid_to_type.write().insert(py_obj_id, ty),
|
||||||
|
_ => self.pyid_to_type.write().remove(&py_obj_id)
|
||||||
|
};
|
||||||
|
result
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
// check integer bounds
|
||||||
|
if unifier.unioned(extracted_ty, primitives.int32) {
|
||||||
|
obj.extract::<i32>().map_or_else(
|
||||||
|
|_| Ok(Err(format!("{} is not in the range of int32", obj))),
|
||||||
|
|_| Ok(Ok(extracted_ty))
|
||||||
|
)
|
||||||
|
} else if unifier.unioned(extracted_ty, primitives.int64) {
|
||||||
|
obj.extract::<i64>().map_or_else(
|
||||||
|
|_| Ok(Err(format!("{} is not in the range of int64", obj))),
|
||||||
|
|_| Ok(Ok(extracted_ty))
|
||||||
|
)
|
||||||
|
} else if unifier.unioned(extracted_ty, primitives.uint32) {
|
||||||
|
obj.extract::<u32>().map_or_else(
|
||||||
|
|_| Ok(Err(format!("{} is not in the range of uint32", obj))),
|
||||||
|
|_| Ok(Ok(extracted_ty))
|
||||||
|
)
|
||||||
|
} else if unifier.unioned(extracted_ty, primitives.uint64) {
|
||||||
|
obj.extract::<u64>().map_or_else(
|
||||||
|
|_| Ok(Err(format!("{} is not in the range of uint64", obj))),
|
||||||
|
|_| Ok(Ok(extracted_ty))
|
||||||
|
)
|
||||||
|
} else if unifier.unioned(extracted_ty, primitives.bool) {
|
||||||
|
obj.extract::<bool>().map_or_else(
|
||||||
|
|_| Ok(Err(format!("{} is not in the range of bool", obj))),
|
||||||
|
|_| Ok(Ok(extracted_ty))
|
||||||
|
)
|
||||||
|
} else if unifier.unioned(extracted_ty, primitives.float) {
|
||||||
|
obj.extract::<f64>().map_or_else(
|
||||||
|
|_| Ok(Err(format!("{} is not in the range of float64", obj))),
|
||||||
|
|_| Ok(Ok(extracted_ty))
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
Ok(Ok(extracted_ty))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => Ok(Ok(extracted_ty)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_obj_value<'ctx, 'a>(
|
pub fn get_obj_value<'ctx, 'a>(
|
||||||
&self,
|
&self,
|
||||||
py: Python,
|
py: Python,
|
||||||
obj: &PyAny,
|
obj: &PyAny,
|
||||||
ctx: &mut CodeGenContext<'ctx, 'a>,
|
ctx: &mut CodeGenContext<'ctx, 'a>,
|
||||||
generator: &mut dyn CodeGenerator,
|
generator: &mut dyn CodeGenerator,
|
||||||
|
expected_ty: Type,
|
||||||
) -> PyResult<Option<BasicValueEnum<'ctx>>> {
|
) -> PyResult<Option<BasicValueEnum<'ctx>>> {
|
||||||
let ty_id: u64 =
|
let ty_id: u64 =
|
||||||
self.helper.id_fn.call1(py, (self.helper.type_fn.call1(py, (obj,))?,))?.extract(py)?;
|
self.helper.id_fn.call1(py, (self.helper.type_fn.call1(py, (obj,))?,))?.extract(py)?;
|
||||||
let id: u64 = self.helper.id_fn.call1(py, (obj,))?.extract(py)?;
|
let id: u64 = self.helper.id_fn.call1(py, (obj,))?.extract(py)?;
|
||||||
if ty_id == self.primitive_ids.int || ty_id == self.primitive_ids.int32 {
|
if ty_id == self.primitive_ids.int || ty_id == self.primitive_ids.int32 {
|
||||||
let val: i32 = obj.extract().map_err(|_| super::CompileError::new_err(
|
let val: i32 = obj.extract().unwrap();
|
||||||
format!("{} is not in the range of int32", obj)))?;
|
|
||||||
self.id_to_primitive.write().insert(id, PrimitiveValue::I32(val));
|
self.id_to_primitive.write().insert(id, PrimitiveValue::I32(val));
|
||||||
Ok(Some(ctx.ctx.i32_type().const_int(val as u64, false).into()))
|
Ok(Some(ctx.ctx.i32_type().const_int(val as u64, false).into()))
|
||||||
} else if ty_id == self.primitive_ids.int64 {
|
} else if ty_id == self.primitive_ids.int64 {
|
||||||
let val: i64 = obj.extract().map_err(|_| super::CompileError::new_err(
|
let val: i64 = obj.extract().unwrap();
|
||||||
format!("{} is not in the range of int64", obj)))?;
|
|
||||||
self.id_to_primitive.write().insert(id, PrimitiveValue::I64(val));
|
self.id_to_primitive.write().insert(id, PrimitiveValue::I64(val));
|
||||||
Ok(Some(ctx.ctx.i64_type().const_int(val as u64, false).into()))
|
Ok(Some(ctx.ctx.i64_type().const_int(val as u64, false).into()))
|
||||||
} else if ty_id == self.primitive_ids.uint32 {
|
} else if ty_id == self.primitive_ids.uint32 {
|
||||||
let val: u32 = obj.extract().map_err(|_| super::CompileError::new_err(
|
let val: u32 = obj.extract().unwrap();
|
||||||
format!("{} is not in the range of uint32", obj)))?;
|
|
||||||
self.id_to_primitive.write().insert(id, PrimitiveValue::U32(val));
|
self.id_to_primitive.write().insert(id, PrimitiveValue::U32(val));
|
||||||
Ok(Some(ctx.ctx.i32_type().const_int(val as u64, false).into()))
|
Ok(Some(ctx.ctx.i32_type().const_int(val as u64, false).into()))
|
||||||
} else if ty_id == self.primitive_ids.uint64 {
|
} else if ty_id == self.primitive_ids.uint64 {
|
||||||
let val: u64 = obj.extract().map_err(|_| super::CompileError::new_err(
|
let val: u64 = obj.extract().unwrap();
|
||||||
format!("{} is not in the range of uint64", obj)))?;
|
|
||||||
self.id_to_primitive.write().insert(id, PrimitiveValue::U64(val));
|
self.id_to_primitive.write().insert(id, PrimitiveValue::U64(val));
|
||||||
Ok(Some(ctx.ctx.i64_type().const_int(val, false).into()))
|
Ok(Some(ctx.ctx.i64_type().const_int(val, false).into()))
|
||||||
} else if ty_id == self.primitive_ids.bool {
|
} else if ty_id == self.primitive_ids.bool {
|
||||||
let val: bool = obj.extract().map_err(|_| super::CompileError::new_err(
|
let val: bool = obj.extract().unwrap();
|
||||||
format!("{} is not in the range of bool", obj)))?;
|
|
||||||
self.id_to_primitive.write().insert(id, PrimitiveValue::Bool(val));
|
self.id_to_primitive.write().insert(id, PrimitiveValue::Bool(val));
|
||||||
Ok(Some(ctx.ctx.bool_type().const_int(val as u64, false).into()))
|
Ok(Some(ctx.ctx.bool_type().const_int(val as u64, false).into()))
|
||||||
} else if ty_id == self.primitive_ids.float {
|
} else if ty_id == self.primitive_ids.float || ty_id == self.primitive_ids.float64 {
|
||||||
let val: f64 = obj.extract().map_err(|_| super::CompileError::new_err(
|
let val: f64 = obj.extract().unwrap();
|
||||||
format!("{} is not in the range of float64", obj)))?;
|
|
||||||
self.id_to_primitive.write().insert(id, PrimitiveValue::F64(val));
|
self.id_to_primitive.write().insert(id, PrimitiveValue::F64(val));
|
||||||
Ok(Some(ctx.ctx.f64_type().const_float(val).into()))
|
Ok(Some(ctx.ctx.f64_type().const_float(val).into()))
|
||||||
} else if ty_id == self.primitive_ids.list {
|
} else if ty_id == self.primitive_ids.list {
|
||||||
@ -727,40 +796,39 @@ impl InnerResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let len: usize = self.helper.len_fn.call1(py, (obj,))?.extract(py)?;
|
let len: usize = self.helper.len_fn.call1(py, (obj,))?.extract(py)?;
|
||||||
let ty = if len == 0 {
|
let elem_ty =
|
||||||
ctx.primitives.int32
|
if let TypeEnum::TList { ty } = ctx.unifier.get_ty_immutable(expected_ty).as_ref()
|
||||||
|
{
|
||||||
|
*ty
|
||||||
} else {
|
} else {
|
||||||
self.get_list_elem_type(
|
unreachable!("must be list")
|
||||||
py,
|
|
||||||
obj,
|
|
||||||
len,
|
|
||||||
&mut ctx.unifier,
|
|
||||||
&ctx.top_level.definitions.read(),
|
|
||||||
&ctx.primitives,
|
|
||||||
)?
|
|
||||||
.unwrap()
|
|
||||||
};
|
};
|
||||||
let ty = ctx.get_llvm_type(generator, ty);
|
let ty = ctx.get_llvm_type(generator, elem_ty);
|
||||||
let size_t = generator.get_size_type(ctx.ctx);
|
let size_t = generator.get_size_type(ctx.ctx);
|
||||||
let arr_ty = ctx
|
let arr_ty = ctx
|
||||||
.ctx
|
.ctx
|
||||||
.struct_type(&[ty.ptr_type(AddressSpace::Generic).into(), size_t.into()], false);
|
.struct_type(&[ty.ptr_type(AddressSpace::Generic).into(), size_t.into()], false);
|
||||||
|
|
||||||
{
|
{
|
||||||
if self.global_value_ids.read().contains(&id) {
|
if self.global_value_ids.read().contains_key(&id) {
|
||||||
let global = ctx.module.get_global(&id_str).unwrap_or_else(|| {
|
let global = ctx.module.get_global(&id_str).unwrap_or_else(|| {
|
||||||
ctx.module.add_global(arr_ty, Some(AddressSpace::Generic), &id_str)
|
ctx.module.add_global(arr_ty, Some(AddressSpace::Generic), &id_str)
|
||||||
});
|
});
|
||||||
return Ok(Some(global.as_pointer_value().into()));
|
return Ok(Some(global.as_pointer_value().into()));
|
||||||
} else {
|
} else {
|
||||||
self.global_value_ids.write().insert(id);
|
self.global_value_ids.write().insert(id, obj.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let arr: Result<Option<Vec<_>>, _> = (0..len)
|
let arr: Result<Option<Vec<_>>, _> = (0..len)
|
||||||
.map(|i| {
|
.map(|i| {
|
||||||
obj.get_item(i).and_then(|elem| self.get_obj_value(py, elem, ctx, generator).map_err(
|
obj
|
||||||
|e| super::CompileError::new_err(format!("Error getting element {}: {}", i, e))))
|
.get_item(i)
|
||||||
|
.and_then(|elem| self.get_obj_value(py, elem, ctx, generator, elem_ty)
|
||||||
|
.map_err(
|
||||||
|
|e| super::CompileError::new_err(
|
||||||
|
format!("Error getting element {}: {}", i, e))
|
||||||
|
))
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
let arr = arr?.unwrap();
|
let arr = arr?.unwrap();
|
||||||
@ -801,58 +869,48 @@ impl InnerResolver {
|
|||||||
|
|
||||||
Ok(Some(global.as_pointer_value().into()))
|
Ok(Some(global.as_pointer_value().into()))
|
||||||
} else if ty_id == self.primitive_ids.tuple {
|
} else if ty_id == self.primitive_ids.tuple {
|
||||||
let id_str = id.to_string();
|
if let TypeEnum::TTuple { ty } = ctx.unifier.get_ty_immutable(expected_ty).as_ref() {
|
||||||
|
let tup_tys = ty.iter();
|
||||||
if let Some(global) = ctx.module.get_global(&id_str) {
|
|
||||||
return Ok(Some(global.as_pointer_value().into()));
|
|
||||||
}
|
|
||||||
|
|
||||||
let elements: &PyTuple = obj.cast_as()?;
|
let elements: &PyTuple = obj.cast_as()?;
|
||||||
let types: Result<Result<Vec<_>, _>, _> = elements
|
assert_eq!(elements.len(), tup_tys.len());
|
||||||
|
let val: Result<Option<Vec<_>>, _> =
|
||||||
|
elements
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(i, elem)| {
|
.zip(tup_tys)
|
||||||
self.get_obj_type(
|
.map(|((i, elem), ty)| self
|
||||||
py,
|
.get_obj_value(py, elem, ctx, generator, *ty).map_err(|e|
|
||||||
elem,
|
super::CompileError::new_err(
|
||||||
&mut ctx.unifier,
|
format!("Error getting element {}: {}", i, e)
|
||||||
&ctx.top_level.definitions.read(),
|
|
||||||
&ctx.primitives,
|
|
||||||
)
|
)
|
||||||
.map_err(|e| super::CompileError::new_err(format!("Error getting element {}: {}", i, e)))
|
)
|
||||||
.map(|ty| ty.map(|ty| ctx.get_llvm_type(generator, ty)))
|
).collect();
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
let types = types?.unwrap();
|
|
||||||
let ty = ctx.ctx.struct_type(&types, false);
|
|
||||||
|
|
||||||
{
|
|
||||||
if self.global_value_ids.read().contains(&id) {
|
|
||||||
let global = ctx.module.get_global(&id_str).unwrap_or_else(|| {
|
|
||||||
ctx.module.add_global(ty, Some(AddressSpace::Generic), &id_str)
|
|
||||||
});
|
|
||||||
return Ok(Some(global.as_pointer_value().into()));
|
|
||||||
} else {
|
|
||||||
self.global_value_ids.write().insert(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let val: Result<Option<Vec<_>>, _> =
|
|
||||||
elements.iter().enumerate().map(|(i, elem)| self.get_obj_value(py, elem, ctx, generator).map_err(|e|
|
|
||||||
super::CompileError::new_err(format!("Error getting element {}: {}", i, e)))).collect();
|
|
||||||
let val = val?.unwrap();
|
let val = val?.unwrap();
|
||||||
let val = ctx.ctx.const_struct(&val, false);
|
let val = ctx.ctx.const_struct(&val, false);
|
||||||
let global = ctx.module.add_global(ty, Some(AddressSpace::Generic), &id_str);
|
Ok(Some(val.into()))
|
||||||
global.set_initializer(&val);
|
} else {
|
||||||
Ok(Some(global.as_pointer_value().into()))
|
unreachable!("must expect tuple type")
|
||||||
|
}
|
||||||
} else if ty_id == self.primitive_ids.option {
|
} else if ty_id == self.primitive_ids.option {
|
||||||
|
let option_val_ty = match ctx.unifier.get_ty_immutable(expected_ty).as_ref() {
|
||||||
|
TypeEnum::TObj { obj_id, params, .. }
|
||||||
|
if *obj_id == ctx.primitives.option.get_obj_id(&ctx.unifier) =>
|
||||||
|
{
|
||||||
|
*params.iter().next().unwrap().1
|
||||||
|
}
|
||||||
|
_ => unreachable!("must be option type")
|
||||||
|
};
|
||||||
if id == self.primitive_ids.none {
|
if id == self.primitive_ids.none {
|
||||||
// for option type, just a null ptr, whose type needs to be casted in codegen
|
// for option type, just a null ptr
|
||||||
// according to the type info attached in the ast
|
Ok(Some(
|
||||||
Ok(Some(ctx.ctx.i8_type().ptr_type(AddressSpace::Generic).const_null().into()))
|
ctx.get_llvm_type(generator, option_val_ty)
|
||||||
|
.ptr_type(AddressSpace::Generic)
|
||||||
|
.const_null()
|
||||||
|
.into(),
|
||||||
|
))
|
||||||
} else {
|
} else {
|
||||||
match self
|
match self
|
||||||
.get_obj_value(py, obj.getattr("_nac3_option").unwrap(), ctx, generator)
|
.get_obj_value(py, obj.getattr("_nac3_option").unwrap(), ctx, generator, option_val_ty)
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
super::CompileError::new_err(format!(
|
super::CompileError::new_err(format!(
|
||||||
"Error getting value of Option object: {}",
|
"Error getting value of Option object: {}",
|
||||||
@ -862,13 +920,13 @@ impl InnerResolver {
|
|||||||
Some(v) => {
|
Some(v) => {
|
||||||
let global_str = format!("{}_option", id);
|
let global_str = format!("{}_option", id);
|
||||||
{
|
{
|
||||||
if self.global_value_ids.read().contains(&id) {
|
if self.global_value_ids.read().contains_key(&id) {
|
||||||
let global = ctx.module.get_global(&global_str).unwrap_or_else(|| {
|
let global = ctx.module.get_global(&global_str).unwrap_or_else(|| {
|
||||||
ctx.module.add_global(v.get_type(), Some(AddressSpace::Generic), &global_str)
|
ctx.module.add_global(v.get_type(), Some(AddressSpace::Generic), &global_str)
|
||||||
});
|
});
|
||||||
return Ok(Some(global.as_pointer_value().into()));
|
return Ok(Some(global.as_pointer_value().into()));
|
||||||
} else {
|
} else {
|
||||||
self.global_value_ids.write().insert(id);
|
self.global_value_ids.write().insert(id, obj.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let global = ctx.module.add_global(v.get_type(), Some(AddressSpace::Generic), &global_str);
|
let global = ctx.module.add_global(v.get_type(), Some(AddressSpace::Generic), &global_str);
|
||||||
@ -895,13 +953,13 @@ impl InnerResolver {
|
|||||||
.get_element_type()
|
.get_element_type()
|
||||||
.into_struct_type();
|
.into_struct_type();
|
||||||
{
|
{
|
||||||
if self.global_value_ids.read().contains(&id) {
|
if self.global_value_ids.read().contains_key(&id) {
|
||||||
let global = ctx.module.get_global(&id_str).unwrap_or_else(|| {
|
let global = ctx.module.get_global(&id_str).unwrap_or_else(|| {
|
||||||
ctx.module.add_global(ty, Some(AddressSpace::Generic), &id_str)
|
ctx.module.add_global(ty, Some(AddressSpace::Generic), &id_str)
|
||||||
});
|
});
|
||||||
return Ok(Some(global.as_pointer_value().into()));
|
return Ok(Some(global.as_pointer_value().into()));
|
||||||
} else {
|
} else {
|
||||||
self.global_value_ids.write().insert(id);
|
self.global_value_ids.write().insert(id, obj.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// should be classes
|
// should be classes
|
||||||
@ -910,15 +968,17 @@ impl InnerResolver {
|
|||||||
if let TopLevelDef::Class { fields, .. } = &*definition {
|
if let TopLevelDef::Class { fields, .. } = &*definition {
|
||||||
let values: Result<Option<Vec<_>>, _> = fields
|
let values: Result<Option<Vec<_>>, _> = fields
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(name, _, _)| {
|
.map(|(name, ty, _)| {
|
||||||
self.get_obj_value(py, obj.getattr(&name.to_string())?, ctx, generator).map_err(|e|
|
self.get_obj_value(py, obj.getattr(&name.to_string())?, ctx, generator, *ty)
|
||||||
super::CompileError::new_err(format!("Error getting field {}: {}", name, e)))
|
.map_err(|e| super::CompileError::new_err(format!("Error getting field {}: {}", name, e)))
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
let values = values?;
|
let values = values?;
|
||||||
if let Some(values) = values {
|
if let Some(values) = values {
|
||||||
let val = ty.const_named_struct(&values);
|
let val = ty.const_named_struct(&values);
|
||||||
let global = ctx.module.add_global(ty, Some(AddressSpace::Generic), &id_str);
|
let global = ctx.module.get_global(&id_str).unwrap_or_else(|| {
|
||||||
|
ctx.module.add_global(ty, Some(AddressSpace::Generic), &id_str)
|
||||||
|
});
|
||||||
global.set_initializer(&val);
|
global.set_initializer(&val);
|
||||||
Ok(Some(global.as_pointer_value().into()))
|
Ok(Some(global.as_pointer_value().into()))
|
||||||
} else {
|
} else {
|
||||||
@ -935,6 +995,7 @@ impl InnerResolver {
|
|||||||
py: Python,
|
py: Python,
|
||||||
obj: &PyAny,
|
obj: &PyAny,
|
||||||
) -> PyResult<Result<SymbolValue, String>> {
|
) -> PyResult<Result<SymbolValue, String>> {
|
||||||
|
let id: u64 = self.helper.id_fn.call1(py, (obj,))?.extract(py)?;
|
||||||
let ty_id: u64 =
|
let ty_id: u64 =
|
||||||
self.helper.id_fn.call1(py, (self.helper.type_fn.call1(py, (obj,))?,))?.extract(py)?;
|
self.helper.id_fn.call1(py, (self.helper.type_fn.call1(py, (obj,))?,))?.extract(py)?;
|
||||||
Ok(if ty_id == self.primitive_ids.int || ty_id == self.primitive_ids.int32 {
|
Ok(if ty_id == self.primitive_ids.int || ty_id == self.primitive_ids.int32 {
|
||||||
@ -943,23 +1004,33 @@ impl InnerResolver {
|
|||||||
} else if ty_id == self.primitive_ids.int64 {
|
} else if ty_id == self.primitive_ids.int64 {
|
||||||
let val: i64 = obj.extract()?;
|
let val: i64 = obj.extract()?;
|
||||||
Ok(SymbolValue::I64(val))
|
Ok(SymbolValue::I64(val))
|
||||||
|
} else if ty_id == self.primitive_ids.uint32 {
|
||||||
|
let val: u32 = obj.extract()?;
|
||||||
|
Ok(SymbolValue::U32(val))
|
||||||
|
} else if ty_id == self.primitive_ids.uint64 {
|
||||||
|
let val: u64 = obj.extract()?;
|
||||||
|
Ok(SymbolValue::U64(val))
|
||||||
} else if ty_id == self.primitive_ids.bool {
|
} else if ty_id == self.primitive_ids.bool {
|
||||||
let val: bool = obj.extract()?;
|
let val: bool = obj.extract()?;
|
||||||
Ok(SymbolValue::Bool(val))
|
Ok(SymbolValue::Bool(val))
|
||||||
} else if ty_id == self.primitive_ids.float {
|
} else if ty_id == self.primitive_ids.float || ty_id == self.primitive_ids.float64 {
|
||||||
let val: f64 = obj.extract()?;
|
let val: f64 = obj.extract()?;
|
||||||
Ok(SymbolValue::Double(val))
|
Ok(SymbolValue::Double(val))
|
||||||
} else if ty_id == self.primitive_ids.tuple {
|
} else if ty_id == self.primitive_ids.tuple {
|
||||||
let elements: &PyTuple = obj.cast_as()?;
|
let elements: &PyTuple = obj.cast_as()?;
|
||||||
let elements: Result<Result<Vec<_>, String>, _> =
|
let elements: Result<Result<Vec<_>, String>, _> =
|
||||||
elements.iter().map(|elem| self.get_default_param_obj_value(py, elem)).collect();
|
elements.iter().map(|elem| self.get_default_param_obj_value(py, elem)).collect();
|
||||||
let elements = match elements? {
|
elements?.map(SymbolValue::Tuple)
|
||||||
Ok(el) => el,
|
} else if ty_id == self.primitive_ids.option {
|
||||||
Err(err) => return Ok(Err(err)),
|
if id == self.primitive_ids.none {
|
||||||
};
|
Ok(SymbolValue::OptionNone)
|
||||||
Ok(SymbolValue::Tuple(elements))
|
|
||||||
} else {
|
} else {
|
||||||
Err("only primitives values and tuple can be default parameter value".into())
|
self
|
||||||
|
.get_default_param_obj_value(py, obj.getattr("_nac3_option").unwrap())?
|
||||||
|
.map(|v| SymbolValue::OptionSome(Box::new(v)))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Err("only primitives values, option and tuple can be default parameter value".into())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -975,8 +1046,9 @@ impl SymbolResolver for Resolver {
|
|||||||
for (key, val) in members.iter() {
|
for (key, val) in members.iter() {
|
||||||
let key: &str = key.extract()?;
|
let key: &str = key.extract()?;
|
||||||
if key == id.to_string() {
|
if key == id.to_string() {
|
||||||
sym_value =
|
if let Ok(Ok(v)) = self.0.get_default_param_obj_value(py, val) {
|
||||||
Some(self.0.get_default_param_obj_value(py, val).unwrap().unwrap());
|
sym_value = Some(v)
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -984,7 +1056,7 @@ impl SymbolResolver for Resolver {
|
|||||||
})
|
})
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
_ => unimplemented!("other type of expr not supported at {}", expr.location),
|
_ => unreachable!("only for resolving names"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,9 +12,9 @@ rayon = "1.5.1"
|
|||||||
nac3parser = { path = "../nac3parser" }
|
nac3parser = { path = "../nac3parser" }
|
||||||
|
|
||||||
[dependencies.inkwell]
|
[dependencies.inkwell]
|
||||||
version = "0.1.0-beta.4"
|
git = "https://github.com/TheDan64/inkwell.git"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["llvm13-0", "target-x86", "target-arm", "target-riscv", "no-libffi-linking"]
|
features = ["llvm14-0", "target-x86", "target-arm", "target-riscv", "no-libffi-linking"]
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
test-case = "1.2.0"
|
test-case = "1.2.0"
|
||||||
|
@ -10,7 +10,10 @@ use crate::{
|
|||||||
},
|
},
|
||||||
symbol_resolver::{SymbolValue, ValueEnum},
|
symbol_resolver::{SymbolValue, ValueEnum},
|
||||||
toplevel::{DefinitionId, TopLevelDef},
|
toplevel::{DefinitionId, TopLevelDef},
|
||||||
typecheck::typedef::{FunSignature, FuncArg, Type, TypeEnum, Unifier},
|
typecheck::{
|
||||||
|
typedef::{FunSignature, FuncArg, Type, TypeEnum, Unifier},
|
||||||
|
magic_methods::{binop_name, binop_assign_name},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use inkwell::{
|
use inkwell::{
|
||||||
AddressSpace,
|
AddressSpace,
|
||||||
@ -91,6 +94,7 @@ impl<'ctx, 'a> CodeGenContext<'ctx, 'a> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
generator: &mut dyn CodeGenerator,
|
generator: &mut dyn CodeGenerator,
|
||||||
val: &SymbolValue,
|
val: &SymbolValue,
|
||||||
|
ty: Type,
|
||||||
) -> BasicValueEnum<'ctx> {
|
) -> BasicValueEnum<'ctx> {
|
||||||
match val {
|
match val {
|
||||||
SymbolValue::I32(v) => self.ctx.i32_type().const_int(*v as u64, true).into(),
|
SymbolValue::I32(v) => self.ctx.i32_type().const_int(*v as u64, true).into(),
|
||||||
@ -107,7 +111,7 @@ impl<'ctx, 'a> CodeGenContext<'ctx, 'a> {
|
|||||||
ty.const_named_struct(&[str_ptr, size.into()]).into()
|
ty.const_named_struct(&[str_ptr, size.into()]).into()
|
||||||
}
|
}
|
||||||
SymbolValue::Tuple(ls) => {
|
SymbolValue::Tuple(ls) => {
|
||||||
let vals = ls.iter().map(|v| self.gen_symbol_val(generator, v)).collect_vec();
|
let vals = ls.iter().map(|v| self.gen_symbol_val(generator, v, ty)).collect_vec();
|
||||||
let fields = vals.iter().map(|v| v.get_type()).collect_vec();
|
let fields = vals.iter().map(|v| v.get_type()).collect_vec();
|
||||||
let ty = self.ctx.struct_type(&fields, false);
|
let ty = self.ctx.struct_type(&fields, false);
|
||||||
let ptr = self.builder.build_alloca(ty, "tuple");
|
let ptr = self.builder.build_alloca(ty, "tuple");
|
||||||
@ -124,6 +128,33 @@ impl<'ctx, 'a> CodeGenContext<'ctx, 'a> {
|
|||||||
}
|
}
|
||||||
self.builder.build_load(ptr, "tup_val")
|
self.builder.build_load(ptr, "tup_val")
|
||||||
}
|
}
|
||||||
|
SymbolValue::OptionSome(v) => {
|
||||||
|
let ty = match self.unifier.get_ty_immutable(ty).as_ref() {
|
||||||
|
TypeEnum::TObj { obj_id, params, .. }
|
||||||
|
if *obj_id == self.primitives.option.get_obj_id(&self.unifier) =>
|
||||||
|
{
|
||||||
|
*params.iter().next().unwrap().1
|
||||||
|
}
|
||||||
|
_ => unreachable!("must be option type"),
|
||||||
|
};
|
||||||
|
let val = self.gen_symbol_val(generator, v, ty);
|
||||||
|
let ptr = self.builder.build_alloca(val.get_type(), "default_opt_some");
|
||||||
|
self.builder.build_store(ptr, val);
|
||||||
|
ptr.into()
|
||||||
|
}
|
||||||
|
SymbolValue::OptionNone => {
|
||||||
|
let ty = match self.unifier.get_ty_immutable(ty).as_ref() {
|
||||||
|
TypeEnum::TObj { obj_id, params, .. }
|
||||||
|
if *obj_id == self.primitives.option.get_obj_id(&self.unifier) =>
|
||||||
|
{
|
||||||
|
*params.iter().next().unwrap().1
|
||||||
|
}
|
||||||
|
_ => unreachable!("must be option type"),
|
||||||
|
};
|
||||||
|
let actual_ptr_type =
|
||||||
|
self.get_llvm_type(generator, ty).ptr_type(AddressSpace::Generic);
|
||||||
|
actual_ptr_type.const_null().into()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,6 +165,7 @@ impl<'ctx, 'a> CodeGenContext<'ctx, 'a> {
|
|||||||
) -> BasicTypeEnum<'ctx> {
|
) -> BasicTypeEnum<'ctx> {
|
||||||
get_llvm_type(
|
get_llvm_type(
|
||||||
self.ctx,
|
self.ctx,
|
||||||
|
&self.module,
|
||||||
generator,
|
generator,
|
||||||
&mut self.unifier,
|
&mut self.unifier,
|
||||||
self.top_level,
|
self.top_level,
|
||||||
@ -206,6 +238,7 @@ impl<'ctx, 'a> CodeGenContext<'ctx, 'a> {
|
|||||||
|
|
||||||
pub fn gen_int_ops(
|
pub fn gen_int_ops(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
generator: &mut dyn CodeGenerator,
|
||||||
op: &Operator,
|
op: &Operator,
|
||||||
lhs: BasicValueEnum<'ctx>,
|
lhs: BasicValueEnum<'ctx>,
|
||||||
rhs: BasicValueEnum<'ctx>,
|
rhs: BasicValueEnum<'ctx>,
|
||||||
@ -241,7 +274,7 @@ impl<'ctx, 'a> CodeGenContext<'ctx, 'a> {
|
|||||||
(Operator::RShift, _) => self.builder.build_right_shift(lhs, rhs, true, "rshift").into(),
|
(Operator::RShift, _) => self.builder.build_right_shift(lhs, rhs, true, "rshift").into(),
|
||||||
(Operator::FloorDiv, true) => self.builder.build_int_signed_div(lhs, rhs, "floordiv").into(),
|
(Operator::FloorDiv, true) => self.builder.build_int_signed_div(lhs, rhs, "floordiv").into(),
|
||||||
(Operator::FloorDiv, false) => self.builder.build_int_unsigned_div(lhs, rhs, "floordiv").into(),
|
(Operator::FloorDiv, false) => self.builder.build_int_unsigned_div(lhs, rhs, "floordiv").into(),
|
||||||
(Operator::Pow, s) => integer_power(self, lhs, rhs, s).into(),
|
(Operator::Pow, s) => integer_power(generator, self, lhs, rhs, s).into(),
|
||||||
// special implementation?
|
// special implementation?
|
||||||
(Operator::MatMult, _) => unreachable!(),
|
(Operator::MatMult, _) => unreachable!(),
|
||||||
}
|
}
|
||||||
@ -355,17 +388,17 @@ impl<'ctx, 'a> CodeGenContext<'ctx, 'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn gen_string<G: CodeGenerator, S: Into<String>>(
|
pub fn gen_string<S: Into<String>>(
|
||||||
&mut self,
|
&mut self,
|
||||||
generator: &mut G,
|
generator: &mut dyn CodeGenerator,
|
||||||
s: S,
|
s: S,
|
||||||
) -> BasicValueEnum<'ctx> {
|
) -> BasicValueEnum<'ctx> {
|
||||||
self.gen_const(generator, &nac3parser::ast::Constant::Str(s.into()), self.primitives.str)
|
self.gen_const(generator, &nac3parser::ast::Constant::Str(s.into()), self.primitives.str)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn raise_exn<G: CodeGenerator>(
|
pub fn raise_exn(
|
||||||
&mut self,
|
&mut self,
|
||||||
generator: &mut G,
|
generator: &mut dyn CodeGenerator,
|
||||||
name: &str,
|
name: &str,
|
||||||
msg: BasicValueEnum<'ctx>,
|
msg: BasicValueEnum<'ctx>,
|
||||||
params: [Option<IntValue<'ctx>>; 3],
|
params: [Option<IntValue<'ctx>>; 3],
|
||||||
@ -402,20 +435,34 @@ impl<'ctx, 'a> CodeGenContext<'ctx, 'a> {
|
|||||||
gen_raise(generator, self, Some(&zelf.into()), loc);
|
gen_raise(generator, self, Some(&zelf.into()), loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn make_assert<G: CodeGenerator>(
|
pub fn make_assert(
|
||||||
&mut self,
|
&mut self,
|
||||||
generator: &mut G,
|
generator: &mut dyn CodeGenerator,
|
||||||
cond: IntValue<'ctx>,
|
cond: IntValue<'ctx>,
|
||||||
err_name: &str,
|
err_name: &str,
|
||||||
err_msg: &str,
|
err_msg: &str,
|
||||||
params: [Option<IntValue<'ctx>>; 3],
|
params: [Option<IntValue<'ctx>>; 3],
|
||||||
loc: Location,
|
loc: Location,
|
||||||
|
) {
|
||||||
|
let err_msg = self.gen_string(generator, err_msg);
|
||||||
|
self.make_assert_impl(generator, cond, err_name, err_msg, params, loc)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn make_assert_impl(
|
||||||
|
&mut self,
|
||||||
|
generator: &mut dyn CodeGenerator,
|
||||||
|
cond: IntValue<'ctx>,
|
||||||
|
err_name: &str,
|
||||||
|
err_msg: BasicValueEnum<'ctx>,
|
||||||
|
params: [Option<IntValue<'ctx>>; 3],
|
||||||
|
loc: Location,
|
||||||
) {
|
) {
|
||||||
let i1 = self.ctx.bool_type();
|
let i1 = self.ctx.bool_type();
|
||||||
let i1_true = i1.const_all_ones();
|
let i1_true = i1.const_all_ones();
|
||||||
let expect_fun = self.module.get_function("llvm.expect.i1").unwrap_or_else(|| {
|
let expect_fun = self.module.get_function("llvm.expect.i1").unwrap_or_else(|| {
|
||||||
self.module.add_function(
|
self.module.add_function(
|
||||||
"llvm.expect",
|
// FIXME:
|
||||||
|
"llvm.expect.i1",
|
||||||
i1.fn_type(&[i1.into(), i1.into()], false),
|
i1.fn_type(&[i1.into(), i1.into()], false),
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
@ -436,7 +483,6 @@ impl<'ctx, 'a> CodeGenContext<'ctx, 'a> {
|
|||||||
let exn_block = self.ctx.append_basic_block(current_fun, "fail");
|
let exn_block = self.ctx.append_basic_block(current_fun, "fail");
|
||||||
self.builder.build_conditional_branch(cond, then_block, exn_block);
|
self.builder.build_conditional_branch(cond, then_block, exn_block);
|
||||||
self.builder.position_at_end(exn_block);
|
self.builder.position_at_end(exn_block);
|
||||||
let err_msg = self.gen_string(generator, err_msg);
|
|
||||||
self.raise_exn(generator, err_name, err_msg, params, loc);
|
self.raise_exn(generator, err_name, err_msg, params, loc);
|
||||||
self.builder.position_at_end(then_block);
|
self.builder.position_at_end(then_block);
|
||||||
}
|
}
|
||||||
@ -452,12 +498,7 @@ pub fn gen_constructor<'ctx, 'a, G: CodeGenerator>(
|
|||||||
match def {
|
match def {
|
||||||
TopLevelDef::Class { methods, .. } => {
|
TopLevelDef::Class { methods, .. } => {
|
||||||
// TODO: what about other fields that require alloca?
|
// TODO: what about other fields that require alloca?
|
||||||
let mut fun_id = None;
|
let fun_id = methods.iter().find(|method| method.0 == "__init__".into()).and_then(|method| Some(method.2));
|
||||||
for (name, _, id) in methods.iter() {
|
|
||||||
if name == &"__init__".into() {
|
|
||||||
fun_id = Some(*id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let ty = ctx.get_llvm_type(generator, signature.ret).into_pointer_type();
|
let ty = ctx.get_llvm_type(generator, signature.ret).into_pointer_type();
|
||||||
let zelf_ty: BasicTypeEnum = ty.get_element_type().try_into().unwrap();
|
let zelf_ty: BasicTypeEnum = ty.get_element_type().try_into().unwrap();
|
||||||
let zelf: BasicValueEnum<'ctx> = ctx.builder.build_alloca(zelf_ty, "alloca").into();
|
let zelf: BasicValueEnum<'ctx> = ctx.builder.build_alloca(zelf_ty, "alloca").into();
|
||||||
@ -593,19 +634,19 @@ pub fn gen_call<'ctx, 'a, G: CodeGenerator>(
|
|||||||
}
|
}
|
||||||
mapping.insert(
|
mapping.insert(
|
||||||
k.name,
|
k.name,
|
||||||
ctx.gen_symbol_val(generator, &k.default_value.unwrap()).into(),
|
ctx.gen_symbol_val(generator, &k.default_value.unwrap(), k.ty).into(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// reorder the parameters
|
// reorder the parameters
|
||||||
let mut real_params =
|
let mut real_params =
|
||||||
fun.0.args.iter().map(|arg| mapping.remove(&arg.name).unwrap()).collect_vec();
|
fun.0.args.iter().map(|arg| (mapping.remove(&arg.name).unwrap(), arg.ty)).collect_vec();
|
||||||
if let Some(obj) = &obj {
|
if let Some(obj) = &obj {
|
||||||
real_params.insert(0, obj.1.clone());
|
real_params.insert(0, (obj.1.clone(), obj.0));
|
||||||
}
|
}
|
||||||
let static_params = real_params
|
let static_params = real_params
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.filter_map(|(i, v)| {
|
.filter_map(|(i, (v, _))| {
|
||||||
if let ValueEnum::Static(s) = v {
|
if let ValueEnum::Static(s) = v {
|
||||||
Some((i, s.clone()))
|
Some((i, s.clone()))
|
||||||
} else {
|
} else {
|
||||||
@ -637,7 +678,7 @@ pub fn gen_call<'ctx, 'a, G: CodeGenerator>(
|
|||||||
};
|
};
|
||||||
param_vals = real_params
|
param_vals = real_params
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|p| p.to_basic_value_enum(ctx, generator))
|
.map(|(p, t)| p.to_basic_value_enum(ctx, generator, t))
|
||||||
.collect::<Result<Vec<_>, String>>()?;
|
.collect::<Result<Vec<_>, String>>()?;
|
||||||
instance_to_symbol.get(&key).cloned().ok_or_else(|| "".into())
|
instance_to_symbol.get(&key).cloned().ok_or_else(|| "".into())
|
||||||
}
|
}
|
||||||
@ -654,6 +695,7 @@ pub fn gen_call<'ctx, 'a, G: CodeGenerator>(
|
|||||||
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 });
|
||||||
}
|
}
|
||||||
|
// println!("\n2=======getting types for func `{}`=======", symbol);
|
||||||
let ret_type = if ctx.unifier.unioned(fun.0.ret, ctx.primitives.none) {
|
let ret_type = if ctx.unifier.unioned(fun.0.ret, ctx.primitives.none) {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
@ -676,6 +718,7 @@ pub fn gen_call<'ctx, 'a, G: CodeGenerator>(
|
|||||||
Some(ret_type) if !has_sret => ret_type.fn_type(¶ms, false),
|
Some(ret_type) if !has_sret => ret_type.fn_type(¶ms, false),
|
||||||
_ => ctx.ctx.void_type().fn_type(¶ms, false)
|
_ => ctx.ctx.void_type().fn_type(¶ms, false)
|
||||||
};
|
};
|
||||||
|
// println!("2=======got types for func `{}`: {}=======\n", symbol, fun_ty.print_to_string().to_string());
|
||||||
let fun_val = ctx.module.add_function(&symbol, fun_ty, None);
|
let fun_val = ctx.module.add_function(&symbol, fun_ty, None);
|
||||||
let offset = if has_sret {
|
let offset = if has_sret {
|
||||||
fun_val.add_attribute(AttributeLoc::Param(0),
|
fun_val.add_attribute(AttributeLoc::Param(0),
|
||||||
@ -750,7 +793,7 @@ pub fn gen_comprehension<'ctx, 'a, G: CodeGenerator>(
|
|||||||
let cont_bb = ctx.ctx.append_basic_block(current, "cont");
|
let cont_bb = ctx.ctx.append_basic_block(current, "cont");
|
||||||
|
|
||||||
let Comprehension { target, iter, ifs, .. } = &generators[0];
|
let Comprehension { target, iter, ifs, .. } = &generators[0];
|
||||||
let iter_val = generator.gen_expr(ctx, iter)?.unwrap().to_basic_value_enum(ctx, generator)?;
|
let iter_val = generator.gen_expr(ctx, iter)?.unwrap().to_basic_value_enum(ctx, generator, iter.custom.unwrap())?;
|
||||||
let int32 = ctx.ctx.i32_type();
|
let int32 = ctx.ctx.i32_type();
|
||||||
let size_t = generator.get_size_type(ctx.ctx);
|
let size_t = generator.get_size_type(ctx.ctx);
|
||||||
let zero_size_t = size_t.const_zero();
|
let zero_size_t = size_t.const_zero();
|
||||||
@ -855,7 +898,7 @@ pub fn gen_comprehension<'ctx, 'a, G: CodeGenerator>(
|
|||||||
let result = generator
|
let result = generator
|
||||||
.gen_expr(ctx, cond)?
|
.gen_expr(ctx, cond)?
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_basic_value_enum(ctx, generator)?
|
.to_basic_value_enum(ctx, generator, cond.custom.unwrap())?
|
||||||
.into_int_value();
|
.into_int_value();
|
||||||
let succ = ctx.ctx.append_basic_block(current, "then");
|
let succ = ctx.ctx.append_basic_block(current, "then");
|
||||||
ctx.builder.build_conditional_branch(result, succ, test_bb);
|
ctx.builder.build_conditional_branch(result, succ, test_bb);
|
||||||
@ -864,7 +907,7 @@ pub fn gen_comprehension<'ctx, 'a, G: CodeGenerator>(
|
|||||||
let elem = generator.gen_expr(ctx, elt)?.unwrap();
|
let elem = generator.gen_expr(ctx, elt)?.unwrap();
|
||||||
let i = ctx.builder.build_load(index, "i").into_int_value();
|
let i = ctx.builder.build_load(index, "i").into_int_value();
|
||||||
let elem_ptr = unsafe { ctx.builder.build_gep(list_content, &[i], "elem_ptr") };
|
let elem_ptr = unsafe { ctx.builder.build_gep(list_content, &[i], "elem_ptr") };
|
||||||
let val = elem.to_basic_value_enum(ctx, generator)?;
|
let val = elem.to_basic_value_enum(ctx, generator, elt.custom.unwrap())?;
|
||||||
ctx.builder.build_store(elem_ptr, val);
|
ctx.builder.build_store(elem_ptr, val);
|
||||||
ctx.builder
|
ctx.builder
|
||||||
.build_store(index, ctx.builder.build_int_add(i, size_t.const_int(1, false), "inc"));
|
.build_store(index, ctx.builder.build_int_add(i, size_t.const_int(1, false), "inc"));
|
||||||
@ -886,41 +929,94 @@ pub fn gen_binop_expr<'ctx, 'a, G: CodeGenerator>(
|
|||||||
left: &Expr<Option<Type>>,
|
left: &Expr<Option<Type>>,
|
||||||
op: &Operator,
|
op: &Operator,
|
||||||
right: &Expr<Option<Type>>,
|
right: &Expr<Option<Type>>,
|
||||||
) -> Result<ValueEnum<'ctx>, String> {
|
loc: Location,
|
||||||
|
is_aug_assign: bool,
|
||||||
|
) -> Result<Option<ValueEnum<'ctx>>, String> {
|
||||||
let ty1 = ctx.unifier.get_representative(left.custom.unwrap());
|
let ty1 = ctx.unifier.get_representative(left.custom.unwrap());
|
||||||
let ty2 = ctx.unifier.get_representative(right.custom.unwrap());
|
let ty2 = ctx.unifier.get_representative(right.custom.unwrap());
|
||||||
let left = generator.gen_expr(ctx, left)?.unwrap().to_basic_value_enum(ctx, generator)?;
|
let left_val = generator
|
||||||
let right = generator.gen_expr(ctx, right)?.unwrap().to_basic_value_enum(ctx, generator)?;
|
.gen_expr(ctx, left)?
|
||||||
|
.unwrap()
|
||||||
|
.to_basic_value_enum(ctx, generator, left.custom.unwrap())?;
|
||||||
|
let right_val = generator
|
||||||
|
.gen_expr(ctx, right)?
|
||||||
|
.unwrap()
|
||||||
|
.to_basic_value_enum(ctx, generator, right.custom.unwrap())?;
|
||||||
|
|
||||||
// we can directly compare the types, because we've got their representatives
|
// we can directly compare the types, because we've got their representatives
|
||||||
// which would be unchanged until further unification, which we would never do
|
// which would be unchanged until further unification, which we would never do
|
||||||
// when doing code generation for function instances
|
// when doing code generation for function instances
|
||||||
Ok(if ty1 == ty2 && [ctx.primitives.int32, ctx.primitives.int64].contains(&ty1) {
|
if ty1 == ty2 && [ctx.primitives.int32, ctx.primitives.int64].contains(&ty1) {
|
||||||
ctx.gen_int_ops(op, left, right, true)
|
Ok(Some(ctx.gen_int_ops(generator, op, left_val, right_val, true).into()))
|
||||||
} else if ty1 == ty2 && [ctx.primitives.uint32, ctx.primitives.uint64].contains(&ty1) {
|
} else if ty1 == ty2 && [ctx.primitives.uint32, ctx.primitives.uint64].contains(&ty1) {
|
||||||
ctx.gen_int_ops(op, left, right, false)
|
Ok(Some(ctx.gen_int_ops(generator, op, left_val, right_val, false).into()))
|
||||||
} else if ty1 == ty2 && ctx.primitives.float == ty1 {
|
} else if ty1 == ty2 && ctx.primitives.float == ty1 {
|
||||||
ctx.gen_float_ops(op, left, right)
|
Ok(Some(ctx.gen_float_ops(op, left_val, right_val).into()))
|
||||||
} else if ty1 == ctx.primitives.float && ty2 == ctx.primitives.int32 {
|
} else if ty1 == ctx.primitives.float && ty2 == ctx.primitives.int32 {
|
||||||
// Pow is the only operator that would pass typecheck between float and int
|
// Pow is the only operator that would pass typecheck between float and int
|
||||||
assert!(*op == Operator::Pow);
|
assert!(*op == Operator::Pow);
|
||||||
// TODO: throw exception when rhs is out of i16 bound
|
let i32_t = ctx.ctx.i32_type();
|
||||||
// since llvm intrinsic only support to i16 for f64
|
let pow_intr = ctx.module.get_function("llvm.powi.f64.i32").unwrap_or_else(|| {
|
||||||
let i16_t = ctx.ctx.i16_type();
|
|
||||||
let pow_intr = ctx.module.get_function("llvm.powi.f64.i16").unwrap_or_else(|| {
|
|
||||||
let f64_t = ctx.ctx.f64_type();
|
let f64_t = ctx.ctx.f64_type();
|
||||||
let ty = f64_t.fn_type(&[f64_t.into(), i16_t.into()], false);
|
let ty = f64_t.fn_type(&[f64_t.into(), i32_t.into()], false);
|
||||||
ctx.module.add_function("llvm.powi.f64.i16", ty, None)
|
ctx.module.add_function("llvm.powi.f64.i32", ty, None)
|
||||||
});
|
});
|
||||||
let right = ctx.builder.build_int_truncate(right.into_int_value(), i16_t, "r_pow");
|
let res = ctx.builder
|
||||||
ctx.builder
|
.build_call(pow_intr, &[left_val.into(), right_val.into()], "f_pow_i")
|
||||||
.build_call(pow_intr, &[left.into(), right.into()], "f_pow_i")
|
|
||||||
.try_as_basic_value()
|
.try_as_basic_value()
|
||||||
.unwrap_left()
|
.unwrap_left();
|
||||||
|
Ok(Some(res.into()))
|
||||||
} else {
|
} else {
|
||||||
unimplemented!()
|
let (op_name, id) = if let TypeEnum::TObj { fields, obj_id, .. } =
|
||||||
|
ctx.unifier.get_ty_immutable(left.custom.unwrap()).as_ref()
|
||||||
|
{
|
||||||
|
let (binop_name, binop_assign_name) = (
|
||||||
|
binop_name(op).into(),
|
||||||
|
binop_assign_name(op).into()
|
||||||
|
);
|
||||||
|
// if is aug_assign, try aug_assign operator first
|
||||||
|
if is_aug_assign && fields.contains_key(&binop_assign_name) {
|
||||||
|
(binop_assign_name, *obj_id)
|
||||||
|
} else {
|
||||||
|
(binop_name, *obj_id)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
unreachable!("must be tobj")
|
||||||
|
};
|
||||||
|
let signature = match ctx.calls.get(&loc.into()) {
|
||||||
|
Some(call) => ctx.unifier.get_call_signature(*call).unwrap(),
|
||||||
|
None => {
|
||||||
|
if let TypeEnum::TObj { fields, .. } =
|
||||||
|
ctx.unifier.get_ty_immutable(left.custom.unwrap()).as_ref()
|
||||||
|
{
|
||||||
|
let fn_ty = fields.get(&op_name).unwrap().0;
|
||||||
|
if let TypeEnum::TFunc(sig) = ctx.unifier.get_ty_immutable(fn_ty).as_ref() {
|
||||||
|
sig.clone()
|
||||||
|
} else {
|
||||||
|
unreachable!("must be func sig")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
unreachable!("must be tobj")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
let fun_id = {
|
||||||
|
let defs = ctx.top_level.definitions.read();
|
||||||
|
let obj_def = defs.get(id.0).unwrap().read();
|
||||||
|
if let TopLevelDef::Class { methods, .. } = &*obj_def {
|
||||||
|
methods.iter().find(|method| method.0 == op_name).unwrap().2
|
||||||
|
} else {
|
||||||
|
unreachable!()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
generator
|
||||||
|
.gen_call(
|
||||||
|
ctx,
|
||||||
|
Some((left.custom.unwrap(), left_val.into())),
|
||||||
|
(&signature, fun_id),
|
||||||
|
vec![(None, right_val.into())],
|
||||||
|
).map(|f| f.map(|f| f.into()))
|
||||||
}
|
}
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn gen_expr<'ctx, 'a, G: CodeGenerator>(
|
pub fn gen_expr<'ctx, 'a, G: CodeGenerator>(
|
||||||
@ -928,8 +1024,19 @@ pub fn gen_expr<'ctx, 'a, G: CodeGenerator>(
|
|||||||
ctx: &mut CodeGenContext<'ctx, 'a>,
|
ctx: &mut CodeGenContext<'ctx, 'a>,
|
||||||
expr: &Expr<Option<Type>>,
|
expr: &Expr<Option<Type>>,
|
||||||
) -> Result<Option<ValueEnum<'ctx>>, String> {
|
) -> Result<Option<ValueEnum<'ctx>>, String> {
|
||||||
|
ctx.current_loc = expr.location;
|
||||||
let int32 = ctx.ctx.i32_type();
|
let int32 = ctx.ctx.i32_type();
|
||||||
let zero = int32.const_int(0, false);
|
let zero = int32.const_int(0, false);
|
||||||
|
|
||||||
|
let loc = ctx.debug_info.0.create_debug_location(
|
||||||
|
ctx.ctx,
|
||||||
|
ctx.current_loc.row as u32,
|
||||||
|
ctx.current_loc.column as u32,
|
||||||
|
ctx.debug_info.2,
|
||||||
|
None,
|
||||||
|
);
|
||||||
|
ctx.builder.set_current_debug_location(ctx.ctx, loc);
|
||||||
|
|
||||||
Ok(Some(match &expr.node {
|
Ok(Some(match &expr.node {
|
||||||
ExprKind::Constant { value, .. } => {
|
ExprKind::Constant { value, .. } => {
|
||||||
let ty = expr.custom.unwrap();
|
let ty = expr.custom.unwrap();
|
||||||
@ -956,30 +1063,7 @@ pub fn gen_expr<'ctx, 'a, G: CodeGenerator>(
|
|||||||
Some((_, Some(static_value), _)) => ValueEnum::Static(static_value.clone()),
|
Some((_, Some(static_value), _)) => ValueEnum::Static(static_value.clone()),
|
||||||
None => {
|
None => {
|
||||||
let resolver = ctx.resolver.clone();
|
let resolver = ctx.resolver.clone();
|
||||||
let val = resolver.get_symbol_value(*id, ctx).unwrap();
|
resolver.get_symbol_value(*id, ctx).unwrap()
|
||||||
// if is tuple, need to deref it to handle tuple as value
|
|
||||||
// if is option, need to cast pointer to handle None
|
|
||||||
match (
|
|
||||||
&*ctx.unifier.get_ty(expr.custom.unwrap()),
|
|
||||||
resolver
|
|
||||||
.get_symbol_value(*id, ctx)
|
|
||||||
.unwrap()
|
|
||||||
.to_basic_value_enum(ctx, generator)?,
|
|
||||||
) {
|
|
||||||
(TypeEnum::TTuple { .. }, BasicValueEnum::PointerValue(ptr)) => {
|
|
||||||
ctx.builder.build_load(ptr, "tup_val").into()
|
|
||||||
}
|
|
||||||
(TypeEnum::TObj { obj_id, params, .. }, BasicValueEnum::PointerValue(ptr))
|
|
||||||
if *obj_id == ctx.primitives.option.get_obj_id(&ctx.unifier) => {
|
|
||||||
let actual_ptr_ty = ctx.get_llvm_type(
|
|
||||||
generator,
|
|
||||||
*params.iter().next().unwrap().1,
|
|
||||||
)
|
|
||||||
.ptr_type(AddressSpace::Generic);
|
|
||||||
ctx.builder.build_bitcast(ptr, actual_ptr_ty, "option_ptr_cast").into()
|
|
||||||
}
|
|
||||||
_ => val,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ExprKind::List { elts, .. } => {
|
ExprKind::List { elts, .. } => {
|
||||||
@ -990,7 +1074,10 @@ pub fn gen_expr<'ctx, 'a, G: CodeGenerator>(
|
|||||||
.map(|x| {
|
.map(|x| {
|
||||||
generator
|
generator
|
||||||
.gen_expr(ctx, x)
|
.gen_expr(ctx, x)
|
||||||
.map_or_else(|e| Err(e), |v| v.unwrap().to_basic_value_enum(ctx, generator))
|
.map_or_else(
|
||||||
|
Err,
|
||||||
|
|v| v.unwrap().to_basic_value_enum(ctx, generator, x.custom.unwrap())
|
||||||
|
)
|
||||||
})
|
})
|
||||||
.collect::<Result<Vec<_>, _>>()?;
|
.collect::<Result<Vec<_>, _>>()?;
|
||||||
let ty = if elements.is_empty() {
|
let ty = if elements.is_empty() {
|
||||||
@ -1023,7 +1110,7 @@ pub fn gen_expr<'ctx, 'a, G: CodeGenerator>(
|
|||||||
.map(|x| {
|
.map(|x| {
|
||||||
generator
|
generator
|
||||||
.gen_expr(ctx, x)
|
.gen_expr(ctx, x)
|
||||||
.map_or_else(|e| Err(e), |v| v.unwrap().to_basic_value_enum(ctx, generator))
|
.map_or_else(Err, |v| v.unwrap().to_basic_value_enum(ctx, generator, x.custom.unwrap()))
|
||||||
})
|
})
|
||||||
.collect::<Result<Vec<_>, _>>()?;
|
.collect::<Result<Vec<_>, _>>()?;
|
||||||
let element_ty = element_val.iter().map(BasicValueEnum::get_type).collect_vec();
|
let element_ty = element_val.iter().map(BasicValueEnum::get_type).collect_vec();
|
||||||
@ -1045,13 +1132,13 @@ pub fn gen_expr<'ctx, 'a, G: CodeGenerator>(
|
|||||||
// note that we would handle class methods directly in calls
|
// note that we would handle class methods directly in calls
|
||||||
match generator.gen_expr(ctx, value)?.unwrap() {
|
match generator.gen_expr(ctx, value)?.unwrap() {
|
||||||
ValueEnum::Static(v) => v.get_field(*attr, ctx).map_or_else(|| {
|
ValueEnum::Static(v) => v.get_field(*attr, ctx).map_or_else(|| {
|
||||||
let v = v.to_basic_value_enum(ctx, generator)?;
|
let v = v.to_basic_value_enum(ctx, generator, value.custom.unwrap())?;
|
||||||
let index = ctx.get_attr_index(value.custom.unwrap(), *attr);
|
let index = ctx.get_attr_index(value.custom.unwrap(), *attr);
|
||||||
Ok(ValueEnum::Dynamic(ctx.build_gep_and_load(
|
Ok(ValueEnum::Dynamic(ctx.build_gep_and_load(
|
||||||
v.into_pointer_value(),
|
v.into_pointer_value(),
|
||||||
&[zero, int32.const_int(index as u64, false)],
|
&[zero, int32.const_int(index as u64, false)],
|
||||||
))) as Result<_, String>
|
))) as Result<_, String>
|
||||||
}, |v| Ok(v))?,
|
}, Ok)?,
|
||||||
ValueEnum::Dynamic(v) => {
|
ValueEnum::Dynamic(v) => {
|
||||||
let index = ctx.get_attr_index(value.custom.unwrap(), *attr);
|
let index = ctx.get_attr_index(value.custom.unwrap(), *attr);
|
||||||
ValueEnum::Dynamic(ctx.build_gep_and_load(
|
ValueEnum::Dynamic(ctx.build_gep_and_load(
|
||||||
@ -1066,7 +1153,7 @@ pub fn gen_expr<'ctx, 'a, G: CodeGenerator>(
|
|||||||
let left = generator
|
let left = generator
|
||||||
.gen_expr(ctx, &values[0])?
|
.gen_expr(ctx, &values[0])?
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_basic_value_enum(ctx, generator)?
|
.to_basic_value_enum(ctx, generator, values[0].custom.unwrap())?
|
||||||
.into_int_value();
|
.into_int_value();
|
||||||
let current = ctx.builder.get_insert_block().unwrap().get_parent().unwrap();
|
let current = ctx.builder.get_insert_block().unwrap().get_parent().unwrap();
|
||||||
let a_bb = ctx.ctx.append_basic_block(current, "a");
|
let a_bb = ctx.ctx.append_basic_block(current, "a");
|
||||||
@ -1082,7 +1169,7 @@ pub fn gen_expr<'ctx, 'a, G: CodeGenerator>(
|
|||||||
let b = generator
|
let b = generator
|
||||||
.gen_expr(ctx, &values[1])?
|
.gen_expr(ctx, &values[1])?
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_basic_value_enum(ctx, generator)?
|
.to_basic_value_enum(ctx, generator, values[1].custom.unwrap())?
|
||||||
.into_int_value();
|
.into_int_value();
|
||||||
ctx.builder.build_unconditional_branch(cont_bb);
|
ctx.builder.build_unconditional_branch(cont_bb);
|
||||||
(a, b)
|
(a, b)
|
||||||
@ -1092,7 +1179,7 @@ pub fn gen_expr<'ctx, 'a, G: CodeGenerator>(
|
|||||||
let a = generator
|
let a = generator
|
||||||
.gen_expr(ctx, &values[1])?
|
.gen_expr(ctx, &values[1])?
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_basic_value_enum(ctx, generator)?
|
.to_basic_value_enum(ctx, generator, values[1].custom.unwrap())?
|
||||||
.into_int_value();
|
.into_int_value();
|
||||||
ctx.builder.build_unconditional_branch(cont_bb);
|
ctx.builder.build_unconditional_branch(cont_bb);
|
||||||
ctx.builder.position_at_end(b_bb);
|
ctx.builder.position_at_end(b_bb);
|
||||||
@ -1106,11 +1193,15 @@ pub fn gen_expr<'ctx, 'a, G: CodeGenerator>(
|
|||||||
phi.add_incoming(&[(&a, a_bb), (&b, b_bb)]);
|
phi.add_incoming(&[(&a, a_bb), (&b, b_bb)]);
|
||||||
phi.as_basic_value().into()
|
phi.as_basic_value().into()
|
||||||
}
|
}
|
||||||
ExprKind::BinOp { op, left, right } => gen_binop_expr(generator, ctx, left, op, right)?,
|
ExprKind::BinOp { op, left, right } => {
|
||||||
|
return gen_binop_expr(generator, ctx, left, op, right, expr.location, false);
|
||||||
|
}
|
||||||
ExprKind::UnaryOp { op, operand } => {
|
ExprKind::UnaryOp { op, operand } => {
|
||||||
let ty = ctx.unifier.get_representative(operand.custom.unwrap());
|
let ty = ctx.unifier.get_representative(operand.custom.unwrap());
|
||||||
let val =
|
let val =
|
||||||
generator.gen_expr(ctx, operand)?.unwrap().to_basic_value_enum(ctx, generator)?;
|
generator.gen_expr(ctx, operand)?
|
||||||
|
.unwrap()
|
||||||
|
.to_basic_value_enum(ctx, generator, operand.custom.unwrap())?;
|
||||||
if ty == ctx.primitives.bool {
|
if ty == ctx.primitives.bool {
|
||||||
let val = val.into_int_value();
|
let val = val.into_int_value();
|
||||||
match op {
|
match op {
|
||||||
@ -1170,11 +1261,11 @@ pub fn gen_expr<'ctx, 'a, G: CodeGenerator>(
|
|||||||
generator
|
generator
|
||||||
.gen_expr(ctx, lhs)?
|
.gen_expr(ctx, lhs)?
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_basic_value_enum(ctx, generator)?,
|
.to_basic_value_enum(ctx, generator, lhs.custom.unwrap())?,
|
||||||
generator
|
generator
|
||||||
.gen_expr(ctx, rhs)?
|
.gen_expr(ctx, rhs)?
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_basic_value_enum(ctx, generator)?,
|
.to_basic_value_enum(ctx, generator, rhs.custom.unwrap())?,
|
||||||
) {
|
) {
|
||||||
(lhs, rhs)
|
(lhs, rhs)
|
||||||
} else {
|
} else {
|
||||||
@ -1198,11 +1289,11 @@ pub fn gen_expr<'ctx, 'a, G: CodeGenerator>(
|
|||||||
generator
|
generator
|
||||||
.gen_expr(ctx, lhs)?
|
.gen_expr(ctx, lhs)?
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_basic_value_enum(ctx, generator)?,
|
.to_basic_value_enum(ctx, generator, lhs.custom.unwrap())?,
|
||||||
generator
|
generator
|
||||||
.gen_expr(ctx, rhs)?
|
.gen_expr(ctx, rhs)?
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_basic_value_enum(ctx, generator)?,
|
.to_basic_value_enum(ctx, generator, rhs.custom.unwrap())?,
|
||||||
) {
|
) {
|
||||||
(lhs, rhs)
|
(lhs, rhs)
|
||||||
} else {
|
} else {
|
||||||
@ -1230,23 +1321,46 @@ pub fn gen_expr<'ctx, 'a, G: CodeGenerator>(
|
|||||||
let test = generator
|
let test = generator
|
||||||
.gen_expr(ctx, test)?
|
.gen_expr(ctx, test)?
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_basic_value_enum(ctx, generator)?
|
.to_basic_value_enum(ctx, generator, test.custom.unwrap())?
|
||||||
.into_int_value();
|
.into_int_value();
|
||||||
|
let body_ty = body.custom.unwrap();
|
||||||
|
let is_none = ctx.unifier.get_representative(body_ty) == ctx.primitives.none;
|
||||||
|
let result = if !is_none {
|
||||||
|
let llvm_ty = ctx.get_llvm_type(generator, body_ty);
|
||||||
|
Some(ctx.builder.build_alloca(llvm_ty, "if_exp_result"))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
let current = ctx.builder.get_insert_block().unwrap().get_parent().unwrap();
|
let current = ctx.builder.get_insert_block().unwrap().get_parent().unwrap();
|
||||||
let then_bb = ctx.ctx.append_basic_block(current, "then");
|
let then_bb = ctx.ctx.append_basic_block(current, "then");
|
||||||
let else_bb = ctx.ctx.append_basic_block(current, "else");
|
let else_bb = ctx.ctx.append_basic_block(current, "else");
|
||||||
let cont_bb = ctx.ctx.append_basic_block(current, "cont");
|
let cont_bb = ctx.ctx.append_basic_block(current, "cont");
|
||||||
ctx.builder.build_conditional_branch(test, then_bb, else_bb);
|
ctx.builder.build_conditional_branch(test, then_bb, else_bb);
|
||||||
ctx.builder.position_at_end(then_bb);
|
ctx.builder.position_at_end(then_bb);
|
||||||
let a = generator.gen_expr(ctx, body)?.unwrap().to_basic_value_enum(ctx, generator)?;
|
let a = generator.gen_expr(ctx, body)?;
|
||||||
|
match result {
|
||||||
|
None => None,
|
||||||
|
Some(v) => {
|
||||||
|
let a = a.unwrap().to_basic_value_enum(ctx, generator, body.custom.unwrap())?;
|
||||||
|
Some(ctx.builder.build_store(v, a))
|
||||||
|
}
|
||||||
|
};
|
||||||
ctx.builder.build_unconditional_branch(cont_bb);
|
ctx.builder.build_unconditional_branch(cont_bb);
|
||||||
ctx.builder.position_at_end(else_bb);
|
ctx.builder.position_at_end(else_bb);
|
||||||
let b = generator.gen_expr(ctx, orelse)?.unwrap().to_basic_value_enum(ctx, generator)?;
|
let b = generator.gen_expr(ctx, orelse)?;
|
||||||
|
match result {
|
||||||
|
None => None,
|
||||||
|
Some(v) => {
|
||||||
|
let b = b.unwrap().to_basic_value_enum(ctx, generator, orelse.custom.unwrap())?;
|
||||||
|
Some(ctx.builder.build_store(v, b))
|
||||||
|
}
|
||||||
|
};
|
||||||
ctx.builder.build_unconditional_branch(cont_bb);
|
ctx.builder.build_unconditional_branch(cont_bb);
|
||||||
ctx.builder.position_at_end(cont_bb);
|
ctx.builder.position_at_end(cont_bb);
|
||||||
let phi = ctx.builder.build_phi(a.get_type(), "ifexpr");
|
match result {
|
||||||
phi.add_incoming(&[(&a, then_bb), (&b, else_bb)]);
|
None => return Ok(None),
|
||||||
phi.as_basic_value().into()
|
Some(v) => return Ok(Some(ctx.builder.build_load(v, "if_exp_val_load").into()))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ExprKind::Call { func, args, keywords } => {
|
ExprKind::Call { func, args, keywords } => {
|
||||||
let mut params = args
|
let mut params = args
|
||||||
@ -1298,35 +1412,72 @@ pub fn gen_expr<'ctx, 'a, G: CodeGenerator>(
|
|||||||
let defs = ctx.top_level.definitions.read();
|
let defs = ctx.top_level.definitions.read();
|
||||||
let obj_def = defs.get(id.0).unwrap().read();
|
let obj_def = defs.get(id.0).unwrap().read();
|
||||||
if let TopLevelDef::Class { methods, .. } = &*obj_def {
|
if let TopLevelDef::Class { methods, .. } = &*obj_def {
|
||||||
let mut fun_id = None;
|
methods.iter().find(|method| method.0 == *attr).unwrap().2
|
||||||
for (name, _, id) in methods.iter() {
|
|
||||||
if name == attr {
|
|
||||||
fun_id = Some(*id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fun_id.unwrap()
|
|
||||||
} else {
|
} else {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// directly generate code for option.unwrap
|
// directly generate code for option.unwrap
|
||||||
// since it needs location information from ast
|
// since it needs to return static value to optimize for kernel invariant
|
||||||
if attr == &"unwrap".into()
|
if attr == &"unwrap".into()
|
||||||
&& id == ctx.primitives.option.get_obj_id(&ctx.unifier)
|
&& id == ctx.primitives.option.get_obj_id(&ctx.unifier)
|
||||||
{
|
{
|
||||||
if let BasicValueEnum::PointerValue(ptr) = val.to_basic_value_enum(ctx, generator)? {
|
match val {
|
||||||
|
ValueEnum::Static(v) => match v.get_field("_nac3_option".into(), ctx) {
|
||||||
|
// if is none, raise exception directly
|
||||||
|
None => {
|
||||||
|
let err_msg = ctx.gen_string(generator, "");
|
||||||
|
let current_fun = ctx
|
||||||
|
.builder
|
||||||
|
.get_insert_block()
|
||||||
|
.unwrap()
|
||||||
|
.get_parent()
|
||||||
|
.unwrap();
|
||||||
|
let unreachable_block = ctx.ctx.append_basic_block(
|
||||||
|
current_fun,
|
||||||
|
"unwrap_none_unreachable"
|
||||||
|
);
|
||||||
|
let exn_block = ctx.ctx.append_basic_block(
|
||||||
|
current_fun,
|
||||||
|
"unwrap_none_exception"
|
||||||
|
);
|
||||||
|
ctx.builder.build_unconditional_branch(exn_block);
|
||||||
|
ctx.builder.position_at_end(exn_block);
|
||||||
|
ctx.raise_exn(
|
||||||
|
generator,
|
||||||
|
"0:UnwrapNoneError",
|
||||||
|
err_msg,
|
||||||
|
[None, None, None],
|
||||||
|
ctx.current_loc
|
||||||
|
);
|
||||||
|
ctx.builder.position_at_end(unreachable_block);
|
||||||
|
let ptr = ctx
|
||||||
|
.get_llvm_type(generator, value.custom.unwrap())
|
||||||
|
.into_pointer_type()
|
||||||
|
.const_null();
|
||||||
|
return Ok(Some(ctx.builder.build_load(
|
||||||
|
ptr,
|
||||||
|
"unwrap_none_unreachable_load"
|
||||||
|
).into()));
|
||||||
|
}
|
||||||
|
Some(v) => return Ok(Some(v)),
|
||||||
|
}
|
||||||
|
ValueEnum::Dynamic(BasicValueEnum::PointerValue(ptr)) => {
|
||||||
let not_null = ctx.builder.build_is_not_null(ptr, "unwrap_not_null");
|
let not_null = ctx.builder.build_is_not_null(ptr, "unwrap_not_null");
|
||||||
ctx.make_assert(
|
ctx.make_assert(
|
||||||
generator,
|
generator,
|
||||||
not_null,
|
not_null,
|
||||||
"0:ValueError",
|
"0:UnwrapNoneError",
|
||||||
"unwrap on none",
|
"",
|
||||||
[None, None, None],
|
[None, None, None],
|
||||||
expr.location,
|
expr.location,
|
||||||
);
|
);
|
||||||
return Ok(Some(ctx.builder.build_load(ptr, "unwrap_some").into()))
|
return Ok(Some(ctx.builder.build_load(
|
||||||
} else {
|
ptr,
|
||||||
unreachable!("option must be ptr")
|
"unwrap_some_load"
|
||||||
|
).into()))
|
||||||
|
}
|
||||||
|
_ => unreachable!("option must be static or ptr")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Ok(generator
|
return Ok(generator
|
||||||
@ -1346,7 +1497,7 @@ pub fn gen_expr<'ctx, 'a, G: CodeGenerator>(
|
|||||||
let v = generator
|
let v = generator
|
||||||
.gen_expr(ctx, value)?
|
.gen_expr(ctx, value)?
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_basic_value_enum(ctx, generator)?
|
.to_basic_value_enum(ctx, generator, value.custom.unwrap())?
|
||||||
.into_pointer_value();
|
.into_pointer_value();
|
||||||
let ty = ctx.get_llvm_type(generator, *ty);
|
let ty = ctx.get_llvm_type(generator, *ty);
|
||||||
let arr_ptr = ctx.build_gep_and_load(v, &[zero, zero]).into_pointer_value();
|
let arr_ptr = ctx.build_gep_and_load(v, &[zero, zero]).into_pointer_value();
|
||||||
@ -1355,6 +1506,7 @@ pub fn gen_expr<'ctx, 'a, G: CodeGenerator>(
|
|||||||
let (start, end, step) =
|
let (start, end, step) =
|
||||||
handle_slice_indices(lower, upper, step, ctx, generator, v)?;
|
handle_slice_indices(lower, upper, step, ctx, generator, v)?;
|
||||||
let length = calculate_len_for_slice_range(
|
let length = calculate_len_for_slice_range(
|
||||||
|
generator,
|
||||||
ctx,
|
ctx,
|
||||||
start,
|
start,
|
||||||
ctx.builder
|
ctx.builder
|
||||||
@ -1376,8 +1528,8 @@ pub fn gen_expr<'ctx, 'a, G: CodeGenerator>(
|
|||||||
let res_ind =
|
let res_ind =
|
||||||
handle_slice_indices(&None, &None, &None, ctx, generator, res_array_ret)?;
|
handle_slice_indices(&None, &None, &None, ctx, generator, res_array_ret)?;
|
||||||
list_slice_assignment(
|
list_slice_assignment(
|
||||||
|
generator,
|
||||||
ctx,
|
ctx,
|
||||||
generator.get_size_type(ctx.ctx),
|
|
||||||
ty,
|
ty,
|
||||||
res_array_ret,
|
res_array_ret,
|
||||||
res_ind,
|
res_ind,
|
||||||
@ -1392,7 +1544,7 @@ pub fn gen_expr<'ctx, 'a, G: CodeGenerator>(
|
|||||||
let raw_index = generator
|
let raw_index = generator
|
||||||
.gen_expr(ctx, slice)?
|
.gen_expr(ctx, slice)?
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_basic_value_enum(ctx, generator)?
|
.to_basic_value_enum(ctx, generator, slice.custom.unwrap())?
|
||||||
.into_int_value();
|
.into_int_value();
|
||||||
let raw_index = ctx.builder.build_int_s_extend(
|
let raw_index = ctx.builder.build_int_s_extend(
|
||||||
raw_index,
|
raw_index,
|
||||||
@ -1427,26 +1579,39 @@ pub fn gen_expr<'ctx, 'a, G: CodeGenerator>(
|
|||||||
[Some(raw_index), Some(len), None],
|
[Some(raw_index), Some(len), None],
|
||||||
expr.location,
|
expr.location,
|
||||||
);
|
);
|
||||||
ctx.build_gep_and_load(arr_ptr, &[index])
|
ctx.build_gep_and_load(arr_ptr, &[index]).into()
|
||||||
}
|
}
|
||||||
} else if let TypeEnum::TTuple { .. } = &*ctx.unifier.get_ty(value.custom.unwrap()) {
|
} else if let TypeEnum::TTuple { .. } = &*ctx.unifier.get_ty(value.custom.unwrap()) {
|
||||||
let v = generator
|
|
||||||
.gen_expr(ctx, value)?
|
|
||||||
.unwrap()
|
|
||||||
.to_basic_value_enum(ctx, generator)?
|
|
||||||
.into_struct_value();
|
|
||||||
let index: u32 =
|
let index: u32 =
|
||||||
if let ExprKind::Constant { value: ast::Constant::Int(v), .. } = &slice.node {
|
if let ExprKind::Constant { value: ast::Constant::Int(v), .. } = &slice.node {
|
||||||
(*v).try_into().unwrap()
|
(*v).try_into().unwrap()
|
||||||
} else {
|
} else {
|
||||||
unreachable!("tuple subscript must be const int after type check");
|
unreachable!("tuple subscript must be const int after type check");
|
||||||
};
|
};
|
||||||
ctx.builder.build_extract_value(v, index, "tup_elem").unwrap()
|
let v = generator
|
||||||
|
.gen_expr(ctx, value)?
|
||||||
|
.unwrap();
|
||||||
|
match v {
|
||||||
|
ValueEnum::Dynamic(v) => {
|
||||||
|
let v = v.into_struct_value();
|
||||||
|
ctx.builder.build_extract_value(v, index, "tup_elem").unwrap().into()
|
||||||
|
}
|
||||||
|
ValueEnum::Static(v) => {
|
||||||
|
match v.get_tuple_element(index) {
|
||||||
|
Some(v) => v,
|
||||||
|
None => {
|
||||||
|
let tup = v
|
||||||
|
.to_basic_value_enum(ctx, generator, value.custom.unwrap())?
|
||||||
|
.into_struct_value();
|
||||||
|
ctx.builder.build_extract_value(tup, index, "tup_elem").unwrap().into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
unreachable!("should not be other subscriptable types after type check");
|
unreachable!("should not be other subscriptable types after type check");
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
.into(),
|
|
||||||
ExprKind::ListComp { .. } => gen_comprehension(generator, ctx, expr)?.into(),
|
ExprKind::ListComp { .. } => gen_comprehension(generator, ctx, expr)?.into(),
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
}))
|
}))
|
||||||
|
@ -36,7 +36,7 @@ pub trait CodeGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Generate object constructor and returns the constructed object.
|
/// Generate object constructor and returns the constructed object.
|
||||||
/// - signature: Function signature of the contructor.
|
/// - signature: Function signature of the constructor.
|
||||||
/// - def: Class definition for the constructor class.
|
/// - def: Class definition for the constructor class.
|
||||||
/// - params: Function parameters.
|
/// - params: Function parameters.
|
||||||
fn gen_constructor<'ctx, 'a>(
|
fn gen_constructor<'ctx, 'a>(
|
||||||
|
@ -6,7 +6,7 @@ use inkwell::{
|
|||||||
context::Context,
|
context::Context,
|
||||||
memory_buffer::MemoryBuffer,
|
memory_buffer::MemoryBuffer,
|
||||||
module::Module,
|
module::Module,
|
||||||
types::{BasicTypeEnum, IntType},
|
types::BasicTypeEnum,
|
||||||
values::{IntValue, PointerValue},
|
values::{IntValue, PointerValue},
|
||||||
AddressSpace, IntPredicate,
|
AddressSpace, IntPredicate,
|
||||||
};
|
};
|
||||||
@ -34,6 +34,7 @@ pub fn load_irrt(ctx: &Context) -> Module {
|
|||||||
// repeated squaring method adapted from GNU Scientific Library:
|
// repeated squaring method adapted from GNU Scientific Library:
|
||||||
// https://git.savannah.gnu.org/cgit/gsl.git/tree/sys/pow_int.c
|
// https://git.savannah.gnu.org/cgit/gsl.git/tree/sys/pow_int.c
|
||||||
pub fn integer_power<'ctx, 'a>(
|
pub fn integer_power<'ctx, 'a>(
|
||||||
|
generator: &mut dyn CodeGenerator,
|
||||||
ctx: &mut CodeGenContext<'ctx, 'a>,
|
ctx: &mut CodeGenContext<'ctx, 'a>,
|
||||||
base: IntValue<'ctx>,
|
base: IntValue<'ctx>,
|
||||||
exp: IntValue<'ctx>,
|
exp: IntValue<'ctx>,
|
||||||
@ -51,7 +52,21 @@ pub fn integer_power<'ctx, 'a>(
|
|||||||
let fn_type = base_type.fn_type(&[base_type.into(), base_type.into()], false);
|
let fn_type = base_type.fn_type(&[base_type.into(), base_type.into()], false);
|
||||||
ctx.module.add_function(symbol, fn_type, None)
|
ctx.module.add_function(symbol, fn_type, None)
|
||||||
});
|
});
|
||||||
// TODO: throw exception when exp < 0
|
// throw exception when exp < 0
|
||||||
|
let ge_zero = ctx.builder.build_int_compare(
|
||||||
|
IntPredicate::SGE,
|
||||||
|
exp,
|
||||||
|
exp.get_type().const_zero(),
|
||||||
|
"assert_int_pow_ge_0",
|
||||||
|
);
|
||||||
|
ctx.make_assert(
|
||||||
|
generator,
|
||||||
|
ge_zero,
|
||||||
|
"0:ValueError",
|
||||||
|
"integer power must be positive or zero",
|
||||||
|
[None, None, None],
|
||||||
|
ctx.current_loc,
|
||||||
|
);
|
||||||
ctx.builder
|
ctx.builder
|
||||||
.build_call(pow_fun, &[base.into(), exp.into()], "call_int_pow")
|
.build_call(pow_fun, &[base.into(), exp.into()], "call_int_pow")
|
||||||
.try_as_basic_value()
|
.try_as_basic_value()
|
||||||
@ -60,6 +75,7 @@ pub fn integer_power<'ctx, 'a>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn calculate_len_for_slice_range<'ctx, 'a>(
|
pub fn calculate_len_for_slice_range<'ctx, 'a>(
|
||||||
|
generator: &mut dyn CodeGenerator,
|
||||||
ctx: &mut CodeGenContext<'ctx, 'a>,
|
ctx: &mut CodeGenContext<'ctx, 'a>,
|
||||||
start: IntValue<'ctx>,
|
start: IntValue<'ctx>,
|
||||||
end: IntValue<'ctx>,
|
end: IntValue<'ctx>,
|
||||||
@ -72,7 +88,21 @@ pub fn calculate_len_for_slice_range<'ctx, 'a>(
|
|||||||
ctx.module.add_function(SYMBOL, fn_t, None)
|
ctx.module.add_function(SYMBOL, fn_t, None)
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: assert step != 0, throw exception if not
|
// assert step != 0, throw exception if not
|
||||||
|
let not_zero = ctx.builder.build_int_compare(
|
||||||
|
IntPredicate::NE,
|
||||||
|
step,
|
||||||
|
step.get_type().const_zero(),
|
||||||
|
"range_step_ne",
|
||||||
|
);
|
||||||
|
ctx.make_assert(
|
||||||
|
generator,
|
||||||
|
not_zero,
|
||||||
|
"0:ValueError",
|
||||||
|
"step must not be zero",
|
||||||
|
[None, None, None],
|
||||||
|
ctx.current_loc,
|
||||||
|
);
|
||||||
ctx.builder
|
ctx.builder
|
||||||
.build_call(len_func, &[start.into(), end.into(), step.into()], "calc_len")
|
.build_call(len_func, &[start.into(), end.into(), step.into()], "calc_len")
|
||||||
.try_as_basic_value()
|
.try_as_basic_value()
|
||||||
@ -129,7 +159,6 @@ pub fn handle_slice_indices<'a, 'ctx, G: CodeGenerator>(
|
|||||||
generator: &mut G,
|
generator: &mut G,
|
||||||
list: PointerValue<'ctx>,
|
list: PointerValue<'ctx>,
|
||||||
) -> Result<(IntValue<'ctx>, IntValue<'ctx>, IntValue<'ctx>), String> {
|
) -> Result<(IntValue<'ctx>, IntValue<'ctx>, IntValue<'ctx>), String> {
|
||||||
// TODO: throw exception when step is 0
|
|
||||||
let int32 = ctx.ctx.i32_type();
|
let int32 = ctx.ctx.i32_type();
|
||||||
let zero = int32.const_zero();
|
let zero = int32.const_zero();
|
||||||
let one = int32.const_int(1, false);
|
let one = int32.const_int(1, false);
|
||||||
@ -154,8 +183,23 @@ pub fn handle_slice_indices<'a, 'ctx, G: CodeGenerator>(
|
|||||||
let step = generator
|
let step = generator
|
||||||
.gen_expr(ctx, step)?
|
.gen_expr(ctx, step)?
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_basic_value_enum(ctx, generator)?
|
.to_basic_value_enum(ctx, generator, ctx.primitives.int32)?
|
||||||
.into_int_value();
|
.into_int_value();
|
||||||
|
// assert step != 0, throw exception if not
|
||||||
|
let not_zero = ctx.builder.build_int_compare(
|
||||||
|
IntPredicate::NE,
|
||||||
|
step,
|
||||||
|
step.get_type().const_zero(),
|
||||||
|
"range_step_ne",
|
||||||
|
);
|
||||||
|
ctx.make_assert(
|
||||||
|
generator,
|
||||||
|
not_zero,
|
||||||
|
"0:ValueError",
|
||||||
|
"slice step cannot be zero",
|
||||||
|
[None, None, None],
|
||||||
|
ctx.current_loc,
|
||||||
|
);
|
||||||
let len_id = ctx.builder.build_int_sub(length, one, "lenmin1");
|
let len_id = ctx.builder.build_int_sub(length, one, "lenmin1");
|
||||||
let neg = ctx.builder.build_int_compare(IntPredicate::SLT, step, zero, "step_is_neg");
|
let neg = ctx.builder.build_int_compare(IntPredicate::SLT, step, zero, "step_is_neg");
|
||||||
(
|
(
|
||||||
@ -217,7 +261,7 @@ pub fn handle_slice_index_bound<'a, 'ctx, G: CodeGenerator>(
|
|||||||
ctx.module.add_function(SYMBOL, fn_t, None)
|
ctx.module.add_function(SYMBOL, fn_t, None)
|
||||||
});
|
});
|
||||||
|
|
||||||
let i = generator.gen_expr(ctx, i)?.unwrap().to_basic_value_enum(ctx, generator)?;
|
let i = generator.gen_expr(ctx, i)?.unwrap().to_basic_value_enum(ctx, generator, i.custom.unwrap())?;
|
||||||
Ok(ctx
|
Ok(ctx
|
||||||
.builder
|
.builder
|
||||||
.build_call(func, &[i.into(), length.into()], "bounded_ind")
|
.build_call(func, &[i.into(), length.into()], "bounded_ind")
|
||||||
@ -231,14 +275,15 @@ pub fn handle_slice_index_bound<'a, 'ctx, G: CodeGenerator>(
|
|||||||
/// Order of tuples assign_idx and value_idx is ('start', 'end', 'step').
|
/// Order of tuples assign_idx and value_idx is ('start', 'end', 'step').
|
||||||
/// Negative index should be handled before entering this function
|
/// Negative index should be handled before entering this function
|
||||||
pub fn list_slice_assignment<'ctx, 'a>(
|
pub fn list_slice_assignment<'ctx, 'a>(
|
||||||
|
generator: &mut dyn CodeGenerator,
|
||||||
ctx: &mut CodeGenContext<'ctx, 'a>,
|
ctx: &mut CodeGenContext<'ctx, 'a>,
|
||||||
size_ty: IntType<'ctx>,
|
|
||||||
ty: BasicTypeEnum<'ctx>,
|
ty: BasicTypeEnum<'ctx>,
|
||||||
dest_arr: PointerValue<'ctx>,
|
dest_arr: PointerValue<'ctx>,
|
||||||
dest_idx: (IntValue<'ctx>, IntValue<'ctx>, IntValue<'ctx>),
|
dest_idx: (IntValue<'ctx>, IntValue<'ctx>, IntValue<'ctx>),
|
||||||
src_arr: PointerValue<'ctx>,
|
src_arr: PointerValue<'ctx>,
|
||||||
src_idx: (IntValue<'ctx>, IntValue<'ctx>, IntValue<'ctx>),
|
src_idx: (IntValue<'ctx>, IntValue<'ctx>, IntValue<'ctx>),
|
||||||
) {
|
) {
|
||||||
|
let size_ty = generator.get_size_type(ctx.ctx);
|
||||||
let int8_ptr = ctx.ctx.i8_type().ptr_type(AddressSpace::Generic);
|
let int8_ptr = ctx.ctx.i8_type().ptr_type(AddressSpace::Generic);
|
||||||
let int32 = ctx.ctx.i32_type();
|
let int32 = ctx.ctx.i32_type();
|
||||||
let (fun_symbol, elem_ptr_type) = ("__nac3_list_slice_assign_var_size", int8_ptr);
|
let (fun_symbol, elem_ptr_type) = ("__nac3_list_slice_assign_var_size", int8_ptr);
|
||||||
@ -282,8 +327,67 @@ pub fn list_slice_assignment<'ctx, 'a>(
|
|||||||
let src_len = ctx.builder.build_int_truncate_or_bit_cast(src_len, int32, "srclen32");
|
let src_len = ctx.builder.build_int_truncate_or_bit_cast(src_len, int32, "srclen32");
|
||||||
|
|
||||||
// index in bound and positive should be done
|
// index in bound and positive should be done
|
||||||
// TODO: assert if dest.step == 1 then len(src) <= len(dest) else len(src) == len(dest), and
|
// assert if dest.step == 1 then len(src) <= len(dest) else len(src) == len(dest), and
|
||||||
// throw exception if not satisfied
|
// throw exception if not satisfied
|
||||||
|
let src_end = ctx.builder
|
||||||
|
.build_select(
|
||||||
|
ctx.builder.build_int_compare(
|
||||||
|
inkwell::IntPredicate::SLT,
|
||||||
|
src_idx.2,
|
||||||
|
zero,
|
||||||
|
"is_neg",
|
||||||
|
),
|
||||||
|
ctx.builder.build_int_sub(src_idx.1, one, "e_min_one"),
|
||||||
|
ctx.builder.build_int_add(src_idx.1, one, "e_add_one"),
|
||||||
|
"final_e",
|
||||||
|
)
|
||||||
|
.into_int_value();
|
||||||
|
let dest_end = ctx.builder
|
||||||
|
.build_select(
|
||||||
|
ctx.builder.build_int_compare(
|
||||||
|
inkwell::IntPredicate::SLT,
|
||||||
|
dest_idx.2,
|
||||||
|
zero,
|
||||||
|
"is_neg",
|
||||||
|
),
|
||||||
|
ctx.builder.build_int_sub(dest_idx.1, one, "e_min_one"),
|
||||||
|
ctx.builder.build_int_add(dest_idx.1, one, "e_add_one"),
|
||||||
|
"final_e",
|
||||||
|
)
|
||||||
|
.into_int_value();
|
||||||
|
let src_slice_len =
|
||||||
|
calculate_len_for_slice_range(generator, ctx, src_idx.0, src_end, src_idx.2);
|
||||||
|
let dest_slice_len =
|
||||||
|
calculate_len_for_slice_range(generator, ctx, dest_idx.0, dest_end, dest_idx.2);
|
||||||
|
let src_eq_dest = ctx.builder.build_int_compare(
|
||||||
|
IntPredicate::EQ,
|
||||||
|
src_slice_len,
|
||||||
|
dest_slice_len,
|
||||||
|
"slice_src_eq_dest",
|
||||||
|
);
|
||||||
|
let src_slt_dest = ctx.builder.build_int_compare(
|
||||||
|
IntPredicate::SLT,
|
||||||
|
src_slice_len,
|
||||||
|
dest_slice_len,
|
||||||
|
"slice_src_slt_dest",
|
||||||
|
);
|
||||||
|
let dest_step_eq_one = ctx.builder.build_int_compare(
|
||||||
|
IntPredicate::EQ,
|
||||||
|
dest_idx.2,
|
||||||
|
dest_idx.2.get_type().const_int(1, false),
|
||||||
|
"slice_dest_step_eq_one",
|
||||||
|
);
|
||||||
|
let cond_1 = ctx.builder.build_and(dest_step_eq_one, src_slt_dest, "slice_cond_1");
|
||||||
|
let cond = ctx.builder.build_or(src_eq_dest, cond_1, "slice_cond");
|
||||||
|
ctx.make_assert(
|
||||||
|
generator,
|
||||||
|
cond,
|
||||||
|
"0:ValueError",
|
||||||
|
"attempt to assign sequence of size {0} to slice of size {1} with step size {2}",
|
||||||
|
[Some(src_slice_len), Some(dest_slice_len), Some(dest_idx.2)],
|
||||||
|
ctx.current_loc,
|
||||||
|
);
|
||||||
|
|
||||||
let new_len = {
|
let new_len = {
|
||||||
let args = vec![
|
let args = vec![
|
||||||
dest_idx.0.into(), // dest start idx
|
dest_idx.0.into(), // dest start idx
|
||||||
|
@ -17,10 +17,13 @@ use inkwell::{
|
|||||||
module::Module,
|
module::Module,
|
||||||
passes::{PassManager, PassManagerBuilder},
|
passes::{PassManager, PassManagerBuilder},
|
||||||
types::{AnyType, BasicType, BasicTypeEnum},
|
types::{AnyType, BasicType, BasicTypeEnum},
|
||||||
values::{BasicValueEnum, FunctionValue, PhiValue, PointerValue}
|
values::{BasicValueEnum, FunctionValue, PhiValue, PointerValue},
|
||||||
|
debug_info::{
|
||||||
|
DebugInfoBuilder, DICompileUnit, DISubprogram, AsDIScope, DIFlagsConstants, DIScope
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use nac3parser::ast::{Stmt, StrRef};
|
use nac3parser::ast::{Stmt, StrRef, Location};
|
||||||
use parking_lot::{Condvar, Mutex};
|
use parking_lot::{Condvar, Mutex};
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
use std::sync::{
|
use std::sync::{
|
||||||
@ -52,6 +55,7 @@ pub type VarValue<'ctx> = (PointerValue<'ctx>, Option<Arc<dyn StaticValue + Send
|
|||||||
pub struct CodeGenContext<'ctx, 'a> {
|
pub struct CodeGenContext<'ctx, 'a> {
|
||||||
pub ctx: &'ctx Context,
|
pub ctx: &'ctx Context,
|
||||||
pub builder: Builder<'ctx>,
|
pub builder: Builder<'ctx>,
|
||||||
|
pub debug_info: (DebugInfoBuilder<'ctx>, DICompileUnit<'ctx>, DIScope<'ctx>),
|
||||||
pub module: Module<'ctx>,
|
pub module: Module<'ctx>,
|
||||||
pub top_level: &'a TopLevelContext,
|
pub top_level: &'a TopLevelContext,
|
||||||
pub unifier: Unifier,
|
pub unifier: Unifier,
|
||||||
@ -77,6 +81,7 @@ pub struct CodeGenContext<'ctx, 'a> {
|
|||||||
pub outer_catch_clauses:
|
pub outer_catch_clauses:
|
||||||
Option<(Vec<Option<BasicValueEnum<'ctx>>>, BasicBlock<'ctx>, PhiValue<'ctx>)>,
|
Option<(Vec<Option<BasicValueEnum<'ctx>>>, BasicBlock<'ctx>, PhiValue<'ctx>)>,
|
||||||
pub need_sret: bool,
|
pub need_sret: bool,
|
||||||
|
pub current_loc: Location,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'ctx, 'a> CodeGenContext<'ctx, 'a> {
|
impl<'ctx, 'a> CodeGenContext<'ctx, 'a> {
|
||||||
@ -198,27 +203,65 @@ impl WorkerRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn worker_thread<G: CodeGenerator>(&self, generator: &mut G, f: Arc<WithCall>) {
|
fn worker_thread<G: CodeGenerator>(&self, generator: &mut G, f: Arc<WithCall>) {
|
||||||
|
// println!("thread start! 1");
|
||||||
let context = Context::create();
|
let context = Context::create();
|
||||||
|
// println!("thread start! 2");
|
||||||
let mut builder = context.create_builder();
|
let mut builder = context.create_builder();
|
||||||
let module = context.create_module(generator.get_name());
|
// println!("thread start! 3");
|
||||||
|
let mut module = context.create_module(generator.get_name());
|
||||||
|
// println!("thread start! 4");
|
||||||
|
|
||||||
|
module.add_basic_value_flag(
|
||||||
|
"Debug Info Version",
|
||||||
|
inkwell::module::FlagBehavior::Warning,
|
||||||
|
context.i32_type().const_int(3, false),
|
||||||
|
);
|
||||||
|
module.add_basic_value_flag(
|
||||||
|
"Dwarf Version",
|
||||||
|
inkwell::module::FlagBehavior::Warning,
|
||||||
|
context.i32_type().const_int(4, false),
|
||||||
|
);
|
||||||
|
|
||||||
let pass_builder = PassManagerBuilder::create();
|
|
||||||
pass_builder.set_optimization_level(OptimizationLevel::Default);
|
|
||||||
let passes = PassManager::create(&module);
|
|
||||||
pass_builder.populate_function_pass_manager(&passes);
|
|
||||||
|
|
||||||
let mut errors = HashSet::new();
|
let mut errors = HashSet::new();
|
||||||
|
// while let Some(task) = self.receiver.recv().unwrap() {
|
||||||
|
// println!("creating tmp");
|
||||||
|
// let tmp_module = context.create_module("tmp");
|
||||||
|
// println!("creating tmp done {}", tmp_module.print_to_string().to_string());
|
||||||
|
// let n = task.symbol_name.clone();
|
||||||
|
// println!("{} start0:", n);
|
||||||
|
// let res = gen_func(&context, generator, self, builder, tmp_module, task);
|
||||||
|
// match res {
|
||||||
|
// Ok(result) => {
|
||||||
|
// builder = result.0;
|
||||||
|
// passes.run_on(&result.2);
|
||||||
|
// result.1.verify().unwrap();
|
||||||
|
// module.link_in_module(result.1).unwrap();
|
||||||
|
// }
|
||||||
|
// Err((old_builder, e)) => {
|
||||||
|
// builder = old_builder;
|
||||||
|
// errors.insert(e);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// println!("{} done0:", n);
|
||||||
|
// *self.task_count.lock() -= 1;
|
||||||
|
// self.wait_condvar.notify_all();
|
||||||
|
// }
|
||||||
|
|
||||||
while let Some(task) = self.receiver.recv().unwrap() {
|
while let Some(task) = self.receiver.recv().unwrap() {
|
||||||
let tmp_module = context.create_module("tmp");
|
match gen_func(&context, generator, self, builder, module, task) {
|
||||||
match gen_func(&context, generator, self, builder, tmp_module, task) {
|
|
||||||
Ok(result) => {
|
Ok(result) => {
|
||||||
builder = result.0;
|
builder = result.0;
|
||||||
passes.run_on(&result.2);
|
// passes.run_on(&result.2);
|
||||||
module.link_in_module(result.1).unwrap();
|
// module.link_in_module(result.1).unwrap();
|
||||||
|
module = result.1;
|
||||||
}
|
}
|
||||||
Err((old_builder, e)) => {
|
Err((old_builder, e)) => {
|
||||||
builder = old_builder;
|
// builder = old_builder;
|
||||||
|
// create a new module to continue to just collect other errors
|
||||||
|
// module = context.create_module(generator.get_name());
|
||||||
errors.insert(e);
|
errors.insert(e);
|
||||||
|
panic!("Codegen error: {}", errors.into_iter().sorted().join("\n----------\n"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*self.task_count.lock() -= 1;
|
*self.task_count.lock() -= 1;
|
||||||
@ -230,10 +273,20 @@ impl WorkerRegistry {
|
|||||||
|
|
||||||
let result = module.verify();
|
let result = module.verify();
|
||||||
if let Err(err) = result {
|
if let Err(err) = result {
|
||||||
println!("{}", module.print_to_string().to_str().unwrap());
|
println!("\n\n!!!!!!!!!!!!!!!!!!error!!!!!!!!!!!!!!!!!!!!!");
|
||||||
println!("{}", err);
|
println!("{}", module.print_to_string().to_string());
|
||||||
|
println!("{}", err.to_string());
|
||||||
|
println!("!!!!!!!!!!!!!!!!!!error!!!!!!!!!!!!!!!!!!!!!\n\n");
|
||||||
panic!()
|
panic!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
println!("aaaa");
|
||||||
|
let pass_builder = PassManagerBuilder::create();
|
||||||
|
pass_builder.set_optimization_level(OptimizationLevel::Default);
|
||||||
|
let passes = PassManager::create(&module);
|
||||||
|
pass_builder.populate_function_pass_manager(&passes);
|
||||||
|
println!("ddddd");
|
||||||
|
|
||||||
f.run(&module);
|
f.run(&module);
|
||||||
let mut lock = self.task_count.lock();
|
let mut lock = self.task_count.lock();
|
||||||
*lock += 1;
|
*lock += 1;
|
||||||
@ -255,6 +308,7 @@ pub struct CodeGenTask {
|
|||||||
|
|
||||||
fn get_llvm_type<'ctx>(
|
fn get_llvm_type<'ctx>(
|
||||||
ctx: &'ctx Context,
|
ctx: &'ctx Context,
|
||||||
|
module: &Module<'ctx>,
|
||||||
generator: &mut dyn CodeGenerator,
|
generator: &mut dyn CodeGenerator,
|
||||||
unifier: &mut Unifier,
|
unifier: &mut Unifier,
|
||||||
top_level: &TopLevelContext,
|
top_level: &TopLevelContext,
|
||||||
@ -266,6 +320,7 @@ fn get_llvm_type<'ctx>(
|
|||||||
// we assume the type cache should already contain primitive types,
|
// we assume the type cache should already contain primitive types,
|
||||||
// and they should be passed by value instead of passing as pointer.
|
// and they should be passed by value instead of passing as pointer.
|
||||||
type_cache.get(&unifier.get_representative(ty)).cloned().unwrap_or_else(|| {
|
type_cache.get(&unifier.get_representative(ty)).cloned().unwrap_or_else(|| {
|
||||||
|
// println!("getting new: {}", unifier.stringify(ty));
|
||||||
let ty_enum = unifier.get_ty(ty);
|
let ty_enum = unifier.get_ty(ty);
|
||||||
let result = match &*ty_enum {
|
let result = match &*ty_enum {
|
||||||
TObj { obj_id, fields, .. } => {
|
TObj { obj_id, fields, .. } => {
|
||||||
@ -279,6 +334,7 @@ fn get_llvm_type<'ctx>(
|
|||||||
) if *obj_id == *opt_id => {
|
) if *obj_id == *opt_id => {
|
||||||
return get_llvm_type(
|
return get_llvm_type(
|
||||||
ctx,
|
ctx,
|
||||||
|
module,
|
||||||
generator,
|
generator,
|
||||||
unifier,
|
unifier,
|
||||||
top_level,
|
top_level,
|
||||||
@ -298,6 +354,28 @@ fn get_llvm_type<'ctx>(
|
|||||||
let ty = if let TopLevelDef::Class { name, fields: fields_list, .. } =
|
let ty = if let TopLevelDef::Class { name, fields: fields_list, .. } =
|
||||||
&*definition.read()
|
&*definition.read()
|
||||||
{
|
{
|
||||||
|
// let struct_type = {
|
||||||
|
// let struct_type = ctx.opaque_struct_type(&name.to_string());
|
||||||
|
// type_cache.insert(unifier.get_representative(ty), struct_type.ptr_type(AddressSpace::Generic).into());
|
||||||
|
// let fields = fields_list
|
||||||
|
// .iter()
|
||||||
|
// .map(|f| {
|
||||||
|
// get_llvm_type(
|
||||||
|
// ctx,
|
||||||
|
// module,
|
||||||
|
// generator,
|
||||||
|
// unifier,
|
||||||
|
// top_level,
|
||||||
|
// type_cache,
|
||||||
|
// primitives,
|
||||||
|
// fields[&f.0].0,
|
||||||
|
// )
|
||||||
|
// })
|
||||||
|
// .collect_vec();
|
||||||
|
// struct_type.set_body(&fields, false);
|
||||||
|
// struct_type
|
||||||
|
// };
|
||||||
|
let struct_type = module.get_struct_type(&name.to_string()).unwrap_or_else(|| {
|
||||||
let struct_type = ctx.opaque_struct_type(&name.to_string());
|
let struct_type = ctx.opaque_struct_type(&name.to_string());
|
||||||
type_cache.insert(unifier.get_representative(ty), struct_type.ptr_type(AddressSpace::Generic).into());
|
type_cache.insert(unifier.get_representative(ty), struct_type.ptr_type(AddressSpace::Generic).into());
|
||||||
let fields = fields_list
|
let fields = fields_list
|
||||||
@ -305,6 +383,7 @@ fn get_llvm_type<'ctx>(
|
|||||||
.map(|f| {
|
.map(|f| {
|
||||||
get_llvm_type(
|
get_llvm_type(
|
||||||
ctx,
|
ctx,
|
||||||
|
module,
|
||||||
generator,
|
generator,
|
||||||
unifier,
|
unifier,
|
||||||
top_level,
|
top_level,
|
||||||
@ -315,7 +394,11 @@ fn get_llvm_type<'ctx>(
|
|||||||
})
|
})
|
||||||
.collect_vec();
|
.collect_vec();
|
||||||
struct_type.set_body(&fields, false);
|
struct_type.set_body(&fields, false);
|
||||||
struct_type.ptr_type(AddressSpace::Generic).into()
|
struct_type
|
||||||
|
});
|
||||||
|
let res = struct_type.ptr_type(AddressSpace::Generic).into();
|
||||||
|
// println!("got: {:?}", res);
|
||||||
|
res
|
||||||
} else {
|
} else {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
};
|
};
|
||||||
@ -325,14 +408,14 @@ fn get_llvm_type<'ctx>(
|
|||||||
// a struct with fields in the order present in the tuple
|
// a struct with fields in the order present in the tuple
|
||||||
let fields = ty
|
let fields = ty
|
||||||
.iter()
|
.iter()
|
||||||
.map(|ty| get_llvm_type(ctx, generator, unifier, top_level, type_cache, primitives, *ty))
|
.map(|ty| get_llvm_type(ctx, module, generator, unifier, top_level, type_cache, primitives, *ty))
|
||||||
.collect_vec();
|
.collect_vec();
|
||||||
ctx.struct_type(&fields, false).into()
|
ctx.struct_type(&fields, false).into()
|
||||||
}
|
}
|
||||||
TList { ty } => {
|
TList { ty } => {
|
||||||
// a struct with an integer and a pointer to an array
|
// a struct with an integer and a pointer to an array
|
||||||
let element_type =
|
let element_type =
|
||||||
get_llvm_type(ctx, generator, unifier, top_level, type_cache, primitives, *ty);
|
get_llvm_type(ctx, module, generator, unifier, top_level, type_cache, primitives, *ty);
|
||||||
let fields = [
|
let fields = [
|
||||||
element_type.ptr_type(AddressSpace::Generic).into(),
|
element_type.ptr_type(AddressSpace::Generic).into(),
|
||||||
generator.get_size_type(ctx).into(),
|
generator.get_size_type(ctx).into(),
|
||||||
@ -360,13 +443,14 @@ fn need_sret<'ctx>(ctx: &'ctx Context, ty: BasicTypeEnum<'ctx>) -> bool {
|
|||||||
need_sret_impl(ctx, ty, true)
|
need_sret_impl(ctx, ty, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn gen_func<'ctx, G: CodeGenerator>(
|
pub fn gen_func_impl<'ctx, G: CodeGenerator, F: FnOnce(&mut G, &mut CodeGenContext) -> Result<(), String>> (
|
||||||
context: &'ctx Context,
|
context: &'ctx Context,
|
||||||
generator: &mut G,
|
generator: &mut G,
|
||||||
registry: &WorkerRegistry,
|
registry: &WorkerRegistry,
|
||||||
builder: Builder<'ctx>,
|
builder: Builder<'ctx>,
|
||||||
module: Module<'ctx>,
|
module: Module<'ctx>,
|
||||||
task: CodeGenTask,
|
task: CodeGenTask,
|
||||||
|
codegen_function: F
|
||||||
) -> Result<(Builder<'ctx>, Module<'ctx>, FunctionValue<'ctx>), (Builder<'ctx>, String)> {
|
) -> Result<(Builder<'ctx>, Module<'ctx>, FunctionValue<'ctx>), (Builder<'ctx>, String)> {
|
||||||
let top_level_ctx = registry.top_level_ctx.clone();
|
let top_level_ctx = registry.top_level_ctx.clone();
|
||||||
let static_value_store = registry.static_value_store.clone();
|
let static_value_store = registry.static_value_store.clone();
|
||||||
@ -458,10 +542,11 @@ pub fn gen_func<'ctx, G: CodeGenerator>(
|
|||||||
} else {
|
} else {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
};
|
};
|
||||||
|
// println!("\n=======getting types for func `{}`=======", task.symbol_name);
|
||||||
let ret_type = if unifier.unioned(ret, primitives.none) {
|
let ret_type = if unifier.unioned(ret, primitives.none) {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(get_llvm_type(context, generator, &mut unifier, top_level_ctx.as_ref(), &mut type_cache, &primitives, ret))
|
Some(get_llvm_type(context, &module, generator, &mut unifier, top_level_ctx.as_ref(), &mut type_cache, &primitives, ret))
|
||||||
};
|
};
|
||||||
|
|
||||||
let has_sret = ret_type.map_or(false, |ty| need_sret(context, ty));
|
let has_sret = ret_type.map_or(false, |ty| need_sret(context, ty));
|
||||||
@ -470,6 +555,7 @@ pub fn gen_func<'ctx, G: CodeGenerator>(
|
|||||||
.map(|arg| {
|
.map(|arg| {
|
||||||
get_llvm_type(
|
get_llvm_type(
|
||||||
context,
|
context,
|
||||||
|
&module,
|
||||||
generator,
|
generator,
|
||||||
&mut unifier,
|
&mut unifier,
|
||||||
top_level_ctx.as_ref(),
|
top_level_ctx.as_ref(),
|
||||||
@ -480,7 +566,6 @@ pub fn gen_func<'ctx, G: CodeGenerator>(
|
|||||||
.into()
|
.into()
|
||||||
})
|
})
|
||||||
.collect_vec();
|
.collect_vec();
|
||||||
|
|
||||||
if has_sret {
|
if has_sret {
|
||||||
params.insert(0, ret_type.unwrap().ptr_type(AddressSpace::Generic).into());
|
params.insert(0, ret_type.unwrap().ptr_type(AddressSpace::Generic).into());
|
||||||
}
|
}
|
||||||
@ -489,7 +574,7 @@ pub fn gen_func<'ctx, G: CodeGenerator>(
|
|||||||
Some(ret_type) if !has_sret => ret_type.fn_type(¶ms, false),
|
Some(ret_type) if !has_sret => ret_type.fn_type(¶ms, false),
|
||||||
_ => context.void_type().fn_type(¶ms, false)
|
_ => context.void_type().fn_type(¶ms, false)
|
||||||
};
|
};
|
||||||
|
// println!("=======got types for func `{}`: {:?}=======\n", task.symbol_name, fn_type);
|
||||||
let symbol = &task.symbol_name;
|
let symbol = &task.symbol_name;
|
||||||
let fn_val =
|
let fn_val =
|
||||||
module.get_function(symbol).unwrap_or_else(|| module.add_function(symbol, fn_type, None));
|
module.get_function(symbol).unwrap_or_else(|| module.add_function(symbol, fn_type, None));
|
||||||
@ -518,6 +603,7 @@ pub fn gen_func<'ctx, G: CodeGenerator>(
|
|||||||
let alloca = builder.build_alloca(
|
let alloca = builder.build_alloca(
|
||||||
get_llvm_type(
|
get_llvm_type(
|
||||||
context,
|
context,
|
||||||
|
&module,
|
||||||
generator,
|
generator,
|
||||||
&mut unifier,
|
&mut unifier,
|
||||||
top_level_ctx.as_ref(),
|
top_level_ctx.as_ref(),
|
||||||
@ -549,6 +635,58 @@ pub fn gen_func<'ctx, G: CodeGenerator>(
|
|||||||
builder.build_unconditional_branch(body_bb);
|
builder.build_unconditional_branch(body_bb);
|
||||||
builder.position_at_end(body_bb);
|
builder.position_at_end(body_bb);
|
||||||
|
|
||||||
|
let (dibuilder, compile_unit) = module.create_debug_info_builder(
|
||||||
|
/* allow_unresolved */ true,
|
||||||
|
/* language */ inkwell::debug_info::DWARFSourceLanguage::Python,
|
||||||
|
/* filename */
|
||||||
|
&task
|
||||||
|
.body
|
||||||
|
.get(0)
|
||||||
|
.map_or_else(
|
||||||
|
|| "<nac3_internal>".to_string(),
|
||||||
|
|f| f.location.file.0.to_string(),
|
||||||
|
),
|
||||||
|
/* directory */ "",
|
||||||
|
/* producer */ "NAC3",
|
||||||
|
/* is_optimized */ true,
|
||||||
|
/* compiler command line flags */ "",
|
||||||
|
/* runtime_ver */ 0,
|
||||||
|
/* split_name */ "",
|
||||||
|
/* kind */ inkwell::debug_info::DWARFEmissionKind::Full,
|
||||||
|
/* dwo_id */ 0,
|
||||||
|
/* split_debug_inling */ true,
|
||||||
|
/* debug_info_for_profiling */ false,
|
||||||
|
/* sysroot */ "",
|
||||||
|
/* sdk */ "",
|
||||||
|
);
|
||||||
|
let subroutine_type = dibuilder.create_subroutine_type(
|
||||||
|
compile_unit.get_file(),
|
||||||
|
Some(
|
||||||
|
dibuilder
|
||||||
|
.create_basic_type("_", 0_u64, 0x00, inkwell::debug_info::DIFlags::PUBLIC)
|
||||||
|
.unwrap()
|
||||||
|
.as_type(),
|
||||||
|
),
|
||||||
|
&[],
|
||||||
|
inkwell::debug_info::DIFlags::PUBLIC,
|
||||||
|
);
|
||||||
|
let (row, col) =
|
||||||
|
task.body.get(0).map_or_else(|| (0, 0), |b| (b.location.row, b.location.column));
|
||||||
|
let func_scope: DISubprogram<'_> = dibuilder.create_function(
|
||||||
|
/* scope */ compile_unit.as_debug_info_scope(),
|
||||||
|
/* func name */ symbol,
|
||||||
|
/* linkage_name */ None,
|
||||||
|
/* file */ compile_unit.get_file(),
|
||||||
|
/* line_no */ row as u32,
|
||||||
|
/* DIType */ subroutine_type,
|
||||||
|
/* is_local_to_unit */ false,
|
||||||
|
/* is_definition */ true,
|
||||||
|
/* scope_line */ row as u32,
|
||||||
|
/* flags */ inkwell::debug_info::DIFlags::PUBLIC,
|
||||||
|
/* is_optimized */ true,
|
||||||
|
);
|
||||||
|
fn_val.set_subprogram(func_scope);
|
||||||
|
|
||||||
let mut code_gen_context = CodeGenContext {
|
let mut code_gen_context = CodeGenContext {
|
||||||
ctx: context,
|
ctx: context,
|
||||||
resolver: task.resolver,
|
resolver: task.resolver,
|
||||||
@ -569,28 +707,55 @@ pub fn gen_func<'ctx, G: CodeGenerator>(
|
|||||||
module,
|
module,
|
||||||
unifier,
|
unifier,
|
||||||
static_value_store,
|
static_value_store,
|
||||||
need_sret: has_sret
|
need_sret: has_sret,
|
||||||
|
current_loc: Default::default(),
|
||||||
|
debug_info: (dibuilder, compile_unit, func_scope.as_debug_info_scope()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut err = None;
|
let loc = code_gen_context.debug_info.0.create_debug_location(
|
||||||
for stmt in task.body.iter() {
|
context,
|
||||||
if let Err(e) = generator.gen_stmt(&mut code_gen_context, stmt) {
|
row as u32,
|
||||||
err = Some(e);
|
col as u32,
|
||||||
break;
|
func_scope.as_debug_info_scope(),
|
||||||
}
|
None
|
||||||
if code_gen_context.is_terminated() {
|
);
|
||||||
break;
|
code_gen_context.builder.set_current_debug_location(context, loc);
|
||||||
}
|
|
||||||
}
|
let result = codegen_function(generator, &mut code_gen_context);
|
||||||
|
|
||||||
// after static analysis, only void functions can have no return at the end.
|
// after static analysis, only void functions can have no return at the end.
|
||||||
if !code_gen_context.is_terminated() {
|
if !code_gen_context.is_terminated() {
|
||||||
code_gen_context.builder.build_return(None);
|
code_gen_context.builder.build_return(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
code_gen_context.builder.unset_current_debug_location();
|
||||||
|
code_gen_context.debug_info.0.finalize();
|
||||||
|
|
||||||
let CodeGenContext { builder, module, .. } = code_gen_context;
|
let CodeGenContext { builder, module, .. } = code_gen_context;
|
||||||
if let Some(e) = err {
|
if let Err(e) = result {
|
||||||
return Err((builder, e));
|
return Err((builder, e));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok((builder, module, fn_val))
|
Ok((builder, module, fn_val))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn gen_func<'ctx, G: CodeGenerator>(
|
||||||
|
context: &'ctx Context,
|
||||||
|
generator: &mut G,
|
||||||
|
registry: &WorkerRegistry,
|
||||||
|
builder: Builder<'ctx>,
|
||||||
|
module: Module<'ctx>,
|
||||||
|
task: CodeGenTask,
|
||||||
|
) -> Result<(Builder<'ctx>, Module<'ctx>, FunctionValue<'ctx>), (Builder<'ctx>, String)> {
|
||||||
|
let n = task.symbol_name.clone();
|
||||||
|
println!("{} start:", n);
|
||||||
|
let body = task.body.clone();
|
||||||
|
let res = gen_func_impl(context, generator, registry, builder, module, task, |generator, ctx| {
|
||||||
|
for stmt in body.iter() {
|
||||||
|
generator.gen_stmt(ctx, stmt)?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
});
|
||||||
|
println!("{} end:", n);
|
||||||
|
res
|
||||||
|
}
|
||||||
|
@ -42,19 +42,26 @@ pub fn gen_store_target<'ctx, 'a, G: CodeGenerator>(
|
|||||||
// very similar to gen_expr, but we don't do an extra load at the end
|
// very similar to gen_expr, but we don't do an extra load at the end
|
||||||
// and we flatten nested tuples
|
// and we flatten nested tuples
|
||||||
Ok(match &pattern.node {
|
Ok(match &pattern.node {
|
||||||
ExprKind::Name { id, .. } => {
|
ExprKind::Name { id, .. } => match ctx.var_assignment.get(id) {
|
||||||
ctx.var_assignment.get(id).map(|v| Ok(v.0) as Result<_, String>).unwrap_or_else(
|
None => {
|
||||||
|| {
|
|
||||||
let ptr_ty = ctx.get_llvm_type(generator, pattern.custom.unwrap());
|
let ptr_ty = ctx.get_llvm_type(generator, pattern.custom.unwrap());
|
||||||
let ptr = generator.gen_var_alloc(ctx, ptr_ty)?;
|
let ptr = generator.gen_var_alloc(ctx, ptr_ty)?;
|
||||||
ctx.var_assignment.insert(*id, (ptr, None, 0));
|
ctx.var_assignment.insert(*id, (ptr, None, 0));
|
||||||
Ok(ptr)
|
ptr
|
||||||
},
|
}
|
||||||
)?
|
Some(v) => {
|
||||||
|
let (ptr, counter) = (v.0, v.2);
|
||||||
|
ctx.var_assignment.insert(*id, (ptr, None, counter));
|
||||||
|
ptr
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ExprKind::Attribute { value, attr, .. } => {
|
ExprKind::Attribute { value, attr, .. } => {
|
||||||
let index = ctx.get_attr_index(value.custom.unwrap(), *attr);
|
let index = ctx.get_attr_index(value.custom.unwrap(), *attr);
|
||||||
let val = generator.gen_expr(ctx, value)?.unwrap().to_basic_value_enum(ctx, generator)?;
|
let val = generator.gen_expr(ctx, value)?.unwrap().to_basic_value_enum(
|
||||||
|
ctx,
|
||||||
|
generator,
|
||||||
|
value.custom.unwrap(),
|
||||||
|
)?;
|
||||||
let ptr = if let BasicValueEnum::PointerValue(v) = val {
|
let ptr = if let BasicValueEnum::PointerValue(v) = val {
|
||||||
v
|
v
|
||||||
} else {
|
} else {
|
||||||
@ -72,17 +79,58 @@ pub fn gen_store_target<'ctx, 'a, G: CodeGenerator>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ExprKind::Subscript { value, slice, .. } => {
|
ExprKind::Subscript { value, slice, .. } => {
|
||||||
|
assert!(matches!(
|
||||||
|
ctx.unifier.get_ty_immutable(value.custom.unwrap()).as_ref(),
|
||||||
|
TypeEnum::TList { .. },
|
||||||
|
));
|
||||||
let i32_type = ctx.ctx.i32_type();
|
let i32_type = ctx.ctx.i32_type();
|
||||||
|
let zero = i32_type.const_zero();
|
||||||
let v = generator
|
let v = generator
|
||||||
.gen_expr(ctx, value)?
|
.gen_expr(ctx, value)?
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_basic_value_enum(ctx, generator)?
|
.to_basic_value_enum(ctx, generator, value.custom.unwrap())?
|
||||||
.into_pointer_value();
|
.into_pointer_value();
|
||||||
let index = generator
|
let len = ctx
|
||||||
|
.build_gep_and_load(v, &[zero, i32_type.const_int(1, false)])
|
||||||
|
.into_int_value();
|
||||||
|
let raw_index = generator
|
||||||
.gen_expr(ctx, slice)?
|
.gen_expr(ctx, slice)?
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_basic_value_enum(ctx, generator)?
|
.to_basic_value_enum(ctx, generator, slice.custom.unwrap())?
|
||||||
.into_int_value();
|
.into_int_value();
|
||||||
|
let raw_index = ctx.builder.build_int_s_extend(
|
||||||
|
raw_index,
|
||||||
|
generator.get_size_type(ctx.ctx),
|
||||||
|
"sext",
|
||||||
|
);
|
||||||
|
// handle negative index
|
||||||
|
let is_negative = ctx.builder.build_int_compare(
|
||||||
|
inkwell::IntPredicate::SLT,
|
||||||
|
raw_index,
|
||||||
|
generator.get_size_type(ctx.ctx).const_zero(),
|
||||||
|
"is_neg",
|
||||||
|
);
|
||||||
|
let adjusted = ctx.builder.build_int_add(raw_index, len, "adjusted");
|
||||||
|
let index = ctx
|
||||||
|
.builder
|
||||||
|
.build_select(is_negative, adjusted, raw_index, "index")
|
||||||
|
.into_int_value();
|
||||||
|
// unsigned less than is enough, because negative index after adjustment is
|
||||||
|
// bigger than the length (for unsigned cmp)
|
||||||
|
let bound_check = ctx.builder.build_int_compare(
|
||||||
|
inkwell::IntPredicate::ULT,
|
||||||
|
index,
|
||||||
|
len,
|
||||||
|
"inbound",
|
||||||
|
);
|
||||||
|
ctx.make_assert(
|
||||||
|
generator,
|
||||||
|
bound_check,
|
||||||
|
"0:IndexError",
|
||||||
|
"index {0} out of bounds 0:{1}",
|
||||||
|
[Some(raw_index), Some(len), None],
|
||||||
|
slice.location,
|
||||||
|
);
|
||||||
unsafe {
|
unsafe {
|
||||||
let arr_ptr = ctx
|
let arr_ptr = ctx
|
||||||
.build_gep_and_load(v, &[i32_type.const_zero(), i32_type.const_zero()])
|
.build_gep_and_load(v, &[i32_type.const_zero(), i32_type.const_zero()])
|
||||||
@ -102,7 +150,9 @@ pub fn gen_assign<'ctx, 'a, G: CodeGenerator>(
|
|||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
match &target.node {
|
match &target.node {
|
||||||
ExprKind::Tuple { elts, .. } => {
|
ExprKind::Tuple { elts, .. } => {
|
||||||
if let BasicValueEnum::StructValue(v) = value.to_basic_value_enum(ctx, generator)? {
|
if let BasicValueEnum::StructValue(v) =
|
||||||
|
value.to_basic_value_enum(ctx, generator, target.custom.unwrap())?
|
||||||
|
{
|
||||||
for (i, elt) in elts.iter().enumerate() {
|
for (i, elt) in elts.iter().enumerate() {
|
||||||
let v = ctx
|
let v = ctx
|
||||||
.builder
|
.builder
|
||||||
@ -121,11 +171,13 @@ pub fn gen_assign<'ctx, 'a, G: CodeGenerator>(
|
|||||||
let ls = generator
|
let ls = generator
|
||||||
.gen_expr(ctx, ls)?
|
.gen_expr(ctx, ls)?
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_basic_value_enum(ctx, generator)?
|
.to_basic_value_enum(ctx, generator, ls.custom.unwrap())?
|
||||||
.into_pointer_value();
|
.into_pointer_value();
|
||||||
let (start, end, step) =
|
let (start, end, step) =
|
||||||
handle_slice_indices(lower, upper, step, ctx, generator, ls)?;
|
handle_slice_indices(lower, upper, step, ctx, generator, ls)?;
|
||||||
let value = value.to_basic_value_enum(ctx, generator)?.into_pointer_value();
|
let value = value
|
||||||
|
.to_basic_value_enum(ctx, generator, target.custom.unwrap())?
|
||||||
|
.into_pointer_value();
|
||||||
let ty =
|
let ty =
|
||||||
if let TypeEnum::TList { ty } = &*ctx.unifier.get_ty(target.custom.unwrap()) {
|
if let TypeEnum::TList { ty } = &*ctx.unifier.get_ty(target.custom.unwrap()) {
|
||||||
ctx.get_llvm_type(generator, *ty)
|
ctx.get_llvm_type(generator, *ty)
|
||||||
@ -133,15 +185,7 @@ pub fn gen_assign<'ctx, 'a, G: CodeGenerator>(
|
|||||||
unreachable!()
|
unreachable!()
|
||||||
};
|
};
|
||||||
let src_ind = handle_slice_indices(&None, &None, &None, ctx, generator, value)?;
|
let src_ind = handle_slice_indices(&None, &None, &None, ctx, generator, value)?;
|
||||||
list_slice_assignment(
|
list_slice_assignment(generator, ctx, ty, ls, (start, end, step), value, src_ind)
|
||||||
ctx,
|
|
||||||
generator.get_size_type(ctx.ctx),
|
|
||||||
ty,
|
|
||||||
ls,
|
|
||||||
(start, end, step),
|
|
||||||
value,
|
|
||||||
src_ind,
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
@ -155,7 +199,7 @@ pub fn gen_assign<'ctx, 'a, G: CodeGenerator>(
|
|||||||
*static_value = Some(s.clone());
|
*static_value = Some(s.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let val = value.to_basic_value_enum(ctx, generator)?;
|
let val = value.to_basic_value_enum(ctx, generator, target.custom.unwrap())?;
|
||||||
ctx.builder.build_store(ptr, val);
|
ctx.builder.build_store(ptr, val);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -185,11 +229,16 @@ pub fn gen_for<'ctx, 'a, G: CodeGenerator>(
|
|||||||
// store loop bb information and restore it later
|
// store loop bb information and restore it later
|
||||||
let loop_bb = ctx.loop_target.replace((test_bb, cont_bb));
|
let loop_bb = ctx.loop_target.replace((test_bb, cont_bb));
|
||||||
|
|
||||||
let iter_val = generator.gen_expr(ctx, iter)?.unwrap().to_basic_value_enum(ctx, generator)?;
|
let iter_val = generator.gen_expr(ctx, iter)?.unwrap().to_basic_value_enum(
|
||||||
|
ctx,
|
||||||
|
generator,
|
||||||
|
iter.custom.unwrap(),
|
||||||
|
)?;
|
||||||
if ctx.unifier.unioned(iter.custom.unwrap(), ctx.primitives.range) {
|
if ctx.unifier.unioned(iter.custom.unwrap(), ctx.primitives.range) {
|
||||||
// setup
|
// setup
|
||||||
let iter_val = iter_val.into_pointer_value();
|
let iter_val = iter_val.into_pointer_value();
|
||||||
let i = generator.gen_store_target(ctx, target)?;
|
let i = generator.gen_var_alloc(ctx, int32.into())?;
|
||||||
|
let user_i = generator.gen_store_target(ctx, target)?;
|
||||||
let (start, end, step) = destructure_range(ctx, iter_val);
|
let (start, end, step) = destructure_range(ctx, iter_val);
|
||||||
ctx.builder.build_store(i, ctx.builder.build_int_sub(start, step, "start_init"));
|
ctx.builder.build_store(i, ctx.builder.build_int_sub(start, step, "start_init"));
|
||||||
ctx.builder.build_unconditional_branch(test_bb);
|
ctx.builder.build_unconditional_branch(test_bb);
|
||||||
@ -207,6 +256,7 @@ pub fn gen_for<'ctx, 'a, G: CodeGenerator>(
|
|||||||
"start_loop",
|
"start_loop",
|
||||||
);
|
);
|
||||||
ctx.builder.build_store(i, tmp);
|
ctx.builder.build_store(i, tmp);
|
||||||
|
ctx.builder.build_store(user_i, tmp);
|
||||||
// // if step > 0, continue when i < end
|
// // if step > 0, continue when i < end
|
||||||
let cmp1 = ctx.builder.build_int_compare(inkwell::IntPredicate::SLT, tmp, end, "cmp1");
|
let cmp1 = ctx.builder.build_int_compare(inkwell::IntPredicate::SLT, tmp, end, "cmp1");
|
||||||
// if step < 0, continue when i > end
|
// if step < 0, continue when i > end
|
||||||
@ -296,7 +346,11 @@ pub fn gen_while<'ctx, 'a, G: CodeGenerator>(
|
|||||||
let loop_bb = ctx.loop_target.replace((test_bb, cont_bb));
|
let loop_bb = ctx.loop_target.replace((test_bb, cont_bb));
|
||||||
ctx.builder.build_unconditional_branch(test_bb);
|
ctx.builder.build_unconditional_branch(test_bb);
|
||||||
ctx.builder.position_at_end(test_bb);
|
ctx.builder.position_at_end(test_bb);
|
||||||
let test = generator.gen_expr(ctx, test)?.unwrap().to_basic_value_enum(ctx, generator)?;
|
let test = generator.gen_expr(ctx, test)?.unwrap().to_basic_value_enum(
|
||||||
|
ctx,
|
||||||
|
generator,
|
||||||
|
test.custom.unwrap(),
|
||||||
|
)?;
|
||||||
if let BasicValueEnum::IntValue(test) = test {
|
if let BasicValueEnum::IntValue(test) = test {
|
||||||
ctx.builder.build_conditional_branch(test, body_bb, orelse_bb);
|
ctx.builder.build_conditional_branch(test, body_bb, orelse_bb);
|
||||||
} else {
|
} else {
|
||||||
@ -357,7 +411,11 @@ pub fn gen_if<'ctx, 'a, G: CodeGenerator>(
|
|||||||
};
|
};
|
||||||
ctx.builder.build_unconditional_branch(test_bb);
|
ctx.builder.build_unconditional_branch(test_bb);
|
||||||
ctx.builder.position_at_end(test_bb);
|
ctx.builder.position_at_end(test_bb);
|
||||||
let test = generator.gen_expr(ctx, test)?.unwrap().to_basic_value_enum(ctx, generator)?;
|
let test = generator.gen_expr(ctx, test)?.unwrap().to_basic_value_enum(
|
||||||
|
ctx,
|
||||||
|
generator,
|
||||||
|
test.custom.unwrap(),
|
||||||
|
)?;
|
||||||
if let BasicValueEnum::IntValue(test) = test {
|
if let BasicValueEnum::IntValue(test) = test {
|
||||||
ctx.builder.build_conditional_branch(test, body_bb, orelse_bb);
|
ctx.builder.build_conditional_branch(test, body_bb, orelse_bb);
|
||||||
} else {
|
} else {
|
||||||
@ -420,8 +478,8 @@ pub fn final_proxy<'ctx, 'a>(
|
|||||||
final_paths.push(block);
|
final_paths.push(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_builtins<'ctx, 'a, G: CodeGenerator>(
|
pub fn get_builtins<'ctx, 'a>(
|
||||||
generator: &mut G,
|
generator: &mut dyn CodeGenerator,
|
||||||
ctx: &mut CodeGenContext<'ctx, 'a>,
|
ctx: &mut CodeGenContext<'ctx, 'a>,
|
||||||
symbol: &str,
|
symbol: &str,
|
||||||
) -> FunctionValue<'ctx> {
|
) -> FunctionValue<'ctx> {
|
||||||
@ -439,7 +497,7 @@ pub fn get_builtins<'ctx, 'a, G: CodeGenerator>(
|
|||||||
if symbol == "__nac3_raise" || symbol == "__nac3_resume" {
|
if symbol == "__nac3_raise" || symbol == "__nac3_resume" {
|
||||||
fun.add_attribute(
|
fun.add_attribute(
|
||||||
AttributeLoc::Function,
|
AttributeLoc::Function,
|
||||||
ctx.ctx.create_enum_attribute(Attribute::get_named_enum_kind_id("noreturn"), 1),
|
ctx.ctx.create_enum_attribute(Attribute::get_named_enum_kind_id("noreturn"), 0),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
fun
|
fun
|
||||||
@ -454,7 +512,7 @@ pub fn exn_constructor<'ctx, 'a>(
|
|||||||
generator: &mut dyn CodeGenerator,
|
generator: &mut dyn CodeGenerator,
|
||||||
) -> Result<Option<BasicValueEnum<'ctx>>, String> {
|
) -> Result<Option<BasicValueEnum<'ctx>>, String> {
|
||||||
let (zelf_ty, zelf) = obj.unwrap();
|
let (zelf_ty, zelf) = obj.unwrap();
|
||||||
let zelf = zelf.to_basic_value_enum(ctx, generator)?.into_pointer_value();
|
let zelf = zelf.to_basic_value_enum(ctx, generator, zelf_ty)?.into_pointer_value();
|
||||||
let int32 = ctx.ctx.i32_type();
|
let int32 = ctx.ctx.i32_type();
|
||||||
let zero = int32.const_zero();
|
let zero = int32.const_zero();
|
||||||
let zelf_id = {
|
let zelf_id = {
|
||||||
@ -477,14 +535,14 @@ pub fn exn_constructor<'ctx, 'a>(
|
|||||||
let ptr =
|
let ptr =
|
||||||
ctx.builder.build_in_bounds_gep(zelf, &[zero, int32.const_int(5, false)], "exn.msg");
|
ctx.builder.build_in_bounds_gep(zelf, &[zero, int32.const_int(5, false)], "exn.msg");
|
||||||
let msg = if !args.is_empty() {
|
let msg = if !args.is_empty() {
|
||||||
args.remove(0).1.to_basic_value_enum(ctx, generator)?
|
args.remove(0).1.to_basic_value_enum(ctx, generator, ctx.primitives.str)?
|
||||||
} else {
|
} else {
|
||||||
empty_string
|
empty_string
|
||||||
};
|
};
|
||||||
ctx.builder.build_store(ptr, msg);
|
ctx.builder.build_store(ptr, msg);
|
||||||
for i in [6, 7, 8].iter() {
|
for i in [6, 7, 8].iter() {
|
||||||
let value = if !args.is_empty() {
|
let value = if !args.is_empty() {
|
||||||
args.remove(0).1.to_basic_value_enum(ctx, generator)?
|
args.remove(0).1.to_basic_value_enum(ctx, generator, ctx.primitives.int64)?
|
||||||
} else {
|
} else {
|
||||||
ctx.ctx.i64_type().const_zero().into()
|
ctx.ctx.i64_type().const_zero().into()
|
||||||
};
|
};
|
||||||
@ -517,8 +575,8 @@ pub fn exn_constructor<'ctx, 'a>(
|
|||||||
Ok(Some(zelf.into()))
|
Ok(Some(zelf.into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn gen_raise<'ctx, 'a, G: CodeGenerator>(
|
pub fn gen_raise<'ctx, 'a>(
|
||||||
generator: &mut G,
|
generator: &mut dyn CodeGenerator,
|
||||||
ctx: &mut CodeGenContext<'ctx, 'a>,
|
ctx: &mut CodeGenContext<'ctx, 'a>,
|
||||||
exception: Option<&BasicValueEnum<'ctx>>,
|
exception: Option<&BasicValueEnum<'ctx>>,
|
||||||
loc: Location,
|
loc: Location,
|
||||||
@ -906,7 +964,11 @@ pub fn gen_return<'ctx, 'a, G: CodeGenerator>(
|
|||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
let value = value
|
let value = value
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|v| generator.gen_expr(ctx, v).and_then(|v| v.unwrap().to_basic_value_enum(ctx, generator)))
|
.map(|v_expr| {
|
||||||
|
generator.gen_expr(ctx, v_expr).and_then(|v| {
|
||||||
|
v.unwrap().to_basic_value_enum(ctx, generator, v_expr.custom.unwrap())
|
||||||
|
})
|
||||||
|
})
|
||||||
.transpose()?;
|
.transpose()?;
|
||||||
if let Some(return_target) = ctx.return_target {
|
if let Some(return_target) = ctx.return_target {
|
||||||
if let Some(value) = value {
|
if let Some(value) = value {
|
||||||
@ -929,6 +991,17 @@ pub fn gen_stmt<'ctx, 'a, G: CodeGenerator>(
|
|||||||
ctx: &mut CodeGenContext<'ctx, 'a>,
|
ctx: &mut CodeGenContext<'ctx, 'a>,
|
||||||
stmt: &Stmt<Option<Type>>,
|
stmt: &Stmt<Option<Type>>,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
|
ctx.current_loc = stmt.location;
|
||||||
|
|
||||||
|
let loc = ctx.debug_info.0.create_debug_location(
|
||||||
|
ctx.ctx,
|
||||||
|
ctx.current_loc.row as u32,
|
||||||
|
ctx.current_loc.column as u32,
|
||||||
|
ctx.debug_info.2,
|
||||||
|
None,
|
||||||
|
);
|
||||||
|
ctx.builder.set_current_debug_location(ctx.ctx, loc);
|
||||||
|
|
||||||
match &stmt.node {
|
match &stmt.node {
|
||||||
StmtKind::Pass { .. } => {}
|
StmtKind::Pass { .. } => {}
|
||||||
StmtKind::Expr { value, .. } => {
|
StmtKind::Expr { value, .. } => {
|
||||||
@ -960,20 +1033,46 @@ pub fn gen_stmt<'ctx, 'a, G: CodeGenerator>(
|
|||||||
StmtKind::For { .. } => generator.gen_for(ctx, stmt)?,
|
StmtKind::For { .. } => generator.gen_for(ctx, stmt)?,
|
||||||
StmtKind::With { .. } => generator.gen_with(ctx, stmt)?,
|
StmtKind::With { .. } => generator.gen_with(ctx, stmt)?,
|
||||||
StmtKind::AugAssign { target, op, value, .. } => {
|
StmtKind::AugAssign { target, op, value, .. } => {
|
||||||
let value = gen_binop_expr(generator, ctx, target, op, value)?;
|
let value = gen_binop_expr(generator, ctx, target, op, value, stmt.location, true)?;
|
||||||
generator.gen_assign(ctx, target, value)?;
|
generator.gen_assign(ctx, target, value.unwrap())?;
|
||||||
}
|
}
|
||||||
StmtKind::Try { .. } => gen_try(generator, ctx, stmt)?,
|
StmtKind::Try { .. } => gen_try(generator, ctx, stmt)?,
|
||||||
StmtKind::Raise { exc, .. } => {
|
StmtKind::Raise { exc, .. } => {
|
||||||
if let Some(exc) = exc {
|
if let Some(exc) = exc {
|
||||||
let exc =
|
let exc = generator.gen_expr(ctx, exc)?.unwrap().to_basic_value_enum(
|
||||||
generator.gen_expr(ctx, exc)?.unwrap().to_basic_value_enum(ctx, generator)?;
|
ctx,
|
||||||
|
generator,
|
||||||
|
exc.custom.unwrap(),
|
||||||
|
)?;
|
||||||
gen_raise(generator, ctx, Some(&exc), stmt.location);
|
gen_raise(generator, ctx, Some(&exc), stmt.location);
|
||||||
} else {
|
} else {
|
||||||
gen_raise(generator, ctx, None, stmt.location);
|
gen_raise(generator, ctx, None, stmt.location);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => unimplemented!(),
|
StmtKind::Assert { test, msg, .. } => {
|
||||||
|
let test = generator.gen_expr(ctx, test)?.unwrap().to_basic_value_enum(
|
||||||
|
ctx,
|
||||||
|
generator,
|
||||||
|
test.custom.unwrap(),
|
||||||
|
)?;
|
||||||
|
let err_msg = match msg {
|
||||||
|
Some(msg) => generator.gen_expr(ctx, msg)?.unwrap().to_basic_value_enum(
|
||||||
|
ctx,
|
||||||
|
generator,
|
||||||
|
msg.custom.unwrap(),
|
||||||
|
)?,
|
||||||
|
None => ctx.gen_string(generator, ""),
|
||||||
|
};
|
||||||
|
ctx.make_assert_impl(
|
||||||
|
generator,
|
||||||
|
test.into_int_value(),
|
||||||
|
"0:AssertionError",
|
||||||
|
err_msg,
|
||||||
|
[None, None, None],
|
||||||
|
stmt.location,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
_ => unimplemented!()
|
||||||
};
|
};
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ impl SymbolResolver for Resolver {
|
|||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_exception_id(&self, tyid: usize) -> usize {
|
fn get_exception_id(&self, _tyid: usize) -> usize {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -181,13 +181,41 @@ fn test_primitives() {
|
|||||||
; ModuleID = 'test'
|
; ModuleID = 'test'
|
||||||
source_filename = \"test\"
|
source_filename = \"test\"
|
||||||
|
|
||||||
define i32 @testing(i32 %0, i32 %1) {
|
define i32 @testing(i32 %0, i32 %1) !dbg !4 {
|
||||||
init:
|
init:
|
||||||
%add = add i32 %0, %1
|
%add = add i32 %0, %1, !dbg !9
|
||||||
%cmp = icmp eq i32 %add, 1
|
%cmp = icmp eq i32 %add, 1, !dbg !10
|
||||||
%ifexpr = select i1 %cmp, i32 %0, i32 0
|
br i1 %cmp, label %then, label %else, !dbg !10
|
||||||
ret i32 %ifexpr
|
|
||||||
|
then: ; preds = %init
|
||||||
|
br label %cont, !dbg !11
|
||||||
|
|
||||||
|
else: ; preds = %init
|
||||||
|
br label %cont, !dbg !12
|
||||||
|
|
||||||
|
cont: ; preds = %else, %then
|
||||||
|
%if_exp_result.0 = phi i32 [ %0, %then ], [ 0, %else ], !dbg !13
|
||||||
|
ret i32 %if_exp_result.0, !dbg !14
|
||||||
}
|
}
|
||||||
|
|
||||||
|
!llvm.module.flags = !{!0, !1}
|
||||||
|
!llvm.dbg.cu = !{!2}
|
||||||
|
|
||||||
|
!0 = !{i32 2, !\"Debug Info Version\", i32 3}
|
||||||
|
!1 = !{i32 2, !\"Dwarf Version\", i32 4}
|
||||||
|
!2 = distinct !DICompileUnit(language: DW_LANG_Python, file: !3, producer: \"NAC3\", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
|
||||||
|
!3 = !DIFile(filename: \"unknown\", directory: \"\")
|
||||||
|
!4 = distinct !DISubprogram(name: \"testing\", linkageName: \"testing\", scope: null, file: !3, line: 1, type: !5, scopeLine: 1, flags: DIFlagPublic, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !8)
|
||||||
|
!5 = !DISubroutineType(flags: DIFlagPublic, types: !6)
|
||||||
|
!6 = !{!7}
|
||||||
|
!7 = !DIBasicType(name: \"_\", flags: DIFlagPublic)
|
||||||
|
!8 = !{}
|
||||||
|
!9 = !DILocation(line: 1, column: 9, scope: !4)
|
||||||
|
!10 = !DILocation(line: 2, column: 15, scope: !4)
|
||||||
|
!11 = !DILocation(line: 2, column: 5, scope: !4)
|
||||||
|
!12 = !DILocation(line: 2, column: 22, scope: !4)
|
||||||
|
!13 = !DILocation(line: 0, scope: !4)
|
||||||
|
!14 = !DILocation(line: 3, column: 8, scope: !4)
|
||||||
"}
|
"}
|
||||||
.trim();
|
.trim();
|
||||||
assert_eq!(expected, module.print_to_string().to_str().unwrap().trim());
|
assert_eq!(expected, module.print_to_string().to_str().unwrap().trim());
|
||||||
@ -333,18 +361,36 @@ fn test_simple_call() {
|
|||||||
; ModuleID = 'test'
|
; ModuleID = 'test'
|
||||||
source_filename = \"test\"
|
source_filename = \"test\"
|
||||||
|
|
||||||
define i32 @testing(i32 %0) {
|
define i32 @testing(i32 %0) !dbg !5 {
|
||||||
init:
|
init:
|
||||||
%call = call i32 @foo.0(i32 %0)
|
%call = call i32 @foo.0(i32 %0), !dbg !10
|
||||||
%mul = mul i32 %call, 2
|
%mul = mul i32 %call, 2, !dbg !11
|
||||||
ret i32 %mul
|
ret i32 %mul, !dbg !11
|
||||||
}
|
}
|
||||||
|
|
||||||
define i32 @foo.0(i32 %0) {
|
define i32 @foo.0(i32 %0) !dbg !12 {
|
||||||
init:
|
init:
|
||||||
%add = add i32 %0, 1
|
%add = add i32 %0, 1, !dbg !13
|
||||||
ret i32 %add
|
ret i32 %add, !dbg !13
|
||||||
}
|
}
|
||||||
|
|
||||||
|
!llvm.module.flags = !{!0, !1}
|
||||||
|
!llvm.dbg.cu = !{!2, !4}
|
||||||
|
|
||||||
|
!0 = !{i32 2, !\"Debug Info Version\", i32 3}
|
||||||
|
!1 = !{i32 2, !\"Dwarf Version\", i32 4}
|
||||||
|
!2 = distinct !DICompileUnit(language: DW_LANG_Python, file: !3, producer: \"NAC3\", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
|
||||||
|
!3 = !DIFile(filename: \"unknown\", directory: \"\")
|
||||||
|
!4 = distinct !DICompileUnit(language: DW_LANG_Python, file: !3, producer: \"NAC3\", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
|
||||||
|
!5 = distinct !DISubprogram(name: \"testing\", linkageName: \"testing\", scope: null, file: !3, line: 1, type: !6, scopeLine: 1, flags: DIFlagPublic, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !9)
|
||||||
|
!6 = !DISubroutineType(flags: DIFlagPublic, types: !7)
|
||||||
|
!7 = !{!8}
|
||||||
|
!8 = !DIBasicType(name: \"_\", flags: DIFlagPublic)
|
||||||
|
!9 = !{}
|
||||||
|
!10 = !DILocation(line: 1, column: 9, scope: !5)
|
||||||
|
!11 = !DILocation(line: 2, column: 12, scope: !5)
|
||||||
|
!12 = distinct !DISubprogram(name: \"foo.0\", linkageName: \"foo.0\", scope: null, file: !3, line: 1, type: !6, scopeLine: 1, flags: DIFlagPublic, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !4, retainedNodes: !9)
|
||||||
|
!13 = !DILocation(line: 1, column: 12, scope: !12)
|
||||||
"}
|
"}
|
||||||
.trim();
|
.trim();
|
||||||
assert_eq!(expected, module.print_to_string().to_str().unwrap().trim());
|
assert_eq!(expected, module.print_to_string().to_str().unwrap().trim());
|
||||||
|
@ -14,7 +14,7 @@ use crate::{
|
|||||||
typedef::{Type, Unifier},
|
typedef::{Type, Unifier},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use inkwell::values::{BasicValueEnum, FloatValue, IntValue, PointerValue};
|
use inkwell::values::{BasicValueEnum, FloatValue, IntValue, PointerValue, StructValue};
|
||||||
use itertools::{chain, izip};
|
use itertools::{chain, izip};
|
||||||
use nac3parser::ast::{Expr, Location, StrRef};
|
use nac3parser::ast::{Expr, Location, StrRef};
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
@ -29,6 +29,8 @@ pub enum SymbolValue {
|
|||||||
Double(f64),
|
Double(f64),
|
||||||
Bool(bool),
|
Bool(bool),
|
||||||
Tuple(Vec<SymbolValue>),
|
Tuple(Vec<SymbolValue>),
|
||||||
|
OptionSome(Box<SymbolValue>),
|
||||||
|
OptionNone,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for SymbolValue {
|
impl Display for SymbolValue {
|
||||||
@ -50,6 +52,8 @@ impl Display for SymbolValue {
|
|||||||
SymbolValue::Tuple(t) => {
|
SymbolValue::Tuple(t) => {
|
||||||
write!(f, "({})", t.iter().map(|v| format!("{}", v)).collect::<Vec<_>>().join(", "))
|
write!(f, "({})", t.iter().map(|v| format!("{}", v)).collect::<Vec<_>>().join(", "))
|
||||||
}
|
}
|
||||||
|
SymbolValue::OptionSome(v) => write!(f, "Some({})", v),
|
||||||
|
SymbolValue::OptionNone => write!(f, "none"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -67,6 +71,7 @@ pub trait StaticValue {
|
|||||||
&self,
|
&self,
|
||||||
ctx: &mut CodeGenContext<'ctx, 'a>,
|
ctx: &mut CodeGenContext<'ctx, 'a>,
|
||||||
generator: &mut dyn CodeGenerator,
|
generator: &mut dyn CodeGenerator,
|
||||||
|
expected_ty: Type,
|
||||||
) -> Result<BasicValueEnum<'ctx>, String>;
|
) -> Result<BasicValueEnum<'ctx>, String>;
|
||||||
|
|
||||||
fn get_field<'ctx, 'a>(
|
fn get_field<'ctx, 'a>(
|
||||||
@ -74,6 +79,8 @@ pub trait StaticValue {
|
|||||||
name: StrRef,
|
name: StrRef,
|
||||||
ctx: &mut CodeGenContext<'ctx, 'a>,
|
ctx: &mut CodeGenContext<'ctx, 'a>,
|
||||||
) -> Option<ValueEnum<'ctx>>;
|
) -> Option<ValueEnum<'ctx>>;
|
||||||
|
|
||||||
|
fn get_tuple_element<'ctx>(&self, index: u32) -> Option<ValueEnum<'ctx>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@ -106,14 +113,21 @@ impl<'ctx> From<FloatValue<'ctx>> for ValueEnum<'ctx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'ctx> From<StructValue<'ctx>> for ValueEnum<'ctx> {
|
||||||
|
fn from(v: StructValue<'ctx>) -> Self {
|
||||||
|
ValueEnum::Dynamic(v.into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'ctx> ValueEnum<'ctx> {
|
impl<'ctx> ValueEnum<'ctx> {
|
||||||
pub fn to_basic_value_enum<'a>(
|
pub fn to_basic_value_enum<'a>(
|
||||||
self,
|
self,
|
||||||
ctx: &mut CodeGenContext<'ctx, 'a>,
|
ctx: &mut CodeGenContext<'ctx, 'a>,
|
||||||
generator: &mut dyn CodeGenerator,
|
generator: &mut dyn CodeGenerator,
|
||||||
|
expected_ty: Type,
|
||||||
) -> Result<BasicValueEnum<'ctx>, String> {
|
) -> Result<BasicValueEnum<'ctx>, String> {
|
||||||
match self {
|
match self {
|
||||||
ValueEnum::Static(v) => v.to_basic_value_enum(ctx, generator),
|
ValueEnum::Static(v) => v.to_basic_value_enum(ctx, generator, expected_ty),
|
||||||
ValueEnum::Dynamic(v) => Ok(v),
|
ValueEnum::Dynamic(v) => Ok(v),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -353,7 +367,7 @@ impl dyn SymbolResolver + Send + Sync {
|
|||||||
unreachable!("expected class definition")
|
unreachable!("expected class definition")
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
&mut |id| format!("var{}", id),
|
&mut |id| format!("typevar{}", id),
|
||||||
&mut None,
|
&mut None,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -105,7 +105,8 @@ pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo {
|
|||||||
("__param2__".into(), int64, true),
|
("__param2__".into(), int64, true),
|
||||||
];
|
];
|
||||||
|
|
||||||
// for Option, is_some and is_none share the same type
|
// for Option, is_some and is_none share the same type: () -> bool,
|
||||||
|
// and they are methods under the same class `Option`
|
||||||
let (is_some_ty, unwrap_ty, (option_ty_var, option_ty_var_id)) =
|
let (is_some_ty, unwrap_ty, (option_ty_var, option_ty_var_id)) =
|
||||||
if let TypeEnum::TObj { fields, params, .. } =
|
if let TypeEnum::TObj { fields, params, .. } =
|
||||||
primitives.1.get_ty(primitives.0.option).as_ref()
|
primitives.1.get_ty(primitives.0.option).as_ref()
|
||||||
@ -223,7 +224,12 @@ pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo {
|
|||||||
resolver: None,
|
resolver: None,
|
||||||
codegen_callback: Some(Arc::new(GenCall::new(Box::new(
|
codegen_callback: Some(Arc::new(GenCall::new(Box::new(
|
||||||
|ctx, obj, _, _, generator| {
|
|ctx, obj, _, _, generator| {
|
||||||
let obj_val = obj.unwrap().1.clone().to_basic_value_enum(ctx, generator)?;
|
let expect_ty = obj.clone().unwrap().0;
|
||||||
|
let obj_val = obj.unwrap().1.clone().to_basic_value_enum(
|
||||||
|
ctx,
|
||||||
|
generator,
|
||||||
|
expect_ty,
|
||||||
|
)?;
|
||||||
if let BasicValueEnum::PointerValue(ptr) = obj_val {
|
if let BasicValueEnum::PointerValue(ptr) = obj_val {
|
||||||
Ok(Some(ctx.builder.build_is_not_null(ptr, "is_some").into()))
|
Ok(Some(ctx.builder.build_is_not_null(ptr, "is_some").into()))
|
||||||
} else {
|
} else {
|
||||||
@ -243,7 +249,12 @@ pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo {
|
|||||||
resolver: None,
|
resolver: None,
|
||||||
codegen_callback: Some(Arc::new(GenCall::new(Box::new(
|
codegen_callback: Some(Arc::new(GenCall::new(Box::new(
|
||||||
|ctx, obj, _, _, generator| {
|
|ctx, obj, _, _, generator| {
|
||||||
let obj_val = obj.unwrap().1.clone().to_basic_value_enum(ctx, generator)?;
|
let expect_ty = obj.clone().unwrap().0;
|
||||||
|
let obj_val = obj.unwrap().1.clone().to_basic_value_enum(
|
||||||
|
ctx,
|
||||||
|
generator,
|
||||||
|
expect_ty,
|
||||||
|
)?;
|
||||||
if let BasicValueEnum::PointerValue(ptr) = obj_val {
|
if let BasicValueEnum::PointerValue(ptr) = obj_val {
|
||||||
Ok(Some(ctx.builder.build_is_null(ptr, "is_none").into()))
|
Ok(Some(ctx.builder.build_is_null(ptr, "is_none").into()))
|
||||||
} else {
|
} else {
|
||||||
@ -262,7 +273,7 @@ pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo {
|
|||||||
instance_to_stmt: Default::default(),
|
instance_to_stmt: Default::default(),
|
||||||
resolver: None,
|
resolver: None,
|
||||||
codegen_callback: Some(Arc::new(GenCall::new(Box::new(
|
codegen_callback: Some(Arc::new(GenCall::new(Box::new(
|
||||||
|ctx, obj, _, _, generator| {
|
|_, _, _, _, _| {
|
||||||
unreachable!("handled in gen_expr")
|
unreachable!("handled in gen_expr")
|
||||||
},
|
},
|
||||||
)))),
|
)))),
|
||||||
@ -289,7 +300,7 @@ pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo {
|
|||||||
let float = ctx.primitives.float;
|
let float = ctx.primitives.float;
|
||||||
let boolean = ctx.primitives.bool;
|
let boolean = ctx.primitives.bool;
|
||||||
let arg_ty = fun.0.args[0].ty;
|
let arg_ty = fun.0.args[0].ty;
|
||||||
let arg = args[0].1.clone().to_basic_value_enum(ctx, generator)?;
|
let arg = args[0].1.clone().to_basic_value_enum(ctx, generator, arg_ty)?;
|
||||||
Ok(if ctx.unifier.unioned(arg_ty, boolean) {
|
Ok(if ctx.unifier.unioned(arg_ty, boolean) {
|
||||||
Some(
|
Some(
|
||||||
ctx.builder
|
ctx.builder
|
||||||
@ -354,7 +365,7 @@ pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo {
|
|||||||
let float = ctx.primitives.float;
|
let float = ctx.primitives.float;
|
||||||
let boolean = ctx.primitives.bool;
|
let boolean = ctx.primitives.bool;
|
||||||
let arg_ty = fun.0.args[0].ty;
|
let arg_ty = fun.0.args[0].ty;
|
||||||
let arg = args[0].1.clone().to_basic_value_enum(ctx, generator)?;
|
let arg = args[0].1.clone().to_basic_value_enum(ctx, generator, arg_ty)?;
|
||||||
Ok(
|
Ok(
|
||||||
if ctx.unifier.unioned(arg_ty, boolean)
|
if ctx.unifier.unioned(arg_ty, boolean)
|
||||||
|| ctx.unifier.unioned(arg_ty, uint32)
|
|| ctx.unifier.unioned(arg_ty, uint32)
|
||||||
@ -421,7 +432,7 @@ pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo {
|
|||||||
let float = ctx.primitives.float;
|
let float = ctx.primitives.float;
|
||||||
let boolean = ctx.primitives.bool;
|
let boolean = ctx.primitives.bool;
|
||||||
let arg_ty = fun.0.args[0].ty;
|
let arg_ty = fun.0.args[0].ty;
|
||||||
let arg = args[0].1.clone().to_basic_value_enum(ctx, generator)?;
|
let arg = args[0].1.clone().to_basic_value_enum(ctx, generator, arg_ty)?;
|
||||||
let res = if ctx.unifier.unioned(arg_ty, boolean) {
|
let res = if ctx.unifier.unioned(arg_ty, boolean) {
|
||||||
ctx.builder
|
ctx.builder
|
||||||
.build_int_z_extend(arg.into_int_value(), ctx.ctx.i64_type(), "zext")
|
.build_int_z_extend(arg.into_int_value(), ctx.ctx.i64_type(), "zext")
|
||||||
@ -473,7 +484,7 @@ pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo {
|
|||||||
let float = ctx.primitives.float;
|
let float = ctx.primitives.float;
|
||||||
let boolean = ctx.primitives.bool;
|
let boolean = ctx.primitives.bool;
|
||||||
let arg_ty = fun.0.args[0].ty;
|
let arg_ty = fun.0.args[0].ty;
|
||||||
let arg = args[0].1.clone().to_basic_value_enum(ctx, generator)?;
|
let arg = args[0].1.clone().to_basic_value_enum(ctx, generator, arg_ty)?;
|
||||||
let res = if ctx.unifier.unioned(arg_ty, int32)
|
let res = if ctx.unifier.unioned(arg_ty, int32)
|
||||||
|| ctx.unifier.unioned(arg_ty, uint32)
|
|| ctx.unifier.unioned(arg_ty, uint32)
|
||||||
|| ctx.unifier.unioned(arg_ty, boolean)
|
|| ctx.unifier.unioned(arg_ty, boolean)
|
||||||
@ -520,7 +531,7 @@ pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo {
|
|||||||
let boolean = ctx.primitives.bool;
|
let boolean = ctx.primitives.bool;
|
||||||
let float = ctx.primitives.float;
|
let float = ctx.primitives.float;
|
||||||
let arg_ty = fun.0.args[0].ty;
|
let arg_ty = fun.0.args[0].ty;
|
||||||
let arg = args[0].1.clone().to_basic_value_enum(ctx, generator)?;
|
let arg = args[0].1.clone().to_basic_value_enum(ctx, generator, arg_ty)?;
|
||||||
Ok(
|
Ok(
|
||||||
if ctx.unifier.unioned(arg_ty, boolean)
|
if ctx.unifier.unioned(arg_ty, boolean)
|
||||||
|| ctx.unifier.unioned(arg_ty, int32)
|
|| ctx.unifier.unioned(arg_ty, int32)
|
||||||
@ -556,7 +567,7 @@ pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo {
|
|||||||
resolver: None,
|
resolver: None,
|
||||||
codegen_callback: Some(Arc::new(GenCall::new(Box::new(
|
codegen_callback: Some(Arc::new(GenCall::new(Box::new(
|
||||||
|ctx, _, _, args, generator| {
|
|ctx, _, _, args, generator| {
|
||||||
let arg = args[0].1.clone().to_basic_value_enum(ctx, generator)?;
|
let arg = args[0].1.clone().to_basic_value_enum(ctx, generator, ctx.primitives.float)?;
|
||||||
let round_intrinsic =
|
let round_intrinsic =
|
||||||
ctx.module.get_function("llvm.round.f64").unwrap_or_else(|| {
|
ctx.module.get_function("llvm.round.f64").unwrap_or_else(|| {
|
||||||
let float = ctx.ctx.f64_type();
|
let float = ctx.ctx.f64_type();
|
||||||
@ -596,7 +607,7 @@ pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo {
|
|||||||
resolver: None,
|
resolver: None,
|
||||||
codegen_callback: Some(Arc::new(GenCall::new(Box::new(
|
codegen_callback: Some(Arc::new(GenCall::new(Box::new(
|
||||||
|ctx, _, _, args, generator| {
|
|ctx, _, _, args, generator| {
|
||||||
let arg = args[0].1.clone().to_basic_value_enum(ctx, generator)?;
|
let arg = args[0].1.clone().to_basic_value_enum(ctx, generator, ctx.primitives.float)?;
|
||||||
let round_intrinsic =
|
let round_intrinsic =
|
||||||
ctx.module.get_function("llvm.round.f64").unwrap_or_else(|| {
|
ctx.module.get_function("llvm.round.f64").unwrap_or_else(|| {
|
||||||
let float = ctx.ctx.f64_type();
|
let float = ctx.ctx.f64_type();
|
||||||
@ -654,23 +665,44 @@ pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo {
|
|||||||
let mut step = None;
|
let mut step = None;
|
||||||
let int32 = ctx.ctx.i32_type();
|
let int32 = ctx.ctx.i32_type();
|
||||||
let zero = int32.const_zero();
|
let zero = int32.const_zero();
|
||||||
|
let ty_i32 = ctx.primitives.int32;
|
||||||
for (i, arg) in args.iter().enumerate() {
|
for (i, arg) in args.iter().enumerate() {
|
||||||
if arg.0 == Some("start".into()) {
|
if arg.0 == Some("start".into()) {
|
||||||
start = Some(arg.1.clone().to_basic_value_enum(ctx, generator)?);
|
start = Some(arg.1.clone().to_basic_value_enum(ctx, generator, ty_i32)?);
|
||||||
} else if arg.0 == Some("stop".into()) {
|
} else if arg.0 == Some("stop".into()) {
|
||||||
stop = Some(arg.1.clone().to_basic_value_enum(ctx, generator)?);
|
stop = Some(arg.1.clone().to_basic_value_enum(ctx, generator, ty_i32)?);
|
||||||
} else if arg.0 == Some("step".into()) {
|
} else if arg.0 == Some("step".into()) {
|
||||||
step = Some(arg.1.clone().to_basic_value_enum(ctx, generator)?);
|
step = Some(arg.1.clone().to_basic_value_enum(ctx, generator, ty_i32)?);
|
||||||
} else if i == 0 {
|
} else if i == 0 {
|
||||||
start = Some(arg.1.clone().to_basic_value_enum(ctx, generator)?);
|
start = Some(arg.1.clone().to_basic_value_enum(ctx, generator, ty_i32)?);
|
||||||
} else if i == 1 {
|
} else if i == 1 {
|
||||||
stop = Some(arg.1.clone().to_basic_value_enum(ctx, generator)?);
|
stop = Some(arg.1.clone().to_basic_value_enum(ctx, generator, ty_i32)?);
|
||||||
} else if i == 2 {
|
} else if i == 2 {
|
||||||
step = Some(arg.1.clone().to_basic_value_enum(ctx, generator)?);
|
step = Some(arg.1.clone().to_basic_value_enum(ctx, generator, ty_i32)?);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO: error when step == 0
|
let step = match step {
|
||||||
let step = step.unwrap_or_else(|| int32.const_int(1, false).into());
|
Some(step) => {
|
||||||
|
let step = step.into_int_value();
|
||||||
|
// assert step != 0, throw exception if not
|
||||||
|
let not_zero = ctx.builder.build_int_compare(
|
||||||
|
IntPredicate::NE,
|
||||||
|
step,
|
||||||
|
step.get_type().const_zero(),
|
||||||
|
"range_step_ne",
|
||||||
|
);
|
||||||
|
ctx.make_assert(
|
||||||
|
generator,
|
||||||
|
not_zero,
|
||||||
|
"0:ValueError",
|
||||||
|
"range() step must not be zero",
|
||||||
|
[None, None, None],
|
||||||
|
ctx.current_loc,
|
||||||
|
);
|
||||||
|
step
|
||||||
|
}
|
||||||
|
None => int32.const_int(1, false),
|
||||||
|
};
|
||||||
let stop = stop.unwrap_or_else(|| {
|
let stop = stop.unwrap_or_else(|| {
|
||||||
let v = start.unwrap();
|
let v = start.unwrap();
|
||||||
start = None;
|
start = None;
|
||||||
@ -713,8 +745,9 @@ pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo {
|
|||||||
instance_to_stmt: Default::default(),
|
instance_to_stmt: Default::default(),
|
||||||
resolver: None,
|
resolver: None,
|
||||||
codegen_callback: Some(Arc::new(GenCall::new(Box::new(
|
codegen_callback: Some(Arc::new(GenCall::new(Box::new(
|
||||||
|ctx, _, _, args, generator| {
|
|ctx, _, fun, args, generator| {
|
||||||
Ok(Some(args[0].1.clone().to_basic_value_enum(ctx, generator)?))
|
let arg_ty = fun.0.args[0].ty;
|
||||||
|
Ok(Some(args[0].1.clone().to_basic_value_enum(ctx, generator, arg_ty)?))
|
||||||
},
|
},
|
||||||
)))),
|
)))),
|
||||||
loc: None,
|
loc: None,
|
||||||
@ -738,7 +771,7 @@ pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo {
|
|||||||
let float = ctx.primitives.float;
|
let float = ctx.primitives.float;
|
||||||
let boolean = ctx.primitives.bool;
|
let boolean = ctx.primitives.bool;
|
||||||
let arg_ty = fun.0.args[0].ty;
|
let arg_ty = fun.0.args[0].ty;
|
||||||
let arg = args[0].1.clone().to_basic_value_enum(ctx, generator)?;
|
let arg = args[0].1.clone().to_basic_value_enum(ctx, generator, arg_ty)?;
|
||||||
Ok(if ctx.unifier.unioned(arg_ty, boolean) {
|
Ok(if ctx.unifier.unioned(arg_ty, boolean) {
|
||||||
Some(arg)
|
Some(arg)
|
||||||
} else if ctx.unifier.unioned(arg_ty, int32) {
|
} else if ctx.unifier.unioned(arg_ty, int32) {
|
||||||
@ -796,7 +829,7 @@ pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo {
|
|||||||
resolver: None,
|
resolver: None,
|
||||||
codegen_callback: Some(Arc::new(GenCall::new(Box::new(
|
codegen_callback: Some(Arc::new(GenCall::new(Box::new(
|
||||||
|ctx, _, _, args, generator| {
|
|ctx, _, _, args, generator| {
|
||||||
let arg = args[0].1.clone().to_basic_value_enum(ctx, generator)?;
|
let arg = args[0].1.clone().to_basic_value_enum(ctx, generator, ctx.primitives.float)?;
|
||||||
let floor_intrinsic =
|
let floor_intrinsic =
|
||||||
ctx.module.get_function("llvm.floor.f64").unwrap_or_else(|| {
|
ctx.module.get_function("llvm.floor.f64").unwrap_or_else(|| {
|
||||||
let float = ctx.ctx.f64_type();
|
let float = ctx.ctx.f64_type();
|
||||||
@ -836,7 +869,7 @@ pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo {
|
|||||||
resolver: None,
|
resolver: None,
|
||||||
codegen_callback: Some(Arc::new(GenCall::new(Box::new(
|
codegen_callback: Some(Arc::new(GenCall::new(Box::new(
|
||||||
|ctx, _, _, args, generator| {
|
|ctx, _, _, args, generator| {
|
||||||
let arg = args[0].1.clone().to_basic_value_enum(ctx, generator)?;
|
let arg = args[0].1.clone().to_basic_value_enum(ctx, generator, ctx.primitives.float)?;
|
||||||
let floor_intrinsic =
|
let floor_intrinsic =
|
||||||
ctx.module.get_function("llvm.floor.f64").unwrap_or_else(|| {
|
ctx.module.get_function("llvm.floor.f64").unwrap_or_else(|| {
|
||||||
let float = ctx.ctx.f64_type();
|
let float = ctx.ctx.f64_type();
|
||||||
@ -876,7 +909,7 @@ pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo {
|
|||||||
resolver: None,
|
resolver: None,
|
||||||
codegen_callback: Some(Arc::new(GenCall::new(Box::new(
|
codegen_callback: Some(Arc::new(GenCall::new(Box::new(
|
||||||
|ctx, _, _, args, generator| {
|
|ctx, _, _, args, generator| {
|
||||||
let arg = args[0].1.clone().to_basic_value_enum(ctx, generator)?;
|
let arg = args[0].1.clone().to_basic_value_enum(ctx, generator, ctx.primitives.float)?;
|
||||||
let ceil_intrinsic =
|
let ceil_intrinsic =
|
||||||
ctx.module.get_function("llvm.ceil.f64").unwrap_or_else(|| {
|
ctx.module.get_function("llvm.ceil.f64").unwrap_or_else(|| {
|
||||||
let float = ctx.ctx.f64_type();
|
let float = ctx.ctx.f64_type();
|
||||||
@ -916,7 +949,7 @@ pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo {
|
|||||||
resolver: None,
|
resolver: None,
|
||||||
codegen_callback: Some(Arc::new(GenCall::new(Box::new(
|
codegen_callback: Some(Arc::new(GenCall::new(Box::new(
|
||||||
|ctx, _, _, args, generator| {
|
|ctx, _, _, args, generator| {
|
||||||
let arg = args[0].1.clone().to_basic_value_enum(ctx, generator)?;
|
let arg = args[0].1.clone().to_basic_value_enum(ctx, generator, ctx.primitives.float)?;
|
||||||
let ceil_intrinsic =
|
let ceil_intrinsic =
|
||||||
ctx.module.get_function("llvm.ceil.f64").unwrap_or_else(|| {
|
ctx.module.get_function("llvm.ceil.f64").unwrap_or_else(|| {
|
||||||
let float = ctx.ctx.f64_type();
|
let float = ctx.ctx.f64_type();
|
||||||
@ -968,11 +1001,11 @@ pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo {
|
|||||||
|ctx, _, fun, args, generator| {
|
|ctx, _, fun, args, generator| {
|
||||||
let range_ty = ctx.primitives.range;
|
let range_ty = ctx.primitives.range;
|
||||||
let arg_ty = fun.0.args[0].ty;
|
let arg_ty = fun.0.args[0].ty;
|
||||||
let arg = args[0].1.clone().to_basic_value_enum(ctx, generator)?;
|
let arg = args[0].1.clone().to_basic_value_enum(ctx, generator, arg_ty)?;
|
||||||
Ok(if ctx.unifier.unioned(arg_ty, range_ty) {
|
Ok(if ctx.unifier.unioned(arg_ty, range_ty) {
|
||||||
let arg = arg.into_pointer_value();
|
let arg = arg.into_pointer_value();
|
||||||
let (start, end, step) = destructure_range(ctx, arg);
|
let (start, end, step) = destructure_range(ctx, arg);
|
||||||
Some(calculate_len_for_slice_range(ctx, start, end, step).into())
|
Some(calculate_len_for_slice_range(generator, ctx, start, end, step).into())
|
||||||
} else {
|
} else {
|
||||||
let int32 = ctx.ctx.i32_type();
|
let int32 = ctx.ctx.i32_type();
|
||||||
let zero = int32.const_zero();
|
let zero = int32.const_zero();
|
||||||
@ -1022,8 +1055,8 @@ pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo {
|
|||||||
let llvm_f64 = ctx.ctx.f64_type().as_basic_type_enum();
|
let llvm_f64 = ctx.ctx.f64_type().as_basic_type_enum();
|
||||||
let m_ty = fun.0.args[0].ty;
|
let m_ty = fun.0.args[0].ty;
|
||||||
let n_ty = fun.0.args[1].ty;
|
let n_ty = fun.0.args[1].ty;
|
||||||
let m_val = args[0].1.clone().to_basic_value_enum(ctx, generator)?;
|
let m_val = args[0].1.clone().to_basic_value_enum(ctx, generator, m_ty)?;
|
||||||
let n_val = args[1].1.clone().to_basic_value_enum(ctx, generator)?;
|
let n_val = args[1].1.clone().to_basic_value_enum(ctx, generator, n_ty)?;
|
||||||
let mut is_type = |a: Type, b: Type| ctx.unifier.unioned(a, b);
|
let mut is_type = |a: Type, b: Type| ctx.unifier.unioned(a, b);
|
||||||
let (fun_name, arg_ty) = if is_type(m_ty, n_ty) && is_type(n_ty, boolean) {
|
let (fun_name, arg_ty) = if is_type(m_ty, n_ty) && is_type(n_ty, boolean) {
|
||||||
("llvm.umin.i1", llvm_i1)
|
("llvm.umin.i1", llvm_i1)
|
||||||
@ -1084,8 +1117,8 @@ pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo {
|
|||||||
let llvm_f64 = ctx.ctx.f64_type().as_basic_type_enum();
|
let llvm_f64 = ctx.ctx.f64_type().as_basic_type_enum();
|
||||||
let m_ty = fun.0.args[0].ty;
|
let m_ty = fun.0.args[0].ty;
|
||||||
let n_ty = fun.0.args[1].ty;
|
let n_ty = fun.0.args[1].ty;
|
||||||
let m_val = args[0].1.clone().to_basic_value_enum(ctx, generator)?;
|
let m_val = args[0].1.clone().to_basic_value_enum(ctx, generator, m_ty)?;
|
||||||
let n_val = args[1].1.clone().to_basic_value_enum(ctx, generator)?;
|
let n_val = args[1].1.clone().to_basic_value_enum(ctx, generator, n_ty)?;
|
||||||
let mut is_type = |a: Type, b: Type| ctx.unifier.unioned(a, b);
|
let mut is_type = |a: Type, b: Type| ctx.unifier.unioned(a, b);
|
||||||
let (fun_name, arg_ty) = if is_type(m_ty, n_ty) && is_type(n_ty, boolean) {
|
let (fun_name, arg_ty) = if is_type(m_ty, n_ty) && is_type(n_ty, boolean) {
|
||||||
("llvm.umax.i1", llvm_i1)
|
("llvm.umax.i1", llvm_i1)
|
||||||
@ -1142,7 +1175,7 @@ pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo {
|
|||||||
let llvm_i64 = ctx.ctx.i64_type().as_basic_type_enum();
|
let llvm_i64 = ctx.ctx.i64_type().as_basic_type_enum();
|
||||||
let llvm_f64 = ctx.ctx.f64_type().as_basic_type_enum();
|
let llvm_f64 = ctx.ctx.f64_type().as_basic_type_enum();
|
||||||
let n_ty = fun.0.args[0].ty;
|
let n_ty = fun.0.args[0].ty;
|
||||||
let n_val = args[0].1.clone().to_basic_value_enum(ctx, generator)?;
|
let n_val = args[0].1.clone().to_basic_value_enum(ctx, generator, n_ty)?;
|
||||||
let mut is_type = |a: Type, b: Type| ctx.unifier.unioned(a, b);
|
let mut is_type = |a: Type, b: Type| ctx.unifier.unioned(a, b);
|
||||||
let mut is_float = false;
|
let mut is_float = false;
|
||||||
let (fun_name, arg_ty) =
|
let (fun_name, arg_ty) =
|
||||||
@ -1199,8 +1232,9 @@ pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo {
|
|||||||
instance_to_stmt: Default::default(),
|
instance_to_stmt: Default::default(),
|
||||||
resolver: None,
|
resolver: None,
|
||||||
codegen_callback: Some(Arc::new(GenCall::new(Box::new(
|
codegen_callback: Some(Arc::new(GenCall::new(Box::new(
|
||||||
|ctx, _, _fun, args, generator| {
|
|ctx, _, fun, args, generator| {
|
||||||
let arg_val = args[0].1.clone().to_basic_value_enum(ctx, generator)?;
|
let arg_ty = fun.0.args[0].ty;
|
||||||
|
let arg_val = args[0].1.clone().to_basic_value_enum(ctx, generator, arg_ty)?;
|
||||||
let alloca = ctx.builder.build_alloca(arg_val.get_type(), "alloca_some");
|
let alloca = ctx.builder.build_alloca(arg_val.get_type(), "alloca_some");
|
||||||
ctx.builder.build_store(alloca, arg_val);
|
ctx.builder.build_store(alloca, arg_val);
|
||||||
Ok(Some(alloca.into()))
|
Ok(Some(alloca.into()))
|
||||||
|
@ -91,7 +91,7 @@ impl TopLevelComposer {
|
|||||||
assert!(name == *simple_name);
|
assert!(name == *simple_name);
|
||||||
builtin_ty.insert(name, *signature);
|
builtin_ty.insert(name, *signature);
|
||||||
builtin_id.insert(name, DefinitionId(id));
|
builtin_id.insert(name, DefinitionId(id));
|
||||||
} else if let TopLevelDef::Class { name, constructor, object_id, type_vars, .. } = &*def
|
} else if let TopLevelDef::Class { name, constructor, object_id, .. } = &*def
|
||||||
{
|
{
|
||||||
assert!(id == object_id.0);
|
assert!(id == object_id.0);
|
||||||
if let Some(constructor) = constructor {
|
if let Some(constructor) = constructor {
|
||||||
@ -434,11 +434,11 @@ impl TopLevelComposer {
|
|||||||
|
|
||||||
// check if all are unique type vars
|
// check if all are unique type vars
|
||||||
let all_unique_type_var = {
|
let all_unique_type_var = {
|
||||||
let mut occured_type_var_id: HashSet<u32> = HashSet::new();
|
let mut occurred_type_var_id: HashSet<u32> = HashSet::new();
|
||||||
type_vars.iter().all(|x| {
|
type_vars.iter().all(|x| {
|
||||||
let ty = unifier.get_ty(*x);
|
let ty = unifier.get_ty(*x);
|
||||||
if let TypeEnum::TVar { id, .. } = ty.as_ref() {
|
if let TypeEnum::TVar { id, .. } = ty.as_ref() {
|
||||||
occured_type_var_id.insert(*id)
|
occurred_type_var_id.insert(*id)
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
@ -536,7 +536,7 @@ impl TopLevelComposer {
|
|||||||
}
|
}
|
||||||
has_base = true;
|
has_base = true;
|
||||||
|
|
||||||
// the function parse_ast_to make sure that no type var occured in
|
// the function parse_ast_to make sure that no type var occurred in
|
||||||
// bast_ty if it is a CustomClassKind
|
// bast_ty if it is a CustomClassKind
|
||||||
let base_ty = parse_ast_to_type_annotation_kinds(
|
let base_ty = parse_ast_to_type_annotation_kinds(
|
||||||
class_resolver,
|
class_resolver,
|
||||||
@ -696,7 +696,7 @@ impl TopLevelComposer {
|
|||||||
return Err(errors.into_iter().sorted().join("\n----------\n"));
|
return Err(errors.into_iter().sorted().join("\n----------\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle the inheritanced methods and fields
|
// handle the inherited methods and fields
|
||||||
// Note: we cannot defer error handling til the end of the loop, because there is loop
|
// Note: we cannot defer error handling til the end of the loop, because there is loop
|
||||||
// carried dependency, ignoring the error (temporarily) will cause all assumptions to break
|
// carried dependency, ignoring the error (temporarily) will cause all assumptions to break
|
||||||
// and produce weird error messages
|
// and produce weird error messages
|
||||||
@ -825,9 +825,9 @@ impl TopLevelComposer {
|
|||||||
let mut function_var_map: HashMap<u32, Type> = HashMap::new();
|
let mut function_var_map: HashMap<u32, Type> = HashMap::new();
|
||||||
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_parameter_name: HashSet<_> = HashSet::new();
|
||||||
for x in args.args.iter() {
|
for x in args.args.iter() {
|
||||||
if !defined_paramter_name.insert(x.node.arg)
|
if !defined_parameter_name.insert(x.node.arg)
|
||||||
|| keyword_list.contains(&x.node.arg)
|
|| keyword_list.contains(&x.node.arg)
|
||||||
{
|
{
|
||||||
return Err(format!(
|
return Err(format!(
|
||||||
@ -1074,10 +1074,10 @@ impl TopLevelComposer {
|
|||||||
|
|
||||||
let arg_types: Vec<FuncArg> = {
|
let arg_types: Vec<FuncArg> = {
|
||||||
// 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_parameter_name: HashSet<_> = HashSet::new();
|
||||||
let zelf: StrRef = "self".into();
|
let zelf: StrRef = "self".into();
|
||||||
for x in args.args.iter() {
|
for x in args.args.iter() {
|
||||||
if !defined_paramter_name.insert(x.node.arg)
|
if !defined_parameter_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!(
|
return Err(format!(
|
||||||
@ -1088,13 +1088,13 @@ impl TopLevelComposer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if name == &"__init__".into() && !defined_paramter_name.contains(&zelf) {
|
if name == &"__init__".into() && !defined_parameter_name.contains(&zelf) {
|
||||||
return Err(format!(
|
return Err(format!(
|
||||||
"__init__ method must have a `self` parameter (at {})",
|
"__init__ method must have a `self` parameter (at {})",
|
||||||
b.location
|
b.location
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
if !defined_paramter_name.contains(&zelf) {
|
if !defined_parameter_name.contains(&zelf) {
|
||||||
return Err(format!(
|
return Err(format!(
|
||||||
"class method must have a `self` parameter (at {})",
|
"class method must have a `self` parameter (at {})",
|
||||||
b.location
|
b.location
|
||||||
@ -1227,7 +1227,7 @@ impl TopLevelComposer {
|
|||||||
dummy_return_type
|
dummy_return_type
|
||||||
} else {
|
} else {
|
||||||
// if do not have return annotation, return none
|
// if do not have return annotation, return none
|
||||||
// for uniform handling, still use type annoatation
|
// for uniform handling, still use type annotation
|
||||||
let dummy_return_type = unifier.get_dummy_var().0;
|
let dummy_return_type = unifier.get_dummy_var().0;
|
||||||
type_var_to_concrete_def.insert(
|
type_var_to_concrete_def.insert(
|
||||||
dummy_return_type,
|
dummy_return_type,
|
||||||
@ -1468,9 +1468,9 @@ impl TopLevelComposer {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// step 5, analyze and call type inferecer to fill the `instance_to_stmt` of topleveldef::function
|
/// step 5, analyze and call type inferencer to fill the `instance_to_stmt` of topleveldef::function
|
||||||
fn analyze_function_instance(&mut self) -> Result<(), String> {
|
fn analyze_function_instance(&mut self) -> Result<(), String> {
|
||||||
// first get the class contructor type correct for the following type check in function body
|
// first get the class constructor type correct for the following type check in function body
|
||||||
// also do class field instantiation check
|
// also do class field instantiation check
|
||||||
let init_str_id = "__init__".into();
|
let init_str_id = "__init__".into();
|
||||||
let mut definition_extension = Vec::new();
|
let mut definition_extension = Vec::new();
|
||||||
@ -1581,7 +1581,7 @@ impl TopLevelComposer {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
let mut init_id: Option<DefinitionId> = None;
|
let mut init_id: Option<DefinitionId> = None;
|
||||||
// get the class contructor type correct
|
// get the class constructor type correct
|
||||||
let (contor_args, contor_type_vars) = {
|
let (contor_args, contor_type_vars) = {
|
||||||
let mut constructor_args: Vec<FuncArg> = Vec::new();
|
let mut constructor_args: Vec<FuncArg> = Vec::new();
|
||||||
let mut type_vars: HashMap<u32, Type> = HashMap::new();
|
let mut type_vars: HashMap<u32, Type> = HashMap::new();
|
||||||
@ -1906,7 +1906,7 @@ impl TopLevelComposer {
|
|||||||
unreachable!("must be class id here")
|
unreachable!("must be class id here")
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
&mut |id| format!("tvar{}", id),
|
&mut |id| format!("typevar{}", id),
|
||||||
&mut None,
|
&mut None,
|
||||||
);
|
);
|
||||||
return Err(format!(
|
return Err(format!(
|
||||||
|
@ -149,7 +149,7 @@ impl TopLevelComposer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// already include the definition_id of itself inside the ancestors vector
|
/// already include the definition_id of itself inside the ancestors vector
|
||||||
/// when first regitering, the type_vars, fields, methods, ancestors are invalid
|
/// when first registering, the type_vars, fields, methods, ancestors are invalid
|
||||||
pub fn make_top_level_class_def(
|
pub fn make_top_level_class_def(
|
||||||
index: usize,
|
index: usize,
|
||||||
resolver: Option<Arc<dyn SymbolResolver + Send + Sync>>,
|
resolver: Option<Arc<dyn SymbolResolver + Send + Sync>>,
|
||||||
@ -416,76 +416,77 @@ impl TopLevelComposer {
|
|||||||
primitive: &PrimitiveStore,
|
primitive: &PrimitiveStore,
|
||||||
unifier: &mut Unifier,
|
unifier: &mut Unifier,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
let res = match val {
|
fn type_default_param(
|
||||||
SymbolValue::Bool(..) => {
|
val: &SymbolValue,
|
||||||
if matches!(ty, TypeAnnotation::Primitive(t) if *t == primitive.bool) {
|
primitive: &PrimitiveStore,
|
||||||
None
|
unifier: &mut Unifier,
|
||||||
} else {
|
) -> TypeAnnotation {
|
||||||
Some("bool".to_string())
|
match val {
|
||||||
|
SymbolValue::Bool(..) => TypeAnnotation::Primitive(primitive.bool),
|
||||||
|
SymbolValue::Double(..) => TypeAnnotation::Primitive(primitive.float),
|
||||||
|
SymbolValue::I32(..) => TypeAnnotation::Primitive(primitive.int32),
|
||||||
|
SymbolValue::I64(..) => TypeAnnotation::Primitive(primitive.int64),
|
||||||
|
SymbolValue::U32(..) => TypeAnnotation::Primitive(primitive.uint32),
|
||||||
|
SymbolValue::U64(..) => TypeAnnotation::Primitive(primitive.uint64),
|
||||||
|
SymbolValue::Str(..) => TypeAnnotation::Primitive(primitive.str),
|
||||||
|
SymbolValue::Tuple(vs) => {
|
||||||
|
let vs_tys = vs
|
||||||
|
.iter()
|
||||||
|
.map(|v| type_default_param(v, primitive, unifier))
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
TypeAnnotation::Tuple(vs_tys)
|
||||||
|
}
|
||||||
|
SymbolValue::OptionNone => TypeAnnotation::CustomClass {
|
||||||
|
id: primitive.option.get_obj_id(unifier),
|
||||||
|
params: Default::default(),
|
||||||
|
},
|
||||||
|
SymbolValue::OptionSome(v) => {
|
||||||
|
let ty = type_default_param(v, primitive, unifier);
|
||||||
|
TypeAnnotation::CustomClass {
|
||||||
|
id: primitive.option.get_obj_id(unifier),
|
||||||
|
params: vec![ty],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SymbolValue::Double(..) => {
|
|
||||||
if matches!(ty, TypeAnnotation::Primitive(t) if *t == primitive.float) {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some("float".to_string())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SymbolValue::I32(..) => {
|
|
||||||
if matches!(ty, TypeAnnotation::Primitive(t) if *t == primitive.int32) {
|
fn is_compatible(
|
||||||
None
|
found: &TypeAnnotation,
|
||||||
} else {
|
expect: &TypeAnnotation,
|
||||||
Some("int32".to_string())
|
unifier: &mut Unifier,
|
||||||
|
primitive: &PrimitiveStore,
|
||||||
|
) -> bool {
|
||||||
|
match (found, expect) {
|
||||||
|
(TypeAnnotation::Primitive(f), TypeAnnotation::Primitive(e)) => {
|
||||||
|
unifier.unioned(*f, *e)
|
||||||
|
}
|
||||||
|
(
|
||||||
|
TypeAnnotation::CustomClass { id: f_id, params: f_param },
|
||||||
|
TypeAnnotation::CustomClass { id: e_id, params: e_param },
|
||||||
|
) => {
|
||||||
|
*f_id == *e_id
|
||||||
|
&& *f_id == primitive.option.get_obj_id(unifier)
|
||||||
|
&& (f_param.is_empty()
|
||||||
|
|| (f_param.len() == 1
|
||||||
|
&& e_param.len() == 1
|
||||||
|
&& is_compatible(&f_param[0], &e_param[0], unifier, primitive)))
|
||||||
|
}
|
||||||
|
(TypeAnnotation::Tuple(f), TypeAnnotation::Tuple(e)) => {
|
||||||
|
f.len() == e.len()
|
||||||
|
&& f.iter()
|
||||||
|
.zip(e.iter())
|
||||||
|
.all(|(f, e)| is_compatible(f, e, unifier, primitive))
|
||||||
|
}
|
||||||
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SymbolValue::I64(..) => {
|
|
||||||
if matches!(ty, TypeAnnotation::Primitive(t) if *t == primitive.int64) {
|
let found = type_default_param(val, primitive, unifier);
|
||||||
None
|
if !is_compatible(&found, ty, unifier, primitive) {
|
||||||
} else {
|
|
||||||
Some("int64".to_string())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SymbolValue::U32(..) => {
|
|
||||||
if matches!(ty, TypeAnnotation::Primitive(t) if *t == primitive.uint32) {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some("uint32".to_string())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SymbolValue::U64(..) => {
|
|
||||||
if matches!(ty, TypeAnnotation::Primitive(t) if *t == primitive.uint64) {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some("uint64".to_string())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SymbolValue::Str(..) => {
|
|
||||||
if matches!(ty, TypeAnnotation::Primitive(t) if *t == primitive.str) {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some("str".to_string())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SymbolValue::Tuple(elts) => {
|
|
||||||
if let TypeAnnotation::Tuple(elts_ty) = ty {
|
|
||||||
for (e, t) in elts.iter().zip(elts_ty.iter()) {
|
|
||||||
Self::check_default_param_type(e, t, primitive, unifier)?
|
|
||||||
}
|
|
||||||
if elts.len() != elts_ty.len() {
|
|
||||||
Some(format!("tuple of length {}", elts.len()))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Some("tuple".to_string())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if let Some(found) = res {
|
|
||||||
Err(format!(
|
Err(format!(
|
||||||
"incompatible default parameter type, expect {}, found {}",
|
"incompatible default parameter type, expect {}, found {}",
|
||||||
ty.stringify(unifier),
|
ty.stringify(unifier),
|
||||||
found
|
found.stringify(unifier),
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -511,6 +512,10 @@ pub fn parse_parameter_default_value(
|
|||||||
Constant::Tuple(tuple) => Ok(SymbolValue::Tuple(
|
Constant::Tuple(tuple) => Ok(SymbolValue::Tuple(
|
||||||
tuple.iter().map(|x| handle_constant(x, loc)).collect::<Result<Vec<_>, _>>()?,
|
tuple.iter().map(|x| handle_constant(x, loc)).collect::<Result<Vec<_>, _>>()?,
|
||||||
)),
|
)),
|
||||||
|
Constant::None => Err(format!(
|
||||||
|
"`None` is not supported, use `none` for option type instead ({})",
|
||||||
|
loc
|
||||||
|
)),
|
||||||
_ => unimplemented!("this constant is not supported at {}", loc),
|
_ => unimplemented!("this constant is not supported at {}", loc),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -548,6 +553,11 @@ pub fn parse_parameter_default_value(
|
|||||||
}
|
}
|
||||||
_ => Err(format!("only allow constant integer here at {}", default.location))
|
_ => Err(format!("only allow constant integer here at {}", default.location))
|
||||||
}
|
}
|
||||||
|
ast::ExprKind::Name { id, .. } if *id == "Some".into() => Ok(
|
||||||
|
SymbolValue::OptionSome(
|
||||||
|
Box::new(parse_parameter_default_value(&args[0], resolver)?)
|
||||||
|
)
|
||||||
|
),
|
||||||
_ => Err(format!("unsupported default parameter at {}", default.location)),
|
_ => Err(format!("unsupported default parameter at {}", default.location)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -556,15 +566,20 @@ pub fn parse_parameter_default_value(
|
|||||||
.map(|x| parse_parameter_default_value(x, resolver))
|
.map(|x| parse_parameter_default_value(x, resolver))
|
||||||
.collect::<Result<Vec<_>, _>>()?
|
.collect::<Result<Vec<_>, _>>()?
|
||||||
)),
|
)),
|
||||||
|
ast::ExprKind::Name { id, .. } if id == &"none".into() => Ok(SymbolValue::OptionNone),
|
||||||
ast::ExprKind::Name { id, .. } => {
|
ast::ExprKind::Name { id, .. } => {
|
||||||
resolver.get_default_param_value(default).ok_or_else(
|
resolver.get_default_param_value(default).ok_or_else(
|
||||||
|| format!(
|
|| format!(
|
||||||
"`{}` cannot be used as a default parameter at {} (not primitive type or tuple / not defined?)",
|
"`{}` cannot be used as a default parameter at {} \
|
||||||
|
(not primitive type, option or tuple / not defined?)",
|
||||||
id,
|
id,
|
||||||
default.location
|
default.location
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
_ => Err(format!("unsupported default parameter at {}", default.location))
|
_ => Err(format!(
|
||||||
|
"unsupported default parameter (not primitive type, option or tuple) at {}",
|
||||||
|
default.location
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,10 +5,10 @@ expression: res_vec
|
|||||||
|
|
||||||
---
|
---
|
||||||
[
|
[
|
||||||
"Class {\nname: \"Generic_A\",\nancestors: [\"{class: Generic_A, params: [\\\"V\\\"]}\", \"{class: B, params: []}\"],\nfields: [\"aa\", \"a\"],\nmethods: [(\"__init__\", \"fn[[], none]\"), (\"foo\", \"fn[[b:T], none]\"), (\"fun\", \"fn[[a:int32], V]\")],\ntype_vars: [\"V\"]\n}\n",
|
"Class {\nname: \"Generic_A\",\nancestors: [\"Generic_A[V]\", \"B\"],\nfields: [\"aa\", \"a\"],\nmethods: [(\"__init__\", \"fn[[], none]\"), (\"foo\", \"fn[[b:T], none]\"), (\"fun\", \"fn[[a:int32], V]\")],\ntype_vars: [\"V\"]\n}\n",
|
||||||
"Function {\nname: \"Generic_A.__init__\",\nsig: \"fn[[], none]\",\nvar_id: []\n}\n",
|
"Function {\nname: \"Generic_A.__init__\",\nsig: \"fn[[], none]\",\nvar_id: []\n}\n",
|
||||||
"Function {\nname: \"Generic_A.fun\",\nsig: \"fn[[a:int32], V]\",\nvar_id: [18]\n}\n",
|
"Function {\nname: \"Generic_A.fun\",\nsig: \"fn[[a:int32], V]\",\nvar_id: [18]\n}\n",
|
||||||
"Class {\nname: \"B\",\nancestors: [\"{class: B, params: []}\"],\nfields: [\"aa\"],\nmethods: [(\"__init__\", \"fn[[], none]\"), (\"foo\", \"fn[[b:T], none]\")],\ntype_vars: []\n}\n",
|
"Class {\nname: \"B\",\nancestors: [\"B\"],\nfields: [\"aa\"],\nmethods: [(\"__init__\", \"fn[[], none]\"), (\"foo\", \"fn[[b:T], none]\")],\ntype_vars: []\n}\n",
|
||||||
"Function {\nname: \"B.__init__\",\nsig: \"fn[[], none]\",\nvar_id: []\n}\n",
|
"Function {\nname: \"B.__init__\",\nsig: \"fn[[], none]\",\nvar_id: []\n}\n",
|
||||||
"Function {\nname: \"B.foo\",\nsig: \"fn[[b:T], none]\",\nvar_id: []\n}\n",
|
"Function {\nname: \"B.foo\",\nsig: \"fn[[b:T], none]\",\nvar_id: []\n}\n",
|
||||||
]
|
]
|
||||||
|
@ -5,13 +5,13 @@ expression: res_vec
|
|||||||
|
|
||||||
---
|
---
|
||||||
[
|
[
|
||||||
"Class {\nname: \"A\",\nancestors: [\"{class: A, params: [\\\"T\\\"]}\"],\nfields: [\"a\", \"b\", \"c\"],\nmethods: [(\"__init__\", \"fn[[t:T], none]\"), (\"fun\", \"fn[[a:int32, b:T], list[virtual[B[bool]]]]\"), (\"foo\", \"fn[[c:C], none]\")],\ntype_vars: [\"T\"]\n}\n",
|
"Class {\nname: \"A\",\nancestors: [\"A[T]\"],\nfields: [\"a\", \"b\", \"c\"],\nmethods: [(\"__init__\", \"fn[[t:T], none]\"), (\"fun\", \"fn[[a:int32, b:T], list[virtual[B[bool]]]]\"), (\"foo\", \"fn[[c:C], none]\")],\ntype_vars: [\"T\"]\n}\n",
|
||||||
"Function {\nname: \"A.__init__\",\nsig: \"fn[[t:T], none]\",\nvar_id: []\n}\n",
|
"Function {\nname: \"A.__init__\",\nsig: \"fn[[t:T], none]\",\nvar_id: []\n}\n",
|
||||||
"Function {\nname: \"A.fun\",\nsig: \"fn[[a:int32, b:T], list[virtual[B[bool]]]]\",\nvar_id: []\n}\n",
|
"Function {\nname: \"A.fun\",\nsig: \"fn[[a:int32, b:T], list[virtual[B[bool]]]]\",\nvar_id: []\n}\n",
|
||||||
"Function {\nname: \"A.foo\",\nsig: \"fn[[c:C], none]\",\nvar_id: []\n}\n",
|
"Function {\nname: \"A.foo\",\nsig: \"fn[[c:C], none]\",\nvar_id: []\n}\n",
|
||||||
"Class {\nname: \"B\",\nancestors: [\"{class: B, params: [\\\"var7\\\"]}\", \"{class: A, params: [\\\"float\\\"]}\"],\nfields: [\"a\", \"b\", \"c\", \"d\"],\nmethods: [(\"__init__\", \"fn[[], none]\"), (\"fun\", \"fn[[a:int32, b:T], list[virtual[B[bool]]]]\"), (\"foo\", \"fn[[c:C], none]\")],\ntype_vars: [\"var7\"]\n}\n",
|
"Class {\nname: \"B\",\nancestors: [\"B[typevar7]\", \"A[float]\"],\nfields: [\"a\", \"b\", \"c\", \"d\"],\nmethods: [(\"__init__\", \"fn[[], none]\"), (\"fun\", \"fn[[a:int32, b:T], list[virtual[B[bool]]]]\"), (\"foo\", \"fn[[c:C], none]\")],\ntype_vars: [\"typevar7\"]\n}\n",
|
||||||
"Function {\nname: \"B.__init__\",\nsig: \"fn[[], none]\",\nvar_id: []\n}\n",
|
"Function {\nname: \"B.__init__\",\nsig: \"fn[[], none]\",\nvar_id: []\n}\n",
|
||||||
"Function {\nname: \"B.fun\",\nsig: \"fn[[a:int32, b:T], list[virtual[B[bool]]]]\",\nvar_id: []\n}\n",
|
"Function {\nname: \"B.fun\",\nsig: \"fn[[a:int32, b:T], list[virtual[B[bool]]]]\",\nvar_id: []\n}\n",
|
||||||
"Class {\nname: \"C\",\nancestors: [\"{class: C, params: []}\", \"{class: B, params: [\\\"bool\\\"]}\", \"{class: A, params: [\\\"float\\\"]}\"],\nfields: [\"a\", \"b\", \"c\", \"d\", \"e\"],\nmethods: [(\"__init__\", \"fn[[], none]\"), (\"fun\", \"fn[[a:int32, b:T], list[virtual[B[bool]]]]\"), (\"foo\", \"fn[[c:C], none]\")],\ntype_vars: []\n}\n",
|
"Class {\nname: \"C\",\nancestors: [\"C\", \"B[bool]\", \"A[float]\"],\nfields: [\"a\", \"b\", \"c\", \"d\", \"e\"],\nmethods: [(\"__init__\", \"fn[[], none]\"), (\"fun\", \"fn[[a:int32, b:T], list[virtual[B[bool]]]]\"), (\"foo\", \"fn[[c:C], none]\")],\ntype_vars: []\n}\n",
|
||||||
"Function {\nname: \"C.__init__\",\nsig: \"fn[[], none]\",\nvar_id: []\n}\n",
|
"Function {\nname: \"C.__init__\",\nsig: \"fn[[], none]\",\nvar_id: []\n}\n",
|
||||||
]
|
]
|
||||||
|
@ -6,10 +6,10 @@ expression: res_vec
|
|||||||
---
|
---
|
||||||
[
|
[
|
||||||
"Function {\nname: \"foo\",\nsig: \"fn[[a:list[int32], b:tuple[T, float]], A[B, bool]]\",\nvar_id: []\n}\n",
|
"Function {\nname: \"foo\",\nsig: \"fn[[a:list[int32], b:tuple[T, float]], A[B, bool]]\",\nvar_id: []\n}\n",
|
||||||
"Class {\nname: \"A\",\nancestors: [\"{class: A, params: [\\\"T\\\", \\\"V\\\"]}\"],\nfields: [\"a\", \"b\"],\nmethods: [(\"__init__\", \"fn[[v:V], none]\"), (\"fun\", \"fn[[a:T], V]\")],\ntype_vars: [\"T\", \"V\"]\n}\n",
|
"Class {\nname: \"A\",\nancestors: [\"A[T, V]\"],\nfields: [\"a\", \"b\"],\nmethods: [(\"__init__\", \"fn[[v:V], none]\"), (\"fun\", \"fn[[a:T], V]\")],\ntype_vars: [\"T\", \"V\"]\n}\n",
|
||||||
"Function {\nname: \"A.__init__\",\nsig: \"fn[[v:V], none]\",\nvar_id: [20]\n}\n",
|
"Function {\nname: \"A.__init__\",\nsig: \"fn[[v:V], none]\",\nvar_id: [20]\n}\n",
|
||||||
"Function {\nname: \"A.fun\",\nsig: \"fn[[a:T], V]\",\nvar_id: [25]\n}\n",
|
"Function {\nname: \"A.fun\",\nsig: \"fn[[a:T], V]\",\nvar_id: [25]\n}\n",
|
||||||
"Function {\nname: \"gfun\",\nsig: \"fn[[a:A[int32, list[float]]], none]\",\nvar_id: []\n}\n",
|
"Function {\nname: \"gfun\",\nsig: \"fn[[a:A[int32, list[float]]], none]\",\nvar_id: []\n}\n",
|
||||||
"Class {\nname: \"B\",\nancestors: [\"{class: B, params: []}\"],\nfields: [],\nmethods: [(\"__init__\", \"fn[[], none]\")],\ntype_vars: []\n}\n",
|
"Class {\nname: \"B\",\nancestors: [\"B\"],\nfields: [],\nmethods: [(\"__init__\", \"fn[[], none]\")],\ntype_vars: []\n}\n",
|
||||||
"Function {\nname: \"B.__init__\",\nsig: \"fn[[], none]\",\nvar_id: []\n}\n",
|
"Function {\nname: \"B.__init__\",\nsig: \"fn[[], none]\",\nvar_id: []\n}\n",
|
||||||
]
|
]
|
||||||
|
@ -5,10 +5,10 @@ expression: res_vec
|
|||||||
|
|
||||||
---
|
---
|
||||||
[
|
[
|
||||||
"Class {\nname: \"A\",\nancestors: [\"{class: A, params: [\\\"var6\\\", \\\"var7\\\"]}\"],\nfields: [\"a\", \"b\"],\nmethods: [(\"__init__\", \"fn[[a:A[bool, float], b:B], none]\"), (\"fun\", \"fn[[a:A[bool, float]], A[bool, int32]]\")],\ntype_vars: [\"var6\", \"var7\"]\n}\n",
|
"Class {\nname: \"A\",\nancestors: [\"A[typevar6, typevar7]\"],\nfields: [\"a\", \"b\"],\nmethods: [(\"__init__\", \"fn[[a:A[bool, float], b:B], none]\"), (\"fun\", \"fn[[a:A[bool, float]], A[bool, int32]]\")],\ntype_vars: [\"typevar6\", \"typevar7\"]\n}\n",
|
||||||
"Function {\nname: \"A.__init__\",\nsig: \"fn[[a:A[bool, float], b:B], none]\",\nvar_id: []\n}\n",
|
"Function {\nname: \"A.__init__\",\nsig: \"fn[[a:A[bool, float], b:B], none]\",\nvar_id: []\n}\n",
|
||||||
"Function {\nname: \"A.fun\",\nsig: \"fn[[a:A[bool, float]], A[bool, int32]]\",\nvar_id: []\n}\n",
|
"Function {\nname: \"A.fun\",\nsig: \"fn[[a:A[bool, float]], A[bool, int32]]\",\nvar_id: []\n}\n",
|
||||||
"Class {\nname: \"B\",\nancestors: [\"{class: B, params: []}\", \"{class: A, params: [\\\"int64\\\", \\\"bool\\\"]}\"],\nfields: [\"a\", \"b\"],\nmethods: [(\"__init__\", \"fn[[], none]\"), (\"fun\", \"fn[[a:A[bool, float]], A[bool, int32]]\"), (\"foo\", \"fn[[b:B], B]\"), (\"bar\", \"fn[[a:A[int32, list[B]]], tuple[A[bool, virtual[A[B, int32]]], B]]\")],\ntype_vars: []\n}\n",
|
"Class {\nname: \"B\",\nancestors: [\"B\", \"A[int64, bool]\"],\nfields: [\"a\", \"b\"],\nmethods: [(\"__init__\", \"fn[[], none]\"), (\"fun\", \"fn[[a:A[bool, float]], A[bool, int32]]\"), (\"foo\", \"fn[[b:B], B]\"), (\"bar\", \"fn[[a:A[int32, list[B]]], tuple[A[bool, virtual[A[B, int32]]], B]]\")],\ntype_vars: []\n}\n",
|
||||||
"Function {\nname: \"B.__init__\",\nsig: \"fn[[], none]\",\nvar_id: []\n}\n",
|
"Function {\nname: \"B.__init__\",\nsig: \"fn[[], none]\",\nvar_id: []\n}\n",
|
||||||
"Function {\nname: \"B.foo\",\nsig: \"fn[[b:B], B]\",\nvar_id: []\n}\n",
|
"Function {\nname: \"B.foo\",\nsig: \"fn[[b:B], B]\",\nvar_id: []\n}\n",
|
||||||
"Function {\nname: \"B.bar\",\nsig: \"fn[[a:A[int32, list[B]]], tuple[A[bool, virtual[A[B, int32]]], B]]\",\nvar_id: []\n}\n",
|
"Function {\nname: \"B.bar\",\nsig: \"fn[[a:A[int32, list[B]]], tuple[A[bool, virtual[A[B, int32]]], B]]\",\nvar_id: []\n}\n",
|
||||||
|
@ -5,13 +5,13 @@ expression: res_vec
|
|||||||
|
|
||||||
---
|
---
|
||||||
[
|
[
|
||||||
"Class {\nname: \"A\",\nancestors: [\"{class: A, params: []}\"],\nfields: [\"a\"],\nmethods: [(\"__init__\", \"fn[[], none]\"), (\"fun\", \"fn[[b:B], none]\"), (\"foo\", \"fn[[a:T, b:V], none]\")],\ntype_vars: []\n}\n",
|
"Class {\nname: \"A\",\nancestors: [\"A\"],\nfields: [\"a\"],\nmethods: [(\"__init__\", \"fn[[], none]\"), (\"fun\", \"fn[[b:B], none]\"), (\"foo\", \"fn[[a:T, b:V], none]\")],\ntype_vars: []\n}\n",
|
||||||
"Function {\nname: \"A.__init__\",\nsig: \"fn[[], none]\",\nvar_id: []\n}\n",
|
"Function {\nname: \"A.__init__\",\nsig: \"fn[[], none]\",\nvar_id: []\n}\n",
|
||||||
"Function {\nname: \"A.fun\",\nsig: \"fn[[b:B], none]\",\nvar_id: []\n}\n",
|
"Function {\nname: \"A.fun\",\nsig: \"fn[[b:B], none]\",\nvar_id: []\n}\n",
|
||||||
"Function {\nname: \"A.foo\",\nsig: \"fn[[a:T, b:V], none]\",\nvar_id: [26]\n}\n",
|
"Function {\nname: \"A.foo\",\nsig: \"fn[[a:T, b:V], none]\",\nvar_id: [26]\n}\n",
|
||||||
"Class {\nname: \"B\",\nancestors: [\"{class: B, params: []}\", \"{class: C, params: []}\", \"{class: A, params: []}\"],\nfields: [\"a\"],\nmethods: [(\"__init__\", \"fn[[], none]\"), (\"fun\", \"fn[[b:B], none]\"), (\"foo\", \"fn[[a:T, b:V], none]\")],\ntype_vars: []\n}\n",
|
"Class {\nname: \"B\",\nancestors: [\"B\", \"C\", \"A\"],\nfields: [\"a\"],\nmethods: [(\"__init__\", \"fn[[], none]\"), (\"fun\", \"fn[[b:B], none]\"), (\"foo\", \"fn[[a:T, b:V], none]\")],\ntype_vars: []\n}\n",
|
||||||
"Function {\nname: \"B.__init__\",\nsig: \"fn[[], none]\",\nvar_id: []\n}\n",
|
"Function {\nname: \"B.__init__\",\nsig: \"fn[[], none]\",\nvar_id: []\n}\n",
|
||||||
"Class {\nname: \"C\",\nancestors: [\"{class: C, params: []}\", \"{class: A, params: []}\"],\nfields: [\"a\"],\nmethods: [(\"__init__\", \"fn[[], none]\"), (\"fun\", \"fn[[b:B], none]\"), (\"foo\", \"fn[[a:T, b:V], none]\")],\ntype_vars: []\n}\n",
|
"Class {\nname: \"C\",\nancestors: [\"C\", \"A\"],\nfields: [\"a\"],\nmethods: [(\"__init__\", \"fn[[], none]\"), (\"fun\", \"fn[[b:B], none]\"), (\"foo\", \"fn[[a:T, b:V], none]\")],\ntype_vars: []\n}\n",
|
||||||
"Function {\nname: \"C.__init__\",\nsig: \"fn[[], none]\",\nvar_id: []\n}\n",
|
"Function {\nname: \"C.__init__\",\nsig: \"fn[[], none]\",\nvar_id: []\n}\n",
|
||||||
"Function {\nname: \"C.fun\",\nsig: \"fn[[b:B], none]\",\nvar_id: []\n}\n",
|
"Function {\nname: \"C.fun\",\nsig: \"fn[[b:B], none]\",\nvar_id: []\n}\n",
|
||||||
"Function {\nname: \"foo\",\nsig: \"fn[[a:A], none]\",\nvar_id: []\n}\n",
|
"Function {\nname: \"foo\",\nsig: \"fn[[a:A], none]\",\nvar_id: []\n}\n",
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
---
|
---
|
||||||
source: nac3core/src/toplevel/test.rs
|
source: nac3core/src/toplevel/test.rs
|
||||||
assertion_line: 541
|
assertion_line: 549
|
||||||
expression: res_vec
|
expression: res_vec
|
||||||
|
|
||||||
---
|
---
|
||||||
[
|
[
|
||||||
"Class {\nname: \"A\",\nancestors: [\"{class: A, params: []}\"],\nfields: [],\nmethods: [],\ntype_vars: []\n}\n",
|
"Class {\nname: \"A\",\nancestors: [\"A\"],\nfields: [],\nmethods: [],\ntype_vars: []\n}\n",
|
||||||
]
|
]
|
||||||
|
@ -65,14 +65,14 @@ impl SymbolResolver for Resolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_identifier_def(&self, id: StrRef) -> Result<DefinitionId, String> {
|
fn get_identifier_def(&self, id: StrRef) -> Result<DefinitionId, String> {
|
||||||
self.0.id_to_def.lock().get(&id).cloned().ok_or("Unknown identifier".to_string())
|
self.0.id_to_def.lock().get(&id).cloned().ok_or_else(|| "Unknown identifier".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_string_id(&self, _: &str) -> i32 {
|
fn get_string_id(&self, _: &str) -> i32 {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_exception_id(&self, tyid: usize) -> usize {
|
fn get_exception_id(&self, _tyid: usize) -> usize {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -763,7 +763,7 @@ fn make_internal_resolver_with_tvar(
|
|||||||
(name, {
|
(name, {
|
||||||
let (ty, id) = unifier.get_fresh_var_with_range(range.as_slice(), None, None);
|
let (ty, id) = unifier.get_fresh_var_with_range(range.as_slice(), None, None);
|
||||||
if print {
|
if print {
|
||||||
println!("{}: {:?}, tvar{}", name, ty, id);
|
println!("{}: {:?}, typevar{}", name, ty, id);
|
||||||
}
|
}
|
||||||
ty
|
ty
|
||||||
})
|
})
|
||||||
@ -791,7 +791,7 @@ impl<'a> Fold<Option<Type>> for TypeToStringFolder<'a> {
|
|||||||
self.unifier.internal_stringify(
|
self.unifier.internal_stringify(
|
||||||
ty,
|
ty,
|
||||||
&mut |id| format!("class{}", id.to_string()),
|
&mut |id| format!("class{}", id.to_string()),
|
||||||
&mut |id| format!("tvar{}", id.to_string()),
|
&mut |id| format!("typevar{}", id.to_string()),
|
||||||
&mut None,
|
&mut None,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
@ -29,20 +29,28 @@ impl TypeAnnotation {
|
|||||||
{
|
{
|
||||||
(*name).into()
|
(*name).into()
|
||||||
} else {
|
} else {
|
||||||
format!("def_{}", id.0)
|
unreachable!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => format!("def_{}", id.0),
|
None => format!("class_def_{}", id.0),
|
||||||
};
|
};
|
||||||
format!(
|
format!(
|
||||||
"{{class: {}, params: {:?}}}",
|
"{}{}",
|
||||||
class_name,
|
class_name,
|
||||||
params.iter().map(|p| p.stringify(unifier)).collect_vec()
|
{
|
||||||
|
let param_list = params.iter().map(|p| p.stringify(unifier)).collect_vec().join(", ");
|
||||||
|
if param_list.is_empty() {
|
||||||
|
"".into()
|
||||||
|
} else {
|
||||||
|
format!("[{}]", param_list)
|
||||||
|
}
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Virtual(ty) | List(ty) => ty.stringify(unifier),
|
Virtual(ty) => format!("virtual[{}]", ty.stringify(unifier)),
|
||||||
|
List(ty) => format!("list[{}]", ty.stringify(unifier)),
|
||||||
Tuple(types) => {
|
Tuple(types) => {
|
||||||
format!("({:?})", types.iter().map(|p| p.stringify(unifier)).collect_vec())
|
format!("tuple[{}]", types.iter().map(|p| p.stringify(unifier)).collect_vec().join(", "))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -348,7 +356,7 @@ pub fn get_type_from_type_annotation_kinds(
|
|||||||
unifier.internal_stringify(
|
unifier.internal_stringify(
|
||||||
p,
|
p,
|
||||||
&mut |id| format!("class{}", id),
|
&mut |id| format!("class{}", id),
|
||||||
&mut |id| format!("tvar{}", id),
|
&mut |id| format!("typevar{}", id),
|
||||||
&mut None
|
&mut None
|
||||||
),
|
),
|
||||||
*id
|
*id
|
||||||
@ -428,7 +436,7 @@ pub fn get_type_from_type_annotation_kinds(
|
|||||||
/// the type of `self` should be similar to `A[T, V]`, where `T`, `V`
|
/// the type of `self` should be similar to `A[T, V]`, where `T`, `V`
|
||||||
/// considered to be type variables associated with the class \
|
/// considered to be type variables associated with the class \
|
||||||
/// \
|
/// \
|
||||||
/// But note that here we do not make a duplication of `T`, `V`, we direclty
|
/// But note that here we do not make a duplication of `T`, `V`, we directly
|
||||||
/// use them as they are in the TopLevelDef::Class since those in the
|
/// use them as they are in the TopLevelDef::Class since those in the
|
||||||
/// TopLevelDef::Class.type_vars will be substitute later when seeing applications/instantiations
|
/// TopLevelDef::Class.type_vars will be substitute later when seeing applications/instantiations
|
||||||
/// the Type of their fields and methods will also be subst when application/instantiation
|
/// the Type of their fields and methods will also be subst when application/instantiation
|
||||||
|
@ -83,7 +83,7 @@ where
|
|||||||
|
|
||||||
pub fn impl_binop(
|
pub fn impl_binop(
|
||||||
unifier: &mut Unifier,
|
unifier: &mut Unifier,
|
||||||
store: &PrimitiveStore,
|
_store: &PrimitiveStore,
|
||||||
ty: Type,
|
ty: Type,
|
||||||
other_ty: &[Type],
|
other_ty: &[Type],
|
||||||
ret_ty: Type,
|
ret_ty: Type,
|
||||||
@ -120,7 +120,7 @@ pub fn impl_binop(
|
|||||||
fields.insert(binop_assign_name(op).into(), {
|
fields.insert(binop_assign_name(op).into(), {
|
||||||
(
|
(
|
||||||
unifier.add_ty(TypeEnum::TFunc(FunSignature {
|
unifier.add_ty(TypeEnum::TFunc(FunSignature {
|
||||||
ret: store.none,
|
ret: ret_ty,
|
||||||
vars: function_vars.clone(),
|
vars: function_vars.clone(),
|
||||||
args: vec![FuncArg {
|
args: vec![FuncArg {
|
||||||
ty: other_ty,
|
ty: other_ty,
|
||||||
|
@ -423,9 +423,16 @@ impl<'a> fold::Fold<()> for Inferencer<'a> {
|
|||||||
(None, None) => {}
|
(None, None) => {}
|
||||||
},
|
},
|
||||||
ast::StmtKind::AugAssign { target, op, value, .. } => {
|
ast::StmtKind::AugAssign { target, op, value, .. } => {
|
||||||
let res_ty = self.infer_bin_ops(stmt.location, target, op, value)?;
|
let res_ty = self.infer_bin_ops(stmt.location, target, op, value, true)?;
|
||||||
self.unify(res_ty, target.custom.unwrap(), &stmt.location)?;
|
self.unify(res_ty, target.custom.unwrap(), &stmt.location)?;
|
||||||
}
|
}
|
||||||
|
ast::StmtKind::Assert { test, msg, .. } => {
|
||||||
|
self.unify(test.custom.unwrap(), self.primitives.bool, &test.location)?;
|
||||||
|
match msg {
|
||||||
|
Some(m) => self.unify(m.custom.unwrap(), self.primitives.str, &m.location)?,
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => return report_error("Unsupported statement type", stmt.location),
|
_ => return report_error("Unsupported statement type", stmt.location),
|
||||||
};
|
};
|
||||||
Ok(stmt)
|
Ok(stmt)
|
||||||
@ -498,7 +505,7 @@ impl<'a> fold::Fold<()> for Inferencer<'a> {
|
|||||||
}
|
}
|
||||||
ast::ExprKind::BoolOp { values, .. } => Some(self.infer_bool_ops(values)?),
|
ast::ExprKind::BoolOp { values, .. } => Some(self.infer_bool_ops(values)?),
|
||||||
ast::ExprKind::BinOp { left, op, right } => {
|
ast::ExprKind::BinOp { left, op, right } => {
|
||||||
Some(self.infer_bin_ops(expr.location, left, op, right)?)
|
Some(self.infer_bin_ops(expr.location, left, op, right, false)?)
|
||||||
}
|
}
|
||||||
ast::ExprKind::UnaryOp { op, operand } => Some(self.infer_unary_ops(op, operand)?),
|
ast::ExprKind::UnaryOp { op, operand } => Some(self.infer_unary_ops(op, operand)?),
|
||||||
ast::ExprKind::Compare { left, ops, comparators } => {
|
ast::ExprKind::Compare { left, ops, comparators } => {
|
||||||
@ -1021,8 +1028,24 @@ impl<'a> Inferencer<'a> {
|
|||||||
left: &ast::Expr<Option<Type>>,
|
left: &ast::Expr<Option<Type>>,
|
||||||
op: &ast::Operator,
|
op: &ast::Operator,
|
||||||
right: &ast::Expr<Option<Type>>,
|
right: &ast::Expr<Option<Type>>,
|
||||||
|
is_aug_assign: bool,
|
||||||
) -> InferenceResult {
|
) -> InferenceResult {
|
||||||
let method = binop_name(op).into();
|
let method = if let TypeEnum::TObj { fields, .. } =
|
||||||
|
self.unifier.get_ty_immutable(left.custom.unwrap()).as_ref()
|
||||||
|
{
|
||||||
|
let (binop_name, binop_assign_name) = (
|
||||||
|
binop_name(op).into(),
|
||||||
|
binop_assign_name(op).into()
|
||||||
|
);
|
||||||
|
// if is aug_assign, try aug_assign operator first
|
||||||
|
if is_aug_assign && fields.contains_key(&binop_assign_name) {
|
||||||
|
binop_assign_name
|
||||||
|
} else {
|
||||||
|
binop_name
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
binop_name(op).into()
|
||||||
|
};
|
||||||
self.build_method_call(
|
self.build_method_call(
|
||||||
location,
|
location,
|
||||||
method,
|
method,
|
||||||
|
@ -44,14 +44,14 @@ impl SymbolResolver for Resolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_identifier_def(&self, id: StrRef) -> Result<DefinitionId, String> {
|
fn get_identifier_def(&self, id: StrRef) -> Result<DefinitionId, String> {
|
||||||
self.id_to_def.get(&id).cloned().ok_or("Unknown identifier".to_string())
|
self.id_to_def.get(&id).cloned().ok_or_else(|| "Unknown identifier".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_string_id(&self, _: &str) -> i32 {
|
fn get_string_id(&self, _: &str) -> i32 {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_exception_id(&self, tyid: usize) -> usize {
|
fn get_exception_id(&self, _tyid: usize) -> usize {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ use crate::toplevel::{DefinitionId, TopLevelContext, TopLevelDef};
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test;
|
mod test;
|
||||||
|
|
||||||
/// Handle for a type, implementated as a key in the unification table.
|
/// Handle for a type, implemented as a key in the unification table.
|
||||||
pub type Type = UnificationKey;
|
pub type Type = UnificationKey;
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||||
@ -657,12 +657,16 @@ impl Unifier {
|
|||||||
return Err(TypeError::new(TypeErrorKind::IncompatibleTypes(a, b), None));
|
return Err(TypeError::new(TypeErrorKind::IncompatibleTypes(a, b), None));
|
||||||
}
|
}
|
||||||
for (x, y) in ty1.iter().zip(ty2.iter()) {
|
for (x, y) in ty1.iter().zip(ty2.iter()) {
|
||||||
self.unify_impl(*x, *y, false)?;
|
if self.unify_impl(*x, *y, false).is_err() {
|
||||||
|
return Err(TypeError::new(TypeErrorKind::IncompatibleTypes(a, b), None));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
self.set_a_to_b(a, b);
|
self.set_a_to_b(a, b);
|
||||||
}
|
}
|
||||||
(TList { ty: ty1 }, TList { ty: ty2 }) => {
|
(TList { ty: ty1 }, TList { ty: ty2 }) => {
|
||||||
self.unify_impl(*ty1, *ty2, false)?;
|
if self.unify_impl(*ty1, *ty2, false).is_err() {
|
||||||
|
return Err(TypeError::new(TypeErrorKind::IncompatibleTypes(a, b), None));
|
||||||
|
}
|
||||||
self.set_a_to_b(a, b);
|
self.set_a_to_b(a, b);
|
||||||
}
|
}
|
||||||
(TVar { fields: Some(map), range, .. }, TObj { fields, .. }) => {
|
(TVar { fields: Some(map), range, .. }, TObj { fields, .. }) => {
|
||||||
@ -743,12 +747,16 @@ impl Unifier {
|
|||||||
self.incompatible_types(a, b)?;
|
self.incompatible_types(a, b)?;
|
||||||
}
|
}
|
||||||
for (x, y) in zip(params1.values(), params2.values()) {
|
for (x, y) in zip(params1.values(), params2.values()) {
|
||||||
self.unify_impl(*x, *y, false)?;
|
if self.unify_impl(*x, *y, false).is_err() {
|
||||||
|
return Err(TypeError::new(TypeErrorKind::IncompatibleTypes(a, b), None));
|
||||||
|
};
|
||||||
}
|
}
|
||||||
self.set_a_to_b(a, b);
|
self.set_a_to_b(a, b);
|
||||||
}
|
}
|
||||||
(TVirtual { ty: ty1 }, TVirtual { ty: ty2 }) => {
|
(TVirtual { ty: ty1 }, TVirtual { ty: ty2 }) => {
|
||||||
self.unify_impl(*ty1, *ty2, false)?;
|
if self.unify_impl(*ty1, *ty2, false).is_err() {
|
||||||
|
return Err(TypeError::new(TypeErrorKind::IncompatibleTypes(a, b), None));
|
||||||
|
};
|
||||||
self.set_a_to_b(a, b);
|
self.set_a_to_b(a, b);
|
||||||
}
|
}
|
||||||
(TCall(calls1), TCall(calls2)) => {
|
(TCall(calls1), TCall(calls2)) => {
|
||||||
@ -784,9 +792,13 @@ impl Unifier {
|
|||||||
if x.name != y.name || x.default_value != y.default_value {
|
if x.name != y.name || x.default_value != y.default_value {
|
||||||
return Err(TypeError::new(TypeErrorKind::IncompatibleTypes(a, b), None));
|
return Err(TypeError::new(TypeErrorKind::IncompatibleTypes(a, b), None));
|
||||||
}
|
}
|
||||||
self.unify_impl(x.ty, y.ty, false)?;
|
if self.unify_impl(x.ty, y.ty, false).is_err() {
|
||||||
|
return Err(TypeError::new(TypeErrorKind::IncompatibleTypes(a, b), None));
|
||||||
|
};
|
||||||
}
|
}
|
||||||
self.unify_impl(sign1.ret, sign2.ret, false)?;
|
if self.unify_impl(sign1.ret, sign2.ret, false).is_err() {
|
||||||
|
return Err(TypeError::new(TypeErrorKind::IncompatibleTypes(a, b), None));
|
||||||
|
};
|
||||||
self.set_a_to_b(a, b);
|
self.set_a_to_b(a, b);
|
||||||
}
|
}
|
||||||
(TVar { fields: Some(fields), .. }, _) => {
|
(TVar { fields: Some(fields), .. }, _) => {
|
||||||
@ -830,7 +842,7 @@ impl Unifier {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
&mut |id| format!("var{}", id),
|
&mut |id| format!("typevar{}", id),
|
||||||
notes,
|
notes,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -286,7 +286,7 @@ fn test_unify(
|
|||||||
("v1", "tuple[int]"),
|
("v1", "tuple[int]"),
|
||||||
("v2", "tuple[float]"),
|
("v2", "tuple[float]"),
|
||||||
],
|
],
|
||||||
(("v1", "v2"), "Incompatible types: 0 and 1")
|
(("v1", "v2"), "Incompatible types: tuple[0] and tuple[1]")
|
||||||
; "tuple parameter mismatch"
|
; "tuple parameter mismatch"
|
||||||
)]
|
)]
|
||||||
#[test_case(2,
|
#[test_case(2,
|
||||||
@ -302,14 +302,14 @@ fn test_unify(
|
|||||||
("v1", "Record[a=float,b=int]"),
|
("v1", "Record[a=float,b=int]"),
|
||||||
("v2", "Foo[v3]"),
|
("v2", "Foo[v3]"),
|
||||||
],
|
],
|
||||||
(("v1", "v2"), "`3[var4]::b` field/method does not exist")
|
(("v1", "v2"), "`3[typevar4]::b` field/method does not exist")
|
||||||
; "record obj merge"
|
; "record obj merge"
|
||||||
)]
|
)]
|
||||||
/// Test cases for invalid unifications.
|
/// Test cases for invalid unifications.
|
||||||
fn test_invalid_unification(
|
fn test_invalid_unification(
|
||||||
variable_count: u32,
|
variable_count: u32,
|
||||||
unify_pairs: &[(&'static str, &'static str)],
|
unify_pairs: &[(&'static str, &'static str)],
|
||||||
errornous_pair: ((&'static str, &'static str), &'static str),
|
erroneous_pair: ((&'static str, &'static str), &'static str),
|
||||||
) {
|
) {
|
||||||
let mut env = TestEnvironment::new();
|
let mut env = TestEnvironment::new();
|
||||||
let mut mapping = HashMap::new();
|
let mut mapping = HashMap::new();
|
||||||
@ -326,11 +326,11 @@ fn test_invalid_unification(
|
|||||||
pairs.push((t1, t2));
|
pairs.push((t1, t2));
|
||||||
}
|
}
|
||||||
let (t1, t2) =
|
let (t1, t2) =
|
||||||
(env.parse(errornous_pair.0 .0, &mapping), env.parse(errornous_pair.0 .1, &mapping));
|
(env.parse(erroneous_pair.0 .0, &mapping), env.parse(erroneous_pair.0 .1, &mapping));
|
||||||
for (a, b) in pairs {
|
for (a, b) in pairs {
|
||||||
env.unifier.unify(a, b).unwrap();
|
env.unifier.unify(a, b).unwrap();
|
||||||
}
|
}
|
||||||
assert_eq!(env.unify(t1, t2), Err(errornous_pair.1.to_string()));
|
assert_eq!(env.unify(t1, t2), Err(erroneous_pair.1.to_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -445,7 +445,7 @@ fn test_typevar_range() {
|
|||||||
// where v in (int, list[v1]), v1 in (int, bool)
|
// where v in (int, list[v1]), v1 in (int, bool)
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
env.unify(float_list, v),
|
env.unify(float_list, v),
|
||||||
Err("Expected any one of these types: 0, list[var5], but got list[1]\n\nNotes:\n var5 ∈ {0, 2}".to_string())
|
Err("Expected any one of these types: 0, list[typevar5], but got list[1]\n\nNotes:\n typevar5 ∈ {0, 2}".to_string())
|
||||||
);
|
);
|
||||||
|
|
||||||
let a = env.unifier.get_fresh_var_with_range(&[int, float], None, None).0;
|
let a = env.unifier.get_fresh_var_with_range(&[int, float], None, None).0;
|
||||||
@ -478,7 +478,8 @@ fn test_typevar_range() {
|
|||||||
let int_list = env.unifier.add_ty(TypeEnum::TList { ty: int });
|
let int_list = env.unifier.add_ty(TypeEnum::TList { ty: int });
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
env.unify(a_list, int_list),
|
env.unify(a_list, int_list),
|
||||||
Err("Expected any one of these types: 1, but got 0".into())
|
Err("Incompatible types: list[typevar22] and list[0]\
|
||||||
|
\n\nNotes:\n typevar22 ∈ {1}".into())
|
||||||
);
|
);
|
||||||
|
|
||||||
let a = env.unifier.get_fresh_var_with_range(&[int, float], None, None).0;
|
let a = env.unifier.get_fresh_var_with_range(&[int, float], None, None).0;
|
||||||
@ -504,9 +505,9 @@ fn test_rigid_var() {
|
|||||||
let int = env.parse("int", &HashMap::new());
|
let int = env.parse("int", &HashMap::new());
|
||||||
let list_int = env.parse("list[int]", &HashMap::new());
|
let list_int = env.parse("list[int]", &HashMap::new());
|
||||||
|
|
||||||
assert_eq!(env.unify(a, b), Err("Incompatible types: var3 and var2".to_string()));
|
assert_eq!(env.unify(a, b), Err("Incompatible types: typevar3 and typevar2".to_string()));
|
||||||
env.unifier.unify(list_a, list_x).unwrap();
|
env.unifier.unify(list_a, list_x).unwrap();
|
||||||
assert_eq!(env.unify(list_x, list_int), Err("Incompatible types: 0 and var2".to_string()));
|
assert_eq!(env.unify(list_x, list_int), Err("Incompatible types: list[typevar2] and list[0]".to_string()));
|
||||||
|
|
||||||
env.unifier.replace_rigid_var(a, int);
|
env.unifier.replace_rigid_var(a, int);
|
||||||
env.unifier.unify(list_x, list_int).unwrap();
|
env.unifier.unify(list_x, list_int).unwrap();
|
||||||
|
@ -121,7 +121,7 @@ mod tests {
|
|||||||
#[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, Default::default()).unwrap();
|
let parse_ast = parse_program(source, Default::default()).unwrap();
|
||||||
insta::assert_debug_snapshot!(parse_ast);
|
insta::assert_debug_snapshot!(parse_ast);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,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, Default::default()).unwrap());
|
insta::assert_debug_snapshot!(parse_program(source, Default::default()).unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -140,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, Default::default()).unwrap());
|
insta::assert_debug_snapshot!(parse_program(source, Default::default()).unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -183,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, Default::default()).unwrap());
|
insta::assert_debug_snapshot!(parse_program(source, Default::default()).unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -196,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, Default::default()).unwrap());
|
insta::assert_debug_snapshot!(parse_program(source, Default::default()).unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -215,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, Default::default()).unwrap());
|
insta::assert_debug_snapshot!(parse_program(source, Default::default()).unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -224,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, Default::default()).is_err());
|
assert!(parse_program(source, Default::default()).is_err());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,6 @@ nac3parser = { path = "../nac3parser" }
|
|||||||
nac3core = { path = "../nac3core" }
|
nac3core = { path = "../nac3core" }
|
||||||
|
|
||||||
[dependencies.inkwell]
|
[dependencies.inkwell]
|
||||||
version = "0.1.0-beta.4"
|
git = "https://github.com/TheDan64/inkwell.git"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["llvm13-0", "target-x86", "target-arm", "target-riscv", "no-libffi-linking"]
|
features = ["llvm14-0", "target-x86", "target-arm", "target-riscv", "no-libffi-linking"]
|
||||||
|
@ -74,6 +74,11 @@ pub extern "C" fn __nac3_personality(_state: u32, _exception_object: u32, _conte
|
|||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn __nac3_raise(_state: u32, _exception_object: u32, _context: u32) -> u32 {
|
||||||
|
unimplemented!();
|
||||||
|
}
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
fn run() -> i32;
|
fn run() -> i32;
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,8 @@ if [ -z "$1" ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -e ../../target/release/nac3standalone ]; then
|
if [ -e ../../target/debug/nac3standalone ]; then
|
||||||
nac3standalone=../../target/release/nac3standalone
|
nac3standalone=../../target/debug/nac3standalone
|
||||||
else
|
else
|
||||||
# used by Nix builds
|
# used by Nix builds
|
||||||
nac3standalone=../../target/x86_64-unknown-linux-gnu/release/nac3standalone
|
nac3standalone=../../target/x86_64-unknown-linux-gnu/release/nac3standalone
|
||||||
|
43
nac3standalone/demo/src/default_param.py
Normal file
43
nac3standalone/demo/src/default_param.py
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
@extern
|
||||||
|
def output_int32(x: int32):
|
||||||
|
...
|
||||||
|
|
||||||
|
def f1(a: int32 = 4):
|
||||||
|
output_int32(a)
|
||||||
|
|
||||||
|
def f2(a: int64 = int64(123)):
|
||||||
|
output_int32(int32(a))
|
||||||
|
|
||||||
|
def f3(a: uint32 = uint32(234)):
|
||||||
|
output_int32(int32(a))
|
||||||
|
|
||||||
|
def f4(a: tuple[int32, tuple[int32, int32], int64] = (4, (5, 6), int64(7))):
|
||||||
|
output_int32(a[0])
|
||||||
|
output_int32(a[1][0])
|
||||||
|
output_int32(a[1][1])
|
||||||
|
output_int32(int32(a[2]))
|
||||||
|
|
||||||
|
def f5(a: float = 3.45):
|
||||||
|
output_int32(int32(a))
|
||||||
|
|
||||||
|
def f6(a: Option[list[int32]] = none):
|
||||||
|
if a.is_none():
|
||||||
|
a = Some([11,22,33])
|
||||||
|
output_int32(a.unwrap()[2])
|
||||||
|
|
||||||
|
def f7(a: Option[tuple[int32, int64]] = Some((3, int64(123)))):
|
||||||
|
if a.is_some():
|
||||||
|
a_unwrap = a.unwrap()
|
||||||
|
output_int32(a_unwrap[0])
|
||||||
|
output_int32(int32(a_unwrap[1]))
|
||||||
|
|
||||||
|
|
||||||
|
def run() -> int32:
|
||||||
|
f1()
|
||||||
|
f2()
|
||||||
|
f3()
|
||||||
|
f4()
|
||||||
|
f5()
|
||||||
|
f6()
|
||||||
|
f7()
|
||||||
|
return 0
|
@ -229,7 +229,7 @@ def list_slice_assignment():
|
|||||||
bl5[3:-5] = []
|
bl5[3:-5] = []
|
||||||
output_int32_list([int32(b) for b in bl5])
|
output_int32_list([int32(b) for b in bl5])
|
||||||
bl6 = bl[:]
|
bl6 = bl[:]
|
||||||
bl6[3:-5] = [True, False, False]
|
bl6[3:-5] = [True, False]
|
||||||
output_int32_list([int32(b) for b in bl6])
|
output_int32_list([int32(b) for b in bl6])
|
||||||
bl7 = bl[:]
|
bl7 = bl[:]
|
||||||
bl7[:-2] = [False]
|
bl7[:-2] = [False]
|
||||||
|
9
nac3standalone/demo/src/loop.py
Normal file
9
nac3standalone/demo/src/loop.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
@extern
|
||||||
|
def output_int32(x: int32):
|
||||||
|
...
|
||||||
|
|
||||||
|
def run() -> int32:
|
||||||
|
for _ in range(10):
|
||||||
|
output_int32(_)
|
||||||
|
_ = 0
|
||||||
|
return 0
|
257
nac3standalone/demo/src/operators.py
Normal file
257
nac3standalone/demo/src/operators.py
Normal file
@ -0,0 +1,257 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
@extern
|
||||||
|
def output_int32(x: int32):
|
||||||
|
...
|
||||||
|
@extern
|
||||||
|
def output_uint32(x: uint32):
|
||||||
|
...
|
||||||
|
@extern
|
||||||
|
def output_int64(x: int64):
|
||||||
|
...
|
||||||
|
@extern
|
||||||
|
def output_uint64(x: uint64):
|
||||||
|
...
|
||||||
|
@extern
|
||||||
|
def output_float64(x: float):
|
||||||
|
...
|
||||||
|
|
||||||
|
def run() -> int32:
|
||||||
|
test_int32()
|
||||||
|
test_uint32()
|
||||||
|
test_int64()
|
||||||
|
test_uint64()
|
||||||
|
test_A()
|
||||||
|
test_B()
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def test_int32():
|
||||||
|
a = 17
|
||||||
|
b = 3
|
||||||
|
output_int32(a + b)
|
||||||
|
output_int32(a - b)
|
||||||
|
output_int32(a * b)
|
||||||
|
output_int32(a // b)
|
||||||
|
output_int32(a % b)
|
||||||
|
output_int32(a | b)
|
||||||
|
output_int32(a ^ b)
|
||||||
|
output_int32(a & b)
|
||||||
|
output_int32(a << b)
|
||||||
|
output_int32(a >> b)
|
||||||
|
output_float64(a / b)
|
||||||
|
a += b
|
||||||
|
output_int32(a)
|
||||||
|
a -= b
|
||||||
|
output_int32(a)
|
||||||
|
a *= b
|
||||||
|
output_int32(a)
|
||||||
|
a //= b
|
||||||
|
output_int32(a)
|
||||||
|
a %= b
|
||||||
|
output_int32(a)
|
||||||
|
a |= b
|
||||||
|
output_int32(a)
|
||||||
|
a ^= b
|
||||||
|
output_int32(a)
|
||||||
|
a &= b
|
||||||
|
output_int32(a)
|
||||||
|
a <<= b
|
||||||
|
output_int32(a)
|
||||||
|
a >>= b
|
||||||
|
output_int32(a)
|
||||||
|
# fail because (a / b) is float
|
||||||
|
# a /= b
|
||||||
|
|
||||||
|
def test_uint32():
|
||||||
|
a = uint32(17)
|
||||||
|
b = uint32(3)
|
||||||
|
output_uint32(a + b)
|
||||||
|
output_uint32(a - b)
|
||||||
|
output_uint32(a * b)
|
||||||
|
output_uint32(a // b)
|
||||||
|
output_uint32(a % b)
|
||||||
|
output_uint32(a | b)
|
||||||
|
output_uint32(a ^ b)
|
||||||
|
output_uint32(a & b)
|
||||||
|
output_uint32(a << b)
|
||||||
|
output_uint32(a >> b)
|
||||||
|
output_float64(a / b)
|
||||||
|
a += b
|
||||||
|
output_uint32(a)
|
||||||
|
a -= b
|
||||||
|
output_uint32(a)
|
||||||
|
a *= b
|
||||||
|
output_uint32(a)
|
||||||
|
a //= b
|
||||||
|
output_uint32(a)
|
||||||
|
a %= b
|
||||||
|
output_uint32(a)
|
||||||
|
a |= b
|
||||||
|
output_uint32(a)
|
||||||
|
a ^= b
|
||||||
|
output_uint32(a)
|
||||||
|
a &= b
|
||||||
|
output_uint32(a)
|
||||||
|
a <<= b
|
||||||
|
output_uint32(a)
|
||||||
|
a >>= b
|
||||||
|
output_uint32(a)
|
||||||
|
|
||||||
|
def test_int64():
|
||||||
|
a = int64(17)
|
||||||
|
b = int64(3)
|
||||||
|
output_int64(a + b)
|
||||||
|
output_int64(a - b)
|
||||||
|
output_int64(a * b)
|
||||||
|
output_int64(a // b)
|
||||||
|
output_int64(a % b)
|
||||||
|
output_int64(a | b)
|
||||||
|
output_int64(a ^ b)
|
||||||
|
output_int64(a & b)
|
||||||
|
output_int64(a << b)
|
||||||
|
output_int64(a >> b)
|
||||||
|
output_float64(a / b)
|
||||||
|
a += b
|
||||||
|
output_int64(a)
|
||||||
|
a -= b
|
||||||
|
output_int64(a)
|
||||||
|
a *= b
|
||||||
|
output_int64(a)
|
||||||
|
a //= b
|
||||||
|
output_int64(a)
|
||||||
|
a %= b
|
||||||
|
output_int64(a)
|
||||||
|
a |= b
|
||||||
|
output_int64(a)
|
||||||
|
a ^= b
|
||||||
|
output_int64(a)
|
||||||
|
a &= b
|
||||||
|
output_int64(a)
|
||||||
|
a <<= b
|
||||||
|
output_int64(a)
|
||||||
|
a >>= b
|
||||||
|
output_int64(a)
|
||||||
|
|
||||||
|
def test_uint64():
|
||||||
|
a = uint64(17)
|
||||||
|
b = uint64(3)
|
||||||
|
output_uint64(a + b)
|
||||||
|
output_uint64(a - b)
|
||||||
|
output_uint64(a * b)
|
||||||
|
output_uint64(a // b)
|
||||||
|
output_uint64(a % b)
|
||||||
|
output_uint64(a | b)
|
||||||
|
output_uint64(a ^ b)
|
||||||
|
output_uint64(a & b)
|
||||||
|
output_uint64(a << b)
|
||||||
|
output_uint64(a >> b)
|
||||||
|
output_float64(a / b)
|
||||||
|
a += b
|
||||||
|
output_uint64(a)
|
||||||
|
a -= b
|
||||||
|
output_uint64(a)
|
||||||
|
a *= b
|
||||||
|
output_uint64(a)
|
||||||
|
a //= b
|
||||||
|
output_uint64(a)
|
||||||
|
a %= b
|
||||||
|
output_uint64(a)
|
||||||
|
a |= b
|
||||||
|
output_uint64(a)
|
||||||
|
a ^= b
|
||||||
|
output_uint64(a)
|
||||||
|
a &= b
|
||||||
|
output_uint64(a)
|
||||||
|
a <<= b
|
||||||
|
output_uint64(a)
|
||||||
|
a >>= b
|
||||||
|
output_uint64(a)
|
||||||
|
|
||||||
|
class A:
|
||||||
|
a: int32
|
||||||
|
def __init__(self, a: int32):
|
||||||
|
self.a = a
|
||||||
|
|
||||||
|
def __add__(self, other: A) -> A:
|
||||||
|
output_int32(self.a + other.a)
|
||||||
|
return A(self.a + other.a)
|
||||||
|
|
||||||
|
def __sub__(self, other: A) -> A:
|
||||||
|
output_int32(self.a - other.a)
|
||||||
|
return A(self.a - other.a)
|
||||||
|
|
||||||
|
def test_A():
|
||||||
|
a = A(17)
|
||||||
|
b = A(3)
|
||||||
|
|
||||||
|
c = a + b
|
||||||
|
# fail due to alloca in __add__ function
|
||||||
|
# output_int32(c.a)
|
||||||
|
|
||||||
|
a += b
|
||||||
|
# fail due to alloca in __add__ function
|
||||||
|
# output_int32(a.a)
|
||||||
|
|
||||||
|
a = A(17)
|
||||||
|
b = A(3)
|
||||||
|
d = a - b
|
||||||
|
# fail due to alloca in __add__ function
|
||||||
|
# output_int32(c.a)
|
||||||
|
|
||||||
|
a -= b
|
||||||
|
# fail due to alloca in __add__ function
|
||||||
|
# output_int32(a.a)
|
||||||
|
|
||||||
|
a = A(17)
|
||||||
|
b = A(3)
|
||||||
|
a.__add__(b)
|
||||||
|
a.__sub__(b)
|
||||||
|
|
||||||
|
|
||||||
|
class B:
|
||||||
|
a: int32
|
||||||
|
def __init__(self, a: int32):
|
||||||
|
self.a = a
|
||||||
|
|
||||||
|
def __add__(self, other: B) -> B:
|
||||||
|
output_int32(self.a + other.a)
|
||||||
|
return B(self.a + other.a)
|
||||||
|
|
||||||
|
def __sub__(self, other: B) -> B:
|
||||||
|
output_int32(self.a - other.a)
|
||||||
|
return B(self.a - other.a)
|
||||||
|
|
||||||
|
def __iadd__(self, other: B) -> B:
|
||||||
|
output_int32(self.a + other.a + 24)
|
||||||
|
return B(self.a + other.a + 24)
|
||||||
|
|
||||||
|
def __isub__(self, other: B) -> B:
|
||||||
|
output_int32(self.a - other.a - 24)
|
||||||
|
return B(self.a - other.a - 24)
|
||||||
|
|
||||||
|
def test_B():
|
||||||
|
a = B(17)
|
||||||
|
b = B(3)
|
||||||
|
|
||||||
|
c = a + b
|
||||||
|
# fail due to alloca in __add__ function
|
||||||
|
# output_int32(c.a)
|
||||||
|
|
||||||
|
a += b
|
||||||
|
# fail due to alloca in __add__ function
|
||||||
|
# output_int32(a.a)
|
||||||
|
|
||||||
|
a = B(17)
|
||||||
|
b = B(3)
|
||||||
|
d = a - b
|
||||||
|
# fail due to alloca in __add__ function
|
||||||
|
# output_int32(c.a)
|
||||||
|
|
||||||
|
a -= b
|
||||||
|
# fail due to alloca in __add__ function
|
||||||
|
# output_int32(a.a)
|
||||||
|
|
||||||
|
a = B(17)
|
||||||
|
b = B(3)
|
||||||
|
a.__add__(b)
|
||||||
|
a.__sub__(b)
|
26
nac3standalone/demo/src/pow.py
Normal file
26
nac3standalone/demo/src/pow.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
@extern
|
||||||
|
def output_float64(f: float):
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
|
def run() -> int32:
|
||||||
|
output_float64(float(3 ** 1))
|
||||||
|
output_float64(float(3 ** 0))
|
||||||
|
output_float64(float(3 ** 19))
|
||||||
|
output_float64(1.0 ** -100)
|
||||||
|
output_float64(1.0 ** -2)
|
||||||
|
output_float64(1.0 ** 0)
|
||||||
|
output_float64(1.0 ** 1)
|
||||||
|
output_float64(1.0 ** 100)
|
||||||
|
output_float64(3.0 ** 0)
|
||||||
|
output_float64(3.0 ** 1)
|
||||||
|
output_float64(3.0 ** 2)
|
||||||
|
output_float64(3.0 ** -1)
|
||||||
|
output_float64(3.0 ** -2)
|
||||||
|
output_float64(3.0 ** -32767)
|
||||||
|
output_float64(3.0 ** -3.0)
|
||||||
|
output_float64(3.0 ** -0.0)
|
||||||
|
output_float64(3.0 ** 0.0)
|
||||||
|
output_float64(4.0 ** 0.5)
|
||||||
|
output_float64(4.0 ** -0.5)
|
||||||
|
return 0
|
29
nac3standalone/demo/src/tuple.py
Normal file
29
nac3standalone/demo/src/tuple.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
@extern
|
||||||
|
def output_int32_list(x: list[int32]):
|
||||||
|
...
|
||||||
|
|
||||||
|
@extern
|
||||||
|
def output_int32(x: int32):
|
||||||
|
...
|
||||||
|
|
||||||
|
class A:
|
||||||
|
a: int32
|
||||||
|
b: bool
|
||||||
|
def __init__(self, a: int32, b: bool):
|
||||||
|
self.a = a
|
||||||
|
self.b = b
|
||||||
|
|
||||||
|
def run() -> int32:
|
||||||
|
data = [0, 1, 2, 3]
|
||||||
|
|
||||||
|
t = [(d, d + d) for d in data]
|
||||||
|
for i in t:
|
||||||
|
tt = (Some(i[1]), i[0])
|
||||||
|
tl = ([i[0], i[1] + i[0]], i[1])
|
||||||
|
output_int32(tt[0].unwrap())
|
||||||
|
output_int32(tt[1])
|
||||||
|
output_int32(tl[0][0])
|
||||||
|
output_int32(tl[0][1])
|
||||||
|
output_int32(tl[1])
|
||||||
|
|
||||||
|
return 0
|
@ -2,7 +2,7 @@ use inkwell::{
|
|||||||
memory_buffer::MemoryBuffer,
|
memory_buffer::MemoryBuffer,
|
||||||
passes::{PassManager, PassManagerBuilder},
|
passes::{PassManager, PassManagerBuilder},
|
||||||
targets::*,
|
targets::*,
|
||||||
OptimizationLevel,
|
OptimizationLevel, module::Module, context::Context, AddressSpace,
|
||||||
};
|
};
|
||||||
use parking_lot::{Mutex, RwLock};
|
use parking_lot::{Mutex, RwLock};
|
||||||
use std::{borrow::Borrow, collections::HashMap, env, fs, path::Path, sync::Arc};
|
use std::{borrow::Borrow, collections::HashMap, env, fs, path::Path, sync::Arc};
|
||||||
@ -30,46 +30,13 @@ use nac3parser::{
|
|||||||
mod basic_symbol_resolver;
|
mod basic_symbol_resolver;
|
||||||
use basic_symbol_resolver::*;
|
use basic_symbol_resolver::*;
|
||||||
|
|
||||||
fn main() {
|
fn handle_typevar_definition(
|
||||||
let file_name = env::args().nth(1).unwrap();
|
|
||||||
let threads: u32 = env::args().nth(2).map(|s| str::parse(&s).unwrap()).unwrap_or(1);
|
|
||||||
|
|
||||||
Target::initialize_all(&InitializationConfig::default());
|
|
||||||
|
|
||||||
let program = match fs::read_to_string(file_name.clone()) {
|
|
||||||
Ok(program) => program,
|
|
||||||
Err(err) => {
|
|
||||||
println!("Cannot open input file: {}", err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let primitive: PrimitiveStore = TopLevelComposer::make_primitives().0;
|
|
||||||
let (mut composer, builtins_def, builtins_ty) =
|
|
||||||
TopLevelComposer::new(vec![], Default::default());
|
|
||||||
|
|
||||||
let internal_resolver: Arc<ResolverInternal> = ResolverInternal {
|
|
||||||
id_to_type: builtins_ty.into(),
|
|
||||||
id_to_def: builtins_def.into(),
|
|
||||||
class_names: Default::default(),
|
|
||||||
module_globals: Default::default(),
|
|
||||||
str_store: Default::default(),
|
|
||||||
}
|
|
||||||
.into();
|
|
||||||
let resolver =
|
|
||||||
Arc::new(Resolver(internal_resolver.clone())) as Arc<dyn SymbolResolver + Send + Sync>;
|
|
||||||
|
|
||||||
let parser_result = parser::parse_program(&program, file_name.into()).unwrap();
|
|
||||||
|
|
||||||
for stmt in parser_result.into_iter() {
|
|
||||||
if let StmtKind::Assign { targets, value, .. } = &stmt.node {
|
|
||||||
fn handle_typevar_definition(
|
|
||||||
var: &Expr,
|
var: &Expr,
|
||||||
resolver: &(dyn SymbolResolver + Send + Sync),
|
resolver: &(dyn SymbolResolver + Send + Sync),
|
||||||
def_list: &[Arc<RwLock<TopLevelDef>>],
|
def_list: &[Arc<RwLock<TopLevelDef>>],
|
||||||
unifier: &mut Unifier,
|
unifier: &mut Unifier,
|
||||||
primitives: &PrimitiveStore,
|
primitives: &PrimitiveStore,
|
||||||
) -> Result<Type, String> {
|
) -> Result<Type, String> {
|
||||||
if let ExprKind::Call { func, args, .. } = &var.node {
|
if let ExprKind::Call { func, args, .. } = &var.node {
|
||||||
if matches!(&func.node, ExprKind::Name { id, .. } if id == &"TypeVar".into()) {
|
if matches!(&func.node, ExprKind::Name { id, .. } if id == &"TypeVar".into()) {
|
||||||
let constraints = args
|
let constraints = args
|
||||||
@ -102,9 +69,9 @@ fn main() {
|
|||||||
var
|
var
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_assignment_pattern(
|
fn handle_assignment_pattern(
|
||||||
targets: &[Expr],
|
targets: &[Expr],
|
||||||
value: &Expr,
|
value: &Expr,
|
||||||
resolver: &(dyn SymbolResolver + Send + Sync),
|
resolver: &(dyn SymbolResolver + Send + Sync),
|
||||||
@ -112,7 +79,7 @@ fn main() {
|
|||||||
def_list: &[Arc<RwLock<TopLevelDef>>],
|
def_list: &[Arc<RwLock<TopLevelDef>>],
|
||||||
unifier: &mut Unifier,
|
unifier: &mut Unifier,
|
||||||
primitives: &PrimitiveStore,
|
primitives: &PrimitiveStore,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
if targets.len() == 1 {
|
if targets.len() == 1 {
|
||||||
match &targets[0].node {
|
match &targets[0].node {
|
||||||
ExprKind::Name { id, .. } => {
|
ExprKind::Name { id, .. } => {
|
||||||
@ -185,8 +152,41 @@ fn main() {
|
|||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let file_name = env::args().nth(1).unwrap();
|
||||||
|
let threads: u32 = env::args().nth(2).map(|s| str::parse(&s).unwrap()).unwrap_or(2);
|
||||||
|
|
||||||
|
Target::initialize_all(&InitializationConfig::default());
|
||||||
|
|
||||||
|
let program = match fs::read_to_string(file_name.clone()) {
|
||||||
|
Ok(program) => program,
|
||||||
|
Err(err) => {
|
||||||
|
println!("Cannot open input file: {}", err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let primitive: PrimitiveStore = TopLevelComposer::make_primitives().0;
|
||||||
|
let (mut composer, builtins_def, builtins_ty) =
|
||||||
|
TopLevelComposer::new(vec![], Default::default());
|
||||||
|
|
||||||
|
let internal_resolver: Arc<ResolverInternal> = ResolverInternal {
|
||||||
|
id_to_type: builtins_ty.into(),
|
||||||
|
id_to_def: builtins_def.into(),
|
||||||
|
class_names: Default::default(),
|
||||||
|
module_globals: Default::default(),
|
||||||
|
str_store: Default::default(),
|
||||||
|
}.into();
|
||||||
|
let resolver =
|
||||||
|
Arc::new(Resolver(internal_resolver.clone())) as Arc<dyn SymbolResolver + Send + Sync>;
|
||||||
|
|
||||||
|
let parser_result = parser::parse_program(&program, file_name.into()).unwrap();
|
||||||
|
|
||||||
|
for stmt in parser_result.into_iter() {
|
||||||
|
match &stmt.node {
|
||||||
|
StmtKind::Assign { targets, value, .. } => {
|
||||||
let def_list = composer.extract_def_list();
|
let def_list = composer.extract_def_list();
|
||||||
let unifier = &mut composer.unifier;
|
let unifier = &mut composer.unifier;
|
||||||
let primitives = &composer.primitives_ty;
|
let primitives = &composer.primitives_ty;
|
||||||
@ -202,17 +202,20 @@ fn main() {
|
|||||||
eprintln!("{}", err);
|
eprintln!("{}", err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
continue;
|
},
|
||||||
}
|
// allow (and ignore) "from __future__ import annotations"
|
||||||
|
StmtKind::ImportFrom { module, names, .. }
|
||||||
|
if module == &Some("__future__".into()) && names.len() == 1 && names[0].name == "annotations".into() => (),
|
||||||
|
_ => {
|
||||||
let (name, def_id, ty) =
|
let (name, def_id, ty) =
|
||||||
composer.register_top_level(stmt, Some(resolver.clone()), "__main__".into()).unwrap();
|
composer.register_top_level(stmt, Some(resolver.clone()), "__main__".into()).unwrap();
|
||||||
|
|
||||||
internal_resolver.add_id_def(name, def_id);
|
internal_resolver.add_id_def(name, def_id);
|
||||||
if let Some(ty) = ty {
|
if let Some(ty) = ty {
|
||||||
internal_resolver.add_id_type(name, ty);
|
internal_resolver.add_id_type(name, ty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let signature = FunSignature { args: vec![], ret: primitive.int32, vars: HashMap::new() };
|
let signature = FunSignature { args: vec![], ret: primitive.int32, vars: HashMap::new() };
|
||||||
let mut store = ConcreteTypeStore::new();
|
let mut store = ConcreteTypeStore::new();
|
||||||
@ -310,4 +313,210 @@ fn main() {
|
|||||||
target_machine
|
target_machine
|
||||||
.write_to_file(&main, FileType::Object, Path::new("module.o"))
|
.write_to_file(&main, FileType::Object, Path::new("module.o"))
|
||||||
.expect("couldn't write module to file");
|
.expect("couldn't write module to file");
|
||||||
|
|
||||||
|
|
||||||
|
// ===================================
|
||||||
|
// let ctxx = inkwell::context::Context::create();
|
||||||
|
// let ctxx2 = inkwell::context::Context::create();
|
||||||
|
// let ctxx3 = inkwell::context::Context::create();
|
||||||
|
|
||||||
|
// // let builder = PassManagerBuilder::create();
|
||||||
|
// // builder.set_optimization_level(OptimizationLevel::Aggressive);
|
||||||
|
// // let passes = PassManager::create(());
|
||||||
|
// // builder.set_inliner_with_threshold(255);
|
||||||
|
// // builder.populate_module_pass_manager(&passes);
|
||||||
|
|
||||||
|
// let mmm = test2(&ctxx, &ctxx, &ctxx3);
|
||||||
|
// // passes.run_on(&mmm);
|
||||||
|
// Target::initialize_all(&InitializationConfig::default());
|
||||||
|
// let triple = TargetMachine::get_default_triple();
|
||||||
|
// let target = Target::from_triple(&triple).expect("couldn't create target from target triple");
|
||||||
|
// let target_machine = target
|
||||||
|
// .create_target_machine(
|
||||||
|
// &triple,
|
||||||
|
// "",
|
||||||
|
// "",
|
||||||
|
// OptimizationLevel::Default,
|
||||||
|
// RelocMode::Default,
|
||||||
|
// CodeModel::Default,
|
||||||
|
// )
|
||||||
|
// .expect("couldn't create target machine");
|
||||||
|
// target_machine
|
||||||
|
// .write_to_file(&mmm, FileType::Object, Path::new("module.o"))
|
||||||
|
// .expect("couldn't write module to file");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test<'ctx>(ctx: &'ctx Context, ctx2: &'ctx Context, ctx3: &'ctx Context) -> Module<'ctx> {
|
||||||
|
let module = ctx.create_module("test");
|
||||||
|
let module2 = ctx2.create_module("test2");
|
||||||
|
let builder = ctx.create_builder();
|
||||||
|
let builder2 = ctx2.create_builder();
|
||||||
|
|
||||||
|
let int32 = ctx.i32_type();
|
||||||
|
let int8 = ctx.i8_type();
|
||||||
|
let int322 = ctx2.i32_type();
|
||||||
|
let int82 = ctx2.i8_type();
|
||||||
|
|
||||||
|
let opaque = ctx.opaque_struct_type("TestType");
|
||||||
|
let opaque = ctx.opaque_struct_type("TestType");
|
||||||
|
opaque.set_body(&[int32.into(), opaque.ptr_type(AddressSpace::Generic).into()], false);
|
||||||
|
let opaque = opaque.ptr_type(AddressSpace::Generic);
|
||||||
|
|
||||||
|
// let opaque2 = module.get_struct_type("TestType").unwrap();
|
||||||
|
let opaque2 = ctx2.opaque_struct_type("TestType");
|
||||||
|
// let opaque2 = ctx2.opaque_struct_type("TestType");
|
||||||
|
opaque2.set_body(&[int322.into(), opaque2.ptr_type(AddressSpace::Generic).into()], false);
|
||||||
|
let opaque2 = opaque2.ptr_type(AddressSpace::Generic);
|
||||||
|
|
||||||
|
|
||||||
|
let func2 = module2.add_function("f", ctx2.void_type().fn_type(&[opaque2.into()], false), None);
|
||||||
|
let func2_bb = ctx2.append_basic_block(func2, "init");
|
||||||
|
builder2.position_at_end(func2_bb);
|
||||||
|
builder2.build_return(None);
|
||||||
|
|
||||||
|
let func = module.add_function("run", ctx.void_type().fn_type(&[], false), None);
|
||||||
|
let fun2_mod1 = module.add_function("f", ctx.void_type().fn_type(&[opaque.into()], false), None);
|
||||||
|
let func1_bb = ctx.append_basic_block(func, "init");
|
||||||
|
builder.position_at_end(func1_bb);
|
||||||
|
let opaque1_ptr = builder.build_alloca(opaque.get_element_type().into_struct_type(), "alloc1");
|
||||||
|
let opaque2_ptr = builder.build_alloca(opaque.get_element_type().into_struct_type(), "alloc2");
|
||||||
|
builder.build_store(
|
||||||
|
unsafe { builder.build_gep(opaque1_ptr, &[int32.const_zero(), int32.const_zero()], "gep") },
|
||||||
|
int32.const_int(123, false)
|
||||||
|
);
|
||||||
|
builder.build_store(
|
||||||
|
unsafe { builder.build_gep(opaque2_ptr, &[int32.const_zero(), int32.const_zero()], "gep") },
|
||||||
|
int32.const_int(23, false)
|
||||||
|
);
|
||||||
|
builder.build_store(
|
||||||
|
unsafe { builder.build_gep(opaque1_ptr, &[int32.const_zero(), int32.const_int(1, false)], "gep") },
|
||||||
|
opaque2_ptr
|
||||||
|
);
|
||||||
|
builder.build_store(
|
||||||
|
unsafe { builder.build_gep(opaque2_ptr, &[int32.const_zero(), int32.const_int(1, false)], "gep") },
|
||||||
|
opaque1_ptr
|
||||||
|
);
|
||||||
|
// let arr = builder.build_array_alloca(opaque, int32.const_int(2, false), "arr");
|
||||||
|
// builder.build_store(
|
||||||
|
// unsafe { builder.build_gep(arr, &[int32.const_zero()], "zero")},
|
||||||
|
// opaque1_ptr
|
||||||
|
// );
|
||||||
|
let arr = module.add_global(
|
||||||
|
opaque.array_type(2),
|
||||||
|
None,
|
||||||
|
"arr_const",
|
||||||
|
);
|
||||||
|
arr.set_initializer(&opaque.const_array(&[opaque1_ptr, opaque2_ptr]));
|
||||||
|
let arr = arr.as_pointer_value();
|
||||||
|
let arg = builder.build_load(
|
||||||
|
unsafe { builder.build_gep(arr, &[int32.const_zero(), int32.const_zero()], "zero")},
|
||||||
|
"load"
|
||||||
|
);
|
||||||
|
builder.build_call(fun2_mod1, &[arg.into()], "call");
|
||||||
|
builder.build_return(None);
|
||||||
|
|
||||||
|
// builder.build_call(func2, args, name)
|
||||||
|
|
||||||
|
println!("before: \n========= module1: \n{}\n=========module2: \n{}=======\n\n", module.print_to_string().to_string(), module2.print_to_string().to_string());
|
||||||
|
module.verify().unwrap();
|
||||||
|
module2.verify().unwrap();
|
||||||
|
// module.link_in_module(module2).unwrap();
|
||||||
|
let mut mem: Vec<Vec<u8>> = Default::default();
|
||||||
|
let bitcode1 = module.write_bitcode_to_memory();
|
||||||
|
let bitcode1 = bitcode1.as_slice();
|
||||||
|
mem.push(bitcode1.into());
|
||||||
|
let bitcode2 = module2.write_bitcode_to_memory();
|
||||||
|
let bitcode2 = bitcode2.as_slice();
|
||||||
|
mem.push(bitcode2.into());
|
||||||
|
|
||||||
|
let mod1 = ctx3.create_module_from_ir(MemoryBuffer::create_from_memory_range(&mem[0], "mod1")).unwrap();
|
||||||
|
let mod2 = ctx3.create_module_from_ir(MemoryBuffer::create_from_memory_range(&mem[1], "mod2")).unwrap();
|
||||||
|
mod1.verify().unwrap();
|
||||||
|
mod2.verify().unwrap();
|
||||||
|
mod1.link_in_module(mod2).unwrap();
|
||||||
|
let module = mod1;
|
||||||
|
println!("after");
|
||||||
|
|
||||||
|
println!("\n\n====finish===\n{}\n=====finish=====\n\n\n", module.print_to_string().to_string());
|
||||||
|
|
||||||
|
|
||||||
|
println!("before2");
|
||||||
|
match module.verify() {
|
||||||
|
Ok(_) => (),
|
||||||
|
Err(s) => {
|
||||||
|
println!("after2");
|
||||||
|
println!("\n\n=======\n{}\n==========\n{}\n\n", module.print_to_string().to_string(), s.to_string());
|
||||||
|
println!("after3");
|
||||||
|
panic!();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
println!("\n=====done===========");
|
||||||
|
module
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test2<'ctx>(ctx: &'ctx Context, ctx2: &'ctx Context, ctx3: &'ctx Context) -> Module<'ctx> {
|
||||||
|
let module = ctx.create_module("test");
|
||||||
|
let module2 = ctx2.create_module("test2");
|
||||||
|
let builder = ctx.create_builder();
|
||||||
|
let builder2 = ctx2.create_builder();
|
||||||
|
|
||||||
|
let int32 = ctx.i32_type();
|
||||||
|
let int8 = ctx.i8_type();
|
||||||
|
let int322 = ctx2.i32_type();
|
||||||
|
let int82 = ctx2.i8_type();
|
||||||
|
|
||||||
|
let opaque = ctx.opaque_struct_type("TestType");
|
||||||
|
opaque.set_body(&[int32.into(), int8.into()], false);
|
||||||
|
let opaque = opaque.ptr_type(AddressSpace::Generic);
|
||||||
|
|
||||||
|
let opaque2 = module2.get_struct_type("TestType").unwrap();
|
||||||
|
// let opaque2 = ctx2.opaque_struct_type("TestType");
|
||||||
|
// let opaque2 = ctx2.opaque_struct_type("TestType");
|
||||||
|
opaque2.set_body(&[int322.into(), int82.into()], false);
|
||||||
|
let opaque2 = opaque2.ptr_type(AddressSpace::Generic);
|
||||||
|
|
||||||
|
|
||||||
|
let func2 = module2.add_function("f", ctx2.void_type().fn_type(&[opaque2.into()], false), None);
|
||||||
|
let func2_bb = ctx2.append_basic_block(func2, "init");
|
||||||
|
builder2.position_at_end(func2_bb);
|
||||||
|
builder2.build_return(None);
|
||||||
|
|
||||||
|
let func = module.add_function("run", ctx.void_type().fn_type(&[], false), None);
|
||||||
|
// let fun2_mod1 = module.add_function("f", ctx.void_type().fn_type(&[opaque2.into()], false), None);
|
||||||
|
let func1_bb = ctx.append_basic_block(func, "init");
|
||||||
|
builder.position_at_end(func1_bb);
|
||||||
|
let opaque1_ptr = builder.build_alloca(opaque.get_element_type().into_struct_type(), "alloc1");
|
||||||
|
builder.build_store(
|
||||||
|
unsafe { builder.build_gep(opaque1_ptr, &[int32.const_zero(), int32.const_zero()], "gep") },
|
||||||
|
int32.const_int(123, false)
|
||||||
|
);
|
||||||
|
builder.build_store(
|
||||||
|
unsafe { builder.build_gep(opaque1_ptr, &[int32.const_zero(), int32.const_int(1, false)], "gep") },
|
||||||
|
int8.const_int(12, false),
|
||||||
|
);
|
||||||
|
builder.build_call(func2, &[opaque1_ptr.into()], "call");
|
||||||
|
builder.build_return(None);
|
||||||
|
|
||||||
|
|
||||||
|
println!("before: \n========= module1: \n{}\n=========module2: \n{}=======\n\n", module.print_to_string().to_string(), module2.print_to_string().to_string());
|
||||||
|
module.verify().unwrap();
|
||||||
|
module2.verify().unwrap();
|
||||||
|
module.link_in_module(module2).unwrap();
|
||||||
|
println!("after");
|
||||||
|
|
||||||
|
// println!("\n\n====finish===\n{}\n=====finish=====\n\n\n", module.print_to_string().to_string());
|
||||||
|
|
||||||
|
|
||||||
|
println!("before2");
|
||||||
|
match module.verify() {
|
||||||
|
Ok(_) => (),
|
||||||
|
Err(s) => {
|
||||||
|
println!("after2");
|
||||||
|
println!("\n\n=======\n{}\n==========\n{}\n\n", module.print_to_string().to_string(), s.to_string());
|
||||||
|
println!("after3");
|
||||||
|
panic!();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
println!("\n=====done===========");
|
||||||
|
module
|
||||||
}
|
}
|
@ -8,7 +8,6 @@
|
|||||||
, ncurses
|
, ncurses
|
||||||
, zlib
|
, zlib
|
||||||
, which
|
, which
|
||||||
, llvmPackages_13
|
|
||||||
, debugVersion ? false
|
, debugVersion ? false
|
||||||
, enableManpages ? false
|
, enableManpages ? false
|
||||||
, enableSharedLibraries ? false
|
, enableSharedLibraries ? false
|
||||||
@ -18,7 +17,7 @@
|
|||||||
let
|
let
|
||||||
inherit (lib) optional optionals optionalString;
|
inherit (lib) optional optionals optionalString;
|
||||||
|
|
||||||
release_version = "13.0.1";
|
release_version = "14.0.3";
|
||||||
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
|
||||||
@ -35,7 +34,7 @@ in stdenv.mkDerivation (rec {
|
|||||||
pname = "llvm";
|
pname = "llvm";
|
||||||
inherit version;
|
inherit version;
|
||||||
|
|
||||||
src = fetch pname "sha256-7GuA2Cw4SsrS3BkpA6bPLNuv+4ibhL+5janXHmMPyDQ=";
|
src = fetch pname "sha256-Hgnowm4bZ7yUoSi2LpucJLcMaXokNqR5yeXu3ErillQ=";
|
||||||
|
|
||||||
unpackPhase = ''
|
unpackPhase = ''
|
||||||
unpackFile $src
|
unpackFile $src
|
||||||
@ -50,19 +49,12 @@ in stdenv.mkDerivation (rec {
|
|||||||
|
|
||||||
buildInputs = [ ];
|
buildInputs = [ ];
|
||||||
|
|
||||||
propagatedBuildInputs = optionals (stdenv.buildPlatform == stdenv.hostPlatform) [ ncurses ]
|
propagatedBuildInputs = [ ncurses zlib ];
|
||||||
++ [ zlib ];
|
|
||||||
|
|
||||||
checkInputs = [ which ];
|
checkInputs = [ which ];
|
||||||
|
|
||||||
patches = [
|
patches = [
|
||||||
./gnu-install-dirs.patch
|
./gnu-install-dirs.patch
|
||||||
# Fix random compiler crashes: https://bugs.llvm.org/show_bug.cgi?id=50611
|
|
||||||
(fetchpatch {
|
|
||||||
url = "https://raw.githubusercontent.com/archlinux/svntogit-packages/4764a4f8c920912a2bfd8b0eea57273acfe0d8a8/trunk/no-strict-aliasing-DwarfCompileUnit.patch";
|
|
||||||
sha256 = "18l6mrvm2vmwm77ckcnbjvh6ybvn72rhrb799d4qzwac4x2ifl7g";
|
|
||||||
stripLen = 1;
|
|
||||||
})
|
|
||||||
./llvm-future-riscv-abi.diff
|
./llvm-future-riscv-abi.diff
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -121,6 +113,8 @@ in stdenv.mkDerivation (rec {
|
|||||||
"-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.hostPlatform.config}"
|
"-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.hostPlatform.config}"
|
||||||
"-DLLVM_ENABLE_UNWIND_TABLES=OFF"
|
"-DLLVM_ENABLE_UNWIND_TABLES=OFF"
|
||||||
"-DLLVM_ENABLE_THREADS=OFF"
|
"-DLLVM_ENABLE_THREADS=OFF"
|
||||||
|
"-DLLVM_INCLUDE_BENCHMARKS=OFF"
|
||||||
|
"-DLLVM_BUILD_TOOLS=OFF"
|
||||||
"-DLLVM_TARGETS_TO_BUILD=X86;ARM;RISCV"
|
"-DLLVM_TARGETS_TO_BUILD=X86;ARM;RISCV"
|
||||||
] ++ optionals enableSharedLibraries [
|
] ++ optionals enableSharedLibraries [
|
||||||
"-DLLVM_LINK_LLVM_DYLIB=ON"
|
"-DLLVM_LINK_LLVM_DYLIB=ON"
|
||||||
@ -137,7 +131,6 @@ 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_13.tools.llvm}/bin/llvm-tblgen"
|
|
||||||
(
|
(
|
||||||
let
|
let
|
||||||
nativeCC = pkgsBuildBuild.targetPackages.stdenv.cc;
|
nativeCC = pkgsBuildBuild.targetPackages.stdenv.cc;
|
||||||
@ -154,6 +147,7 @@ in stdenv.mkDerivation (rec {
|
|||||||
] ++ extraCmakeFlags;
|
] ++ extraCmakeFlags;
|
||||||
|
|
||||||
postBuild = ''
|
postBuild = ''
|
||||||
|
make llvm-config
|
||||||
rm -fR $out
|
rm -fR $out
|
||||||
'';
|
'';
|
||||||
|
|
||||||
@ -162,6 +156,7 @@ in stdenv.mkDerivation (rec {
|
|||||||
'';
|
'';
|
||||||
|
|
||||||
postInstall = ''
|
postInstall = ''
|
||||||
|
cp bin/llvm-config $out/bin
|
||||||
mkdir -p $python/share
|
mkdir -p $python/share
|
||||||
mv $out/share/opt-viewer $python/share/opt-viewer
|
mv $out/share/opt-viewer $python/share/opt-viewer
|
||||||
moveToOutput "bin/llvm-config*" "$dev"
|
moveToOutput "bin/llvm-config*" "$dev"
|
220
nix/llvm/gnu-install-dirs.patch
Normal file
220
nix/llvm/gnu-install-dirs.patch
Normal file
@ -0,0 +1,220 @@
|
|||||||
|
diff --git a/CMakeLists.txt b/CMakeLists.txt
|
||||||
|
index fec956091cd5..5a766f5c5d7c 100644
|
||||||
|
--- a/CMakeLists.txt
|
||||||
|
+++ b/CMakeLists.txt
|
||||||
|
@@ -303,6 +303,9 @@ set(LLVM_EXAMPLES_INSTALL_DIR "examples" CACHE STRING
|
||||||
|
"Path for examples subdirectory (enabled by LLVM_BUILD_EXAMPLES=ON) (defaults to 'examples')")
|
||||||
|
mark_as_advanced(LLVM_EXAMPLES_INSTALL_DIR)
|
||||||
|
|
||||||
|
+set(LLVM_INSTALL_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/cmake/llvm" CACHE STRING
|
||||||
|
+ "Path for CMake subdirectory (defaults to lib/cmake/llvm)" )
|
||||||
|
+
|
||||||
|
# They are used as destination of target generators.
|
||||||
|
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})
|
||||||
|
diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake
|
||||||
|
index fed1fec7d72e..4baed19b9e98 100644
|
||||||
|
--- a/cmake/modules/AddLLVM.cmake
|
||||||
|
+++ b/cmake/modules/AddLLVM.cmake
|
||||||
|
@@ -838,8 +838,8 @@ macro(add_llvm_library name)
|
||||||
|
get_target_export_arg(${name} LLVM export_to_llvmexports ${umbrella})
|
||||||
|
install(TARGETS ${name}
|
||||||
|
${export_to_llvmexports}
|
||||||
|
- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name}
|
||||||
|
- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name}
|
||||||
|
+ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" COMPONENT ${name}
|
||||||
|
+ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" COMPONENT ${name}
|
||||||
|
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT ${name})
|
||||||
|
|
||||||
|
if (NOT LLVM_ENABLE_IDE)
|
||||||
|
@@ -1056,7 +1056,7 @@ function(process_llvm_pass_plugins)
|
||||||
|
"set(LLVM_STATIC_EXTENSIONS ${LLVM_STATIC_EXTENSIONS})")
|
||||||
|
install(FILES
|
||||||
|
${llvm_cmake_builddir}/LLVMConfigExtensions.cmake
|
||||||
|
- DESTINATION ${LLVM_INSTALL_PACKAGE_DIR}
|
||||||
|
+ DESTINATION ${LLVM_INSTALL_CMAKE_DIR}
|
||||||
|
COMPONENT cmake-exports)
|
||||||
|
|
||||||
|
set(ExtensionDef "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def")
|
||||||
|
@@ -1902,7 +1902,7 @@ function(llvm_install_library_symlink name dest type)
|
||||||
|
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(output_dir lib${LLVM_LIBDIR_SUFFIX})
|
||||||
|
+ set(output_dir ${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX})
|
||||||
|
if(WIN32 AND "${type}" STREQUAL "SHARED")
|
||||||
|
set(output_dir bin)
|
||||||
|
endif()
|
||||||
|
@@ -1913,7 +1913,7 @@ function(llvm_install_library_symlink name dest type)
|
||||||
|
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
-function(llvm_install_symlink name dest)
|
||||||
|
+function(llvm_install_symlink name dest output_dir)
|
||||||
|
cmake_parse_arguments(ARG "ALWAYS_GENERATE" "COMPONENT" "" ${ARGN})
|
||||||
|
foreach(path ${CMAKE_MODULE_PATH})
|
||||||
|
if(EXISTS ${path}/LLVMInstallSymlink.cmake)
|
||||||
|
@@ -1936,7 +1936,7 @@ function(llvm_install_symlink name dest)
|
||||||
|
set(full_dest ${dest}${CMAKE_EXECUTABLE_SUFFIX})
|
||||||
|
|
||||||
|
install(SCRIPT ${INSTALL_SYMLINK}
|
||||||
|
- CODE "install_symlink(${full_name} ${full_dest} ${LLVM_TOOLS_INSTALL_DIR})"
|
||||||
|
+ CODE "install_symlink(${full_name} ${full_dest} ${output_dir})"
|
||||||
|
COMPONENT ${component})
|
||||||
|
|
||||||
|
if (NOT LLVM_ENABLE_IDE AND NOT ARG_ALWAYS_GENERATE)
|
||||||
|
@@ -2019,7 +2019,8 @@ function(add_llvm_tool_symlink link_name target)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if ((TOOL_IS_TOOLCHAIN OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY) AND LLVM_BUILD_TOOLS)
|
||||||
|
- llvm_install_symlink(${link_name} ${target})
|
||||||
|
+ GNUInstallDirs_get_absolute_install_dir(output_dir LLVM_TOOLS_INSTALL_DIR)
|
||||||
|
+ llvm_install_symlink(${link_name} ${target} ${output_dir})
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
|
@@ -2148,9 +2149,9 @@ function(llvm_setup_rpath name)
|
||||||
|
# Since BUILD_SHARED_LIBS is only recommended for use by developers,
|
||||||
|
# hardcode the rpath to build/install lib dir first in this mode.
|
||||||
|
# FIXME: update this when there is better solution.
|
||||||
|
- set(_install_rpath "${LLVM_LIBRARY_OUTPUT_INTDIR}" "${CMAKE_INSTALL_PREFIX}/lib${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)
|
||||||
|
- set(_install_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir})
|
||||||
|
+ set(_install_rpath "\$ORIGIN/../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir})
|
||||||
|
if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
|
||||||
|
set_property(TARGET ${name} APPEND_STRING PROPERTY
|
||||||
|
LINK_FLAGS " -Wl,-z,origin ")
|
||||||
|
diff --git a/cmake/modules/AddOCaml.cmake b/cmake/modules/AddOCaml.cmake
|
||||||
|
index 891c9e6d618c..8d963f3b0069 100644
|
||||||
|
--- a/cmake/modules/AddOCaml.cmake
|
||||||
|
+++ b/cmake/modules/AddOCaml.cmake
|
||||||
|
@@ -147,9 +147,9 @@ function(add_ocaml_library name)
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
if( APPLE )
|
||||||
|
- set(ocaml_rpath "@executable_path/../../../lib${LLVM_LIBDIR_SUFFIX}")
|
||||||
|
+ set(ocaml_rpath "@executable_path/../../../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}")
|
||||||
|
elseif( UNIX )
|
||||||
|
- set(ocaml_rpath "\\$ORIGIN/../../../lib${LLVM_LIBDIR_SUFFIX}")
|
||||||
|
+ set(ocaml_rpath "\\$ORIGIN/../../../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}")
|
||||||
|
endif()
|
||||||
|
list(APPEND ocaml_flags "-ldopt" "-Wl,-rpath,${ocaml_rpath}")
|
||||||
|
|
||||||
|
diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt
|
||||||
|
index cea0c1df0a14..eedcd9450312 100644
|
||||||
|
--- a/cmake/modules/CMakeLists.txt
|
||||||
|
+++ b/cmake/modules/CMakeLists.txt
|
||||||
|
@@ -2,7 +2,7 @@ include(ExtendPath)
|
||||||
|
include(LLVMDistributionSupport)
|
||||||
|
include(FindPrefixFromConfig)
|
||||||
|
|
||||||
|
-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_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}")
|
||||||
|
|
||||||
|
# First for users who use an installed LLVM, create the LLVMExports.cmake file.
|
||||||
|
@@ -122,7 +122,7 @@ set(LLVM_CONFIG_INCLUDE_DIRS
|
||||||
|
)
|
||||||
|
list(REMOVE_DUPLICATES LLVM_CONFIG_INCLUDE_DIRS)
|
||||||
|
|
||||||
|
-extend_path(LLVM_CONFIG_LIBRARY_DIR "\${LLVM_INSTALL_PREFIX}" "lib\${LLVM_LIBDIR_SUFFIX}")
|
||||||
|
+extend_path(LLVM_CONFIG_LIBRARY_DIR "\${LLVM_INSTALL_PREFIX}" "${CMAKE_INSTALL_LIBDIR}\${LLVM_LIBDIR_SUFFIX}")
|
||||||
|
set(LLVM_CONFIG_LIBRARY_DIRS
|
||||||
|
"${LLVM_CONFIG_LIBRARY_DIR}"
|
||||||
|
# FIXME: Should there be other entries here?
|
||||||
|
diff --git a/cmake/modules/LLVMInstallSymlink.cmake b/cmake/modules/LLVMInstallSymlink.cmake
|
||||||
|
index b5c35f706cb7..9261ab797de6 100644
|
||||||
|
--- a/cmake/modules/LLVMInstallSymlink.cmake
|
||||||
|
+++ b/cmake/modules/LLVMInstallSymlink.cmake
|
||||||
|
@@ -6,7 +6,7 @@ include(GNUInstallDirs)
|
||||||
|
|
||||||
|
function(install_symlink name target outdir)
|
||||||
|
set(DESTDIR $ENV{DESTDIR})
|
||||||
|
- set(bindir "${DESTDIR}${CMAKE_INSTALL_PREFIX}/${outdir}")
|
||||||
|
+ set(bindir "${DESTDIR}${outdir}/")
|
||||||
|
|
||||||
|
message(STATUS "Creating ${name}")
|
||||||
|
|
||||||
|
diff --git a/docs/CMake.rst b/docs/CMake.rst
|
||||||
|
index 044ec8a4d39d..504d0eac3ade 100644
|
||||||
|
--- a/docs/CMake.rst
|
||||||
|
+++ b/docs/CMake.rst
|
||||||
|
@@ -224,7 +224,7 @@ description is in `LLVM-related variables`_ below.
|
||||||
|
**LLVM_LIBDIR_SUFFIX**:STRING
|
||||||
|
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``
|
||||||
|
- to install libraries to ``/usr/lib64``.
|
||||||
|
+ to install libraries to ``/usr/lib64``. See also ``CMAKE_INSTALL_LIBDIR``.
|
||||||
|
|
||||||
|
**LLVM_PARALLEL_{COMPILE,LINK}_JOBS**:STRING
|
||||||
|
Building the llvm toolchain can use a lot of resources, particularly
|
||||||
|
@@ -910,9 +910,11 @@ the ``cmake`` command or by setting it directly in ``ccmake`` or ``cmake-gui``).
|
||||||
|
|
||||||
|
This file is available in two different locations.
|
||||||
|
|
||||||
|
-* ``<INSTALL_PREFIX>/lib/cmake/llvm/LLVMConfig.cmake`` where
|
||||||
|
- ``<INSTALL_PREFIX>`` is the install prefix of an installed version of LLVM.
|
||||||
|
- On Linux typically this is ``/usr/lib/cmake/llvm/LLVMConfig.cmake``.
|
||||||
|
+* ``<LLVM_INSTALL_PACKAGE_DIR>LLVMConfig.cmake`` where
|
||||||
|
+ ``<LLVM_INSTALL_PACKAGE_DIR>`` is the location where LLVM CMake modules are
|
||||||
|
+ installed as part of an installed version of LLVM. This is typically
|
||||||
|
+ ``cmake/llvm/`` within the lib directory. On Linux, this is typically
|
||||||
|
+ ``/usr/lib/cmake/llvm/LLVMConfig.cmake``.
|
||||||
|
|
||||||
|
* ``<LLVM_BUILD_ROOT>/lib/cmake/llvm/LLVMConfig.cmake`` where
|
||||||
|
``<LLVM_BUILD_ROOT>`` is the root of the LLVM build tree. **Note: this is only
|
||||||
|
diff --git a/include/llvm/CMakeLists.txt b/include/llvm/CMakeLists.txt
|
||||||
|
index b46319f24fc8..2feabd1954e4 100644
|
||||||
|
--- a/include/llvm/CMakeLists.txt
|
||||||
|
+++ b/include/llvm/CMakeLists.txt
|
||||||
|
@@ -5,5 +5,5 @@ add_subdirectory(Frontend)
|
||||||
|
# If we're doing an out-of-tree build, copy a module map for generated
|
||||||
|
# header files into the build area.
|
||||||
|
if (NOT "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
|
||||||
|
- configure_file(module.modulemap.build module.modulemap COPYONLY)
|
||||||
|
+ configure_file(module.modulemap.build ${LLVM_INCLUDE_DIR}/module.modulemap COPYONLY)
|
||||||
|
endif (NOT "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
|
||||||
|
diff --git a/tools/llvm-config/BuildVariables.inc.in b/tools/llvm-config/BuildVariables.inc.in
|
||||||
|
index abbb8a450da6..70c497be12f5 100644
|
||||||
|
--- a/tools/llvm-config/BuildVariables.inc.in
|
||||||
|
+++ b/tools/llvm-config/BuildVariables.inc.in
|
||||||
|
@@ -23,7 +23,10 @@
|
||||||
|
#define LLVM_CXXFLAGS "@LLVM_CXXFLAGS@"
|
||||||
|
#define LLVM_BUILDMODE "@LLVM_BUILDMODE@"
|
||||||
|
#define LLVM_LIBDIR_SUFFIX "@LLVM_LIBDIR_SUFFIX@"
|
||||||
|
+#define LLVM_INSTALL_BINDIR "@CMAKE_INSTALL_BINDIR@"
|
||||||
|
+#define LLVM_INSTALL_LIBDIR "@CMAKE_INSTALL_LIBDIR@"
|
||||||
|
#define LLVM_INSTALL_INCLUDEDIR "@CMAKE_INSTALL_INCLUDEDIR@"
|
||||||
|
+#define LLVM_INSTALL_CMAKEDIR "@LLVM_INSTALL_CMAKE_DIR@"
|
||||||
|
#define LLVM_TARGETS_BUILT "@LLVM_TARGETS_BUILT@"
|
||||||
|
#define LLVM_SYSTEM_LIBS "@LLVM_SYSTEM_LIBS@"
|
||||||
|
#define LLVM_BUILD_SYSTEM "@LLVM_BUILD_SYSTEM@"
|
||||||
|
diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp
|
||||||
|
index 8ed88f33ead4..5e7184bab90d 100644
|
||||||
|
--- a/tools/llvm-config/llvm-config.cpp
|
||||||
|
+++ b/tools/llvm-config/llvm-config.cpp
|
||||||
|
@@ -363,12 +363,20 @@ int main(int argc, char **argv) {
|
||||||
|
ActiveIncludeDir = std::string(Path.str());
|
||||||
|
}
|
||||||
|
{
|
||||||
|
- SmallString<256> Path(LLVM_TOOLS_INSTALL_DIR);
|
||||||
|
+ SmallString<256> Path(LLVM_INSTALL_BINDIR);
|
||||||
|
sys::fs::make_absolute(ActivePrefix, Path);
|
||||||
|
ActiveBinDir = std::string(Path.str());
|
||||||
|
}
|
||||||
|
- ActiveLibDir = ActivePrefix + "/lib" + LLVM_LIBDIR_SUFFIX;
|
||||||
|
- ActiveCMakeDir = ActiveLibDir + "/cmake/llvm";
|
||||||
|
+ {
|
||||||
|
+ SmallString<256> Path(LLVM_INSTALL_LIBDIR LLVM_LIBDIR_SUFFIX);
|
||||||
|
+ sys::fs::make_absolute(ActivePrefix, Path);
|
||||||
|
+ ActiveLibDir = std::string(Path.str());
|
||||||
|
+ }
|
||||||
|
+ {
|
||||||
|
+ SmallString<256> Path(LLVM_INSTALL_CMAKEDIR);
|
||||||
|
+ sys::fs::make_absolute(ActivePrefix, Path);
|
||||||
|
+ ActiveCMakeDir = std::string(Path.str());
|
||||||
|
+ }
|
||||||
|
ActiveIncludeOption = "-I" + ActiveIncludeDir;
|
||||||
|
}
|
||||||
|
|
26
nix/windows/PKGBUILD
Normal file
26
nix/windows/PKGBUILD
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
pkgbase="mingw-w64-nac3artiq"
|
||||||
|
pkgname="mingw-w64-x86_64-nac3artiq"
|
||||||
|
pkgver=1.0
|
||||||
|
pkgrel=1
|
||||||
|
pkgdesc="New ARTIQ compiler 3"
|
||||||
|
arch=("any")
|
||||||
|
mingw_arch=("mingw64")
|
||||||
|
url="https://m-labs.hk"
|
||||||
|
license=("LGPL")
|
||||||
|
source=("nac3artiq.pyd")
|
||||||
|
noextract=("nac3artiq.pyd")
|
||||||
|
sha256sums=("SKIP")
|
||||||
|
depends=("mingw-w64-x86_64-python")
|
||||||
|
|
||||||
|
prepare() {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
build() {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
package() {
|
||||||
|
mkdir -p $pkgdir/mingw64/lib/python3.9/site-packages
|
||||||
|
cp ${srcdir}/nac3artiq.pyd $pkgdir/mingw64/lib/python3.9/site-packages
|
||||||
|
}
|
@ -33,14 +33,15 @@ let
|
|||||||
};
|
};
|
||||||
in rec {
|
in rec {
|
||||||
llvm-nac3 = pkgs.stdenvNoCC.mkDerivation rec {
|
llvm-nac3 = pkgs.stdenvNoCC.mkDerivation rec {
|
||||||
name = "llvm-nac3-msys2";
|
pname = "llvm-nac3-msys2";
|
||||||
|
version = "14.0.3";
|
||||||
src-llvm = pkgs.fetchurl {
|
src-llvm = pkgs.fetchurl {
|
||||||
url = "https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.1/llvm-13.0.1.src.tar.xz";
|
url = "https://github.com/llvm/llvm-project/releases/download/llvmorg-${version}/llvm-${version}.src.tar.xz";
|
||||||
sha256 = "sha256-7GuA2Cw4SsrS3BkpA6bPLNuv+4ibhL+5janXHmMPyDQ=";
|
sha256 = "sha256-Hgnowm4bZ7yUoSi2LpucJLcMaXokNqR5yeXu3ErillQ=";
|
||||||
};
|
};
|
||||||
src-clang = pkgs.fetchurl {
|
src-clang = pkgs.fetchurl {
|
||||||
url = "https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.1/clang-13.0.1.src.tar.xz";
|
url = "https://github.com/llvm/llvm-project/releases/download/llvmorg-${version}/clang-${version}.src.tar.xz";
|
||||||
sha256 = "sha256-eHqeLZn1yHIKoXc+S+AJRhzTDTvUD90kWR5HNGfJF8k=";
|
sha256 = "sha256-+FxV8ZLLNbnWrx+Zi31avpDjafixZEVQP/qxsC51pvA=";
|
||||||
};
|
};
|
||||||
buildInputs = [ pkgs.wineWowPackages.stable ];
|
buildInputs = [ pkgs.wineWowPackages.stable ];
|
||||||
phases = [ "unpackPhase" "patchPhase" "configurePhase" "buildPhase" "installPhase" ];
|
phases = [ "unpackPhase" "patchPhase" "configurePhase" "buildPhase" "installPhase" ];
|
||||||
@ -48,6 +49,7 @@ in rec {
|
|||||||
''
|
''
|
||||||
mkdir llvm
|
mkdir llvm
|
||||||
tar xf ${src-llvm} -C llvm --strip-components=1
|
tar xf ${src-llvm} -C llvm --strip-components=1
|
||||||
|
mv llvm/Modules/* llvm/cmake/modules # work around https://github.com/llvm/llvm-project/issues/53281
|
||||||
mkdir clang
|
mkdir clang
|
||||||
tar xf ${src-clang} -C clang --strip-components=1
|
tar xf ${src-clang} -C clang --strip-components=1
|
||||||
cd llvm
|
cd llvm
|
||||||
@ -63,7 +65,7 @@ in rec {
|
|||||||
${silenceFontconfig}
|
${silenceFontconfig}
|
||||||
mkdir build
|
mkdir build
|
||||||
cd build
|
cd build
|
||||||
wine64 cmake .. -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_UNWIND_TABLES=OFF -DLLVM_ENABLE_THREADS=OFF -DLLVM_TARGETS_TO_BUILD=X86\;ARM\;RISCV -DLLVM_LINK_LLVM_DYLIB=OFF -DLLVM_ENABLE_FFI=OFF -DFFI_INCLUDE_DIR=fck-cmake -DFFI_LIBRARY_DIR=fck-cmake -DLLVM_ENABLE_LIBXML2=OFF -DLLVM_ENABLE_PROJECTS=clang -DCMAKE_INSTALL_PREFIX=Z:$out
|
wine64 cmake .. -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_UNWIND_TABLES=OFF -DLLVM_ENABLE_THREADS=OFF -DLLVM_TARGETS_TO_BUILD=X86\;ARM\;RISCV -DLLVM_LINK_LLVM_DYLIB=OFF -DLLVM_ENABLE_FFI=OFF -DFFI_INCLUDE_DIR=fck-cmake -DFFI_LIBRARY_DIR=fck-cmake -DLLVM_ENABLE_LIBXML2=OFF -DLLVM_INCLUDE_BENCHMARKS=OFF -DLLVM_ENABLE_PROJECTS=clang -DCMAKE_INSTALL_PREFIX=Z:$out
|
||||||
'';
|
'';
|
||||||
buildPhase =
|
buildPhase =
|
||||||
''
|
''
|
||||||
@ -73,12 +75,18 @@ in rec {
|
|||||||
''
|
''
|
||||||
wine64 ninja install
|
wine64 ninja install
|
||||||
'';
|
'';
|
||||||
|
dontFixup = true;
|
||||||
};
|
};
|
||||||
nac3artiq = pkgs.rustPlatform.buildRustPackage {
|
nac3artiq = pkgs.rustPlatform.buildRustPackage {
|
||||||
name = "nac3artiq";
|
name = "nac3artiq-msys2";
|
||||||
src = ../.;
|
src = ../../.;
|
||||||
cargoLock = { lockFile = ../Cargo.lock; };
|
cargoLock = {
|
||||||
nativeBuildInputs = [ pkgs.wineWowPackages.stable pkgs.zip ];
|
lockFile = ../../Cargo.lock;
|
||||||
|
outputHashes = {
|
||||||
|
"inkwell-0.1.0" = "sha256-gDHV3RDuBU/l1viV1G1YO4kdTylRUctlxZcocX1hIIo=";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
nativeBuildInputs = [ pkgs.wineWowPackages.stable ];
|
||||||
buildPhase =
|
buildPhase =
|
||||||
''
|
''
|
||||||
export HOME=`mktemp -d`
|
export HOME=`mktemp -d`
|
||||||
@ -90,10 +98,9 @@ in rec {
|
|||||||
'';
|
'';
|
||||||
installPhase =
|
installPhase =
|
||||||
''
|
''
|
||||||
mkdir -p $out $out/nix-support
|
mkdir $out $out/nix-support
|
||||||
ln -s target/release/nac3artiq.dll nac3artiq.pyd
|
cp target/release/nac3artiq.dll $out/nac3artiq.pyd
|
||||||
zip $out/nac3artiq.zip nac3artiq.pyd
|
echo file binary-dist $out/nac3artiq.pyd >> $out/nix-support/hydra-build-products
|
||||||
echo file binary-dist $out/nac3artiq.zip >> $out/nix-support/hydra-build-products
|
|
||||||
'';
|
'';
|
||||||
checkPhase =
|
checkPhase =
|
||||||
''
|
''
|
||||||
@ -101,6 +108,61 @@ in rec {
|
|||||||
'';
|
'';
|
||||||
dontFixup = true;
|
dontFixup = true;
|
||||||
};
|
};
|
||||||
|
nac3artiq-pkg = pkgs.stdenvNoCC.mkDerivation {
|
||||||
|
name = "nac3artiq-msys2-pkg";
|
||||||
|
nativeBuildInputs = [ pkgs.pacman pkgs.fakeroot pkgs.libarchive pkgs.zstd ];
|
||||||
|
src = nac3artiq;
|
||||||
|
phases = [ "buildPhase" "installPhase" ];
|
||||||
|
buildPhase =
|
||||||
|
''
|
||||||
|
ln -s ${./PKGBUILD} PKGBUILD
|
||||||
|
ln -s $src/nac3artiq.pyd nac3artiq.pyd
|
||||||
|
makepkg --config ${./makepkg.conf} --nodeps
|
||||||
|
'';
|
||||||
|
installPhase =
|
||||||
|
''
|
||||||
|
mkdir $out $out/nix-support
|
||||||
|
cp *.pkg.tar.zst $out
|
||||||
|
echo file msys2 $out/*.pkg.tar.zst >> $out/nix-support/hydra-build-products
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
lld = pkgs.stdenvNoCC.mkDerivation rec {
|
||||||
|
pname = "lld-msys2";
|
||||||
|
version = "14.0.3";
|
||||||
|
src = pkgs.fetchurl {
|
||||||
|
url = "https://github.com/llvm/llvm-project/releases/download/llvmorg-${version}/lld-${version}.src.tar.xz";
|
||||||
|
sha256 = "sha256-qRcW9Z+OeAGCRqerbK0b/d3sJwxNttPSo5SETuh5nI8=";
|
||||||
|
};
|
||||||
|
buildInputs = [ pkgs.wineWowPackages.stable ];
|
||||||
|
phases = [ "unpackPhase" "patchPhase" "configurePhase" "buildPhase" "installPhase" ];
|
||||||
|
patches = [ ./lld-disable-macho.diff ];
|
||||||
|
setSourceRoot = # work around https://github.com/llvm/llvm-project/issues/53281
|
||||||
|
''
|
||||||
|
mv cmake/Modules/* lld-14.0.3.src/cmake/modules
|
||||||
|
sourceRoot=lld-14.0.3.src
|
||||||
|
'';
|
||||||
|
configurePhase =
|
||||||
|
''
|
||||||
|
export HOME=`mktemp -d`
|
||||||
|
export WINEDEBUG=-all
|
||||||
|
export WINEPATH=Z:${msys2-env}/mingw64/bin\;Z:${llvm-nac3}/bin
|
||||||
|
${silenceFontconfig}
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
wine64 cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=Z:$out
|
||||||
|
'';
|
||||||
|
buildPhase =
|
||||||
|
''
|
||||||
|
wine64 ninja
|
||||||
|
'';
|
||||||
|
installPhase =
|
||||||
|
''
|
||||||
|
mkdir -p $out $out/nix-support
|
||||||
|
cp bin/ld.lld.exe $out
|
||||||
|
echo file binary-dist $out/ld.lld.exe >> $out/nix-support/hydra-build-products
|
||||||
|
'';
|
||||||
|
dontFixup = true;
|
||||||
|
};
|
||||||
wine-msys2 = pkgs.writeShellScriptBin "wine-msys2"
|
wine-msys2 = pkgs.writeShellScriptBin "wine-msys2"
|
||||||
''
|
''
|
||||||
export WINEDEBUG=-all
|
export WINEDEBUG=-all
|
||||||
@ -108,4 +170,12 @@ in rec {
|
|||||||
export PYO3_CONFIG_FILE=Z:${pyo3-mingw-config}
|
export PYO3_CONFIG_FILE=Z:${pyo3-mingw-config}
|
||||||
exec ${pkgs.wineWowPackages.stable}/bin/wine64 cmd
|
exec ${pkgs.wineWowPackages.stable}/bin/wine64 cmd
|
||||||
'';
|
'';
|
||||||
|
wine-msys2-build = pkgs.writeShellScriptBin "wine-msys2-build"
|
||||||
|
''
|
||||||
|
export HOME=`mktemp -d`
|
||||||
|
export WINEDEBUG=-all
|
||||||
|
export WINEPATH=Z:${msys2-env}/mingw64/bin
|
||||||
|
${silenceFontconfig}
|
||||||
|
exec ${pkgs.wineWowPackages.stable}/bin/wine64 $@
|
||||||
|
'';
|
||||||
}
|
}
|
34
nix/windows/lld-disable-macho.diff
Normal file
34
nix/windows/lld-disable-macho.diff
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
diff '--color=auto' -Naur lld-14.0.1.src.orig/CMakeLists.txt lld-14.0.1.src/CMakeLists.txt
|
||||||
|
--- lld-14.0.1.src.orig/CMakeLists.txt 2022-04-12 07:44:22.000000000 +0800
|
||||||
|
+++ lld-14.0.1.src/CMakeLists.txt 2022-04-18 18:03:22.530746411 +0800
|
||||||
|
@@ -248,7 +248,6 @@
|
||||||
|
add_subdirectory(docs)
|
||||||
|
add_subdirectory(COFF)
|
||||||
|
add_subdirectory(ELF)
|
||||||
|
-add_subdirectory(MachO)
|
||||||
|
add_subdirectory(MinGW)
|
||||||
|
add_subdirectory(wasm)
|
||||||
|
|
||||||
|
diff '--color=auto' -Naur lld-14.0.1.src.orig/tools/lld/CMakeLists.txt lld-14.0.1.src/tools/lld/CMakeLists.txt
|
||||||
|
--- lld-14.0.1.src.orig/tools/lld/CMakeLists.txt 2022-04-12 07:44:22.000000000 +0800
|
||||||
|
+++ lld-14.0.1.src/tools/lld/CMakeLists.txt 2022-04-18 18:03:34.434692221 +0800
|
||||||
|
@@ -14,7 +14,6 @@
|
||||||
|
lldCommon
|
||||||
|
lldCOFF
|
||||||
|
lldELF
|
||||||
|
- lldMachO
|
||||||
|
lldMinGW
|
||||||
|
lldWasm
|
||||||
|
)
|
||||||
|
diff '--color=auto' -Naur lld-14.0.1.src.orig/tools/lld/lld.cpp lld-14.0.1.src/tools/lld/lld.cpp
|
||||||
|
--- lld-14.0.1.src.orig/tools/lld/lld.cpp 2022-04-12 07:44:22.000000000 +0800
|
||||||
|
+++ lld-14.0.1.src/tools/lld/lld.cpp 2022-04-18 18:04:08.517537288 +0800
|
||||||
|
@@ -151,8 +151,6 @@
|
||||||
|
return elf::link;
|
||||||
|
else if (f == WinLink)
|
||||||
|
return coff::link;
|
||||||
|
- else if (f == Darwin)
|
||||||
|
- return macho::link;
|
||||||
|
else if (f == Wasm)
|
||||||
|
return lld::wasm::link;
|
||||||
|
else
|
@ -10,7 +10,7 @@ curl -L https://mirror.msys2.org/msys/x86_64/pacman-mirrors-20220205-1-any.pkg.t
|
|||||||
curl -L https://raw.githubusercontent.com/msys2/MSYS2-packages/master/pacman/pacman.conf | grep -v SigLevel | sed s\|/etc/pacman.d\|$MSYS2DIR/etc/pacman.d\|g > $MSYS2DIR/etc/pacman.conf
|
curl -L https://raw.githubusercontent.com/msys2/MSYS2-packages/master/pacman/pacman.conf | grep -v SigLevel | sed s\|/etc/pacman.d\|$MSYS2DIR/etc/pacman.d\|g > $MSYS2DIR/etc/pacman.conf
|
||||||
|
|
||||||
fakeroot pacman --root $MSYS2DIR --config $MSYS2DIR/etc/pacman.conf -Syy
|
fakeroot pacman --root $MSYS2DIR --config $MSYS2DIR/etc/pacman.conf -Syy
|
||||||
pacman --root $MSYS2DIR --config $MSYS2DIR/etc/pacman.conf --cachedir $MSYS2DIR/msys/cache -Sp mingw-w64-x86_64-rust mingw-w64-x86_64-cmake mingw-w64-x86_64-ninja mingw-w64-x86_64-python3.9 mingw-w64-x86_64-python-numpy > $MSYS2DIR/packages.txt
|
pacman --root $MSYS2DIR --config $MSYS2DIR/etc/pacman.conf --cachedir $MSYS2DIR/msys/cache -Sp mingw-w64-x86_64-rust mingw-w64-x86_64-cmake mingw-w64-x86_64-ninja mingw-w64-x86_64-python3.9 mingw-w64-x86_64-python-numpy mingw-w64-x86_64-python-setuptools > $MSYS2DIR/packages.txt
|
||||||
|
|
||||||
echo "{ pkgs } : [" > msys2_packages.nix
|
echo "{ pkgs } : [" > msys2_packages.nix
|
||||||
while read package; do
|
while read package; do
|
2
nix/windows/makepkg.conf
Normal file
2
nix/windows/makepkg.conf
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
PKGEXT='.pkg.tar.zst'
|
||||||
|
SRCEXT='.src.tar.gz'
|
@ -6,8 +6,8 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
(pkgs.fetchurl {
|
(pkgs.fetchurl {
|
||||||
url = "https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-zlib-1.2.11-9-any.pkg.tar.zst";
|
url = "https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-zlib-1.2.12-1-any.pkg.tar.zst";
|
||||||
sha256 = "0fb3xbw9a0ah4viwp3a7hr5phnc7mvcl9ba2yjidncpqmspypacx";
|
sha256 = "1b461ic5s3hjk3y70ldik82ny08rdywn1zfqa8d2jyyvnh4dya77";
|
||||||
})
|
})
|
||||||
|
|
||||||
(pkgs.fetchurl {
|
(pkgs.fetchurl {
|
||||||
@ -16,13 +16,13 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
(pkgs.fetchurl {
|
(pkgs.fetchurl {
|
||||||
url = "https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-headers-git-9.0.0.6451.a3f6d363d-1-any.pkg.tar.zst";
|
url = "https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-headers-git-9.0.0.6454.b4445ee52-1-any.pkg.tar.zst";
|
||||||
sha256 = "1ngnjb9vgk295wlwqandm0nhqqdfrp584kx3nfshxkhwmj5gpzxk";
|
sha256 = "0wyg5ad3fh2lwd7avxvpncipj5wxmp647l43wzr1l3rrkd820yy3";
|
||||||
})
|
})
|
||||||
|
|
||||||
(pkgs.fetchurl {
|
(pkgs.fetchurl {
|
||||||
url = "https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-crt-git-9.0.0.6451.a3f6d363d-1-any.pkg.tar.zst";
|
url = "https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-crt-git-9.0.0.6454.b4445ee52-1-any.pkg.tar.zst";
|
||||||
sha256 = "1ccipidbsjncdhr48k50ia53dwn7v3ghdl8f1svgwvnh3mrx0bww";
|
sha256 = "0bnzwgf395fbwbsq8900prj409b081hi0dd76kak6d971xqyy2r4";
|
||||||
})
|
})
|
||||||
|
|
||||||
(pkgs.fetchurl {
|
(pkgs.fetchurl {
|
||||||
@ -46,8 +46,8 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
(pkgs.fetchurl {
|
(pkgs.fetchurl {
|
||||||
url = "https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-libwinpthread-git-9.0.0.6451.a3f6d363d-1-any.pkg.tar.zst";
|
url = "https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-libwinpthread-git-9.0.0.6454.b4445ee52-1-any.pkg.tar.zst";
|
||||||
sha256 = "0qdy79l5y02lw2xa8i3j6yayhz8a7awfgyyd82pcmbzwx57q2xqb";
|
sha256 = "181fm72bi6cs348hixkqjzivizzcsyn2lxvnbqprx4366prjf7nn";
|
||||||
})
|
})
|
||||||
|
|
||||||
(pkgs.fetchurl {
|
(pkgs.fetchurl {
|
||||||
@ -61,8 +61,8 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
(pkgs.fetchurl {
|
(pkgs.fetchurl {
|
||||||
url = "https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-winpthreads-git-9.0.0.6451.a3f6d363d-1-any.pkg.tar.zst";
|
url = "https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-winpthreads-git-9.0.0.6454.b4445ee52-1-any.pkg.tar.zst";
|
||||||
sha256 = "08zwgkrp45y5ry8avz61krasjkk4k4a5rrdz4nd78bbbah84mpgz";
|
sha256 = "0n3pim85wlsc93y9sh06rnfraqgzbz300sp9hd8n7wgvcsmpj9rx";
|
||||||
})
|
})
|
||||||
|
|
||||||
(pkgs.fetchurl {
|
(pkgs.fetchurl {
|
||||||
@ -86,8 +86,8 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
(pkgs.fetchurl {
|
(pkgs.fetchurl {
|
||||||
url = "https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-expat-2.4.7-1-any.pkg.tar.zst";
|
url = "https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-expat-2.4.8-1-any.pkg.tar.zst";
|
||||||
sha256 = "19qh3kk2kmkkzxirpx1swgfsfb29gy9q8qgdmrzzbwrqrn8vs77j";
|
sha256 = "1qkw4k61ddaflns5ms0xh0czbx99wxhs0dfbk8sv8by2rkshl51k";
|
||||||
})
|
})
|
||||||
|
|
||||||
(pkgs.fetchurl {
|
(pkgs.fetchurl {
|
||||||
@ -101,8 +101,8 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
(pkgs.fetchurl {
|
(pkgs.fetchurl {
|
||||||
url = "https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-libidn2-2.3.1-1-any.pkg.tar.zst";
|
url = "https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-libidn2-2.3.2-1-any.pkg.tar.zst";
|
||||||
sha256 = "00vm6d56ldr1f4h0dn15j0ja17dif45qxlxaqv4x5nw555frklf5";
|
sha256 = "0p694g8g716zyvcxc48xmdanjyrkp3ir4naqlradrw2szy9bj800";
|
||||||
})
|
})
|
||||||
|
|
||||||
(pkgs.fetchurl {
|
(pkgs.fetchurl {
|
||||||
@ -231,8 +231,8 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
(pkgs.fetchurl {
|
(pkgs.fetchurl {
|
||||||
url = "https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-cmake-3.22.3-2-any.pkg.tar.zst";
|
url = "https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-cmake-3.23.0-1-any.pkg.tar.zst";
|
||||||
sha256 = "1xp8n5s98va7a9cq36d9p49lk32yv9vkvlayc4d4j465xzm21hgp";
|
sha256 = "1gcmm3bd29zfd88ack6xdqwmbskyvhb4ymrfspayk4jfcj4svky5";
|
||||||
})
|
})
|
||||||
|
|
||||||
(pkgs.fetchurl {
|
(pkgs.fetchurl {
|
||||||
@ -266,8 +266,8 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
(pkgs.fetchurl {
|
(pkgs.fetchurl {
|
||||||
url = "https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-sqlite3-3.38.1-1-any.pkg.tar.zst";
|
url = "https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-sqlite3-3.38.2-1-any.pkg.tar.zst";
|
||||||
sha256 = "04h4m72mwmad82nzrl5qj9wlsinjs7z7bsbbq17dxkx92aj75p26";
|
sha256 = "14agi4611h5400j7bqh1w5i5qbhp4hp6apzaddilxq97y37vj90q";
|
||||||
})
|
})
|
||||||
|
|
||||||
(pkgs.fetchurl {
|
(pkgs.fetchurl {
|
||||||
@ -291,12 +291,17 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
(pkgs.fetchurl {
|
(pkgs.fetchurl {
|
||||||
url = "https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-openblas-0.3.20-1-any.pkg.tar.zst";
|
url = "https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-openblas-0.3.20-2-any.pkg.tar.zst";
|
||||||
sha256 = "1adbbycbvs2nkjhgap92fk3x0vqfjb3ghhvyd1xlnn56c5n0iphf";
|
sha256 = "1cj0j06b2xhcvq9v6jx5cn130r8pkv2xa885f3z3z98kmrifjw0l";
|
||||||
})
|
})
|
||||||
|
|
||||||
(pkgs.fetchurl {
|
(pkgs.fetchurl {
|
||||||
url = "https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-python-numpy-1.21.5-1-any.pkg.tar.zst";
|
url = "https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-python-numpy-1.21.5-1-any.pkg.tar.zst";
|
||||||
sha256 = "10bhfq65nrzxipgy75bqaad74daif4ay06phwvbx70b9j0wm33c3";
|
sha256 = "10bhfq65nrzxipgy75bqaad74daif4ay06phwvbx70b9j0wm33c3";
|
||||||
})
|
})
|
||||||
|
|
||||||
|
(pkgs.fetchurl {
|
||||||
|
url = "https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-python-setuptools-59.8.0-2-any.pkg.tar.zst";
|
||||||
|
sha256 = "1jbvsmh1r00yb6fm8by6z7xp9069f9lkj73jrsnxmflmvpdkjl5c";
|
||||||
|
})
|
||||||
]
|
]
|
Loading…
Reference in New Issue
Block a user