• R/O
  • SSH

kink: 提交

Kink runtime


Commit MetaInfo

修订版a8a84d148a491ece8871aedb1cf55c156071efb7 (tree)
时间2020-03-22 12:32:28
作者miyakawataku
Commitermiyakawataku

Log Message

rename TICK.new_stopwatch to STOPWATCH.start

更改概述

差异

diff -r d22648f49033 -r a8a84d148a49 src/bench/bench/BENCH.kn
--- a/src/bench/bench/BENCH.kn Sun Mar 22 01:26:21 2020 +0900
+++ b/src/bench/bench/BENCH.kn Sun Mar 22 12:32:28 2020 +0900
@@ -1,6 +1,6 @@
11 #!/usr/bin/env kink
22
3-:TICK.require_from('kink/')
3+:STOPWATCH.require_from('kink/')
44 :VEC.require_from('kink/')
55
66 # Measure the running time of $thunk.
@@ -9,14 +9,14 @@
99 # measure the elapsed time of three invocations and returns the median.
1010 :measure <- {(:thunk)
1111 2.times.each{(:I)
12- :stopwatch = TICK.new_stopwatch
12+ :stopwatch = STOPWATCH.start
1313 stderr.print('Warmup #{}: '.format(I + 1))
1414 thunk
1515 stderr.print_line('{} seconds'.format(stopwatch))
1616 }
1717
1818 :Seconds = VEC.of_each(3.times.map{(:I)
19- :stopwatch = TICK.new_stopwatch
19+ :stopwatch = STOPWATCH.start
2020 stderr.print('Attempt #{}: '.format(I + 1))
2121 thunk
2222 :Elapsed = stopwatch
diff -r d22648f49033 -r a8a84d148a49 src/kinkdoc-for-host-mod/kink/STOPWATCH.kn
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/kinkdoc-for-host-mod/kink/STOPWATCH.kn Sun Mar 22 12:32:28 2020 +0900
@@ -0,0 +1,29 @@
1+##
2+# Provides funs dealing with ticks, or elapsed machine time.
3+#
4+# A tick is represented as the number of seconds.
5+# For example, 0.123456789 represents 123456789 nanoseconds.
6+
7+:Mod_syms <- []
8+
9+## STOPWATCH.start
10+#
11+# STOPWATCH.start makes a stopwatch fun.
12+#
13+# The stopwatch fun takes no argument,
14+# then returns the elapsed time from the invocation of TICK.new_stopwatch in seconds,
15+# with the precision of nanoseconds.
16+#
17+# The result of the stopwatch fun is always equal to or greater than zero.
18+#
19+# Example (the output varies for each execution):
20+#
21+# :STOPWATCH.require_from('kink/')
22+# :elapsed_seconds <- STOPWATCH.start
23+# STOPWATCH.sleep(1)
24+# stdout.print_line(elapsed_seconds.repr) # => 1.001089645
25+# STOPWATCH.sleep(2)
26+# stdout.print_line(elapsed_seconds.repr) # => 3.004145317
27+Mod_syms.push_back('start')
28+
29+# vim: et sw=2 sts=2
diff -r d22648f49033 -r a8a84d148a49 src/kinkdoc-for-host-mod/kink/TICK.kn
--- a/src/kinkdoc-for-host-mod/kink/TICK.kn Sun Mar 22 01:26:21 2020 +0900
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,29 +0,0 @@
1-##
2-# Provides funs dealing with ticks, or elapsed machine time.
3-#
4-# A tick is represented as the number of seconds.
5-# For example, 0.123456789 represents 123456789 nanoseconds.
6-
7-:Mod_syms <- []
8-
9-## TICK.new_stopwatch
10-#
11-# TICK.new_stopwatch makes a stopwatch fun.
12-#
13-# The stopwatch fun takes no argument,
14-# then returns the elapsed time from the invocation of TICK.new_stopwatch in seconds,
15-# with the precision of nanoseconds.
16-#
17-# The result of the stopwatch fun is always equal to or greater than zero.
18-#
19-# Example (the output varies for each execution):
20-#
21-# :TICK.require_from('kink/')
22-# :elapsed_seconds <- TICK.new_stopwatch
23-# TICK.sleep(1)
24-# stdout.print_line(elapsed_seconds.repr) # => 1.001089645
25-# TICK.sleep(2)
26-# stdout.print_line(elapsed_seconds.repr) # => 3.004145317
27-Mod_syms.push_back('new_stopwatch')
28-
29-# vim: et sw=2 sts=2
diff -r d22648f49033 -r a8a84d148a49 src/main/java/org/kink_lang/kink/internal/mod/tick/TickMod.java
--- a/src/main/java/org/kink_lang/kink/internal/mod/tick/TickMod.java Sun Mar 22 01:26:21 2020 +0900
+++ b/src/main/java/org/kink_lang/kink/internal/mod/tick/TickMod.java Sun Mar 22 12:32:28 2020 +0900
@@ -8,7 +8,7 @@
88 import org.kink_lang.kink.hostfun.HostResult;
99
1010 /**
11- * Helper for kink/TICK mod.
11+ * Helper for kink/STOPWATCH mod.
1212 */
1313 public class TickMod {
1414
@@ -16,7 +16,7 @@
1616 private final Vm vm;
1717
1818 /** The mod name. */
19- public static final String MOD_NAME = "kink/TICK";
19+ public static final String MOD_NAME = "kink/STOPWATCH";
2020
2121 /**
2222 * Constructs the helper.
@@ -40,15 +40,15 @@
4040 */
4141 private Val makeMod() {
4242 Val mod = vm.newVal();
43- mod.setVar(vm.sym.getHandle("new_stopwatch"),
44- vm.fun.make("TICK.new_stopwatch").take(0).action(this::stopwatchStartFun));
43+ mod.setVar(vm.sym.getHandle("start"),
44+ vm.fun.make("STOPWATCH.start").take(0).action(this::stopwatchStartFun));
4545 mod.setVar(vm.sym.getHandle("repr"),
4646 vm.fun.constant(vm.str.of(String.format(Locale.ROOT, "Mod(%s)", MOD_NAME))));
4747 return mod;
4848 }
4949
5050 /**
51- * Implementation of TICK.new_stopwatch.
51+ * Implementation of STOPWATCH.start.
5252 */
5353 private HostResult stopwatchStartFun(HostContext c) {
5454 return watchFun(System.nanoTime());
@@ -61,7 +61,7 @@
6161 * Makes a stopwatch fun from {@code startNano}.
6262 */
6363 private FunVal watchFun(long startNano) {
64- return vm.fun.make("TICK.new_stopwatch#watchfun").take(0).action(c -> {
64+ return vm.fun.make("STOPWATCH.start#watchfun").take(0).action(c -> {
6565 long now = System.nanoTime();
6666 long elapsed = Math.max(0, now - startNano);
6767 return vm.num.of(BigDecimal.valueOf(elapsed).multiply(NANO));
diff -r d22648f49033 -r a8a84d148a49 src/main/java/org/kink_lang/kink/internal/mod/tick/package-info.java
--- a/src/main/java/org/kink_lang/kink/internal/mod/tick/package-info.java Sun Mar 22 01:26:21 2020 +0900
+++ b/src/main/java/org/kink_lang/kink/internal/mod/tick/package-info.java Sun Mar 22 12:32:28 2020 +0900
@@ -1,5 +1,5 @@
11 /**
2- * Provides kink/tick/TICK mod.
2+ * Provides kink/tick/STOPWATCH mod.
33 */
44 package org.kink_lang.kink.internal.mod.tick;
55
diff -r d22648f49033 -r a8a84d148a49 src/main/resources/kink-mods/kink/chan/_SELECTOR.kn
--- a/src/main/resources/kink-mods/kink/chan/_SELECTOR.kn Sun Mar 22 01:26:21 2020 +0900
+++ b/src/main/resources/kink-mods/kink/chan/_SELECTOR.kn Sun Mar 22 12:32:28 2020 +0900
@@ -4,7 +4,7 @@
44
55 :MUTEX.require_from('kink/thread/')
66 :ATOMIC.require_from('kink/thread/')
7-:TICK.require_from('kink/')
7+:STOPWATCH.require_from('kink/')
88
99 # make a selector
1010 :new <- {
@@ -124,7 +124,7 @@
124124 '_park_and_bye' {[:S]()
125125 [:bye :Detachers] = S._with_lock{
126126 S.Status.set($_status_parking)
127- :stopwatch = TICK.new_stopwatch
127+ :stopwatch = STOPWATCH.start
128128 S.Mut.notify_all
129129 :loop <- {
130130 :s = S.Status.get
diff -r d22648f49033 -r a8a84d148a49 src/main/resources/kink-mods/kink/datetime/INSTANT.kn
--- a/src/main/resources/kink-mods/kink/datetime/INSTANT.kn Sun Mar 22 01:26:21 2020 +0900
+++ b/src/main/resources/kink-mods/kink/datetime/INSTANT.kn Sun Mar 22 12:32:28 2020 +0900
@@ -98,7 +98,7 @@
9898 # The result is not guarunteed to to progress monotonically, or smoothly.
9999 # For example, when the system clock is synchronized, the result can move back or jump forward.
100100 #
101-# If you want to measure the elapsed machine time, use TICK.new_stopwatch. See kink/TICK.
101+# If you want to measure the elapsed machine time, use STOPWATCH.new_stopwatch. See kink/STOPWATCH.
102102 :now <- {()
103103 :Java_ins = Instant_class.call_static('now' [])
104104 _new_instant_truncating(Java_ins)
diff -r d22648f49033 -r a8a84d148a49 src/main/resources/kink-mods/kink/thread/THREAD.kn
--- a/src/main/resources/kink-mods/kink/thread/THREAD.kn Sun Mar 22 01:26:21 2020 +0900
+++ b/src/main/resources/kink-mods/kink/thread/THREAD.kn Sun Mar 22 12:32:28 2020 +0900
@@ -80,7 +80,7 @@
8080 # Seconds must be a non-negative num of an arbitrary precision.
8181 # The maximum precision effective in the result depends on the runtime system.
8282 # For example, in a Kink runtime system on the JVM,
83-# the two invocations of TICK.sleep in the following program are equivalent.
83+# the two invocations of STOPWATCH.start in the following program are equivalent.
8484 # Both tries to sleep 1234 milliseconds.
8585 #
8686 # :THREAD.require_from('kink/thread/')
diff -r d22648f49033 -r a8a84d148a49 src/test/kink/TICK_test.kn
--- a/src/test/kink/TICK_test.kn Sun Mar 22 01:26:21 2020 +0900
+++ b/src/test/kink/TICK_test.kn Sun Mar 22 12:32:28 2020 +0900
@@ -1,18 +1,18 @@
11 #!/usr/bin/env kink
22
3-:TICK.require_from('kink/')
3+:STOPWATCH.require_from('kink/')
44 :CONTROL.require_from('kink/')
55 :TEST.require_from('kink/test/')
66
7-TEST.group('.stopwatch'){ # {{{1
7+TEST.group('.start'){ # {{{1
88 TEST.test('fun returns num >=0'){
9- :watch = TICK.new_stopwatch
9+ :watch = STOPWATCH.start
1010 :Time = watch
1111 Time >= 0 || raise('got {}'.format(Time))
1212 }
1313
1414 TEST.test('fun returns increasing nums'){
15- :watch = TICK.new_stopwatch
15+ :watch = STOPWATCH.start
1616 :First = watch
1717 :Second = watch
1818 First <= Second || raise('got {} and {}'.format(First Second))
@@ -21,9 +21,9 @@
2121
2222 # }}}1
2323 TEST.group('.repr'){ # {{{1
24- TEST.test('return "Mod(kink/TICK)"'){
25- :Repr = TICK.repr
26- Repr == 'Mod(kink/TICK)' || raise('got {}'.format(Repr.repr))
24+ TEST.test('return "Mod(kink/STOPWATCH)"'){
25+ :Repr = STOPWATCH.repr
26+ Repr == 'Mod(kink/STOPWATCH)' || raise('got {}'.format(Repr.repr))
2727 }
2828 }
2929
diff -r d22648f49033 -r a8a84d148a49 src/test/kink/chan/CHAN_test.kn
--- a/src/test/kink/chan/CHAN_test.kn Sun Mar 22 01:26:21 2020 +0900
+++ b/src/test/kink/chan/CHAN_test.kn Sun Mar 22 12:32:28 2020 +0900
@@ -2,7 +2,7 @@
22 :THREAD.require_from('kink/thread/')
33 :MUTEX.require_from('kink/thread/')
44 :FIXED_Q.require_from('kink/chan/_data/')
5-:TICK.require_from('kink/')
5+:STOPWATCH.require_from('kink/')
66 :CONTROL.require_from('kink/')
77 :FLAT_MAP.require_from('kink/container/')
88 :TEST.require_from('kink/test/')
@@ -808,7 +808,7 @@
808808 TEST.group('CHAN.timeout'){ # {{{1
809809 TEST.test('fired after the specified seconds'){
810810 :Seconds = 0.3
811- :watch = TICK.new_stopwatch
811+ :watch = STOPWATCH.start
812812 :R = CHAN.select(
813813 CHAN.timeout(Seconds){() 'done' }
814814 )
diff -r d22648f49033 -r a8a84d148a49 src/test/kink/kinkdoc/hostmod_kinkdoc_entries_test.kn
--- a/src/test/kink/kinkdoc/hostmod_kinkdoc_entries_test.kn Sun Mar 22 01:26:21 2020 +0900
+++ b/src/test/kink/kinkdoc/hostmod_kinkdoc_entries_test.kn Sun Mar 22 12:32:28 2020 +0900
@@ -54,10 +54,10 @@
5454 Actual_syms == Doc_syms || raise('{} != {}'.format(Actual_syms.repr Doc_syms.repr))
5555 }
5656
57-TEST.test('kink/TICK'){
58- :TICK.require_from('kink/')
59- :Actual_syms = TICK.var_syms
60- :Doc_syms = FLAT_SET.of_each(_load('src/kinkdoc-for-host-mod/kink/TICK.kn').Mod_syms + Common_to_all_vals)
57+TEST.test('kink/STOPWATCH'){
58+ :STOPWATCH.require_from('kink/')
59+ :Actual_syms = STOPWATCH.var_syms
60+ :Doc_syms = FLAT_SET.of_each(_load('src/kinkdoc-for-host-mod/kink/STOPWATCH.kn').Mod_syms + Common_to_all_vals)
6161 Actual_syms == Doc_syms || raise('{} != {}'.format(Actual_syms.repr Doc_syms.repr))
6262 }
6363
diff -r d22648f49033 -r a8a84d148a49 src/test/kink/thread/MUTEX_test.kn
--- a/src/test/kink/thread/MUTEX_test.kn Sun Mar 22 01:26:21 2020 +0900
+++ b/src/test/kink/thread/MUTEX_test.kn Sun Mar 22 12:32:28 2020 +0900
@@ -1,7 +1,7 @@
11 :JAVA.require_from('kink/javahost/')
22 :MUTEX.require_from('kink/thread/')
33 :THREAD.require_from('kink/thread/')
4-:TICK.require_from('kink/')
4+:STOPWATCH.require_from('kink/')
55 :TEST.require_from('kink/test/')
66 :CONTROL.require_from('kink/')
77
@@ -195,7 +195,7 @@
195195 }
196196 :Result = Mut.with_lock{
197197 Latch.go
198- :sw = TICK.new_stopwatch
198+ :sw = STOPWATCH.start
199199 :loop <- {
200200 :Remaining = 99 - sw
201201 branch(
@@ -228,7 +228,7 @@
228228 :V = new_val('Status' 'Not_done')
229229 :Mut = MUTEX.new
230230 :Result = Mut.with_lock{
231- :sw = TICK.new_stopwatch
231+ :sw = STOPWATCH.start
232232 :loop <- {
233233 :Remaining = 1 - sw
234234 branch(
diff -r d22648f49033 -r a8a84d148a49 src/test/kink/thread/THREAD_test.kn
--- a/src/test/kink/thread/THREAD_test.kn Sun Mar 22 01:26:21 2020 +0900
+++ b/src/test/kink/thread/THREAD_test.kn Sun Mar 22 12:32:28 2020 +0900
@@ -1,6 +1,6 @@
11 :THREAD.require_from('kink/thread/')
22 :MUTEX.require_from('kink/thread/')
3-:TICK.require_from('kink/')
3+:STOPWATCH.require_from('kink/')
44 :CONTROL.require_from('kink/')
55 :STR_PRINTER.require_from('kink/io/')
66 :TEST.require_from('kink/test/')
@@ -48,7 +48,7 @@
4848 TEST.group('@nondeterministic'){
4949 TEST.test('sleeps some seconds'){
5050 :Leniency_rate = 0.5
51- :watch = TICK.new_stopwatch
51+ :watch = STOPWATCH.start
5252 THREAD.sleep(0.3)
5353 :Elapsed = watch
5454 Elapsed >= 0.3 * Leniency_rate || raise('elapsed {} seconds'.format(Elapsed))
Show on old repository browser