Squashed commit of the following:
commit677a200a15Author: sebastianselander <sebastian.selander@gmail.com> Date: Fri May 5 15:12:37 2023 +0200 Removed GC, merge it into main to save correct commit history commita720b9ffd8Author: sebastianselander <sebastian.selander@gmail.com> Date: Fri May 5 15:09:51 2023 +0200 Peano commit22d9dd8efaAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Fri May 5 14:28:05 2023 +0200 Fixed incorrect constructor name with Gilliam commit63fef958a7Author: sebastianselander <sebastian.selander@gmail.com> Date: Fri May 5 14:09:54 2023 +0200 Improved prelude commit7562949909Author: Rakarake <williambodin2001@gmail.com> Date: Fri May 5 12:24:13 2023 +0200 Finally, bug nr4 fixed commit513cb34eb5Author: sebastianselander <sebastian.selander@gmail.com> Date: Fri May 5 12:22:36 2023 +0200 back to inj commit47cbf12cd1Merge:010ca29747de6aAuthor: Rakarake <williambodin2001@gmail.com> Date: Fri May 5 11:44:17 2023 +0200 Merge branch 'pattern-matching-with-typechecking' of github.com:bachelor-group-66-systemf/churf into pattern-matching-with-typechecking commit010ca29cedAuthor: Rakarake <williambodin2001@gmail.com> Date: Fri May 5 11:44:08 2023 +0200 Fixed wrong name bug -- samuel commit747de6a34eAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Fri May 5 11:43:17 2023 +0200 Renaming symbols in desugar, removed incorrect comment in emits commitfe25f18eb7Author: Rakarake <williambodin2001@gmail.com> Date: Fri May 5 11:28:40 2023 +0200 Fixed naming-cons bug in monomorphizer commit4aa72beccbAuthor: Martin Fredin <fredin.martin@gmail.com> Date: Fri May 5 09:02:10 2023 +0200 Add missing clauses. Still broken commit1d551e5874Author: sebastian <sebastian.selander@gmail.com> Date: Fri May 5 00:35:48 2023 +0200 added alternative better implemenatation of checkBind commit0a588c4e14Author: Martin Fredin <fredin.martin@gmail.com> Date: Thu May 4 23:54:19 2023 +0200 Revert AnnForall change commit15025a67f9Author: sebastian <sebastian.selander@gmail.com> Date: Thu May 4 23:15:24 2023 +0200 removed unused imports commit988d0dbb53Author: sebastian <sebastian.selander@gmail.com> Date: Thu May 4 23:03:11 2023 +0200 moved stuff commit4f21a58200Author: sebastian <sebastian.selander@gmail.com> Date: Thu May 4 23:00:51 2023 +0200 more symbols and changed err msg commit0dc06eaf80Author: sebastian <sebastian.selander@gmail.com> Date: Thu May 4 22:50:15 2023 +0200 Parens removed on types and infix symbols work almost, just need to adapt in LLVM commitc309c439cbAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Thu May 4 21:30:19 2023 +0200 Fixed bug when freshening types commit122bff7436Author: sebastian <sebastian.selander@gmail.com> Date: Thu May 4 21:29:24 2023 +0200 Sugar has arrived commitc7b76cbbb4Author: sebastianselander <sebastian.selander@gmail.com> Date: Wed May 3 18:56:16 2023 +0200 Fixed a bug of repeated application of same function to arguments of differing types. More bufs appeared commit5a28f9d909Author: sebastianselander <sebastian.selander@gmail.com> Date: Wed May 3 17:59:09 2023 +0200 Bind now does correct subtype check. commitf8a70b4cf4Author: sebastianselander <sebastian.selander@gmail.com> Date: Wed May 3 17:58:50 2023 +0200 Improved error messages commit4038f34cc5Author: Rakarake <williambodin2001@gmail.com> Date: Wed May 3 15:08:07 2023 +0200 Fixed woring order of monomorphization in ECase commite70eae776aAuthor: Rakarake <williambodin2001@gmail.com> Date: Tue May 2 17:25:22 2023 +0200 Maybe made lets work in monomorphizer 🙃 commiteba91ec646Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Mon May 1 22:50:37 2023 +0200 The log folder is now created as well. commit22dcbc6a13Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Mon May 1 22:50:22 2023 +0200 Various codegen fixes commit45578a79b1Merge:59da6d80452a30Author: Rakarake <williambodin2001@gmail.com> Date: Mon May 1 16:14:10 2023 +0200 Merge branch 'pattern-matching-with-typechecking' of github.com:bachelor-group-66-systemf/churf into pattern-matching-with-typechecking commit59da6d8864Author: Rakarake <williambodin2001@gmail.com> Date: Mon May 1 16:14:01 2023 +0200 Fixed printing bug in MorbIr, fixed Monomorphizer forgetting to output constructors on EInj commit0452a30409Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Mon May 1 16:01:39 2023 +0200 Yoinked newer GC. commit3377879dd0Author: Rakarake <williambodin2001@gmail.com> Date: Mon May 1 11:57:06 2023 +0200 Small fix in morphBind commit0af2aac61eAuthor: Rakarake <williambodin2001@gmail.com> Date: Mon May 1 11:53:18 2023 +0200 Removed some warnings, better internal error commit6b72d08b94Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Mon May 1 11:09:23 2023 +0200 Commented out `customHelperFunctionCuzPoorImplementation` as it is not needed with type annotations. commit78af9431b9Author: Martin Fredin <fredin.martin@gmail.com> Date: Mon May 1 11:10:47 2023 +0200 Remove clang 11 commit63d805fa13Author: Martin Fredin <fredin.martin@gmail.com> Date: Mon May 1 10:55:34 2023 +0200 Uncomment prelude commit0fb13f59fbAuthor: Martin Fredin <fredin.martin@gmail.com> Date: Mon May 1 10:47:07 2023 +0200 Remove bad program commit8463dc2887Author: Martin Fredin <fredin.martin@gmail.com> Date: Sat Apr 29 21:58:39 2023 +0200 Small fix to lambda lifter commitd7a09a720bAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Sat Apr 29 17:55:18 2023 +0200 Fixed more precise type annotation for monomorphizer commita87862a99fAuthor: Martin Fredin <fredin.martin@gmail.com> Date: Sat Apr 29 16:02:51 2023 +0200 Fix sample programs commita2f61ea910Author: Martin Fredin <fredin.martin@gmail.com> Date: Sat Apr 29 15:56:01 2023 +0200 Fix missing pattern synonym commit619242ccafAuthor: Martin Fredin <fredin.martin@gmail.com> Date: Sat Apr 29 15:52:37 2023 +0200 Fix lambda lifter commitdf1a5de04aAuthor: Martin Fredin <fredin.martin@gmail.com> Date: Fri Apr 28 19:45:15 2023 +0200 Add module to sort definitions commitde03a2cc34Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Fri Apr 28 14:52:47 2023 +0200 The code generator can now compile without the GC. commitf9d28028b5Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Fri Apr 28 14:24:44 2023 +0200 The GC argument is now passed to the compiler and codegen. commitddffe7913cAuthor: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Fri Apr 28 14:22:02 2023 +0200 Added an option to disable the garbage collector (this feature is not implemented fully yet.). commit38b88d36b5Author: Martin Fredin <fredin.martin@gmail.com> Date: Fri Apr 28 14:20:24 2023 +0200 Use throwError instead of error commite8d37c77cbAuthor: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Fri Apr 28 14:10:39 2023 +0200 Fixed a typo. commitcb619c96a8Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Fri Apr 28 14:10:22 2023 +0200 Removed a stupid file commit1723796006Author: sebastianselander <sebastian.selander@gmail.com> Date: Fri Apr 28 14:01:05 2023 +0200 renamed and fixed const in prelude commitb27988b4d8Author: Martin Fredin <fredin.martin@gmail.com> Date: Fri Apr 28 14:04:47 2023 +0200 Add checking for case commit22ffdffa5aAuthor: Martin Fredin <fredin.martin@gmail.com> Date: Thu Apr 27 18:59:16 2023 +0200 Fix pretty printer commit072f2206e6Author: sebastianselander <sebastian.selander@gmail.com> Date: Fri Apr 28 12:53:29 2023 +0200 added const body again commite42c775135Author: Martin Fredin <fredin.martin@gmail.com> Date: Thu Apr 27 17:29:13 2023 +0200 Fix prelude commit3729278041Author: Rakarake <williambodin2001@gmail.com> Date: Thu Apr 27 16:44:30 2023 +0200 Unreachable branhces are removed, fixed a nasty bug in monomorphizer 😸 commit46a4d3d252Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Thu Apr 27 16:01:22 2023 +0200 Fixed a bug with penums commite19c809d5eMerge:509b51d39d0650Author: Rakarake <williambodin2001@gmail.com> Date: Thu Apr 27 15:09:45 2023 +0200 Merge branch 'pattern-matching-with-typechecking' of github.com:bachelor-group-66-systemf/churf into pattern-matching-with-typechecking commit509b51d2deAuthor: Rakarake <williambodin2001@gmail.com> Date: Thu Apr 27 15:09:39 2023 +0200 No output of wrongly typed cons commit39d0650115Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Thu Apr 27 15:06:42 2023 +0200 Fixed a booleans not being outputted as literals. commit579153b679Merge:60e12b6d026dcaAuthor: Rakarake <williambodin2001@gmail.com> Date: Thu Apr 27 14:02:10 2023 +0200 Merged commit60e12b622eAuthor: Rakarake <williambodin2001@gmail.com> Date: Thu Apr 27 13:55:54 2023 +0200 Using type annotations in case expressions, monomorphizer now handles case expressions without crashing commitd026dca42fAuthor: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Thu Apr 27 13:49:00 2023 +0200 Attacked the code generator and added bool support. commit1a21698772Author: sebastianselander <sebastian.selander@gmail.com> Date: Thu Apr 27 12:57:36 2023 +0200 mono fixier commit55fd35d661Author: sebastianselander <sebastian.selander@gmail.com> Date: Thu Apr 27 12:49:29 2023 +0200 mono fix commite9852079abAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Thu Apr 27 12:43:02 2023 +0200 bool now lit commit8782556603Author: Martin Fredin <fredin.martin@gmail.com> Date: Thu Apr 27 12:22:20 2023 +0200 Fix types in pattersgit add .git add . commitfc306d5f25Author: Martin Fredin <fredin.martin@gmail.com> Date: Thu Apr 27 11:43:56 2023 +0200 Fix pattern types commitfd418faa5fAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Thu Apr 27 12:18:56 2023 +0200 introduced lt in prelude commit2cb8527848Author: Martin Fredin <fredin.martin@gmail.com> Date: Tue Apr 25 23:02:56 2023 +0200 Rename variables commite138cb27ecAuthor: Martin Fredin <fredin.martin@gmail.com> Date: Tue Apr 25 22:59:33 2023 +0200 Simplify pattern matching commit9ffcbf66b9Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Tue Apr 18 15:28:03 2023 +0200 Added support for running GC profiller. commitb5384bf2c3Author: Martin Fredin <fredin.martin@gmail.com> Date: Tue Apr 25 13:22:33 2023 +0200 Fix typo commit2d96a50219Author: Martin Fredin <fredin.martin@gmail.com> Date: Mon Apr 24 10:47:33 2023 +0200 Change name commit804d0da167Author: Martin Fredin <fredin.martin@gmail.com> Date: Mon Apr 24 10:10:15 2023 +0200 Check number of arguments in pattern match commit25075ccaacAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Thu Apr 20 15:36:36 2023 +0200 added simple script for running benchmarks commit4bd5801c97Author: Rakarake <williambodin2001@gmail.com> Date: Tue Apr 18 15:52:33 2023 +0200 Removed traces commit2611ddc2b2Author: Rakarake <williambodin2001@gmail.com> Date: Tue Apr 18 15:48:25 2023 +0200 Fixed wrong handeling of EAdd in monomorphizer, as well as more documentation and cleanup commit7ab0e65981Author: sebastianselander <sebastian.selander@gmail.com> Date: Mon Apr 17 16:05:23 2023 +0200 removed minor thing in EAdd commita23269f907Author: Rakarake <williambodin2001@gmail.com> Date: Mon Apr 17 15:53:16 2023 +0200 Fixed small bug in monomorphizer commitc2bf6312f6Author: Rakarake <williambodin2001@gmail.com> Date: Wed Apr 12 16:36:22 2023 +0200 Monomorphizer now outputs constructors that are matched on but not created commit0ab13e5979Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Wed Apr 12 15:15:38 2023 +0200 Fixed the ordering of data types. commit2b7715714eAuthor: Martin Fredin <fredin.martin@gmail.com> Date: Tue Apr 11 18:56:53 2023 +0200 Use better names commit9730552eabAuthor: Martin Fredin <fredin.martin@gmail.com> Date: Tue Apr 11 13:46:54 2023 +0200 Remove parenthesis from EAnn commita109b3010dAuthor: Martin Fredin <fredin.martin@gmail.com> Date: Sat Apr 8 21:52:57 2023 +0200 Fix bad inference on case expression, and make pretty for report commit29de6c49e4Author: Martin Fredin <fredin.martin@gmail.com> Date: Sat Apr 8 13:39:00 2023 +0200 Fix naming commit9cb4a620bbAuthor: Martin Fredin <fredin.martin@gmail.com> Date: Sat Apr 8 13:38:30 2023 +0200 Fix redundant print paren commit21b1ba7b1fAuthor: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Fri Apr 7 16:01:23 2023 +0200 Replaced # with $ commit9c699ecb63Author: Rakarake <williambodin2001@gmail.com> Date: Thu Apr 6 14:29:30 2023 +0200 Fixed output of monomorphizer in main commit0d30cb80e0Author: sebastian <sebastian.selander@gmail.com> Date: Thu Apr 6 14:19:54 2023 +0200 removed pretty printing of tvars commite7cd3b2c3aAuthor: Rakarake <51128488+Rakarake@users.noreply.github.com> Date: Thu Apr 6 14:12:45 2023 +0200 Added README section about Nix commit90352449f4Author: sebastianselander <sebastian.selander@gmail.com> Date: Wed Apr 5 18:25:41 2023 +0200 added todo for semi monomorphization commit05ea23d22cAuthor: Martin Fredin <fredin.martin@gmail.com> Date: Wed Apr 5 17:41:17 2023 +0200 Fix test error message commit9870802371Author: Martin Fredin <fredin.martin@gmail.com> Date: Mon Apr 3 17:34:33 2023 +0200 Add implicit foralls for bidir, update and unify pipeline commit12bca1c32dAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Wed Apr 5 12:56:57 2023 +0200 Added small comment about incorrect subtyping commitc6e0e40ef1Author: Rakarake <williambodin2001@gmail.com> Date: Wed Apr 5 03:03:42 2023 +0200 Monomorphizer now monomorphizes data commit5e5d258bb1Author: Martin Fredin <fredin.martin@gmail.com> Date: Mon Apr 3 12:31:29 2023 +0200 Update readme with identation syntax commit077f76eb12Author: Martin Fredin <fredin.martin@gmail.com> Date: Mon Apr 3 12:24:22 2023 +0200 Separate make file actions commite5dc28b282Author: Martin Fredin <fredin.martin@gmail.com> Date: Mon Apr 3 12:11:21 2023 +0200 Add pdf of grammar commita1b1343d67Author: Martin Fredin <fredin.martin@gmail.com> Date: Mon Apr 3 12:04:52 2023 +0200 Add latex file commit03bb6a8534Author: Martin Fredin <fredin.martin@gmail.com> Date: Mon Apr 3 09:42:14 2023 +0200 Fix sample-program commitc998241c65Author: Martin Fredin <fredin.martin@gmail.com> Date: Mon Apr 3 09:39:24 2023 +0200 Fix tests commit0d6c5920a9Author: Martin Fredin <fredin.martin@gmail.com> Date: Mon Apr 3 09:24:27 2023 +0200 Fix type checker commitcc5755c3a9Author: Martin Fredin <fredin.martin@gmail.com> Date: Mon Apr 3 09:24:13 2023 +0200 Add layout grammar commitbd02f52795Author: sebastian <sebastian.selander@gmail.com> Date: Sun Apr 2 13:48:11 2023 +0200 Fixed structure a bit morer commitfaffb2744eAuthor: sebastian <sebastian.selander@gmail.com> Date: Sun Apr 2 13:47:35 2023 +0200 Fixed structure a bit more commit6a2ebf4ecdAuthor: sebastian <sebastian.selander@gmail.com> Date: Sun Apr 2 13:46:46 2023 +0200 Fixed structure a bit commit03a486410fAuthor: sebastian <sebastian.selander@gmail.com> Date: Sun Apr 2 13:42:47 2023 +0200 Added somewhat detailed README commitaaaff776e0Author: sebastian <sebastian.selander@gmail.com> Date: Sun Apr 2 00:42:42 2023 +0200 Add some boiler plate for warnings commit6c180554ecAuthor: sebastian <sebastian.selander@gmail.com> Date: Sun Apr 2 00:04:33 2023 +0200 Reworked order of inference, added prettifier for tvars etc etc. commitec8d554af1Author: sebastian <sebastian.selander@gmail.com> Date: Sat Apr 1 18:45:08 2023 +0200 Disabled shadowing in pattern match with nice error message, added aux functions commit4b14cbdebfAuthor: sebastian <sebastian.selander@gmail.com> Date: Sat Apr 1 17:10:26 2023 +0200 reverted Hindley-Milner type checker to before mutual recursion merge commitec57712eecAuthor: Rakarake <williambodin2001@gmail.com> Date: Fri Mar 31 19:43:05 2023 +0200 Fixed bad names after monomorphizer commitc6173c0077Author: Rakarake <williambodin2001@gmail.com> Date: Fri Mar 31 19:25:48 2023 +0200 Plus now working in monomorphizer commitb8f717f39fMerge:0749ca000e23a1Author: Rakarake <williambodin2001@gmail.com> Date: Fri Mar 31 18:59:05 2023 +0200 Merge branch 'monomorphizer-data' into pattern-matching-with-typechecking commit00e23a16ddAuthor: Rakarake <williambodin2001@gmail.com> Date: Fri Mar 31 18:58:33 2023 +0200 Monomorphization of datatypes done! commit0749ca062dAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Fri Mar 31 18:28:04 2023 +0200 Merge in mutual recursion handling commitb7420b5adbAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Fri Mar 31 18:27:30 2023 +0200 Merge in mutual recursion handling commitc4f78ca37dAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Fri Mar 31 18:26:58 2023 +0200 Merge in mutual recursion handling commite2e469d84eAuthor: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Fri Mar 31 18:17:28 2023 +0200 Added some examples that were shown to our handledare. commitb0ec5a2333Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Fri Mar 31 18:16:26 2023 +0200 Started working on a Case Desugar phase. commit15c18271baAuthor: Rakarake <williambodin2001@gmail.com> Date: Fri Mar 31 17:53:56 2023 +0200 Monomorphizer, fixed problem with type of bind commitd097cd28e8Author: Rakarake <williambodin2001@gmail.com> Date: Fri Mar 31 17:02:54 2023 +0200 New morb tree for internal use in monomorphizer, data types implemented commit7d2a0e60d8Author: Martin Fredin <fredin.martin@gmail.com> Date: Thu Mar 30 19:07:12 2023 +0200 Fixes commit72352d9619Author: Martin Fredin <fredin.martin@gmail.com> Date: Thu Mar 30 18:46:37 2023 +0200 Use use tevars for bind without type signatures, fix recursive functions commit4831205e67Author: Martin Fredin <fredin.martin@gmail.com> Date: Thu Mar 30 12:49:27 2023 +0200 Remove incorrect test commit5d2c0e787eAuthor: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Thu Mar 30 15:08:40 2023 +0200 The compiler is now compiled with O3. commit9b38c6d804Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Thu Mar 30 12:37:24 2023 +0200 Main now prints the exit code of the program, as Haskell likes to hide segfaults. commitb3525db7fdAuthor: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Thu Mar 30 12:31:03 2023 +0200 Integrated the garbage collector. commitbbe0d77a19Author: Martin Fredin <fredin.martin@gmail.com> Date: Thu Mar 30 12:35:47 2023 +0200 Add signature of inferred bind to allow some mutually defined definitions commita37a52d9f8Author: Martin Fredin <fredin.martin@gmail.com> Date: Thu Mar 30 11:49:13 2023 +0200 Apply env to return type. fixes #14 commit2851c408d1Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Thu Mar 30 11:41:10 2023 +0200 Added the updated GC. commitc4477d3df4Author: sebastianselander <sebastian.selander@gmail.com> Date: Thu Mar 30 11:38:06 2023 +0200 moved some funcs to aux, added a universal definition of int and char, updated usages in both tcs commit59676605cdAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Thu Mar 30 10:55:01 2023 +0200 moved injections back to state commitc34041860dAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Thu Mar 30 10:21:04 2023 +0200 duplicate signatures / declarations correct commitc4931c3996Author: sebastian <sebastian.selander@gmail.com> Date: Wed Mar 29 22:59:21 2023 +0200 Fixed bug in EApp, cleaned a bit, added todo for disallowing mutual recursion commitaa1ff630a5Author: Martin Fredin <fredin.martin@gmail.com> Date: Wed Mar 29 22:48:26 2023 +0200 Fix double vars commit343be08a4aAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Wed Mar 29 18:47:14 2023 +0200 Tried solving bug, failed, added todo message, fixed printing commit61f364cd75Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Wed Mar 29 17:34:47 2023 +0200 Splat up the codegenerator a bit. commit36b6a8f781Author: sebastianselander <sebastian.selander@gmail.com> Date: Wed Mar 29 17:32:21 2023 +0200 removed trace commit4efe7cf9a2Author: sebastianselander <sebastian.selander@gmail.com> Date: Wed Mar 29 17:30:31 2023 +0200 inference does not depend on order. mutual recursion still not working correctly commit29fcddf44cAuthor: Rakarake <williambodin2001@gmail.com> Date: Wed Mar 29 17:05:56 2023 +0200 Data defs in monomorphizer output environment commit53589e8d50Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Wed Mar 29 16:54:30 2023 +0200 Made the output from running the compiler a bit clearer. commitd26bde6a7fAuthor: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Wed Mar 29 16:47:52 2023 +0200 Added a fun Maybe example! commitd4115fd2f5Author: Rakarake <williambodin2001@gmail.com> Date: Wed Mar 29 16:45:30 2023 +0200 Monomoprhizer handles new types commitc59cd02361Author: Martin Fredin <fredin.martin@gmail.com> Date: Wed Mar 29 16:37:52 2023 +0200 Lift lambdas in the scrutinized expression commit2f12fdd7e2Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Wed Mar 29 15:29:53 2023 +0200 Removed a trace. commitf69151a7ceAuthor: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Wed Mar 29 15:12:33 2023 +0200 Fixed a bug with pattern matching on literals. commit82f1b38f1bAuthor: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Wed Mar 29 14:41:52 2023 +0200 Removed the Tjabatjena comment that the compiler generated. commit100b7b113aAuthor: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Wed Mar 29 14:31:24 2023 +0200 We got pattern matching on data types! commit2860d47f11Author: Rakarake <williambodin2001@gmail.com> Date: Wed Mar 29 13:48:00 2023 +0200 Case expressions implemented in monomorphizer commit4755f434fdAuthor: Martin Fredin <fredin.martin@gmail.com> Date: Wed Mar 29 11:25:45 2023 +0200 Add test for pattern matching on recursive data types, and remove traces commit52db1943bbAuthor: Martin Fredin <fredin.martin@gmail.com> Date: Wed Mar 29 11:12:33 2023 +0200 Finished new check pattern commit76b1c55065Author: Martin Fredin <fredin.martin@gmail.com> Date: Tue Mar 28 15:33:03 2023 +0200 Progress commit133cc31e77Author: Martin Fredin <fredin.martin@gmail.com> Date: Tue Mar 28 14:36:43 2023 +0200 Fix lambda lifter commit528369c95cAuthor: Martin Fredin <fredin.martin@gmail.com> Date: Mon Mar 27 23:55:04 2023 +0200 Progress on new checkPattern commitf20b80cab3Author: sebastian <sebastian.selander@gmail.com> Date: Tue Mar 28 23:19:04 2023 +0200 added skomeliation on given type signatures commit7c5041d270Author: sebastian <sebastian.selander@gmail.com> Date: Tue Mar 28 21:52:09 2023 +0200 added this stupid complex bug to Bugs.md commit9e6fe454ceAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Tue Mar 28 17:57:44 2023 +0200 reverted back to most close to correct version commitd8a75d6643Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Tue Mar 28 17:49:47 2023 +0200 Solved 30+ WARNINGS!! 😎 commitc77139dfa8Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Tue Mar 28 17:47:43 2023 +0200 Added a Malloc instruction. commit230a205965Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Tue Mar 28 17:37:29 2023 +0200 Fixed wrongly typed functions in the code generator. commite87e2d3870Author: sebastianselander <sebastian.selander@gmail.com> Date: Tue Mar 28 17:33:14 2023 +0200 sneaky buggy fixy commit8910d8adc0Author: sebastianselander <sebastian.selander@gmail.com> Date: Tue Mar 28 17:13:51 2023 +0200 temporary commit incase of breakage commit91d6332dc5Author: Rakarake <williambodin2001@gmail.com> Date: Tue Mar 28 17:14:55 2023 +0200 Fixed removed args in tree after monomorphizer commit92a2ff3235Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Tue Mar 28 17:13:38 2023 +0200 Fixed a broken path. commit4809cad1cbAuthor: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Tue Mar 28 16:54:11 2023 +0200 Fixed chars. commitba832ba288Author: sebastianselander <sebastian.selander@gmail.com> Date: Tue Mar 28 16:07:39 2023 +0200 added printTree for monomorphizer commitcf12c3443dAuthor: Rakarake <williambodin2001@gmail.com> Date: Tue Mar 28 15:57:35 2023 +0200 Main had a weird look commita7401f0ee3Author: Rakarake <williambodin2001@gmail.com> Date: Tue Mar 28 15:55:06 2023 +0200 Monomorphizer main fix commit43a863c153Author: sebastianselander <sebastian.selander@gmail.com> Date: Tue Mar 28 15:44:03 2023 +0200 fixed coerce type error commitcca2f853eaAuthor: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Tue Mar 28 15:36:08 2023 +0200 Added a variable lookup. commit5a70286802Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Tue Mar 28 15:35:34 2023 +0200 Added a files back. commit7f0dab6dcbAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Tue Mar 28 15:35:48 2023 +0200 adapted changes to work commit59d9be87cbAuthor: Martin Fredin <fredin.martin@gmail.com> Date: Tue Mar 28 15:35:01 2023 +0200 Add cases for lambda lifter commit5986e2108eAuthor: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Tue Mar 28 15:32:54 2023 +0200 Added c output files to the gitignore commitb35c19572fMerge:b1d3e314a6c72fAuthor: Rakarake <williambodin2001@gmail.com> Date: Tue Mar 28 15:26:35 2023 +0200 Newer changes commitb1d3e31efdAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Tue Mar 28 14:31:20 2023 +0200 Fixed previously incorrect type equality check, commented code, add test commit85f31b129bAuthor: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Tue Mar 28 14:15:22 2023 +0200 Yoinked over the garbage collector. commit2aff7a7743Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Tue Mar 28 13:50:19 2023 +0200 Fixed argumentless constructors being treated as variables. commitd7549d421cAuthor: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Tue Mar 28 13:49:34 2023 +0200 Fixed a missing dependency. commit66e419efa6Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Tue Mar 28 11:53:25 2023 +0200 Fixed the unnamed temporary bugs. commit58fe92affeAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Tue Mar 28 10:50:45 2023 +0200 Revert "restructured layout of code a bit" This reverts commit0639489d28. commit0639489d28Author: sebastianselander <sebastian.selander@gmail.com> Date: Tue Mar 28 10:50:05 2023 +0200 restructured layout of code a bit commit1558c98d10Author: sebastianselander <sebastian.selander@gmail.com> Date: Tue Mar 28 10:46:04 2023 +0200 improved the idea of error messages, still not very clean commit54f7d54bf9Author: sebastianselander <sebastian.selander@gmail.com> Date: Tue Mar 28 10:10:26 2023 +0200 fixed EAdd conversion bug in RemoveTEVars commit437c193ea8Author: sebastianselander <sebastian.selander@gmail.com> Date: Tue Mar 28 10:07:30 2023 +0200 fixed EAnn commit4d3d90c6a3Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Tue Mar 28 09:48:27 2023 +0200 Added some debug options to the just file. commit0d2fe862e0Author: sebastian <sebastian.selander@gmail.com> Date: Mon Mar 27 23:05:40 2023 +0200 fixed bug and additional test commit4b24755b93Author: sebastian <sebastian.selander@gmail.com> Date: Mon Mar 27 22:38:39 2023 +0200 cleaned up implementations and added check for duplicate constructors commite1633ea147Author: sebastian <sebastian.selander@gmail.com> Date: Mon Mar 27 21:16:48 2023 +0200 small fixed and added qualifiedDo commita38e96a83bAuthor: Martin Fredin <fredin.martin@gmail.com> Date: Mon Mar 27 20:51:00 2023 +0200 Fix Ident print instance commitad2bd645d9Author: sebastian <sebastian.selander@gmail.com> Date: Mon Mar 27 20:33:11 2023 +0200 tests are running now commit4a6c72fce0Author: Rakarake <williambodin2001@gmail.com> Date: Mon Mar 27 20:11:49 2023 +0200 Removed codegen to compile, type seem to work for newly added example commit0d23a59f0cMerge:2137414bef7821Author: Rakarake <williambodin2001@gmail.com> Date: Mon Mar 27 19:14:35 2023 +0200 Merged into commit not compiling on codegen 😤 commit506d8733d9Author: sebastianselander <sebastian.selander@gmail.com> Date: Mon Mar 27 16:54:10 2023 +0200 added old tests, still broken commit2adc3dceeeAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Mon Mar 27 16:53:29 2023 +0200 added old tests commitd5ce73beaeAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Mon Mar 27 16:52:22 2023 +0200 hm is compatible commit6e54378327Author: sebastianselander <sebastian.selander@gmail.com> Date: Mon Mar 27 16:48:23 2023 +0200 Fixed errors in tc hm commit847ec37117Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Mon Mar 27 16:32:48 2023 +0200 Fixed the dependency on the Grammar Ident. commit750503063aAuthor: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Mon Mar 27 16:31:47 2023 +0200 Fixed the dependency on the Grammar Ident. commit72f4f26078Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Mon Mar 27 16:31:30 2023 +0200 Fixed the dependency on the Grammar Ident. commitdb2f8cd197Author: Martin Fredin <fredin.martin@gmail.com> Date: Mon Mar 27 16:21:01 2023 +0200 Fix Codegen commit22783cf817Author: sebastianselander <sebastian.selander@gmail.com> Date: Mon Mar 27 16:14:40 2023 +0200 Removed custom Character in favor of BNFC Char commitb7be75aa1eAuthor: Martin Fredin <fredin.martin@gmail.com> Date: Mon Mar 27 16:14:14 2023 +0200 Fix TypeCheckerIr commit623c6d1e58Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Mon Mar 27 16:11:33 2023 +0200 Fixed language.cabal. commitaab75a10f2Author: sebastianselander <sebastian.selander@gmail.com> Date: Mon Mar 27 16:10:13 2023 +0200 fixed justfile commit45527abd50Author: Martin Fredin <fredin.martin@gmail.com> Date: Mon Mar 27 16:10:02 2023 +0200 Fix module name commitac3f222753Author: Martin Fredin <fredin.martin@gmail.com> Date: Sat Feb 18 14:49:33 2023 +0100 Add bidirectional type checker, lambda lifter. commit2fa30faa87Author: sebastianselander <sebastian.selander@gmail.com> Date: Mon Mar 27 15:37:58 2023 +0200 renamed stuff commitaa4a615c28Author: sebastianselander <sebastian.selander@gmail.com> Date: Mon Mar 27 14:44:21 2023 +0200 fixed one bug commitbd3cf3c3f1Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Mon Mar 27 13:40:18 2023 +0200 Fixed simple pattern matching. commit582747a997Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Mon Mar 27 10:07:04 2023 +0200 The created binary is now saved in the output folder. commit5062356cefAuthor: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Mon Mar 27 10:05:39 2023 +0200 Fixed broken padding on datatypes. commit91cfb21a35Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Sun Mar 26 22:21:44 2023 +0200 Almost got a lot of bugs fixed. commit9952eb0279Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Sun Mar 26 21:10:20 2023 +0200 Fixed the printing of TypeCheckerIr commitc37db41431Author: sebastian <sebastian.selander@gmail.com> Date: Sun Mar 26 18:52:25 2023 +0200 fixed bug commitccfae19541Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Sun Mar 26 18:38:07 2023 +0200 Added .crf to every sample-program commit9ea3a3dc56Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Sun Mar 26 18:37:55 2023 +0200 Added another bug. commitebac869761Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Sun Mar 26 18:24:12 2023 +0200 Fixed a type error in teh codegen. commit4e92f86d60Author: sebastian <sebastian.selander@gmail.com> Date: Sun Mar 26 16:57:34 2023 +0200 added test for bug. experimented with solutions, none found commit2af7855a77Author: sebastian <sebastian.selander@gmail.com> Date: Sun Mar 26 14:12:09 2023 +0200 documented 3 bugs commit213741407bAuthor: sebastian <sebastian.selander@gmail.com> Date: Sun Mar 26 00:41:26 2023 +0100 small add to Justfile commit2974c10c0cAuthor: sebastian <sebastian.selander@gmail.com> Date: Sun Mar 26 00:13:10 2023 +0100 moved tests commitd49e2401bfAuthor: sebastian <sebastian.selander@gmail.com> Date: Sun Mar 26 00:09:47 2023 +0100 added file suffix and check commitac43af8110Author: sebastian <sebastian.selander@gmail.com> Date: Sat Mar 25 22:40:15 2023 +0100 fixed a substitution bug where `ap` was incorrectly inferred. also added cleaner fresh variables commit975dd34063Author: sebastian <sebastian.selander@gmail.com> Date: Sat Mar 25 20:43:19 2023 +0100 Better inference & stuff on pattern matches, added more tests for regression commit88eaa466e4Author: sebastian <sebastian.selander@gmail.com> Date: Sat Mar 25 19:17:46 2023 +0100 Nested pattern matching should work correctly, added more tests commit3082444347Author: sebastian <sebastian.selander@gmail.com> Date: Sat Mar 25 18:42:11 2023 +0100 fixed bugs potentially. tests are working atleast commit368413515bAuthor: sebastian <sebastian.selander@gmail.com> Date: Sat Mar 25 12:04:00 2023 +0100 found incorrectly accepted program. added test commit05333c5689Author: sebastian <sebastian.selander@gmail.com> Date: Sat Mar 25 00:02:38 2023 +0100 started on cleaner unit tests commitaccbd4eea6Author: sebastian <sebastian.selander@gmail.com> Date: Fri Mar 24 22:03:43 2023 +0100 dummy monomorphizer complete commit7e246a94e5Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Fri Mar 24 19:57:49 2023 +0100 Fixed a segfault. commitf531afb3abAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Fri Mar 24 19:04:29 2023 +0100 added comment when codegen ok commit2566c53f58Author: sebastianselander <sebastian.selander@gmail.com> Date: Fri Mar 24 19:01:33 2023 +0100 mono adapt commit3e31fe0ea5Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Fri Mar 24 18:52:12 2023 +0100 The compiler now also runs the outputed program. commitb08ae7aef1Author: sebastianselander <sebastian.selander@gmail.com> Date: Fri Mar 24 18:48:40 2023 +0100 rewrote unification for data type and variable. could definitely be wrong. have to double check commite500c70529Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Fri Mar 24 18:46:12 2023 +0100 Programs are now actually compiled all the way through. commite0c78f5783Author: sebastianselander <sebastian.selander@gmail.com> Date: Fri Mar 24 18:32:33 2023 +0100 debug for parse tree commitb4cae11c0dAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Fri Mar 24 18:26:59 2023 +0100 added debug info commit23c174607bAuthor: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Fri Mar 24 18:22:37 2023 +0100 temp merge commit56ccd793acAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Fri Mar 24 18:21:07 2023 +0100 more error messages and better unification commit867485be12Author: sebastianselander <sebastian.selander@gmail.com> Date: Fri Mar 24 17:40:57 2023 +0100 removed trace commit41fc863658Author: sebastianselander <sebastian.selander@gmail.com> Date: Fri Mar 24 17:39:10 2023 +0100 added PEnum commitd6d0fb7146Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Fri Mar 24 17:29:00 2023 +0100 Enabled compiling to llvm again. commitb1209b3353Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Fri Mar 24 17:13:56 2023 +0100 Updated the monomorphizer to the new tree. commit3c2cb1a713Author: sebastianselander <sebastian.selander@gmail.com> Date: Fri Mar 24 17:06:32 2023 +0100 new good version works commitf404acdbadAuthor: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Fri Mar 24 17:00:31 2023 +0100 Updated some more changes. commit481667f2d8Author: sebastianselander <sebastian.selander@gmail.com> Date: Fri Mar 24 16:10:46 2023 +0100 added tc as well commit38680a4dcbAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Fri Mar 24 16:10:25 2023 +0100 adapted new tree to fuck with samuel commit50bea83a18Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Fri Mar 24 13:55:06 2023 +0100 Got some more stuff working. commitf4163bbb7dAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Fri Mar 24 14:56:33 2023 +0100 formatting commitce3971cf75Author: sebastianselander <sebastian.selander@gmail.com> Date: Fri Mar 24 12:21:54 2023 +0100 renamed stuff commit3f618e77f9Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Fri Mar 24 11:55:05 2023 +0100 Got most of the codegenerator working. commit32f8a3e8a9Author: sebastianselander <sebastian.selander@gmail.com> Date: Fri Mar 24 11:27:19 2023 +0100 duplicate signatures disallowed commitaa73f147f0Author: sebastianselander <sebastian.selander@gmail.com> Date: Fri Mar 24 11:21:46 2023 +0100 Remade lets with bind & improvements commit3371c3a146Author: sebastianselander <sebastian.selander@gmail.com> Date: Fri Mar 24 11:21:25 2023 +0100 Remade lets with bind & improvements commit30a79f34afAuthor: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Fri Mar 24 10:57:21 2023 +0100 Added some missing functionality to the dummy monomorphizer. commitbef7821756Author: Rakarake <williambodin2001@gmail.com> Date: Fri Mar 24 00:55:05 2023 +0100 ReaderT rewrite, recursive and cyclic calls should work commitfc60112877Author: sebastian <sebastian.selander@gmail.com> Date: Thu Mar 23 22:07:55 2023 +0100 Made binds keep args instead of lambda converting commit0012efabb7Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Thu Mar 23 22:01:40 2023 +0100 Fixed some more stuff. commit75fa232e21Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Thu Mar 23 21:35:52 2023 +0100 No more warnings, but everything to do with datatypes is outcommented. commit6cbc83c5d9Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Thu Mar 23 20:22:36 2023 +0100 Fixed a miss. commitc85010a8a1Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Thu Mar 23 20:20:17 2023 +0100 Fixed ExpT commitc6e8305215Author: sebastianselander <sebastian.selander@gmail.com> Date: Thu Mar 23 18:15:25 2023 +0100 created dummy monomorphizer commitc19f821892Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Thu Mar 23 17:54:41 2023 +0100 Switched around EId. commite283e83486Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Thu Mar 23 17:49:37 2023 +0100 Fixed some reexports. commite3df4192bbAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Thu Mar 23 17:20:19 2023 +0100 created dummy monomorphizer commit42c8ebc7b6Author: sebastianselander <sebastian.selander@gmail.com> Date: Thu Mar 23 16:49:49 2023 +0100 Making progress towards finished product commitd3d173eb59Merge:bf0064d519ed8aAuthor: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Thu Mar 23 16:33:05 2023 +0100 Merge remote-tracking branch 'origin/typechecking-merge' into pattern-matching-with-typechecking commitbf0064db86Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Thu Mar 23 16:13:59 2023 +0100 Added the trait ToIr. commit519ed8af6cAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Thu Mar 23 16:06:09 2023 +0100 Added monadic fail to renamer commit129a70e051Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Thu Mar 23 15:29:25 2023 +0100 WIP Added support for more types of cases. commit7fa677e3d3Author: sebastianselander <sebastian.selander@gmail.com> Date: Thu Mar 23 14:18:23 2023 +0100 typechecker working, still unsure of quality commit8d1330ad42Author: sebastianselander <sebastian.selander@gmail.com> Date: Thu Mar 23 11:13:48 2023 +0100 typechecker is compatible with one extra addition to the spec commit3335ab7a57Author: sebastian <sebastian.selander@gmail.com> Date: Wed Mar 22 21:26:14 2023 +0100 compatible, EId rule for parsing is not working, testing not done yet commit914855e20fAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Wed Mar 22 17:52:39 2023 +0100 working on adapting the typechecker commit936cb1301fAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Wed Mar 22 12:45:51 2023 +0100 new grammar and adapted renamer commitcd85297b85Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Wed Mar 22 11:48:40 2023 +0100 Removed the ear operator. commit61c844a255Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Wed Mar 22 11:46:07 2023 +0100 Revamped getNewVar commitfeeef18cfdAuthor: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Wed Mar 22 11:41:02 2023 +0100 Started implementing pattern matching on data types. commit88a4a934b8Author: sebastianselander <sebastian.selander@gmail.com> Date: Wed Mar 22 10:32:22 2023 +0100 added more manual tests commitd36370329eAuthor: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Wed Mar 22 10:24:00 2023 +0100 Realized that getelementptr might be doing to right thing, and that the uninitialized data comes from padding. commit24007313cbAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Wed Mar 22 10:10:11 2023 +0100 added shadowing for ECase in Renamer commit33b69a1895Author: sebastian <sebastian.selander@gmail.com> Date: Tue Mar 21 22:07:21 2023 +0100 Improved formatting commit57fe8cd0a6Author: sebastian <sebastian.selander@gmail.com> Date: Tue Mar 21 22:02:28 2023 +0100 Fixed larger bug where pattern matching on `Just a` with type `Maybe b` could be used for any type. commit8f151b7531Author: Rakarake <williambodin2001@gmail.com> Date: Tue Mar 21 17:15:15 2023 +0100 Monomorphization of function applications should work commit509de4415eAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Tue Mar 21 17:09:03 2023 +0100 progress on fixing bugs commit71d07ebf0fAuthor: Rakarake <williambodin2001@gmail.com> Date: Tue Mar 21 15:59:47 2023 +0100 Fixed some internal errors commit3026a96eb7Author: sebastian <sebastian.selander@gmail.com> Date: Tue Mar 21 14:51:06 2023 +0100 added todo for class commit4c015a4aacAuthor: sebastian <sebastian.selander@gmail.com> Date: Tue Mar 21 14:33:18 2023 +0100 initial pattern matching implementation. should be somewhat correct commitae34c494f5Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Tue Mar 21 10:14:00 2023 +0100 Improved the visibility checkup a little bit. commit91816abfe6Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Tue Mar 21 10:11:02 2023 +0100 Constructors are now seen as global functions. commitbbf7a47e74Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Tue Mar 21 09:39:05 2023 +0100 Started updating the Code Generator to the new monomorphizer tree. commit9cd2cdb511Author: sebastianselander <sebastian.selander@gmail.com> Date: Mon Mar 20 17:40:09 2023 +0100 continued work on pattern matching v2 commitec95e0d9efAuthor: Rakarake <williambodin2001@gmail.com> Date: Sun Mar 12 17:53:46 2023 +0100 Monomorphizer cleanup commite2db863c3eAuthor: Rakarake <williambodin2001@gmail.com> Date: Fri Mar 10 17:24:03 2023 +0100 Fixed name clashes commit96c4a2bddfAuthor: Rakarake <williambodin2001@gmail.com> Date: Fri Mar 10 17:20:23 2023 +0100 Added test of multiple instanciations of same polymorphic function commitc3ea343d00Author: sebastianselander <sebastian.selander@gmail.com> Date: Fri Mar 10 16:54:29 2023 +0100 unified top level type with expression type commit224a165715Author: Rakarake <williambodin2001@gmail.com> Date: Thu Mar 9 18:52:35 2023 +0100 Unique names of new binds with different types commitf10919ac20Author: Rakarake <williambodin2001@gmail.com> Date: Thu Mar 9 18:32:00 2023 +0100 Better tests commit0e20670343Author: Rakarake <williambodin2001@gmail.com> Date: Wed Mar 8 17:52:41 2023 +0100 Added check for recursive calls commitd377ded7e1Author: Rakarake <williambodin2001@gmail.com> Date: Wed Mar 8 17:38:50 2023 +0100 Deleted bad sample programs, added polymorphic call in polymorphic function test commit62724964d7Author: sebastian <sebastian.selander@gmail.com> Date: Wed Mar 8 15:22:42 2023 +0100 fixed Maybe ('a -> 'a) bug. Pattern matching still wonky, will have to redo commit350cd3b0e9Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Wed Mar 8 11:01:07 2023 +0100 Started importing Sebastian's new typechecker. commitd5dd7896d8Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Wed Mar 8 10:35:07 2023 +0100 Moved modules into a proper folder structure. commitac0ac2dac7Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Wed Mar 8 10:27:39 2023 +0100 Removed a few imports. commit2af00da482Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Wed Mar 8 10:25:53 2023 +0100 Renamed the `compile` function to generate `code` commit832efbcdd8Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Wed Mar 8 10:24:52 2023 +0100 Gave the code generator a proper module name. commitbff75bb00bAuthor: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Wed Mar 8 10:22:21 2023 +0100 Switched an Int to Integer. commit63f9689f38Author: Rakarake <williambodin2001@gmail.com> Date: Tue Mar 7 18:49:21 2023 +0100 Simple polymorphic and monomorphic functions properly morphed in test demo. commit887c3b8391Author: Rakarake <williambodin2001@gmail.com> Date: Tue Mar 7 16:42:56 2023 +0100 Working on bugs commitfce54e7899Author: sebastianselander <sebastian.selander@gmail.com> Date: Mon Mar 6 16:41:59 2023 +0100 documented possible bad functions commiteef6fa7668Author: sebastianselander <sebastian.selander@gmail.com> Date: Mon Mar 6 16:25:03 2023 +0100 added new test and found another bug commit6947614fbaAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Mon Mar 6 13:04:07 2023 +0100 Updated bug list & started working on more tests commitf5b5f11903Author: sebastianselander <sebastian.selander@gmail.com> Date: Mon Mar 6 11:38:25 2023 +0100 fixed formatting commit9c2f52f8bbAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Mon Mar 6 11:27:17 2023 +0100 fixed bug where bound variable didn't exist in case commit8ca876a101Author: Rakarake <williambodin2001@gmail.com> Date: Mon Mar 6 10:47:52 2023 +0100 Most code written, no tests yet commit778fec3dc4Author: sebastianselander <sebastian.selander@gmail.com> Date: Sun Mar 5 14:34:39 2023 +0100 Implemented potential fix for one of the bugs commitfe63fa6215Author: sebastianselander <sebastian.selander@gmail.com> Date: Sun Mar 5 13:24:56 2023 +0100 Improved error message and created document for known bugs. commitfecb71bc07Author: sebastianselander <sebastian.selander@gmail.com> Date: Fri Mar 3 18:17:51 2023 +0100 Found a bug. commit03d7080396Author: sebastianselander <sebastian.selander@gmail.com> Date: Fri Mar 3 11:46:54 2023 +0100 pattern matching works? have to test more commit7656b46e3fAuthor: sebastian <sebastian.selander@gmail.com> Date: Thu Mar 2 22:07:38 2023 +0100 a bit more work on pattern match + case expr commitdbc77ec5f3Author: Rakarake <williambodin2001@gmail.com> Date: Thu Mar 2 18:36:50 2023 +0100 Progress commit2401b6437bAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Thu Mar 2 16:05:43 2023 +0100 continued work pattern matching commit514d79bd6cAuthor: Rakarake <williambodin2001@gmail.com> Date: Wed Mar 1 13:50:01 2023 +0100 Strucute in place, MonomorpherIr module created commit05313652f9Author: sebastianselander <sebastian.selander@gmail.com> Date: Tue Feb 28 17:15:48 2023 +0100 unit tests, started on pattern matching commitd23d417ff3Author: Sebastian Selander <70573736+sebastianselander@users.noreply.github.com> Date: Mon Feb 27 19:38:45 2023 +0100 Update TypeChecker.hs commitbbf6e159c7Author: sebastianselander <sebastian.selander@gmail.com> Date: Mon Feb 27 17:22:42 2023 +0100 Type inference/checking on ADTs mostly complete(?). Still have to test commit2f45f39435Author: sebastianselander <sebastian.selander@gmail.com> Date: Mon Feb 27 11:12:05 2023 +0100 Incorporated most of main, as well as started on quickcheck commit7cf6f30835Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Fri Feb 24 18:37:31 2023 +0100 Data type constructors now properly tag the data. commit262543931cAuthor: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Fri Feb 24 16:05:49 2023 +0100 Types for data types are now created. commit272fbe3504Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Fri Feb 24 09:29:55 2023 +0100 Removed some unused code. commit5d004f4286Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Fri Feb 24 09:00:29 2023 +0100 Added calling conventions to functions. commit06e65de235Author: sebastianselander <sebastian.selander@gmail.com> Date: Thu Feb 23 11:54:35 2023 +0100 started on a test suite commit5daa5573f2Author: sebastianselander <sebastian.selander@gmail.com> Date: Wed Feb 22 15:24:38 2023 +0100 Added more comments to the code commit8065576c31Author: sebastianselander <sebastian.selander@gmail.com> Date: Mon Feb 20 20:38:36 2023 +0100 Let has a bug, otherwise probably(?) done commita98135827cAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Mon Feb 20 16:51:44 2023 +0100 EAdd is bugged. Mostly complete though. commit4df3f705edAuthor: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Mon Feb 20 16:44:27 2023 +0100 LLVMIr code now has the fastcc flag to enable speeed 😎 commitafbc700db2Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Mon Feb 20 16:43:54 2023 +0100 Fixed the type checker accidentally chucking cases in some cases. commitcd0f9dd456Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Mon Feb 20 15:27:13 2023 +0100 The output directory is now cleared when the program is ran. commita36de2bde1Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Mon Feb 20 14:52:11 2023 +0100 Added support for the minus operator. commitfe4533c7aeAuthor: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Mon Feb 20 14:39:56 2023 +0100 Added an option to output some debug info. commit6749650223Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Mon Feb 20 14:39:43 2023 +0100 Added support for pattern matching on ints. Might need a lookover. commit18e0a92fe0Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Mon Feb 20 14:39:00 2023 +0100 Added grammar for case matching. commitdfbdb6678eAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Mon Feb 20 12:09:31 2023 +0100 Working on non-ugly version of algorithm W (Hindley-Milner) commit420fb107f0Author: sebastianselander <sebastian.selander@gmail.com> Date: Sun Feb 19 15:25:49 2023 +0100 Commented code and fixed some bugs I think. Still not complete id : Int -> Int id x = x does not type check commitdb932048baAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Sun Feb 19 02:10:57 2023 +0100 Tried fixing bug. Failed. commit8b5cd3cf9aAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Sat Feb 18 23:08:27 2023 +0100 Remade the algorithm myself. Still some bugs. commita4c12ede79Merge:287f8434ab6681Author: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Sat Feb 18 15:03:11 2023 +0100 Merge branch 'prep-tc-martin' of github.com:bachelor-group-66-systemf/language into prep-tc-martin commit287f84377cAuthor: Samuel Hammersberg <samuel.hammersberg@gmail.com> Date: Sat Feb 18 14:36:46 2023 +0100 Implemented case matching on ints in the code generator commitf188cffb8dAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Fri Feb 17 18:42:50 2023 +0100 Unification part works (probably). Have a hard time understanding it. commit764faa582bAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Fri Feb 17 12:01:57 2023 +0100 Remove hls pragmas commitf2e8a02255Author: sebastianselander <sebastian.selander@gmail.com> Date: Fri Feb 17 12:01:22 2023 +0100 Removed adhoc tests commita9f54dbca1Author: sebastianselander <sebastian.selander@gmail.com> Date: Fri Feb 17 11:09:48 2023 +0100 Simplified quite a bit. Made a unify function. Still bugs left commiteafe0fea0bAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Thu Feb 16 16:37:36 2023 +0100 Rewrote using unification-fd. Heavily inspired (aka copied) from: https://byorgey.wordpress.com/2021/09/08/implementing-hindley-milner-with-the-unification-fd-library/ commitf1b77a7efaAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Wed Feb 15 19:52:52 2023 +0100 Refactored. Cleaner version, ala Martin version commitb03df17e34Author: sebastianselander <sebastian.selander@gmail.com> Date: Wed Feb 15 18:10:28 2023 +0100 Minor changes. Added a comment commit7619e36c60Author: sebastianselander <sebastian.selander@gmail.com> Date: Wed Feb 15 17:40:18 2023 +0100 Inference works better now. Still work to do. Should use proper library commitad3f6b7011Author: sebastianselander <sebastian.selander@gmail.com> Date: Tue Feb 14 22:35:00 2023 +0100 Attempt at fixing EApp, failed. commit5d247057f5Author: sebastianselander <sebastian.selander@gmail.com> Date: Tue Feb 14 22:03:56 2023 +0100 Minor rewrite of tc. Some bugs still left commit6218efac20Author: sebastianselander <sebastian.selander@gmail.com> Date: Tue Feb 14 16:44:38 2023 +0100 Renamer done. It renames bound variables to numbers, converts let to lambda, and removes all variables from binds commit53314551f5Author: sebastianselander <sebastian.selander@gmail.com> Date: Tue Feb 14 12:56:07 2023 +0100 A bit cleaner code. A renamer is the focus to make the tc simpler commit200a9e57edAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Tue Feb 14 10:12:38 2023 +0100 Fixed EId, more work on other expressions needed commitc10d7703adAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Mon Feb 13 19:03:06 2023 +0100 Progression on type checker ;) commit73dc2e4b6aAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Mon Feb 13 12:17:49 2023 +0100 Inference on most expressions. HM based. Still have to figure out how to infer type of lambda variables, as well as how function application on polymorphic should work commita1e9624d5eAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Fri Feb 10 12:09:08 2023 +0100 TTGing the lambda lifter commitf4f1786be3Author: sebastianselander <sebastian.selander@gmail.com> Date: Fri Feb 10 10:41:16 2023 +0100 Revert "Merge branch 'typechecking' into codegen-martin-3" This reverts commite000e5159f, reversing changes made to3ac8377fa0. commit771c73c0dbMerge:b6f03e9e000e51Author: Sebastian Selander <70573736+sebastianselander@users.noreply.github.com> Date: Fri Feb 10 10:33:50 2023 +0100 Merge pull request #5 from bachelor-group-66-systemf/codegen-martin-3 Codegen martin 3 commite000e5159fMerge:3ac8377b6f03e9Author: sebastianselander <sebastian.selander@gmail.com> Date: Fri Feb 10 10:33:15 2023 +0100 Merge branch 'typechecking' into codegen-martin-3 commit3ac8377fa0Author: Martin Fredin <fredin.martin@gmail.com> Date: Thu Feb 9 20:25:00 2023 +0100 Fix auxiliary path commit59fb773bc1Author: Martin Fredin <fredin.martin@gmail.com> Date: Thu Feb 9 20:24:25 2023 +0100 Some clean up and documenting commit07bec3e7efAuthor: Martin Fredin <fredin.martin@gmail.com> Date: Thu Feb 9 20:24:06 2023 +0100 Add auxiliary module commit7c313b3faaAuthor: Martin Fredin <fredin.martin@gmail.com> Date: Thu Feb 9 20:23:49 2023 +0100 Fix basic tests commit23261ec380Author: Martin Fredin <fredin.martin@gmail.com> Date: Thu Feb 9 20:23:20 2023 +0100 Add llvm dep commitce31e4d490Author: Martin Fredin <fredin.martin@gmail.com> Date: Thu Feb 9 17:53:39 2023 +0100 Fix first unnecessary supercombinator commitb6f03e953bAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Thu Feb 9 09:42:44 2023 +0100 deprecated branch commit7a2404cf74Author: Martin Fredin <fredin.martin@gmail.com> Date: Thu Feb 9 06:19:58 2023 +0100 Finish Lambda Lifter commit1f47288fcfAuthor: Martin Fredin <fredin.martin@gmail.com> Date: Thu Feb 9 05:19:51 2023 +0100 Implement lambda lifting passes: freeVars, abstract, and rename commitb669381572Author: Martin Fredin <fredin.martin@gmail.com> Date: Thu Feb 9 05:18:49 2023 +0100 Remove files from git commit84eb430c41Author: sebastianselander <sebastian.selander@gmail.com> Date: Fri Feb 3 11:29:42 2023 +0100 relaxed base dependency and added overwrite commit6607173b93Author: Patrik Jansson <patrik.ja@gmail.com> Date: Fri Feb 3 11:12:44 2023 +0100 Typo fix (to check access). commitbe3fcfc9e3Author: sebastianselander <sebastian.selander@gmail.com> Date: Tue Jan 24 16:39:22 2023 +0100 Typeinference/checking on expressions done. Simplified the typechecker a bit, removed GADT solution for now. Still not fully working commitb6b2dfa25fAuthor: sebastianselander <sebastian.selander@gmail.com> Date: Mon Jan 23 17:17:06 2023 +0100 Some work on a typechecker commit43e0f67fe2Author: Martin Fredin <fredin.martin@gmail.com> Date: Sun Jan 22 20:16:03 2023 +0100 Fix conflict
This commit is contained in:
parent
d115efe34b
commit
7663c7ad4e
65 changed files with 7018 additions and 1248 deletions
51
src/Codegen/Auxillary.hs
Normal file
51
src/Codegen/Auxillary.hs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
module Codegen.Auxillary where
|
||||
|
||||
import Codegen.LlvmIr (LLVMType (..), LLVMValue (..))
|
||||
import Control.Monad (foldM_)
|
||||
import Monomorphizer.MonomorphizerIr as MIR (ExpT, Type (..))
|
||||
import TypeChecker.TypeCheckerIr qualified as TIR
|
||||
|
||||
type2LlvmType :: MIR.Type -> LLVMType
|
||||
type2LlvmType (MIR.TLit id@(TIR.Ident name)) = case name of
|
||||
"Int" -> I64
|
||||
"Char" -> I8
|
||||
"Bool" -> I1
|
||||
_ -> CustomType id
|
||||
type2LlvmType (MIR.TFun t xs) = do
|
||||
let (t', xs') = function2LLVMType xs [type2LlvmType t]
|
||||
Function t' xs'
|
||||
where
|
||||
function2LLVMType :: Type -> [LLVMType] -> (LLVMType, [LLVMType])
|
||||
function2LLVMType (TFun t xs) s = function2LLVMType xs (type2LlvmType t : s)
|
||||
function2LLVMType x s = (type2LlvmType x, s)
|
||||
|
||||
getType :: ExpT -> LLVMType
|
||||
getType (_, t) = type2LlvmType t
|
||||
|
||||
extractTypeName :: MIR.Type -> TIR.Ident
|
||||
extractTypeName (MIR.TLit id) = id
|
||||
extractTypeName (MIR.TFun t xs) =
|
||||
let (TIR.Ident i) = extractTypeName t
|
||||
(TIR.Ident is) = extractTypeName xs
|
||||
in TIR.Ident $ i <> "_$_" <> is
|
||||
|
||||
valueGetType :: LLVMValue -> LLVMType
|
||||
valueGetType (VInteger _) = I64
|
||||
valueGetType (VChar _) = I8
|
||||
valueGetType (VIdent _ t) = t
|
||||
valueGetType (VConstant s) = Array (fromIntegral $ length s) I8
|
||||
valueGetType (VFunction _ _ t) = t
|
||||
|
||||
typeByteSize :: LLVMType -> Integer
|
||||
typeByteSize I1 = 1
|
||||
typeByteSize I8 = 1
|
||||
typeByteSize I32 = 4
|
||||
typeByteSize I64 = 8
|
||||
typeByteSize Ptr = 8
|
||||
typeByteSize (Ref _) = 8
|
||||
typeByteSize (Function _ _) = 8
|
||||
typeByteSize (Array n t) = n * typeByteSize t
|
||||
typeByteSize (CustomType _) = 8
|
||||
|
||||
enumerateOneM_ :: Monad m => (Integer -> a -> m b) -> [a] -> m ()
|
||||
enumerateOneM_ f = foldM_ (\i a -> f i a >> pure (i + 1)) 1
|
||||
35
src/Codegen/Codegen.hs
Normal file
35
src/Codegen/Codegen.hs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
module Codegen.Codegen (generateCode) where
|
||||
|
||||
import Codegen.CompilerState (
|
||||
CodeGenerator (instructions),
|
||||
initCodeGenerator,
|
||||
)
|
||||
import Codegen.Emits (compileScs)
|
||||
import Codegen.LlvmIr as LIR (llvmIrToString)
|
||||
import Control.Monad.State (
|
||||
execStateT,
|
||||
)
|
||||
import Data.List (sortBy)
|
||||
import Grammar.ErrM (Err)
|
||||
import Monomorphizer.MonomorphizerIr as MIR (Bind (..), Data (..), Def (DBind, DData), Program (..), Type (TLit))
|
||||
import TypeChecker.TypeCheckerIr (Ident (..))
|
||||
|
||||
{- | Compiles an AST and produces a LLVM Ir string.
|
||||
An easy way to actually "compile" this output is to
|
||||
Simply pipe it to LLI
|
||||
-}
|
||||
generateCode :: MIR.Program -> Bool -> Err String
|
||||
generateCode (MIR.Program scs) addGc = do
|
||||
let tree = filter (not . detectPrelude) (sortBy lowData scs)
|
||||
let codegen = initCodeGenerator addGc tree
|
||||
llvmIrToString . instructions <$> execStateT (compileScs tree) codegen
|
||||
|
||||
detectPrelude :: Def -> Bool
|
||||
detectPrelude (DData (Data (TLit (Ident "Bool")) _)) = True
|
||||
detectPrelude (DBind (Bind (Ident ('l' : 't' : '$' : _), _) _ _)) = True
|
||||
detectPrelude _ = False
|
||||
|
||||
lowData :: Def -> Def -> Ordering
|
||||
lowData (DData _) (DBind _) = LT
|
||||
lowData (DBind _) (DData _) = GT
|
||||
lowData _ _ = EQ
|
||||
147
src/Codegen/CompilerState.hs
Normal file
147
src/Codegen/CompilerState.hs
Normal file
|
|
@ -0,0 +1,147 @@
|
|||
module Codegen.CompilerState where
|
||||
|
||||
import Auxiliary (snoc)
|
||||
import Codegen.Auxillary (type2LlvmType, typeByteSize)
|
||||
import Codegen.LlvmIr as LIR (LLVMIr (UnsafeRaw),
|
||||
LLVMType)
|
||||
import Control.Monad.State (StateT, gets, modify)
|
||||
import Data.Map (Map)
|
||||
import qualified Data.Map as Map
|
||||
import Grammar.ErrM (Err)
|
||||
import Monomorphizer.MonomorphizerIr as MIR
|
||||
import qualified TypeChecker.TypeCheckerIr as TIR
|
||||
|
||||
-- | The record used as the code generator state
|
||||
data CodeGenerator = CodeGenerator
|
||||
{ instructions :: [LLVMIr]
|
||||
, functions :: Map MIR.Id FunctionInfo
|
||||
, customTypes :: Map LLVMType Integer
|
||||
, constructors :: Map TIR.Ident ConstructorInfo
|
||||
, variableCount :: Integer
|
||||
, labelCount :: Integer
|
||||
, gcEnabled :: Bool
|
||||
}
|
||||
|
||||
-- | A state type synonym
|
||||
type CompilerState a = StateT CodeGenerator Err a
|
||||
|
||||
data FunctionInfo = FunctionInfo
|
||||
{ numArgs :: Int
|
||||
, arguments :: [Id]
|
||||
}
|
||||
deriving (Show)
|
||||
data ConstructorInfo = ConstructorInfo
|
||||
{ numArgsCI :: Int
|
||||
, argumentsCI :: [Id]
|
||||
, numCI :: Integer
|
||||
, returnTypeCI :: MIR.Type
|
||||
}
|
||||
deriving (Show)
|
||||
|
||||
-- | Adds a instruction to the CodeGenerator state
|
||||
emit :: LLVMIr -> CompilerState ()
|
||||
emit l = modify $ \t -> t{instructions = Auxiliary.snoc l $ instructions t}
|
||||
|
||||
-- | Increases the variable counter in the CodeGenerator state
|
||||
increaseVarCount :: CompilerState ()
|
||||
increaseVarCount = modify $ \t -> t{variableCount = variableCount t + 1}
|
||||
|
||||
-- | Returns the variable count from the CodeGenerator state
|
||||
getVarCount :: CompilerState Integer
|
||||
getVarCount = gets variableCount
|
||||
|
||||
-- | Increases the variable count and returns it from the CodeGenerator state
|
||||
getNewVar :: CompilerState TIR.Ident
|
||||
getNewVar = TIR.Ident . show <$> (increaseVarCount >> getVarCount)
|
||||
|
||||
-- | Increses the label count and returns a label from the CodeGenerator state
|
||||
getNewLabel :: CompilerState Integer
|
||||
getNewLabel = do
|
||||
modify (\t -> t{labelCount = labelCount t + 1})
|
||||
gets labelCount
|
||||
|
||||
{- | Produces a map of functions infos from a list of binds,
|
||||
which contains useful data for code generation.
|
||||
-}
|
||||
getFunctions :: [MIR.Def] -> Map Id FunctionInfo
|
||||
getFunctions bs = Map.fromList $ go bs
|
||||
where
|
||||
go [] = []
|
||||
go (MIR.DBind (MIR.Bind id args _) : xs) =
|
||||
(id, FunctionInfo{numArgs = length args, arguments = args})
|
||||
: go xs
|
||||
go (_ : xs) = go xs
|
||||
|
||||
createArgs :: [MIR.Type] -> [Id]
|
||||
createArgs xs = fst $ foldl (\(acc, l) t -> (acc ++ [(TIR.Ident ("arg_" <> show l), t)], l + 1)) ([], 0) xs
|
||||
|
||||
{- | Produces a map of functions infos from a list of binds,
|
||||
which contains useful data for code generation.
|
||||
-}
|
||||
getConstructors :: [MIR.Def] -> Map TIR.Ident ConstructorInfo
|
||||
getConstructors bs = Map.fromList $ go bs
|
||||
where
|
||||
go [] = []
|
||||
go (MIR.DData (MIR.Data t cons) : xs) =
|
||||
fst
|
||||
( foldl
|
||||
( \(acc, i) (Inj id xs) ->
|
||||
( ( id
|
||||
, ConstructorInfo
|
||||
{ numArgsCI = length (init . flattenType $ xs)
|
||||
, argumentsCI = createArgs (init . flattenType $ xs)
|
||||
, numCI = i
|
||||
, returnTypeCI = t -- last . flattenType $ xs
|
||||
}
|
||||
)
|
||||
: acc
|
||||
, i + 1
|
||||
)
|
||||
)
|
||||
([], 0)
|
||||
cons
|
||||
)
|
||||
<> go xs
|
||||
go (_ : xs) = go xs
|
||||
|
||||
getTypes :: [MIR.Def] -> Map LLVMType Integer
|
||||
getTypes bs = Map.fromList $ go bs
|
||||
where
|
||||
go [] = []
|
||||
go (MIR.DData (MIR.Data t ts) : xs) = (type2LlvmType t, biggestVariant ts) : go xs
|
||||
go (_ : xs) = go xs
|
||||
variantTypes fi = init $ map type2LlvmType (flattenType fi)
|
||||
biggestVariant ts = 8 + maximum (sum . (\(Inj _ fi) -> typeByteSize <$> variantTypes fi) <$> ts)
|
||||
|
||||
initCodeGenerator :: Bool -> [MIR.Def] -> CodeGenerator
|
||||
initCodeGenerator addGc scs =
|
||||
CodeGenerator
|
||||
{ instructions = defaultStart <> if addGc then gcStart else []
|
||||
, functions = getFunctions scs
|
||||
, constructors = getConstructors scs
|
||||
, customTypes = getTypes scs
|
||||
, variableCount = 0
|
||||
, labelCount = 0
|
||||
, gcEnabled = addGc
|
||||
}
|
||||
|
||||
defaultStart :: [LLVMIr]
|
||||
defaultStart =
|
||||
[ UnsafeRaw "target triple = \"x86_64-pc-linux-gnu\"\n"
|
||||
, UnsafeRaw "target datalayout = \"e-m:o-i64:64-f80:128-n8:16:32:64-S128\"\n"
|
||||
, UnsafeRaw "@.str = private unnamed_addr constant [3 x i8] c\"%i\n\", align 1\n"
|
||||
, UnsafeRaw "@.non_exhaustive_patterns = private unnamed_addr constant [41 x i8] c\"Non-exhaustive patterns in case at %i:%i\n\"\n"
|
||||
, UnsafeRaw "declare i32 @printf(ptr noalias nocapture, ...)\n"
|
||||
, UnsafeRaw "declare i32 @exit(i32 noundef)\n"
|
||||
, UnsafeRaw "declare ptr @malloc(i32 noundef)\n"
|
||||
]
|
||||
|
||||
gcStart :: [LLVMIr]
|
||||
gcStart =
|
||||
[ UnsafeRaw "declare external void @cheap_init()\n"
|
||||
, UnsafeRaw "declare external ptr @cheap_alloc(i64)\n"
|
||||
, UnsafeRaw "declare external void @cheap_dispose()\n"
|
||||
, UnsafeRaw "declare external ptr @cheap_the()\n"
|
||||
, UnsafeRaw "declare external void @cheap_set_profiler(ptr, i1)\n"
|
||||
, UnsafeRaw "declare external void @cheap_profiler_log_options(ptr, i64)\n"
|
||||
]
|
||||
392
src/Codegen/Emits.hs
Normal file
392
src/Codegen/Emits.hs
Normal file
|
|
@ -0,0 +1,392 @@
|
|||
{-# LANGUAGE LambdaCase #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Codegen.Emits where
|
||||
|
||||
import Codegen.Auxillary
|
||||
import Codegen.CompilerState
|
||||
import Codegen.LlvmIr as LIR
|
||||
import Control.Applicative ((<|>))
|
||||
import Control.Monad (when)
|
||||
import Control.Monad.State (gets, modify)
|
||||
import Data.Bifunctor qualified as BI
|
||||
import Data.Char (ord)
|
||||
import Data.Coerce (coerce)
|
||||
import Data.Map qualified as Map
|
||||
import Data.Maybe (fromJust, fromMaybe, isNothing)
|
||||
import Data.Tuple.Extra (dupe, first, second)
|
||||
import Debug.Trace (trace, traceShow)
|
||||
import Grammar.Print
|
||||
import Monomorphizer.MonomorphizerIr as MIR
|
||||
import TypeChecker.TypeCheckerIr qualified as TIR
|
||||
|
||||
compileScs :: [MIR.Def] -> CompilerState ()
|
||||
compileScs [] = do
|
||||
emit $ UnsafeRaw "\n"
|
||||
-- as a last step create all the constructors
|
||||
-- //TODO maybe merge this with the data type match?
|
||||
c <- gets (Map.toList . constructors)
|
||||
mapM_
|
||||
( \(id, ci) -> do
|
||||
let t = returnTypeCI ci
|
||||
let t' = type2LlvmType t
|
||||
let x = BI.second type2LlvmType <$> argumentsCI ci
|
||||
emit $ Define FastCC t' id x
|
||||
top <- getNewVar
|
||||
ptr <- getNewVar
|
||||
-- allocated the primary type
|
||||
emit $ SetVariable top (Alloca t')
|
||||
|
||||
-- set the first byte to the index of the constructor
|
||||
emit $
|
||||
SetVariable ptr $
|
||||
GetElementPtr
|
||||
t'
|
||||
(Ref t')
|
||||
(VIdent top I8)
|
||||
I64
|
||||
(VInteger 0)
|
||||
I32
|
||||
(VInteger 0)
|
||||
emit $ Store I8 (VInteger $ numCI ci) (Ref I8) ptr
|
||||
|
||||
-- get a pointer of the correct type
|
||||
ptr' <- getNewVar
|
||||
emit $ SetVariable ptr' (Bitcast (Ref t') (VIdent top Ptr) (Ref $ CustomType id))
|
||||
cTypes <- gets customTypes
|
||||
|
||||
enumerateOneM_
|
||||
( \i (TIR.Ident arg_n, arg_t) -> do
|
||||
let arg_t' = type2LlvmType arg_t
|
||||
emit $ Comment (toIr arg_t' <> " " <> arg_n <> " " <> show i)
|
||||
elemPtr <- getNewVar
|
||||
emit $
|
||||
SetVariable
|
||||
elemPtr
|
||||
( GetElementPtr
|
||||
(CustomType id)
|
||||
(Ref (CustomType id))
|
||||
(VIdent ptr' Ptr)
|
||||
I64
|
||||
(VInteger 0)
|
||||
I32
|
||||
(VInteger i)
|
||||
)
|
||||
case Map.lookup arg_t' cTypes of
|
||||
Just s -> do
|
||||
emit $ Comment "Malloc and store"
|
||||
heapPtr <- getNewVar
|
||||
useGc <- gets gcEnabled
|
||||
emit $ SetVariable heapPtr (if useGc then GcMalloc s else Malloc s)
|
||||
emit $ Store arg_t' (VIdent (TIR.Ident arg_n) arg_t') Ptr heapPtr
|
||||
emit $ Store (Ref arg_t') (VIdent heapPtr arg_t') Ptr elemPtr
|
||||
Nothing -> do
|
||||
emit $ Comment "Just store"
|
||||
emit $ Store arg_t' (VIdent (TIR.Ident arg_n) arg_t') Ptr elemPtr
|
||||
)
|
||||
(argumentsCI ci)
|
||||
|
||||
-- load and return the constructed value
|
||||
emit $ Comment "Return the newly constructed value"
|
||||
load <- getNewVar
|
||||
emit $ SetVariable load (Load t' Ptr top)
|
||||
emit $ Ret t' (VIdent load t')
|
||||
emit DefineEnd
|
||||
emit $ UnsafeRaw "\n"
|
||||
|
||||
modify $ \s -> s{variableCount = 0}
|
||||
)
|
||||
c
|
||||
compileScs (MIR.DBind (MIR.Bind (name, t) args exp) : xs) = do
|
||||
let t_return = type2LlvmType . last . flattenType $ t
|
||||
emit $ UnsafeRaw "\n"
|
||||
emit . Comment $ show name <> ": " <> show exp
|
||||
let args' = map (second type2LlvmType) args
|
||||
emit $ Define FastCC t_return name args'
|
||||
useGc <- gets gcEnabled
|
||||
when (name == "main") (mapM_ emit (firstMainContent useGc))
|
||||
functionBody <- exprToValue exp
|
||||
if name == "main"
|
||||
then mapM_ emit $ lastMainContent useGc functionBody
|
||||
else emit $ Ret t_return functionBody
|
||||
emit DefineEnd
|
||||
modify $ \s -> s{variableCount = 0}
|
||||
compileScs xs
|
||||
compileScs (MIR.DData (MIR.Data typ ts) : xs) = do
|
||||
let (TIR.Ident outer_id) = extractTypeName typ
|
||||
-- //TODO this could be extracted from the customTypes map
|
||||
let variantTypes fi = init $ map type2LlvmType (flattenType fi)
|
||||
let biggestVariant = 7 + maximum (sum . (\(Inj _ fi) -> typeByteSize <$> variantTypes fi) <$> ts)
|
||||
emit $ LIR.Type (TIR.Ident outer_id) [I8, Array biggestVariant I8]
|
||||
typeSets <- gets customTypes
|
||||
mapM_
|
||||
( \(Inj inner_id fi) -> do
|
||||
let types = (\s -> if Map.member s typeSets then Ref s else s) <$> variantTypes fi
|
||||
emit $ LIR.Type inner_id (I8 : types)
|
||||
)
|
||||
ts
|
||||
compileScs xs
|
||||
|
||||
firstMainContent :: Bool -> [LLVMIr]
|
||||
firstMainContent True =
|
||||
[ UnsafeRaw "%prof = call ptr @cheap_the()\n"
|
||||
, UnsafeRaw "call void @cheap_set_profiler(ptr %prof, i1 true)\n"
|
||||
, UnsafeRaw "call void @cheap_profiler_log_options(ptr %prof, i64 30)\n"
|
||||
, UnsafeRaw "call void @cheap_init()\n"
|
||||
]
|
||||
firstMainContent False = []
|
||||
|
||||
lastMainContent :: Bool -> LLVMValue -> [LLVMIr]
|
||||
lastMainContent True var =
|
||||
[ UnsafeRaw $
|
||||
"call i32 (ptr, ...) @printf(ptr noundef @.str, i64 noundef " <> toIr var <> ")\n"
|
||||
, UnsafeRaw "call void @cheap_dispose()\n"
|
||||
, Ret I64 (VInteger 0)
|
||||
]
|
||||
lastMainContent False var =
|
||||
[ UnsafeRaw $
|
||||
"call i32 (ptr, ...) @printf(ptr noundef @.str, i64 noundef " <> toIr var <> ")\n"
|
||||
, Ret I64 (VInteger 0)
|
||||
]
|
||||
|
||||
compileExp :: ExpT -> CompilerState ()
|
||||
compileExp (MIR.ELit lit, _t) = emitLit lit
|
||||
compileExp (MIR.EAdd e1 e2, t) = emitAdd t e1 e2
|
||||
compileExp (MIR.EVar name, _t) = emitIdent name
|
||||
compileExp (MIR.EApp e1 e2, t) = emitApp t e1 e2
|
||||
compileExp (MIR.ELet bind e, _) = emitLet bind e
|
||||
compileExp (MIR.ECase e cs, t) = emitECased t e (map (t,) cs)
|
||||
|
||||
emitLet :: MIR.Bind -> ExpT -> CompilerState ()
|
||||
emitLet (MIR.Bind id [] innerExp) e = do
|
||||
evaled <- exprToValue innerExp
|
||||
tempVar <- getNewVar
|
||||
let t = type2LlvmType . snd $ innerExp
|
||||
emit $ SetVariable tempVar (Alloca t)
|
||||
emit $ Store (type2LlvmType . snd $ innerExp) evaled Ptr tempVar
|
||||
emit $ SetVariable (fst id) (Load t Ptr tempVar)
|
||||
compileExp e
|
||||
emitLet b _ = error $ "Non empty argument list in let-bind " <> show b
|
||||
|
||||
emitECased :: MIR.Type -> ExpT -> [(MIR.Type, Branch)] -> CompilerState ()
|
||||
emitECased t e cases = do
|
||||
let cs = snd <$> cases
|
||||
let ty = type2LlvmType t
|
||||
let rt = type2LlvmType (snd e)
|
||||
vs <- exprToValue e
|
||||
lbl <- getNewLabel
|
||||
let label = TIR.Ident $ "escape_" <> show lbl
|
||||
stackPtr <- getNewVar
|
||||
emit $ SetVariable stackPtr (Alloca ty)
|
||||
mapM_ (emitCases rt ty label stackPtr vs) cs
|
||||
-- crashLbl <- TIR.Ident . ("crash_" <>) . show <$> getNewLabel
|
||||
-- emit $ Label crashLbl
|
||||
var_num <- getVarCount
|
||||
emit . UnsafeRaw $ "call i32 (ptr, ...) @printf(ptr noundef @.non_exhaustive_patterns, i64 noundef " <> show var_num <> ", i64 noundef 6)\n"
|
||||
useGc <- gets gcEnabled
|
||||
when useGc (emit . UnsafeRaw $ "call void @cheap_dispose()\n")
|
||||
emit . UnsafeRaw $ "call i32 @exit(i32 noundef 1)\n"
|
||||
mapM_ (const increaseVarCount) [0 .. 1]
|
||||
emit $ Br label
|
||||
emit $ Label label
|
||||
res <- getNewVar
|
||||
emit $ SetVariable res (Load ty Ptr stackPtr)
|
||||
where
|
||||
emitCases :: LLVMType -> LLVMType -> TIR.Ident -> TIR.Ident -> LLVMValue -> Branch -> CompilerState ()
|
||||
emitCases rt ty label stackPtr vs (Branch (MIR.PInj consId cs, _t) exp) = do
|
||||
emit $ Comment "Inj"
|
||||
cons <- gets constructors
|
||||
let r = fromJust $ Map.lookup consId cons
|
||||
|
||||
lbl_failPos <- (\x -> TIR.Ident $ "failed_" <> show x) <$> getNewLabel
|
||||
lbl_succPos <- (\x -> TIR.Ident $ "success_" <> show x) <$> getNewLabel
|
||||
|
||||
consVal <- getNewVar
|
||||
emit $ SetVariable consVal (ExtractValue rt vs 0)
|
||||
|
||||
consCheck <- getNewVar
|
||||
emit $ SetVariable consCheck (Icmp LLEq I8 (VIdent consVal I8) (VInteger $ numCI r))
|
||||
emit $ BrCond (VIdent consCheck ty) lbl_succPos lbl_failPos
|
||||
emit $ Label lbl_succPos
|
||||
|
||||
castPtr <- getNewVar
|
||||
casted <- getNewVar
|
||||
emit $ SetVariable castPtr (Alloca rt)
|
||||
emit $ Store rt vs Ptr castPtr
|
||||
emit $ SetVariable casted (Load (CustomType (coerce consId)) Ptr castPtr)
|
||||
enumerateOneM_
|
||||
( \i c -> do
|
||||
case c of
|
||||
PVar (x, topT) -> do
|
||||
let topT' = type2LlvmType topT
|
||||
let botT' = CustomType (coerce consId)
|
||||
emit . Comment $ "ident " <> toIr topT'
|
||||
cTypes <- gets customTypes
|
||||
if Map.member topT' cTypes
|
||||
then do
|
||||
deref <- getNewVar
|
||||
emit $ SetVariable deref (ExtractValue botT' (VIdent casted Ptr) i)
|
||||
emit $ SetVariable x (Load topT' Ptr deref)
|
||||
else emit $ SetVariable x (ExtractValue botT' (VIdent casted Ptr) i)
|
||||
PLit (_l, _t) -> error "Nested pattern matching to be implemented"
|
||||
PInj _id _ps -> error "Nested pattern matching to be implemented"
|
||||
PCatch -> pure ()
|
||||
PEnum _id -> error "Nested pattern matching to be implemented"
|
||||
)
|
||||
cs
|
||||
val <- exprToValue exp
|
||||
emit $ Store ty val Ptr stackPtr
|
||||
emit $ Br label
|
||||
emit $ Label lbl_failPos
|
||||
emitCases _rt ty label stackPtr vs (Branch (MIR.PLit (i, ct), t) exp) = do
|
||||
emit $ Comment "Plit"
|
||||
let i' = case i of
|
||||
MIR.LInt i -> VInteger i
|
||||
MIR.LChar i -> VChar (ord i)
|
||||
ns <- getNewVar
|
||||
lbl_failPos <- (\x -> TIR.Ident $ "failed_" <> show x) <$> getNewLabel
|
||||
lbl_succPos <- (\x -> TIR.Ident $ "success_" <> show x) <$> getNewLabel
|
||||
emit $ SetVariable ns (Icmp LLEq (type2LlvmType ct) vs i')
|
||||
emit $ BrCond (VIdent ns ty) lbl_succPos lbl_failPos
|
||||
emit $ Label lbl_succPos
|
||||
val <- exprToValue exp
|
||||
emit $ Store ty val Ptr stackPtr
|
||||
emit $ Br label
|
||||
emit $ Label lbl_failPos
|
||||
emitCases rt ty label stackPtr vs (Branch (MIR.PVar (id, _), _) exp) = do
|
||||
emit $ Comment "Pvar"
|
||||
-- //TODO this is pretty disgusting and would heavily benefit from a rewrite
|
||||
valPtr <- getNewVar
|
||||
emit $ SetVariable valPtr (Alloca rt)
|
||||
emit $ Store rt vs Ptr valPtr
|
||||
emit $ SetVariable id (Load rt Ptr valPtr)
|
||||
val <- exprToValue exp
|
||||
emit $ Store ty val Ptr stackPtr
|
||||
emit $ Br label
|
||||
lbl_failPos <- (\x -> TIR.Ident $ "failed_" <> show x) <$> getNewLabel
|
||||
emit $ Label lbl_failPos
|
||||
emitCases rt ty label stackPtr vs (Branch (MIR.PEnum (TIR.Ident "True$Bool"), t) exp) = do
|
||||
emitCases rt ty label stackPtr vs (Branch (MIR.PLit (MIR.LInt 1, TLit "Bool"), t) exp)
|
||||
emitCases rt ty label stackPtr vs (Branch (MIR.PEnum (TIR.Ident "False$Bool"), _) exp) = do
|
||||
emitCases rt ty label stackPtr vs (Branch (MIR.PLit (MIR.LInt 0, TLit "Bool"), t) exp)
|
||||
emitCases rt ty label stackPtr vs br@(Branch (MIR.PEnum consId, _) exp) = do
|
||||
emit $ Comment "Penum"
|
||||
cons <- gets constructors
|
||||
let r = Map.lookup consId cons
|
||||
when (isNothing r) (error $ "Constructor: '" ++ printTree consId ++ "' does not exist in cons state:\n" ++ show cons ++ "\nin pattern\n'" ++ printTree br ++ "'\n")
|
||||
|
||||
lbl_failPos <- (\x -> TIR.Ident $ "failed_" <> show x) <$> getNewLabel
|
||||
lbl_succPos <- (\x -> TIR.Ident $ "success_" <> show x) <$> getNewLabel
|
||||
|
||||
consVal <- getNewVar
|
||||
emit $ SetVariable consVal (ExtractValue rt vs 0)
|
||||
|
||||
consCheck <- getNewVar
|
||||
emit $ SetVariable consCheck (Icmp LLEq I8 (VIdent consVal I8) (VInteger $ numCI (fromJust r)))
|
||||
emit $ BrCond (VIdent consCheck ty) lbl_succPos lbl_failPos
|
||||
emit $ Label lbl_succPos
|
||||
|
||||
castPtr <- getNewVar
|
||||
casted <- getNewVar
|
||||
emit $ SetVariable castPtr (Alloca rt)
|
||||
emit $ Store rt vs Ptr castPtr
|
||||
emit $ SetVariable casted (Load (CustomType (coerce consId)) Ptr castPtr)
|
||||
val <- exprToValue exp
|
||||
emit $ Store ty val Ptr stackPtr
|
||||
emit $ Br label
|
||||
emit $ Label lbl_failPos
|
||||
emitCases _ ty label stackPtr _ (Branch (MIR.PCatch, _) exp) = do
|
||||
emit $ Comment "Pcatch"
|
||||
val <- exprToValue exp
|
||||
emit $ Store ty val Ptr stackPtr
|
||||
emit $ Br label
|
||||
lbl_failPos <- (\x -> TIR.Ident $ "failed_" <> show x) <$> getNewLabel
|
||||
emit $ Label lbl_failPos
|
||||
|
||||
emitApp :: MIR.Type -> ExpT -> ExpT -> CompilerState ()
|
||||
emitApp rt e1 e2 = appEmitter e1 e2 []
|
||||
where
|
||||
appEmitter :: ExpT -> ExpT -> [ExpT] -> CompilerState ()
|
||||
appEmitter e1 e2 stack = do
|
||||
let newStack = e2 : stack
|
||||
case e1 of
|
||||
(MIR.EApp e1' e2', _) -> appEmitter e1' e2' newStack
|
||||
(MIR.EVar name, t) -> do
|
||||
args <- traverse exprToValue newStack
|
||||
vs <- getNewVar
|
||||
funcs <- gets functions
|
||||
consts <- gets constructors
|
||||
let visibility =
|
||||
fromMaybe Local $
|
||||
Global <$ Map.lookup name consts
|
||||
<|> Global <$ Map.lookup (name, t) funcs
|
||||
-- this piece of code could probably be improved, i.e remove the double `const Global`
|
||||
args' = map (first valueGetType . dupe) args
|
||||
let call =
|
||||
case name of
|
||||
TIR.Ident ('l' : 't' : '$' : _) -> Icmp LLSlt I64 (snd (head args')) (snd (args' !! 1))
|
||||
TIR.Ident ('$' : 'm' : 'i' : 'n' : 'u' : 's' : '$' : '$' : _) -> Sub I64 (snd (head args')) (snd (args' !! 1))
|
||||
_ -> Call FastCC (type2LlvmType rt) visibility name args'
|
||||
emit $ Comment $ show rt
|
||||
emit $ SetVariable vs call
|
||||
x -> error $ "The unspeakable happened: " <> show x
|
||||
|
||||
emitIdent :: TIR.Ident -> CompilerState ()
|
||||
emitIdent id = do
|
||||
-- !!this should never happen!!
|
||||
emit $ Comment "This should not have happened!"
|
||||
emit $ Variable id
|
||||
emit $ UnsafeRaw "\n"
|
||||
|
||||
emitLit :: MIR.Lit -> CompilerState ()
|
||||
emitLit i = do
|
||||
-- !!this should never happen!!
|
||||
let (i', t) = case i of
|
||||
(MIR.LInt i'') -> (VInteger i'', I64)
|
||||
(MIR.LChar i'') -> (VChar $ ord i'', I8)
|
||||
varCount <- getNewVar
|
||||
emit $ Comment "This should not have happened!"
|
||||
emit $ SetVariable varCount (Add t i' (VInteger 0))
|
||||
|
||||
emitAdd :: MIR.Type -> ExpT -> ExpT -> CompilerState ()
|
||||
emitAdd t e1 e2 = do
|
||||
v1 <- exprToValue e1
|
||||
v2 <- exprToValue e2
|
||||
v <- getNewVar
|
||||
emit $ SetVariable v (Add (type2LlvmType t) v1 v2)
|
||||
|
||||
exprToValue :: ExpT -> CompilerState LLVMValue
|
||||
exprToValue = \case
|
||||
(MIR.ELit i, _t) -> pure $ case i of
|
||||
(MIR.LInt i) -> VInteger i
|
||||
(MIR.LChar i) -> VChar $ ord i
|
||||
(MIR.EVar (TIR.Ident "True$Bool"), _t) -> pure $ VInteger 1
|
||||
(MIR.EVar (TIR.Ident "False$Bool"), _t) -> pure $ VInteger 0
|
||||
(MIR.EVar name, t) -> do
|
||||
funcs <- gets functions
|
||||
cons <- gets constructors
|
||||
let res =
|
||||
Map.lookup (name, t) funcs
|
||||
<|> ( \c ->
|
||||
FunctionInfo
|
||||
{ numArgs = numArgsCI c
|
||||
, arguments = argumentsCI c
|
||||
}
|
||||
)
|
||||
<$> Map.lookup name cons
|
||||
case res of
|
||||
Just fi -> do
|
||||
if numArgs fi == 0
|
||||
then do
|
||||
vc <- getNewVar
|
||||
emit $
|
||||
SetVariable
|
||||
vc
|
||||
(Call FastCC (type2LlvmType t) Global name [])
|
||||
pure $ VIdent vc (type2LlvmType t)
|
||||
else pure $ VFunction name Global (type2LlvmType t)
|
||||
Nothing -> pure $ VIdent name (type2LlvmType t)
|
||||
e -> do
|
||||
compileExp e
|
||||
v <- getVarCount
|
||||
pure $ VIdent (TIR.Ident $ show v) (getType e)
|
||||
271
src/Codegen/LlvmIr.hs
Normal file
271
src/Codegen/LlvmIr.hs
Normal file
|
|
@ -0,0 +1,271 @@
|
|||
{-# LANGUAGE LambdaCase #-}
|
||||
|
||||
module Codegen.LlvmIr (
|
||||
LLVMType (..),
|
||||
LLVMIr (..),
|
||||
llvmIrToString,
|
||||
LLVMValue (..),
|
||||
LLVMComp (..),
|
||||
Visibility (..),
|
||||
CallingConvention (..),
|
||||
ToIr (..),
|
||||
) where
|
||||
|
||||
import Data.List (intercalate)
|
||||
import TypeChecker.TypeCheckerIr (Ident (..))
|
||||
|
||||
data CallingConvention = TailCC | FastCC | CCC | ColdCC deriving (Show, Eq, Ord)
|
||||
instance ToIr CallingConvention where
|
||||
toIr :: CallingConvention -> String
|
||||
toIr TailCC = "tailcc"
|
||||
toIr FastCC = "fastcc"
|
||||
toIr CCC = "ccc"
|
||||
toIr ColdCC = "coldcc"
|
||||
|
||||
-- | A datatype which represents some basic LLVM types
|
||||
data LLVMType
|
||||
= I1
|
||||
| I8
|
||||
| I32
|
||||
| I64
|
||||
| Ptr
|
||||
| Ref LLVMType
|
||||
| Function LLVMType [LLVMType]
|
||||
| Array Integer LLVMType
|
||||
| CustomType Ident
|
||||
deriving (Show, Eq, Ord)
|
||||
|
||||
class ToIr a where
|
||||
toIr :: a -> String
|
||||
|
||||
instance ToIr LLVMType where
|
||||
toIr :: LLVMType -> String
|
||||
toIr = \case
|
||||
I1 -> "i1"
|
||||
I8 -> "i8"
|
||||
I32 -> "i32"
|
||||
I64 -> "i64"
|
||||
Ptr -> "ptr"
|
||||
Ref ty -> toIr ty <> "*"
|
||||
Function t xs -> toIr t <> " (" <> intercalate ", " (map toIr xs) <> ")*"
|
||||
Array n ty -> concat ["[", show n, " x ", toIr ty, "]"]
|
||||
CustomType (Ident ty) -> "%" <> ty
|
||||
|
||||
data LLVMComp
|
||||
= LLEq
|
||||
| LLNe
|
||||
| LLUgt
|
||||
| LLUge
|
||||
| LLUlt
|
||||
| LLUle
|
||||
| LLSgt
|
||||
| LLSge
|
||||
| LLSlt
|
||||
| LLSle
|
||||
deriving (Show, Eq, Ord)
|
||||
instance ToIr LLVMComp where
|
||||
toIr :: LLVMComp -> String
|
||||
toIr = \case
|
||||
LLEq -> "eq"
|
||||
LLNe -> "ne"
|
||||
LLUgt -> "ugt"
|
||||
LLUge -> "uge"
|
||||
LLUlt -> "ult"
|
||||
LLUle -> "ule"
|
||||
LLSgt -> "sgt"
|
||||
LLSge -> "sge"
|
||||
LLSlt -> "slt"
|
||||
LLSle -> "sle"
|
||||
|
||||
data Visibility = Local | Global deriving (Show, Eq, Ord)
|
||||
instance ToIr Visibility where
|
||||
toIr :: Visibility -> String
|
||||
toIr Local = "%"
|
||||
toIr Global = "@"
|
||||
|
||||
{- | Represents a LLVM "value", as in an integer, a register variable,
|
||||
or a string contstant
|
||||
-}
|
||||
data LLVMValue
|
||||
= VInteger Integer
|
||||
| VChar Int
|
||||
| VIdent Ident LLVMType
|
||||
| VConstant String
|
||||
| VFunction Ident Visibility LLVMType
|
||||
deriving (Show, Eq, Ord)
|
||||
|
||||
instance ToIr LLVMValue where
|
||||
toIr :: LLVMValue -> String
|
||||
toIr v = case v of
|
||||
VInteger i -> show i
|
||||
VChar i -> show i
|
||||
VIdent (Ident n) _ -> "%" <> n
|
||||
VFunction (Ident n) vis _ -> toIr vis <> n
|
||||
VConstant s -> "c" <> show s
|
||||
|
||||
type Params = [(Ident, LLVMType)]
|
||||
type Args = [(LLVMType, LLVMValue)]
|
||||
|
||||
-- | A datatype which represents different instructions in LLVM
|
||||
data LLVMIr
|
||||
= Type Ident [LLVMType]
|
||||
| Define CallingConvention LLVMType Ident Params
|
||||
| DefineEnd
|
||||
| Declare LLVMType Ident Params
|
||||
| SetVariable Ident LLVMIr
|
||||
| Variable Ident
|
||||
| ExtractValue LLVMType LLVMValue Integer
|
||||
| GetElementPtr LLVMType LLVMType LLVMValue LLVMType LLVMValue LLVMType LLVMValue
|
||||
| GetElementPtrInbounds LLVMType LLVMType LLVMValue LLVMType LLVMValue LLVMType LLVMValue
|
||||
| Add LLVMType LLVMValue LLVMValue
|
||||
| Sub LLVMType LLVMValue LLVMValue
|
||||
| Div LLVMType LLVMValue LLVMValue
|
||||
| Mul LLVMType LLVMValue LLVMValue
|
||||
| Srem LLVMType LLVMValue LLVMValue
|
||||
| Icmp LLVMComp LLVMType LLVMValue LLVMValue
|
||||
| Br Ident
|
||||
| BrCond LLVMValue Ident Ident
|
||||
| Label Ident
|
||||
| Call CallingConvention LLVMType Visibility Ident Args
|
||||
| Alloca LLVMType
|
||||
| Store LLVMType LLVMValue LLVMType Ident
|
||||
| Load LLVMType LLVMType Ident
|
||||
| Bitcast LLVMType LLVMValue LLVMType
|
||||
| Ret LLVMType LLVMValue
|
||||
| Comment String
|
||||
| Malloc Integer
|
||||
| GcMalloc Integer
|
||||
| UnsafeRaw String -- This should generally be avoided, and proper
|
||||
-- instructions should be used in its place
|
||||
deriving (Show, Eq, Ord)
|
||||
|
||||
-- | Converts a list of LLVMIr instructions to a string
|
||||
llvmIrToString :: [LLVMIr] -> String
|
||||
llvmIrToString = go 0
|
||||
where
|
||||
go :: Int -> [LLVMIr] -> String
|
||||
go _ [] = mempty
|
||||
go i (x : xs) = do
|
||||
let (i', n) = case x of
|
||||
Define{} -> (i + 1, 0)
|
||||
DefineEnd -> (i - 1, 0)
|
||||
_ -> (i, i)
|
||||
insToString n x <> go i' xs
|
||||
|
||||
-- \| Converts a LLVM inststruction to a String, allowing for printing etc.
|
||||
-- The integer represents the indentation
|
||||
--
|
||||
{- FOURMOLU_DISABLE -}
|
||||
insToString :: Int -> LLVMIr -> String
|
||||
insToString i l =
|
||||
replicate i '\t' <> case l of
|
||||
(GetElementPtr t1 t2 p t3 v1 t4 v2) -> do
|
||||
-- getelementptr inbounds %Foo, %Foo* %x, i32 0, i32 0
|
||||
concat
|
||||
[ "getelementptr ", toIr t1, ", " , toIr t2
|
||||
, " ", toIr p, ", ", toIr t3, " ", toIr v1
|
||||
, ", ", toIr t4, " ", toIr v2, "\n"
|
||||
]
|
||||
(ExtractValue t1 v i) -> do
|
||||
concat
|
||||
[ "extractvalue ", toIr t1, " "
|
||||
, toIr v, ", ", show i, "\n"
|
||||
]
|
||||
(GetElementPtrInbounds t1 t2 p t3 v1 t4 v2) -> do
|
||||
-- getelementptr inbounds %Foo, %Foo* %x, i32 0, i32 0
|
||||
concat
|
||||
[ "getelementptr inbounds ", toIr t1, ", " , toIr t2
|
||||
, " ", toIr p, ", ", toIr t3, " ", toIr v1,
|
||||
", ", toIr t4, " ", toIr v2, "\n" ]
|
||||
(Type (Ident n) types) ->
|
||||
concat
|
||||
[ "%", n, " = type { "
|
||||
, intercalate ", " (map toIr types)
|
||||
, " }\n"
|
||||
]
|
||||
(Define c t (Ident i) params) ->
|
||||
concat
|
||||
[ "define ", toIr c, " ", toIr t, " @", i
|
||||
, "(", intercalate ", " (map (\(Ident y, x) -> unwords [toIr x, "%" <> y]) params)
|
||||
, ") {\n"
|
||||
]
|
||||
DefineEnd -> "}\n"
|
||||
(Declare _t (Ident _i) _params) -> undefined
|
||||
(SetVariable (Ident i) ir) -> concat ["%", i, " = ", insToString 0 ir]
|
||||
(Add t v1 v2) ->
|
||||
concat
|
||||
[ "add ", toIr t, " ", toIr v1
|
||||
, ", ", toIr v2, "\n"
|
||||
]
|
||||
(Sub t v1 v2) ->
|
||||
concat
|
||||
[ "sub ", toIr t, " ", toIr v1, ", "
|
||||
, toIr v2, "\n"
|
||||
]
|
||||
(Div t v1 v2) ->
|
||||
concat
|
||||
[ "sdiv ", toIr t, " ", toIr v1, ", "
|
||||
, toIr v2, "\n"
|
||||
]
|
||||
(Mul t v1 v2) ->
|
||||
concat
|
||||
[ "mul ", toIr t, " ", toIr v1
|
||||
, ", ", toIr v2, "\n"
|
||||
]
|
||||
(Srem t v1 v2) ->
|
||||
concat
|
||||
[ "srem ", toIr t, " ", toIr v1, ", "
|
||||
, toIr v2, "\n"
|
||||
]
|
||||
(Call c t vis (Ident i) arg) ->
|
||||
concat
|
||||
[ "call ", toIr c, " ", toIr t, " ", toIr vis, i, "("
|
||||
, intercalate ", " $ Prelude.map (\(x, y) -> toIr x <> " " <> toIr y) arg
|
||||
, ")\n"
|
||||
]
|
||||
(Alloca t) -> unwords ["alloca", toIr t, "\n"]
|
||||
(Malloc t) ->
|
||||
concat
|
||||
[ "call ptr @malloc(i64 ", show t, ")\n"]
|
||||
(GcMalloc t) ->
|
||||
concat
|
||||
[ "call ptr @cheap_alloc(i64 ", show t, ")\n"]
|
||||
(Store t1 val t2 (Ident id2)) ->
|
||||
concat
|
||||
[ "store ", toIr t1, " ", toIr val
|
||||
, ", ", toIr t2 , " %", id2, "\n"
|
||||
]
|
||||
(Load t1 t2 (Ident addr)) ->
|
||||
concat
|
||||
[ "load ", toIr t1, ", "
|
||||
, toIr t2, " %", addr, "\n"
|
||||
]
|
||||
(Bitcast t1 v t2) ->
|
||||
concat
|
||||
[ "bitcast ", toIr t1, " "
|
||||
, toIr v, " to ", toIr t2, "\n"
|
||||
]
|
||||
(Icmp comp t v1 v2) ->
|
||||
concat
|
||||
[ "icmp ", toIr comp, " ", toIr t
|
||||
, " ", toIr v1, ", ", toIr v2, "\n"
|
||||
]
|
||||
(Ret t v) ->
|
||||
concat
|
||||
[ "ret ", toIr t, " "
|
||||
, toIr v, "\n"
|
||||
]
|
||||
(UnsafeRaw s) -> s
|
||||
(Label (Ident s)) -> "\n" <> lblPfx <> s <> ":\n"
|
||||
(Br (Ident s)) -> "br label %" <> lblPfx <> s <> "\n"
|
||||
(BrCond val (Ident s1) (Ident s2)) ->
|
||||
concat
|
||||
[ "br i1 ", toIr val, ", ", "label %"
|
||||
, lblPfx, s1, ", ", "label %", lblPfx, s2, "\n"
|
||||
]
|
||||
(Comment s) -> "; " <> s <> "\n"
|
||||
(Variable (Ident id)) -> "%" <> id
|
||||
{- FOURMOLU_ENABLE -}
|
||||
|
||||
lblPfx :: String
|
||||
lblPfx = "lbl_"
|
||||
Loading…
Add table
Add a link
Reference in a new issue