2 * (C) Copyright 2007-2008 Jeremy Maitin-Shepard
4 * Use, modification, and distribution are subject to the terms specified in the
9 let _keyword_argument_list = [];
10 let _get_keyword_argument_setter = function _get_keyword_argument_setter (name) {
11 return function (value) { _keyword_argument_list[_keyword_argument_list.length] = name; return value; };
14 let _get_keyword_argument_getter = function _get_keyword_argument_getter (name) {
15 return function () { _keyword_argument_list[_keyword_argument_list.length] = name; return true; };
18 // This function must be called with all string arguments, all of
19 // which must begin with "$".
20 function define_keywords () {
21 for (var i = 0, alen = arguments.length; i < alen; ++i) {
22 var name = arguments[i];
23 this.__defineSetter__(name, _get_keyword_argument_setter(name));
24 this.__defineGetter__(name, _get_keyword_argument_getter(name));
28 var define_keyword = define_keywords;
30 function write_keywords (output, input, first_index) {
31 if (first_index == null)
32 first_index = input.callee.length;
33 let max_index = input.length;
34 let count = max_index - first_index;
36 let offset = _keyword_argument_list.length - 1;
37 for (let i = max_index - 1; i >= first_index; --i) {
39 if (value instanceof keyword_argument_forwarder) {
44 let name = _keyword_argument_list[offset--];
48 _keyword_argument_list.length -= count;
52 let keyword_argument_forwarder = function keyword_argument_forwarder (args) {
53 if ("_processed_keywords" in args) {
59 write_keywords(this, args);
62 function keywords (args) {
63 write_keywords(args, arguments);
64 write_keywords(args, args);
65 args._processed_keywords = true;
68 function forward_keywords (args) {
69 return new keyword_argument_forwarder(args);
72 function protect_keywords () {
73 return new keyword_argument_forwarder(arguments);