Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions src/intrprtr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1790,19 +1790,24 @@ void IntrLongIntExpr(Obj string)

static Obj CONVERT_FLOAT_LITERAL_EAGER;

static Obj ConvertFloatLiteralEager(Obj str) {
Char *chars = (Char *)CHARS_STRING(str);
UInt len = GET_LEN_STRING(str);
Char mark = '\0';
if (chars[len-1] == '_') {
SET_LEN_STRING(str, len-1);
chars[len-1] = '\0';
} else if (chars[len-2] == '_') {
mark = chars[len-1];
SET_LEN_STRING(str, len-2);
chars[len-2] = '\0';
}
return CALL_2ARGS(CONVERT_FLOAT_LITERAL_EAGER, str, ObjsChar[(UInt)mark]);
static Obj ConvertFloatLiteralEager(Obj str)
{
Char * chars = (Char *)CHARS_STRING(str);
UInt len = GET_LEN_STRING(str);
Char mark = '\0';
if (chars[len - 1] == '_') {
SET_LEN_STRING(str, len - 1);
chars[len - 1] = '\0';
}
else if (chars[len - 2] == '_') {
mark = chars[len - 1];
SET_LEN_STRING(str, len - 2);
chars[len - 2] = '\0';
}
Obj res = CALL_2ARGS(CONVERT_FLOAT_LITERAL_EAGER, str, ObjsChar[(UInt)mark]);
if (res == Fail)
ErrorQuit("failed to convert float literal", 0, 0);
return res;
}

void IntrFloatExpr (
Expand Down
44 changes: 23 additions & 21 deletions src/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -778,14 +778,16 @@ void ReadCallVarAss(TypSymbolSet follow, Char mode)
// deal with references
if (mode == 'r' || (mode == 'x' && STATE(Symbol) != S_ASSIGN)) {
Obj val = ValAutoGVar(ref.var);
if (val == True)
IntrTrueExpr();
else if (val == False)
IntrFalseExpr();
else if (IS_INTOBJ(val))
IntrIntObjExpr(val);
else
SyntaxError("Invalid constant variable");
TRY_READ {
if (val == True)
IntrTrueExpr();
else if (val == False)
IntrFalseExpr();
else if (IS_INTOBJ(val))
IntrIntObjExpr(val);
else
SyntaxError("Invalid constant variable");
}
return;
}
}
Expand Down Expand Up @@ -976,7 +978,7 @@ void ReadLongNumber(
case S_INT:
appendToString(string, STATE(Value));
Match(S_INT, "integer", follow);
IntrLongIntExpr(string);
TRY_READ { IntrLongIntExpr(string); }
done = 1;
break;

Expand All @@ -1001,7 +1003,7 @@ void ReadLongNumber(
case S_FLOAT:
appendToString(string, STATE(Value));
Match(S_FLOAT, "float", follow);
IntrLongFloatExpr(string);
TRY_READ { IntrLongFloatExpr(string); }
done = 1;
break;

Expand All @@ -1010,7 +1012,7 @@ void ReadLongNumber(

default:
appendToString(string, STATE(Value));
IntrLongIntExpr(string);
TRY_READ { IntrLongIntExpr(string); }
done = 1;
}
break;
Expand All @@ -1036,7 +1038,7 @@ void ReadLongNumber(
case S_FLOAT:
appendToString(string, STATE(Value));
Match(S_FLOAT, "float", follow);
IntrLongFloatExpr(string);
TRY_READ { IntrLongFloatExpr(string); }
done = 1;
break;

Expand Down Expand Up @@ -1066,7 +1068,7 @@ void ReadLongNumber(
case S_FLOAT:
appendToString(string, STATE(Value));
Match(S_FLOAT, "float", follow);
IntrLongFloatExpr(string);
TRY_READ { IntrLongFloatExpr(string); }
done = 1;
break;

Expand All @@ -1076,7 +1078,7 @@ void ReadLongNumber(

default:
appendToString(string, STATE(Value));
IntrLongFloatExpr(string);
TRY_READ { IntrLongFloatExpr(string); }
done = 1;
}
break;
Expand All @@ -1102,7 +1104,7 @@ void ReadLongNumber(
case S_FLOAT:
appendToString(string, STATE(Value));
Match(S_FLOAT, "float", follow);
IntrLongFloatExpr(string);
TRY_READ { IntrLongFloatExpr(string); }
done = 1;
break;

Expand Down Expand Up @@ -1133,7 +1135,7 @@ void ReadLongNumber(
case S_FLOAT:
appendToString(string, STATE(Value));
Match(S_FLOAT, "float", follow);
IntrLongFloatExpr(string);
TRY_READ { IntrLongFloatExpr(string); }
done = 1;
break;

Expand All @@ -1142,7 +1144,7 @@ void ReadLongNumber(

default:
appendToString(string, STATE(Value));
IntrLongFloatExpr(string);
TRY_READ { IntrLongFloatExpr(string); }
done = 1;

}
Expand Down Expand Up @@ -1185,7 +1187,7 @@ void ReadString(
SET_LEN_STRING(string, len);
/* ensure trailing zero for interpretation as C-string */
*(CHARS_STRING(string) + len) = 0;
IntrStringExpr( string );
TRY_READ { IntrStringExpr( string ); }
}

/****************************************************************************
Expand Down Expand Up @@ -2047,7 +2049,7 @@ void ReadQualifiedExpr (
TypSymbolSet follow,
Char mode )
{
UInt access = 0;
volatile UInt access = 0;
if (STATE(Symbol) == S_READWRITE)
{
Match( S_READWRITE, "readwrite", follow | EXPRBEGIN );
Expand All @@ -2058,9 +2060,9 @@ void ReadQualifiedExpr (
Match( S_READONLY, "readonly", follow | EXPRBEGIN );
access = 1;
}
IntrQualifiedExprBegin(access);
TRY_READ { IntrQualifiedExprBegin(access); }
ReadExpr(follow,mode);
IntrQualifiedExprEnd();
TRY_READ { IntrQualifiedExprEnd(); }
}


Expand Down
10 changes: 8 additions & 2 deletions src/read.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,16 @@
** }
**
** Then, if the reader encounters an error, or if the interpretation of an
** expression or statement leads to an error, then 'ReadEvalError' is
** invoked which in turn calls 'longjmp' to return to right after the block
** expression or statement leads to an error, 'ReadEvalError' is invoked,
** which in turn calls 'longjmp' to return to right after the block
** following TRY_READ.
**
** A second effect of 'TRY_READ' is that it prevents the execution of the
** code it wraps if 'STATE(NrError)' is non-zero, i.e. if any errors
** occurred. This is key for enabling graceful error recovery in the reader,
** and for this reason it is crucial that all calls from the reader into
** the interpreter are wrapped into 'TRY_READ' blocks.
**
** Note that while you can in principle nest TRY_READ constructs, to do this
** correctly, you must backup ReadJmpError before TRY_READ, and restore it
** in a matching CATCH_READ_ERROR block.
Expand Down
21 changes: 21 additions & 0 deletions tst/testinstall/float.tst
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,27 @@ false
gap> EqFloat(0.0,0.0/0.0);
false

#
# float literals in the REPL
#
gap> 1.1;
1.1
gap> 1.1_;
1.1
gap> 1.x1;
Syntax error: Badly formed number in stream:1
1.x1;
^
gap> 1.1xx;
Syntax error: Badly formed number in stream:1
1.1xx;
^

# The following is potentially correct, *if* there is a conversion handler for
# 'x' installed, which normally isn't the case.
gap> 1.1x;
Error, failed to convert float literal

#
# float literal expressions in functions
#
Expand Down
2 changes: 1 addition & 1 deletion tst/testinstall/longnumber.tst
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ int in stream:1
.q;
^
gap> .0n;
fail
Error, failed to convert float literal
gap> .0q;
Syntax error: Badly Formed Number: need at least one digit in the exponent in \
stream:1
Expand Down