summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-11-01 18:06:28 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-11-01 18:06:28 -0600
commitea4aa854075d0622d4ffba54ed432da8b7346921 (patch)
tree4b5b4203e3520712450fd412125367f4c3141dfd /apps
parent9694c7f17c7d741c997e2641a4a52d0bb83a02d0 (diff)
downloadnuttx-ea4aa854075d0622d4ffba54ed432da8b7346921.tar.gz
nuttx-ea4aa854075d0622d4ffba54ed432da8b7346921.tar.bz2
nuttx-ea4aa854075d0622d4ffba54ed432da8b7346921.zip
A few baby steps toward getting closer to the coding standard
Diffstat (limited to 'apps')
-rw-r--r--apps/interpreters/bas/bas.c2974
-rw-r--r--apps/interpreters/bas/global.c12
-rw-r--r--apps/interpreters/bas/main.c8
-rw-r--r--apps/interpreters/bas/program.c2
-rw-r--r--apps/interpreters/bas/statement.c26
-rw-r--r--apps/interpreters/bas/token.c82
-rw-r--r--apps/interpreters/bas/value.c14
7 files changed, 1730 insertions, 1388 deletions
diff --git a/apps/interpreters/bas/bas.c b/apps/interpreters/bas/bas.c
index eba40371f..e43f918dc 100644
--- a/apps/interpreters/bas/bas.c
+++ b/apps/interpreters/bas/bas.c
@@ -1,4 +1,7 @@
-/* #includes */ /*{{{C}}}*//*{{{*/
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
#include "config.h"
#include <sys/stat.h>
@@ -9,10 +12,10 @@
#include <errno.h>
#include <fcntl.h>
#ifdef HAVE_GETTEXT
-#include <libintl.h>
-#define _(String) gettext(String)
+# include <libintl.h>
+# define _(String) gettext(String)
#else
-#define _(String) String
+# define _(String) String
#endif
#include <limits.h>
#include <math.h>
@@ -34,46 +37,55 @@
#include "var.h"
#ifdef USE_DMALLOC
-#include "dmalloc.h"
+# include "dmalloc.h"
#endif
-/*}}}*/
-/* #defines */ /*{{{*/
-#define DIRECTMODE (pc.line==-1)
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define DIRECTMODE (pc.line== -1)
#ifndef __GNUC__
-#define inline
+# define inline
#endif
-/*}}}*/
-/* types */ /*{{{*/
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
enum LabelType
-{
- L_IF=1,
- L_ELSE,
- L_DO,
- L_DOcondition,
- L_FOR,
- L_FOR_VAR,
- L_FOR_LIMIT,
- L_FOR_BODY,
- L_REPEAT,
- L_SELECTCASE,
- L_WHILE,
- L_FUNC
-};
+ {
+ L_IF = 1,
+ L_ELSE,
+ L_DO,
+ L_DOcondition,
+ L_FOR,
+ L_FOR_VAR,
+ L_FOR_LIMIT,
+ L_FOR_BODY,
+ L_REPEAT,
+ L_SELECTCASE,
+ L_WHILE,
+ L_FUNC
+ };
struct LabelStack
-{
- enum LabelType type;
- struct Pc patch;
-};
-/*}}}*/
-/* variables */ /*{{{*/
-static unsigned int labelStackPointer,labelStackCapacity;
+ {
+ enum LabelType type;
+ struct Pc patch;
+ };
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static unsigned int labelStackPointer, labelStackCapacity;
static struct LabelStack *labelStack;
static struct Pc *lastdata;
static struct Pc curdata;
static struct Pc nextdata;
-static enum { DECLARE, COMPILE, INTERPRET } pass;
+static enum
+ { DECLARE, COMPILE, INTERPRET } pass;
static int stopped;
static int optionbase;
static struct Pc pc;
@@ -86,350 +98,421 @@ int bas_argc;
char *bas_argv0;
char **bas_argv;
int bas_end;
-/*}}}*/
-/* forward prototypes */ /*{{{*/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
static struct Value *statements(struct Value *value);
static struct Value *compileProgram(struct Value *v, int clearGlobals);
static struct Value *eval(struct Value *value, const char *desc);
-/*}}}*/
-static char *mytmpnam(void) /*{{{*/
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static char *mytmpnam(void)
{
static char buf[_POSIX_PATH_MAX];
- const char *tmpdir;
+ const char *tmpdir;
unsigned int i;
- int fd=-1;
-
- if ((tmpdir=getenv("TMPDIR"))==(char*)0) tmpdir="/tmp";
- if ((strlen(tmpdir)+1+8+1)>=_POSIX_PATH_MAX) return (char*)0;
- i=getpid();
- while (i<0xffffffff && (snprintf(buf,sizeof(buf),"%s/%08x",tmpdir,i),(fd=open(buf,O_RDWR|O_CREAT|O_EXCL,0600)))==-1 && errno==EEXIST) ++i;
- if (fd==-1) return (char*)0;
+ int fd = -1;
+
+ if ((tmpdir = getenv("TMPDIR")) == (char *)0)
+ tmpdir = "/tmp";
+ if ((strlen(tmpdir) + 1 + 8 + 1) >= _POSIX_PATH_MAX)
+ return (char *)0;
+ i = getpid();
+ while (i < 0xffffffff &&
+ (snprintf(buf, sizeof(buf), "%s/%08x", tmpdir, i),
+ (fd = open(buf, O_RDWR | O_CREAT | O_EXCL, 0600))) == -1 &&
+ errno == EEXIST)
+ ++i;
+ if (fd == -1)
+ return (char *)0;
close(fd);
return buf;
}
-/*}}}*/
-static int cat(const char *filename) /*{{{*/
+
+static int cat(const char *filename)
{
int fd;
char buf[4096];
ssize_t l;
int err;
- if ((fd=open(filename,O_RDONLY))==-1) return -1;
- while ((l=read(fd,buf,sizeof(buf)))>0)
- {
- ssize_t off,w;
+ if ((fd = open(filename, O_RDONLY)) == -1)
+ return -1;
+ while ((l = read(fd, buf, sizeof(buf))) > 0)
+ {
+ ssize_t off, w;
- off=0;
- while (off<l)
+ off = 0;
+ while (off < l)
+ {
+ if ((w = write(1, buf + off, l - off)) == -1)
+ {
+ err = errno;
+ close(fd);
+ errno = err;
+ return -1;
+ }
+ off += w;
+ }
+ }
+ if (l == -1)
{
- if ((w=write(1,buf+off,l-off))==-1)
- {
- err=errno;
- close(fd);
- errno=err;
- return -1;
- }
- off+=w;
+ err = errno;
+ close(fd);
+ errno = err;
+ return -1;
}
- }
- if (l==-1)
- {
- err=errno;
- close(fd);
- errno=err;
- return -1;
- }
close(fd);
return 0;
}
-/*}}}*/
-static struct Value *lvalue(struct Value *value) /*{{{*/
+
+static struct Value *lvalue(struct Value *value)
{
struct Symbol *sym;
- struct Pc lvpc=pc;
+ struct Pc lvpc = pc;
- sym=pc.token->u.identifier->sym;
- assert(pass==DECLARE || sym->type==GLOBALVAR || sym->type==GLOBALARRAY || sym->type==LOCALVAR);
- if ((pc.token+1)->type==T_OP)
- {
- struct Pc idxpc;
- unsigned int dim,capacity;
- int *idx;
-
- pc.token+=2;
- dim=0;
- capacity=0;
- idx=(int*)0;
- while (1)
+ sym = pc.token->u.identifier->sym;
+ assert(pass == DECLARE || sym->type == GLOBALVAR || sym->type == GLOBALARRAY
+ || sym->type == LOCALVAR);
+ if ((pc.token + 1)->type == T_OP)
{
- if (dim==capacity && pass==INTERPRET) /* enlarge idx */ /*{{{*/
- {
- int *more;
+ struct Pc idxpc;
+ unsigned int dim, capacity;
+ int *idx;
+
+ pc.token += 2;
+ dim = 0;
+ capacity = 0;
+ idx = (int *)0;
+ while (1)
+ {
+ if (dim == capacity && pass == INTERPRET) /* enlarge idx */
+ {
+ int *more;
+
+ more =
+ realloc(idx,
+ sizeof(unsigned int) *
+ (capacity ? (capacity *= 2) : (capacity = 3)));
+ if (!more)
+ {
+ if (capacity)
+ free(idx);
+ return Value_new_ERROR(value, OUTOFMEMORY);
+ }
+ idx = more;
+ }
- more=realloc(idx,sizeof(unsigned int)*(capacity?(capacity*=2):(capacity=3)));
- if (!more)
+ idxpc = pc;
+ if (eval(value, _("index"))->type == V_ERROR ||
+ VALUE_RETYPE(value, V_INTEGER)->type == V_ERROR)
+ {
+ if (capacity)
+ free(idx);
+ pc = idxpc;
+ return value;
+ }
+ if (pass == INTERPRET)
+ {
+ idx[dim] = value->u.integer;
+ ++dim;
+ }
+ Value_destroy(value);
+ if (pc.token->type == T_COMMA)
+ ++pc.token;
+ else
+ break;
+ }
+ if (pc.token->type != T_CP)
{
- if (capacity) free(idx);
- return Value_new_ERROR(value,OUTOFMEMORY);
+ assert(pass != INTERPRET);
+ return Value_new_ERROR(value, MISSINGCP);
}
- idx=more;
- }
- /*}}}*/
- idxpc=pc;
- if (eval(value,_("index"))->type==V_ERROR || VALUE_RETYPE(value,V_INTEGER)->type==V_ERROR)
- {
- if (capacity) free(idx);
- pc=idxpc;
- return value;
- }
- if (pass==INTERPRET)
- {
- idx[dim]=value->u.integer;
- ++dim;
- }
- Value_destroy(value);
- if (pc.token->type==T_COMMA) ++pc.token;
- else break;
- }
- if (pc.token->type!=T_CP)
- {
- assert(pass!=INTERPRET);
- return Value_new_ERROR(value,MISSINGCP);
- }
- else ++pc.token;
- switch (pass)
- {
- case INTERPRET:
- {
- if ((value=Var_value(&(sym->u.var),dim,idx,value))->type==V_ERROR) pc=lvpc;
- free(idx);
- return value;
- }
- case DECLARE:
- {
- return Value_nullValue(V_INTEGER);
- }
- case COMPILE:
- {
- return Value_nullValue(sym->type==GLOBALARRAY ? sym->u.var.type : Auto_varType(&stack,sym));
- }
- default: assert(0);
+ else
+ ++pc.token;
+ switch (pass)
+ {
+ case INTERPRET:
+ {
+ if ((value =
+ Var_value(&(sym->u.var), dim, idx, value))->type == V_ERROR)
+ pc = lvpc;
+ free(idx);
+ return value;
+ }
+ case DECLARE:
+ {
+ return Value_nullValue(V_INTEGER);
+ }
+ case COMPILE:
+ {
+ return Value_nullValue(sym->type ==
+ GLOBALARRAY ? sym->u.var.
+ type : Auto_varType(&stack, sym));
+ }
+ default:
+ assert(0);
+ }
+ return (struct Value *)0;
}
- return (struct Value*)0;
- }
else
- {
- ++pc.token;
- switch (pass)
{
- case INTERPRET: return VAR_SCALAR_VALUE(sym->type==GLOBALVAR ? &(sym->u.var) : Auto_local(&stack,sym->u.local.offset));
- case DECLARE: return Value_nullValue(V_INTEGER);
- case COMPILE: return Value_nullValue(sym->type==GLOBALVAR? sym->u.var.type : Auto_varType(&stack,sym));
- default: assert(0);
+ ++pc.token;
+ switch (pass)
+ {
+ case INTERPRET:
+ return VAR_SCALAR_VALUE(sym->type ==
+ GLOBALVAR ? &(sym->u.var) : Auto_local(&stack,
+ sym->u.
+ local.
+ offset));
+ case DECLARE:
+ return Value_nullValue(V_INTEGER);
+ case COMPILE:
+ return Value_nullValue(sym->type ==
+ GLOBALVAR ? sym->u.var.
+ type : Auto_varType(&stack, sym));
+ default:
+ assert(0);
+ }
+ return (struct Value *)0;
}
- return (struct Value*)0;
- }
}
-/*}}}*/
-static struct Value *func(struct Value *value) /*{{{*/
+
+static struct Value *func(struct Value *value)
{
struct Identifier *ident;
- struct Pc funcpc=pc;
- int firstslot=-99;
- int args=0;
+ struct Pc funcpc = pc;
+ int firstslot = -99;
+ int args = 0;
struct Symbol *sym;
- assert(pc.token->type==T_IDENTIFIER);
+ assert(pc.token->type == T_IDENTIFIER);
/*
- Evaluating a function in direct mode may start a program, so it needs to
- be compiled. If in direct mode, programs will be compiled after the
- direct mode pass DECLARE, but errors are ignored at that point, because
- the program may not be needed. If the program is fine, its symbols will
- be available during the compile phase already. If not and we need it
- at this point, compile it again to get the error and abort.
- */
- if (DIRECTMODE && !program.runnable && pass!=DECLARE)
- {
- if (compileProgram(value,0)->type==V_ERROR) return value;
- Value_destroy(value);
- }
- ident=pc.token->u.identifier;
- assert(pass==DECLARE || ident->sym->type==BUILTINFUNCTION || ident->sym->type==USERFUNCTION);
- ++pc.token;
- if (pass!=DECLARE)
- {
- firstslot=stack.stackPointer;
- if (ident->sym->type==USERFUNCTION && ident->sym->u.sub.retType!=V_VOID)
+ * Evaluating a function in direct mode may start a program, so it needs to
+ * be compiled. If in direct mode, programs will be compiled after the
+ * direct mode pass DECLARE, but errors are ignored at that point, because
+ * the program may not be needed. If the program is fine, its symbols will
+ * be available during the compile phase already. If not and we need it at
+ * this point, compile it again to get the error and abort. */
+ if (DIRECTMODE && !program.runnable && pass != DECLARE)
{
- struct Var *v=Auto_pushArg(&stack);
- Var_new(v,ident->sym->u.sub.retType,0,(const unsigned int*)0,0);
+ if (compileProgram(value, 0)->type == V_ERROR)
+ return value;
+ Value_destroy(value);
}
- }
- if (pc.token->type==T_OP) /* push arguments to stack */ /*{{{*/
- {
- ++pc.token;
- if (pc.token->type!=T_CP) while (1)
+ ident = pc.token->u.identifier;
+ assert(pass == DECLARE || ident->sym->type == BUILTINFUNCTION ||
+ ident->sym->type == USERFUNCTION);
+ ++pc.token;
+ if (pass != DECLARE)
{
- if (pass==DECLARE)
- {
- if (eval(value,_("actual parameter"))->type==V_ERROR) return value;
- Value_destroy(value);
- }
- else
- {
- struct Var *v=Auto_pushArg(&stack);
-
- Var_new_scalar(v);
- if (eval(v->value,(const char*)0)->type==V_ERROR)
+ firstslot = stack.stackPointer;
+ if (ident->sym->type == USERFUNCTION &&
+ ident->sym->u.sub.retType != V_VOID)
{
- Value_clone(value,v->value);
- while (stack.stackPointer>firstslot) Var_destroy(&stack.slot[--stack.stackPointer].var);
- return value;
+ struct Var *v = Auto_pushArg(&stack);
+ Var_new(v, ident->sym->u.sub.retType, 0, (const unsigned int *)0, 0);
}
- v->type=v->value->type;
- }
- ++args;
- if (pc.token->type==T_COMMA) ++pc.token;
- else break;
}
- if (pc.token->type!=T_CP)
+ if (pc.token->type == T_OP) /* push arguments to stack */
{
- if (pass!=DECLARE)
- {
- while (stack.stackPointer>firstslot) Var_destroy(&stack.slot[--stack.stackPointer].var);
- }
- return Value_new_ERROR(value,MISSINGCP);
+ ++pc.token;
+ if (pc.token->type != T_CP)
+ while (1)
+ {
+ if (pass == DECLARE)
+ {
+ if (eval(value, _("actual parameter"))->type == V_ERROR)
+ return value;
+ Value_destroy(value);
+ }
+ else
+ {
+ struct Var *v = Auto_pushArg(&stack);
+
+ Var_new_scalar(v);
+ if (eval(v->value, (const char *)0)->type == V_ERROR)
+ {
+ Value_clone(value, v->value);
+ while (stack.stackPointer > firstslot)
+ Var_destroy(&stack.slot[--stack.stackPointer].var);
+ return value;
+ }
+ v->type = v->value->type;
+ }
+ ++args;
+ if (pc.token->type == T_COMMA)
+ ++pc.token;
+ else
+ break;
+ }
+ if (pc.token->type != T_CP)
+ {
+ if (pass != DECLARE)
+ {
+ while (stack.stackPointer > firstslot)
+ Var_destroy(&stack.slot[--stack.stackPointer].var);
+ }
+ return Value_new_ERROR(value, MISSINGCP);
+ }
+ ++pc.token;
}
- ++pc.token;
- }
- /*}}}*/
- if (pass==DECLARE) Value_new_null(value,ident->defaultType);
- else
- {
- int i;
- int nomore;
- int argerr;
- int overloaded;
- if (pass==INTERPRET && ident->sym->type==USERFUNCTION)
+ if (pass == DECLARE)
+ Value_new_null(value, ident->defaultType);
+ else
{
- for (i=0; i<ident->sym->u.sub.u.def.localLength; ++i)
- {
- struct Var *v=Auto_pushArg(&stack);
- Var_new(v,ident->sym->u.sub.u.def.localTypes[i],0,(const unsigned int*)0,0);
- }
- }
- Auto_pushFuncRet(&stack,firstslot,&pc);
+ int i;
+ int nomore;
+ int argerr;
+ int overloaded;
- sym=ident->sym;
- overloaded=(pass==COMPILE && sym->type==BUILTINFUNCTION && sym->u.sub.u.bltin.next);
- do
- {
- nomore=(pass==COMPILE && !(sym->type==BUILTINFUNCTION && sym->u.sub.u.bltin.next));
- argerr=0;
- if (args<sym->u.sub.argLength) /*{{{*/
- {
- if (nomore) Value_new_ERROR(value,TOOFEW);
- argerr=1;
- }
- /*}}}*/
- else if (args>sym->u.sub.argLength) /*{{{*/
- {
- if (nomore) Value_new_ERROR(value,TOOMANY);
- argerr=1;
- }
- /*}}}*/
- else /*{{{*/
- {
- for (i=0; i<args; ++i)
+ if (pass == INTERPRET && ident->sym->type == USERFUNCTION)
{
- struct Value *arg=Var_value(Auto_local(&stack,i),0,(int*)0,value);
-
- assert(arg->type!=V_ERROR);
- if (overloaded)
- {
- if (arg->type!=sym->u.sub.argTypes[i])
+ for (i = 0; i < ident->sym->u.sub.u.def.localLength; ++i)
{
- if (nomore) Value_new_ERROR(value,TYPEMISMATCH2,i+1);
- argerr=1;
- break;
+ struct Var *v = Auto_pushArg(&stack);
+ Var_new(v, ident->sym->u.sub.u.def.localTypes[i], 0,
+ (const unsigned int *)0, 0);
}
- }
- else if (Value_retype(arg,sym->u.sub.argTypes[i])->type==V_ERROR)
- {
- if (nomore) Value_new_ERROR(value,TYPEMISMATCH3,arg->u.error.msg,i+1);
- argerr=1;
- break;
- }
}
- }
- /*}}}*/
- if (argerr)
- {
- if (nomore)
- {
- Auto_funcReturn(&stack,(struct Pc*)0);
- pc=funcpc;
- return value;
- }
- else sym=sym->u.sub.u.bltin.next;
- }
- } while (argerr);
- ident->sym=sym;
- if (sym->type==BUILTINFUNCTION)
- {
- if (pass==INTERPRET)
- {
- if (sym->u.sub.u.bltin.call(value,&stack)->type==V_ERROR) pc=funcpc;
- }
- else Value_new_null(value,sym->u.sub.retType);
- }
- else if (sym->type==USERFUNCTION)
- {
- if (pass==INTERPRET)
- {
- int r=1;
+ Auto_pushFuncRet(&stack, firstslot, &pc);
- pc=sym->u.sub.u.def.scope.start;
- if (pc.token->type==T_COLON) ++pc.token;
- else Program_skipEOL(&program,&pc,STDCHANNEL,1);
- do
+ sym = ident->sym;
+ overloaded = (pass == COMPILE && sym->type == BUILTINFUNCTION &&
+ sym->u.sub.u.bltin.next);
+ do
{
- if (statements(value)->type==V_ERROR)
- {
- if (strchr(value->u.error.msg,'\n')==(char*)0)
+ nomore = (pass == COMPILE &&
+ !(sym->type == BUILTINFUNCTION && sym->u.sub.u.bltin.next));
+ argerr = 0;
+ if (args < sym->u.sub.argLength)
{
- Auto_setError(&stack,Program_lineNumber(&program,&pc),&pc,value);
- Program_PCtoError(&program,&pc,value);
+ if (nomore)
+ Value_new_ERROR(value, TOOFEW);
+ argerr = 1;
}
- if (stack.onerror.line!=-1)
+
+ else if (args > sym->u.sub.argLength)
{
- stack.resumeable=1;
- pc=stack.onerror;
+ if (nomore)
+ Value_new_ERROR(value, TOOMANY);
+ argerr = 1;
}
- else
+
+ else
{
- Auto_frameToError(&stack,&program,value);
- break;
+ for (i = 0; i < args; ++i)
+ {
+ struct Value *arg =
+ Var_value(Auto_local(&stack, i), 0, (int *)0, value);
+
+ assert(arg->type != V_ERROR);
+ if (overloaded)
+ {
+ if (arg->type != sym->u.sub.argTypes[i])
+ {
+ if (nomore)
+ Value_new_ERROR(value, TYPEMISMATCH2, i + 1);
+ argerr = 1;
+ break;
+ }
+ }
+ else if (Value_retype(arg, sym->u.sub.argTypes[i])->type ==
+ V_ERROR)
+ {
+ if (nomore)
+ Value_new_ERROR(value, TYPEMISMATCH3, arg->u.error.msg,
+ i + 1);
+ argerr = 1;
+ break;
+ }
+ }
}
- }
- else if (value->type!=V_NIL) break;
- Value_destroy(value);
- } while ((r=Program_skipEOL(&program,&pc,STDCHANNEL,1)));
- if (!r) Value_new_VOID(value);
- }
- else Value_new_null(value,sym->u.sub.retType);
+
+ if (argerr)
+ {
+ if (nomore)
+ {
+ Auto_funcReturn(&stack, (struct Pc *)0);
+ pc = funcpc;
+ return value;
+ }
+ else
+ sym = sym->u.sub.u.bltin.next;
+ }
+ }
+ while (argerr);
+ ident->sym = sym;
+ if (sym->type == BUILTINFUNCTION)
+ {
+ if (pass == INTERPRET)
+ {
+ if (sym->u.sub.u.bltin.call(value, &stack)->type == V_ERROR)
+ pc = funcpc;
+ }
+ else
+ Value_new_null(value, sym->u.sub.retType);
+ }
+ else if (sym->type == USERFUNCTION)
+ {
+ if (pass == INTERPRET)
+ {
+ int r = 1;
+
+ pc = sym->u.sub.u.def.scope.start;
+ if (pc.token->type == T_COLON)
+ ++pc.token;
+ else
+ Program_skipEOL(&program, &pc, STDCHANNEL, 1);
+ do
+ {
+ if (statements(value)->type == V_ERROR)
+ {
+ if (strchr(value->u.error.msg, '\n') == (char *)0)
+ {
+ Auto_setError(&stack,
+ Program_lineNumber(&program, &pc), &pc,
+ value);
+ Program_PCtoError(&program, &pc, value);
+ }
+ if (stack.onerror.line != -1)
+ {
+ stack.resumeable = 1;
+ pc = stack.onerror;
+ }
+ else
+ {
+ Auto_frameToError(&stack, &program, value);
+ break;
+ }
+ }
+ else if (value->type != V_NIL)
+ break;
+ Value_destroy(value);
+ }
+ while ((r = Program_skipEOL(&program, &pc, STDCHANNEL, 1)));
+ if (!r)
+ Value_new_VOID(value);
+ }
+ else
+ Value_new_null(value, sym->u.sub.retType);
+ }
+ Auto_funcReturn(&stack, pass == INTERPRET &&
+ value->type != V_ERROR ? &pc : (struct Pc *)0);
}
- Auto_funcReturn(&stack,pass==INTERPRET && value->type!=V_ERROR ? &pc : (struct Pc*)0);
- }
return value;
}
-/*}}}*/
#ifdef USE_LR0
-/* Grammar with LR(0) sets */ /*{{{*/
+
+/* Grammar with LR(0) sets */
/*
Grammar:
@@ -491,578 +574,716 @@ i9:
E -> ( E ) . reduce 4
*/
-/*}}}*/
-static struct Value *eval(struct Value *value, const char *desc) /*{{{*/
+
+static struct Value *eval(struct Value *value, const char *desc)
{
- /* variables */ /*{{{*/
- static const int gotoState[10]={ 5,8,6,7,-1,-1,-1,-1,-1,-1 };
- int capacity=10;
+ /* variables */
+ static const int gotoState[10] = { 5, 8, 6, 7, -1, -1, -1, -1, -1, -1 };
+ int capacity = 10;
struct Pdastack
- {
- union
{
- enum TokenType token;
- struct Value value;
- } u;
- char state;
- };
- struct Pdastack *pdastack=malloc(capacity*sizeof(struct Pdastack));
- struct Pdastack *sp=pdastack;
- struct Pdastack *stackEnd=pdastack+capacity-1;
+ union
+ {
+ enum TokenType token;
+ struct Value value;
+ } u;
+ char state;
+ };
+ struct Pdastack *pdastack = malloc(capacity * sizeof(struct Pdastack));
+ struct Pdastack *sp = pdastack;
+ struct Pdastack *stackEnd = pdastack + capacity - 1;
enum TokenType ip;
- /*}}}*/
- sp->state=0;
+ sp->state = 0;
while (1)
- {
- if (sp==stackEnd)
- {
- pdastack=realloc(pdastack,(capacity+10)*sizeof(struct Pdastack));
- sp=pdastack+capacity-1;
- capacity+=10;
- stackEnd=pdastack+capacity-1;
- }
- ip=pc.token->type;
- switch (sp->state)
{
- case 0:
- case 1:
- case 2:
- case 3: /*{{{*/ /* including 4 */
- {
- if (ip==T_IDENTIFIER) /*{{{*/
+ if (sp == stackEnd)
+ {
+ pdastack =
+ realloc(pdastack, (capacity + 10) * sizeof(struct Pdastack));
+ sp = pdastack + capacity - 1;
+ capacity += 10;
+ stackEnd = pdastack + capacity - 1;
+ }
+ ip = pc.token->type;
+ switch (sp->state)
{
- /* printf("state %d: shift 4\n",sp->state); */
- /* printf("state 4: reduce E -> value\n"); */
- ++sp;
- sp->state=gotoState[(sp-1)->state];
- if (pass==COMPILE)
+ case 0:
+ case 1:
+ case 2:
+ case 3: /* including 4 */
{
- if
- (
- ((pc.token+1)->type==T_OP || Auto_find(&stack,pc.token->u.identifier)==0)
- && Global_find(&globals,pc.token->u.identifier,(pc.token+1)->type==T_OP)==0
- )
- {
- Value_new_ERROR(value,UNDECLARED);
- goto error;
- }
+ if (ip == T_IDENTIFIER)
+ {
+ /* printf("state %d: shift 4\n",sp->state); */
+ /* printf("state 4: reduce E -> value\n"); */
+ ++sp;
+ sp->state = gotoState[(sp - 1)->state];
+ if (pass == COMPILE)
+ {
+ if (((pc.token + 1)->type == T_OP ||
+ Auto_find(&stack, pc.token->u.identifier) == 0) &&
+ Global_find(&globals, pc.token->u.identifier,
+ (pc.token + 1)->type == T_OP) == 0)
+ {
+ Value_new_ERROR(value, UNDECLARED);
+ goto error;
+ }
+ }
+ if (pass != DECLARE &&
+ (pc.token->u.identifier->sym->type == GLOBALVAR ||
+ pc.token->u.identifier->sym->type == GLOBALARRAY ||
+ pc.token->u.identifier->sym->type == LOCALVAR))
+ {
+ struct Value *l;
+
+ if ((l = lvalue(value))->type == V_ERROR)
+ goto error;
+ Value_clone(&sp->u.value, l);
+ }
+ else
+ {
+ struct Pc var = pc;
+
+ func(&sp->u.value);
+ if (sp->u.value.type == V_VOID)
+ {
+ pc = var;
+ Value_new_ERROR(value, VOIDVALUE);
+ goto error;
+ }
+ }
+ }
+ else if (ip == T_INTEGER)
+ {
+ /* printf("state %d: shift 4\n",sp->state); */
+ /* printf("state 4: reduce E -> value\n"); */
+ ++sp;
+ sp->state = gotoState[(sp - 1)->state];
+ VALUE_NEW_INTEGER(&sp->u.value, pc.token->u.integer);
+ ++pc.token;
+ }
+ else if (ip == T_REAL)
+ {
+ /* printf("state %d: shift 4\n",sp->state); */
+ /* printf("state 4: reduce E -> value\n"); */
+ ++sp;
+ sp->state = gotoState[(sp - 1)->state];
+ VALUE_NEW_REAL(&sp->u.value, pc.token->u.real);
+ ++pc.token;
+ }
+ else if (TOKEN_ISUNARYOPERATOR(ip))
+ {
+ /* printf("state %d: shift 2\n",sp->state); */
+ ++sp;
+ sp->state = 2;
+ sp->u.token = ip;
+ ++pc.token;
+ }
+ else if (ip == T_HEXINTEGER)
+ {
+ /* printf("state %d: shift 4\n",sp->state); */
+ /* printf("state 4: reduce E -> value\n"); */
+ ++sp;
+ sp->state = gotoState[(sp - 1)->state];
+ VALUE_NEW_INTEGER(&sp->u.value, pc.token->u.hexinteger);
+ ++pc.token;
+ }
+ else if (ip == T_OCTINTEGER)
+ {
+ /* printf("state %d: shift 4\n",sp->state); */
+ /* printf("state 4: reduce E -> value\n"); */
+ ++sp;
+ sp->state = gotoState[(sp - 1)->state];
+ VALUE_NEW_INTEGER(&sp->u.value, pc.token->u.octinteger);
+ ++pc.token;
+ }
+ else if (ip == T_OP)
+ {
+ /* printf("state %d: shift 3\n",sp->state); */
+ ++sp;
+ sp->state = 3;
+ sp->u.token = T_OP;
+ ++pc.token;
+ }
+ else if (ip == T_STRING)
+ {
+ /* printf("state %d: shift 4\n",sp->state); */
+ /* printf("state 4: reduce E -> value\n"); */
+ ++sp;
+ sp->state = gotoState[(sp - 1)->state];
+ Value_new_STRING(&sp->u.value);
+ String_destroy(&sp->u.value.u.string);
+ String_clone(&sp->u.value.u.string, pc.token->u.string);
+ ++pc.token;
+ }
+ else
+ {
+ char state = sp->state;
+
+ if (state == 0)
+ {
+ if (desc)
+ Value_new_ERROR(value, MISSINGEXPR, desc);
+ else
+ value = (struct Value *)0;
+ }
+ else
+ Value_new_ERROR(value, MISSINGEXPR, _("operand"));
+ goto error;
+ }
+ break;
}
- if (pass!=DECLARE && (pc.token->u.identifier->sym->type==GLOBALVAR || pc.token->u.identifier->sym->type==GLOBALARRAY || pc.token->u.identifier->sym->type==LOCALVAR))
- {
- struct Value *l;
- if ((l=lvalue(value))->type==V_ERROR) goto error;
- Value_clone(&sp->u.value,l);
- }
- else
+ case 5:
{
- struct Pc var=pc;
-
- func(&sp->u.value);
- if (sp->u.value.type==V_VOID)
- {
- pc=var;
- Value_new_ERROR(value,VOIDVALUE);
- goto error;
- }
+ if (TOKEN_ISBINARYOPERATOR(ip))
+ {
+ /* printf("state %d: shift 1\n",sp->state); */
+ ++sp;
+ sp->state = 1;
+ sp->u.token = ip;
+ ++pc.token;
+ break;
+ }
+ else
+ {
+ assert(sp == pdastack + 1);
+ *value = sp->u.value;
+ free(pdastack);
+ return value;
+ }
+ break;
}
- }
- /*}}}*/
- else if (ip==T_INTEGER) /*{{{*/
- {
- /* printf("state %d: shift 4\n",sp->state); */
- /* printf("state 4: reduce E -> value\n"); */
- ++sp;
- sp->state=gotoState[(sp-1)->state];
- VALUE_NEW_INTEGER(&sp->u.value,pc.token->u.integer);
- ++pc.token;
- }
- /*}}}*/
- else if (ip==T_REAL) /*{{{*/
- {
- /* printf("state %d: shift 4\n",sp->state); */
- /* printf("state 4: reduce E -> value\n"); */
- ++sp;
- sp->state=gotoState[(sp-1)->state];
- VALUE_NEW_REAL(&sp->u.value,pc.token->u.real);
- ++pc.token;
- }
- /*}}}*/
- else if (TOKEN_ISUNARYOPERATOR(ip)) /*{{{*/
- {
- /* printf("state %d: shift 2\n",sp->state); */
- ++sp;
- sp->state=2;
- sp->u.token=ip;
- ++pc.token;
- }
- /*}}}*/
- else if (ip==T_HEXINTEGER) /*{{{*/
- {
- /* printf("state %d: shift 4\n",sp->state); */
- /* printf("state 4: reduce E -> value\n"); */
- ++sp;
- sp->state=gotoState[(sp-1)->state];
- VALUE_NEW_INTEGER(&sp->u.value,pc.token->u.hexinteger);
- ++pc.token;
- }
- /*}}}*/
- else if (ip==T_OCTINTEGER) /*{{{*/
- {
- /* printf("state %d: shift 4\n",sp->state); */
- /* printf("state 4: reduce E -> value\n"); */
- ++sp;
- sp->state=gotoState[(sp-1)->state];
- VALUE_NEW_INTEGER(&sp->u.value,pc.token->u.octinteger);
- ++pc.token;
- }
- /*}}}*/
- else if (ip==T_OP) /*{{{*/
- {
- /* printf("state %d: shift 3\n",sp->state); */
- ++sp;
- sp->state=3;
- sp->u.token=T_OP;
- ++pc.token;
- }
- /*}}}*/
- else if (ip==T_STRING) /*{{{*/
- {
- /* printf("state %d: shift 4\n",sp->state); */
- /* printf("state 4: reduce E -> value\n"); */
- ++sp;
- sp->state=gotoState[(sp-1)->state];
- Value_new_STRING(&sp->u.value);
- String_destroy(&sp->u.value.u.string);
- String_clone(&sp->u.value.u.string,pc.token->u.string);
- ++pc.token;
- }
- /*}}}*/
- else /*{{{*/
- {
- char state=sp->state;
- if (state==0)
+ case 6:
{
- if (desc) Value_new_ERROR(value,MISSINGEXPR,desc);
- else value=(struct Value*)0;
+ if (TOKEN_ISBINARYOPERATOR(ip) &&
+ TOKEN_UNARYPRIORITY((sp - 1)->u.token) <
+ TOKEN_BINARYPRIORITY(ip))
+ {
+ assert(TOKEN_ISUNARYOPERATOR((sp - 1)->u.token));
+ /* printf("state %d: shift 1 (not reducing E -> op
+ * E)\n",sp->state); */
+ ++sp;
+ sp->state = 1;
+ sp->u.token = ip;
+ ++pc.token;
+ }
+ else
+ {
+ enum TokenType op;
+
+ /* printf("reduce E -> op E\n"); */
+ --sp;
+ op = sp->u.token;
+ sp->u.value = (sp + 1)->u.value;
+ switch (op)
+ {
+ case T_PLUS:
+ break;
+ case T_MINUS:
+ Value_uneg(&sp->u.value, pass == INTERPRET);
+ break;
+ case T_NOT:
+ Value_unot(&sp->u.value, pass == INTERPRET);
+ break;
+ default:
+ assert(0);
+ }
+ sp->state = gotoState[(sp - 1)->state];
+ if (sp->u.value.type == V_ERROR)
+ {
+ *value = sp->u.value;
+ --sp;
+ goto error;
+ }
+ }
+ break;
}
- else Value_new_ERROR(value,MISSINGEXPR,_("operand"));
- goto error;
- }
- /*}}}*/
- break;
- }
- /*}}}*/
- case 5: /*{{{*/
- {
- if (TOKEN_ISBINARYOPERATOR(ip))
- {
- /* printf("state %d: shift 1\n",sp->state); */
- ++sp;
- sp->state=1;
- sp->u.token=ip;
- ++pc.token;
- break;
- }
- else
- {
- assert(sp==pdastack+1);
- *value=sp->u.value;
- free(pdastack);
- return value;
- }
- break;
- }
- /*}}}*/
- case 6: /*{{{*/
- {
- if (TOKEN_ISBINARYOPERATOR(ip) && TOKEN_UNARYPRIORITY((sp-1)->u.token)<TOKEN_BINARYPRIORITY(ip))
- {
- assert(TOKEN_ISUNARYOPERATOR((sp-1)->u.token));
- /* printf("state %d: shift 1 (not reducing E -> op E)\n",sp->state); */
- ++sp;
- sp->state=1;
- sp->u.token=ip;
- ++pc.token;
- }
- else
- {
- enum TokenType op;
- /* printf("reduce E -> op E\n"); */
- --sp;
- op=sp->u.token;
- sp->u.value=(sp+1)->u.value;
- switch (op)
+ case 7: /* including 9 */
{
- case T_PLUS: break;
- case T_MINUS: Value_uneg(&sp->u.value,pass==INTERPRET); break;
- case T_NOT: Value_unot(&sp->u.value,pass==INTERPRET); break;
- default: assert(0);
+ if (TOKEN_ISBINARYOPERATOR(ip))
+ {
+ /* printf("state %d: shift 1\n"sp->state); */
+ ++sp;
+ sp->state = 1;
+ sp->u.token = ip;
+ ++pc.token;
+ }
+ else if (ip == T_CP)
+ {
+ /* printf("state %d: shift 9\n",sp->state); */
+ /* printf("state 9: reduce E -> ( E )\n"); */
+ --sp;
+ sp->state = gotoState[(sp - 1)->state];
+ sp->u.value = (sp + 1)->u.value;
+ ++pc.token;
+ }
+ else
+ {
+ Value_new_ERROR(value, MISSINGCP);
+ goto error;
+ }
+ break;
}
- sp->state=gotoState[(sp-1)->state];
- if (sp->u.value.type==V_ERROR)
+
+ case 8:
{
- *value=sp->u.value;
- --sp;
- goto error;
+ int p1, p2;
+
+ if (TOKEN_ISBINARYOPERATOR(ip)
+ &&
+ (((p1 = TOKEN_BINARYPRIORITY((sp - 1)->u.token)) < (p2 =
+ TOKEN_BINARYPRIORITY
+ (ip))) ||
+ (p1 == p2 && TOKEN_ISRIGHTASSOCIATIVE((sp - 1)->u.token))))
+ {
+ /* printf("state %d: shift 1\n",sp->state); */
+ ++sp;
+ sp->state = 1;
+ sp->u.token = ip;
+ ++pc.token;
+ }
+ else
+ {
+ /* printf("state %d: reduce E -> E op E\n",sp->state); */
+ if (Value_commonType[(sp - 2)->u.value.type][sp->u.value.type]
+ == V_ERROR)
+ {
+ Value_destroy(&sp->u.value);
+ sp -= 2;
+ Value_destroy(&sp->u.value);
+ Value_new_ERROR(value, INVALIDOPERAND);
+ --sp;
+ goto error;
+ }
+ else
+ switch ((sp - 1)->u.token)
+ {
+ case T_LT:
+ Value_lt(&(sp - 2)->u.value, &sp->u.value,
+ pass == INTERPRET);
+ break;
+ case T_LE:
+ Value_le(&(sp - 2)->u.value, &sp->u.value,
+ pass == INTERPRET);
+ break;
+ case T_EQ:
+ Value_eq(&(sp - 2)->u.value, &sp->u.value,
+ pass == INTERPRET);
+ break;
+ case T_GE:
+ Value_ge(&(sp - 2)->u.value, &sp->u.value,
+ pass == INTERPRET);
+ break;
+ case T_GT:
+ Value_gt(&(sp - 2)->u.value, &sp->u.value,
+ pass == INTERPRET);
+ break;
+ case T_NE:
+ Value_ne(&(sp - 2)->u.value, &sp->u.value,
+ pass == INTERPRET);
+ break;
+ case T_PLUS:
+ Value_add(&(sp - 2)->u.value, &sp->u.value,
+ pass == INTERPRET);
+ break;
+ case T_MINUS:
+ Value_sub(&(sp - 2)->u.value, &sp->u.value,
+ pass == INTERPRET);
+ break;
+ case T_MULT:
+ Value_mult(&(sp - 2)->u.value, &sp->u.value,
+ pass == INTERPRET);
+ break;
+ case T_DIV:
+ Value_div(&(sp - 2)->u.value, &sp->u.value,
+ pass == INTERPRET);
+ break;
+ case T_IDIV:
+ Value_idiv(&(sp - 2)->u.value, &sp->u.value,
+ pass == INTERPRET);
+ break;
+ case T_MOD:
+ Value_mod(&(sp - 2)->u.value, &sp->u.value,
+ pass == INTERPRET);
+ break;
+ case T_POW:
+ Value_pow(&(sp - 2)->u.value, &sp->u.value,
+ pass == INTERPRET);
+ break;
+ case T_AND:
+ Value_and(&(sp - 2)->u.value, &sp->u.value,
+ pass == INTERPRET);
+ break;
+ case T_OR:
+ Value_or(&(sp - 2)->u.value, &sp->u.value,
+ pass == INTERPRET);
+ break;
+ case T_XOR:
+ Value_xor(&(sp - 2)->u.value, &sp->u.value,
+ pass == INTERPRET);
+ break;
+ case T_EQV:
+ Value_eqv(&(sp - 2)->u.value, &sp->u.value,
+ pass == INTERPRET);
+ break;
+ case T_IMP:
+ Value_imp(&(sp - 2)->u.value, &sp->u.value,
+ pass == INTERPRET);
+ break;
+ default:
+ assert(0);
+ }
+ Value_destroy(&sp->u.value);
+ sp -= 2;
+ sp->state = gotoState[(sp - 1)->state];
+ if (sp->u.value.type == V_ERROR)
+ {
+ *value = sp->u.value;
+ --sp;
+ goto error;
+ }
+ }
+ break;
}
+
}
- break;
- }
- /*}}}*/
- case 7: /*{{{*/ /* including 9 */
- {
- if (TOKEN_ISBINARYOPERATOR(ip))
- {
- /* printf("state %d: shift 1\n"sp->state); */
- ++sp;
- sp->state=1;
- sp->u.token=ip;
- ++pc.token;
- }
- else if (ip==T_CP)
- {
- /* printf("state %d: shift 9\n",sp->state); */
- /* printf("state 9: reduce E -> ( E )\n"); */
- --sp;
- sp->state=gotoState[(sp-1)->state];
- sp->u.value=(sp+1)->u.value;
- ++pc.token;
- }
- else
- {
- Value_new_ERROR(value,MISSINGCP);
- goto error;
- }
- break;
- }
- /*}}}*/
- case 8: /*{{{*/
- {
- int p1,p2;
-
- if
- (
- TOKEN_ISBINARYOPERATOR(ip)
- &&
- (
- ((p1=TOKEN_BINARYPRIORITY((sp-1)->u.token))<(p2=TOKEN_BINARYPRIORITY(ip)))
- || (p1==p2 && TOKEN_ISRIGHTASSOCIATIVE((sp-1)->u.token))
- )
- )
- {
- /* printf("state %d: shift 1\n",sp->state); */
- ++sp;
- sp->state=1;
- sp->u.token=ip;
- ++pc.token;
- }
- else
+ }
+
+error:
+ while (sp > pdastack)
+ {
+ switch (sp->state)
{
- /* printf("state %d: reduce E -> E op E\n",sp->state); */
- if (Value_commonType[(sp-2)->u.value.type][sp->u.value.type]==V_ERROR)
- {
- Value_destroy(&sp->u.value);
- sp-=2;
- Value_destroy(&sp->u.value);
- Value_new_ERROR(value,INVALIDOPERAND);
- --sp;
- goto error;
- }
- else switch ((sp-1)->u.token)
- {
- case T_LT: Value_lt(&(sp-2)->u.value,&sp->u.value,pass==INTERPRET); break;
- case T_LE: Value_le(&(sp-2)->u.value,&sp->u.value,pass==INTERPRET); break;
- case T_EQ: Value_eq(&(sp-2)->u.value,&sp->u.value,pass==INTERPRET); break;
- case T_GE: Value_ge(&(sp-2)->u.value,&sp->u.value,pass==INTERPRET); break;
- case T_GT: Value_gt(&(sp-2)->u.value,&sp->u.value,pass==INTERPRET); break;
- case T_NE: Value_ne(&(sp-2)->u.value,&sp->u.value,pass==INTERPRET); break;
- case T_PLUS: Value_add(&(sp-2)->u.value,&sp->u.value,pass==INTERPRET); break;
- case T_MINUS: Value_sub(&(sp-2)->u.value,&sp->u.value,pass==INTERPRET); break;
- case T_MULT: Value_mult(&(sp-2)->u.value,&sp->u.value,pass==INTERPRET); break;
- case T_DIV: Value_div(&(sp-2)->u.value,&sp->u.value,pass==INTERPRET); break;
- case T_IDIV: Value_idiv(&(sp-2)->u.value,&sp->u.value,pass==INTERPRET); break;
- case T_MOD: Value_mod(&(sp-2)->u.value,&sp->u.value,pass==INTERPRET); break;
- case T_POW: Value_pow(&(sp-2)->u.value,&sp->u.value,pass==INTERPRET); break;
- case T_AND: Value_and(&(sp-2)->u.value,&sp->u.value,pass==INTERPRET); break;
- case T_OR: Value_or(&(sp-2)->u.value,&sp->u.value,pass==INTERPRET); break;
- case T_XOR: Value_xor(&(sp-2)->u.value,&sp->u.value,pass==INTERPRET); break;
- case T_EQV: Value_eqv(&(sp-2)->u.value,&sp->u.value,pass==INTERPRET); break;
- case T_IMP: Value_imp(&(sp-2)->u.value,&sp->u.value,pass==INTERPRET); break;
- default: assert(0);
- }
+ case 5:
+ case 6:
+ case 7:
+ case 8:
Value_destroy(&sp->u.value);
- sp-=2;
- sp->state=gotoState[(sp-1)->state];
- if (sp->u.value.type==V_ERROR)
- {
- *value=sp->u.value;
- --sp;
- goto error;
- }
}
- break;
- }
- /*}}}*/
- }
- }
- error:
- while (sp>pdastack)
- {
- switch (sp->state)
- {
- case 5:
- case 6:
- case 7:
- case 8: Value_destroy(&sp->u.value);
+ --sp;
}
- --sp;
- }
+
free(pdastack);
return value;
}
-/*}}}*/
+
#else
-static inline struct Value *binarydown(struct Value *value, struct Value *(level)(struct Value *value), const int prio) /*{{{*/
+static inline struct Value *binarydown(struct Value *value, struct Value *(level) (struct Value * value), const int prio)
{
enum TokenType op;
struct Pc oppc;
- if (level(value)==(struct Value*)0) return (struct Value*)0;
- if (value->type==V_ERROR) return value;
+ if (level(value) == (struct Value *)0)
+ return (struct Value *)0;
+ if (value->type == V_ERROR)
+ return value;
do
- {
- struct Value x;
-
- op=pc.token->type;
- if (!TOKEN_ISBINARYOPERATOR(op) || TOKEN_BINARYPRIORITY(op)!=prio) return value;
- oppc=pc;
- ++pc.token;
- if (level(&x)==(struct Value*)0)
{
- Value_destroy(value);
- return Value_new_ERROR(value,MISSINGEXPR,_("binary operand"));
- }
- if (x.type==V_ERROR)
- {
- Value_destroy(value);
- *value=x;
- return value;
- }
- if (Value_commonType[value->type][x.type]==V_ERROR)
- {
- Value_destroy(value);
+ struct Value x;
+
+ op = pc.token->type;
+ if (!TOKEN_ISBINARYOPERATOR(op) || TOKEN_BINARYPRIORITY(op) != prio)
+ return value;
+ oppc = pc;
+ ++pc.token;
+ if (level(&x) == (struct Value *)0)
+ {
+ Value_destroy(value);
+ return Value_new_ERROR(value, MISSINGEXPR, _("binary operand"));
+ }
+ if (x.type == V_ERROR)
+ {
+ Value_destroy(value);
+ *value = x;
+ return value;
+ }
+ if (Value_commonType[value->type][x.type] == V_ERROR)
+ {
+ Value_destroy(value);
+ Value_destroy(&x);
+ return Value_new_ERROR(value, INVALIDOPERAND);
+ }
+ else
+ switch (op)
+ {
+ case T_LT:
+ Value_lt(value, &x, pass == INTERPRET);
+ break;
+ case T_LE:
+ Value_le(value, &x, pass == INTERPRET);
+ break;
+ case T_EQ:
+ Value_eq(value, &x, pass == INTERPRET);
+ break;
+ case T_GE:
+ Value_ge(value, &x, pass == INTERPRET);
+ break;
+ case T_GT:
+ Value_gt(value, &x, pass == INTERPRET);
+ break;
+ case T_NE:
+ Value_ne(value, &x, pass == INTERPRET);
+ break;
+ case T_PLUS:
+ Value_add(value, &x, pass == INTERPRET);
+ break;
+ case T_MINUS:
+ Value_sub(value, &x, pass == INTERPRET);
+ break;
+ case T_MULT:
+ Value_mult(value, &x, pass == INTERPRET);
+ break;
+ case T_DIV:
+ Value_div(value, &x, pass == INTERPRET);
+ break;
+ case T_IDIV:
+ Value_idiv(value, &x, pass == INTERPRET);
+ break;
+ case T_MOD:
+ Value_mod(value, &x, pass == INTERPRET);
+ break;
+ case T_POW:
+ Value_pow(value, &x, pass == INTERPRET);
+ break;
+ case T_AND:
+ Value_and(value, &x, pass == INTERPRET);
+ break;
+ case T_OR:
+ Value_or(value, &x, pass == INTERPRET);
+ break;
+ case T_XOR:
+ Value_xor(value, &x, pass == INTERPRET);
+ break;
+ case T_EQV:
+ Value_eqv(value, &x, pass == INTERPRET);
+ break;
+ case T_IMP:
+ Value_imp(value, &x, pass == INTERPRET);
+ break;
+ default:
+ assert(0);
+ }
+
Value_destroy(&x);
- return Value_new_ERROR(value,INVALIDOPERAND);
- }
- else switch (op)
- {
- case T_LT: Value_lt(value,&x,pass==INTERPRET); break;
- case T_LE: Value_le(value,&x,pass==INTERPRET); break;
- case T_EQ: Value_eq(value,&x,pass==INTERPRET); break;
- case T_GE: Value_ge(value,&x,pass==INTERPRET); break;
- case T_GT: Value_gt(value,&x,pass==INTERPRET); break;
- case T_NE: Value_ne(value,&x,pass==INTERPRET); break;
- case T_PLUS: Value_add(value,&x,pass==INTERPRET); break;
- case T_MINUS: Value_sub(value,&x,pass==INTERPRET); break;
- case T_MULT: Value_mult(value,&x,pass==INTERPRET); break;
- case T_DIV: Value_div(value,&x,pass==INTERPRET); break;
- case T_IDIV: Value_idiv(value,&x,pass==INTERPRET); break;
- case T_MOD: Value_mod(value,&x,pass==INTERPRET); break;
- case T_POW: Value_pow(value,&x,pass==INTERPRET); break;
- case T_AND: Value_and(value,&x,pass==INTERPRET); break;
- case T_OR: Value_or(value,&x,pass==INTERPRET); break;
- case T_XOR: Value_xor(value,&x,pass==INTERPRET); break;
- case T_EQV: Value_eqv(value,&x,pass==INTERPRET); break;
- case T_IMP: Value_imp(value,&x,pass==INTERPRET); break;
- default: assert(0);
}
- Value_destroy(&x);
- } while (value->type!=V_ERROR);
- if (value->type==V_ERROR) pc=oppc;
+ while (value->type != V_ERROR);
+
+ if (value->type == V_ERROR)
+ pc = oppc;
+
return value;
}
-/*}}}*/
-static inline struct Value *unarydown(struct Value *value, struct Value *(level)(struct Value *value), const int prio) /*{{{*/
+
+
+static inline struct Value *unarydown(struct Value *value, struct Value *(level) (struct Value * value), const int prio)
{
enum TokenType op;
struct Pc oppc;
- op=pc.token->type;
- if (!TOKEN_ISUNARYOPERATOR(op) || TOKEN_UNARYPRIORITY(op)!=prio) return level(value);
- oppc=pc;
+ op = pc.token->type;
+ if (!TOKEN_ISUNARYOPERATOR(op) || TOKEN_UNARYPRIORITY(op) != prio)
+ return level(value);
+ oppc = pc;
++pc.token;
- if (unarydown(value,level,prio)==(struct Value*)0) return Value_new_ERROR(value,MISSINGEXPR,_("unary operand"));
- if (value->type==V_ERROR) return value;
+ if (unarydown(value, level, prio) == (struct Value *)0)
+ return Value_new_ERROR(value, MISSINGEXPR, _("unary operand"));
+
+ if (value->type == V_ERROR)
+ return value;
+
switch (op)
- {
- case T_PLUS: Value_uplus(value,pass==INTERPRET); break;
- case T_MINUS: Value_uneg(value,pass==INTERPRET); break;
- case T_NOT: Value_unot(value,pass==INTERPRET); break;
- default: assert(0);
- }
- if (value->type==V_ERROR) pc=oppc;
+ {
+ case T_PLUS:
+ Value_uplus(value, pass == INTERPRET);
+ break;
+ case T_MINUS:
+ Value_uneg(value, pass == INTERPRET);
+ break;
+ case T_NOT:
+ Value_unot(value, pass == INTERPRET);
+ break;
+ default:
+ assert(0);
+ }
+
+ if (value->type == V_ERROR)
+ pc = oppc;
+
return value;
}
-/*}}}*/
-static struct Value *eval8(struct Value *value) /*{{{*/
+
+
+static struct Value *eval8(struct Value *value)
{
switch (pc.token->type)
- {
- case T_IDENTIFIER: /*{{{*/
{
- struct Pc var;
- struct Value *l;
+ case T_IDENTIFIER:
+ {
+ struct Pc var;
+ struct Value *l;
- var=pc;
- if (pass==COMPILE)
+ var = pc;
+ if (pass == COMPILE)
+ {
+ if (((pc.token + 1)->type == T_OP ||
+ Auto_find(&stack, pc.token->u.identifier) == 0) &&
+ Global_find(&globals, pc.token->u.identifier,
+ (pc.token + 1)->type == T_OP) == 0)
+ return Value_new_ERROR(value, UNDECLARED);
+ }
+ assert(pass == DECLARE || pc.token->u.identifier->sym);
+ if (pass != DECLARE &&
+ (pc.token->u.identifier->sym->type == GLOBALVAR ||
+ pc.token->u.identifier->sym->type == GLOBALARRAY ||
+ pc.token->u.identifier->sym->type == LOCALVAR))
+ {
+ if ((l = lvalue(value))->type == V_ERROR)
+ return value;
+ Value_clone(value, l);
+ }
+ else
+ {
+ func(value);
+ if (value->type == V_VOID)
+ {
+ Value_destroy(value);
+ pc = var;
+ return Value_new_ERROR(value, VOIDVALUE);
+ }
+ }
+ break;
+ }
+
+ case T_INTEGER:
{
- if
- (
- ((pc.token+1)->type==T_OP || Auto_find(&stack,pc.token->u.identifier)==0)
- && Global_find(&globals,pc.token->u.identifier,(pc.token+1)->type==T_OP)==0
- ) return Value_new_ERROR(value,UNDECLARED);
+ VALUE_NEW_INTEGER(value, pc.token->u.integer);
+ ++pc.token;
+ break;
}
- assert(pass==DECLARE || pc.token->u.identifier->sym);
- if (pass!=DECLARE && (pc.token->u.identifier->sym->type==GLOBALVAR || pc.token->u.identifier->sym->type==GLOBALARRAY || pc.token->u.identifier->sym->type==LOCALVAR))
+
+ case T_REAL:
{
- if ((l=lvalue(value))->type==V_ERROR) return value;
- Value_clone(value,l);
+ VALUE_NEW_REAL(value, pc.token->u.real);
+ ++pc.token;
+ break;
}
- else
+
+ case T_STRING:
{
- func(value);
- if (value->type==V_VOID)
- {
- Value_destroy(value);
- pc=var;
- return Value_new_ERROR(value,VOIDVALUE);
- }
+ Value_new_STRING(value);
+ String_destroy(&value->u.string);
+ String_clone(&value->u.string, pc.token->u.string);
+ ++pc.token;
+ break;
}
- break;
- }
- /*}}}*/
- case T_INTEGER: /*{{{*/
- {
- VALUE_NEW_INTEGER(value,pc.token->u.integer);
- ++pc.token;
- break;
- }
- /*}}}*/
- case T_REAL: /*{{{*/
- {
- VALUE_NEW_REAL(value,pc.token->u.real);
- ++pc.token;
- break;
- }
- /*}}}*/
- case T_STRING: /*{{{*/
- {
- Value_new_STRING(value);
- String_destroy(&value->u.string);
- String_clone(&value->u.string,pc.token->u.string);
- ++pc.token;
- break;
- }
- /*}}}*/
- case T_HEXINTEGER: /*{{{*/
- {
- VALUE_NEW_INTEGER(value,pc.token->u.hexinteger);
- ++pc.token;
- break;
- }
- /*}}}*/
- case T_OCTINTEGER: /*{{{*/
- {
- VALUE_NEW_INTEGER(value,pc.token->u.octinteger);
- ++pc.token;
- break;
- }
- /*}}}*/
- case T_OP: /*{{{*/
- {
- ++pc.token;
- if (eval(value,_("parenthetic"))->type==V_ERROR) return value;
- if (pc.token->type!=T_CP)
+
+ case T_HEXINTEGER:
{
- Value_destroy(value);
- return Value_new_ERROR(value,MISSINGCP);
+ VALUE_NEW_INTEGER(value, pc.token->u.hexinteger);
+ ++pc.token;
+ break;
}
- ++pc.token;
- break;
- }
- /*}}}*/
- default: /*{{{*/
- {
- return (struct Value *)0;
+
+ case T_OCTINTEGER:
+ {
+ VALUE_NEW_INTEGER(value, pc.token->u.octinteger);
+ ++pc.token;
+ break;
+ }
+
+ case T_OP:
+ {
+ ++pc.token;
+ if (eval(value, _("parenthetic"))->type == V_ERROR)
+ return value;
+ if (pc.token->type != T_CP)
+ {
+ Value_destroy(value);
+ return Value_new_ERROR(value, MISSINGCP);
+ }
+ ++pc.token;
+ break;
+ }
+
+ default:
+ {
+ return (struct Value *)0;
+ }
+
}
- /*}}}*/
- }
+
return value;
}
-/*}}}*/
-static struct Value *eval7(struct Value *value) /*{{{*/
+
+static struct Value *eval7(struct Value *value)
{
- return binarydown(value,eval8,7);
+ return binarydown(value, eval8, 7);
}
-/*}}}*/
-static struct Value *eval6(struct Value *value) /*{{{*/
+
+static struct Value *eval6(struct Value *value)
{
- return unarydown(value,eval7,6);
+ return unarydown(value, eval7, 6);
}
-/*}}}*/
-static struct Value *eval5(struct Value *value) /*{{{*/
+
+static struct Value *eval5(struct Value *value)
{
- return binarydown(value,eval6,5);
+ return binarydown(value, eval6, 5);
}
-/*}}}*/
-static struct Value *eval4(struct Value *value) /*{{{*/
+
+static struct Value *eval4(struct Value *value)
{
- return binarydown(value,eval5,4);
+ return binarydown(value, eval5, 4);
}
-/*}}}*/
-static struct Value *eval3(struct Value *value) /*{{{*/
+
+static struct Value *eval3(struct Value *value)
{
- return binarydown(value,eval4,3);
+ return binarydown(value, eval4, 3);
}
-/*}}}*/
-static struct Value *eval2(struct Value *value) /*{{{*/
+
+static struct Value *eval2(struct Value *value)
{
- return unarydown(value,eval3,2);
+ return unarydown(value, eval3, 2);
}
-/*}}}*/
-static struct Value *eval1(struct Value *value) /*{{{*/
+
+static struct Value *eval1(struct Value *value)
{
- return binarydown(value,eval2,1);
+ return binarydown(value, eval2, 1);
}
-/*}}}*/
-static struct Value *eval(struct Value *value, const char *desc) /*{{{*/
+
+static struct Value *eval(struct Value *value, const char *desc)
{
/* avoid function calls for atomic expression */
switch (pc.token->type)
- {
+ {
case T_STRING:
case T_REAL:
case T_INTEGER:
case T_HEXINTEGER:
case T_OCTINTEGER:
- case T_IDENTIFIER: if (!TOKEN_ISBINARYOPERATOR((pc.token+1)->type) && (pc.token+1)->type!=T_OP) return eval7(value);
- default: break;
- }
- if (binarydown(value,eval1,0)==(struct Value*)0)
- {
- if (desc) return Value_new_ERROR(value,MISSINGEXPR,desc);
- else return (struct Value*)0;
- }
- else return value;
+ case T_IDENTIFIER:
+ if (!TOKEN_ISBINARYOPERATOR((pc.token + 1)->type) &&
+ (pc.token + 1)->type != T_OP)
+ return eval7(value);
+ default:
+ break;
+ }
+ if (binarydown(value, eval1, 0) == (struct Value *)0)
+ {
+ if (desc)
+ return Value_new_ERROR(value, MISSINGEXPR, desc);
+ else
+ return (struct Value *)0;
+ }
+ else
+ return value;
}
-/*}}}*/
#endif
-static void new(void) /*{{{*/
+static void new(void)
{
Global_destroy(&globals);
Global_new(&globals);
@@ -1071,666 +1292,781 @@ static void new(void) /*{{{*/
Program_destroy(&program);
Program_new(&program);
FS_closefiles();
- optionbase=0;
+ optionbase = 0;
}
-/*}}}*/
-static void pushLabel(enum LabelType type, struct Pc *patch) /*{{{*/
+
+static void pushLabel(enum LabelType type, struct Pc *patch)
{
- if (labelStackPointer==labelStackCapacity)
- {
- struct LabelStack *more;
+ if (labelStackPointer == labelStackCapacity)
+ {
+ struct LabelStack *more;
+
+ more =
+ realloc(labelStack,
+ sizeof(struct LabelStack) *
+ (labelStackCapacity ? (labelStackCapacity *= 2) : (32)));
+ labelStack = more;
+ }
- more=realloc(labelStack,sizeof(struct LabelStack)*(labelStackCapacity?(labelStackCapacity*=2):(32)));
- labelStack=more;
- }
- labelStack[labelStackPointer].type=type;
- labelStack[labelStackPointer].patch=*patch;
+ labelStack[labelStackPointer].type = type;
+ labelStack[labelStackPointer].patch = *patch;
++labelStackPointer;
}
-/*}}}*/
-static struct Pc *popLabel(enum LabelType type) /*{{{*/
+
+static struct Pc *popLabel(enum LabelType type)
{
- if (labelStackPointer==0 || labelStack[labelStackPointer-1].type!=type) return (struct Pc*)0;
- else return &labelStack[--labelStackPointer].patch;
+ if (labelStackPointer == 0 || labelStack[labelStackPointer - 1].type != type)
+ return (struct Pc *)0;
+ else
+ return &labelStack[--labelStackPointer].patch;
}
-/*}}}*/
-static struct Pc *findLabel(enum LabelType type) /*{{{*/
+
+static struct Pc *findLabel(enum LabelType type)
{
int i;
- for (i=labelStackPointer-1; i>=0; --i) if (labelStack[i].type==type) return &labelStack[i].patch;
- return (struct Pc*)0;
+ for (i = labelStackPointer - 1; i >= 0; --i)
+ if (labelStack[i].type == type)
+ return &labelStack[i].patch;
+ return (struct Pc *)0;
}
-/*}}}*/
-static void labelStackError(struct Value *v) /*{{{*/
+
+static void labelStackError(struct Value *v)
{
assert(labelStackPointer);
- pc=labelStack[labelStackPointer-1].patch;
- switch (labelStack[labelStackPointer-1].type)
- {
- case L_IF: Value_new_ERROR(v,STRAYIF); break;
- case L_DO: Value_new_ERROR(v,STRAYDO); break;
- case L_DOcondition: Value_new_ERROR(v,STRAYDOcondition); break;
- case L_ELSE: Value_new_ERROR(v,STRAYELSE2); break;
- case L_FOR_BODY:
+ pc = labelStack[labelStackPointer - 1].patch;
+ switch (labelStack[labelStackPointer - 1].type)
{
- Value_new_ERROR(v,STRAYFOR);
- pc=*findLabel(L_FOR);
+ case L_IF:
+ Value_new_ERROR(v, STRAYIF);
+ break;
+ case L_DO:
+ Value_new_ERROR(v, STRAYDO);
+ break;
+ case L_DOcondition:
+ Value_new_ERROR(v, STRAYDOcondition);
+ break;
+ case L_ELSE:
+ Value_new_ERROR(v, STRAYELSE2);
+ break;
+ case L_FOR_BODY:
+ {
+ Value_new_ERROR(v, STRAYFOR);
+ pc = *findLabel(L_FOR);
+ break;
+ }
+ case L_WHILE:
+ Value_new_ERROR(v, STRAYWHILE);
break;
+ case L_REPEAT:
+ Value_new_ERROR(v, STRAYREPEAT);
+ break;
+ case L_SELECTCASE:
+ Value_new_ERROR(v, STRAYSELECTCASE);
+ break;
+ case L_FUNC:
+ Value_new_ERROR(v, STRAYFUNC);
+ break;
+ default:
+ assert(0);
}
- case L_WHILE: Value_new_ERROR(v,STRAYWHILE); break;
- case L_REPEAT: Value_new_ERROR(v,STRAYREPEAT); break;
- case L_SELECTCASE: Value_new_ERROR(v,STRAYSELECTCASE); break;
- case L_FUNC: Value_new_ERROR(v,STRAYFUNC); break;
- default: assert(0);
- }
}
-/*}}}*/
-static const char *topLabelDescription(void) /*{{{*/
+
+static const char *topLabelDescription(void)
{
- if (labelStackPointer==0)
- {
- return _("program");
- }
- switch (labelStack[labelStackPointer-1].type)
- {
- case L_IF: return _("`if' branch");
- case L_DO: return _("`do' loop");
- case L_DOcondition: return _("`do while' or `do until' loop");
- case L_ELSE: return _("`else' branch");
- case L_FOR_BODY: return _("`for' loop");
- case L_WHILE: return _("`while' loop");
- case L_REPEAT: return _("`repeat' loop");
- case L_SELECTCASE: return _("`select case' control structure");
- case L_FUNC: return _("function or procedure");
- default: assert(0);
- }
+ if (labelStackPointer == 0)
+ {
+ return _("program");
+ }
+ switch (labelStack[labelStackPointer - 1].type)
+ {
+ case L_IF:
+ return _("`if' branch");
+ case L_DO:
+ return _("`do' loop");
+ case L_DOcondition:
+ return _("`do while' or `do until' loop");
+ case L_ELSE:
+ return _("`else' branch");
+ case L_FOR_BODY:
+ return _("`for' loop");
+ case L_WHILE:
+ return _("`while' loop");
+ case L_REPEAT:
+ return _("`repeat' loop");
+ case L_SELECTCASE:
+ return _("`select case' control structure");
+ case L_FUNC:
+ return _("function or procedure");
+ default:
+ assert(0);
+ }
/* NOTREACHED */
- return (const char*)0;
+ return (const char *)0;
}
-/*}}}*/
-static struct Value *assign(struct Value *value) /*{{{*/
+
+static struct Value *assign(struct Value *value)
{
struct Pc expr;
- if (strcasecmp(pc.token->u.identifier->name,"mid$")==0) /* mid$(a$,n,m)=b$ */ /*{{{*/
- {
- long int n,m;
- struct Value *l;
-
- ++pc.token;
- if (pc.token->type!=T_OP) return Value_new_ERROR(value,MISSINGOP);
- ++pc.token;
- if (pc.token->type!=T_IDENTIFIER) return Value_new_ERROR(value,MISSINGSTRIDENT);
- if (pass==DECLARE)
- {
- if
- (
- ((pc.token+1)->type==T_OP || Auto_find(&stack,pc.token->u.identifier)==0)
- && Global_variable(&globals,pc.token->u.identifier,pc.token->u.identifier->defaultType,(pc.token+1)->type==T_OP?GLOBALARRAY:GLOBALVAR,0)==0
- )
- {
- return Value_new_ERROR(value,REDECLARATION);
- }
- }
- if ((l=lvalue(value))->type==V_ERROR) return value;
- if (pass==COMPILE && l->type!=V_STRING) return Value_new_ERROR(value,TYPEMISMATCH4);
- if (pc.token->type!=T_COMMA) return Value_new_ERROR(value,MISSINGCOMMA);
- ++pc.token;
- if (eval(value,_("position"))->type==V_ERROR || Value_retype(value,V_INTEGER)->type==V_ERROR) return value;
- n=value->u.integer;
- Value_destroy(value);
- if (pass==INTERPRET && n<1) return Value_new_ERROR(value,OUTOFRANGE,"position");
- if (pc.token->type==T_COMMA)
+ if (strcasecmp(pc.token->u.identifier->name, "mid$") == 0) /* mid$(a$,n,m)=b$
+ */
{
+ long int n, m;
+ struct Value *l;
+
++pc.token;
- if (eval(value,_("length"))->type==V_ERROR || Value_retype(value,V_INTEGER)->type==V_ERROR) return value;
- m=value->u.integer;
- if (pass==INTERPRET && m<0) return Value_new_ERROR(value,OUTOFRANGE,_("length"));
+ if (pc.token->type != T_OP)
+ return Value_new_ERROR(value, MISSINGOP);
+ ++pc.token;
+ if (pc.token->type != T_IDENTIFIER)
+ return Value_new_ERROR(value, MISSINGSTRIDENT);
+ if (pass == DECLARE)
+ {
+ if (((pc.token + 1)->type == T_OP ||
+ Auto_find(&stack, pc.token->u.identifier) == 0) &&
+ Global_variable(&globals, pc.token->u.identifier,
+ pc.token->u.identifier->defaultType,
+ (pc.token + 1)->type ==
+ T_OP ? GLOBALARRAY : GLOBALVAR, 0) == 0)
+ {
+ return Value_new_ERROR(value, REDECLARATION);
+ }
+ }
+ if ((l = lvalue(value))->type == V_ERROR)
+ return value;
+ if (pass == COMPILE && l->type != V_STRING)
+ return Value_new_ERROR(value, TYPEMISMATCH4);
+ if (pc.token->type != T_COMMA)
+ return Value_new_ERROR(value, MISSINGCOMMA);
+ ++pc.token;
+ if (eval(value, _("position"))->type == V_ERROR ||
+ Value_retype(value, V_INTEGER)->type == V_ERROR)
+ return value;
+ n = value->u.integer;
Value_destroy(value);
+ if (pass == INTERPRET && n < 1)
+ return Value_new_ERROR(value, OUTOFRANGE, "position");
+ if (pc.token->type == T_COMMA)
+ {
+ ++pc.token;
+ if (eval(value, _("length"))->type == V_ERROR ||
+ Value_retype(value, V_INTEGER)->type == V_ERROR)
+ return value;
+ m = value->u.integer;
+ if (pass == INTERPRET && m < 0)
+ return Value_new_ERROR(value, OUTOFRANGE, _("length"));
+ Value_destroy(value);
+ }
+ else
+ m = -1;
+ if (pc.token->type != T_CP)
+ return Value_new_ERROR(value, MISSINGCP);
+ ++pc.token;
+ if (pc.token->type != T_EQ)
+ return Value_new_ERROR(value, MISSINGEQ);
+ ++pc.token;
+ if (eval(value, _("rhs"))->type == V_ERROR ||
+ Value_retype(value, V_STRING)->type == V_ERROR)
+ return value;
+ if (pass == INTERPRET)
+ {
+ if (m == -1)
+ m = value->u.string.length;
+ String_set(&l->u.string, n - 1, &value->u.string, m);
+ }
}
- else m=-1;
- if (pc.token->type!=T_CP) return Value_new_ERROR(value,MISSINGCP);
- ++pc.token;
- if (pc.token->type!=T_EQ) return Value_new_ERROR(value,MISSINGEQ);
- ++pc.token;
- if (eval(value,_("rhs"))->type==V_ERROR || Value_retype(value,V_STRING)->type==V_ERROR) return value;
- if (pass==INTERPRET)
- {
- if (m==-1) m=value->u.string.length;
- String_set(&l->u.string,n-1,&value->u.string,m);
- }
- }
- /*}}}*/
- else /*{{{*/
- {
- struct Value **l=(struct Value**)0;
- int i, used=0, capacity=0;
- struct Value retyped_value;
-
- for (;;)
+ else
{
- if (used==capacity)
- {
- struct Value **more;
-
- capacity=capacity?2*capacity:2;
- more=realloc(l,capacity*sizeof(*l));
- l=more;
- }
+ struct Value **l = (struct Value **)0;
+ int i, used = 0, capacity = 0;
+ struct Value retyped_value;
- if (pass==DECLARE)
- {
- if
- (
- ((pc.token+1)->type==T_OP || Auto_find(&stack,pc.token->u.identifier)==0)
- && Global_variable(&globals,pc.token->u.identifier,pc.token->u.identifier->defaultType,(pc.token+1)->type==T_OP?GLOBALARRAY:GLOBALVAR,0)==0
- )
+ for (;;)
{
- if (capacity) free(l);
- return Value_new_ERROR(value,REDECLARATION);
+ if (used == capacity)
+ {
+ struct Value **more;
+
+ capacity = capacity ? 2 * capacity : 2;
+ more = realloc(l, capacity * sizeof(*l));
+ l = more;
+ }
+
+ if (pass == DECLARE)
+ {
+ if (((pc.token + 1)->type == T_OP ||
+ Auto_find(&stack, pc.token->u.identifier) == 0) &&
+ Global_variable(&globals, pc.token->u.identifier,
+ pc.token->u.identifier->defaultType,
+ (pc.token + 1)->type ==
+ T_OP ? GLOBALARRAY : GLOBALVAR, 0) == 0)
+ {
+ if (capacity)
+ free(l);
+ return Value_new_ERROR(value, REDECLARATION);
+ }
+ }
+ if ((l[used] = lvalue(value))->type == V_ERROR)
+ return value;
+ ++used;
+ if (pc.token->type == T_COMMA)
+ ++pc.token;
+ else
+ break;
}
- }
- if ((l[used]=lvalue(value))->type==V_ERROR) return value;
- ++used;
- if (pc.token->type==T_COMMA) ++pc.token;
- else break;
- }
- if (pc.token->type!=T_EQ) return Value_new_ERROR(value,MISSINGEQ);
- ++pc.token;
- expr=pc;
- if (eval(value,_("rhs"))->type==V_ERROR) return value;
- for (i=0; i<used; ++i)
- {
- Value_clone(&retyped_value,value);
- if (pass!=DECLARE && VALUE_RETYPE(&retyped_value,(l[i])->type)->type==V_ERROR)
- {
- pc=expr;
- free(l);
- Value_destroy(value);
- *value=retyped_value;
+
+ if (pc.token->type != T_EQ)
+ return Value_new_ERROR(value, MISSINGEQ);
+ ++pc.token;
+ expr = pc;
+ if (eval(value, _("rhs"))->type == V_ERROR)
return value;
- }
- if (pass==INTERPRET)
- {
- Value_destroy(l[i]);
- *(l[i])=retyped_value;
- }
+
+ for (i = 0; i < used; ++i)
+ {
+ Value_clone(&retyped_value, value);
+ if (pass != DECLARE &&
+ VALUE_RETYPE(&retyped_value, (l[i])->type)->type == V_ERROR)
+ {
+ pc = expr;
+ free(l);
+ Value_destroy(value);
+ *value = retyped_value;
+ return value;
+ }
+ if (pass == INTERPRET)
+ {
+ Value_destroy(l[i]);
+ *(l[i]) = retyped_value;
+ }
+ }
+
+ free(l);
+ Value_destroy(value);
+ *value = retyped_value; /* for status only */
}
- free(l);
- Value_destroy(value);
- *value=retyped_value; /* for status only */
- }
- /*}}}*/
+
return value;
}
-/*}}}*/
-static struct Value *compileProgram(struct Value *v, int clearGlobals) /*{{{*/
+
+
+static struct Value *compileProgram(struct Value *v, int clearGlobals)
{
struct Pc begin;
- stack.resumeable=0;
+ stack.resumeable = 0;
if (clearGlobals)
- {
- Global_destroy(&globals);
- Global_new(&globals);
- }
- else Global_clearFunctions(&globals);
- if (Program_beginning(&program,&begin))
- {
- struct Pc savepc;
- int savepass;
-
- savepc=pc;
- savepass=pass;
- Program_norun(&program);
- for (pass=DECLARE; pass!=INTERPRET; ++pass)
{
- if (pass==DECLARE)
- {
- stack.begindata.line=-1;
- lastdata=&stack.begindata;
- }
- optionbase=0;
- FS_intr=0;
- stopped=0;
- program.runnable=1;
- pc=begin;
- while (1)
- {
- statements(v);
- if (v->type==V_ERROR) break;
- Value_destroy(v);
- if (!Program_skipEOL(&program,&pc,0,0)) { Value_new_NIL(v); break; }
- }
- if (v->type!=V_ERROR && labelStackPointer>0)
- {
- Value_destroy(v);
- labelStackError(v);
- }
- if (v->type==V_ERROR)
- {
- labelStackPointer=0;
- Program_norun(&program);
- if (stack.cur) Auto_funcEnd(&stack); /* Always correct? */
- pass=savepass;
- return v;
- }
+ Global_destroy(&globals);
+ Global_new(&globals);
}
- pc=begin;
- if (Program_analyse(&program,&pc,v))
+ else
+ Global_clearFunctions(&globals);
+
+ if (Program_beginning(&program, &begin))
{
- labelStackPointer=0;
+ struct Pc savepc;
+ int savepass;
+
+ savepc = pc;
+ savepass = pass;
Program_norun(&program);
- if (stack.cur) Auto_funcEnd(&stack); /* Always correct? */
- pass=savepass;
- return v;
+ for (pass = DECLARE; pass != INTERPRET; ++pass)
+ {
+ if (pass == DECLARE)
+ {
+ stack.begindata.line = -1;
+ lastdata = &stack.begindata;
+ }
+ optionbase = 0;
+ FS_intr = 0;
+ stopped = 0;
+ program.runnable = 1;
+ pc = begin;
+ while (1)
+ {
+ statements(v);
+ if (v->type == V_ERROR)
+ break;
+ Value_destroy(v);
+ if (!Program_skipEOL(&program, &pc, 0, 0))
+ {
+ Value_new_NIL(v);
+ break;
+ }
+ }
+ if (v->type != V_ERROR && labelStackPointer > 0)
+ {
+ Value_destroy(v);
+ labelStackError(v);
+ }
+ if (v->type == V_ERROR)
+ {
+ labelStackPointer = 0;
+ Program_norun(&program);
+ if (stack.cur)
+ Auto_funcEnd(&stack); /* Always correct? */
+ pass = savepass;
+ return v;
+ }
+ }
+ pc = begin;
+ if (Program_analyse(&program, &pc, v))
+ {
+ labelStackPointer = 0;
+ Program_norun(&program);
+ if (stack.cur)
+ Auto_funcEnd(&stack); /* Always correct? */
+ pass = savepass;
+ return v;
+ }
+
+ curdata = stack.begindata;
+ pc = savepc;
+ pass = savepass;
}
- curdata=stack.begindata;
- pc=savepc;
- pass=savepass;
- }
+
return Value_new_NIL(v);
}
-/*}}}*/
-static void runline(struct Token *line) /*{{{*/
+
+static void runline(struct Token *line)
{
struct Value value;
FS_flush(STDCHANNEL);
- for (pass=DECLARE; pass!=INTERPRET; ++pass)
- {
- curdata.line=-1;
- pc.line=-1;
- pc.token=line;
- optionbase=0;
- FS_intr=0;
- stopped=0;
- statements(&value);
- if (value.type!=V_ERROR && pc.token->type!=T_EOL)
- {
- Value_destroy(&value);
- Value_new_ERROR(&value,SYNTAX);
- }
- if (value.type!=V_ERROR && labelStackPointer>0)
+ for (pass = DECLARE; pass != INTERPRET; ++pass)
{
- Value_destroy(&value);
- labelStackError(&value);
- }
- if (value.type==V_ERROR)
- {
- struct String s;
-
- Auto_setError(&stack,Program_lineNumber(&program,&pc),&pc,&value);
- Program_PCtoError(&program,&pc,&value);
- labelStackPointer=0;
- FS_putChars(STDCHANNEL,_("Error: "));
- String_new(&s);
- Value_toString(&value,&s,' ',-1,0,0,0,0,-1,0,0);
- Value_destroy(&value);
- FS_putString(STDCHANNEL,&s);
- String_destroy(&s);
- return;
- }
- if (!program.runnable && pass==COMPILE)
- {
- Value_destroy(&value);
- (void)compileProgram(&value,0);
+ curdata.line = -1;
+ pc.line = -1;
+ pc.token = line;
+ optionbase = 0;
+ FS_intr = 0;
+ stopped = 0;
+ statements(&value);
+ if (value.type != V_ERROR && pc.token->type != T_EOL)
+ {
+ Value_destroy(&value);
+ Value_new_ERROR(&value, SYNTAX);
+ }
+ if (value.type != V_ERROR && labelStackPointer > 0)
+ {
+ Value_destroy(&value);
+ labelStackError(&value);
+ }
+ if (value.type == V_ERROR)
+ {
+ struct String s;
+
+ Auto_setError(&stack, Program_lineNumber(&program, &pc), &pc, &value);
+ Program_PCtoError(&program, &pc, &value);
+ labelStackPointer = 0;
+ FS_putChars(STDCHANNEL, _("Error: "));
+ String_new(&s);
+ Value_toString(&value, &s, ' ', -1, 0, 0, 0, 0, -1, 0, 0);
+ Value_destroy(&value);
+ FS_putString(STDCHANNEL, &s);
+ String_destroy(&s);
+ return;
+ }
+ if (!program.runnable && pass == COMPILE)
+ {
+ Value_destroy(&value);
+ (void)compileProgram(&value, 0);
+ }
}
- }
- pc.line=-1;
- pc.token=line;
- optionbase=0;
- curdata=stack.begindata;
- nextdata.line=-1;
+ pc.line = -1;
+ pc.token = line;
+ optionbase = 0;
+ curdata = stack.begindata;
+ nextdata.line = -1;
Value_destroy(&value);
- pass=INTERPRET;
+ pass = INTERPRET;
FS_allowIntr(1);
do
- {
- assert(pass==INTERPRET);
- statements(&value);
- assert(pass==INTERPRET);
- if (value.type==V_ERROR)
{
- if (strchr(value.u.error.msg,'\n')==(char*)0)
- {
- Auto_setError(&stack,Program_lineNumber(&program,&pc),&pc,&value);
- Program_PCtoError(&program,&pc,&value);
- }
- if (stack.onerror.line!=-1)
- {
- stack.resumeable=1;
- pc=stack.onerror;
- }
- else
- {
- struct String s;
-
- String_new(&s);
- if (!stopped)
+ assert(pass == INTERPRET);
+ statements(&value);
+ assert(pass == INTERPRET);
+ if (value.type == V_ERROR)
{
- stopped=0;
- FS_putChars(STDCHANNEL,_("Error: "));
+ if (strchr(value.u.error.msg, '\n') == (char *)0)
+ {
+ Auto_setError(&stack, Program_lineNumber(&program, &pc), &pc,
+ &value);
+ Program_PCtoError(&program, &pc, &value);
+ }
+ if (stack.onerror.line != -1)
+ {
+ stack.resumeable = 1;
+ pc = stack.onerror;
+ }
+ else
+ {
+ struct String s;
+
+ String_new(&s);
+ if (!stopped)
+ {
+ stopped = 0;
+ FS_putChars(STDCHANNEL, _("Error: "));
+ }
+ Auto_frameToError(&stack, &program, &value);
+ Value_toString(&value, &s, ' ', -1, 0, 0, 0, 0, -1, 0, 0);
+ while (Auto_gosubReturn(&stack, (struct Pc *)0));
+ FS_putString(STDCHANNEL, &s);
+ String_destroy(&s);
+ Value_destroy(&value);
+ break;
+ }
}
- Auto_frameToError(&stack,&program,&value);
- Value_toString(&value,&s,' ',-1,0,0,0,0,-1,0,0);
- while (Auto_gosubReturn(&stack,(struct Pc*)0));
- FS_putString(STDCHANNEL,&s);
- String_destroy(&s);
- Value_destroy(&value);
- break;
- }
+ Value_destroy(&value);
}
- Value_destroy(&value);
- } while (pc.token->type!=T_EOL || Program_skipEOL(&program,&pc,STDCHANNEL,1));
+ while (pc.token->type != T_EOL ||
+ Program_skipEOL(&program, &pc, STDCHANNEL, 1));
FS_allowIntr(0);
}
-/*}}}*/
-static struct Value *evalGeometry(struct Value *value, unsigned int *dim, unsigned int geometry[]) /*{{{*/
+
+static struct Value *evalGeometry(struct Value *value, unsigned int *dim, unsigned int geometry[])
{
- struct Pc exprpc=pc;
+ struct Pc exprpc = pc;
- if (eval(value,_("dimension"))->type==V_ERROR || (pass!=DECLARE && Value_retype(value,V_INTEGER)->type==V_ERROR)) return value;
- if (pass==INTERPRET && value->u.integer<optionbase)
- {
- Value_destroy(value);
- pc=exprpc;
- return Value_new_ERROR(value,OUTOFRANGE,_("dimension"));
- }
- geometry[0]=value->u.integer-optionbase+1;
+ if (eval(value, _("dimension"))->type == V_ERROR ||
+ (pass != DECLARE && Value_retype(value, V_INTEGER)->type == V_ERROR))
+ return value;
+ if (pass == INTERPRET && value->u.integer < optionbase)
+ {
+ Value_destroy(value);
+ pc = exprpc;
+ return Value_new_ERROR(value, OUTOFRANGE, _("dimension"));
+ }
+ geometry[0] = value->u.integer - optionbase + 1;
Value_destroy(value);
- if (pc.token->type==T_COMMA)
- {
- ++pc.token;
- exprpc=pc;
- if (eval(value,_("dimension"))->type==V_ERROR || (pass!=DECLARE && Value_retype(value,V_INTEGER)->type==V_ERROR)) return value;
- if (pass==INTERPRET && value->u.integer<optionbase)
+ if (pc.token->type == T_COMMA)
{
+ ++pc.token;
+ exprpc = pc;
+ if (eval(value, _("dimension"))->type == V_ERROR ||
+ (pass != DECLARE && Value_retype(value, V_INTEGER)->type == V_ERROR))
+ return value;
+ if (pass == INTERPRET && value->u.integer < optionbase)
+ {
+ Value_destroy(value);
+ pc = exprpc;
+ return Value_new_ERROR(value, OUTOFRANGE, _("dimension"));
+ }
+ geometry[1] = value->u.integer - optionbase + 1;
Value_destroy(value);
- pc=exprpc;
- return Value_new_ERROR(value,OUTOFRANGE,_("dimension"));
+ *dim = 2;
}
- geometry[1]=value->u.integer-optionbase+1;
- Value_destroy(value);
- *dim=2;
- }
- else *dim=1;
- if (pc.token->type==T_CP) ++pc.token;
- else return Value_new_ERROR(value,MISSINGCP);
- return (struct Value*)0;
+ else
+ *dim = 1;
+ if (pc.token->type == T_CP)
+ ++pc.token;
+ else
+ return Value_new_ERROR(value, MISSINGCP);
+ return (struct Value *)0;
}
-/*}}}*/
-static struct Value *convert(struct Value *value, struct Value *l, struct Token *t) /*{{{*/
+
+static struct Value *convert(struct Value *value, struct Value *l, struct Token *t)
{
switch (l->type)
- {
+ {
case V_INTEGER:
+ {
+ char *datainput;
+ char *end;
+ long int v;
+ int overflow;
+
+ if (t->type != T_DATAINPUT)
+ return Value_new_ERROR(value, BADCONVERSION, _("integer"));
+ datainput = t->u.datainput;
+ v = Value_vali(datainput, &end, &overflow);
+ if (end == datainput || (*end != '\0' && *end != ' ' && *end != '\t'))
+ return Value_new_ERROR(value, BADCONVERSION, _("integer"));
+ if (overflow)
+ return Value_new_ERROR(value, OUTOFRANGE, _("converted value"));
+ Value_destroy(l);
+ VALUE_NEW_INTEGER(l, v);
+ break;
+ }
+ case V_REAL:
+ {
+ char *datainput;
+ char *end;
+ double v;
+ int overflow;
+
+ if (t->type != T_DATAINPUT)
+ return Value_new_ERROR(value, BADCONVERSION, _("real"));
+ datainput = t->u.datainput;
+ v = Value_vald(datainput, &end, &overflow);
+ if (end == datainput || (*end != '\0' && *end != ' ' && *end != '\t'))
+ return Value_new_ERROR(value, BADCONVERSION, _("real"));
+ if (overflow)
+ return Value_new_ERROR(value, OUTOFRANGE, _("converted value"));
+ Value_destroy(l);
+ VALUE_NEW_REAL(l, v);
+ break;
+ }
+ case V_STRING:
+ {
+ Value_destroy(l);
+ Value_new_STRING(l);
+ if (t->type == T_STRING)
+ String_appendString(&l->u.string, t->u.string);
+ else
+ String_appendChars(&l->u.string, t->u.datainput);
+ break;
+ }
+ default:
+ assert(0);
+ }
+ return (struct Value *)0;
+}
+
+static struct Value *dataread(struct Value *value, struct Value *l)
+{
+ if (curdata.line == -1)
{
- char *datainput;
- char *end;
- long int v;
- int overflow;
-
- if (t->type!=T_DATAINPUT) return Value_new_ERROR(value,BADCONVERSION,_("integer"));
- datainput=t->u.datainput;
- v=Value_vali(datainput,&end,&overflow);
- if (end==datainput || (*end!='\0' && *end!=' ' && *end!='\t')) return Value_new_ERROR(value,BADCONVERSION,_("integer"));
- if (overflow) return Value_new_ERROR(value,OUTOFRANGE,_("converted value"));
- Value_destroy(l);
- VALUE_NEW_INTEGER(l,v);
- break;
+ return Value_new_ERROR(value, ENDOFDATA);
}
- case V_REAL:
+ if (curdata.token->type == T_DATA)
{
- char *datainput;
- char *end;
- double v;
- int overflow;
-
- if (t->type!=T_DATAINPUT) return Value_new_ERROR(value,BADCONVERSION,_("real"));
- datainput=t->u.datainput;
- v=Value_vald(datainput,&end,&overflow);
- if (end==datainput || (*end!='\0' && *end!=' ' && *end!='\t')) return Value_new_ERROR(value,BADCONVERSION,_("real"));
- if (overflow) return Value_new_ERROR(value,OUTOFRANGE,_("converted value"));
- Value_destroy(l);
- VALUE_NEW_REAL(l,v);
- break;
+ nextdata = curdata.token->u.nextdata;
+ ++curdata.token;
}
- case V_STRING:
+ if (convert(value, l, curdata.token))
{
- Value_destroy(l);
- Value_new_STRING(l);
- if (t->type==T_STRING) String_appendString(&l->u.string,t->u.string);
- else String_appendChars(&l->u.string,t->u.datainput);
- break;
+ return value;
}
- default: assert(0);
- }
- return (struct Value*)0;
-}
-/*}}}*/
-static struct Value *dataread(struct Value *value, struct Value *l) /*{{{*/
-{
- if (curdata.line==-1)
- {
- return Value_new_ERROR(value,ENDOFDATA);
- }
- if (curdata.token->type==T_DATA)
- {
- nextdata=curdata.token->u.nextdata;
- ++curdata.token;
- }
- if (convert(value,l,curdata.token))
- {
- return value;
- }
++curdata.token;
- if (curdata.token->type==T_COMMA) ++curdata.token;
- else curdata=nextdata;
- return (struct Value*)0;
+ if (curdata.token->type == T_COMMA)
+ ++curdata.token;
+ else
+ curdata = nextdata;
+ return (struct Value *)0;
}
-/*}}}*/
+
static struct Value more_statements;
#include "statement.c"
-static struct Value *statements(struct Value *value) /*{{{*/
+static struct Value *statements(struct Value *value)
{
- more:
+more:
if (pc.token->statement)
- {
- struct Value *v;
-
- if ((v=pc.token->statement(value)))
{
- if (v==&more_statements) goto more;
- else return value;
+ struct Value *v;
+
+ if ((v = pc.token->statement(value)))
+ {
+ if (v == &more_statements)
+ goto more;
+ else
+ return value;
+ }
}
- }
- else return Value_new_ERROR(value,MISSINGSTATEMENT);
+ else
+ return Value_new_ERROR(value, MISSINGSTATEMENT);
if (FS_intr)
- {
- stopped=1;
- return Value_new_ERROR(value,BREAK);
- }
- else if (pc.token->type==T_COLON && (pc.token+1)->type==T_ELSE) ++pc.token;
- else if ((pc.token->type==T_COLON && (pc.token+1)->type!=T_ELSE) || pc.token->type==T_QUOTE)
- {
+ {
+ stopped = 1;
+ return Value_new_ERROR(value, BREAK);
+ }
+ else if (pc.token->type == T_COLON && (pc.token + 1)->type == T_ELSE)
++pc.token;
- goto more;
- }
- else if ((pass==DECLARE || pass==COMPILE) && pc.token->type!=T_EOL && pc.token->type!=T_ELSE)
- {
- return Value_new_ERROR(value,MISSINGCOLON);
- }
+ else if ((pc.token->type == T_COLON && (pc.token + 1)->type != T_ELSE) ||
+ pc.token->type == T_QUOTE)
+ {
+ ++pc.token;
+ goto more;
+ }
+ else if ((pass == DECLARE || pass == COMPILE) && pc.token->type != T_EOL &&
+ pc.token->type != T_ELSE)
+ {
+ return Value_new_ERROR(value, MISSINGCOLON);
+ }
return Value_new_NIL(value);
}
-/*}}}*/
-void bas_init(int backslash_colon, int restricted, int uppercase, int lpfd) /*{{{*/
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+void bas_init(int backslash_colon, int restricted, int uppercase, int lpfd)
{
#ifdef HAVE_GETTEXT
- bindtextdomain("bas",LOCALEDIR);
+ bindtextdomain("bas", LOCALEDIR);
textdomain("bas");
#endif
- stack.begindata.line=-1;
- Token_init(backslash_colon,uppercase);
+ stack.begindata.line = -1;
+ Token_init(backslash_colon, uppercase);
Global_new(&globals);
Auto_new(&stack);
Program_new(&program);
- FS_opendev(STDCHANNEL,0,1);
- FS_opendev(LPCHANNEL,-1,lpfd);
- run_restricted=restricted;
+ FS_opendev(STDCHANNEL, 0, 1);
+ FS_opendev(LPCHANNEL, -1, lpfd);
+ run_restricted = restricted;
}
-/*}}}*/
-void bas_runFile(const char *runFile) /*{{{*/
+
+void bas_runFile(const char *runFile)
{
struct Value value;
int dev;
new();
- if ((dev=FS_openin(runFile))==-1)
- {
- const char *errmsg=FS_errmsg;
-
- FS_putChars(0,_("bas: Executing `"));
- FS_putChars(0,runFile);
- FS_putChars(0,_("' failed ("));
- FS_putChars(0,errmsg);
- FS_putChars(0,_(").\n"));
- }
- else if (Program_merge(&program,dev,&value))
- {
- struct String s;
-
- FS_putChars(0,"bas: ");
- String_new(&s);
- Value_toString(&value,&s,' ',-1,0,0,0,0,-1,0,0);
- FS_putString(0,&s);
- String_destroy(&s);
- FS_putChar(0,'\n');
- Value_destroy(&value);
- }
+ if ((dev = FS_openin(runFile)) == -1)
+ {
+ const char *errmsg = FS_errmsg;
+
+ FS_putChars(0, _("bas: Executing `"));
+ FS_putChars(0, runFile);
+ FS_putChars(0, _("' failed ("));
+ FS_putChars(0, errmsg);
+ FS_putChars(0, _(").\n"));
+ }
+ else if (Program_merge(&program, dev, &value))
+ {
+ struct String s;
+
+ FS_putChars(0, "bas: ");
+ String_new(&s);
+ Value_toString(&value, &s, ' ', -1, 0, 0, 0, 0, -1, 0, 0);
+ FS_putString(0, &s);
+ String_destroy(&s);
+ FS_putChar(0, '\n');
+ Value_destroy(&value);
+ }
else
- {
- struct Token line[2];
+ {
+ struct Token line[2];
- Program_setname(&program,runFile);
- line[0].type=T_RUN;
- line[0].statement=stmt_RUN;
- line[1].type=T_EOL;
- line[1].statement=stmt_COLON_EOL;
+ Program_setname(&program, runFile);
+ line[0].type = T_RUN;
+ line[0].statement = stmt_RUN;
+ line[1].type = T_EOL;
+ line[1].statement = stmt_COLON_EOL;
- FS_close(dev);
- runline(line);
- }
+ FS_close(dev);
+ runline(line);
+ }
}
-/*}}}*/
-void bas_runLine(const char *runLine) /*{{{*/
+
+void bas_runLine(const char *runLine)
{
struct Token *line;
- line=Token_newCode(runLine);
- runline(line+1);
+ line = Token_newCode(runLine);
+ runline(line + 1);
Token_destroy(line);
}
-/*}}}*/
-void bas_interpreter(void) /*{{{*/
+
+void bas_interpreter(void)
{
if (FS_istty(STDCHANNEL))
- {
- //FS_putChars(STDCHANNEL,"bas " VERSION "\n"); //acassis: fix it
- FS_putChars(STDCHANNEL,"Copyright 1999-2014 Michael Haardt.\n");
- FS_putChars(STDCHANNEL,_("This is free software with ABSOLUTELY NO WARRANTY.\n"));
- }
- new();
- while (1)
- {
- struct Token *line;
- struct String s;
-
- FS_intr=0; stopped=0;
- FS_allowIntr(1);
- FS_nextline(STDCHANNEL);
- if (FS_istty(STDCHANNEL)) FS_putChars(STDCHANNEL,"> ");
- FS_flush(STDCHANNEL);
- String_new(&s);
- if (FS_appendToString(STDCHANNEL,&s,1)==-1)
{
- if (FS_intr)
- {
- FS_putChars(STDCHANNEL,_("\nBreak\n"));
- FS_flush(STDCHANNEL);
- String_destroy(&s);
- continue;
- }
- else
- {
- FS_putChars(STDCHANNEL,FS_errmsg);
- FS_flush(STDCHANNEL);
- String_destroy(&s);
- break;
- }
+ // FS_putChars(STDCHANNEL,"bas " VERSION "\n"); //acassis: fix it
+ FS_putChars(STDCHANNEL, "Copyright 1999-2014 Michael Haardt.\n");
+ FS_putChars(STDCHANNEL,
+ _("This is free software with ABSOLUTELY NO WARRANTY.\n"));
}
- if (s.length==0)
- {
- String_destroy(&s);
- break;
- }
- line=Token_newCode(s.character);
- String_destroy(&s);
- if (line->type!=T_EOL)
+ new();
+ while (1)
{
- if (line->type==T_INTEGER && line->u.integer>0)
- {
- if (program.numbered)
- {
- if ((line+1)->type==T_EOL)
- {
- struct Pc where;
+ struct Token *line;
+ struct String s;
- if (Program_goLine(&program,line->u.integer,&where)==(struct Pc*)0) FS_putChars(STDCHANNEL,(NOSUCHLINE));
- else Program_delete(&program,&where,&where);
- Token_destroy(line);
- }
- else Program_store(&program,line,line->u.integer);
+ FS_intr = 0;
+ stopped = 0;
+ FS_allowIntr(1);
+ FS_nextline(STDCHANNEL);
+ if (FS_istty(STDCHANNEL))
+ FS_putChars(STDCHANNEL, "> ");
+ FS_flush(STDCHANNEL);
+ String_new(&s);
+ if (FS_appendToString(STDCHANNEL, &s, 1) == -1)
+ {
+ if (FS_intr)
+ {
+ FS_putChars(STDCHANNEL, _("\nBreak\n"));
+ FS_flush(STDCHANNEL);
+ String_destroy(&s);
+ continue;
+ }
+ else
+ {
+ FS_putChars(STDCHANNEL, FS_errmsg);
+ FS_flush(STDCHANNEL);
+ String_destroy(&s);
+ break;
+ }
}
- else
+ if (s.length == 0)
{
- FS_putChars(STDCHANNEL,_("Use `renum' to number program first"));
- Token_destroy(line);
+ String_destroy(&s);
+ break;
}
- }
- else if (line->type==T_UNNUMBERED)
- {
- runline(line+1);
- Token_destroy(line);
- if (FS_istty(STDCHANNEL) && bas_end>0)
+ line = Token_newCode(s.character);
+ String_destroy(&s);
+ if (line->type != T_EOL)
{
- FS_putChars(STDCHANNEL,_("END program\n"));
- bas_end=0;
+ if (line->type == T_INTEGER && line->u.integer > 0)
+ {
+ if (program.numbered)
+ {
+ if ((line + 1)->type == T_EOL)
+ {
+ struct Pc where;
+
+ if (Program_goLine(&program, line->u.integer, &where) ==
+ (struct Pc *)0)
+ FS_putChars(STDCHANNEL, (NOSUCHLINE));
+ else
+ Program_delete(&program, &where, &where);
+ Token_destroy(line);
+ }
+ else
+ Program_store(&program, line, line->u.integer);
+ }
+ else
+ {
+ FS_putChars(STDCHANNEL,
+ _("Use `renum' to number program first"));
+ Token_destroy(line);
+ }
+ }
+ else if (line->type == T_UNNUMBERED)
+ {
+ runline(line + 1);
+ Token_destroy(line);
+ if (FS_istty(STDCHANNEL) && bas_end > 0)
+ {
+ FS_putChars(STDCHANNEL, _("END program\n"));
+ bas_end = 0;
+ }
+ }
+ else
+ {
+ FS_putChars(STDCHANNEL, _("Invalid line\n"));
+ Token_destroy(line);
+ }
}
- }
else
- {
- FS_putChars(STDCHANNEL,_("Invalid line\n"));
Token_destroy(line);
- }
}
- else Token_destroy(line);
- }
FS_allowIntr(0);
}
-/*}}}*/
-void bas_exit(void) /*{{{*/
+
+void bas_exit(void)
{
Auto_destroy(&stack);
Global_destroy(&globals);
Program_destroy(&program);
- if (labelStack) free(labelStack);
+ if (labelStack)
+ free(labelStack);
FS_closefiles();
FS_close(LPCHANNEL);
FS_close(STDCHANNEL);
}
-/*}}}*/
diff --git a/apps/interpreters/bas/global.c b/apps/interpreters/bas/global.c
index 0b78f999b..ef8cc0c64 100644
--- a/apps/interpreters/bas/global.c
+++ b/apps/interpreters/bas/global.c
@@ -100,7 +100,7 @@ static struct Value *bin(struct Value *v, unsigned long int value, long int digi
{
char buf[sizeof(long int)*8+1];
char *s;
-
+
Value_new_STRING(v);
s=buf+sizeof(buf);
*--s='\0';
@@ -133,7 +133,7 @@ static struct Value *find(struct Value *v, struct String *pattern, long int occu
struct dirent *ent;
int currentdir;
int found=0;
-
+
Value_new_STRING(v);
String_new(&dirname);
String_new(&basename);
@@ -418,7 +418,7 @@ static struct Value *fn_cvi(struct Value *v, struct Auto *stack) /*{{{*/
struct String *s=stringValue(stack,0);
long int n=(s->length && s->character[s->length-1]<0) ? -1 : 0;
int i;
-
+
for (i=s->length-1; i>=0; --i) n=(n<<8)|(s->character[i]&0xff);
return Value_new_INTEGER(v,n);
}
@@ -508,7 +508,7 @@ static struct Value *fn_edit(struct Value *v, struct Auto *stack) /*{{{*/
if ((code&16) && ((*rd==' ') || (*rd=='\t')))
{
*wr++=' ';
- while (rd<end && (*rd==' ' || *rd=='\t')) ++rd;
+ while (rd<end && (*rd==' ' || *rd=='\t')) ++rd;
continue;
}
@@ -1377,7 +1377,7 @@ static struct Value *fn_timer(struct Value *v, struct Auto *stack) /*{{{*/
static struct Value *fn_tl(struct Value *v, struct Auto *stack) /*{{{*/
{
struct String *s=stringValue(stack,0);
-
+
Value_new_STRING(v);
if (s->length)
{
@@ -1408,7 +1408,7 @@ static struct Value *fn_val(struct Value *v, struct Auto *stack) /*{{{*/
char *end;
long int i;
int overflow;
-
+
if (s->character==(char*)0) return Value_new_REAL(v,0.0);
i=Value_vali(s->character,&end,&overflow);
if (*end=='\0') return Value_new_INTEGER(v,i);
diff --git a/apps/interpreters/bas/main.c b/apps/interpreters/bas/main.c
index 33680c3fc..e925c0894 100644
--- a/apps/interpreters/bas/main.c
+++ b/apps/interpreters/bas/main.c
@@ -1,3 +1,7 @@
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
#undef _POSIX_SOURCE
#define _POSIX_SOURCE 1
#undef _POSIX_C_SOURCE
@@ -24,7 +28,9 @@
#include "bas.h"
-/*}}}*/
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
#ifdef CONFIG_BUILD_KERNEL
int main(int argc, FAR char *argv[])
diff --git a/apps/interpreters/bas/program.c b/apps/interpreters/bas/program.c
index a0e046a95..f90201908 100644
--- a/apps/interpreters/bas/program.c
+++ b/apps/interpreters/bas/program.c
@@ -323,7 +323,7 @@ struct Value *Program_merge(struct Program *this, int dev, struct Value *value)
struct Token *line;
++l;
- if (l!=1 || s.character[0]!='#')
+ if (l!=1 || s.character[0]!='#')
{
line=Token_newCode(s.character);
if (line->type==T_INTEGER && line->u.integer>0) Program_store(this,line,this->numbered?line->u.integer:0);
diff --git a/apps/interpreters/bas/statement.c b/apps/interpreters/bas/statement.c
index 4e965dbe1..804fb37f6 100644
--- a/apps/interpreters/bas/statement.c
+++ b/apps/interpreters/bas/statement.c
@@ -54,7 +54,7 @@ struct Value *stmt_CASE(struct Value *value) /*{{{*/
*nextcasevalue=pc;
if (pass==COMPILE) pc.token->u.casevalue->endselect=selectcase->token->u.selectcase->endselect;
pc.token->u.casevalue->nextcasevalue.line=-1;
- ++pc.token;
+ ++pc.token;
switch (statementpc.token->type)
{
case T_CASEELSE: break;
@@ -85,7 +85,7 @@ struct Value *stmt_CASE(struct Value *value) /*{{{*/
pc=exprpc;
return value;
}
- Value_destroy(value);
+ Value_destroy(value);
}
/*}}}*/
else /* value or range */ /*{{{*/
@@ -556,7 +556,7 @@ struct Value *stmt_DIM(struct Value *value) /*{{{*/
*var=newarray;
free(geometry);
}
- if (pc.token->type==T_COMMA) ++pc.token; /* advance to next var */
+ if (pc.token->type==T_COMMA) ++pc.token; /* advance to next var */
else break;
}
return (struct Value*)0;
@@ -655,7 +655,7 @@ struct Value *stmt_EDIT(struct Value *value) /*{{{*/
{ "joe", "+%ld " },
{ "modeori", "-l%ld " },
{ "origami", "-l%ld " },
- { "vi", "-c%ld " },
+ { "vi", "-c%ld " },
{ "vim", "+%ld " },
{ "xemacs", "+%ld " }
};
@@ -789,7 +789,7 @@ struct Value *stmt_END(struct Value *value) /*{{{*/
struct Token *eol;
for (eol=pc.token; eol->type!=T_EOL; ++eol);
-
+
pc.token->u.endpc=pc;
pc.token->u.endpc.token=eol;
++pc.token;
@@ -1202,7 +1202,7 @@ struct Value *stmt_GET_PUT(struct Value *value) /*{{{*/
int put=pc.token->type==T_PUT;
long int chn;
struct Pc errpc;
-
+
++pc.token;
if (pc.token->type==T_CHANNEL) ++pc.token;
if (eval(value,_("channel"))->type==V_ERROR || Value_retype(value,V_INTEGER)->type==V_ERROR) return value;
@@ -1556,7 +1556,7 @@ struct Value *stmt_LOCATE(struct Value *value) /*{{{*/
if (eval(value,_("row"))->type==V_ERROR || Value_retype(value,V_INTEGER)->type==V_ERROR) return value;
line=value->u.integer;
Value_destroy(value);
- if (pass==INTERPRET && line<1)
+ if (pass==INTERPRET && line<1)
{
pc=argpc;
return Value_new_ERROR(value,OUTOFRANGE,_("row"));
@@ -1567,7 +1567,7 @@ struct Value *stmt_LOCATE(struct Value *value) /*{{{*/
if (eval(value,_("column"))->type==V_ERROR || Value_retype(value,V_INTEGER)->type==V_ERROR) return value;
column=value->u.integer;
Value_destroy(value);
- if (pass==INTERPRET && column<1)
+ if (pass==INTERPRET && column<1)
{
pc=argpc;
return Value_new_ERROR(value,OUTOFRANGE,_("column"));
@@ -1716,7 +1716,7 @@ struct Value *stmt_IDENTIFIER(struct Value *value) /*{{{*/
if (pass!=INTERPRET) Value_destroy(value);
}
}
-
+
return (struct Value*)0;
}
/*}}}*/
@@ -2796,7 +2796,7 @@ struct Value *stmt_OPEN(struct Value *value) /*{{{*/
}
}
Value_destroy(value);
- if (pass==INTERPRET && inout==-1)
+ if (pass==INTERPRET && inout==-1)
{
pc=errpc;
return Value_new_ERROR(value,BADMODE);
@@ -3042,7 +3042,7 @@ struct Value *stmt_PRINT_LPRINT(struct Value *value) /*{{{*/
{
struct Pc usingpc;
- usingpc=pc;
+ usingpc=pc;
printusing=1;
++pc.token;
if (pc.token->type==T_INTEGER)
@@ -3386,7 +3386,7 @@ struct Value *stmt_RUN(struct Value *value) /*{{{*/
if (Program_beginning(&program,&begin)==(struct Pc*)0)
{
return Value_new_ERROR(value,NOPROGRAM);
- }
+ }
}
else Value_destroy(value);
}
@@ -3986,7 +3986,7 @@ struct Value *stmt_WRITE(struct Value *value) /*{{{*/
/*}}}*/
while (1)
{
- if (eval(value,(const char*)0))
+ if (eval(value,(const char*)0))
{
if (value->type==V_ERROR) return value;
if (pass==INTERPRET)
diff --git a/apps/interpreters/bas/token.c b/apps/interpreters/bas/token.c
index bec1b05c5..12a9c49d2 100644
--- a/apps/interpreters/bas/token.c
+++ b/apps/interpreters/bas/token.c
@@ -33,7 +33,7 @@
#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
- * if you want the limit (max/min) macros for int types.
+ * if you want the limit (max/min) macros for int types.
*/
#ifndef __STDC_LIMIT_MACROS
#define __STDC_LIMIT_MACROS 1
@@ -50,7 +50,7 @@ typedef uint32_t flex_uint32_t;
typedef signed char flex_int8_t;
typedef short int flex_int16_t;
typedef int flex_int32_t;
-typedef unsigned char flex_uint8_t;
+typedef unsigned char flex_uint8_t;
typedef unsigned short int flex_uint16_t;
typedef unsigned int flex_uint32_t;
@@ -176,7 +176,7 @@ extern FILE *yyin, *yyout;
#define YY_LESS_LINENO(n)
#define YY_LINENO_REWIND_TO(ptr)
-
+
/* Return all but the first "n" matched characters back to the input stream. */
#define yyless(n) \
do \
@@ -233,7 +233,7 @@ struct yy_buffer_state
int yy_bs_lineno; /**< The line count. */
int yy_bs_column; /**< The column count. */
-
+
/* Whether to try to fill the input buffer when we reach the
* end of it.
*/
@@ -1646,7 +1646,7 @@ YY_DECL
register yy_state_type yy_current_state;
register char *yy_cp, *yy_bp;
register int yy_act;
-
+
if ( !(yy_init) )
{
(yy_init) = 1;
@@ -3629,7 +3629,7 @@ YY_RULE_SETUP
{
cur->statement=stmt_QUOTE_REM;
strcpy(cur->u.rem=malloc(strlen(yytext+1)+1),yytext+1);
- }
+ }
return T_QUOTE;
}
YY_BREAK
@@ -3989,7 +3989,7 @@ static int yy_get_next_buffer (void)
{
register yy_state_type yy_current_state;
register char *yy_cp;
-
+
yy_current_state = (yy_start);
for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp )
@@ -4049,7 +4049,7 @@ static int yy_get_next_buffer (void)
{
int c;
-
+
*(yy_c_buf_p) = (yy_hold_char);
if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR )
@@ -4116,12 +4116,12 @@ static int yy_get_next_buffer (void)
/** Immediately switch to a different input stream.
* @param input_file A readable stream.
- *
+ *
* @note This function does not reset the start condition to @c INITIAL .
*/
void yyrestart (FILE * input_file )
{
-
+
if ( ! YY_CURRENT_BUFFER ){
yyensure_buffer_stack ();
YY_CURRENT_BUFFER_LVALUE =
@@ -4134,11 +4134,11 @@ static int yy_get_next_buffer (void)
/** Switch to a different input buffer.
* @param new_buffer The new input buffer.
- *
+ *
*/
void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer )
{
-
+
/* TODO. We should be able to replace this entire function body
* with
* yypop_buffer_state();
@@ -4178,13 +4178,13 @@ static void yy_load_buffer_state (void)
/** Allocate and initialize an input buffer state.
* @param file A readable stream.
* @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
- *
+ *
* @return the allocated buffer state.
*/
YY_BUFFER_STATE yy_create_buffer (FILE * file, int size )
{
YY_BUFFER_STATE b;
-
+
b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) );
if ( ! b )
YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
@@ -4207,11 +4207,11 @@ static void yy_load_buffer_state (void)
/** Destroy the buffer.
* @param b a buffer created with yy_create_buffer()
- *
+ *
*/
void yy_delete_buffer (YY_BUFFER_STATE b )
{
-
+
if ( ! b )
return;
@@ -4232,7 +4232,7 @@ static void yy_load_buffer_state (void)
{
int oerrno = errno;
-
+
yy_flush_buffer(b );
b->yy_input_file = file;
@@ -4248,13 +4248,13 @@ static void yy_load_buffer_state (void)
}
b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
-
+
errno = oerrno;
}
/** Discard all buffered characters. On the next scan, YY_INPUT will be called.
* @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
- *
+ *
*/
void yy_flush_buffer (YY_BUFFER_STATE b )
{
@@ -4283,7 +4283,7 @@ static void yy_load_buffer_state (void)
* the current state. This function will allocate the stack
* if necessary.
* @param new_buffer The new state.
- *
+ *
*/
void yypush_buffer_state (YY_BUFFER_STATE new_buffer )
{
@@ -4313,7 +4313,7 @@ void yypush_buffer_state (YY_BUFFER_STATE new_buffer )
/** Removes and deletes the top of the stack, if present.
* The next element becomes the new top.
- *
+ *
*/
void yypop_buffer_state (void)
{
@@ -4337,7 +4337,7 @@ void yypop_buffer_state (void)
static void yyensure_buffer_stack (void)
{
yy_size_t num_to_alloc;
-
+
if (!(yy_buffer_stack)) {
/* First allocation is just for 2 elements, since we don't know if this
@@ -4350,7 +4350,7 @@ static void yyensure_buffer_stack (void)
);
if ( ! (yy_buffer_stack) )
YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
-
+
memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*));
(yy_buffer_stack_max) = num_to_alloc;
@@ -4380,13 +4380,13 @@ static void yyensure_buffer_stack (void)
/** Setup the input buffer state to scan directly from a user-specified character buffer.
* @param base the character buffer
* @param size the size in bytes of the character buffer
- *
- * @return the newly allocated buffer state object.
+ *
+ * @return the newly allocated buffer state object.
*/
YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size )
{
YY_BUFFER_STATE b;
-
+
if ( size < 2 ||
base[size-2] != YY_END_OF_BUFFER_CHAR ||
base[size-1] != YY_END_OF_BUFFER_CHAR )
@@ -4415,14 +4415,14 @@ YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size )
/** Setup the input buffer state to scan a string. The next call to yylex() will
* scan from a @e copy of @a str.
* @param yystr a NUL-terminated string to scan
- *
+ *
* @return the newly allocated buffer state object.
* @note If you want to scan bytes that may contain NUL values, then use
* yy_scan_bytes() instead.
*/
YY_BUFFER_STATE yy_scan_string (yyconst char * yystr )
{
-
+
return yy_scan_bytes(yystr,strlen(yystr) );
}
@@ -4430,7 +4430,7 @@ YY_BUFFER_STATE yy_scan_string (yyconst char * yystr )
* scan from a @e copy of @a bytes.
* @param yybytes the byte buffer to scan
* @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
- *
+ *
* @return the newly allocated buffer state object.
*/
YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len )
@@ -4439,7 +4439,7 @@ YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len
char *buf;
yy_size_t n;
yy_size_t i;
-
+
/* Get memory for full buffer, including space for trailing EOB's. */
n = _yybytes_len + 2;
buf = (char *) yyalloc(n );
@@ -4493,16 +4493,16 @@ static void yy_fatal_error (yyconst char* msg )
/* Accessor methods (get/set functions) to struct members. */
/** Get the current line number.
- *
+ *
*/
int yyget_lineno (void)
{
-
+
return yylineno;
}
/** Get the input stream.
- *
+ *
*/
FILE *yyget_in (void)
{
@@ -4510,7 +4510,7 @@ FILE *yyget_in (void)
}
/** Get the output stream.
- *
+ *
*/
FILE *yyget_out (void)
{
@@ -4518,7 +4518,7 @@ FILE *yyget_out (void)
}
/** Get the length of the current token.
- *
+ *
*/
yy_size_t yyget_leng (void)
{
@@ -4526,7 +4526,7 @@ yy_size_t yyget_leng (void)
}
/** Get the current token.
- *
+ *
*/
char *yyget_text (void)
@@ -4536,18 +4536,18 @@ char *yyget_text (void)
/** Set the current line number.
* @param line_number
- *
+ *
*/
void yyset_lineno (int line_number )
{
-
+
yylineno = line_number;
}
/** Set the input stream. This does not discard the current
* input buffer.
* @param in_str A readable stream.
- *
+ *
* @see yy_switch_to_buffer
*/
void yyset_in (FILE * in_str )
@@ -4601,7 +4601,7 @@ static int yy_init_globals (void)
/* yylex_destroy is for both reentrant and non-reentrant scanners. */
int yylex_destroy (void)
{
-
+
/* Pop the buffer stack, destroying each element. */
while(YY_CURRENT_BUFFER){
yy_delete_buffer(YY_CURRENT_BUFFER );
@@ -5182,7 +5182,7 @@ struct String *Token_toString(struct Token *token, struct Token *spaceto, struct
++thisnotindent; ++nextindent;
}
break;
- }
+ }
case T_SELECTCASE: thisnotindent+=2; nextindent+=2; break;
case T_EQ:
{
diff --git a/apps/interpreters/bas/value.c b/apps/interpreters/bas/value.c
index 6a5ab0b4d..6d0d54053 100644
--- a/apps/interpreters/bas/value.c
+++ b/apps/interpreters/bas/value.c
@@ -1284,7 +1284,7 @@ struct Value *Value_toStringUsing(struct Value *this, struct String *s, struct S
goto work;
}
else
- {
+ {
Value_destroy(this);
return Value_new_ERROR(this,IOERROR,_("unpaired \\ in format"));
}
@@ -1340,17 +1340,17 @@ struct Value *Value_toStringUsing(struct Value *this, struct String *s, struct S
}
}
if (*usingpos<using->length && using->character[*usingpos]=='-' )
- {
+ {
++(*usingpos);
if (headingsign==0) headingsign=2;
trailingsign=-1;
- }
+ }
else if (*usingpos<using->length && using->character[*usingpos]=='+')
- {
+ {
++(*usingpos);
if (headingsign==0) headingsign=2;
trailingsign=1;
- }
+ }
while (*usingpos<using->length && using->character[*usingpos]=='^')
{
++(*usingpos);
@@ -1405,7 +1405,7 @@ struct String *Value_toWrite(struct Value *this, struct String *s) /*{{{*/
switch (this->type)
{
case V_INTEGER: String_appendPrintf(s,"%ld",this->u.integer); break;
- case V_REAL:
+ case V_REAL:
{
double x;
int p=DBL_DIG;
@@ -1427,7 +1427,7 @@ struct String *Value_toWrite(struct Value *this, struct String *s) /*{{{*/
{
size_t l=this->u.string.length;
char *data=this->u.string.character;
-
+
String_appendChar(s,'"');
while (l--)
{