firefly-compiler 0.4.78 → 0.4.79
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.hintrc +4 -4
- package/.vscode/settings.json +4 -4
- package/bin/Release.ff +153 -153
- package/bin/firefly.mjs +1 -1
- package/compiler/Builder.ff +257 -257
- package/compiler/Compiler.ff +227 -227
- package/compiler/Dependencies.ff +187 -187
- package/compiler/DependencyLock.ff +17 -17
- package/compiler/JsEmitter.ff +946 -946
- package/compiler/LspHook.ff +202 -202
- package/compiler/ModuleCache.ff +178 -178
- package/compiler/Workspace.ff +88 -88
- package/core/.firefly/include/package-lock.json +564 -394
- package/core/.firefly/include/package.json +5 -5
- package/core/.firefly/include/prepare.sh +1 -1
- package/core/.firefly/package.ff +2 -2
- package/core/Array.ff +265 -265
- package/core/Atomic.ff +64 -64
- package/core/Box.ff +7 -7
- package/core/BrowserSystem.ff +40 -40
- package/core/BuildSystem.ff +148 -148
- package/core/Crypto.ff +96 -96
- package/core/Equal.ff +36 -36
- package/core/HttpClient.ff +148 -148
- package/core/JsSystem.ff +69 -69
- package/core/Json.ff +434 -434
- package/core/List.ff +486 -486
- package/core/Lock.ff +144 -144
- package/core/NodeSystem.ff +216 -216
- package/core/Ordering.ff +161 -161
- package/core/Path.ff +401 -401
- package/core/Random.ff +134 -134
- package/core/RbMap.ff +216 -216
- package/core/Show.ff +43 -43
- package/core/SourceLocation.ff +68 -68
- package/core/Task.ff +141 -141
- package/experimental/benchmarks/ListGrab.ff +23 -23
- package/experimental/benchmarks/ListGrab.java +55 -55
- package/experimental/benchmarks/Pyrotek45.ff +30 -30
- package/experimental/benchmarks/Pyrotek45.java +64 -64
- package/experimental/bidirectional/Bidi.ff +88 -88
- package/experimental/random/Index.ff +53 -53
- package/experimental/random/Process.ff +120 -120
- package/experimental/random/Scrape.ff +51 -51
- package/experimental/random/Symbols.ff +73 -73
- package/experimental/random/Tensor.ff +52 -52
- package/experimental/random/Units.ff +36 -36
- package/experimental/s3/S3TestAuthorizationHeader.ff +39 -38
- package/experimental/s3/S3TestPut.ff +16 -15
- package/experimental/tests/TestJson.ff +26 -26
- package/firefly.sh +0 -0
- package/fireflysite/.firefly/package.ff +4 -4
- package/fireflysite/CommunityOverview.ff +20 -20
- package/fireflysite/CountingButtonDemo.ff +58 -58
- package/fireflysite/DocumentParser.ff +218 -0
- package/fireflysite/ExamplesOverview.ff +40 -31
- package/fireflysite/FrontPage.ff +360 -0
- package/fireflysite/Guide.ff +411 -308
- package/fireflysite/GuideAll.ff +21 -0
- package/fireflysite/GuideBaseTypes.ff +168 -0
- package/fireflysite/GuideControlFlow.ff +212 -0
- package/fireflysite/GuideIntroduction.ff +52 -69
- package/fireflysite/Main.ff +137 -92
- package/fireflysite/MatchingPasswordsDemo.ff +82 -86
- package/fireflysite/PackagesOverview.ff +49 -49
- package/fireflysite/PostgresqlDemo.ff +34 -0
- package/fireflysite/Styles.ff +495 -306
- package/fireflysite/assets/NotoSansMono-Regular.ttf +0 -0
- package/fireflysite/assets/NunitoSans-VariableFont_YTLC,opsz,wdth,wght.ttf +0 -0
- package/fireflysite/assets/autocomplete-small.png +0 -0
- package/fireflysite/assets/autocomplete.png +0 -0
- package/fireflysite/assets/edit-time-error.png +0 -0
- package/fireflysite/assets/firefly-logo-yellow.png +0 -0
- package/fireflysite/assets/markdown/ControlFlow.md +136 -0
- package/fireflysite/assets/markdown/Example.md +78 -0
- package/lsp/.firefly/package.ff +1 -1
- package/lsp/CompletionHandler.ff +828 -828
- package/lsp/Handler.ff +714 -714
- package/lsp/HoverHandler.ff +79 -79
- package/lsp/LanguageServer.ff +272 -272
- package/lsp/SignatureHelpHandler.ff +55 -55
- package/lsp/SymbolHandler.ff +181 -181
- package/lsp/TestReferences.ff +17 -17
- package/lsp/TestReferencesCase.ff +7 -7
- package/lsp/stderr.txt +1 -1
- package/lsp/stdout.txt +34 -34
- package/lux/.firefly/package.ff +1 -1
- package/lux/Css.ff +648 -648
- package/lux/CssTest.ff +48 -48
- package/lux/Lux.ff +487 -487
- package/lux/LuxEvent.ff +116 -116
- package/lux/Main.ff +123 -123
- package/lux/Main2.ff +143 -143
- package/output/js/ff/compiler/Builder.mjs +43 -43
- package/output/js/ff/compiler/Dependencies.mjs +3 -3
- package/output/js/ff/core/Array.mjs +59 -59
- package/output/js/ff/core/Atomic.mjs +36 -36
- package/output/js/ff/core/BrowserSystem.mjs +11 -11
- package/output/js/ff/core/BuildSystem.mjs +30 -30
- package/output/js/ff/core/Crypto.mjs +40 -40
- package/output/js/ff/core/HttpClient.mjs +56 -56
- package/output/js/ff/core/Json.mjs +147 -147
- package/output/js/ff/core/List.mjs +50 -50
- package/output/js/ff/core/Lock.mjs +97 -97
- package/output/js/ff/core/NodeSystem.mjs +83 -83
- package/output/js/ff/core/Ordering.mjs +8 -8
- package/output/js/ff/core/Path.mjs +231 -231
- package/output/js/ff/core/Random.mjs +56 -56
- package/output/js/ff/core/Task.mjs +31 -31
- package/package.json +1 -1
- package/rpc/.firefly/package.ff +1 -1
- package/rpc/Rpc.ff +70 -70
- package/s3/.firefly/package.ff +1 -1
- package/s3/S3.ff +94 -94
- package/unsafejs/UnsafeJs.ff +19 -19
- package/vscode/LICENSE.txt +21 -21
- package/vscode/Prepublish.ff +15 -15
- package/vscode/README.md +16 -16
- package/vscode/client/package.json +22 -22
- package/vscode/client/src/extension.ts +104 -104
- package/vscode/icons/firefly-icon.svg +10 -10
- package/vscode/language-configuration.json +61 -61
- package/vscode/package-lock.json +3623 -3623
- package/vscode/package.json +15 -1
- package/vscode/snippets.json +241 -241
- package/vscode/syntaxes/firefly-markdown-injection.json +45 -0
- package/webserver/.firefly/include/package-lock.json +22 -16
- package/webserver/.firefly/include/package.json +5 -5
- package/webserver/.firefly/package.ff +2 -2
- package/webserver/WebServer.ff +685 -685
- package/websocket/.firefly/package.ff +1 -1
- package/websocket/WebSocket.ff +131 -131
- /package/fireflysite/{firefly-logo-notext.png → assets/firefly-logo-notext.png} +0 -0
package/core/Task.ff
CHANGED
|
@@ -1,141 +1,141 @@
|
|
|
1
|
-
capability Task {}
|
|
2
|
-
|
|
3
|
-
extend self: Task {
|
|
4
|
-
// Spawns a task running body. The return value as well as the argument to body is the task handle.
|
|
5
|
-
// Automatically aborts and then joins subtasks when body returns or throws an unhandled exception.
|
|
6
|
-
// If body throws, the parent task is also aborted with the dueToSubtask flag set to true.
|
|
7
|
-
spawn(body: Task => Unit): Task
|
|
8
|
-
target js async """
|
|
9
|
-
return ff_core_Task.Task_spawn(self_, body_)
|
|
10
|
-
"""
|
|
11
|
-
target js sync """
|
|
12
|
-
ff_core_Task.Task_throwIfAborted(self_)
|
|
13
|
-
const task = {controller: new AbortController(), subtasks: new Set(), started: performance.now() * 0.001}
|
|
14
|
-
self_.subtasks.add(task)
|
|
15
|
-
task.promise = Promise.resolve(task).then(async () => {
|
|
16
|
-
try {
|
|
17
|
-
await body_(task, task)
|
|
18
|
-
} catch(e) {
|
|
19
|
-
await ff_core_Task.Task_abort$(self_)
|
|
20
|
-
throw e
|
|
21
|
-
} finally {
|
|
22
|
-
for(const subtask of task.subtasks) subtask.controller.abort()
|
|
23
|
-
await Promise.allSettled([...task.subtasks].map(subtask => subtask.promise))
|
|
24
|
-
self_.subtasks.delete(task)
|
|
25
|
-
}
|
|
26
|
-
})
|
|
27
|
-
return task
|
|
28
|
-
"""
|
|
29
|
-
|
|
30
|
-
// If the aborted flag is set for the current task, clears it and throws TaskAbortedException.
|
|
31
|
-
// You don't normally need to call this, but you might want to before doing an expensive computation.
|
|
32
|
-
throwIfAborted(): Unit
|
|
33
|
-
target js async """
|
|
34
|
-
ff_core_Task.Task_throwIfAborted(self_)
|
|
35
|
-
"""
|
|
36
|
-
target js sync """
|
|
37
|
-
if(self_.controller.signal.aborted) {
|
|
38
|
-
const signal = self_.controller.signal
|
|
39
|
-
self_.controller = new AbortController()
|
|
40
|
-
signal.throwIfAborted()
|
|
41
|
-
}
|
|
42
|
-
"""
|
|
43
|
-
|
|
44
|
-
// Sets the tasks aborted flag, which causes the ongoing/next async call to throw TaskAbortedException.
|
|
45
|
-
abort(): Unit
|
|
46
|
-
target js async """
|
|
47
|
-
self_.controller.abort()
|
|
48
|
-
"""
|
|
49
|
-
target js sync """
|
|
50
|
-
self_.controller.abort()
|
|
51
|
-
"""
|
|
52
|
-
|
|
53
|
-
// Create a blocking channel with the specified capacity. The channel is not tied to the task.
|
|
54
|
-
channel[T](capacity: Int = 0): Channel[T]
|
|
55
|
-
target js async """return ff_core_Task.Task_channel(capacity_)"""
|
|
56
|
-
target js sync """return {capacity: capacity_, buffer: [], readers: new Set(), writers: new Set()}"""
|
|
57
|
-
|
|
58
|
-
// Create a mutex. The mutex is not tied to the task.
|
|
59
|
-
lock(): Lock
|
|
60
|
-
target js async """return {owner: null, level: 0, stack: [], queue: []}"""
|
|
61
|
-
|
|
62
|
-
now(): Instant
|
|
63
|
-
target js sync "return Date.now() * 0.001"
|
|
64
|
-
target js async "return Date.now() * 0.001" // TODO: Mark now() as sync and remove async version
|
|
65
|
-
|
|
66
|
-
elapsed(): Duration
|
|
67
|
-
target js sync "return performance.now() * 0.001 - self_.started"
|
|
68
|
-
target js async "return performance.now() * 0.001 - self_.started" // TODO: Mark sync and remove async version
|
|
69
|
-
|
|
70
|
-
time[R](body: () => R): Pair[R, Duration] {
|
|
71
|
-
let start = self.elapsed()
|
|
72
|
-
let result = body()
|
|
73
|
-
let stop = self.elapsed()
|
|
74
|
-
let duration = Duration(stop.seconds - start.seconds)
|
|
75
|
-
Pair(result, duration)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Convenience methods
|
|
81
|
-
extend self: Task {
|
|
82
|
-
|
|
83
|
-
sleep(duration: Duration): Unit {
|
|
84
|
-
Channel.
|
|
85
|
-
readOr(self.channel()) {_ => }.
|
|
86
|
-
timeout(duration) {}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
all[T](tasks: List[() => T]): List[T] {
|
|
90
|
-
let successChannel = self.channel()
|
|
91
|
-
let failureChannel = self.channel()
|
|
92
|
-
self.spawn {t =>
|
|
93
|
-
let channel = t.channel()
|
|
94
|
-
try {
|
|
95
|
-
tasks.pairs().each {| Pair(i, task) =>
|
|
96
|
-
t.spawn {_ =>
|
|
97
|
-
channel.write(Pair(i, task()))
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
let result = tasks.map {_ =>
|
|
101
|
-
channel.read()
|
|
102
|
-
}.sortBy {_.first}.map {_.second}
|
|
103
|
-
successChannel.write(result)
|
|
104
|
-
} catchAny {error =>
|
|
105
|
-
failureChannel.write(error)
|
|
106
|
-
t.abort()
|
|
107
|
-
} grab()
|
|
108
|
-
}
|
|
109
|
-
Channel.
|
|
110
|
-
readOr(successChannel, {_}).
|
|
111
|
-
readOr(failureChannel, {_.rethrow()}).
|
|
112
|
-
wait()
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
race[T](tasks: List[() => T]): T {
|
|
116
|
-
let successChannel = self.channel()
|
|
117
|
-
let failureChannel = self.channel()
|
|
118
|
-
mutable live = tasks.size()
|
|
119
|
-
let started = tasks.map {task =>
|
|
120
|
-
self.spawn {_ =>
|
|
121
|
-
try {
|
|
122
|
-
successChannel.write(task())
|
|
123
|
-
} catchAny {e =>
|
|
124
|
-
live -= 1 // Not thread safe (but OK in JS)
|
|
125
|
-
if(live == 0) {
|
|
126
|
-
failureChannel.write(e)
|
|
127
|
-
}
|
|
128
|
-
} grab()
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
try {
|
|
132
|
-
Channel.
|
|
133
|
-
readOr(successChannel, {_}).
|
|
134
|
-
readOr(failureChannel, {_.rethrow()}).
|
|
135
|
-
wait()
|
|
136
|
-
} finally {
|
|
137
|
-
started.each {_.abort()}
|
|
138
|
-
} grab()
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
}
|
|
1
|
+
capability Task {}
|
|
2
|
+
|
|
3
|
+
extend self: Task {
|
|
4
|
+
// Spawns a task running body. The return value as well as the argument to body is the task handle.
|
|
5
|
+
// Automatically aborts and then joins subtasks when body returns or throws an unhandled exception.
|
|
6
|
+
// If body throws, the parent task is also aborted with the dueToSubtask flag set to true.
|
|
7
|
+
spawn(body: Task => Unit): Task
|
|
8
|
+
target js async """
|
|
9
|
+
return ff_core_Task.Task_spawn(self_, body_)
|
|
10
|
+
"""
|
|
11
|
+
target js sync """
|
|
12
|
+
ff_core_Task.Task_throwIfAborted(self_)
|
|
13
|
+
const task = {controller: new AbortController(), subtasks: new Set(), started: performance.now() * 0.001}
|
|
14
|
+
self_.subtasks.add(task)
|
|
15
|
+
task.promise = Promise.resolve(task).then(async () => {
|
|
16
|
+
try {
|
|
17
|
+
await body_(task, task)
|
|
18
|
+
} catch(e) {
|
|
19
|
+
await ff_core_Task.Task_abort$(self_)
|
|
20
|
+
throw e
|
|
21
|
+
} finally {
|
|
22
|
+
for(const subtask of task.subtasks) subtask.controller.abort()
|
|
23
|
+
await Promise.allSettled([...task.subtasks].map(subtask => subtask.promise))
|
|
24
|
+
self_.subtasks.delete(task)
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
return task
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
// If the aborted flag is set for the current task, clears it and throws TaskAbortedException.
|
|
31
|
+
// You don't normally need to call this, but you might want to before doing an expensive computation.
|
|
32
|
+
throwIfAborted(): Unit
|
|
33
|
+
target js async """
|
|
34
|
+
ff_core_Task.Task_throwIfAborted(self_)
|
|
35
|
+
"""
|
|
36
|
+
target js sync """
|
|
37
|
+
if(self_.controller.signal.aborted) {
|
|
38
|
+
const signal = self_.controller.signal
|
|
39
|
+
self_.controller = new AbortController()
|
|
40
|
+
signal.throwIfAborted()
|
|
41
|
+
}
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
// Sets the tasks aborted flag, which causes the ongoing/next async call to throw TaskAbortedException.
|
|
45
|
+
abort(): Unit
|
|
46
|
+
target js async """
|
|
47
|
+
self_.controller.abort()
|
|
48
|
+
"""
|
|
49
|
+
target js sync """
|
|
50
|
+
self_.controller.abort()
|
|
51
|
+
"""
|
|
52
|
+
|
|
53
|
+
// Create a blocking channel with the specified capacity. The channel is not tied to the task.
|
|
54
|
+
channel[T](capacity: Int = 0): Channel[T]
|
|
55
|
+
target js async """return ff_core_Task.Task_channel(capacity_)"""
|
|
56
|
+
target js sync """return {capacity: capacity_, buffer: [], readers: new Set(), writers: new Set()}"""
|
|
57
|
+
|
|
58
|
+
// Create a mutex. The mutex is not tied to the task.
|
|
59
|
+
lock(): Lock
|
|
60
|
+
target js async """return {owner: null, level: 0, stack: [], queue: []}"""
|
|
61
|
+
|
|
62
|
+
now(): Instant
|
|
63
|
+
target js sync "return Date.now() * 0.001"
|
|
64
|
+
target js async "return Date.now() * 0.001" // TODO: Mark now() as sync and remove async version
|
|
65
|
+
|
|
66
|
+
elapsed(): Duration
|
|
67
|
+
target js sync "return performance.now() * 0.001 - self_.started"
|
|
68
|
+
target js async "return performance.now() * 0.001 - self_.started" // TODO: Mark sync and remove async version
|
|
69
|
+
|
|
70
|
+
time[R](body: () => R): Pair[R, Duration] {
|
|
71
|
+
let start = self.elapsed()
|
|
72
|
+
let result = body()
|
|
73
|
+
let stop = self.elapsed()
|
|
74
|
+
let duration = Duration(stop.seconds - start.seconds)
|
|
75
|
+
Pair(result, duration)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Convenience methods
|
|
81
|
+
extend self: Task {
|
|
82
|
+
|
|
83
|
+
sleep(duration: Duration): Unit {
|
|
84
|
+
Channel.
|
|
85
|
+
readOr(self.channel()) {_ => }.
|
|
86
|
+
timeout(duration) {}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
all[T](tasks: List[() => T]): List[T] {
|
|
90
|
+
let successChannel = self.channel()
|
|
91
|
+
let failureChannel = self.channel()
|
|
92
|
+
self.spawn {t =>
|
|
93
|
+
let channel = t.channel()
|
|
94
|
+
try {
|
|
95
|
+
tasks.pairs().each {| Pair(i, task) =>
|
|
96
|
+
t.spawn {_ =>
|
|
97
|
+
channel.write(Pair(i, task()))
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
let result = tasks.map {_ =>
|
|
101
|
+
channel.read()
|
|
102
|
+
}.sortBy {_.first}.map {_.second}
|
|
103
|
+
successChannel.write(result)
|
|
104
|
+
} catchAny {error =>
|
|
105
|
+
failureChannel.write(error)
|
|
106
|
+
t.abort()
|
|
107
|
+
} grab()
|
|
108
|
+
}
|
|
109
|
+
Channel.
|
|
110
|
+
readOr(successChannel, {_}).
|
|
111
|
+
readOr(failureChannel, {_.rethrow()}).
|
|
112
|
+
wait()
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
race[T](tasks: List[() => T]): T {
|
|
116
|
+
let successChannel = self.channel()
|
|
117
|
+
let failureChannel = self.channel()
|
|
118
|
+
mutable live = tasks.size()
|
|
119
|
+
let started = tasks.map {task =>
|
|
120
|
+
self.spawn {_ =>
|
|
121
|
+
try {
|
|
122
|
+
successChannel.write(task())
|
|
123
|
+
} catchAny {e =>
|
|
124
|
+
live -= 1 // Not thread safe (but OK in JS)
|
|
125
|
+
if(live == 0) {
|
|
126
|
+
failureChannel.write(e)
|
|
127
|
+
}
|
|
128
|
+
} grab()
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
Channel.
|
|
133
|
+
readOr(successChannel, {_}).
|
|
134
|
+
readOr(failureChannel, {_.rethrow()}).
|
|
135
|
+
wait()
|
|
136
|
+
} finally {
|
|
137
|
+
started.each {_.abort()}
|
|
138
|
+
} grab()
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
}
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
nodeMain(system: NodeSystem) {
|
|
2
|
-
let list = 1.to(10000)
|
|
3
|
-
benchmark(list, 100000)
|
|
4
|
-
let time = system.mainTask().time {
|
|
5
|
-
benchmark(list, 100000)
|
|
6
|
-
}
|
|
7
|
-
Log.trace(time.second.show())
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
benchmark(list: List[Int], iterations: Int): Int {
|
|
11
|
-
mutable sum = 0
|
|
12
|
-
mutable i = 0
|
|
13
|
-
while {i < iterations} {
|
|
14
|
-
mutable j = 0
|
|
15
|
-
sum = 0
|
|
16
|
-
while {j < 10000} {
|
|
17
|
-
sum += list.grab(j)
|
|
18
|
-
j += 1
|
|
19
|
-
}
|
|
20
|
-
i += 1
|
|
21
|
-
}
|
|
22
|
-
sum
|
|
23
|
-
}
|
|
1
|
+
nodeMain(system: NodeSystem) {
|
|
2
|
+
let list = 1.to(10000)
|
|
3
|
+
benchmark(list, 100000)
|
|
4
|
+
let time = system.mainTask().time {
|
|
5
|
+
benchmark(list, 100000)
|
|
6
|
+
}
|
|
7
|
+
Log.trace(time.second.show())
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
benchmark(list: List[Int], iterations: Int): Int {
|
|
11
|
+
mutable sum = 0
|
|
12
|
+
mutable i = 0
|
|
13
|
+
while {i < iterations} {
|
|
14
|
+
mutable j = 0
|
|
15
|
+
sum = 0
|
|
16
|
+
while {j < 10000} {
|
|
17
|
+
sum += list.grab(j)
|
|
18
|
+
j += 1
|
|
19
|
+
}
|
|
20
|
+
i += 1
|
|
21
|
+
}
|
|
22
|
+
sum
|
|
23
|
+
}
|
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
/*
|
|
2
|
-
|
|
3
|
-
nodeMain(system: NodeSystem) {
|
|
4
|
-
let list = 1.to(10000)
|
|
5
|
-
benchmark(list, 10000)
|
|
6
|
-
let time = system.mainTask().time {
|
|
7
|
-
benchmark(list, 10000)
|
|
8
|
-
}
|
|
9
|
-
Log.trace(time.second.show())
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
benchmark(list: List[Int], iterations: Int): Int {
|
|
13
|
-
mutable sum = 0
|
|
14
|
-
mutable i = 0
|
|
15
|
-
while {i < iterations} {
|
|
16
|
-
mutable j = 0
|
|
17
|
-
while {j < 10000} {
|
|
18
|
-
sum += list.grab(j)
|
|
19
|
-
j += 1
|
|
20
|
-
}
|
|
21
|
-
i += 1
|
|
22
|
-
}
|
|
23
|
-
sum
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
// Rewrite the above to Java
|
|
29
|
-
|
|
30
|
-
import java.util.ArrayList;
|
|
31
|
-
|
|
32
|
-
public class ListGrab {
|
|
33
|
-
public static void main(String[] args) {
|
|
34
|
-
ArrayList<Integer> list = new ArrayList<>();
|
|
35
|
-
for (int i = 1; i <= 10000; i++) {
|
|
36
|
-
list.add(i);
|
|
37
|
-
}
|
|
38
|
-
benchmark(list, 100000);
|
|
39
|
-
long time = System.currentTimeMillis();
|
|
40
|
-
benchmark(list, 100000);
|
|
41
|
-
time = System.currentTimeMillis() - time;
|
|
42
|
-
System.out.println(time / 1000.0);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
public static long benchmark(ArrayList<Integer> list, int iterations) {
|
|
46
|
-
long sum = 0;
|
|
47
|
-
for (int i = 0; i < iterations; i++) {
|
|
48
|
-
sum = 0;
|
|
49
|
-
for (int j = 0; j < 10000; j++) {
|
|
50
|
-
sum += list.get(j);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return sum;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
nodeMain(system: NodeSystem) {
|
|
4
|
+
let list = 1.to(10000)
|
|
5
|
+
benchmark(list, 10000)
|
|
6
|
+
let time = system.mainTask().time {
|
|
7
|
+
benchmark(list, 10000)
|
|
8
|
+
}
|
|
9
|
+
Log.trace(time.second.show())
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
benchmark(list: List[Int], iterations: Int): Int {
|
|
13
|
+
mutable sum = 0
|
|
14
|
+
mutable i = 0
|
|
15
|
+
while {i < iterations} {
|
|
16
|
+
mutable j = 0
|
|
17
|
+
while {j < 10000} {
|
|
18
|
+
sum += list.grab(j)
|
|
19
|
+
j += 1
|
|
20
|
+
}
|
|
21
|
+
i += 1
|
|
22
|
+
}
|
|
23
|
+
sum
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
// Rewrite the above to Java
|
|
29
|
+
|
|
30
|
+
import java.util.ArrayList;
|
|
31
|
+
|
|
32
|
+
public class ListGrab {
|
|
33
|
+
public static void main(String[] args) {
|
|
34
|
+
ArrayList<Integer> list = new ArrayList<>();
|
|
35
|
+
for (int i = 1; i <= 10000; i++) {
|
|
36
|
+
list.add(i);
|
|
37
|
+
}
|
|
38
|
+
benchmark(list, 100000);
|
|
39
|
+
long time = System.currentTimeMillis();
|
|
40
|
+
benchmark(list, 100000);
|
|
41
|
+
time = System.currentTimeMillis() - time;
|
|
42
|
+
System.out.println(time / 1000.0);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public static long benchmark(ArrayList<Integer> list, int iterations) {
|
|
46
|
+
long sum = 0;
|
|
47
|
+
for (int i = 0; i < iterations; i++) {
|
|
48
|
+
sum = 0;
|
|
49
|
+
for (int j = 0; j < 10000; j++) {
|
|
50
|
+
sum += list.get(j);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return sum;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
nodeMain(system: NodeSystem) {
|
|
2
|
-
benchmark()
|
|
3
|
-
let time = system.mainTask().time {
|
|
4
|
-
benchmark()
|
|
5
|
-
}
|
|
6
|
-
Log.trace(time.second.show())
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
benchmark() {
|
|
10
|
-
mutable num = 20000
|
|
11
|
-
let v = num
|
|
12
|
-
mutable i = 1
|
|
13
|
-
mutable j = 1
|
|
14
|
-
mutable sum = 0
|
|
15
|
-
while {i < v} {
|
|
16
|
-
j = 1
|
|
17
|
-
while {j < num - 1} {
|
|
18
|
-
if(num % j == 0) {
|
|
19
|
-
sum += j
|
|
20
|
-
}
|
|
21
|
-
j += 1
|
|
22
|
-
}
|
|
23
|
-
if(num == sum) {
|
|
24
|
-
Log.show(sum)
|
|
25
|
-
}
|
|
26
|
-
sum = 0
|
|
27
|
-
num -= 1
|
|
28
|
-
i += 1
|
|
29
|
-
}
|
|
30
|
-
}
|
|
1
|
+
nodeMain(system: NodeSystem) {
|
|
2
|
+
benchmark()
|
|
3
|
+
let time = system.mainTask().time {
|
|
4
|
+
benchmark()
|
|
5
|
+
}
|
|
6
|
+
Log.trace(time.second.show())
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
benchmark() {
|
|
10
|
+
mutable num = 20000
|
|
11
|
+
let v = num
|
|
12
|
+
mutable i = 1
|
|
13
|
+
mutable j = 1
|
|
14
|
+
mutable sum = 0
|
|
15
|
+
while {i < v} {
|
|
16
|
+
j = 1
|
|
17
|
+
while {j < num - 1} {
|
|
18
|
+
if(num % j == 0) {
|
|
19
|
+
sum += j
|
|
20
|
+
}
|
|
21
|
+
j += 1
|
|
22
|
+
}
|
|
23
|
+
if(num == sum) {
|
|
24
|
+
Log.show(sum)
|
|
25
|
+
}
|
|
26
|
+
sum = 0
|
|
27
|
+
num -= 1
|
|
28
|
+
i += 1
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
/*
|
|
2
|
-
nodeMain(system: NodeSystem) {
|
|
3
|
-
benchmark()
|
|
4
|
-
let time = system.mainTask().time {
|
|
5
|
-
benchmark()
|
|
6
|
-
}
|
|
7
|
-
Log.trace(time.second.show())
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
benchmark() {
|
|
11
|
-
mutable num = 20000
|
|
12
|
-
let v = num
|
|
13
|
-
mutable i = 1
|
|
14
|
-
mutable j = 1
|
|
15
|
-
mutable sum = 0
|
|
16
|
-
while {i < v} {
|
|
17
|
-
j = 1
|
|
18
|
-
while {j < num - 1} {
|
|
19
|
-
if(num % j == 0) {
|
|
20
|
-
sum += j
|
|
21
|
-
}
|
|
22
|
-
j += 1
|
|
23
|
-
}
|
|
24
|
-
if(num == sum) {
|
|
25
|
-
Log.show(sum)
|
|
26
|
-
}
|
|
27
|
-
sum = 0
|
|
28
|
-
num -= 1
|
|
29
|
-
i += 1
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
// Rewrite this in Java
|
|
35
|
-
|
|
36
|
-
public class Pyrotek45 {
|
|
37
|
-
public static void main(String[] args) {
|
|
38
|
-
benchmark();
|
|
39
|
-
long time = System.currentTimeMillis();
|
|
40
|
-
benchmark();
|
|
41
|
-
time = System.currentTimeMillis() - time;
|
|
42
|
-
System.out.println(time / 1000.0);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
public static void benchmark() {
|
|
46
|
-
int num = 20000;
|
|
47
|
-
int v = num;
|
|
48
|
-
int i = 1;
|
|
49
|
-
int j = 1;
|
|
50
|
-
int sum = 0;
|
|
51
|
-
for (i = 1; i < v; i++) {
|
|
52
|
-
for (j = 1; j < num - 1; j++) {
|
|
53
|
-
if (num % j == 0) {
|
|
54
|
-
sum += j;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
if (num == sum) {
|
|
58
|
-
System.out.println(sum);
|
|
59
|
-
}
|
|
60
|
-
sum = 0;
|
|
61
|
-
num -= 1;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
nodeMain(system: NodeSystem) {
|
|
3
|
+
benchmark()
|
|
4
|
+
let time = system.mainTask().time {
|
|
5
|
+
benchmark()
|
|
6
|
+
}
|
|
7
|
+
Log.trace(time.second.show())
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
benchmark() {
|
|
11
|
+
mutable num = 20000
|
|
12
|
+
let v = num
|
|
13
|
+
mutable i = 1
|
|
14
|
+
mutable j = 1
|
|
15
|
+
mutable sum = 0
|
|
16
|
+
while {i < v} {
|
|
17
|
+
j = 1
|
|
18
|
+
while {j < num - 1} {
|
|
19
|
+
if(num % j == 0) {
|
|
20
|
+
sum += j
|
|
21
|
+
}
|
|
22
|
+
j += 1
|
|
23
|
+
}
|
|
24
|
+
if(num == sum) {
|
|
25
|
+
Log.show(sum)
|
|
26
|
+
}
|
|
27
|
+
sum = 0
|
|
28
|
+
num -= 1
|
|
29
|
+
i += 1
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
// Rewrite this in Java
|
|
35
|
+
|
|
36
|
+
public class Pyrotek45 {
|
|
37
|
+
public static void main(String[] args) {
|
|
38
|
+
benchmark();
|
|
39
|
+
long time = System.currentTimeMillis();
|
|
40
|
+
benchmark();
|
|
41
|
+
time = System.currentTimeMillis() - time;
|
|
42
|
+
System.out.println(time / 1000.0);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public static void benchmark() {
|
|
46
|
+
int num = 20000;
|
|
47
|
+
int v = num;
|
|
48
|
+
int i = 1;
|
|
49
|
+
int j = 1;
|
|
50
|
+
int sum = 0;
|
|
51
|
+
for (i = 1; i < v; i++) {
|
|
52
|
+
for (j = 1; j < num - 1; j++) {
|
|
53
|
+
if (num % j == 0) {
|
|
54
|
+
sum += j;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (num == sum) {
|
|
58
|
+
System.out.println(sum);
|
|
59
|
+
}
|
|
60
|
+
sum = 0;
|
|
61
|
+
num -= 1;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|