From 3ea0d2bba71300756f040801b03ee73773025a3c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 4 Nov 2014 15:51:19 -0600 Subject: BAS: ALL files are not close to the NuttX coding style.. except in variable and function naming --- apps/interpreters/bas/auto.h | 110 ++++++++++++--- apps/interpreters/bas/autotypes.h | 72 +++++++++- apps/interpreters/bas/bas.h | 86 ++++++++++-- apps/interpreters/bas/error.h | 68 ++++++++- apps/interpreters/bas/fs.h | 236 ++++++++++++++++++++----------- apps/interpreters/bas/global.h | 101 ++++++++++++-- apps/interpreters/bas/program.h | 139 ++++++++++++++---- apps/interpreters/bas/programtypes.h | 72 +++++++++- apps/interpreters/bas/statement.h | 264 +++++++++++++++++++++-------------- apps/interpreters/bas/str.h | 126 +++++++++++++---- apps/interpreters/bas/token.h | 118 ++++++++++++++-- apps/interpreters/bas/value.h | 215 +++++++++++++++++++--------- apps/interpreters/bas/var.h | 119 +++++++++++++--- 13 files changed, 1343 insertions(+), 383 deletions(-) (limited to 'apps/interpreters') diff --git a/apps/interpreters/bas/auto.h b/apps/interpreters/bas/auto.h index 73912ad1a..841ea5380 100644 --- a/apps/interpreters/bas/auto.h +++ b/apps/interpreters/bas/auto.h @@ -1,9 +1,75 @@ -#ifndef AUTO_H -#define AUTO_H +/**************************************************************************** + * apps/interpreters/bas/auto.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 + * Gregory Nutt + * + * 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_AUTO_H +#define __APPS_EXAMPLES_BAS_AUTO_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ #include "programtypes.h" #include "var.h" +/**************************************************************************** + * Public Types + ****************************************************************************/ + struct Auto { long int stackPointer; @@ -43,21 +109,25 @@ union AutoSlot #include "token.h" -extern struct Auto *Auto_new(struct Auto *this); -extern void Auto_destroy(struct Auto *this); -extern struct Var *Auto_pushArg(struct Auto *this); -extern void Auto_pushFuncRet(struct Auto *this, int firstarg, struct Pc *pc); -extern void Auto_pushGosubRet(struct Auto *this, struct Pc *pc); -extern struct Var *Auto_local(struct Auto *this, int l); -extern int Auto_funcReturn(struct Auto *this, struct Pc *pc); -extern int Auto_gosubReturn(struct Auto *this, struct Pc *pc); -extern void Auto_frameToError(struct Auto *this, struct Program *program, struct Value *v); -extern void Auto_setError(struct Auto *this, long int line, struct Pc *pc, struct Value *v); - -extern int Auto_find(struct Auto *this, struct Identifier *ident); -extern int Auto_variable(struct Auto *this, const struct Identifier *ident); -extern enum ValueType Auto_argType(const struct Auto *this, int l); -extern enum ValueType Auto_varType(const struct Auto *this, struct Symbol *sym); -extern void Auto_funcEnd(struct Auto *this); - -#endif +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +struct Auto *Auto_new(struct Auto *this); +void Auto_destroy(struct Auto *this); +struct Var *Auto_pushArg(struct Auto *this); +void Auto_pushFuncRet(struct Auto *this, int firstarg, struct Pc *pc); +void Auto_pushGosubRet(struct Auto *this, struct Pc *pc); +struct Var *Auto_local(struct Auto *this, int l); +int Auto_funcReturn(struct Auto *this, struct Pc *pc); +int Auto_gosubReturn(struct Auto *this, struct Pc *pc); +void Auto_frameToError(struct Auto *this, struct Program *program, struct Value *v); +void Auto_setError(struct Auto *this, long int line, struct Pc *pc, struct Value *v); + +int Auto_find(struct Auto *this, struct Identifier *ident); +int Auto_variable(struct Auto *this, const struct Identifier *ident); +enum ValueType Auto_argType(const struct Auto *this, int l); +enum ValueType Auto_varType(const struct Auto *this, struct Symbol *sym); +void Auto_funcEnd(struct Auto *this); + +#endif /* __APPS_EXAMPLES_BAS_AUTO_H */ diff --git a/apps/interpreters/bas/autotypes.h b/apps/interpreters/bas/autotypes.h index 8c11eabbf..211a1d3f4 100644 --- a/apps/interpreters/bas/autotypes.h +++ b/apps/interpreters/bas/autotypes.h @@ -1,10 +1,76 @@ -#ifndef AUTO_H -#define AUTO_H +/**************************************************************************** + * apps/interpreters/bas/autotypes.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 + * Gregory Nutt + * + * 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_AUTOTYPES_H +#define __APPS_EXAMPLES_BAS_AUTOTYPES_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ #include "program.h" #include "var.h" #include "token.h" +/**************************************************************************** + * Public Types + ****************************************************************************/ + struct Auto { long int stackPointer; @@ -32,4 +98,4 @@ union AutoSlot struct Var var; }; -#endif +#endif /* __APPS_EXAMPLES_BAS_AUTOTYPES_H */ diff --git a/apps/interpreters/bas/bas.h b/apps/interpreters/bas/bas.h index f54bfbb22..970e949d6 100644 --- a/apps/interpreters/bas/bas.h +++ b/apps/interpreters/bas/bas.h @@ -1,18 +1,88 @@ -#ifndef BAS_H -#define BAS_H +/**************************************************************************** + * apps/interpreters/bas/fs.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 + * Gregory Nutt + * + * 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_BAS_H +#define __APPS_EXAMPLES_BAS_BAS_H + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ #define STDCHANNEL 0 #define LPCHANNEL 32 +/**************************************************************************** + * Public Data + ****************************************************************************/ + extern int bas_argc; extern char *bas_argv0; extern char **bas_argv; extern int bas_end; -extern void bas_init(int backslash_colon, int restricted, int uppercase, int lpfd); -extern void bas_runFile(const char *runFile); -extern void bas_runLine(const char *runLine); -extern void bas_interpreter(void); -extern void bas_exit(void); +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +void bas_init(int backslash_colon, int restricted, int uppercase, int lpfd); +void bas_runFile(const char *runFile); +void bas_runLine(const char *runLine); +void bas_interpreter(void); +void bas_exit(void); -#endif +#endif /* __APPS_EXAMPLES_BAS_BAS_H */ diff --git a/apps/interpreters/bas/error.h b/apps/interpreters/bas/error.h index 3f3e5e26a..15af8da49 100644 --- a/apps/interpreters/bas/error.h +++ b/apps/interpreters/bas/error.h @@ -1,5 +1,67 @@ -#ifndef ERROR_H -#define ERROR_H +/**************************************************************************** + * apps/interpreters/bas/error.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 + * Gregory Nutt + * + * 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_ERROR_H +#define __APPS_EXAMPLES_BAS_ERROR_H + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ #define _(String) String @@ -123,4 +185,4 @@ #define OUTOFMEMORY RUNTIME+20,_("Out of memory") #define RESTRICTED RUNTIME+21,_("Restricted") -#endif +#endif /* __APPS_EXAMPLES_BAS_ERROR_H */ diff --git a/apps/interpreters/bas/fs.h b/apps/interpreters/bas/fs.h index 5dd1027f9..ed4055908 100644 --- a/apps/interpreters/bas/fs.h +++ b/apps/interpreters/bas/fs.h @@ -1,32 +1,73 @@ -#ifndef FILE_H -#define FILE_H +/**************************************************************************** + * apps/interpreters/bas/fs.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 + * Gregory Nutt + * + * 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. + * + ****************************************************************************/ -#include "str.h" +#ifndef __APPS_EXAMPLES_BAS_FS_H +#define __APPS_EXAMPLES_BAS_FS_H -struct FileStream -{ - int dev,tty; - int recLength; - - int infd; - char inBuf[1024]; - size_t inSize,inCapacity; +/**************************************************************************** + * Included Files + ****************************************************************************/ - int outfd; - int outPos; - int outLineWidth; - int outColWidth; - char outBuf[1024]; - size_t outSize,outCapacity; - int outforeground,outbackground; - - int randomfd; - int recPos; - char *recBuf; - struct StringField field; +#include "str.h" - int binaryfd; -}; +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ #define FS_COLOUR_BLACK 0 #define FS_COLOUR_BLUE 1 @@ -54,66 +95,103 @@ struct FileStream #define FS_LOCK_SHARED 1 #define FS_LOCK_EXCLUSIVE 2 +/**************************************************************************** + * Public Types + ****************************************************************************/ + +struct FileStream +{ + int dev,tty; + int recLength; + + int infd; + char inBuf[1024]; + size_t inSize,inCapacity; + + int outfd; + int outPos; + int outLineWidth; + int outColWidth; + char outBuf[1024]; + size_t outSize,outCapacity; + int outforeground,outbackground; + + int randomfd; + int recPos; + char *recBuf; + struct StringField field; + + int binaryfd; +}; + +/**************************************************************************** + * Public Data + ****************************************************************************/ + extern const char *FS_errmsg; -extern int FS_opendev(int dev, int infd, int outfd); -extern int FS_openin(const char *name); -extern int FS_openinChn(int chn, const char *name, int mode); -extern int FS_openout(const char *name); -extern int FS_openoutChn(int chn, const char *name, int mode, int append); -extern int FS_openrandomChn(int chn, const char *name, int mode, int recLength); -extern int FS_openbinaryChn(int chn, const char *name, int mode); -extern int FS_freechn(void); -extern int FS_flush(int dev); -extern int FS_close(int dev); +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +int FS_opendev(int dev, int infd, int outfd); +int FS_openin(const char *name); +int FS_openinChn(int chn, const char *name, int mode); +int FS_openout(const char *name); +int FS_openoutChn(int chn, const char *name, int mode, int append); +int FS_openrandomChn(int chn, const char *name, int mode, int recLength); +int FS_openbinaryChn(int chn, const char *name, int mode); +int FS_freechn(void); +int FS_flush(int dev); +int FS_close(int dev); #ifdef CONFIG_SERIAL_TERMIOS -extern int FS_istty(int chn); +int FS_istty(int chn); #else # define FS_istty(chn) (1) #endif -extern int FS_lock(int chn, off_t offset, off_t length, int mode, int w); -extern int FS_truncate(int chn); -extern void FS_shellmode(int chn); -extern void FS_fsmode(int chn); -extern void FS_xonxoff(int chn, int on); -extern int FS_put(int chn); -extern int FS_putChar(int dev, char ch); -extern int FS_putChars(int dev, const char *chars); -extern int FS_putString(int dev, const struct String *s); -extern int FS_putItem(int dev, const struct String *s); -extern int FS_putbinaryString(int chn, const struct String *s); -extern int FS_putbinaryInteger(int chn, long int x); -extern int FS_putbinaryReal(int chn, double x); -extern int FS_getbinaryString(int chn, struct String *s); -extern int FS_getbinaryInteger(int chn, long int *x); -extern int FS_getbinaryReal(int chn, double *x); -extern int FS_nextcol(int dev); -extern int FS_nextline(int dev); -extern int FS_tab(int dev, int position); -extern int FS_cls(int chn); -extern int FS_locate(int chn, int line, int column); -extern int FS_colour(int chn, int foreground, int background); -extern int FS_get(int chn); -extern int FS_getChar(int dev); -extern int FS_eof(int chn); -extern long int FS_loc(int chn); -extern long int FS_lof(int chn); -extern int FS_width(int dev, int width); -extern int FS_zone(int dev, int zone); -extern long int FS_recLength(int chn); -extern void FS_field(int chn, struct String *s, long int position, long int length); -extern int FS_appendToString(int dev, struct String *s, int onl); -extern int FS_inkeyChar(int dev, int ms); -extern void FS_sleep(double s); -extern int FS_seek(int chn, long int record); -extern void FS_closefiles(void); -extern int FS_charpos(int chn); -extern int FS_copy(const char *from, const char *to); -extern int FS_portInput(int address); -extern int FS_memInput(int address); -extern int FS_portOutput(int address, int value); -extern int FS_memOutput(int address, int value); +int FS_lock(int chn, off_t offset, off_t length, int mode, int w); +int FS_truncate(int chn); +void FS_shellmode(int chn); +void FS_fsmode(int chn); +void FS_xonxoff(int chn, int on); +int FS_put(int chn); +int FS_putChar(int dev, char ch); +int FS_putChars(int dev, const char *chars); +int FS_putString(int dev, const struct String *s); +int FS_putItem(int dev, const struct String *s); +int FS_putbinaryString(int chn, const struct String *s); +int FS_putbinaryInteger(int chn, long int x); +int FS_putbinaryReal(int chn, double x); +int FS_getbinaryString(int chn, struct String *s); +int FS_getbinaryInteger(int chn, long int *x); +int FS_getbinaryReal(int chn, double *x); +int FS_nextcol(int dev); +int FS_nextline(int dev); +int FS_tab(int dev, int position); +int FS_cls(int chn); +int FS_locate(int chn, int line, int column); +int FS_colour(int chn, int foreground, int background); +int FS_get(int chn); +int FS_getChar(int dev); +int FS_eof(int chn); +long int FS_loc(int chn); +long int FS_lof(int chn); +int FS_width(int dev, int width); +int FS_zone(int dev, int zone); +long int FS_recLength(int chn); +void FS_field(int chn, struct String *s, long int position, long int length); +int FS_appendToString(int dev, struct String *s, int onl); +int FS_inkeyChar(int dev, int ms); +void FS_sleep(double s); +int FS_seek(int chn, long int record); +void FS_closefiles(void); +int FS_charpos(int chn); +int FS_copy(const char *from, const char *to); +int FS_portInput(int address); +int FS_memInput(int address); +int FS_portOutput(int address, int value); +int FS_memOutput(int address, int value); -#endif +#endif /* __APPS_EXAMPLES_BAS_FS_H */ diff --git a/apps/interpreters/bas/global.h b/apps/interpreters/bas/global.h index 0fd211c05..bd91d4a02 100644 --- a/apps/interpreters/bas/global.h +++ b/apps/interpreters/bas/global.h @@ -1,12 +1,82 @@ -#ifndef GLOBAL_H -#define GLOBAL_H +/**************************************************************************** + * apps/interpreters/bas/global.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 + * Gregory Nutt + * + * 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_GLOBAL_H +#define __APPS_EXAMPLES_BAS_GLOBAL_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ #include "token.h" #include "value.h" #include "var.h" +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + #define GLOBAL_HASHSIZE 31 +/**************************************************************************** + * Public Data + ****************************************************************************/ + struct GlobalFunctionChain { struct Pc begin,end; @@ -20,13 +90,22 @@ struct Global struct GlobalFunctionChain *chain; }; -extern struct Global *Global_new(struct Global *this); -extern void Global_destroy(struct Global *this); -extern void Global_clear(struct Global *this); -extern void Global_clearFunctions(struct Global *this); -extern int Global_find(struct Global *this, struct Identifier *ident, int oparen); -extern int Global_function(struct Global *this, struct Identifier *ident, enum ValueType type, struct Pc *deffn, struct Pc *begin, int argTypesLength, enum ValueType *argTypes); -extern void Global_endfunction(struct Global *this, struct Identifier *ident, struct Pc *end); -extern int Global_variable(struct Global *this, struct Identifier *ident, enum ValueType type, enum SymbolType symbolType, int redeclare); +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +struct Global *Global_new(struct Global *this); +void Global_destroy(struct Global *this); +void Global_clear(struct Global *this); +void Global_clearFunctions(struct Global *this); +int Global_find(struct Global *this, struct Identifier *ident, int oparen); +int Global_function(struct Global *this, struct Identifier *ident, + enum ValueType type, struct Pc *deffn, struct Pc *begin, + int argTypesLength, enum ValueType *argTypes); +void Global_endfunction(struct Global *this, struct Identifier *ident, + struct Pc *end); +int Global_variable(struct Global *this, struct Identifier *ident, + enum ValueType type, enum SymbolType symbolType, + int redeclare); -#endif +#endif /* __APPS_EXAMPLES_BAS_GLOBAL_H */ diff --git a/apps/interpreters/bas/program.h b/apps/interpreters/bas/program.h index 5b6646d99..b50ff0951 100644 --- a/apps/interpreters/bas/program.h +++ b/apps/interpreters/bas/program.h @@ -1,35 +1,114 @@ -#ifndef PROGRAM_H -#define PROGRAM_H +/**************************************************************************** + * apps/interpreters/bas/program.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 + * Gregory Nutt + * + * 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_PROGRAM_H +#define __APPS_EXAMPLES_BAS_PROGRAM_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ #include "programtypes.h" #include "token.h" -extern struct Program *Program_new(struct Program *this); -extern void Program_destroy(struct Program *this); -extern void Program_norun(struct Program *this); -extern void Program_store(struct Program *this, struct Token *line, long int where); -extern void Program_delete(struct Program *this, const struct Pc *from, const struct Pc *to); -extern void Program_addScope(struct Program *this, struct Scope *scope); -extern struct Pc *Program_goLine(struct Program *this, long int line, struct Pc *pc); -extern struct Pc *Program_fromLine(struct Program *this, long int line, struct Pc *pc); -extern struct Pc *Program_toLine(struct Program *this, long int line, struct Pc *pc); -extern int Program_scopeCheck(struct Program *this, struct Pc *pc, struct Pc *fn); -extern struct Pc *Program_dataLine(struct Program *this, long int line, struct Pc *pc); -extern struct Pc *Program_imageLine(struct Program *this, long int line, struct Pc *pc); -extern long int Program_lineNumber(const struct Program *this, const struct Pc *pc); -extern struct Pc *Program_beginning(struct Program *this, struct Pc *pc); -extern struct Pc *Program_end(struct Program *this, struct Pc *pc); -extern struct Pc *Program_nextLine(struct Program *this, struct Pc *pc); -extern int Program_skipEOL(struct Program *this, struct Pc *pc, int dev, int tr); -extern void Program_trace(struct Program *this, struct Pc *pc, int dev, int tr); -extern void Program_PCtoError(struct Program *this, struct Pc *pc, struct Value *v); -extern struct Value *Program_merge(struct Program *this, int dev, struct Value *value); -extern int Program_lineNumberWidth(struct Program *this); -extern struct Value *Program_list(struct Program *this, int dev, int watchIntr, struct Pc *from, struct Pc *to, struct Value *value); -extern struct Value *Program_analyse(struct Program *this, struct Pc *pc, struct Value *value); -extern void Program_renum(struct Program *this, int first, int inc); -extern void Program_unnum(struct Program *this); -extern int Program_setname(struct Program *this, const char *filename); -extern void Program_xref(struct Program *this, int chn); +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +struct Program *Program_new(struct Program *this); +void Program_destroy(struct Program *this); +void Program_norun(struct Program *this); +void Program_store(struct Program *this, struct Token *line, + long int where); +void Program_delete(struct Program *this, const struct Pc *from, + const struct Pc *to); +void Program_addScope(struct Program *this, struct Scope *scope); +struct Pc *Program_goLine(struct Program *this, long int line, + struct Pc *pc); +struct Pc *Program_fromLine(struct Program *this, long int line, + struct Pc *pc); +struct Pc *Program_toLine(struct Program *this, long int line, + struct Pc *pc); +int Program_scopeCheck(struct Program *this, struct Pc *pc, struct Pc *fn); +struct Pc *Program_dataLine(struct Program *this, long int line, + struct Pc *pc); +struct Pc *Program_imageLine(struct Program *this, long int line, + struct Pc *pc); +long int Program_lineNumber(const struct Program *this, + const struct Pc *pc); +struct Pc *Program_beginning(struct Program *this, struct Pc *pc); +struct Pc *Program_end(struct Program *this, struct Pc *pc); +struct Pc *Program_nextLine(struct Program *this, struct Pc *pc); +int Program_skipEOL(struct Program *this, struct Pc *pc, int dev, int tr); +void Program_trace(struct Program *this, struct Pc *pc, int dev, int tr); +void Program_PCtoError(struct Program *this, struct Pc *pc, + struct Value *v); +struct Value *Program_merge(struct Program *this, int dev, + struct Value *value); +int Program_lineNumberWidth(struct Program *this); +struct Value *Program_list(struct Program *this, int dev, int watchIntr, + struct Pc *from, struct Pc *to, + struct Value *value); +struct Value *Program_analyse(struct Program *this, struct Pc *pc, + struct Value *value); +void Program_renum(struct Program *this, int first, int inc); +void Program_unnum(struct Program *this); +int Program_setname(struct Program *this, const char *filename); +void Program_xref(struct Program *this, int chn); -#endif +#endif /* __APPS_EXAMPLES_BAS_PROGRAM_H */ diff --git a/apps/interpreters/bas/programtypes.h b/apps/interpreters/bas/programtypes.h index fd673c901..b5c1e9c1a 100644 --- a/apps/interpreters/bas/programtypes.h +++ b/apps/interpreters/bas/programtypes.h @@ -1,8 +1,74 @@ -#ifndef PROGRAMTYPES_H -#define PROGRAMTYPES_H +/**************************************************************************** + * apps/interpreters/bas/programtypes.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 + * Gregory Nutt + * + * 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_PROGRAMTYPES_H +#define __APPS_EXAMPLES_BAS_PROGRAMTYPES_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ #include "str.h" +/**************************************************************************** + * Public Types + ****************************************************************************/ + struct Pc { int line; @@ -30,4 +96,4 @@ struct Program struct Scope *scope; }; -#endif +#endif /* __APPS_EXAMPLES_BAS_PROGRAMTYPES_H */ diff --git a/apps/interpreters/bas/statement.h b/apps/interpreters/bas/statement.h index fefb09c06..49512171e 100644 --- a/apps/interpreters/bas/statement.h +++ b/apps/interpreters/bas/statement.h @@ -1,104 +1,166 @@ -#ifndef STATEMENT_H -#define STATEMENT_H +/**************************************************************************** + * apps/interpreters/bas/statement.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 + * Gregory Nutt + * + * 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. + * + ****************************************************************************/ -extern struct Value *stmt_CALL(struct Value *value); -extern struct Value *stmt_CASE(struct Value *value); -extern struct Value *stmt_CHDIR_MKDIR(struct Value *value); -extern struct Value *stmt_CLEAR(struct Value *value); -extern struct Value *stmt_CLOSE(struct Value *value); -extern struct Value *stmt_CLS(struct Value *value); -extern struct Value *stmt_COLOR(struct Value *value); -extern struct Value *stmt_DATA(struct Value *value); -extern struct Value *stmt_DEFFN_DEFPROC_FUNCTION_SUB(struct Value *value); -extern struct Value *stmt_DEC_INC(struct Value *value); -extern struct Value *stmt_DEFINT_DEFDBL_DEFSTR(struct Value *value); -extern struct Value *stmt_DELETE(struct Value *value); -extern struct Value *stmt_DIM(struct Value *value); -extern struct Value *stmt_DISPLAY(struct Value *value); -extern struct Value *stmt_DO(struct Value *value); -extern struct Value *stmt_DOcondition(struct Value *value); -extern struct Value *stmt_EDIT(struct Value *value); -extern struct Value *stmt_ELSE_ELSEIFELSE(struct Value *value); -extern struct Value *stmt_END(struct Value *value); -extern struct Value *stmt_ENDIF(struct Value *value); -extern struct Value *stmt_ENDFN(struct Value *value); -extern struct Value *stmt_ENDPROC_SUBEND(struct Value *value); -extern struct Value *stmt_ENDSELECT(struct Value *value); -extern struct Value *stmt_ENVIRON(struct Value *value); -extern struct Value *stmt_FNEXIT(struct Value *value); -extern struct Value *stmt_COLON_EOL(struct Value *value); -extern struct Value *stmt_QUOTE_REM(struct Value *value); -extern struct Value *stmt_EQ_FNRETURN_FNEND(struct Value *value); -extern struct Value *stmt_ERASE(struct Value *value); -extern struct Value *stmt_EXITDO(struct Value *value); -extern struct Value *stmt_EXITFOR(struct Value *value); -extern struct Value *stmt_FIELD(struct Value *value); -extern struct Value *stmt_FOR(struct Value *value); -extern struct Value *stmt_GET_PUT(struct Value *value); -extern struct Value *stmt_GOSUB(struct Value *value); -extern struct Value *stmt_RESUME_GOTO(struct Value *value); -extern struct Value *stmt_KILL(struct Value *value); -extern struct Value *stmt_LET(struct Value *value); -extern struct Value *stmt_LINEINPUT(struct Value *value); -extern struct Value *stmt_LIST_LLIST(struct Value *value); -extern struct Value *stmt_LOAD(struct Value *value); -extern struct Value *stmt_LOCAL(struct Value *value); -extern struct Value *stmt_LOCATE(struct Value *value); -extern struct Value *stmt_LOCK_UNLOCK(struct Value *value); -extern struct Value *stmt_LOOP(struct Value *value); -extern struct Value *stmt_LOOPUNTIL(struct Value *value); -extern struct Value *stmt_LSET_RSET(struct Value *value); -extern struct Value *stmt_IDENTIFIER(struct Value *value); -extern struct Value *stmt_IF_ELSEIFIF(struct Value *value); -extern struct Value *stmt_IMAGE(struct Value *value); -extern struct Value *stmt_INPUT(struct Value *value); -extern struct Value *stmt_MAT(struct Value *value); -extern struct Value *stmt_MATINPUT(struct Value *value); -extern struct Value *stmt_MATPRINT(struct Value *value); -extern struct Value *stmt_MATREAD(struct Value *value); -extern struct Value *stmt_MATREDIM(struct Value *value); -extern struct Value *stmt_MATWRITE(struct Value *value); -extern struct Value *stmt_NAME(struct Value *value); -extern struct Value *stmt_NEW(struct Value *value); -extern struct Value *stmt_NEXT(struct Value *value); -extern struct Value *stmt_ON(struct Value *value); -extern struct Value *stmt_ONERROR(struct Value *value); -extern struct Value *stmt_ONERRORGOTO0(struct Value *value); -extern struct Value *stmt_ONERROROFF(struct Value *value); -extern struct Value *stmt_OPEN(struct Value *value); -extern struct Value *stmt_OPTIONBASE(struct Value *value); -extern struct Value *stmt_OPTIONRUN(struct Value *value); -extern struct Value *stmt_OPTIONSTOP(struct Value *value); -extern struct Value *stmt_OUT_POKE(struct Value *value); -extern struct Value *stmt_PRINT_LPRINT(struct Value *value); -extern struct Value *stmt_RANDOMIZE(struct Value *value); -extern struct Value *stmt_READ(struct Value *value); -extern struct Value *stmt_COPY_RENAME(struct Value *value); -extern struct Value *stmt_RENUM(struct Value *value); -extern struct Value *stmt_REPEAT(struct Value *value); -extern struct Value *stmt_RESTORE(struct Value *value); -extern struct Value *stmt_RETURN(struct Value *value); -extern struct Value *stmt_RUN(struct Value *value); -extern struct Value *stmt_SAVE(struct Value *value); -extern struct Value *stmt_SELECTCASE(struct Value *value); -extern struct Value *stmt_SHELL(struct Value *value); -extern struct Value *stmt_SLEEP(struct Value *value); -extern struct Value *stmt_STOP(struct Value *value); -extern struct Value *stmt_SUBEXIT(struct Value *value); -extern struct Value *stmt_SWAP(struct Value *value); -extern struct Value *stmt_SYSTEM(struct Value *value); +#ifndef __APPS_EXAMPLES_BAS_STATEMENT_H +#define __APPS_EXAMPLES_BAS_STATEMENT_H -extern struct Value *stmt_TROFF(struct Value *value); -extern struct Value *stmt_TRON(struct Value *value); -extern struct Value *stmt_TRUNCATE(struct Value *value); -extern struct Value *stmt_UNNUM(struct Value *value); -extern struct Value *stmt_UNTIL(struct Value *value); -extern struct Value *stmt_WAIT(struct Value *value); -extern struct Value *stmt_WHILE(struct Value *value); -extern struct Value *stmt_WEND(struct Value *value); -extern struct Value *stmt_WIDTH(struct Value *value); -extern struct Value *stmt_WRITE(struct Value *value); -extern struct Value *stmt_XREF(struct Value *value); -extern struct Value *stmt_ZONE(struct Value *value); +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ -#endif +struct Value *stmt_CALL(struct Value *value); +struct Value *stmt_CASE(struct Value *value); +struct Value *stmt_CHDIR_MKDIR(struct Value *value); +struct Value *stmt_CLEAR(struct Value *value); +struct Value *stmt_CLOSE(struct Value *value); +struct Value *stmt_CLS(struct Value *value); +struct Value *stmt_COLOR(struct Value *value); +struct Value *stmt_DATA(struct Value *value); +struct Value *stmt_DEFFN_DEFPROC_FUNCTION_SUB(struct Value *value); +struct Value *stmt_DEC_INC(struct Value *value); +struct Value *stmt_DEFINT_DEFDBL_DEFSTR(struct Value *value); +struct Value *stmt_DELETE(struct Value *value); +struct Value *stmt_DIM(struct Value *value); +struct Value *stmt_DISPLAY(struct Value *value); +struct Value *stmt_DO(struct Value *value); +struct Value *stmt_DOcondition(struct Value *value); +struct Value *stmt_EDIT(struct Value *value); +struct Value *stmt_ELSE_ELSEIFELSE(struct Value *value); +struct Value *stmt_END(struct Value *value); +struct Value *stmt_ENDIF(struct Value *value); +struct Value *stmt_ENDFN(struct Value *value); +struct Value *stmt_ENDPROC_SUBEND(struct Value *value); +struct Value *stmt_ENDSELECT(struct Value *value); +struct Value *stmt_ENVIRON(struct Value *value); +struct Value *stmt_FNEXIT(struct Value *value); +struct Value *stmt_COLON_EOL(struct Value *value); +struct Value *stmt_QUOTE_REM(struct Value *value); +struct Value *stmt_EQ_FNRETURN_FNEND(struct Value *value); +struct Value *stmt_ERASE(struct Value *value); +struct Value *stmt_EXITDO(struct Value *value); +struct Value *stmt_EXITFOR(struct Value *value); +struct Value *stmt_FIELD(struct Value *value); +struct Value *stmt_FOR(struct Value *value); +struct Value *stmt_GET_PUT(struct Value *value); +struct Value *stmt_GOSUB(struct Value *value); +struct Value *stmt_RESUME_GOTO(struct Value *value); +struct Value *stmt_KILL(struct Value *value); +struct Value *stmt_LET(struct Value *value); +struct Value *stmt_LINEINPUT(struct Value *value); +struct Value *stmt_LIST_LLIST(struct Value *value); +struct Value *stmt_LOAD(struct Value *value); +struct Value *stmt_LOCAL(struct Value *value); +struct Value *stmt_LOCATE(struct Value *value); +struct Value *stmt_LOCK_UNLOCK(struct Value *value); +struct Value *stmt_LOOP(struct Value *value); +struct Value *stmt_LOOPUNTIL(struct Value *value); +struct Value *stmt_LSET_RSET(struct Value *value); +struct Value *stmt_IDENTIFIER(struct Value *value); +struct Value *stmt_IF_ELSEIFIF(struct Value *value); +struct Value *stmt_IMAGE(struct Value *value); +struct Value *stmt_INPUT(struct Value *value); +struct Value *stmt_MAT(struct Value *value); +struct Value *stmt_MATINPUT(struct Value *value); +struct Value *stmt_MATPRINT(struct Value *value); +struct Value *stmt_MATREAD(struct Value *value); +struct Value *stmt_MATREDIM(struct Value *value); +struct Value *stmt_MATWRITE(struct Value *value); +struct Value *stmt_NAME(struct Value *value); +struct Value *stmt_NEW(struct Value *value); +struct Value *stmt_NEXT(struct Value *value); +struct Value *stmt_ON(struct Value *value); +struct Value *stmt_ONERROR(struct Value *value); +struct Value *stmt_ONERRORGOTO0(struct Value *value); +struct Value *stmt_ONERROROFF(struct Value *value); +struct Value *stmt_OPEN(struct Value *value); +struct Value *stmt_OPTIONBASE(struct Value *value); +struct Value *stmt_OPTIONRUN(struct Value *value); +struct Value *stmt_OPTIONSTOP(struct Value *value); +struct Value *stmt_OUT_POKE(struct Value *value); +struct Value *stmt_PRINT_LPRINT(struct Value *value); +struct Value *stmt_RANDOMIZE(struct Value *value); +struct Value *stmt_READ(struct Value *value); +struct Value *stmt_COPY_RENAME(struct Value *value); +struct Value *stmt_RENUM(struct Value *value); +struct Value *stmt_REPEAT(struct Value *value); +struct Value *stmt_RESTORE(struct Value *value); +struct Value *stmt_RETURN(struct Value *value); +struct Value *stmt_RUN(struct Value *value); +struct Value *stmt_SAVE(struct Value *value); +struct Value *stmt_SELECTCASE(struct Value *value); +struct Value *stmt_SHELL(struct Value *value); +struct Value *stmt_SLEEP(struct Value *value); +struct Value *stmt_STOP(struct Value *value); +struct Value *stmt_SUBEXIT(struct Value *value); +struct Value *stmt_SWAP(struct Value *value); +struct Value *stmt_SYSTEM(struct Value *value); + +struct Value *stmt_TROFF(struct Value *value); +struct Value *stmt_TRON(struct Value *value); +struct Value *stmt_TRUNCATE(struct Value *value); +struct Value *stmt_UNNUM(struct Value *value); +struct Value *stmt_UNTIL(struct Value *value); +struct Value *stmt_WAIT(struct Value *value); +struct Value *stmt_WHILE(struct Value *value); +struct Value *stmt_WEND(struct Value *value); +struct Value *stmt_WIDTH(struct Value *value); +struct Value *stmt_WRITE(struct Value *value); +struct Value *stmt_XREF(struct Value *value); +struct Value *stmt_ZONE(struct Value *value); + +#endif /* __APPS_EXAMPLES_BAS_STATEMENT_H */ diff --git a/apps/interpreters/bas/str.h b/apps/interpreters/bas/str.h index eb2166d84..9c706a27b 100644 --- a/apps/interpreters/bas/str.h +++ b/apps/interpreters/bas/str.h @@ -1,8 +1,74 @@ -#ifndef STR_H -#define STR_H +/**************************************************************************** + * apps/interpreters/bas/str.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 + * Gregory Nutt + * + * 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_STR_H +#define __APPS_EXAMPLES_BAS_STR_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ #include +/**************************************************************************** + * Public Types + ****************************************************************************/ + struct String { size_t length; @@ -16,28 +82,34 @@ struct StringField int refCount; }; -extern int cistrcmp(const char *s, const char *r); - -extern struct String *String_new(struct String *this); -extern void String_destroy(struct String *this); -extern int String_joinField(struct String *this, struct StringField *field, char *character, size_t length); -extern void String_leaveField(struct String *this); -extern struct String *String_clone(struct String *this, const struct String *clon); -extern int String_appendString(struct String *this, const struct String *app); -extern int String_appendChar(struct String *this, char ch); -extern int String_appendChars(struct String *this, const char *ch); -extern int String_appendPrintf(struct String *this, const char *fmt, ...); -extern int String_insertChar(struct String *this, size_t where, char ch); -extern int String_delete(struct String *this, size_t where, size_t len); -extern void String_ucase(struct String *this); -extern void String_lcase(struct String *this); -extern int String_size(struct String *this, size_t length); -extern int String_cmp(const struct String *this, const struct String *s); -extern void String_lset(struct String *this, const struct String *s); -extern void String_rset(struct String *this, const struct String *s); -extern void String_set(struct String *this, size_t pos, const struct String *s, size_t length); - -extern struct StringField *StringField_new(struct StringField *this); -extern void StringField_destroy(struct StringField *this); - -#endif +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +int cistrcmp(const char *s, const char *r); + +struct String *String_new(struct String *this); +void String_destroy(struct String *this); +int String_joinField(struct String *this, struct StringField *field, + char *character, size_t length); +void String_leaveField(struct String *this); +struct String *String_clone(struct String *this, const struct String *clon); +int String_appendString(struct String *this, const struct String *app); +int String_appendChar(struct String *this, char ch); +int String_appendChars(struct String *this, const char *ch); +int String_appendPrintf(struct String *this, const char *fmt, ...); +int String_insertChar(struct String *this, size_t where, char ch); +int String_delete(struct String *this, size_t where, size_t len); +void String_ucase(struct String *this); +void String_lcase(struct String *this); +int String_size(struct String *this, size_t length); +int String_cmp(const struct String *this, const struct String *s); +void String_lset(struct String *this, const struct String *s); +void String_rset(struct String *this, const struct String *s); +void String_set(struct String *this, size_t pos, const struct String *s, + size_t length); + +struct StringField *StringField_new(struct StringField *this); +void StringField_destroy(struct StringField *this); + +#endif /* __APPS_EXAMPLES_BAS_STR_H */ diff --git a/apps/interpreters/bas/token.h b/apps/interpreters/bas/token.h index 8feb76283..b6f24cec8 100644 --- a/apps/interpreters/bas/token.h +++ b/apps/interpreters/bas/token.h @@ -1,11 +1,94 @@ -#ifndef TOKEN_H -#define TOKEN_H +/**************************************************************************** + * apps/interpreters/bas/token.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 + * Gregory Nutt + * + * 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_TOKEN_H +#define __APPS_EXAMPLES_BAS_TOKEN_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ #include "autotypes.h" #include "value.h" #include "var.h" -enum SymbolType { GLOBALVAR, GLOBALARRAY, LOCALVAR, BUILTINFUNCTION, USERFUNCTION }; +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define TOKEN_ISBINARYOPERATOR(t) (Token_property[t]&1) +#define TOKEN_ISUNARYOPERATOR(t) (Token_property[t]&(1<<1)) +#define TOKEN_BINARYPRIORITY(t) ((Token_property[t]>>2)&7) +#define TOKEN_UNARYPRIORITY(t) ((Token_property[t]>>5)&7) +#define TOKEN_ISRIGHTASSOCIATIVE(t) (Token_property[t]&(1<<8)) + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +enum SymbolType +{ + GLOBALVAR, + GLOBALARRAY, + LOCALVAR, + BUILTINFUNCTION, + USERFUNCTION +}; struct Symbol { @@ -82,7 +165,7 @@ struct Casevalue enum TokenType { - T_NOTOKEN=0, + T_NOTOKEN = 0, T_ACCESS_READ, T_ACCESS_READ_WRITE, T_ACCESS_WRITE, @@ -443,16 +526,21 @@ struct Token } u; }; -extern struct Token *Token_newCode(const char *ln); -extern struct Token *Token_newData(const char *ln); -extern void Token_destroy(struct Token *token); -extern struct String *Token_toString(struct Token *token, struct Token *spaceto, struct String *s, int *indent, int full); +/**************************************************************************** + * Public Data + ****************************************************************************/ + extern int Token_property[]; -#define TOKEN_ISBINARYOPERATOR(t) (Token_property[t]&1) -#define TOKEN_ISUNARYOPERATOR(t) (Token_property[t]&(1<<1)) -#define TOKEN_BINARYPRIORITY(t) ((Token_property[t]>>2)&7) -#define TOKEN_UNARYPRIORITY(t) ((Token_property[t]>>5)&7) -#define TOKEN_ISRIGHTASSOCIATIVE(t) (Token_property[t]&(1<<8)) -extern void Token_init(int backslash_colon, int uppercase); -#endif +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +struct Token *Token_newCode(const char *ln); +struct Token *Token_newData(const char *ln); +void Token_destroy(struct Token *token); +struct String *Token_toString(struct Token *token, struct Token *spaceto, + struct String *s, int *indent, int full); +void Token_init(int backslash_colon, int uppercase); + +#endif /* __APPS_EXAMPLES_BAS_TOKEN_H */ 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 + * Gregory Nutt + * + * 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 */ diff --git a/apps/interpreters/bas/var.h b/apps/interpreters/bas/var.h index 41db98a85..afec8ba95 100644 --- a/apps/interpreters/bas/var.h +++ b/apps/interpreters/bas/var.h @@ -1,8 +1,80 @@ -#ifndef VAR_H -#define VAR_H +/**************************************************************************** + * apps/interpreters/bas/var.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 + * Gregory Nutt + * + * 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_VAR_H +#define __APPS_EXAMPLES_BAS_VAR_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ #include "value.h" +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define VAR_SCALAR_VALUE(this) ((this)->value) + +/**************************************************************************** + * Public Types + ****************************************************************************/ + struct Var { unsigned int dim; @@ -13,20 +85,31 @@ struct Var char base; }; -#define VAR_SCALAR_VALUE(this) ((this)->value) +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +struct Var *Var_new(struct Var *this, enum ValueType type, unsigned int dim, + const unsigned int *geometry, int base); +struct Var *Var_new_scalar(struct Var *this); +void Var_destroy(struct Var *this); +void Var_retype(struct Var *this, enum ValueType type); +struct Value *Var_value(struct Var *this, unsigned int dim, int idx[], + struct Value *value); +void Var_clear(struct Var *this); +struct Value *Var_mat_assign(struct Var *this, struct Var *x, + struct Value *err, int work); +struct Value *Var_mat_addsub(struct Var *this, struct Var *x, struct Var *y, + int add, struct Value *err, int work); +struct Value *Var_mat_mult(struct Var *this, struct Var *x, struct Var *y, + struct Value *err, int work); +struct Value *Var_mat_scalarMult(struct Var *this, struct Value *factor, + struct Var *x, int work); +void Var_mat_transpose(struct Var *this, struct Var *x); +struct Value *Var_mat_invert(struct Var *this, struct Var *x, + struct Value *det, struct Value *err); +struct Value *Var_mat_redim(struct Var *this, unsigned int dim, + const unsigned int *geometry, + struct Value *err); -extern struct Var *Var_new(struct Var *this, enum ValueType type, unsigned int dim, const unsigned int *geometry, int base); -extern struct Var *Var_new_scalar(struct Var *this); -extern void Var_destroy(struct Var *this); -extern void Var_retype(struct Var *this, enum ValueType type); -extern struct Value *Var_value(struct Var *this, unsigned int dim, int idx[], struct Value *value); -extern void Var_clear(struct Var *this); -extern struct Value *Var_mat_assign(struct Var *this, struct Var *x, struct Value *err, int work); -extern struct Value *Var_mat_addsub(struct Var *this, struct Var *x, struct Var *y, int add, struct Value *err, int work); -extern struct Value *Var_mat_mult(struct Var *this, struct Var *x, struct Var *y, struct Value *err, int work); -extern struct Value *Var_mat_scalarMult(struct Var *this, struct Value *factor, struct Var *x, int work); -extern void Var_mat_transpose(struct Var *this, struct Var *x); -extern struct Value *Var_mat_invert(struct Var *this, struct Var *x, struct Value *det, struct Value *err); -extern struct Value *Var_mat_redim(struct Var *this, unsigned int dim, const unsigned int *geometry, struct Value *err); - -#endif +#endif /* __APPS_EXAMPLES_BAS_VAR_H */ -- cgit v1.2.3