Skip to content

Commit

Permalink
generate: Further iteration on function support
Browse files Browse the repository at this point in the history
  • Loading branch information
tmc committed Sep 3, 2023
1 parent c7397a7 commit c8f5646
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 116 deletions.
19 changes: 17 additions & 2 deletions generate/codegen/gen_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ var reservedWords = map[string]bool{
"type": true,
}

var typeMap = map[string]string{
"*kernel.Boolean_t": "*int",
"*kernel.UniChar": "*uint16",
"kernel.Boolean_t": "int",
"kernel.Pid_t": "int32",
}

// GoArgs return go function args
func (f *Function) GoArgs(currentModule *modules.Module) string {
log.Println("rendering function", f.Name)
Expand All @@ -54,7 +61,11 @@ func (f *Function) GoArgs(currentModule *modules.Module) string {
p.Name = fmt.Sprintf("arg%d", blankArgCounter)
blankArgCounter++
}
args = append(args, fmt.Sprintf("%s %s", p.Name, p.Type.GoName(currentModule, true)))
typ := p.Type.GoName(currentModule, false)
if v, ok := typeMap[typ]; ok {
typ = v
}
args = append(args, fmt.Sprintf("%s %s", p.Name, typ))
}
return strings.Join(args, ", ")
}
Expand All @@ -65,7 +76,11 @@ func (f *Function) GoReturn(currentModule *modules.Module) string {
return ""
}
// log.Printf("rendering GoReturn function return: %s %T", f.ReturnType, f.ReturnType)
return f.ReturnType.GoName(currentModule, true)
typ := f.ReturnType.GoName(currentModule, true)
if v, ok := typeMap[typ]; ok {
typ = v
}
return typ
}

// CArgs return go function args
Expand Down
9 changes: 8 additions & 1 deletion generate/codegen/modulewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,11 @@ func shouldSkipFunction(f *Function) bool {
return true
}
if _, ok := map[string]bool{
"CGDirectDisplayCopyCurrentMetalDevice": true,
"CGDirectDisplayCopyCurrentMetalDevice": true,
"CGColorSpaceCreateWithPropertyList": true,
"CGDisplayIOServicePort": true,
"CGGetEventTapList": true,
"CGColorConversionInfoCreateFromListWithArguments": true,
}[f.Name]; ok {
return true
}
Expand Down Expand Up @@ -234,6 +238,9 @@ func (m *ModuleWriter) WriteFunctionWrappers() {
//TODO: determine appropriate imports
cw.WriteLineF("#import \"%s\"", m.Module.Header)
for _, f := range m.Functions {
if shouldSkipFunction(f) {
continue
}
f.WriteObjcWrapper(&m.Module, cw)
}
}
Expand Down
34 changes: 19 additions & 15 deletions macos/corefoundation/corefoundation_structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,28 @@ import (
"unsafe"
)

type RunLoopRef = unsafe.Pointer
type TypeRef = unsafe.Pointer
type StringRef = unsafe.Pointer
type ReadStreamRef = unsafe.Pointer
type AllocatorRef = unsafe.Pointer
type RunLoopObserverRef = unsafe.Pointer
type RunLoopTimerRef = unsafe.Pointer
type XMLExternalID = unsafe.Pointer
type ArrayRef = unsafe.Pointer
type DataRef = unsafe.Pointer
type DateRef = unsafe.Pointer
type DictionaryRef = unsafe.Pointer
type FileDescriptorRef = unsafe.Pointer
type MachPortRef = unsafe.Pointer
type MessagePortRef = unsafe.Pointer
type NotificationCenterRef = unsafe.Pointer
type UserNotificationRef = unsafe.Pointer
type NotificationName = unsafe.Pointer
type DictionaryRef = unsafe.Pointer
type MessagePortRef = unsafe.Pointer
type DataRef = unsafe.Pointer
type SocketRef = unsafe.Pointer
type WriteStreamRef = unsafe.Pointer
type FileDescriptorRef = unsafe.Pointer
type PlugInInstanceRef = unsafe.Pointer
type PropertyListRef = unsafe.Pointer
type ReadStreamRef = unsafe.Pointer
type RunLoopObserverRef = unsafe.Pointer
type RunLoopRef = unsafe.Pointer
type RunLoopSourceRef = unsafe.Pointer
type RunLoopTimerRef = unsafe.Pointer
type SocketRef = unsafe.Pointer
type StringRef = unsafe.Pointer
type TypeRef = unsafe.Pointer
type URLRef = unsafe.Pointer
type UUIDRef = unsafe.Pointer
type ArrayRef = unsafe.Pointer
type UserNotificationRef = unsafe.Pointer
type WriteStreamRef = unsafe.Pointer
type XMLExternalID = unsafe.Pointer
5 changes: 5 additions & 0 deletions macos/coregraphics/coregraphics_structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ type Rect struct {
Size Size
}

type Vector struct {
Dx Float
Dy Float
}

type Size struct {
Width Float
Height Float
Expand Down
Loading

0 comments on commit c8f5646

Please sign in to comment.