mirror of
https://github.com/janet-lang/janet
synced 2024-11-28 11:09:54 +00:00
Update documentation to include source
location of bindings.
This commit is contained in:
parent
003472354d
commit
77ea11c603
@ -9,9 +9,16 @@
|
|||||||
<title>Janet Language Documentation</title>
|
<title>Janet Language Documentation</title>
|
||||||
<meta name="description" content="API Documentation for the janet programming language.">
|
<meta name="description" content="API Documentation for the janet programming language.">
|
||||||
<style>
|
<style>
|
||||||
p {
|
.docstring {
|
||||||
font-family: monospace;
|
font-family: monospace;
|
||||||
}
|
}
|
||||||
|
.binding-type {
|
||||||
|
color: blue;
|
||||||
|
}
|
||||||
|
.source-map {
|
||||||
|
color: steelblue;
|
||||||
|
font-size: 0.8em;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
```)
|
```)
|
||||||
@ -64,14 +71,19 @@ p {
|
|||||||
(let [{:macro macro
|
(let [{:macro macro
|
||||||
:value val
|
:value val
|
||||||
:ref ref
|
:ref ref
|
||||||
|
:source-map sm
|
||||||
:doc docstring} env-entry
|
:doc docstring} env-entry
|
||||||
binding-type (cond
|
binding-type (cond
|
||||||
macro :macro
|
macro :macro
|
||||||
ref (string :var " (" (type ref.0) ")")
|
ref (string :var " (" (type ref.0) ")")
|
||||||
(type val))]
|
(type val))
|
||||||
(string "<h2>" (html-escape key) "</h2>"
|
source-ref (if-let [[path start end] sm]
|
||||||
"<span style=\"color:blue;\">" binding-type "</span>"
|
(string "<span class=\"source-map\">" path " (" start ":" end ")</span>")
|
||||||
"<p>" (trim-lead (html-escape docstring)) "</p>")))
|
"")]
|
||||||
|
(string "<h2 class=\"binding\">" (html-escape key) "</h2>\n"
|
||||||
|
"<span class=\"binding-type\">" binding-type "</span>\n"
|
||||||
|
"<p class=\"docstring\">" (trim-lead (html-escape docstring)) "</p>\n"
|
||||||
|
source-ref)))
|
||||||
|
|
||||||
# Generate parts and print them to stdout
|
# Generate parts and print them to stdout
|
||||||
(def parts (seq [[k entry]
|
(def parts (seq [[k entry]
|
||||||
@ -81,5 +93,5 @@ p {
|
|||||||
(print
|
(print
|
||||||
prelude
|
prelude
|
||||||
(make-title)
|
(make-title)
|
||||||
;(interpose "<hr>" parts)
|
;(interpose "<hr>\n" parts)
|
||||||
postlude)
|
postlude)
|
||||||
|
@ -575,13 +575,13 @@ JanetSlot janetc_value(JanetFopts opts, Janet x) {
|
|||||||
|
|
||||||
if (c->result.status == JANET_COMPILE_ERROR)
|
if (c->result.status == JANET_COMPILE_ERROR)
|
||||||
return janetc_cslot(janet_wrap_nil());
|
return janetc_cslot(janet_wrap_nil());
|
||||||
c->current_mapping = last_mapping;
|
|
||||||
if (opts.flags & JANET_FOPTS_TAIL)
|
if (opts.flags & JANET_FOPTS_TAIL)
|
||||||
ret = janetc_return(opts.compiler, ret);
|
ret = janetc_return(opts.compiler, ret);
|
||||||
if (opts.flags & JANET_FOPTS_HINT) {
|
if (opts.flags & JANET_FOPTS_HINT) {
|
||||||
janetc_copy(opts.compiler, opts.hint, ret);
|
janetc_copy(opts.compiler, opts.hint, ret);
|
||||||
ret = opts.hint;
|
ret = opts.hint;
|
||||||
}
|
}
|
||||||
|
c->current_mapping = last_mapping;
|
||||||
opts.compiler->recursion_guard++;
|
opts.compiler->recursion_guard++;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -131,9 +131,9 @@
|
|||||||
|
|
||||||
(defmacro with-idemp
|
(defmacro with-idemp
|
||||||
"Return janet code body that has been prepended
|
"Return janet code body that has been prepended
|
||||||
with a binding of form to atom. If form is a non-
|
with a binding of form to atom. If form is a non-idempotent
|
||||||
idempotent form (a function call, etc.), make sure the resulting
|
form (a function call, etc.), make sure the resulting
|
||||||
code will only call evaluate once, even if body contains multiple
|
code will only evaluate once, even if body contains multiple
|
||||||
copies of binding. In body, use binding instead of form."
|
copies of binding. In body, use binding instead of form."
|
||||||
[binding form & body]
|
[binding form & body]
|
||||||
(def $result (gensym))
|
(def $result (gensym))
|
||||||
@ -152,7 +152,7 @@
|
|||||||
(defmacro ++ "Increments the var x by 1." [x] ~(set ,x (,+ ,x ,1)))
|
(defmacro ++ "Increments the var x by 1." [x] ~(set ,x (,+ ,x ,1)))
|
||||||
(defmacro -- "Decrements the var x by 1." [x] ~(set ,x (,- ,x ,1)))
|
(defmacro -- "Decrements the var x by 1." [x] ~(set ,x (,- ,x ,1)))
|
||||||
(defmacro += "Increments the var x by n." [x n] ~(set ,x (,+ ,x ,n)))
|
(defmacro += "Increments the var x by n." [x n] ~(set ,x (,+ ,x ,n)))
|
||||||
(defmacro -= "Decrements the vat x by n." [x n] ~(set ,x (,- ,x ,n)))
|
(defmacro -= "Decrements the var x by n." [x n] ~(set ,x (,- ,x ,n)))
|
||||||
(defmacro *= "Shorthand for (set x (* x n))." [x n] ~(set ,x (,* ,x ,n)))
|
(defmacro *= "Shorthand for (set x (* x n))." [x n] ~(set ,x (,* ,x ,n)))
|
||||||
(defmacro /= "Shorthand for (set x (/ x n))." [x n] ~(set ,x (,/ ,x ,n)))
|
(defmacro /= "Shorthand for (set x (/ x n))." [x n] ~(set ,x (,/ ,x ,n)))
|
||||||
(defmacro %= "Shorthand for (set x (% x n))." [x n] ~(set ,x (,% ,x ,n)))
|
(defmacro %= "Shorthand for (set x (% x n))." [x n] ~(set ,x (,% ,x ,n)))
|
||||||
@ -441,9 +441,9 @@
|
|||||||
accum)
|
accum)
|
||||||
|
|
||||||
(defmacro if-let
|
(defmacro if-let
|
||||||
"Takes the first one or two forms in a vector and if both are true binds
|
"Make mutliple bindings, anf if all are truthy,
|
||||||
all the forms with let and evaluates the first expression else
|
evaluate the tru form. If any are false or nil, evaluate
|
||||||
evaluates the second"
|
the fal form. Bindings have the same syntax as the let macro."
|
||||||
[bindings tru fal &]
|
[bindings tru fal &]
|
||||||
(def len (length bindings))
|
(def len (length bindings))
|
||||||
(if (zero? len) (error "expected at least 1 binding"))
|
(if (zero? len) (error "expected at least 1 binding"))
|
||||||
@ -472,8 +472,7 @@
|
|||||||
(aux 0))
|
(aux 0))
|
||||||
|
|
||||||
(defmacro when-let
|
(defmacro when-let
|
||||||
"Takes the first one or two forms in vector and if true binds
|
"Same as (if-let bindings (do ;body))."
|
||||||
all the forms with let and evaluates the body"
|
|
||||||
[bindings & body]
|
[bindings & body]
|
||||||
~(if-let ,bindings (do ,;body)))
|
~(if-let ,bindings (do ,;body)))
|
||||||
|
|
||||||
@ -803,8 +802,8 @@ value, one key will be ignored."
|
|||||||
ret)
|
ret)
|
||||||
|
|
||||||
(defn zipcoll
|
(defn zipcoll
|
||||||
"Creates an table or tuple from two arrays/tuples. If a third argument of
|
"Creates an table or tuple from two arrays/tuples.
|
||||||
:struct is given result is struct else is table. Returns a new table."
|
Returns a new table."
|
||||||
[keys vals]
|
[keys vals]
|
||||||
(def res @{})
|
(def res @{})
|
||||||
(def lk (length keys))
|
(def lk (length keys))
|
||||||
@ -1075,7 +1074,7 @@ value, one key will be ignored."
|
|||||||
(print "symbol " sym " not found.")
|
(print "symbol " sym " not found.")
|
||||||
(do
|
(do
|
||||||
(def bind-type
|
(def bind-type
|
||||||
(string " "
|
(string " "
|
||||||
(cond
|
(cond
|
||||||
x:ref (string :var " (" (type (get x:ref 0)) ")")
|
x:ref (string :var " (" (type (get x:ref 0)) ")")
|
||||||
x:macro :macro
|
x:macro :macro
|
||||||
|
@ -324,7 +324,7 @@ static const JanetReg cfuns[] = {
|
|||||||
"(buffer & xs)\n\n"
|
"(buffer & xs)\n\n"
|
||||||
"Creates a new buffer by concatenating values together. Values are "
|
"Creates a new buffer by concatenating values together. Values are "
|
||||||
"converted to bytes via describe if they are not byte sequences. Returns "
|
"converted to bytes via describe if they are not byte sequences. Returns "
|
||||||
"the new symbol."
|
"the new buffer."
|
||||||
},
|
},
|
||||||
{"abstract?", janet_core_is_abstract,
|
{"abstract?", janet_core_is_abstract,
|
||||||
"(abstract? x)\n\n"
|
"(abstract? x)\n\n"
|
||||||
@ -384,7 +384,7 @@ static const JanetReg cfuns[] = {
|
|||||||
{"gcsetinterval", janet_core_gcsetinterval,
|
{"gcsetinterval", janet_core_gcsetinterval,
|
||||||
"(gcsetinterval interval)\n\n"
|
"(gcsetinterval interval)\n\n"
|
||||||
"Set an integer number of bytes to allocate before running garbage collection. "
|
"Set an integer number of bytes to allocate before running garbage collection. "
|
||||||
"Low values interval will be slower but use less memory. "
|
"Low valuesi for interval will be slower but use less memory. "
|
||||||
"High values will be faster but use more memory."
|
"High values will be faster but use more memory."
|
||||||
},
|
},
|
||||||
{"gcinterval", janet_core_gcinterval,
|
{"gcinterval", janet_core_gcinterval,
|
||||||
|
@ -520,11 +520,11 @@ static int root(JanetParser *p, JanetParseState *state, uint8_t c) {
|
|||||||
int janet_parser_consume(JanetParser *parser, uint8_t c) {
|
int janet_parser_consume(JanetParser *parser, uint8_t c) {
|
||||||
int consumed = 0;
|
int consumed = 0;
|
||||||
if (parser->error) return 0;
|
if (parser->error) return 0;
|
||||||
|
parser->offset++;
|
||||||
while (!consumed && !parser->error) {
|
while (!consumed && !parser->error) {
|
||||||
JanetParseState *state = parser->states + parser->statecount - 1;
|
JanetParseState *state = parser->states + parser->statecount - 1;
|
||||||
consumed = state->consumer(parser, state, c);
|
consumed = state->consumer(parser, state, c);
|
||||||
}
|
}
|
||||||
parser->offset++;
|
|
||||||
parser->lookback = c;
|
parser->lookback = c;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -172,6 +172,15 @@ static int destructure(JanetCompiler *c,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Create a source map for definitions. */
|
||||||
|
static const Janet *janetc_make_sourcemap(JanetCompiler *c) {
|
||||||
|
Janet *tup = janet_tuple_begin(3);
|
||||||
|
tup[0] = janet_wrap_string(c->source);
|
||||||
|
tup[1] = janet_wrap_integer(c->current_mapping.start);
|
||||||
|
tup[2] = janet_wrap_integer(c->current_mapping.end);
|
||||||
|
return janet_tuple_end(tup);
|
||||||
|
}
|
||||||
|
|
||||||
static JanetSlot janetc_varset(JanetFopts opts, int32_t argn, const Janet *argv) {
|
static JanetSlot janetc_varset(JanetFopts opts, int32_t argn, const Janet *argv) {
|
||||||
/*JanetFopts subopts = janetc_fopts_default(opts.compiler);*/
|
/*JanetFopts subopts = janetc_fopts_default(opts.compiler);*/
|
||||||
/*JanetSlot ret, dest;*/
|
/*JanetSlot ret, dest;*/
|
||||||
@ -252,6 +261,8 @@ static int varleaf(
|
|||||||
JanetArray *ref = janet_array(1);
|
JanetArray *ref = janet_array(1);
|
||||||
janet_array_push(ref, janet_wrap_nil());
|
janet_array_push(ref, janet_wrap_nil());
|
||||||
janet_table_put(reftab, janet_csymbolv(":ref"), janet_wrap_array(ref));
|
janet_table_put(reftab, janet_csymbolv(":ref"), janet_wrap_array(ref));
|
||||||
|
janet_table_put(reftab, janet_csymbolv(":source-map"),
|
||||||
|
janet_wrap_tuple(janetc_make_sourcemap(c)));
|
||||||
janet_table_put(c->env, janet_wrap_symbol(sym), janet_wrap_table(reftab));
|
janet_table_put(c->env, janet_wrap_symbol(sym), janet_wrap_table(reftab));
|
||||||
refslot = janetc_cslot(janet_wrap_array(ref));
|
refslot = janetc_cslot(janet_wrap_array(ref));
|
||||||
janetc_emit_ssu(c, JOP_PUT_INDEX, refslot, s, 0, 0);
|
janetc_emit_ssu(c, JOP_PUT_INDEX, refslot, s, 0, 0);
|
||||||
@ -278,6 +289,8 @@ static int defleaf(
|
|||||||
JanetTable *attr) {
|
JanetTable *attr) {
|
||||||
if (c->scope->flags & JANET_SCOPE_TOP) {
|
if (c->scope->flags & JANET_SCOPE_TOP) {
|
||||||
JanetTable *tab = janet_table(2);
|
JanetTable *tab = janet_table(2);
|
||||||
|
janet_table_put(tab, janet_csymbolv(":source-map"),
|
||||||
|
janet_wrap_tuple(janetc_make_sourcemap(c)));
|
||||||
tab->proto = attr;
|
tab->proto = attr;
|
||||||
JanetSlot valsym = janetc_cslot(janet_csymbolv(":value"));
|
JanetSlot valsym = janetc_cslot(janet_csymbolv(":value"));
|
||||||
JanetSlot tabslot = janetc_cslot(janet_wrap_table(tab));
|
JanetSlot tabslot = janetc_cslot(janet_wrap_table(tab));
|
||||||
|
Loading…
Reference in New Issue
Block a user