mirror of
https://github.com/carp-lang/Carp.git
synced 2024-11-05 04:44:12 +03:00
63 lines
1.8 KiB
Plaintext
63 lines
1.8 KiB
Plaintext
(doc Dynamic "This module contains dynamic functions which are used in the Carp repl and during compilation. They are not available in compiled code. Read more about dynamic functions in the [Language Guide](https://github.com/carp-lang/Carp/blob/master/docs/LanguageGuide.md#dynamic-functions).")
|
|
|
|
(defmodule Dynamic
|
|
;; Functions for doing things at the REPL and during compile time.
|
|
|
|
(defndynamic inc [x]
|
|
(+ x 1))
|
|
|
|
(defndynamic dec [x]
|
|
(- x 1))
|
|
|
|
(defmodule Project
|
|
(doc no-echo "Turn off debug printing in the compiler.")
|
|
(defndynamic no-echo []
|
|
(do
|
|
(Project.config "print-ast" false)
|
|
(Project.config "echo-compiler-cmd" false))))
|
|
|
|
(defmodule String
|
|
(defndynamic prefix [s to]
|
|
(String.slice s 0 to))
|
|
|
|
(defndynamic suffix [s from]
|
|
(String.slice s from (String.length s)))
|
|
|
|
(defndynamic tail [s ]
|
|
(String.suffix s 1))
|
|
)
|
|
)
|
|
|
|
|
|
;; The following functions are not put into a module for now:
|
|
|
|
(defndynamic add-cflag [flag]
|
|
(eval (list 'Project.config "cflag" flag)))
|
|
|
|
(defndynamic add-lib [lib]
|
|
(eval (list 'Project.config "libflag" lib)))
|
|
|
|
(defndynamic pkg-config [pkg flags]
|
|
(Dynamic.String.concat (Dynamic.append
|
|
(Dynamic.append
|
|
["`pkg-config " pkg " "]
|
|
(Project.get-config "pkgconfigflag")
|
|
)
|
|
[flags "`"])))
|
|
|
|
(defndynamic add-pkg [pkg]
|
|
(do
|
|
(add-cflag (pkg-config pkg "--cflags"))
|
|
(add-lib (pkg-config pkg "--libs"))))
|
|
|
|
(defndynamic current-file []
|
|
(car (Project.get-config "load-stack")))
|
|
|
|
(defndynamic relative-to [path relpath]
|
|
(Dynamic.String.concat [(Dynamic.Path.directory path)
|
|
"/"
|
|
relpath]))
|
|
|
|
(defndynamic add-c [relpath]
|
|
(Project.config "cmod" (relative-to (current-file) relpath)))
|