Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
8e50882
make beta-ast in pattern_elim
RozhkovAleksandr Mar 3, 2025
e9116ce
Add Pe Ast
DmitryPilyuk Mar 6, 2025
3c6834a
fix
RozhkovAleksandr Mar 6, 2025
73b744a
fix pe
RozhkovAleksandr Mar 6, 2025
0fbd7cc
fix pe (unit pattern)
RozhkovAleksandr Mar 6, 2025
ca6b955
add monade for pe
RozhkovAleksandr Mar 6, 2025
0d100a1
fix again
RozhkovAleksandr Mar 6, 2025
bc67222
Add new manytests
DmitryPilyuk Mar 6, 2025
96d0977
Fix problem with PNill
DmitryPilyuk Mar 6, 2025
bd343e3
pe fix(ast trouble)
RozhkovAleksandr Mar 7, 2025
ecc4462
add monade
RozhkovAleksandr Mar 7, 2025
31e8f60
add alpha converter
RozhkovAleksandr Mar 7, 2025
409a271
Closure converdion
DmitryPilyuk Mar 8, 2025
2807fd0
add ll beta version
RozhkovAleksandr Mar 8, 2025
3463a1c
fix bugs
RozhkovAleksandr Mar 8, 2025
5f038dc
oops
RozhkovAleksandr Mar 8, 2025
037f995
fix bug with fack
RozhkovAleksandr Mar 8, 2025
04ff3bd
Fix lint problem
DmitryPilyuk Mar 8, 2025
e780b7c
Add mli files
DmitryPilyuk Mar 8, 2025
ce93478
Fix format
DmitryPilyuk Mar 8, 2025
722181b
Update tests
DmitryPilyuk Mar 8, 2025
81ee04b
WIP ANF
DmitryPilyuk Mar 8, 2025
fafce86
anf barely
RozhkovAleksandr Mar 9, 2025
4e50402
Anf runner
DmitryPilyuk Mar 9, 2025
09691c2
fix ll let
RozhkovAleksandr Mar 9, 2025
228ba80
Some fixes
DmitryPilyuk Mar 9, 2025
15a8d8c
Fix alpha convertion
DmitryPilyuk Mar 10, 2025
08ff5a5
Improve anf runner
DmitryPilyuk Mar 10, 2025
6961314
Fix LL
DmitryPilyuk Mar 10, 2025
4202b0c
Init llvm module
DmitryPilyuk Mar 10, 2025
9debdac
add llvm dune and binops
RozhkovAleksandr Mar 10, 2025
76992ac
WIP compiler of cexpr
DmitryPilyuk Mar 11, 2025
8203f3d
Add compilation of if then else
DmitryPilyuk Mar 11, 2025
61a3d91
fix maybe
RozhkovAleksandr Mar 11, 2025
adc44da
Add runner
DmitryPilyuk Mar 11, 2025
0b28bc2
fixes
DmitryPilyuk Mar 11, 2025
392bacc
Add exec tests
DmitryPilyuk Mar 11, 2025
e8f3c14
fix type
DmitryPilyuk Mar 11, 2025
de464b2
Fix exception
DmitryPilyuk Mar 11, 2025
efe194d
Fix apply
DmitryPilyuk Mar 11, 2025
144cd41
fix all bugs
RozhkovAleksandr Mar 11, 2025
10428ce
add some tests
RozhkovAleksandr Mar 11, 2025
f1fefcb
clean code
RozhkovAleksandr Mar 11, 2025
9196ce4
Improve not partial apply
DmitryPilyuk Mar 11, 2025
7f5f471
Fix double ret in main
DmitryPilyuk Mar 11, 2025
5ed69cc
fix identifiers
DmitryPilyuk Mar 12, 2025
8329933
fix anf inference
DmitryPilyuk Mar 12, 2025
0c58bd2
Typechecker fails
Kakadu Mar 24, 2025
bcf0a2b
Fix type of tuple_element func
DmitryPilyuk Mar 24, 2025
8f9032c
Rework alpha_conv
DmitryPilyuk Mar 30, 2025
d244bb4
add a little for me
RozhkovAleksandr Apr 1, 2025
01af38f
feat: semi-live version match elimination
RozhkovAleksandr Apr 2, 2025
e34f0f2
fix: tuple conv
RozhkovAleksandr Apr 3, 2025
f1d96ba
fix match (add check bindinings for cons, clever comb and more
RozhkovAleksandr Apr 4, 2025
78e9210
fix middle ast
RozhkovAleksandr Apr 4, 2025
45fde2a
Format me_elim and add tests
DmitryPilyuk Apr 5, 2025
29285f9
Add tests
DmitryPilyuk Apr 5, 2025
5bc4d36
fix hard patterns decl
RozhkovAleksandr Apr 5, 2025
efe5d44
fix bug in tuple
RozhkovAleksandr Apr 5, 2025
22cc79d
fix
RozhkovAleksandr Apr 5, 2025
35ac2b3
feat: add somes in lambda lift
RozhkovAleksandr Apr 6, 2025
d2ca6fd
add handle for LL. feat for efun and elet ll
RozhkovAleksandr Apr 9, 2025
aafbf94
delete old
RozhkovAleksandr Apr 9, 2025
858c036
clean code (monade add in common)
RozhkovAleksandr Apr 9, 2025
dd26e54
Closure conversion fix
DmitryPilyuk Apr 9, 2025
95b5415
rename fail and fix ll (bultins problem)
RozhkovAleksandr Apr 10, 2025
a36b41c
fix case with _ in match
RozhkovAleksandr Apr 10, 2025
49f1ecb
fix handle for func first class in LL
RozhkovAleksandr Apr 11, 2025
3806322
fix bugs
DmitryPilyuk Apr 14, 2025
f1fde8c
wip anf
RozhkovAleksandr Apr 15, 2025
9674be3
fix ast
RozhkovAleksandr Apr 15, 2025
4bbc30d
anf done
RozhkovAleksandr Apr 15, 2025
35652e1
fix based value
RozhkovAleksandr Apr 15, 2025
fcac1b1
Improve LL
DmitryPilyuk Apr 15, 2025
a85f2ec
Update tests
DmitryPilyuk Apr 15, 2025
1da3c7b
Add type inference to anf tests
DmitryPilyuk Apr 15, 2025
b2e28a1
Format
DmitryPilyuk Apr 17, 2025
5a78434
better
DmitryPilyuk Apr 17, 2025
933c96c
fix bug with getting tuple in efun
RozhkovAleksandr Apr 19, 2025
0696fe6
Fix order of args
DmitryPilyuk Apr 19, 2025
cfc9bfb
fix list pattern in me
RozhkovAleksandr Apr 19, 2025
9e3fcd3
Fix linter warnings
DmitryPilyuk Apr 20, 2025
d6cfe9e
Fixes
DmitryPilyuk Apr 22, 2025
366ac51
New runtime
DmitryPilyuk Apr 24, 2025
7793a88
Codegen
DmitryPilyuk Apr 27, 2025
8b65ac9
Codegen in work
DmitryPilyuk Apr 28, 2025
1d39388
fixes
DmitryPilyuk Apr 28, 2025
fa9e675
Add mli
DmitryPilyuk Apr 29, 2025
e82ba58
Why compiler crashes?
Kakadu Oct 22, 2025
4db570c
Add apply_args and new_closure names in builtins
DmitryPilyuk Oct 22, 2025
9fb9bbf
Fixes CI issue due to manytests directory change
DmitryPilyuk Oct 23, 2025
b252f7b
Rename x013.ml
DmitryPilyuk Oct 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 146 additions & 0 deletions FML/bin/bitecode.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
$ ./compiler.exe < manytests/typed/001fac.ml
$ cat < out.ll
; ModuleID = 'FML'
source_filename = "FML"
target triple = "x86_64-pc-linux-gnu"

declare i64 @new_closure(i64, i64)

declare i64 @apply_args(i64, i64, i64, ...)

declare i64 @print_int(i64)

declare i64 @rt_add(i64, i64)

declare i64 @rt_sub(i64, i64)

declare i64 @rt_mul(i64, i64)

declare i64 @rt_div(i64, i64)

declare i64 @rt_leq(i64, i64)

declare i64 @rt_less(i64, i64)

declare i64 @rt_geq(i64, i64)

declare i64 @rt_gre(i64, i64)

declare i64 @rt_eq(i64, i64)

declare i64 @rt_neq(i64, i64)

declare i64 @rt_and(i64, i64)

declare i64 @rt_or(i64, i64)

declare i64 @fail_match(i64)

define i64 @fac(i64 %n) {
entry:
%sle = icmp sle i64 %n, 1
%sle_i64t = zext i1 %sle to i64
%cond_v = icmp ne i64 %sle_i64t, 0
br i1 %cond_v, label %then, label %else

then: ; preds = %entry
br label %merge

else: ; preds = %entry
%sub = sub i64 %n, 1
%call = call i64 @fac(i64 %sub)
%mul = mul i64 %n, %call
br label %merge

merge: ; preds = %else, %then
%phi = phi i64 [ 1, %then ], [ %mul, %else ]
ret i64 %phi
}

define i64 @main() {
entry:
%call = call i64 @fac(i64 4)
%call1 = call i64 @print_int(i64 %call)
ret i64 0
}

$ ./compiler.exe < manytests/typed/002fac.ml
$ cat < out.ll
; ModuleID = 'FML'
source_filename = "FML"
target triple = "x86_64-pc-linux-gnu"

declare i64 @new_closure(i64, i64)

declare i64 @apply_args(i64, i64, i64, ...)

declare i64 @print_int(i64)

declare i64 @rt_add(i64, i64)

declare i64 @rt_sub(i64, i64)

declare i64 @rt_mul(i64, i64)

declare i64 @rt_div(i64, i64)

declare i64 @rt_leq(i64, i64)

declare i64 @rt_less(i64, i64)

declare i64 @rt_geq(i64, i64)

declare i64 @rt_gre(i64, i64)

declare i64 @rt_eq(i64, i64)

declare i64 @rt_neq(i64, i64)

declare i64 @rt_and(i64, i64)

declare i64 @rt_or(i64, i64)

declare i64 @fail_match(i64)

define i64 @lam_ll0(i64 %k, i64 %n, i64 %p) {
entry:
%mul = mul i64 %p, %n
%applied_closure = call i64 (i64, i64, ...) @apply_args(i64 %k, i64 1, i64 %mul)
ret i64 %applied_closure
}

define i64 @fac_cps(i64 %n, i64 %k) {
entry:
%eq = icmp eq i64 %n, 1
%eq_i64t = zext i1 %eq to i64
%cond_v = icmp ne i64 %eq_i64t, 0
br i1 %cond_v, label %then, label %else

then: ; preds = %entry
%applied_closure = call i64 (i64, i64, ...) @apply_args(i64 %k, i64 1, i64 1)
br label %merge

else: ; preds = %entry
%empty_closure = call i64 @new_closure(i64 ptrtoint (ptr @lam_ll0 to i64), i64 3)
%applied_closure1 = call i64 (i64, i64, ...) @apply_args(i64 %empty_closure, i64 2, i64 %k, i64 %n)
%sub = sub i64 %n, 1
%call = call i64 @fac_cps(i64 %sub, i64 %applied_closure1)
br label %merge

merge: ; preds = %else, %then
%phi = phi i64 [ %applied_closure, %then ], [ %call, %else ]
ret i64 %phi
}

define i64 @lam_ll1(i64 %print_int_ac0) {
entry:
ret i64 %print_int_ac0
}

define i64 @main() {
entry:
%empty_closure = call i64 @new_closure(i64 ptrtoint (ptr @lam_ll1 to i64), i64 1)
%call = call i64 @fac_cps(i64 4, i64 %empty_closure)
%call1 = call i64 @print_int(i64 %call)
ret i64 0
}
26 changes: 26 additions & 0 deletions FML/bin/compiler.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
(** Copyright 2024-2025, Dmitry Pilyuk, Aleksandr Rozhkov *)

(** SPDX-License-Identifier: LGPL-2.1 *)

open Fml_lib

let () =
let input = Stdio.In_channel.input_all Stdlib.stdin in
let parse_and_infer input =
match Parser.parse input with
| Ok parsed ->
(match Inferencer.run_program_inferencer parsed with
| Ok types -> Ok (parsed, types)
| Error _ -> Error (Format.asprintf "Infer error:"))
| Error e -> Error (Format.sprintf "Parsing error: %s" e)
in
match parse_and_infer input with
| Ok (ast, _) ->
let ast = A_conv.ac_program ast in
let ast_me = Match_elimination.match_elimination ast in
let ast_cc = C_conv.cc_program ast_me in
let ast_ll = Lambda_lift.lambda_lift ast_cc in
let ast_anf = Anf.anf ast_ll in
Codegen.compile_program ast_anf
| Error message -> Format.printf "%s" message
;;
62 changes: 62 additions & 0 deletions FML/bin/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
(executable
(name compiler)
(public_name compliler)
(modules compiler)
(libraries fml_lib stdio))

(cram
(deps ./x013.ml_test.txt))

(cram
(applies_to bitecode)
(deps
./compiler.exe
manytests/do_not_type/001.ml
manytests/do_not_type/002if.ml
manytests/do_not_type/003occurs.ml
manytests/do_not_type/004let_poly.ml
manytests/do_not_type/015tuples.ml
manytests/typed/001fac.ml
manytests/typed/002fac.ml
manytests/typed/003fib.ml
manytests/typed/004manyargs.ml
manytests/typed/005fix.ml
manytests/typed/006partial.ml
manytests/typed/006partial2.ml
manytests/typed/006partial3.ml
manytests/typed/007order.ml
manytests/typed/008ascription.ml
manytests/typed/009let_poly.ml
manytests/typed/011mapcps.ml
manytests/typed/012fibcps.ml
manytests/typed/013foldfoldr.ml
manytests/typed/015tuples.ml
manytests/typed/016lists.ml))

(cram
(applies_to llvm_exec)
(deps
./compiler.exe
../lib/llvm/runtime.o
manytests/do_not_type/001.ml
manytests/do_not_type/002if.ml
manytests/do_not_type/003occurs.ml
manytests/do_not_type/004let_poly.ml
manytests/do_not_type/015tuples.ml
manytests/typed/001fac.ml
manytests/typed/002fac.ml
manytests/typed/003fib.ml
manytests/typed/004manyargs.ml
manytests/typed/005fix.ml
manytests/typed/006partial.ml
manytests/typed/006partial2.ml
manytests/typed/006partial3.ml
manytests/typed/007order.ml
manytests/typed/008ascription.ml
manytests/typed/009let_poly.ml
manytests/typed/011mapcps.ml
manytests/typed/012fibcps.ml
; manytests/typed/x013.ml
manytests/typed/013foldfoldr.ml
manytests/typed/015tuples.ml
manytests/typed/016lists.ml))
65 changes: 65 additions & 0 deletions FML/bin/llvm_exec.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
$ ./compiler.exe < manytests/typed/001fac.ml
$ clang-16 out.ll ../lib/llvm/runtime.o -lffi -o 001fac
$ ./001fac
24

$ ./compiler.exe < manytests/typed/002fac.ml
$ clang-16 out.ll ../lib/llvm/runtime.o -lffi -o 002fac
$ ./002fac
24

$ ./compiler.exe < manytests/typed/003fib.ml
$ clang-16 out.ll ../lib/llvm/runtime.o -lffi -o 003fib
$ ./003fib
33

$ ./compiler.exe < manytests/typed/004manyargs.ml
$ clang-16 out.ll ../lib/llvm/runtime.o -lffi -o 004manyargs
$ ./004manyargs
1111111111110100

$ ./compiler.exe < manytests/typed/005fix.ml
$ clang-16 out.ll ../lib/llvm/runtime.o -lffi -o 005fix
$ ./005fix
720

$ ./compiler.exe < manytests/typed/006partial.ml
$ clang-16 out.ll ../lib/llvm/runtime.o -lffi -o 006partial
$ ./006partial
1122

$ ./compiler.exe < manytests/typed/006partial2.ml
$ clang-16 out.ll ../lib/llvm/runtime.o -lffi -o 006partial2
$ ./006partial2
1237

$ ./compiler.exe < manytests/typed/006partial3.ml
$ clang-16 out.ll ../lib/llvm/runtime.o -lffi -o 006partial3
$ ./006partial3
489

$ ./compiler.exe < manytests/typed/007order.ml
$ clang-16 out.ll ../lib/llvm/runtime.o -lffi -o 007order
$ ./007order
-1421103-55555510000

$ ./compiler.exe < manytests/typed/008ascription.ml
$ clang-16 out.ll ../lib/llvm/runtime.o -lffi -o 008ascription
$ ./008ascription
8

$ ./compiler.exe < manytests/typed/012fibcps.ml
$ clang-16 out.ll ../lib/llvm/runtime.o -lffi -o 012fibcps && rm out.ll
$ ./012fibcps && rm -f out.ll
8

$ ls manytests/typed
$ ocaml -w -26 ./x013.ml_test.txt
1111111111

$ ./compiler.exe < ./x013.ml_test.txt
$ clang-16 out.ll ../lib/llvm/runtime.o -lffi -o 013
$ ./013
1111111111


1 change: 1 addition & 0 deletions FML/bin/manytests
18 changes: 18 additions & 0 deletions FML/bin/x013.ml_test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
let wrap f = if 1 = 1 then f else f

let test3 a b c =
let a = print_int a in
let b = print_int b in
let c = print_int c in
0

let apply_args a b c d e f g h i j = a + b + c + d + e + f + g + h + i + j

let main =
let rez =
(wrap apply_args 1 10 100 1000 10000 100000 1000000 10000000 100000000
1000000000)
in
let () = print_int rez in
0

Loading
Loading