BuiltinFunctions.hpp
Go to the documentation of this file.
1 /*----------------------------------------------------------------------------*/
2 /* */
3 /* Copyright (c) 1995, 2004 IBM Corporation. All rights reserved. */
4 /* Copyright (c) 2005-2009 Rexx Language Association. All rights reserved. */
5 /* */
6 /* This program and the accompanying materials are made available under */
7 /* the terms of the Common Public License v1.0 which accompanies this */
8 /* distribution. A copy is also available at the following address: */
9 /* http://www.oorexx.org/license.html */
10 /* */
11 /* Redistribution and use in source and binary forms, with or */
12 /* without modification, are permitted provided that the following */
13 /* conditions are met: */
14 /* */
15 /* Redistributions of source code must retain the above copyright */
16 /* notice, this list of conditions and the following disclaimer. */
17 /* Redistributions in binary form must reproduce the above copyright */
18 /* notice, this list of conditions and the following disclaimer in */
19 /* the documentation and/or other materials provided with the distribution. */
20 /* */
21 /* Neither the name of Rexx Language Association nor the names */
22 /* of its contributors may be used to endorse or promote products */
23 /* derived from this software without specific prior written permission. */
24 /* */
25 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
26 /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
27 /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS */
28 /* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
29 /* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
30 /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
31 /* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */
32 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY */
33 /* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
34 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
35 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
36 /* */
37 /*----------------------------------------------------------------------------*/
38 /******************************************************************************/
39 /* REXX Translator BuiltinFunctions.h */
40 /* */
41 /* Builtin Function Execution Stub macros */
42 /* */
43 /******************************************************************************/
44 
45 #ifndef OTPBIF_INCLUDED
46 #define OTPBIF_INCLUDED
47 
48 void expandArgs(RexxObject **arguments, size_t argcount, size_t min, size_t max, const char *function);
49 RexxString *requiredStringArg(size_t position, RexxObject **arguments, size_t argcount, const char *function);
50 RexxString *optionalStringArg(size_t position, RexxObject **arguments, size_t argcount, const char *function);
51 RexxInteger *requiredIntegerArg(size_t position, RexxObject **arguments, size_t argcount, const char *function);
52 RexxInteger *optionalIntegerArg(size_t position, RexxObject **arguments, size_t argcount, const char *function);
53 RexxObject *requiredBigIntegerArg(size_t position, RexxObject **arguments, size_t argcount, const char *function);
54 RexxObject *optionalBigIntegerArg(size_t position, RexxObject **arguments, size_t argcount, const char *function);
55 
56 /*
57 x is the name of the builtin function.
58 n is the argument name.
59 
60 #define ABBREV_MIN 2 // arg1 and arg2 are mandatory: at least 2 args
61 #define ABBREV_MAX 3 // arg3 is optional: at max 3 args
62 #define ABBREV_information 1 // arg1 is information
63 #define ABBREV_info 2 // arg2 is info
64 #define ABBREV_length 3 // arg3 length
65 
66 BUILTIN(ABBREV)
67 {
68  fix_args(ABBREV);
69  RexxString *information = required_string(ABBREV, information);
70  RexxString *info = required_string(ABBREV, info);
71  RexxInteger *length = optional_integer(ABBREV, length);
72  return information->abbrev(info, length);
73 }
74 
75 Macro expansion:
76 RexxObject *builtin_function_abbrev ( RexxActivation * context, RexxObject **arguments, size_t argcount, size_t named_argcount, RexxExpressionStack *stack )
77 {
78  expandArgs(arguments, argcount, 2, 3, CHAR_ABBREV);
79  RexxString *information = requiredStringArg(argcount - 1)
80  RexxString *info = requiredStringArg(argcount - 2)
81  RexxInteger *length = ((argcount >= 3) ? optionalIntegerArg(argcount - 3, argcount, CHAR_ABBREV) : OREF_NULL)
82 }
83 
84 ABBREV("Print","Pri") ABBREV("Print","Pri",4)
85 argcount == 2 argcount == 3
86 stack top "Pri" stack top 4
87 stack top-1 "Print" stack top-1 "Pri"
88  stack top-2 "Print"
89 */
90 
91 #define fix_args(x) expandArgs(arguments, argcount, x##_MIN, x##_MAX, CHAR_##x)
92 #define check_args(x) expandArgs(arguments, argcount, x##_MIN, x##_MAX, CHAR_##x)
93 
94 #define get_arg(x,n) arguments[x##_##n - 1]
95 #define set_arg(x,n1,n2) arguments[x##_##n1 - 1] = arguments[x##_##n2 - 1]
96 
97 #define required_string(x,n) requiredStringArg(x##_##n, arguments, argcount, CHAR_##x)
98 #define optional_string(x,n) optionalStringArg(x##_##n, arguments, argcount, CHAR_##x)
99 
100 #define required_text(x,n) requiredTextArg(x##_##n, arguments, argcount, CHAR_##x)
101 
102 #define required_integer(x,n) requiredIntegerArg(x##_##n, arguments, argcount, CHAR_##x)
103 #define optional_integer(x,n) optionalIntegerArg(x##_##n, arguments, argcount, CHAR_##x)
104 
105 #define required_big_integer(x,n) requiredBigIntegerArg(x##_##n, arguments, argcount, CHAR_##x)
106 #define optional_big_integer(x,n) optionalBigIntegerArg(x##_##n, arguments, argcount, CHAR_##x)
107 
108 #define optional_argument(x,n) ((argcount >= x##_##n) ? arguments[x##_##n -1] : OREF_NULL )
109 #define arg_exists(x,n) ((argcount < x##_##n) ? false : arguments[x##_##n - 1] != OREF_NULL )
110 #define arg_omitted(x,n) ((argcount < x##_##n) ? true : arguments[x##_##n - 1] == OREF_NULL )
111 
112 #define BUILTIN(x) RexxObject *builtin_function_##x ( RexxActivation * context, RexxObject **arguments, size_t argcount, size_t named_argcount, RexxExpressionStack *stack )
113 
114 #define positive_integer(n,f,p) if (n <= 0) reportException(Error_Incorrect_call_positive, CHAR_##f, OREF_positional, p, n)
115 #define nonnegative_integer(n,f,p) if (n < 0) reportException(Error_Incorrect_call_nonnegative, CHAR_##f, OREF_positional, p, n)
116 
117 #define ALPHANUM "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
118 #endif
#define min(a, b)
Definition: ArrayClass.cpp:82
RexxString * requiredStringArg(size_t position, RexxObject **arguments, size_t argcount, const char *function)
void expandArgs(RexxObject **arguments, size_t argcount, size_t min, size_t max, const char *function)
RexxInteger * requiredIntegerArg(size_t position, RexxObject **arguments, size_t argcount, const char *function)
RexxString * optionalStringArg(size_t position, RexxObject **arguments, size_t argcount, const char *function)
RexxObject * optionalBigIntegerArg(size_t position, RexxObject **arguments, size_t argcount, const char *function)
RexxInteger * optionalIntegerArg(size_t position, RexxObject **arguments, size_t argcount, const char *function)
RexxObject * requiredBigIntegerArg(size_t position, RexxObject **arguments, size_t argcount, const char *function)