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

View file

@ -1,32 +1,24 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0" opam-version: "2.0"
version: "1.30" synopsis: "TODO"
synopsis: "Lama programming language"
maintainer: "dboulytchev@gmail.com"
authors: [
"Dmitry Boulytchev <dboulytchev@gmail.com>"
"Daniil Berezun <danya.berezun@gmail.com>"
"Egor Sheremetov <egor.sheremetov.dev@gmail.com>"
]
homepage: "https://github.com/PLTools/Lama"
bug-reports: "https://github.com/PLTools/Lama/issues"
depends: [ depends: [
"ocaml" { >= "4.13.1" } "dune" {>= "3.3"}
"ocamlfind" { build } "posix-uname"
"camlp5" { >= "8.00.05" } "GT"
"ostap" { >= "0.5"} "ostap" {>= "0.6"}
"GT" { >= "0.5.1" } "odoc" {with-doc}
"posix-uname" { = "2.0.2" }
] ]
build: [ build: [
[make] ["dune" "subst"] {dev}
[make "regression"] {with-test} [
"dune"
"build"
"-p"
name
"-j"
jobs
"@install"
"@runtest" {with-test}
"@doc" {with-doc}
]
] ]
install: [make "install"]
dev-repo: "git+https://github.com/PLTools/Lama.git"
url {
src: "git+https://github.com/PLTools/Lama.git#1.30"
}

View file

@ -6,5 +6,10 @@
(package (package
(name Lama) (name Lama)
(allow_empty)
(synopsis "TODO") (synopsis "TODO")
(depends posix-uname)) (depends
posix-uname
GT
(ostap
(>= 0.6))))

1
tutorial/.gitignore vendored
View file

@ -1 +0,0 @@
../stdlib/.gitignore

9
tutorial/.gitignore vendored Normal file
View file

@ -0,0 +1,9 @@
*.html
*.sm
/*.log
*.i
*.s
*.exe
*.x32.exe
*.x64.exe

View file

@ -1,19 +0,0 @@
FILES=$(wildcard *.lama)
ALL=$(sort $(FILES:.lama=))
EXTRA_TARGETS =
ifeq ($(LAMAC),)
LAMAC := LAMA=../runtime ../src/lamac -I ../stdlib
EXTRA_TARGETS += ../src/lamac
endif
all: $(EXTRA_TARGETS) $(ALL)
../src/lamac:
$(MAKE) -C ../src
%: %.lama
$(LAMAC) $<
clean:
$(RM) -R *.s *.o *.i *~ $(ALL)

View file

@ -1,6 +1,7 @@
(rule (rule
(targets Hello.exe) (targets Expressions.x32.exe)
(deps Hello.lama) (deps (:lama Expressions.lama) ../runtime32/runtime.a)
(mode (mode
(promote (until-clean))) (promote (until-clean)))
(action (action
@ -9,11 +10,191 @@
"../runtime32" "../runtime32"
(run (run
%{project_root}/src/Driver.exe %{project_root}/src/Driver.exe
%{deps}
-march=x86 -march=x86
%{lama}
-I -I
../stdlib/x32 ../stdlib/x32
-I -I
../runtime32 ../runtime32
-o -o
%{targets})))) %{targets}))))
(rule
(targets Expressions.x64.exe)
(deps (:lama Expressions.lama) ../runtime/runtime.a)
(mode
(promote (until-clean)))
(action
(setenv
LAMA
"../runtime"
(run
%{project_root}/src/Driver.exe
-march=x86_64
%{lama}
-I
../stdlib/x64
-I
../runtime
-o
%{targets}))))
(rule
(targets Functions.x32.exe)
(deps (:lama Functions.lama) ../runtime32/runtime.a)
(mode
(promote (until-clean)))
(action
(setenv
LAMA
"../runtime32"
(run
%{project_root}/src/Driver.exe
-march=x86
%{lama}
-I
../stdlib/x32
-I
../runtime32
-o
%{targets}))))
(rule
(targets Functions.x64.exe)
(deps (:lama Functions.lama) ../runtime/runtime.a)
(mode
(promote (until-clean)))
(action
(setenv
LAMA
"../runtime"
(run
%{project_root}/src/Driver.exe
-march=x86_64
%{lama}
-I
../stdlib/x64
-I
../runtime
-o
%{targets}))))
(rule
(targets Hello.x32.exe)
(deps (:lama Hello.lama) ../runtime32/runtime.a)
(mode
(promote (until-clean)))
(action
(setenv
LAMA
"../runtime32"
(run
%{project_root}/src/Driver.exe
-march=x86
%{lama}
-I
../stdlib/x32
-I
../runtime32
-o
%{targets}))))
(rule
(targets Hello.x64.exe)
(deps (:lama Hello.lama) ../runtime/runtime.a)
(mode
(promote (until-clean)))
(action
(setenv
LAMA
"../runtime"
(run
%{project_root}/src/Driver.exe
-march=x86_64
%{lama}
-I
../stdlib/x64
-I
../runtime
-o
%{targets}))))
(rule
(targets PatternMatching.x32.exe)
(deps (:lama PatternMatching.lama) ../runtime32/runtime.a)
(mode
(promote (until-clean)))
(action
(setenv
LAMA
"../runtime32"
(run
%{project_root}/src/Driver.exe
-march=x86
%{lama}
-I
../stdlib/x32
-I
../runtime32
-o
%{targets}))))
(rule
(targets PatternMatching.x64.exe)
(deps (:lama PatternMatching.lama) ../runtime/runtime.a)
(mode
(promote (until-clean)))
(action
(setenv
LAMA
"../runtime"
(run
%{project_root}/src/Driver.exe
-march=x86_64
%{lama}
-I
../stdlib/x64
-I
../runtime
-o
%{targets}))))
(rule
(targets Values.x32.exe)
(deps (:lama Values.lama) ../runtime32/runtime.a)
(mode
(promote (until-clean)))
(action
(setenv
LAMA
"../runtime32"
(run
%{project_root}/src/Driver.exe
-march=x86
%{lama}
-I
../stdlib/x32
-I
../runtime32
-o
%{targets}))))
(rule
(targets Values.x64.exe)
(deps (:lama Values.lama) ../runtime/runtime.a)
(mode
(promote (until-clean)))
(action
(setenv
LAMA
"../runtime"
(run
%{project_root}/src/Driver.exe
-march=x86_64
%{lama}
-I
../stdlib/x64
-I
../runtime
-o
%{targets}))))

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)