Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tools support #85

Merged
merged 23 commits into from
Jun 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions .travis/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ echo "---------- Testing ----------"
cd ../tests

python test.py StdLib/RangesTest.spr --returnError
python test.py ../tools/formatTool.spr --returnError
python test.py --returnError
6 changes: 0 additions & 6 deletions SparrowImplicitLib/check.spr
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,18 @@ fun ()(this: @Gen, sizeHint: UInt): ValueType = _generator(sizeHint)

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



concept GenType(x) \
if typeOf(x.ValueType) == Type \
&& typeOf(x.isValid) == Bool \
&& typeOf(x(0)) == x.ValueType


//! Arbitrary prototype
//fun arbitrary(t: Type): t Gen

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


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


fun randBetween(min, max: Integer): commonType(typeOf(min), typeOf(max))
using T = commonType(typeOf(min), typeOf(max))
using RAND_MAX = 0x7fffffff
Expand Down Expand Up @@ -260,7 +255,6 @@ package _Impl
res.isTrivial = _pred(res.value)
return res


[initCtor]
datatype ClassifierRange(rangeType, predType: Type) \
if typeOf((#$predType)((#$rangeType front).value)) == String
Expand Down
5 changes: 0 additions & 5 deletions SparrowImplicitLib/logic/lRef.spr
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ concept LRefType(x) if (
&& isValid(x.reset(#$x.ValueType))
)


//using logicDebug = 1
//using logicRefDebug = 1


// A logical reference that contains strings
using LStr = LRef(String)

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


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


[protected]
fun dtor(this: @LRef)
[ct] if ( isValid(logicDebug) && isValid(logicRefDebug) )
Expand Down Expand Up @@ -181,7 +177,6 @@ package _Impl

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


fun mkPlusOp(l, r: @ValWrapper) = mkBinaryOp(l, r, _operPlus)
fun mkMinusOp(l, r: @ValWrapper) = mkBinaryOp(l, r, _operMinus)
fun mkMulOp(l, r: @ValWrapper) = mkBinaryOp(l, r, _operMul)
Expand Down
7 changes: 0 additions & 7 deletions SparrowImplicitLib/logic/predicates.spr
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ fun isSet(this: @Predicate) = predObj.isSet()

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


/// Logic equality: equality test + inference
fun eq(l, r: @AnyType) = _mkEq(mkValOrRef(l), mkValOrRef(r))
fun /=/(l, r: @AnyType) = _mkEq(mkValOrRef(l), mkValOrRef(r))
Expand All @@ -42,8 +41,6 @@ using oper_precedence_=/ = oper_precedence_== + 1
//setOperPrecedence("/=/", getOperPrecedence("==") + 1)
//setOperPrecedence("=/", getOperPrecedence("==") + 1)



/// Logic Disjunction
fun ||(l, r: @PredicateType) = OrRelation(-@typeOf(l), -@typeOf(r))(l, r)

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


datatype UnifyLR(leftType, rightType: Type) if ValWrapper(#$leftType) && ValWrapper(#$rightType)
using ValueType = Bool
using ValuePassType = Bool
Expand Down Expand Up @@ -139,7 +135,6 @@ fun ()(this: @UnifyLR): Bool

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


datatype OrRelation(leftPredicateType, rightPredicateType: Type)
using ValueType = Bool
using ValuePassType = Bool
Expand Down Expand Up @@ -225,8 +220,6 @@ fun ()(this: @AndRelation): Bool
return false
return false



datatype LFalse
;
fun ()(this: LFalse) = false
Expand Down
85 changes: 39 additions & 46 deletions SparrowImplicitLib/logic/prolog.spr
Original file line number Diff line number Diff line change
@@ -1,60 +1,53 @@
module logic.prolog;
module logic.prolog

import lRef;
import predicates;
import recurse;
import lRef
import predicates
import recurse

import prologImpl.nodes;
import prologImpl.lexer;
import prologImpl.parser;
import prologImpl.ir;
import prologImpl.sprCodeDump;
import prologImpl.codeGen;
import prologImpl.nodes
import prologImpl.lexer
import prologImpl.parser
import prologImpl.ir
import prologImpl.sprCodeDump
import prologImpl.codeGen

import meta = meta.nodeKinds;
import meta = meta.nodeKinds

import assert;
import time = time;
import assert
import time = time

[macro] fun compileProlog(sourceString: CompilerAstNode): CompilerAstNode
{
var sourceStr: meta.AstNode = sourceString;
var sourceStr: meta.AstNode = sourceString
[ct] if ( (sourceString nodeKind) != meta.nkSparrowExpLiteral )
meta.report("compileProlog should take a string literal as argument", (sourceStr location));
meta.report("compileProlog should take a string literal as argument", (sourceStr location))
return CompilerAstNode()
else
{
sourceStr semanticCheck;
var loc = sourceStr location;
var ctx = sourceStr context;
var str: String = astEval(sourceString clone);
return handlePrologCode(str, loc, ctx);
}
}
sourceStr semanticCheck
var loc = sourceStr location
var ctx = sourceStr context
var str: String = astEval(sourceString clone)
return handlePrologCode(str, loc, ctx)

[ct] fun handlePrologCode(code: @String, location: meta.Location, context: meta.CompilationContext): meta.AstNode
{
//cout << "(" << location.startLineNo << ":" << location.startColNo << " - " << location.endLineNo << ":" << location.endColNo << ')' << endl << flush;
var t: time.Timer;
var errorReporter: CompilerErrorReporter;
var lexer = mkLexer(code.all(), errorReporter, location);
var parser = mkParser(lexer, errorReporter);
var sps: SparrowPrologSystem = parser.parse();
sps.semanticCheck();
var t: time.Timer
var errorReporter: CompilerErrorReporter
var lexer = mkLexer(code.all(), errorReporter, location)
var parser = mkParser(lexer, errorReporter)
var sps: SparrowPrologSystem = parser.parse()
sps.semanticCheck()
//dumpProlog(cout, sps);
var res = genProlog(sps);
res setContext context;
cout << "Elapsed: " << t.elapsed() << endl << flush;
return res;
}
var res = genProlog(sps)
res setContext context
cout << "Elapsed: " << t.elapsed() << endl << flush
return res

[ct] fun prologToString(source: @String): String
{
var errorReporter = mkConsoleErrorReporter(source.all());
var lexer = mkLexer(source.all(), errorReporter);
var parser = mkParser(lexer, errorReporter);
var sps: SparrowPrologSystem = parser.parse();
sps.semanticCheck();
var ss: StringOutputStream;
dumpProlog(ss, sps);
return ss.result;
}
var errorReporter = mkConsoleErrorReporter(source.all())
var lexer = mkLexer(source.all(), errorReporter)
var parser = mkParser(lexer, errorReporter)
var sps: SparrowPrologSystem = parser.parse()
sps.semanticCheck()
var ss: StringOutputStream
dumpProlog(ss, sps)
return ss.result
6 changes: 3 additions & 3 deletions SparrowImplicitLib/logic/prologFrontend.spr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import prolog;
import meta.compiler;
import prolog
import meta.compiler

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