mt-lang 0.3.14 → 0.3.17
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.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/docs/index.html +8 -8
- data/docs/language-design.md +7 -12
- data/docs/language-manual.md +20 -8
- data/lib/milk_tea/base.rb +1 -1
- data/lib/milk_tea/core/ast.rb +2 -2
- data/lib/milk_tea/core/{binding_types.rb → bindings.rb} +1 -1
- data/lib/milk_tea/core/c_backend.rb +14 -15
- data/lib/milk_tea/core/compile_time.rb +181 -2
- data/lib/milk_tea/core/control_flow/builder.rb +62 -2
- data/lib/milk_tea/core/control_flow/constant_propagation.rb +1 -1
- data/lib/milk_tea/core/{compatibility_helpers.rb → intrinsics.rb} +2 -2
- data/lib/milk_tea/core/lexer.rb +10 -14
- data/lib/milk_tea/core/lowering/async/analysis.rb +3 -9
- data/lib/milk_tea/core/lowering/async/lowering.rb +2 -10
- data/lib/milk_tea/core/lowering/async/normalization.rb +2 -7
- data/lib/milk_tea/core/lowering/block.rb +1 -5
- data/lib/milk_tea/core/lowering/proc.rb +1 -5
- data/lib/milk_tea/core/lowering/scans.rb +3 -1
- data/lib/milk_tea/core/lowering/utils.rb +1 -27
- data/lib/milk_tea/core/lowering.rb +18 -18
- data/lib/milk_tea/core/module_loader.rb +26 -15
- data/lib/milk_tea/core/parser/statements.rb +18 -12
- data/lib/milk_tea/core/parser.rb +17 -17
- data/lib/milk_tea/core/pretty_printer/ast_formatter.rb +3 -11
- data/lib/milk_tea/core/semantic_analyzer/analysis_context.rb +2 -3
- data/lib/milk_tea/core/semantic_analyzer/flow_refinement.rb +1 -1
- data/lib/milk_tea/core/semantic_analyzer/function_binding.rb +1 -2
- data/lib/milk_tea/core/semantic_analyzer/nullability.rb +2 -4
- data/lib/milk_tea/core/semantic_analyzer/statements.rb +2 -8
- data/lib/milk_tea/core/semantic_analyzer.rb +1 -1
- data/lib/milk_tea/core.rb +6 -2
- data/lib/milk_tea/dap/lldb_dap_backend.rb +153 -0
- data/lib/milk_tea/dap/server/lldb_backend.rb +1 -1
- data/lib/milk_tea/dap.rb +1 -1
- data/lib/milk_tea/lsp.rb +1 -7
- data/lib/milk_tea/{bindings/cli.rb → tooling/bindgen_cli.rb} +1 -1
- data/lib/milk_tea/tooling/linter/imports_platform.rb +2 -4
- data/lib/milk_tea/tooling/linter/release_rules.rb +1 -6
- data/lib/milk_tea/tooling/linter/source_helpers.rb +0 -6
- data/lib/milk_tea/tooling/linter/visitors.rb +4 -8
- data/lib/milk_tea/tooling/sexpr_dumper.rb +2 -0
- data/lib/milk_tea/tooling.rb +1 -1
- data/std/asset_pack.mt +1 -1
- data/std/async/libuv_runtime.mt +6 -6
- data/std/async/mailbox.mt +4 -4
- data/std/cookie.mt +2 -2
- data/std/crypto.mt +1 -1
- data/std/curl/runtime.mt +10 -10
- data/std/fs.linux.mt +26 -26
- data/std/fs.windows.mt +22 -22
- data/std/goap.mt +2 -2
- data/std/http/server.mt +21 -21
- data/std/http.mt +14 -14
- data/std/jobs.mt +4 -4
- data/std/json.mt +5 -5
- data/std/log.mt +1 -1
- data/std/mem/tracking.mt +1 -1
- data/std/net/channel.mt +4 -4
- data/std/net/clock.mt +6 -6
- data/std/net/discovery.mt +7 -7
- data/std/net/lobby.mt +10 -10
- data/std/net/manager.mt +1 -1
- data/std/net/mux.mt +4 -4
- data/std/net/nat.mt +4 -4
- data/std/net/packet.mt +3 -3
- data/std/net/punch.mt +3 -3
- data/std/net/rpc.mt +3 -3
- data/std/net/session.mt +15 -15
- data/std/net/stun.mt +4 -4
- data/std/net/turn.mt +4 -4
- data/std/oauth2.mt +12 -12
- data/std/path.mt +8 -8
- data/std/process.mt +4 -4
- data/std/raylib/packed_assets.mt +5 -5
- data/std/serialize.mt +1 -1
- data/std/tar.mt +10 -10
- data/std/terminal.mt +18 -18
- data/std/tls.mt +8 -8
- data/std/uri.mt +1 -1
- data/std/utility.mt +1 -1
- metadata +7 -9
- data/lib/milk_tea/core/compile_time/const_eval.rb +0 -182
- data/lib/milk_tea/core/module_loader/errors.rb +0 -23
- data/lib/milk_tea/dap/backends/lldb_dap.rb +0 -156
- /data/lib/milk_tea/core/lowering/{async.rb → async/frame_builder.rb} +0 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "open3"
|
|
4
|
+
require "thread"
|
|
5
|
+
require "timeout"
|
|
6
|
+
|
|
7
|
+
module MilkTea
|
|
8
|
+
module DAP
|
|
9
|
+
class LLDBDAPBackend
|
|
10
|
+
def initialize(adapter_command: ["lldb-dap"], on_event: nil, on_request: nil)
|
|
11
|
+
@adapter_command = adapter_command
|
|
12
|
+
@on_event = on_event
|
|
13
|
+
@on_request = on_request
|
|
14
|
+
@protocol = nil
|
|
15
|
+
@stdin = nil
|
|
16
|
+
@stdout = nil
|
|
17
|
+
@stderr = nil
|
|
18
|
+
@wait_thread = nil
|
|
19
|
+
@reader_thread = nil
|
|
20
|
+
@stderr_thread = nil
|
|
21
|
+
@write_mutex = Mutex.new
|
|
22
|
+
@pending_mutex = Mutex.new
|
|
23
|
+
@pending = {}
|
|
24
|
+
@next_seq = 1
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def start!
|
|
28
|
+
return if running?
|
|
29
|
+
|
|
30
|
+
@stdin, @stdout, @stderr, @wait_thread = Open3.popen3(*@adapter_command)
|
|
31
|
+
@protocol = Protocol.new(input: @stdout, output: @stdin)
|
|
32
|
+
|
|
33
|
+
@reader_thread = Thread.new { read_loop }
|
|
34
|
+
@stderr_thread = Thread.new { drain_stderr }
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def running?
|
|
38
|
+
!@wait_thread.nil? && @wait_thread.alive?
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def request(command, arguments = {}, timeout: 5)
|
|
42
|
+
start! unless running?
|
|
43
|
+
|
|
44
|
+
seq = next_seq
|
|
45
|
+
queue = Queue.new
|
|
46
|
+
@pending_mutex.synchronize do
|
|
47
|
+
@pending[seq] = queue
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
@write_mutex.synchronize do
|
|
51
|
+
@protocol.write_message({
|
|
52
|
+
seq: seq,
|
|
53
|
+
type: "request",
|
|
54
|
+
command: command,
|
|
55
|
+
arguments: arguments
|
|
56
|
+
})
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
Timeout.timeout(timeout) { queue.pop }
|
|
60
|
+
rescue Timeout::Error
|
|
61
|
+
{
|
|
62
|
+
"type" => "response",
|
|
63
|
+
"request_seq" => seq,
|
|
64
|
+
"success" => false,
|
|
65
|
+
"message" => "backend request timed out: #{command}"
|
|
66
|
+
}
|
|
67
|
+
ensure
|
|
68
|
+
@pending_mutex.synchronize { @pending.delete(seq) }
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def stop!
|
|
72
|
+
@stdin&.close
|
|
73
|
+
@stdout&.close
|
|
74
|
+
@stderr&.close
|
|
75
|
+
if @wait_thread&.alive?
|
|
76
|
+
Process.kill("TERM", @wait_thread.pid)
|
|
77
|
+
end
|
|
78
|
+
rescue StandardError
|
|
79
|
+
nil
|
|
80
|
+
ensure
|
|
81
|
+
@wait_thread&.join(0.2)
|
|
82
|
+
@reader_thread&.join(0.2)
|
|
83
|
+
@stderr_thread&.join(0.2)
|
|
84
|
+
@stdin = nil
|
|
85
|
+
@stdout = nil
|
|
86
|
+
@stderr = nil
|
|
87
|
+
@wait_thread = nil
|
|
88
|
+
@reader_thread = nil
|
|
89
|
+
@stderr_thread = nil
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def next_seq
|
|
93
|
+
seq = @next_seq
|
|
94
|
+
@next_seq += 1
|
|
95
|
+
seq
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def read_loop
|
|
99
|
+
loop do
|
|
100
|
+
message = @protocol.read_message
|
|
101
|
+
break if message.nil?
|
|
102
|
+
|
|
103
|
+
if message["type"] == "response"
|
|
104
|
+
queue = @pending_mutex.synchronize { @pending[message["request_seq"]] }
|
|
105
|
+
queue&.push(message)
|
|
106
|
+
elsif message["type"] == "event"
|
|
107
|
+
@on_event&.call(message)
|
|
108
|
+
elsif message["type"] == "request"
|
|
109
|
+
handle_adapter_request(message)
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
rescue StandardError
|
|
113
|
+
nil
|
|
114
|
+
ensure
|
|
115
|
+
@pending_mutex.synchronize do
|
|
116
|
+
@pending.each_value do |queue|
|
|
117
|
+
queue.push({
|
|
118
|
+
"type" => "response",
|
|
119
|
+
"success" => false,
|
|
120
|
+
"message" => "backend closed"
|
|
121
|
+
})
|
|
122
|
+
end
|
|
123
|
+
@pending.clear
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def drain_stderr
|
|
128
|
+
return unless @stderr
|
|
129
|
+
|
|
130
|
+
@stderr.each_line do |_line|
|
|
131
|
+
# Intentionally ignored in this bridge layer.
|
|
132
|
+
end
|
|
133
|
+
rescue StandardError
|
|
134
|
+
nil
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def handle_adapter_request(message)
|
|
138
|
+
response = @on_request&.call(message)
|
|
139
|
+
response ||= {
|
|
140
|
+
"type" => "response",
|
|
141
|
+
"request_seq" => message["seq"],
|
|
142
|
+
"success" => false,
|
|
143
|
+
"command" => message["command"],
|
|
144
|
+
"message" => "unsupported reverse request: #{message['command']}"
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
@write_mutex.synchronize do
|
|
148
|
+
@protocol.write_message(response)
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
end
|
|
@@ -22,7 +22,7 @@ module MilkTea
|
|
|
22
22
|
@lldb_backend = if @backend_factory
|
|
23
23
|
build_backend_via_factory(adapter_command)
|
|
24
24
|
else
|
|
25
|
-
|
|
25
|
+
LLDBDAPBackend.new(
|
|
26
26
|
adapter_command: adapter_command,
|
|
27
27
|
on_event: method(:handle_backend_event),
|
|
28
28
|
on_request: method(:handle_backend_request)
|
data/lib/milk_tea/dap.rb
CHANGED
data/lib/milk_tea/lsp.rb
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
module MilkTea
|
|
4
|
-
module LSP
|
|
5
|
-
# LSP implementation - language server protocol support
|
|
6
|
-
end
|
|
7
|
-
end
|
|
8
|
-
|
|
9
3
|
require_relative 'lsp/protocol'
|
|
10
4
|
require_relative 'lsp/dependency_resolution'
|
|
11
5
|
require_relative 'lsp/workspace'
|
|
12
6
|
require_relative 'lsp/diagnostics'
|
|
13
|
-
require_relative 'lsp/server'
|
|
7
|
+
require_relative 'lsp/server'
|
|
@@ -484,8 +484,7 @@ module MilkTea
|
|
|
484
484
|
when AST::UnsafeStmt
|
|
485
485
|
stmt.body.each { |child| collect_indirect_import_uses_from_stmt(child, used, binding_resolution, import_module_names) }
|
|
486
486
|
when AST::DeferStmt
|
|
487
|
-
|
|
488
|
-
stmt.body&.each { |child| collect_indirect_import_uses_from_stmt(child, used, binding_resolution, import_module_names) }
|
|
487
|
+
stmt.body.each { |child| collect_indirect_import_uses_from_stmt(child, used, binding_resolution, import_module_names) }
|
|
489
488
|
when AST::ReturnStmt
|
|
490
489
|
collect_indirect_import_uses_from_expr(stmt.value, used, binding_resolution, import_module_names) if stmt.value
|
|
491
490
|
when AST::ExpressionStmt
|
|
@@ -766,8 +765,7 @@ module MilkTea
|
|
|
766
765
|
when AST::UnsafeStmt
|
|
767
766
|
stmt.body.each { |s| collect_names_from_statement(s, used) }
|
|
768
767
|
when AST::DeferStmt
|
|
769
|
-
|
|
770
|
-
stmt.body&.each { |s| collect_names_from_statement(s, used) }
|
|
768
|
+
stmt.body.each { |s| collect_names_from_statement(s, used) }
|
|
771
769
|
when AST::ReturnStmt
|
|
772
770
|
collect_names_from_expr(stmt.value, used) if stmt.value
|
|
773
771
|
when AST::ExpressionStmt
|
|
@@ -169,9 +169,6 @@ module MilkTea
|
|
|
169
169
|
when AST::UnsafeStmt
|
|
170
170
|
_collect_own_released_names(stmt.body, result)
|
|
171
171
|
when AST::DeferStmt
|
|
172
|
-
if stmt.expression
|
|
173
|
-
_collect_heap_release_names(stmt.expression, result)
|
|
174
|
-
end
|
|
175
172
|
_collect_own_released_names(stmt.body, result) if stmt.body.is_a?(Array)
|
|
176
173
|
end
|
|
177
174
|
end
|
|
@@ -476,7 +473,6 @@ module MilkTea
|
|
|
476
473
|
when AST::UnsafeStmt
|
|
477
474
|
_collect_released_names(stmt.body, result)
|
|
478
475
|
when AST::DeferStmt
|
|
479
|
-
_collect_released_names_in_expr(stmt.expression, result) if stmt.expression
|
|
480
476
|
_collect_released_names(stmt.body, result) if stmt.body.is_a?(Array)
|
|
481
477
|
end
|
|
482
478
|
end
|
|
@@ -611,9 +607,8 @@ module MilkTea
|
|
|
611
607
|
def release_call_in_stmt?(stmt, name)
|
|
612
608
|
return false unless stmt
|
|
613
609
|
|
|
614
|
-
# DeferStmt:
|
|
610
|
+
# DeferStmt: block form `defer: …` (inline defers are a single-statement body)
|
|
615
611
|
if stmt.is_a?(AST::DeferStmt)
|
|
616
|
-
return true if stmt.expression && _expr_has_release?(stmt.expression, name)
|
|
617
612
|
return stmt.body.is_a?(Array) && stmt.body.any? { |s| release_call_in_stmt?(s, name) }
|
|
618
613
|
end
|
|
619
614
|
|
|
@@ -240,8 +240,6 @@ module MilkTea
|
|
|
240
240
|
expression_column(statement.expression)
|
|
241
241
|
when AST::ReturnStmt
|
|
242
242
|
expression_column(statement.value)
|
|
243
|
-
when AST::DeferStmt
|
|
244
|
-
expression_column(statement.expression)
|
|
245
243
|
when AST::ExpressionStmt
|
|
246
244
|
expression_column(statement.expression) || source_statement_span(statement.line)&.first
|
|
247
245
|
else
|
|
@@ -267,8 +265,6 @@ module MilkTea
|
|
|
267
265
|
expression_length(statement.expression)
|
|
268
266
|
when AST::ReturnStmt
|
|
269
267
|
expression_length(statement.value)
|
|
270
|
-
when AST::DeferStmt
|
|
271
|
-
expression_length(statement.expression)
|
|
272
268
|
when AST::ExpressionStmt
|
|
273
269
|
expression_length(statement.expression) || source_statement_span(statement.line)&.last
|
|
274
270
|
else
|
|
@@ -326,8 +322,6 @@ module MilkTea
|
|
|
326
322
|
walk_expression_tree(statement.expression, &block)
|
|
327
323
|
when AST::ReturnStmt
|
|
328
324
|
walk_expression_tree(statement.value, &block)
|
|
329
|
-
when AST::DeferStmt
|
|
330
|
-
walk_expression_tree(statement.expression, &block)
|
|
331
325
|
when AST::ExpressionStmt
|
|
332
326
|
walk_expression_tree(statement.expression, &block)
|
|
333
327
|
when AST::StaticAssert
|
|
@@ -225,8 +225,7 @@ module MilkTea
|
|
|
225
225
|
visit_expression(statement.value) if statement.value
|
|
226
226
|
flag_redundant_widening_cast(statement.value) if statement.value
|
|
227
227
|
when AST::DeferStmt
|
|
228
|
-
|
|
229
|
-
with_scope { visit_statement_list(statement.body) } if statement.body
|
|
228
|
+
with_scope { visit_statement_list(statement.body) }
|
|
230
229
|
when AST::ExpressionStmt
|
|
231
230
|
visit_expression(statement.expression)
|
|
232
231
|
check_useless_expression(statement)
|
|
@@ -1252,8 +1251,7 @@ module MilkTea
|
|
|
1252
1251
|
when AST::UnsafeStmt
|
|
1253
1252
|
stmt.body.each { |s| collect_borrows_from_stmt(s, names) }
|
|
1254
1253
|
when AST::DeferStmt
|
|
1255
|
-
|
|
1256
|
-
stmt.body&.each { |s| collect_borrows_from_stmt(s, names) }
|
|
1254
|
+
stmt.body.each { |s| collect_borrows_from_stmt(s, names) }
|
|
1257
1255
|
when AST::WhenStmt
|
|
1258
1256
|
collect_borrows_from_expr(stmt.discriminant, names)
|
|
1259
1257
|
stmt.branches.each { |b| b.body.each { |s| collect_borrows_from_stmt(s, names) } }
|
|
@@ -1319,7 +1317,7 @@ module MilkTea
|
|
|
1319
1317
|
when AST::UnsafeStmt
|
|
1320
1318
|
stmt.body.each { |s| collect_writes_from_stmt(s, names) }
|
|
1321
1319
|
when AST::DeferStmt
|
|
1322
|
-
stmt.body
|
|
1320
|
+
stmt.body.each { |s| collect_writes_from_stmt(s, names) }
|
|
1323
1321
|
end
|
|
1324
1322
|
end
|
|
1325
1323
|
|
|
@@ -1376,9 +1374,7 @@ module MilkTea
|
|
|
1376
1374
|
stmt.body.each { |s| location = find_borrow_location_in_stmt(s, name); return location if location }
|
|
1377
1375
|
nil
|
|
1378
1376
|
when AST::DeferStmt
|
|
1379
|
-
location =
|
|
1380
|
-
return location if location
|
|
1381
|
-
stmt.body&.each { |s| location = find_borrow_location_in_stmt(s, name); return location if location }
|
|
1377
|
+
stmt.body.each { |s| location = find_borrow_location_in_stmt(s, name); return location if location }
|
|
1382
1378
|
nil
|
|
1383
1379
|
when AST::WhenStmt
|
|
1384
1380
|
location = find_borrow_location_in_expr(stmt.discriminant, name)
|
|
@@ -38,6 +38,7 @@ module MilkTea
|
|
|
38
38
|
when Float then buf << format_float(value)
|
|
39
39
|
when String then emit_string(value, buf)
|
|
40
40
|
when Symbol then buf << ":" << value.to_s.tr("_", "-")
|
|
41
|
+
when Hash, Set then nil
|
|
41
42
|
else buf << escape_string(value.to_s)
|
|
42
43
|
end
|
|
43
44
|
end
|
|
@@ -50,6 +51,7 @@ module MilkTea
|
|
|
50
51
|
buf << "(" << type_name
|
|
51
52
|
members.each do |field|
|
|
52
53
|
val = node.public_send(field)
|
|
54
|
+
next if val.is_a?(Hash) || val.is_a?(Set)
|
|
53
55
|
buf << " :" << field.to_s << " "
|
|
54
56
|
emit_value(val, buf)
|
|
55
57
|
end
|
data/lib/milk_tea/tooling.rb
CHANGED
|
@@ -18,5 +18,5 @@ require_relative "tooling/linter"
|
|
|
18
18
|
require_relative "tooling/docs_app"
|
|
19
19
|
require_relative "tooling/project_scaffold"
|
|
20
20
|
require_relative "tooling/toolchain_cli"
|
|
21
|
-
require_relative "
|
|
21
|
+
require_relative "tooling/bindgen_cli"
|
|
22
22
|
require_relative "tooling/cli"
|
data/std/asset_pack.mt
CHANGED
|
@@ -187,7 +187,7 @@ function read_entry_metadata(file: stdio.File?) -> Result[EntryMetadata, Error]:
|
|
|
187
187
|
|
|
188
188
|
function read_path_matches(file: stdio.File?, path_length: ptr_uint, logical_path: str) -> Result[bool, Error]:
|
|
189
189
|
let path_buffer = heap.must_alloc[ubyte](path_length)
|
|
190
|
-
defer heap.release(path_buffer)
|
|
190
|
+
defer: heap.release(path_buffer)
|
|
191
191
|
|
|
192
192
|
if not read_exact(file, path_buffer, path_length):
|
|
193
193
|
return Result[bool, Error].failure(error= Error.malformed_index)
|
data/std/async/libuv_runtime.mt
CHANGED
|
@@ -475,7 +475,7 @@ public function result[T](task: Task[T]) -> T:
|
|
|
475
475
|
if not completed[T](task):
|
|
476
476
|
fatal(c"async.result called before task completed")
|
|
477
477
|
|
|
478
|
-
defer task.release(task.frame)
|
|
478
|
+
defer: task.release(task.frame)
|
|
479
479
|
return task.take_result(task.frame)
|
|
480
480
|
|
|
481
481
|
|
|
@@ -484,7 +484,7 @@ public function wait_on[T](runtime: Runtime, task: Task[T]) -> T:
|
|
|
484
484
|
while not task.ready(task.frame):
|
|
485
485
|
runtime_poll(runtime)
|
|
486
486
|
|
|
487
|
-
defer task.release(task.frame)
|
|
487
|
+
defer: task.release(task.frame)
|
|
488
488
|
return task.take_result(task.frame)
|
|
489
489
|
|
|
490
490
|
|
|
@@ -503,7 +503,7 @@ public function wait[T](root: proc() -> Task[T]) -> T:
|
|
|
503
503
|
|
|
504
504
|
var runtime = runtime_create()
|
|
505
505
|
runtime_activate(runtime)
|
|
506
|
-
defer runtime_release(ref_of(runtime))
|
|
506
|
+
defer: runtime_release(ref_of(runtime))
|
|
507
507
|
return wait_on[T](runtime, root())
|
|
508
508
|
|
|
509
509
|
|
|
@@ -514,7 +514,7 @@ public function run(root: proc() -> Task[void]) -> void:
|
|
|
514
514
|
|
|
515
515
|
var runtime = runtime_create()
|
|
516
516
|
runtime_activate(runtime)
|
|
517
|
-
defer runtime_release(ref_of(runtime))
|
|
517
|
+
defer: runtime_release(ref_of(runtime))
|
|
518
518
|
run_on(runtime, root())
|
|
519
519
|
|
|
520
520
|
|
|
@@ -524,7 +524,7 @@ public function with_runtime[T](body: proc(runtime: Runtime) -> T) -> T:
|
|
|
524
524
|
|
|
525
525
|
var runtime = runtime_create()
|
|
526
526
|
runtime_activate(runtime)
|
|
527
|
-
defer runtime_release(ref_of(runtime))
|
|
527
|
+
defer: runtime_release(ref_of(runtime))
|
|
528
528
|
return body(runtime)
|
|
529
529
|
|
|
530
530
|
|
|
@@ -535,5 +535,5 @@ public function run_with_runtime(body: proc(runtime: Runtime) -> void) -> void:
|
|
|
535
535
|
|
|
536
536
|
var runtime = runtime_create()
|
|
537
537
|
runtime_activate(runtime)
|
|
538
|
-
defer runtime_release(ref_of(runtime))
|
|
538
|
+
defer: runtime_release(ref_of(runtime))
|
|
539
539
|
body(runtime)
|
data/std/async/mailbox.mt
CHANGED
|
@@ -138,7 +138,7 @@ extending Mailbox[T]:
|
|
|
138
138
|
|
|
139
139
|
var mutex = unsafe: read(state).mutex
|
|
140
140
|
mutex.lock()
|
|
141
|
-
defer mutex.unlock()
|
|
141
|
+
defer: mutex.unlock()
|
|
142
142
|
|
|
143
143
|
let handle = unsafe: read(state).handle else:
|
|
144
144
|
return Result[bool, Error].failure(error = mailbox_error("mailbox is closed"))
|
|
@@ -161,7 +161,7 @@ extending Mailbox[T]:
|
|
|
161
161
|
|
|
162
162
|
var mutex = unsafe: read(state).mutex
|
|
163
163
|
mutex.lock()
|
|
164
|
-
defer mutex.unlock()
|
|
164
|
+
defer: mutex.unlock()
|
|
165
165
|
return unsafe: read(state).queue.pop_front()
|
|
166
166
|
|
|
167
167
|
|
|
@@ -171,7 +171,7 @@ extending Mailbox[T]:
|
|
|
171
171
|
|
|
172
172
|
var mutex = unsafe: read(state).mutex
|
|
173
173
|
mutex.lock()
|
|
174
|
-
defer mutex.unlock()
|
|
174
|
+
defer: mutex.unlock()
|
|
175
175
|
|
|
176
176
|
var drained = vec.Vec[T].with_capacity(unsafe: read(state).queue.len())
|
|
177
177
|
while true:
|
|
@@ -187,5 +187,5 @@ extending Mailbox[T]:
|
|
|
187
187
|
|
|
188
188
|
var mutex = unsafe: read(state).mutex
|
|
189
189
|
mutex.lock()
|
|
190
|
-
defer mutex.unlock()
|
|
190
|
+
defer: mutex.unlock()
|
|
191
191
|
return unsafe: read(state).queue.is_empty()
|
data/std/cookie.mt
CHANGED
|
@@ -94,7 +94,7 @@ function apply_attribute(cookie: ref[Cookie], attribute_text: str) -> void:
|
|
|
94
94
|
match eq:
|
|
95
95
|
Option.none:
|
|
96
96
|
var normalized = ascii_lower(attribute_text)
|
|
97
|
-
defer normalized.release()
|
|
97
|
+
defer: normalized.release()
|
|
98
98
|
|
|
99
99
|
if normalized.as_str().equal("secure"):
|
|
100
100
|
cookie.secure = true
|
|
@@ -106,7 +106,7 @@ function apply_attribute(cookie: ref[Cookie], attribute_text: str) -> void:
|
|
|
106
106
|
let value_text = attribute_text.slice(e.value + 1, attribute_text.len - e.value - 1).trim_ascii_whitespace()
|
|
107
107
|
|
|
108
108
|
var normalized_key = ascii_lower(key_text)
|
|
109
|
-
defer normalized_key.release()
|
|
109
|
+
defer: normalized_key.release()
|
|
110
110
|
|
|
111
111
|
if normalized_key.as_str().equal("domain"):
|
|
112
112
|
cookie.domain = Option[string.String].some(value = string.String.from_str(value_text))
|
data/std/crypto.mt
CHANGED
|
@@ -23,7 +23,7 @@ public function sha256(data: span[ubyte]) -> bytes.Bytes:
|
|
|
23
23
|
|
|
24
24
|
public function sha256_to_str(data: span[ubyte]) -> string.String:
|
|
25
25
|
var digest = sha256(data)
|
|
26
|
-
defer digest.release()
|
|
26
|
+
defer: digest.release()
|
|
27
27
|
|
|
28
28
|
var result = string.String.with_capacity(raw.SHA256_DIGEST_LENGTH * 2)
|
|
29
29
|
var index: ptr_uint = 0
|
data/std/curl/runtime.mt
CHANGED
|
@@ -69,21 +69,21 @@ public function get_bytes(url: str) -> Result[bytes.Bytes, curl.Code]:
|
|
|
69
69
|
return Result[bytes.Bytes, curl.Code].failure(error= curl.Code<-CURLE_URL_MALFORMAT_CODE)
|
|
70
70
|
|
|
71
71
|
var scratch = arena.create(url.len + 1)
|
|
72
|
-
defer scratch.release()
|
|
72
|
+
defer: scratch.release()
|
|
73
73
|
|
|
74
74
|
let url_cstr = scratch.to_cstr(url)
|
|
75
75
|
|
|
76
76
|
let global_status = curl.global_init(curl.CURL_GLOBAL_NOTHING)
|
|
77
77
|
if int<-global_status != CURLE_OK_CODE:
|
|
78
78
|
return Result[bytes.Bytes, curl.Code].failure(error= global_status)
|
|
79
|
-
defer curl.global_cleanup()
|
|
79
|
+
defer: curl.global_cleanup()
|
|
80
80
|
|
|
81
81
|
let handle = curl.easy_init() else:
|
|
82
82
|
return Result[bytes.Bytes, curl.Code].failure(error= curl.Code<-CURLE_FAILED_INIT_CODE)
|
|
83
|
-
defer curl.easy_cleanup(handle)
|
|
83
|
+
defer: curl.easy_cleanup(handle)
|
|
84
84
|
|
|
85
85
|
var body = vec.Vec[ubyte].create()
|
|
86
|
-
defer body.release()
|
|
86
|
+
defer: body.release()
|
|
87
87
|
|
|
88
88
|
let write_function_status = easy_setopt_writefunction(handle, write_response_chunk)
|
|
89
89
|
if int<-write_function_status != CURLE_OK_CODE:
|
|
@@ -199,7 +199,7 @@ function do_request(
|
|
|
199
199
|
let global_status = curl.global_init(curl.CURL_GLOBAL_NOTHING)
|
|
200
200
|
if int<-global_status != CURLE_OK_CODE:
|
|
201
201
|
return Result[HttpResponse, HttpError].failure(error = http_error(global_status))
|
|
202
|
-
defer curl.global_cleanup()
|
|
202
|
+
defer: curl.global_cleanup()
|
|
203
203
|
|
|
204
204
|
let handle = curl.easy_init() else:
|
|
205
205
|
return Result[HttpResponse, HttpError].failure(
|
|
@@ -208,10 +208,10 @@ function do_request(
|
|
|
208
208
|
message = string.String.from_str("curl_easy_init failed")
|
|
209
209
|
)
|
|
210
210
|
)
|
|
211
|
-
defer curl.easy_cleanup(handle)
|
|
211
|
+
defer: curl.easy_cleanup(handle)
|
|
212
212
|
|
|
213
213
|
var buffer = vec.Vec[ubyte].create()
|
|
214
|
-
defer buffer.release()
|
|
214
|
+
defer: buffer.release()
|
|
215
215
|
|
|
216
216
|
let _wfn = easy_setopt_writefunction(handle, write_response_chunk)
|
|
217
217
|
let _wdata = easy_setopt_writedata(handle, unsafe: ptr[void]<-ptr_of(buffer))
|
|
@@ -225,7 +225,7 @@ function do_request(
|
|
|
225
225
|
)
|
|
226
226
|
|
|
227
227
|
var scratch = arena.create(url.len + 1)
|
|
228
|
-
defer scratch.release()
|
|
228
|
+
defer: scratch.release()
|
|
229
229
|
|
|
230
230
|
let url_cstr = scratch.to_cstr(url)
|
|
231
231
|
let _url = easy_setopt_url(handle, url_cstr)
|
|
@@ -237,12 +237,12 @@ function do_request(
|
|
|
237
237
|
if body.is_some():
|
|
238
238
|
let body_content = body.unwrap()
|
|
239
239
|
var body_scratch = arena.create(body_content.len + 1)
|
|
240
|
-
defer body_scratch.release()
|
|
240
|
+
defer: body_scratch.release()
|
|
241
241
|
let _pf = easy_setopt_postfields(handle, body_scratch.to_cstr(body_content))
|
|
242
242
|
|
|
243
243
|
if method.len > 0 and not method.starts_with("GET"):
|
|
244
244
|
var method_scratch = arena.create(method.len + 1)
|
|
245
|
-
defer method_scratch.release()
|
|
245
|
+
defer: method_scratch.release()
|
|
246
246
|
let _method = easy_setopt_customrequest(handle, method_scratch.to_cstr(method))
|
|
247
247
|
|
|
248
248
|
if method.starts_with("HEAD"):
|