Carp/core/Dynamic.carp
2020-06-01 21:34:12 +02:00

52 lines
1.5 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"))))