parsing.jl 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #======================================================
  2. GLOBAL PARSING
  3. ======================================================#
  4. starpu_parse_key_word_parsing_function = Dict{Symbol, Function}()
  5. """
  6. Translates x Expr into a new StarpuExpr object
  7. """
  8. function starpu_parse(x :: Expr)
  9. if (x.head == :macrocall)
  10. if (x.args[1] != Symbol("@indep"))
  11. error("Only @indep macro, used before a for loop, is allowed ($(x.args[1]) was found)")
  12. end
  13. if (length(x.args) != 2)
  14. error("Invalid usage of @indep macro")
  15. end
  16. return starpu_parse_for(x.args[2], is_independant = true)
  17. end
  18. if !(x.head in keys(starpu_parse_key_word_parsing_function))
  19. return StarpuExprInvalid() #TODO error ?
  20. end
  21. return starpu_parse_key_word_parsing_function[x.head](x)
  22. end
  23. for kw in (:if, :call, :for, :block, :return, :function, :while, :ref)
  24. starpu_parse_key_word_parsing_function[kw] = eval(Symbol(:starpu_parse_, kw))
  25. end
  26. starpu_parse_key_word_parsing_function[:(:)] = starpu_parse_interval
  27. starpu_parse_key_word_parsing_function[:(::)] = starpu_parse_typed
  28. starpu_parse_key_word_parsing_function[:(=)] = starpu_parse_affect
  29. starpu_parse_key_word_parsing_function[:(.)] = starpu_parse_field
  30. """
  31. Executes the starpu_parse function on the following expression,
  32. and returns the obtained StarpuExpr
  33. """
  34. macro parse(x)
  35. y = Expr(:quote, x)
  36. :(starpu_parse($y))
  37. end