Skip to content

Commit 10bc4a8

Browse files
committed
0.0.4 release
1 parent ac7d861 commit 10bc4a8

73 files changed

Lines changed: 1287 additions & 279 deletions

Some content is hidden

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

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
secret/
22
bin/
3+
*.so
4+
*.h

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
[![Build Status](https://travis-ci.org/spatialcurrent/go-dfl.svg)](https://travis-ci.org/spatialcurrent/go-dfl) [![Go Report Card](https://goreportcard.com/badge/spatialcurrent/go-dfl)](https://goreportcard.com/report/spatialcurrent/go-dfl) [![GoDoc](https://godoc.org/github.com/spatialcurrent/go-dfl?status.svg)](https://godoc.org/github.com/spatialcurrent/go-dfl) [![license](http://img.shields.io/badge/license-MIT-red.svg?style=flat)](https://github.com/go-spatial/tegola/blob/master/LICENSE.md)
1+
[![Build Status](https://travis-ci.org/spatialcurrent/go-dfl.svg)](https://travis-ci.org/spatialcurrent/go-dfl) [![Go Report Card](https://goreportcard.com/badge/spatialcurrent/go-dfl)](https://goreportcard.com/report/spatialcurrent/go-dfl) [![GoDoc](https://godoc.org/github.com/spatialcurrent/go-dfl?status.svg)](https://godoc.org/github.com/spatialcurrent/go-dfl) [![license](http://img.shields.io/badge/license-MIT-red.svg?style=flat)](https://github.com/spatialcurrent/go-dfl/blob/master/LICENSE.md)
22

33
# go-dfl
44

55
# Description
66

77
**go-dfl** is a Go implementation of the Dynamic Filter Language (DFL).
88

9+
Using cross compilers, this library can also be called by other languages. This library is cross compiled into a Shared Object file (`*.so`). The Shared Object file can be called by `C`, `C++`, and `Python` on Linux machines. See the examples folder for patterns that you can use. This library is also compiled to pure `JavaScript` using [GopherJS](https://github.com/gopherjs/gopherjs).
10+
911
# Usage
1012

1113
**CLI**
@@ -55,6 +57,16 @@ import (
5557
</html>
5658
```
5759

60+
**C**
61+
62+
A variant of the `EvaluateBool` function is exported in a Shared Object file (`*.so`), which can be called by `C`, `C++`, and `Python` programs on Linux machines. For example:
63+
64+
```
65+
err = EvaluateBool(expression, size, ctx, &result);
66+
```
67+
68+
The Go function definition defined in `plugins/dfl/main.go` takes in the expression and context. For complete patterns for `C`, `C++`, and `Python`, see the `examples`.
69+
5870
# Examples:
5971

6072
**Environment**
@@ -124,6 +136,10 @@ The command line DFL program can be built with the `scripts/build_cli.sh` script
124136

125137
You can compile DFL to pure JavaScript with the `scripts/build_javascript.sh` script.
126138

139+
**Shared Object**
140+
141+
The `build_so.sh` script is used to build a Shared Object (`*.go`), which can be called by `C`, `C++`, and `Python` on Linux machines.
142+
127143
# Contributing
128144

129145
[Spatial Current, Inc.](https://spatialcurrent.io) is currently accepting pull requests for this repository. We'd love to have your contributions! Please see [Contributing.md](https://github.com/spatialcurrent/go-dfl/blob/master/CONTRIBUTING.md) for how to get started.

cmd/dfl.js/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
"honnef.co/go/js/console"
2727
)
2828

29-
var GO_DFL_VERSION = "0.0.3"
29+
var GO_DFL_VERSION = "0.0.4"
3030

3131
type Node struct {
3232
Node dfl.Node

cmd/dfl/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import (
4444
"github.com/spatialcurrent/go-dfl/dfl"
4545
)
4646

47-
var GO_DFL_VERSION = "0.0.3"
47+
var GO_DFL_VERSION = "0.0.4"
4848

4949
func main() {
5050

dfl/Add.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (a Add) Compile() Node {
3636
case Literal:
3737
switch right.(type) {
3838
case Literal:
39-
v, err := AddNumbers(left.(Literal).Value, right.(Literal).Value)
39+
v, err := AddValues(left.(Literal).Value, right.(Literal).Value)
4040
if err != nil {
4141
panic(err)
4242
}
@@ -47,14 +47,14 @@ func (a Add) Compile() Node {
4747
}
4848

4949
// Evaluate returns the value of this node given Context ctx, and an error if any.
50-
func (a Add) Evaluate(ctx Context, funcs FunctionMap) (interface{}, error) {
50+
func (a Add) Evaluate(ctx interface{}, funcs FunctionMap) (interface{}, error) {
5151

5252
lv, rv, err := a.EvaluateLeftAndRight(ctx, funcs)
5353
if err != nil {
5454
return 0, err
5555
}
5656

57-
v, err := AddNumbers(lv, rv)
57+
v, err := AddValues(lv, rv)
5858
if err != nil {
5959
return 0, err
6060
}

dfl/AddValues.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// =================================================================
2+
//
3+
// Copyright (C) 2018 Spatial Current, Inc. - All Rights Reserved
4+
// Released as open source under the MIT License. See LICENSE file.
5+
//
6+
// =================================================================
7+
8+
package dfl
9+
10+
import (
11+
"fmt"
12+
"reflect"
13+
)
14+
15+
import (
16+
"github.com/pkg/errors"
17+
)
18+
19+
// AddValues adds 2 values and returns the result.
20+
// The parameters can be an int, int64, float64, string, or []byte.
21+
// The parameters will be cast as applicable.
22+
// For example you can add two integers with
23+
// total := AddNumbers(1, 2)
24+
// or you could add an int with a float64.
25+
// total := AddNumbers(1.54345345, 5)
26+
func AddValues(a interface{}, b interface{}) (interface{}, error) {
27+
switch a.(type) {
28+
case string:
29+
switch b.(type) {
30+
case string:
31+
return a.(string) + b.(string), nil
32+
}
33+
case []byte:
34+
a_bytes := a.([]byte)
35+
switch b.(type) {
36+
case []byte:
37+
b_bytes := b.([]byte)
38+
return append(append(make([]byte, 0, len(a_bytes)+len(b_bytes)), a_bytes...), b_bytes...), nil
39+
}
40+
case int:
41+
switch b.(type) {
42+
case int:
43+
return a.(int) + b.(int), nil
44+
case int64:
45+
return int64(a.(int)) + b.(int64), nil
46+
case float64:
47+
return float64(a.(int)) + b.(float64), nil
48+
}
49+
case int64:
50+
switch b.(type) {
51+
case int:
52+
return a.(int64) + int64(b.(int)), nil
53+
case int64:
54+
return a.(int64) + b.(int64), nil
55+
case float64:
56+
return float64(a.(int64)) + b.(float64), nil
57+
}
58+
case float64:
59+
switch b.(type) {
60+
case int:
61+
return a.(float64) + float64(b.(int)), nil
62+
case int64:
63+
return a.(float64) + float64(b.(int64)), nil
64+
case float64:
65+
return a.(float64) + b.(float64), nil
66+
}
67+
}
68+
69+
return 0, errors.New(fmt.Sprintf("Error adding values %#v (%v) and %#v (%v)", a, reflect.TypeOf(a).String(), b, reflect.TypeOf(b).String()))
70+
}

dfl/Add_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818

1919
func TestAdd(t *testing.T) {
2020

21-
ctx := Context{"a": 2, "b": 3.0}
21+
ctx := map[string]interface{}{"a": 2, "b": 3.0}
2222

2323
testCases := []TestCase{
2424
NewTestCase("2 + 7", ctx, 9),

dfl/After.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (a After) Compile() Node {
4242
return After{&TemporalBinaryOperator{&BinaryOperator{Left: left, Right: right}}}
4343
}
4444

45-
func (a After) Evaluate(ctx Context, funcs FunctionMap) (interface{}, error) {
45+
func (a After) Evaluate(ctx interface{}, funcs FunctionMap) (interface{}, error) {
4646

4747
v, err := a.EvaluateAndCompare(ctx, funcs)
4848
if err != nil {

dfl/After_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919

2020
func TestAfter(t *testing.T) {
2121

22-
ctx := Context{
22+
ctx := map[string]interface{}{
2323
"a": time.Date(2018, time.April, 2, 3, 28, 56, 0, time.UTC),
2424
"b": time.Date(2018, time.May, 2, 3, 28, 56, 0, time.UTC),
2525
}

dfl/And.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (a And) Compile() Node {
5050
return And{&BinaryOperator{Left: left, Right: right}}
5151
}
5252

53-
func (a And) Evaluate(ctx Context, funcs FunctionMap) (interface{}, error) {
53+
func (a And) Evaluate(ctx interface{}, funcs FunctionMap) (interface{}, error) {
5454
lv, err := a.Left.Evaluate(ctx, funcs)
5555
if err != nil {
5656
return false, err

0 commit comments

Comments
 (0)