manual c function interop
This commit is contained in:
@@ -1,15 +1,75 @@
|
||||
package main
|
||||
|
||||
import "./compiler"
|
||||
import "./compiler/linker"
|
||||
import "core:fmt"
|
||||
import "core:os/os2"
|
||||
|
||||
Cli_Options :: struct {
|
||||
input_path: string,
|
||||
output_path: string,
|
||||
link_arguments: []linker.Argument,
|
||||
}
|
||||
|
||||
parse_cli_args :: proc(args: []string, allocator := context.allocator) -> (Cli_Options, bool) {
|
||||
if len(args) < 4 {
|
||||
return {}, false
|
||||
}
|
||||
options := Cli_Options{input_path=args[1]}
|
||||
link_arguments: [dynamic]linker.Argument
|
||||
link_arguments.allocator = allocator
|
||||
output_set := false
|
||||
cursor := 2
|
||||
for cursor < len(args) {
|
||||
option := args[cursor]
|
||||
cursor += 1
|
||||
if cursor >= len(args) {
|
||||
delete(link_arguments)
|
||||
return {}, false
|
||||
}
|
||||
value := args[cursor]
|
||||
cursor += 1
|
||||
switch option {
|
||||
case "-o":
|
||||
if output_set {
|
||||
delete(link_arguments)
|
||||
return {}, false
|
||||
}
|
||||
output_set = true
|
||||
options.output_path = value
|
||||
case "--link":
|
||||
append(&link_arguments, linker.Argument{kind=.Input, value=value})
|
||||
case "--library-path":
|
||||
append(&link_arguments, linker.Argument{kind=.Library_Path, value=value})
|
||||
case "--library":
|
||||
append(&link_arguments, linker.Argument{kind=.Library, value=value})
|
||||
case:
|
||||
delete(link_arguments)
|
||||
return {}, false
|
||||
}
|
||||
}
|
||||
if !output_set || len(options.output_path) == 0 {
|
||||
delete(link_arguments)
|
||||
return {}, false
|
||||
}
|
||||
options.link_arguments = link_arguments[:]
|
||||
return options, true
|
||||
}
|
||||
|
||||
print_usage :: proc() {
|
||||
fmt.eprintln(
|
||||
"usage: brolang <package-directory> -o <executable> [--link <path> | --library-path <dir> | --library <name>]...",
|
||||
)
|
||||
}
|
||||
|
||||
main :: proc() {
|
||||
if len(os2.args) != 4 || os2.args[2] != "-o" {
|
||||
fmt.eprintln("usage: brolang <package-directory> -o <executable>")
|
||||
options, valid := parse_cli_args(os2.args)
|
||||
if !valid {
|
||||
print_usage()
|
||||
os2.exit(2)
|
||||
}
|
||||
status := compiler.compile_package(os2.args[1], os2.args[3])
|
||||
defer delete(options.link_arguments)
|
||||
status := compiler.compile_package(options.input_path, options.output_path, options.link_arguments)
|
||||
if status != 0 {
|
||||
os2.exit(status)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user