feat: supply process arguments through native startup
This commit is contained in:
@@ -1756,16 +1756,47 @@ configure_entry_point :: proc(checker: ^Checker) {
|
||||
if io_package == ast.INVALID_PACKAGE {
|
||||
return
|
||||
}
|
||||
init_item, init_ok := types.node(&checker.module.types, parameter_type)
|
||||
init_fields := types.fields_for(&checker.module.types, parameter_type)
|
||||
io_field_name := symbol.intern(checker.symbols, "io")
|
||||
if !init_ok || init_item.kind != .Struct || init_item.tuple || init_item.c_layout ||
|
||||
len(init_fields) != 1 || init_fields[0].name != u32(io_field_name) ||
|
||||
!types.equal(types.resolve_alias(init_fields[0].type, &checker.module.types), io_type) {
|
||||
args_name := symbol.intern(checker.symbols, "Args")
|
||||
args_type := types.resolve_alias(
|
||||
types.find_named(&checker.module.types, u32(process_package), u32(args_name)),
|
||||
&checker.module.types,
|
||||
)
|
||||
args_item, args_ok := types.node(&checker.module.types, args_type)
|
||||
args_fields := types.fields_for(&checker.module.types, args_type)
|
||||
values_name := symbol.intern(checker.symbols, "values")
|
||||
argument_pointer := types.pointer(&checker.module.types, types.U8, false, true, true, 0)
|
||||
argument_values := types.slice(&checker.module.types, argument_pointer, false)
|
||||
if !args_ok || args_item.kind != .Struct || args_item.tuple || args_item.c_layout ||
|
||||
len(args_fields) != 1 || args_fields[0].name != u32(values_name) ||
|
||||
!types.equal(types.resolve_alias(args_fields[0].type, &checker.module.types), argument_values) {
|
||||
checker.template_diagnostics[main_template] = source.add(
|
||||
checker.diagnostics,
|
||||
main.span,
|
||||
"@std/process Init must be an auto-layout record containing exactly 'io io.Io'",
|
||||
"@std/process Args must be an auto-layout record containing exactly 'values [][*;0]u8'",
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
init_item, init_ok := types.node(&checker.module.types, parameter_type)
|
||||
init_fields := types.fields_for(&checker.module.types, parameter_type)
|
||||
io_field_name := symbol.intern(checker.symbols, "io")
|
||||
args_field_name := symbol.intern(checker.symbols, "args")
|
||||
io_field_ok, args_field_ok := false, false
|
||||
for field in init_fields {
|
||||
field_type := types.resolve_alias(field.type, &checker.module.types)
|
||||
if field.name == u32(io_field_name) && types.equal(field_type, io_type) {
|
||||
io_field_ok = true
|
||||
}
|
||||
if field.name == u32(args_field_name) && types.equal(field_type, args_type) {
|
||||
args_field_ok = true
|
||||
}
|
||||
}
|
||||
if !init_ok || init_item.kind != .Struct || init_item.tuple || init_item.c_layout ||
|
||||
len(init_fields) != 2 || !io_field_ok || !args_field_ok {
|
||||
checker.template_diagnostics[main_template] = source.add(
|
||||
checker.diagnostics,
|
||||
main.span,
|
||||
"@std/process Init must be an auto-layout record containing exactly 'io io.Io' and 'args Args'",
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user