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

Compiler crash (segfault) on macro execution #105

Open
kballenegger opened this issue Jun 17, 2014 · 1 comment
Open

Compiler crash (segfault) on macro execution #105

kballenegger opened this issue Jun 17, 2014 · 1 comment

Comments

@kballenegger
Copy link

This code crashes the compiler:

(Search for WTF for the line that crashes the compiler.)

(set! exports {})

; react macros...

(defmacro hash-map-pairs
  "make a hash map from its arguments. each argument is a tuple (key value)"
  [ & args ]
  (let [new-args (map (fn [a] (let [f (first a), s (second a)]
                                `(set! (aget h ~f) ~s)
                                )) args)]
    `(let [h {}] ~@new-args h)
    )
  )

(defmacro def-react-class
  "macro to create a react class"
  [ name & args ]
  (let [; if the second element after the key name is a vector, treat as a fn
        process-value (fn [v] (if (and (vector? (second v)) (second (rest v)))
                                (list `fn (first v) (rest v))
                                (second v)
                                )),
        new-args (map
                  ; map = for each method, make a named property
                  (fn [a] (list (keyword (first a)) (process-value a))) args)
        ]
    `(def ~name (.createClass React (hash-map-pairs ~@new-args)))
    )
  )

(defmacro dom
  "xml el"
  [el-name attrs & body]
  (let [react-full-sym (str 'React.DOM. el-name)]
    (concat `(~react-full-sym ~attrs) body)
    )
  )


;; implementation

;;(def converter (new Showdown.converter))
(def converter {:makeHtml (fn [x] (+ x " - BLAH"))})
(defn md->html
  "convert markdown to html using showdown"
  [md]
  (converter.makeHtml md)
  )

(def-react-class Comment
  (render []
          (dom div {:className :comment}
               (dom div {:className :author}
                    this.props.name)
               (dom div {:className :text}
                    (md->html this.props.text)
                    )
               ))
  (name :hello) ; just to test the macro
  (somevector []) ; just to test the macro
  )

(def-react-class CommentList
  (render []
          (dom div {}
               (Comment)
               (Comment {:name "second", :body "#onetwo\nthree"})
               (Comment {:name "third"})
               )
          )
  )

(def-react-class CommentBox
  (render []
          (dom div {:className :commentBox}
               (dom h1 {} "Comments:") ; WTF this crashes the wisp compiler
               "Comments:"
               (CommentList {:name "World"})
               )
          )
  )

(React.renderComponent
  (CommentBox)
  (document.getElementById "app"))
@Gozala
Copy link
Collaborator

Gozala commented Jul 11, 2014

I am afraid this is caused by a strange error coming from nodejs/node-v0.x-archive#6691 which I was not able to followup in order to find a fix. Also given that v0.11.9 of node no longer has this I was hoping it would be released by the time ppl will notice.

All I can say is that somehow combination of string literals in wisp cause this error :( I hate to say that but simple workaround that worked for me has being changing some docstrings to comments in other cases I just had to rephrase string content to fix the error.

I'm afraid I don't have enough time these days to drill down into this issue, but if one of you want's to dig into to fix, I'd only welcome that. In such case feel free to ping me and I can give some more clues I have that can help resolving this.

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

No branches or pull requests

2 participants