Skip to content

Commit

Permalink
Merge pull request #38 from Sparrow-lang/bugfixing
Browse files Browse the repository at this point in the history
Bugfixing
  • Loading branch information
lucteo authored Mar 15, 2017
2 parents 2c7acda + cb04c2e commit 51b0279
Show file tree
Hide file tree
Showing 8 changed files with 1,449 additions and 1,413 deletions.
2 changes: 1 addition & 1 deletion SparrowImplicitLib/check.spr
Original file line number Diff line number Diff line change
Expand Up @@ -285,4 +285,4 @@ package _Impl
r advance randBetween(0, Int(_count))
return r.front

fun gen: Gen(ElementType) = ife(_count>0, this, Gen(ElementType)())
fun gen: Gen(ElementType) = ife(_count>0, this, Gen(ElementType)())
11 changes: 11 additions & 0 deletions src/Feather/src/Api/Feather_Nodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,17 @@ using namespace Feather;
if ( !Feather_isTestable(condition) )
REP_ERROR_RET(nullptr, condition->location, "The condition of the while is not Testable");

// Dereference the condition as much as possible
while ( condition->type && condition->type->numReferences > 0 )
{
condition = Feather_mkMemLoad(condition->location, condition);
Nest_setContext(condition, Nest_childrenContext(node));
if ( !Nest_semanticCheck(condition) )
return nullptr;
}
at(node->children, 0) = condition;
// TODO (while): Remove this dereference from here

if ( Feather_nodeEvalMode(node) == modeCt )
{
if ( !Feather_isCt(condition) )
Expand Down
4 changes: 2 additions & 2 deletions src/SparrowFrontend/Grammar/layoutDecoder.spr
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ fun popFront(this: @_This)
// Consume the current token from the input range
_src.popFront

// Check for line endings
var changeLine = _src.front().type == tkEOL
// Check for line endings (or end of files)
var changeLine = _src.front().type == tkEOL || _src.front().type == tkEND
while _src.front().type == tkEOL
_src.popFront

Expand Down
1 change: 1 addition & 0 deletions src/SparrowFrontend/Grammar/parser.spr
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ package _Impl

fun parseExpression(this: @This): Node
var res = parseExpr(this)
this accept tkSEMICOLON
this expect tkEND
return res

Expand Down
2,821 changes: 1,417 additions & 1,404 deletions src/SparrowFrontend/Grammar/parserIf.ll

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions src/SparrowFrontend/Grammar/scanner.spr
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class SparrowScanner(sourceType, errorReporterType: Type) \
this._src.ctor(RangeWithLookahead(sourceType)(source), _curLocation)
this._curToken ctor
this._tokenIsComputed ctor false
this._atEnd ctor false
this._errorReporter ctor errorReporter

/// Location that we use to keep track of the source chars
Expand All @@ -64,22 +63,23 @@ class SparrowScanner(sourceType, errorReporterType: Type) \
var _curToken: Token
/// Indicates if '_curToken' is computed or not
var _tokenIsComputed: Bool
/// Indicates if '_curToken' is computed or not
var _atEnd: Bool
/// Object used to report errors
var _errorReporter: errorReporterType
/// Concept that matches SparrowScanner above
concept _OurScanner(t) if t.IsSparrowScanner

fun isEmpty(this: @_OurScanner) = _atEnd
fun isEmpty(this: @_OurScanner) = false
fun front(this: @_OurScanner): Token
if !_tokenIsComputed
_tokenIsComputed = true
this.popFront
return _curToken
fun popFront(this: @_OurScanner)
if (_src.isEmpty) && _curToken.type == tkEND
_atEnd = true
if _src.isEmpty
_src.location stepOver
_curToken.type = tkEND
_curToken.data clear
_curToken.loc = _src.location
else
_curToken.type = _Impl.nextToken(this)
_curToken.loc = _src.location
Expand Down
8 changes: 8 additions & 0 deletions tests/Bugs/WhileVarCond.spr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fun sprMain
var a: Bool
a = true
var ra: @Bool = a
while a
break
while ra
break
3 changes: 3 additions & 0 deletions tests/tests.in
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Bugs/SpecializationOnCt.spr: Bugs - specialization on CT vs RT
# Bugs/Overload.spr: Bugs - overload resolution fails
Bugs/StaticGlobal.spr: Bugs - static vars, global vars, static ctor
Bugs/VectorOfCtClass.spr: Bugs - vectors of CT-only classes
Bugs/WhileVarCond.spr: Bugs - while condition is a variable or a reference

# AlgoProblems/P1_Collatz.spr: Algo problems - P1. Collatz sequences
Examples/Power.spr: Examples: Powers
Expand Down Expand Up @@ -163,3 +164,5 @@ Frontend/Identifiers.spr: Frontend - identifiers
Frontend/Operators.spr: Frontend - operators
Frontend/PrefixPostfix.spr: Frontend - prefix & postfix operators
Frontend/StringAndDsl.spr: Frontend - string and DSL

# ../src/SparrowFrontend/Grammar/parserTest.spr: Sparrow parser test

0 comments on commit 51b0279

Please sign in to comment.