Skip to content

Commit

Permalink
slides on DSL
Browse files Browse the repository at this point in the history
  • Loading branch information
antonkolotaev committed Mar 4, 2014
1 parent 7ac8e73 commit 73c47b7
Show file tree
Hide file tree
Showing 21 changed files with 215 additions and 30 deletions.
Binary file modified doc/talks/07_03_2014.pdf
Binary file not shown.
17 changes: 17 additions & 0 deletions doc/talks/07_03_2014.tex
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,24 @@ \section{Introduction}
Previous definition is de-sugared at typing stage into

\includegraphics[width=1\linewidth]{macd_desugared.png}
\end{frame}
%------------------------------------------------
\begin{frame}
\frametitle{Class Inheritance}
Classes derive fields and methods from base classes.

Methods are treated as "virtual" to stimulate code re-use

\includegraphics[width=1\linewidth]{moments.png}
\end{frame}
%------------------------------------------------
\begin{frame}
\frametitle{Packages and Attributes}
Package are used to group functions and types. They can be nested. Attributes are inherited from enclosing package. Anonymous packages are used to assign same attributes to a group of functions without introducing a new name scope.

\includegraphics[width=1\linewidth]{packages.png}

In this sample \texttt{.A.B.f} will have attributes \texttt{X == "Xa", Y == "Y"} and \texttt{.A.B.g} and \texttt{.A.B.h} will have attributes \texttt{X == "Xb", Y == "Y"}

\end{frame}
%------------------------------------------------
Expand Down
Binary file added doc/talks/moments.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/talks/packages.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions marketsim/_pub/_test/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from marketsim.gen._out._test._a import A

import a
import in1
import types
import overloading
1 change: 1 addition & 0 deletions marketsim/_pub/_test/a/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import b
6 changes: 6 additions & 0 deletions marketsim/_pub/_test/a/b/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from marketsim.gen._out._test.a.b._f import f

from marketsim.gen._out._test.a.b._g import g

from marketsim.gen._out._test.a.b._h import h

