Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Macros with unlimited parameters (organic specification draft)
- For any macro, the final parameter's name may have "..." appended to it, which will signal that any number of parameters may follow.
- Here is an example macro that uses that syntax:
- .macro example(arg1,arg2,args...)
- SET arg1, arg2
- ADD PC, args[0]
- .endmacro
- Any argument that falls within the ellipsized parameter may be indexed with [], starting from zero.
- Additionally, args_length will be defined implicitly with the total number of provided arguments.
- To assist in making such a feature useful, certain directives should be added:
- .for variable=value, iterator, condition
- .foreach variable in argument
- .while condition
- An example:
- .macro example(args...)
- .foreach arg in args
- SET arg, A
- .end
- .endmacro
- Alternative:
- .macro example(args...)
- .for i=0, i + 1, i < args_length
- SET args[i], A
- .end
- .endmacro
- Another alternative:
- .macro example(args...)
- .define i
- .while i < args_length
- SET args[i], A
- .redefine i, i+1
- .end
- .endmacro
- 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:
- .macro example(args...)
- .define i
- .while i < args_length
- SET args[i], A ; or SET args[.(i++)], A
- .(i++) ; or (i = i++)
- .end
- .endmacro
Advertisement
Add Comment
Please, Sign In to add comment