mirror of
https://github.com/janet-lang/janet
synced 2024-11-28 19:19:53 +00:00
Merge branch 'master' of https://github.com/bakpakin/dst
This commit is contained in:
commit
169a3e8498
18
README.md
18
README.md
@ -102,22 +102,8 @@ make test
|
|||||||
1. Install [Visual Studio](https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=Community&rel=15#)
|
1. Install [Visual Studio](https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=Community&rel=15#)
|
||||||
or [Visual Studio Build Tools](https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=BuildTools&rel=15#)
|
or [Visual Studio Build Tools](https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=BuildTools&rel=15#)
|
||||||
2. Run a Visual Studio Command Prompt (cl.exe and link.exe need to be on the PATH) and cd to the directory with dst.
|
2. Run a Visual Studio Command Prompt (cl.exe and link.exe need to be on the PATH) and cd to the directory with dst.
|
||||||
3. Run `build` to compile dst.
|
3. Run `build_win` to compile dst.
|
||||||
4. Run `build test` to make sure everything is working.
|
4. Run `build_win test` to make sure everything is working.
|
||||||
|
|
||||||
```sh
|
|
||||||
cd somewhere/my/projects/dst
|
|
||||||
mkdir -p build
|
|
||||||
cd build
|
|
||||||
cmake -DCMAKE_BUILD_TYPE=Release ..
|
|
||||||
make
|
|
||||||
make test
|
|
||||||
```
|
|
||||||
|
|
||||||
The repl can also be run with the CMake run target.
|
|
||||||
```sh
|
|
||||||
make run
|
|
||||||
```
|
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
|
@ -92,7 +92,8 @@ void dst_struct_put(DstKV *st, Dst key, Dst value) {
|
|||||||
* is closer to their source than current. We use robinhood
|
* is closer to their source than current. We use robinhood
|
||||||
* hashing to ensure that equivalent structs that are contsructed
|
* hashing to ensure that equivalent structs that are contsructed
|
||||||
* with different order have the same internal layout, and therefor
|
* with different order have the same internal layout, and therefor
|
||||||
* will compare properly - i.e., {1 2 3 4} should equal {3 4 1 2}. */
|
* will compare properly - i.e., {1 2 3 4} should equal {3 4 1 2}.
|
||||||
|
* Collisions are resolved via an insertion sort insertion. */
|
||||||
otherhash = dst_hash(kv->key);
|
otherhash = dst_hash(kv->key);
|
||||||
otherindex = dst_struct_maphash(cap, otherhash);
|
otherindex = dst_struct_maphash(cap, otherhash);
|
||||||
otherdist = (i + cap - otherindex) & (cap - 1);
|
otherdist = (i + cap - otherindex) & (cap - 1);
|
||||||
@ -155,11 +156,7 @@ const DstKV *dst_struct_end(DstKV *st) {
|
|||||||
/* Get an item from a struct */
|
/* Get an item from a struct */
|
||||||
Dst dst_struct_get(const DstKV *st, Dst key) {
|
Dst dst_struct_get(const DstKV *st, Dst key) {
|
||||||
const DstKV *kv = dst_struct_find(st, key);
|
const DstKV *kv = dst_struct_find(st, key);
|
||||||
if (NULL == kv) {
|
return kv ? kv->value : dst_wrap_nil();
|
||||||
return dst_wrap_nil();
|
|
||||||
} else {
|
|
||||||
return kv->value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the next key in a struct */
|
/* Get the next key in a struct */
|
||||||
|
@ -10,8 +10,8 @@
|
|||||||
|
|
||||||
# Flag handlers
|
# Flag handlers
|
||||||
(def handlers :private
|
(def handlers :private
|
||||||
{"h" (fn []
|
{"h" (fn @[]
|
||||||
(print "usage: " (get args 0) " [options] scripts...")
|
(print "usage: " (get process.args 0) " [options] scripts...")
|
||||||
(print
|
(print
|
||||||
`Options are:
|
`Options are:
|
||||||
-h Show this help
|
-h Show this help
|
||||||
@ -30,18 +30,18 @@
|
|||||||
"-" (fn @[] (:= *handleopts* false) 1)
|
"-" (fn @[] (:= *handleopts* false) 1)
|
||||||
"e" (fn @[i]
|
"e" (fn @[i]
|
||||||
(:= *no-file* false)
|
(:= *no-file* false)
|
||||||
(eval (get args (+ i 1)))
|
(eval (get process.args (+ i 1)))
|
||||||
2)})
|
2)})
|
||||||
|
|
||||||
(defn- dohandler @[n i]
|
(defn- dohandler @[n i]
|
||||||
(def h (get handlers n))
|
(def h (get handlers n))
|
||||||
(if h (h i) (print "unknown flag -" n)))
|
(if h (h i) (do (print "unknown flag -" n) ((get handlers "h")))))
|
||||||
|
|
||||||
# Process arguments
|
# Process arguments
|
||||||
(var i 1)
|
(var i 1)
|
||||||
(def lenargs (length args))
|
(def lenargs (length process.args))
|
||||||
(while (< i lenargs)
|
(while (< i lenargs)
|
||||||
(def arg (get args i))
|
(def arg (get process.args i))
|
||||||
(if (and *handleopts* (= "-" (string.slice arg 0 1)))
|
(if (and *handleopts* (= "-" (string.slice arg 0 1)))
|
||||||
(+= i (dohandler (string.slice arg 1 2) i))
|
(+= i (dohandler (string.slice arg 1 2) i))
|
||||||
(do
|
(do
|
||||||
|
@ -38,7 +38,7 @@ int main(int argc, char **argv) {
|
|||||||
args = dst_array(argc);
|
args = dst_array(argc);
|
||||||
for (i = 0; i < argc; i++)
|
for (i = 0; i < argc; i++)
|
||||||
dst_array_push(args, dst_cstringv(argv[i]));
|
dst_array_push(args, dst_cstringv(argv[i]));
|
||||||
dst_env_def(env, "args", dst_wrap_array(args));
|
dst_env_def(env, "process.args", dst_wrap_array(args));
|
||||||
|
|
||||||
/* Expose line getter */
|
/* Expose line getter */
|
||||||
dst_env_def(env, "getline", dst_wrap_cfunction(dst_line_getter));
|
dst_env_def(env, "getline", dst_wrap_cfunction(dst_line_getter));
|
||||||
|
Loading…
Reference in New Issue
Block a user