22 changes: 21 additions & 1 deletion marketsim/gen/.output/names.sc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,25 @@ package event
@method = "N/A"
package _test
{
package A
{
@X = "X"
@Y = "Y"
package B
{
@X = "Xa"
def f() : () => .Float

@X = "Xb"
def g() : () => .Float

@X = "Xb"
def h() : () => .Float

}

}

package in1
{
package in2
Expand Down Expand Up @@ -385,7 +404,8 @@ package math
@python.mathops("atan")
def Atan(x = .constant(0.0)) : () => .Float

/** Observable that adds a lag to an observable data source so [Lagged(x, dt)]t=t0 == [x]t=t0+dt
/** Observable that adds a lag to an observable data source
* so Lagged(x, dt)(t0+dt) == x(t0)
*/
@python.intrinsic("observable.lagged.Lagged_Impl")
@label = "Lagged_{%(timeframe)s}(%(source)s)"
Expand Down
23 changes: 22 additions & 1 deletion marketsim/gen/.output/typed.sc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,26 @@ package event {
@method = "N/A"

package _test {
package A {@X = "X"
@Y = "Y"

package B {
@X = "Xa"

def f() : () => .Float

@X = "Xb"

def g() : () => .Float

@X = "Xb"

def h() : () => .Float
}

}


package in1 {
package in2 {

Expand Down Expand Up @@ -810,7 +830,8 @@ package math {
@python.accessor()
def Fast(x : Optional[.math.macd] = .math.macd()) : .Float

/** Observable that adds a lag to an observable data source so [Lagged(x, dt)]t=t0 == [x]t=t0+dt
/** Observable that adds a lag to an observable data source
* so Lagged(x, dt)(t0+dt) == x(t0)
*/
@label = "Lagged_{%(timeframe)s}(%(source)s)"

Expand Down
13 changes: 7 additions & 6 deletions marketsim/gen/.parsed/defs/math/rsi.pretty-printed.sc
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@

package math() {
// defined at defs\math\rsi.sc: 3.5
/** Observable that adds a lag to an observable data source so [Lagged(x, dt)]t=t0 == [x]t=t0+dt
/** Observable that adds a lag to an observable data source
* so Lagged(x, dt)(t0+dt) == x(t0)
*/
@python.intrinsic("observable.lagged.Lagged_Impl")
@label = "Lagged_{%(timeframe)s}(%(source)s)"
def Lagged(/** observable data source */ source = const(1.0),
/** lag size */ timeframe = 10.0) : IObservable[Float]

// defined at defs\math\rsi.sc: 11.5
// defined at defs\math\rsi.sc: 12.5
/** Returns positive movements of some observable *source* with lag *timeframe*
*/
@label = "Ups_{%(timeframe)s}(%(source)s)"
def UpMovements(/** observable data source */ source = const(1.0),
/** lag size */ timeframe = 10.0) = Max(0.0,source-source~>Lagged(timeframe))

// defined at defs\math\rsi.sc: 20.5
// defined at defs\math\rsi.sc: 21.5
/** Returns negative movements of some observable *source* with lag *timeframe*
*/
@label = "Downs_{%(timeframe)s}(%(source)s)"
Expand All @@ -27,17 +28,17 @@ package math() {
@label = "RSIRaw_{%(timeframe)s}^{%(alpha)s}(%(source)s)"
type RSI(/** observable data source */ source = .const(1.0),/** lag size */ timeframe = 10.0,/** alpha parameter for EWMA */ alpha = 0.015)
{
// defined at defs\math\rsi.sc: 39.13
// defined at defs\math\rsi.sc: 40.13
/** Absolute value for Relative Strength Index
*/
def Raw() = source~>UpMovements(timeframe)~>EW(alpha)~>Avg/source~>DownMovements(timeframe)~>EW(alpha)~>Avg

// defined at defs\math\rsi.sc: 46.13
// defined at defs\math\rsi.sc: 47.13
def Value() = 100.0-100.0/(1.0+Raw)
}
}

// defined at defs\math\rsi.sc: 51.5
// defined at defs\math\rsi.sc: 52.5
/** Log returns
*/
@label = "LogReturns_{%(timeframe)s}(%(x)s)"
Expand Down
3 changes: 2 additions & 1 deletion marketsim/gen/.parsed/defs/math/rsi.raw
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ Definitions:
| | | | | | | | | - List:
| | | | | - Some:
| | | | | | - DocString:
| | | | | | | - Observable that adds a lag to an observable data source so [Lagged(x, dt)]t=t0 == [x]t=t0+dt
| | | | | | | - Observable that adds a lag to an observable data source
| | | | | | | - List:
| | | | | | | | - so Lagged(x, dt)(t0+dt) == x(t0)
| | | | | - List:
| | | | | | - Annotation:
| | | | | | | - QualifiedName:
Expand Down
53 changes: 35 additions & 18 deletions marketsim/gen/.parsed/defs/trash.pretty-printed.sc
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
@category = "internal tests"
@method = "N/A"

package _test() {
package _test() {@X = "X"
@Y = "Y"

package A.B() {
// defined at defs\trash.sc: 8.5
@X = "Xa"
def f() : () => Float
@X = "Xb"

package () {
// defined at defs\trash.sc: 13.9
def g() : () => Float

// defined at defs\trash.sc: 14.9
def h() : () => Float
}
}

package types() {
type T1 = T

Expand All @@ -13,64 +30,64 @@ package _test() {
}

package overloading() {
// defined at defs\trash.sc: 17.5
// defined at defs\trash.sc: 30.5
def f(x : IFunction[Price]) = x

// defined at defs\trash.sc: 18.5
// defined at defs\trash.sc: 31.5
def f(x : IFunction[Volume]) = x

// defined at defs\trash.sc: 20.5
// defined at defs\trash.sc: 33.5
def g(x : IFunction[Volume]) = f(x)

// defined at defs\trash.sc: 22.5
// defined at defs\trash.sc: 35.5
def h() = f(12)

// defined at defs\trash.sc: 23.5
// defined at defs\trash.sc: 36.5
def hh() = f(12.2)
}

abstract package _base1() {
// defined at defs\trash.sc: 27.27
// defined at defs\trash.sc: 40.27
def toInject1() : () => Int
}

abstract package _base2() {
// defined at defs\trash.sc: 28.27
// defined at defs\trash.sc: 41.27
def toInject2() : () => Int
}

// defined at defs\trash.sc: 30.1
// defined at defs\trash.sc: 43.1
def A(x = in1.in2.A()) : () => types.R

package in1() extends _base1 extends _base2 {
// defined at defs\trash.sc: 33.1
// defined at defs\trash.sc: 46.1
def A(x : () => ._test.types.T1 = ._test.A()) : () => types.U

package in2() {
// defined at defs\trash.sc: 36.1
// defined at defs\trash.sc: 49.1
def A(x = constant(),
y = if 3>x+2 then x else x*2) : () => types.T

// defined at defs\trash.sc: 38.1
// defined at defs\trash.sc: 51.1
def S1(y = "abc") = y

// defined at defs\trash.sc: 40.1
// defined at defs\trash.sc: 53.1
def S2() : Optional[String] = S1()

// defined at defs\trash.sc: 42.1
// defined at defs\trash.sc: 55.1
def C(x : IFunction[ICandleStick],
p = 12) = p

// defined at defs\trash.sc: 44.1
// defined at defs\trash.sc: 57.1
def IntFunc() : IFunction[Int] = const(0)

// defined at defs\trash.sc: 46.1
// defined at defs\trash.sc: 59.1
def F(x = IntFunc() : IFunction[Float]) = x

// defined at defs\trash.sc: 48.1
// defined at defs\trash.sc: 61.1
def IntObs() : IObservable[Int] = const(0)

// defined at defs\trash.sc: 50.1
// defined at defs\trash.sc: 63.1
def O(x = IntObs() : IObservable[Float]) = x
}
}
Expand Down
74 changes: 74 additions & 0 deletions marketsim/gen/.parsed/defs/trash.raw
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,80 @@ Definitions:
| | | | | - Some:
| | | | | | - QualifiedName:
| | | | | | | - List:
| | | | | | | | - A
| | | | | | | | - B
| | | | | - List:
| | | | | - Definitions:
| | | | | | - List:
| | | | | | | - FunDef:
| | | | | | | | - f
| | | | | | | | - List:
| | | | | | | | - None
| | | | | | | | - Some:
| | | | | | | | | - FunctionType:
| | | | | | | | | | - List:
| | | | | | | | | | - SimpleType:
| | | | | | | | | | | - QualifiedName:
| | | | | | | | | | | | - List:
| | | | | | | | | | | | | - Float
| | | | | | | | | | | - List:
| | | | | | | | - None
| | | | | | | | - List:
| | | | | | | | | - Attribute:
| | | | | | | | | | - X
| | | | | | | | | | - Xa
| | | | | | | - PackageDef:
| | | | | | | | - None
| | | | | | | | - List:
| | | | | | | | - Definitions:
| | | | | | | | | - List:
| | | | | | | | | | - FunDef:
| | | | | | | | | | | - g
| | | | | | | | | | | - List:
| | | | | | | | | | | - None
| | | | | | | | | | | - Some:
| | | | | | | | | | | | - FunctionType:
| | | | | | | | | | | | | - List:
| | | | | | | | | | | | | - SimpleType:
| | | | | | | | | | | | | | - QualifiedName:
| | | | | | | | | | | | | | | - List:
| | | | | | | | | | | | | | | | - Float
| | | | | | | | | | | | | | - List:
| | | | | | | | | | | - None
| | | | | | | | | | | - List:
| | | | | | | | | | - FunDef:
| | | | | | | | | | | - h
| | | | | | | | | | | - List:
| | | | | | | | | | | - None
| | | | | | | | | | | - Some:
| | | | | | | | | | | | - FunctionType:
| | | | | | | | | | | | | - List:
| | | | | | | | | | | | | - SimpleType:
| | | | | | | | | | | | | | - QualifiedName:
| | | | | | | | | | | | | | | - List:
| | | | | | | | | | | | | | | | - Float
| | | | | | | | | | | | | | - List:
| | | | | | | | | | | - None
| | | | | | | | | | | - List:
| | | | | | | | - List:
| | | | | | | | | - Attribute:
| | | | | | | | | | - X
| | | | | | | | | | - Xb
| | | | | | | | - List:
| | | | | | | | - false
| | | | | - List:
| | | | | | - Attribute:
| | | | | | | - X
| | | | | | | - X
| | | | | | - Attribute:
| | | | | | | - Y
| | | | | | | - Y
| | | | | - List:
| | | | | - false
| | | | - PackageDef:
| | | | | - Some:
| | | | | | - QualifiedName:
| | | | | | | - List:
| | | | | | | | - types
| | | | | - List:
| | | | | - Definitions:
Expand Down
Empty file.
Empty file.
4 changes: 4 additions & 0 deletions marketsim/gen/_out/_test/a/b/_f.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def f():
from marketsim import rtti
return f_()
raise Exception('Cannot find suitable overload for f('++')')
4 changes: 4 additions & 0 deletions marketsim/gen/_out/_test/a/b/_g.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def g():
from marketsim import rtti
return g_()
raise Exception('Cannot find suitable overload for g('++')')
4 changes: 4 additions & 0 deletions marketsim/gen/_out/_test/a/b/_h.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def h():
from marketsim import rtti
return h_()
raise Exception('Cannot find suitable overload for h('++')')
2 changes: 1 addition & 1 deletion marketsim/gen/_out/math/_Lagged.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from marketsim.gen._out._iobservable._iobservablefloat import IObservablefloat
@registry.expose(["Basic", "Lagged"])
class Lagged_IObservableFloatFloat(Observablefloat,Lagged_Impl):
"""
""" so Lagged(x, dt)(t0+dt) == x(t0)
"""
def __init__(self, source = None, timeframe = None):
from marketsim import deref_opt
Expand Down
5 changes: 3 additions & 2 deletions marketsim/gen/defs/math/rsi.sc
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package math
{
/**
* Observable that adds a lag to an observable data source so [Lagged(x, dt)]t=t0 == [x]t=t0+dt
* Observable that adds a lag to an observable data source
* so Lagged(x, dt)(t0+dt) == x(t0)
*/
@python.intrinsic("observable.lagged.Lagged_Impl")
@label = "Lagged_{%(timeframe)s}(%(source)s)"
def Lagged (/** observable data source */ source = const (1.),
def Lagged (/** observable data source */ source = const (1.),
/** lag size */ timeframe = 10.0) : IObservable[Float]

/**
Expand Down
Loading

0 comments on commit 73c47b7

Please sign in to comment.