Dunify tutorial

Signed-off-by: Kakadu <Kakadu@pm.me>
This commit is contained in:
Kakadu 2024-09-05 14:51:37 +03:00
parent 3f7f51b2f0
commit a91f4824c4
6 changed files with 262 additions and 51 deletions

44
tutorial/gen.ml Normal file
View file

@ -0,0 +1,44 @@
#use "topfind";;
#require "str";;
let demos = ["Expressions"; "Functions"; "Hello"; "PatternMatching"; "Values"]
let template = {|
(rule
(targets %DEMO%.exe)
(deps (:lama %DEMOSRC%.lama) %RUNTIME%/runtime.a)
(mode
(promote (until-clean)))
(action
(setenv
LAMA
"%RUNTIME%"
(run
%{project_root}/src/Driver.exe
%EXTRASWITCHES%
%{lama}
-I
%STDLIB%
-I
%RUNTIME%
-o
%{targets}))))
|}
let () =
Out_channel.with_open_text "dune" (fun ch ->
List.iter (fun demo ->
template
|> Str.global_replace (Str.regexp "%DEMO%") (demo^".x32")
|> Str.global_replace (Str.regexp "%DEMOSRC%") demo
|> Str.global_replace (Str.regexp "%RUNTIME%") "../runtime32"
|> Str.global_replace (Str.regexp "%STDLIB%") "../stdlib/x32"
|> Str.global_replace (Str.regexp "%EXTRASWITCHES%") "-march=x86"
|> output_string ch;
template
|> Str.global_replace (Str.regexp "%DEMO%") (demo^".x64")
|> Str.global_replace (Str.regexp "%DEMOSRC%") demo
|> Str.global_replace (Str.regexp "%RUNTIME%") "../runtime"
|> Str.global_replace (Str.regexp "%STDLIB%") "../stdlib/x64"
|> Str.global_replace (Str.regexp "%EXTRASWITCHES%") "-march=x86_64"
|> output_string ch;
) demos)