diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2014-11-04 15:51:19 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2014-11-04 15:51:19 -0600 |
commit | 3ea0d2bba71300756f040801b03ee73773025a3c (patch) | |
tree | 9fb52b2466bef5f60eba4bb932da265cb65178fe /apps/interpreters/bas/value.h | |
parent | e79503dba9c0702e4354194ffb52b281edddba25 (diff) | |
download | nuttx-3ea0d2bba71300756f040801b03ee73773025a3c.tar.gz nuttx-3ea0d2bba71300756f040801b03ee73773025a3c.tar.bz2 nuttx-3ea0d2bba71300756f040801b03ee73773025a3c.zip |
BAS: ALL files are not close to the NuttX coding style.. except in variable and function naming
Diffstat (limited to 'apps/interpreters/bas/value.h')
-rw-r--r-- | apps/interpreters/bas/value.h | 215 |
1 files changed, 150 insertions, 65 deletions
diff --git a/apps/interpreters/bas/value.h b/apps/interpreters/bas/value.h index 77df977f8..56e62a01e 100644 --- a/apps/interpreters/bas/value.h +++ b/apps/interpreters/bas/value.h @@ -1,8 +1,94 @@ -#ifndef VALUE_H -#define VALUE_H +/**************************************************************************** + * apps/interpreters/bas/value.h + * + * Copyright (c) 1999-2014 Michael Haardt + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Adapted to NuttX and re-released under a 3-clause BSD license: + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Authors: Alan Carvalho de Assis <Alan Carvalho de Assis> + * Gregory Nutt <gnutt@nuttx.org> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __APPS_EXAMPLES_BAS_VALUE_H +#define __APPS_EXAMPLES_BAS_VALUE_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ #include "str.h" +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define VALUE_NEW_INTEGER(this,n) ((this)->type=V_INTEGER,(this)->u.integer=(n)) +#define VALUE_NEW_REAL(this,n) ((this)->type=V_REAL,(this)->u.real=(n)) +#define VALUE_RETYPE(v,t) ((v)->type==(t) ? (v) : Value_retype(v,t)) +#define VALUE_DESTROY(this) assert((this)!=(struct Value*)0); \ + switch ((this)->type) \ + { \ + case V_ERROR: free((this)->u.error.msg); break; \ + case V_INTEGER: break; \ + case V_NIL: break; \ + case V_REAL: break; \ + case V_STRING: String_destroy(&(this)->u.string); break; \ + case V_VOID: break; \ + default: assert(0); \ + } \ + (this)->type=0; + +/**************************************************************************** + * Public Types + ****************************************************************************/ + enum ValueType { V_ERROR=1, @@ -27,71 +113,70 @@ struct Value } u; }; -extern const enum ValueType Value_commonType[V_VOID+1][V_VOID+1]; +/**************************************************************************** + * Public Data + ****************************************************************************/ -#define VALUE_NEW_INTEGER(this,n) ((this)->type=V_INTEGER,(this)->u.integer=(n)) -#define VALUE_NEW_REAL(this,n) ((this)->type=V_REAL,(this)->u.real=(n)) -#define VALUE_RETYPE(v,t) ((v)->type==(t) ? (v) : Value_retype(v,t)) -#define VALUE_DESTROY(this) assert((this)!=(struct Value*)0); \ - switch ((this)->type) \ - { \ - case V_ERROR: free((this)->u.error.msg); break; \ - case V_INTEGER: break; \ - case V_NIL: break; \ - case V_REAL: break; \ - case V_STRING: String_destroy(&(this)->u.string); break; \ - case V_VOID: break; \ - default: assert(0); \ - } \ - (this)->type=0; +extern const enum ValueType Value_commonType[V_VOID+1][V_VOID+1]; +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ -extern long int lrint(double d); -extern double Value_trunc(double d); -extern double Value_round(double d); -extern long int Value_toi(double d, int *overflow); -extern long int Value_vali(const char *s, char **end, int *overflow); -extern double Value_vald(const char *s, char **end, int *overflow); +long int lrint(double d); +double Value_trunc(double d); +double Value_round(double d); +long int Value_toi(double d, int *overflow); +long int Value_vali(const char *s, char **end, int *overflow); +double Value_vald(const char *s, char **end, int *overflow); -extern struct Value *Value_new_NIL(struct Value *this); -extern struct Value *Value_new_ERROR(struct Value *this, int code, const char *error, ...); -extern struct Value *Value_new_INTEGER(struct Value *this, int n); -extern struct Value *Value_new_REAL(struct Value *this, double n); -extern struct Value *Value_new_STRING(struct Value *this); -extern struct Value *Value_new_VOID(struct Value *this); -extern struct Value *Value_new_null(struct Value *this, enum ValueType type); -extern int Value_isNull(const struct Value *this); -extern void Value_destroy(struct Value *this); -extern void Value_errorPrefix(struct Value *this, const char *prefix); -extern void Value_errorSuffix(struct Value *this, const char *suffix); -extern struct Value *Value_new_typeError(struct Value *this, enum ValueType t1, enum ValueType t2); -extern struct Value *Value_retype(struct Value *this, enum ValueType type); -extern struct Value *Value_clone(struct Value *this, const struct Value *original); -extern struct Value *Value_uplus(struct Value *this, int calc); -extern struct Value *Value_uneg(struct Value *this, int calc); -extern struct Value *Value_unot(struct Value *this, int calc); -extern struct Value *Value_add(struct Value *this, struct Value *x, int calc); -extern struct Value *Value_sub(struct Value *this, struct Value *x, int calc); -extern struct Value *Value_mult(struct Value *this, struct Value *x, int calc); -extern struct Value *Value_div(struct Value *this, struct Value *x, int calc); -extern struct Value *Value_idiv(struct Value *this, struct Value *x, int calc); -extern struct Value *Value_mod(struct Value *this, struct Value *x, int calc); -extern struct Value *Value_pow(struct Value *this, struct Value *x, int calc); -extern struct Value *Value_and(struct Value *this, struct Value *x, int calc); -extern struct Value *Value_or(struct Value *this, struct Value *x, int calc); -extern struct Value *Value_xor(struct Value *this, struct Value *x, int calc); -extern struct Value *Value_eqv(struct Value *this, struct Value *x, int calc); -extern struct Value *Value_imp(struct Value *this, struct Value *x, int calc); -extern struct Value *Value_lt(struct Value *this, struct Value *x, int calc); -extern struct Value *Value_le(struct Value *this, struct Value *x, int calc); -extern struct Value *Value_eq(struct Value *this, struct Value *s, int calc); -extern struct Value *Value_ge(struct Value *this, struct Value *x, int calc); -extern struct Value *Value_gt(struct Value *this, struct Value *x, int calc); -extern struct Value *Value_ne(struct Value *this, struct Value *x, int calc); -extern int Value_exitFor(struct Value *this, struct Value *limit, struct Value *step); -extern struct String *Value_toString(struct Value *this, struct String *s, char pad, int headingsign, size_t width, int commas, int dollar, int dollarleft, int precision, int exponent, int trailingsign); -extern struct Value *Value_toStringUsing(struct Value *this, struct String *s, struct String *using, size_t *usingpos); -extern struct String *Value_toWrite(struct Value *this, struct String *s); -extern struct Value *Value_nullValue(enum ValueType type); +struct Value *Value_new_NIL(struct Value *this); +struct Value *Value_new_ERROR(struct Value *this, int code, + const char *error, ...); +struct Value *Value_new_INTEGER(struct Value *this, int n); +struct Value *Value_new_REAL(struct Value *this, double n); +struct Value *Value_new_STRING(struct Value *this); +struct Value *Value_new_VOID(struct Value *this); +struct Value *Value_new_null(struct Value *this, enum ValueType type); +int Value_isNull(const struct Value *this); +void Value_destroy(struct Value *this); +void Value_errorPrefix(struct Value *this, const char *prefix); +void Value_errorSuffix(struct Value *this, const char *suffix); +struct Value *Value_new_typeError(struct Value *this, enum ValueType t1, + enum ValueType t2); +struct Value *Value_retype(struct Value *this, enum ValueType type); +struct Value *Value_clone(struct Value *this, const struct Value *original); +struct Value *Value_uplus(struct Value *this, int calc); +struct Value *Value_uneg(struct Value *this, int calc); +struct Value *Value_unot(struct Value *this, int calc); +struct Value *Value_add(struct Value *this, struct Value *x, int calc); +struct Value *Value_sub(struct Value *this, struct Value *x, int calc); +struct Value *Value_mult(struct Value *this, struct Value *x, int calc); +struct Value *Value_div(struct Value *this, struct Value *x, int calc); +struct Value *Value_idiv(struct Value *this, struct Value *x, int calc); +struct Value *Value_mod(struct Value *this, struct Value *x, int calc); +struct Value *Value_pow(struct Value *this, struct Value *x, int calc); +struct Value *Value_and(struct Value *this, struct Value *x, int calc); +struct Value *Value_or(struct Value *this, struct Value *x, int calc); +struct Value *Value_xor(struct Value *this, struct Value *x, int calc); +struct Value *Value_eqv(struct Value *this, struct Value *x, int calc); +struct Value *Value_imp(struct Value *this, struct Value *x, int calc); +struct Value *Value_lt(struct Value *this, struct Value *x, int calc); +struct Value *Value_le(struct Value *this, struct Value *x, int calc); +struct Value *Value_eq(struct Value *this, struct Value *s, int calc); +struct Value *Value_ge(struct Value *this, struct Value *x, int calc); +struct Value *Value_gt(struct Value *this, struct Value *x, int calc); +struct Value *Value_ne(struct Value *this, struct Value *x, int calc); +int Value_exitFor(struct Value *this, struct Value *limit, + struct Value *step); +struct String *Value_toString(struct Value *this, struct String *s, + char pad, int headingsign, size_t width, + int commas, int dollar, int dollarleft, + int precision, int exponent, + int trailingsign); +struct Value *Value_toStringUsing(struct Value *this, struct String *s, + struct String *using, size_t *usingpos); +struct String *Value_toWrite(struct Value *this, struct String *s); +struct Value *Value_nullValue(enum ValueType type); -#endif +#endif /* __APPS_EXAMPLES_BAS_VALUE_H */ |