Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

match windy #63

Merged
merged 1 commit into from
Feb 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions src/puppy/objc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ macro objc*(body: untyped) =
## Takes function declarations and converts them to ObjC calls.

# Header contains all static class lookups and selector registration.
var
header = newStmtList()
var header = newStmtList()

# For each funciton add body and collect its classes and selectors.
# For each function, add body and collect its classes and selectors.
for fn in body:
var
name = fn[0].repr
Expand All @@ -51,10 +50,9 @@ macro objc*(body: untyped) =
classMethod = false
numParams = 0

# echo name
sel.removeSuffix("*")

# Mark each prock inline:
# Mark each proc inline:
fn[4] = quote do: {.inline.}

# Add a template body without the arguments.
Expand All @@ -64,12 +62,13 @@ macro objc*(body: untyped) =
objc_msgSend
)
`msgSend`()

fn[6] = procBody

# Someday we can look at the retType and be smarter but this works well now.
if repr(retType) in ["NSRect"]:
procBody[0][0][2][1] = ident("objc_msgSend_stret")

if repr(retType) in ["float64", "NSPoint"]:
elif repr(retType) in ["float64", "NSPoint"]:
procBody[0][0][2][1] = ident("objc_msgSend_fpret")

# For each argument decide what to do
Expand All @@ -79,13 +78,11 @@ macro objc*(body: untyped) =
argName = repr arg
argType = defs[^2]

# echo " ", argName, ": ", repr argType

if numParams == 0:
if argName notin ["class", "self"]:
error("First arugment needs to be class or self.", arg)
error("First argument needs to be class or self.", arg)

# First argument is very special, its either a class or self ID.
# First argument is very special, it is either a class or self ID.
if argType.kind == nnkBracketExpr:
if argType[0].strVal == "typedesc":
let
Expand Down Expand Up @@ -127,9 +124,6 @@ macro objc*(body: untyped) =

inc numParams

# echo " return ", repr retType
# echo " selector '", sel, "'"

let
selVar = ident("sel" & $numSel)
selStr = newStrLitNode(sel)
Expand All @@ -140,8 +134,6 @@ macro objc*(body: untyped) =

body.insert(0, header)

# echo repr body

return body

type
Expand Down