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

Comments: Fix add1Tree cursorize example #252

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

vidsinghal
Copy link
Collaborator

No description provided.

Node -> ...

Every packed input becomes a read cursor. And it takes additional output cursors
for every packed type in the return value. Every packed return value becomes a
(Cursor,Cursor) i.e (start,end). And it returns additional end_of_read cursors
if the functions "traverses" it's input (more details in the paer).

if the functions "traverses" it's input (more details in the paper).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if the functions "traverses" it's input (more details in the paper).
if the functions "traverses" its input (more details in the paper).

@ulysses4ever
Copy link
Collaborator

One day we'll add doctests, and all those commented out examples will be checked... I hope!

@vidsinghal
Copy link
Collaborator Author

vidsinghal commented Feb 9, 2024

To introduce the notion of mutable cursors, would it not be ideal if we just change lout in the example to a mutable cursor since we still want the read cursors to be non-mutable @rrnewton ?
Continuing the example in the Cursorize file.

E.g.

    add1Tree :: Tree -> Tree
    add1Tree tr =
      case tr of
        Leaf n   -> Leaf (n + 1)
        Node l r -> Node (add1Tree l) (add1Tree r)

becomes

    -- char*
    type Cursor = Ptr Char

    add1Tree :: Cursor -> Cursor -> Cursor -> Cursor -> (Cursor,Cursor,Cursor,(Cursor,Cursor))
    add1Tree end_rin end_rout lout lin =
      in case lin of
           Leaf -> let n = readScalar "Int" (lin + 1) 
                       wt = writeTag lout Leaf
                       wi = writeInt wt (n+1)
                   in (lin + 9, (lout, wi))
           Node -> ...

For mutable cursor case, this potentially turns into something like

    -- char*
    type Cursor = Ptr Char
    -- char**
    type MutableCursor = Ptr Ptr Char

    add1Tree :: Cursor -> Cursor -> MutableCursor -> Cursor -> (Cursor,Cursor)
    add1Tree end_rin end_rout lout lin =
      in case lin of
           Leaf -> let n = readScalar "Int" (lin + 1) 
                       wt = writeTag lout Leaf
                       wi = writeInt wt (n+1)
                   in (lout, wi)
           Node -> ...

For the return type, there are 2 possibilities, we could still return the start location and end location of the Packed type (Cursor,Cursor) or make the function a void function.
For the former it might require to pass another argument to thread the start location of the output buffer, in which case it seems like making it void is probably better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants