1
0
mirror of https://github.com/janet-lang/janet synced 2025-10-14 23:37:40 +00:00

Add functionality that allows the set macro to

take a tuple as an l-value. Remove the old
multi-sym report in anticipation of a different
mechanism.
This commit is contained in:
Calvin Rose
2019-01-06 19:33:27 -05:00
parent 92e9e64945
commit eae4e0dede
11 changed files with 138 additions and 207 deletions

View File

@@ -76,6 +76,20 @@
[name]
(string "build" sep name modext))
(defn- make-define
"Generate strings for adding custom defines to the compiler."
[define value]
(def prefix (if is-win "\\D" "-D"))
(if value
(string prefix define "=" value)
(string prefix define)))
(defn- make-defines
"Generate many defines. Takes a dictionary of defines. If a value is
true, generates -DNAME (\\DNAME on windows), otherwise -DNAME=value."
[defines]
(seq [[d v] :pairs defines] (make-define d (if (not= v true) v))))
# Defaults
(def OPTIMIZE 2)
(def CC (if is-win "cl" "cc"))
@@ -85,18 +99,19 @@
(defn- compile-c
"Compile a C file into an object file."
[opts src dest]
(def cc (or opts:compiler CC))
(def cflags (or opts:cflags CFLAGS))
(def cc (or (opts :compiler) CC))
(def cflags (or (opts :cflags) CFLAGS))
(def defines (interpose " " (make-defines (or (opts :defines) {}))))
(if (older-than dest src)
(if is-win
(shell cc " /nologo /c " cflags " /Fo" dest " " src)
(shell cc " " cflags " -o " dest " -c " src))))
(shell cc " " ;defines " /nologo /c " cflags " /Fo" dest " " src)
(shell cc " " ;defines " " cflags " -o " dest " -c " src))))
(defn- link-c
"Link a number of object files together."
[opts target & objects]
(def ld (or opts:linker LD))
(def cflags (or opts:cflags CFLAGS))
(def ld (or (opts :linker) LD))
(def cflags (or (opts :cflags) CFLAGS))
(def olist (string/join objects " "))
(if (older-than-some target objects)
(if is-win
@@ -129,17 +144,19 @@
[& opts]
(def opt-table (table ;opts))
(mkdir "build")
(loop [src :in opt-table:source]
(def sources (opt-table :source))
(def name (opt-table :name))
(loop [src :in sources]
(compile-c opt-table src (object-name src)))
(def objects (map object-name opt-table:source))
(when opt-table:embedded
(loop [src :in opt-table:embedded]
(def objects (map object-name sources))
(when-let [embedded (opt-table :embedded)]
(loop [src :in embedded]
(def c-src (embed-c-name src))
(def o-src (embed-o-name src))
(array/push objects o-src)
(create-buffer-c src c-src (embed-name src))
(compile-c opt-table c-src o-src)))
(link-c opt-table (lib-name opt-table:name) ;objects))
(link-c opt-table (lib-name name) ;objects))
(defn clean
"Remove all built artifacts."

View File

@@ -44,7 +44,7 @@
"Trim leading newlines"
[str]
(var i 0)
(while (= 10 str.i) (++ i))
(while (= 10 (get str i)) (++ i))
(string/slice str i))
(defn- html-escape
@@ -52,7 +52,7 @@
[str]
(def buf @"")
(loop [byte :in str]
(if-let [rep escapes.byte]
(if-let [rep (get escapes byte)]
(buffer/push-string buf rep)
(buffer/push-byte buf byte)))
buf)
@@ -90,7 +90,7 @@
# Generate parts and print them to stdout
(def parts (seq [[k entry]
:in (sort (pairs (table/getproto _env)))
:when (and entry:doc (not entry:private))]
:when (and (get entry :doc) (not (get entry :private)))]
(emit-item k entry)))
(print
prelude

View File

@@ -1,12 +1,10 @@
#
# Tool to dump a marshalled version of the janet core to stdout. The
# image should eventually allow janet to be started from a pre-compiled
# image rather than recompiled every time from the embedded source. More
# work will go into shrinking the image (it isn't currently that large but
# could be smaller), creating the mechanism to load the image, and modifying
# the build process to compile janet with a build int image rather than
# the build process to compile janet with a built image rather than
# embedded source.
#
# Get image. This image contains as much of the core library and documentation that
# can be written to an image (no cfunctions, no abstracts (stdout, stdin, stderr)),

View File

@@ -1,4 +1,5 @@
# Helper to generate core library mappings for janet
# Used to help build the tmLanguage grammar.
(def allsyms (all-symbols))
@@ -22,7 +23,7 @@
[str]
(def buf @"")
(loop [byte :in str]
(if-let [rep escapes.byte]
(if-let [rep (get escapes byte)]
(buffer/push-string buf rep)
(buffer/push-byte buf byte)))
buf)