Skip to content

Commit cb8b6e3

Browse files
authored
Merge pull request #85 from Sparrow-lang/tools_support
Tools support
2 parents 9cedda1 + e755d23 commit cb8b6e3

File tree

235 files changed

+25757
-20727
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

235 files changed

+25757
-20727
lines changed

.travis/run.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ echo "---------- Testing ----------"
2727
cd ../tests
2828

2929
python test.py StdLib/RangesTest.spr --returnError
30+
python test.py ../tools/formatTool.spr --returnError
3031
python test.py --returnError

SparrowImplicitLib/check.spr

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,18 @@ fun ()(this: @Gen, sizeHint: UInt): ValueType = _generator(sizeHint)
1818

1919
fun isValid(this: @Gen): Bool = _generator isSet
2020

21-
22-
2321
concept GenType(x) \
2422
if typeOf(x.ValueType) == Type \
2523
&& typeOf(x.isValid) == Bool \
2624
&& typeOf(x(0)) == x.ValueType
2725

28-
2926
//! Arbitrary prototype
3027
//fun arbitrary(t: Type): t Gen
3128

3229
//! Arbitrary definition for the integer types
3330
fun arbitrary(t: Type): t Gen if Integer(#$t)
3431
return mkGen(t, \_Impl.NumericGen(t).gen)
3532

36-
3733
//! Configuration options for our check function
3834
[initCtor]
3935
datatype CheckConfig
@@ -170,7 +166,6 @@ fun frequency(gens: Range): typeOf((#$gens.RetType).v2) if FreqGenType(#$gens.Re
170166
curAcc += fg.v1
171167
return typeOf((#$gens.RetType).v2)()
172168

173-
174169
fun randBetween(min, max: Integer): commonType(typeOf(min), typeOf(max))
175170
using T = commonType(typeOf(min), typeOf(max))
176171
using RAND_MAX = 0x7fffffff
@@ -260,7 +255,6 @@ package _Impl
260255
res.isTrivial = _pred(res.value)
261256
return res
262257

263-
264258
[initCtor]
265259
datatype ClassifierRange(rangeType, predType: Type) \
266260
if typeOf((#$predType)((#$rangeType front).value)) == String

SparrowImplicitLib/logic/lRef.spr

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@ concept LRefType(x) if (
2020
&& isValid(x.reset(#$x.ValueType))
2121
)
2222

23-
2423
//using logicDebug = 1
2524
//using logicRefDebug = 1
2625

27-
2826
// A logical reference that contains strings
2927
using LStr = LRef(String)
3028

@@ -40,7 +38,6 @@ fun ctor(this: @ScopeTracer, name: StringRef)
4038
fun dtor(this: @ScopeTracer)
4139
cout << '>>> ' << str << '\n'
4240

43-
4441
/// A logical reference
4542
///
4643
/// A logical reference is in essence a shared pointer over an optional value.
@@ -76,7 +73,6 @@ fun ctor(this, other: @LRef)
7673
[ct] if ( isValid(logicDebug) && isValid(logicRefDebug) )
7774
cout << "copy ctor: " << this << "\n"
7875

79-
8076
[protected]
8177
fun dtor(this: @LRef)
8278
[ct] if ( isValid(logicDebug) && isValid(logicRefDebug) )
@@ -181,7 +177,6 @@ package _Impl
181177

182178
fun mkBinaryOp(l, r: @ValWrapper, oper: Int ct) = BinaryOp(-@typeOf(l), -@typeOf(r), oper)(l, r)
183179

184-
185180
fun mkPlusOp(l, r: @ValWrapper) = mkBinaryOp(l, r, _operPlus)
186181
fun mkMinusOp(l, r: @ValWrapper) = mkBinaryOp(l, r, _operMinus)
187182
fun mkMulOp(l, r: @ValWrapper) = mkBinaryOp(l, r, _operMul)

SparrowImplicitLib/logic/predicates.spr

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ fun isSet(this: @Predicate) = predObj.isSet()
2727

2828
fun ()(this: @Predicate): Bool = predObj()
2929

30-
3130
/// Logic equality: equality test + inference
3231
fun eq(l, r: @AnyType) = _mkEq(mkValOrRef(l), mkValOrRef(r))
3332
fun /=/(l, r: @AnyType) = _mkEq(mkValOrRef(l), mkValOrRef(r))
@@ -42,8 +41,6 @@ using oper_precedence_=/ = oper_precedence_== + 1
4241
//setOperPrecedence("/=/", getOperPrecedence("==") + 1)
4342
//setOperPrecedence("=/", getOperPrecedence("==") + 1)
4443

45-
46-
4744
/// Logic Disjunction
4845
fun ||(l, r: @PredicateType) = OrRelation(-@typeOf(l), -@typeOf(r))(l, r)
4946

@@ -55,7 +52,6 @@ fun mkFalse = LFalse()
5552
/// Relation that always returns true
5653
fun mkTrue = LTrue()
5754

58-
5955
datatype UnifyLR(leftType, rightType: Type) if ValWrapper(#$leftType) && ValWrapper(#$rightType)
6056
using ValueType = Bool
6157
using ValuePassType = Bool
@@ -139,7 +135,6 @@ fun ()(this: @UnifyLR): Bool
139135

140136
fun _mkEq(l, r: @ValWrapper) = UnifyLR(-@typeOf(l), -@typeOf(r))(l, r)
141137

142-
143138
datatype OrRelation(leftPredicateType, rightPredicateType: Type)
144139
using ValueType = Bool
145140
using ValuePassType = Bool
@@ -225,8 +220,6 @@ fun ()(this: @AndRelation): Bool
225220
return false
226221
return false
227222

228-
229-
230223
datatype LFalse
231224
;
232225
fun ()(this: LFalse) = false

SparrowImplicitLib/logic/prolog.spr

Lines changed: 39 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,53 @@
1-
module logic.prolog;
1+
module logic.prolog
22

3-
import lRef;
4-
import predicates;
5-
import recurse;
3+
import lRef
4+
import predicates
5+
import recurse
66

7-
import prologImpl.nodes;
8-
import prologImpl.lexer;
9-
import prologImpl.parser;
10-
import prologImpl.ir;
11-
import prologImpl.sprCodeDump;
12-
import prologImpl.codeGen;
7+
import prologImpl.nodes
8+
import prologImpl.lexer
9+
import prologImpl.parser
10+
import prologImpl.ir
11+
import prologImpl.sprCodeDump
12+
import prologImpl.codeGen
1313

14-
import meta = meta.nodeKinds;
14+
import meta = meta.nodeKinds
1515

16-
import assert;
17-
import time = time;
16+
import assert
17+
import time = time
1818

1919
[macro] fun compileProlog(sourceString: CompilerAstNode): CompilerAstNode
20-
{
21-
var sourceStr: meta.AstNode = sourceString;
20+
var sourceStr: meta.AstNode = sourceString
2221
[ct] if ( (sourceString nodeKind) != meta.nkSparrowExpLiteral )
23-
meta.report("compileProlog should take a string literal as argument", (sourceStr location));
22+
meta.report("compileProlog should take a string literal as argument", (sourceStr location))
23+
return CompilerAstNode()
2424
else
25-
{
26-
sourceStr semanticCheck;
27-
var loc = sourceStr location;
28-
var ctx = sourceStr context;
29-
var str: String = astEval(sourceString clone);
30-
return handlePrologCode(str, loc, ctx);
31-
}
32-
}
25+
sourceStr semanticCheck
26+
var loc = sourceStr location
27+
var ctx = sourceStr context
28+
var str: String = astEval(sourceString clone)
29+
return handlePrologCode(str, loc, ctx)
3330

3431
[ct] fun handlePrologCode(code: @String, location: meta.Location, context: meta.CompilationContext): meta.AstNode
35-
{
3632
//cout << "(" << location.startLineNo << ":" << location.startColNo << " - " << location.endLineNo << ":" << location.endColNo << ')' << endl << flush;
37-
var t: time.Timer;
38-
var errorReporter: CompilerErrorReporter;
39-
var lexer = mkLexer(code.all(), errorReporter, location);
40-
var parser = mkParser(lexer, errorReporter);
41-
var sps: SparrowPrologSystem = parser.parse();
42-
sps.semanticCheck();
33+
var t: time.Timer
34+
var errorReporter: CompilerErrorReporter
35+
var lexer = mkLexer(code.all(), errorReporter, location)
36+
var parser = mkParser(lexer, errorReporter)
37+
var sps: SparrowPrologSystem = parser.parse()
38+
sps.semanticCheck()
4339
//dumpProlog(cout, sps);
44-
var res = genProlog(sps);
45-
res setContext context;
46-
cout << "Elapsed: " << t.elapsed() << endl << flush;
47-
return res;
48-
}
40+
var res = genProlog(sps)
41+
res setContext context
42+
cout << "Elapsed: " << t.elapsed() << endl << flush
43+
return res
4944

5045
[ct] fun prologToString(source: @String): String
51-
{
52-
var errorReporter = mkConsoleErrorReporter(source.all());
53-
var lexer = mkLexer(source.all(), errorReporter);
54-
var parser = mkParser(lexer, errorReporter);
55-
var sps: SparrowPrologSystem = parser.parse();
56-
sps.semanticCheck();
57-
var ss: StringOutputStream;
58-
dumpProlog(ss, sps);
59-
return ss.result;
60-
}
46+
var errorReporter = mkConsoleErrorReporter(source.all())
47+
var lexer = mkLexer(source.all(), errorReporter)
48+
var parser = mkParser(lexer, errorReporter)
49+
var sps: SparrowPrologSystem = parser.parse()
50+
sps.semanticCheck()
51+
var ss: StringOutputStream
52+
dumpProlog(ss, sps)
53+
return ss.result
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import prolog;
2-
import meta.compiler;
1+
import prolog
2+
import meta.compiler
33

4-
[ct] var dummy1 = registerFrontendFun(".pl", "logic/prolog.spr:handlePrologCode");
4+
[ct] var dummy1 = registerFrontendFun(".pl", "logic/prolog.spr:handlePrologCode")

0 commit comments

Comments
 (0)