SMProxy

Untitled

May 13th, 2012
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. Macros with unlimited parameters (organic specification draft)
  2.  
  3. For any macro, the final parameter's name may have "..." appended to it, which will signal that any number of parameters may follow.
  4. Here is an example macro that uses that syntax:
  5.  
  6. .macro example(arg1,arg2,args...)
  7. SET arg1, arg2
  8. ADD PC, args[0]
  9. .endmacro
  10.  
  11. Any argument that falls within the ellipsized parameter may be indexed with [], starting from zero.
  12. Additionally, args_length will be defined implicitly with the total number of provided arguments.
  13.  
  14. To assist in making such a feature useful, certain directives should be added:
  15.  
  16. .for variable=value, iterator, condition
  17. .foreach variable in argument
  18. .while condition
  19.  
  20. An example:
  21.  
  22. .macro example(args...)
  23. .foreach arg in args
  24. SET arg, A
  25. .end
  26. .endmacro
  27.  
  28. Alternative:
  29.  
  30. .macro example(args...)
  31. .for i=0, i + 1, i < args_length
  32. SET args[i], A
  33. .end
  34. .endmacro
  35.  
  36. Another alternative:
  37.  
  38. .macro example(args...)
  39. .define i
  40. .while i < args_length
  41. SET args[i], A
  42. .redefine i, i+1
  43. .end
  44. .endmacro
  45.  
  46. The final example demonstrates some extended logic, with ".redefine i, i+1". Another proposal is to simplify such logic with additional directives. For example, the same macro, using the proposal, could look like this:
  47.  
  48. .macro example(args...)
  49. .define i
  50. .while i < args_length
  51. SET args[i], A ; or SET args[.(i++)], A
  52. .(i++) ; or (i = i++)
  53. .end
  54. .endmacro
Advertisement
Add Comment
Please, Sign In to add comment