Skip to content

Commit

Permalink
Fix for #6
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaferretti committed Jun 1, 2016
1 parent de88c97 commit 6a3ae64
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
nimcache
/test
/test
*.ndb
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ A couple of limitations fo the `variant` macro:

In the future, Patty may also add copy constructors. Also, some work needs to be done to make it easier to use the generated contructors with `ref` types, in particular for the important case of recursive algebraic data types.

Versions
--------

Patty 0.1.8 works for latest Nim (devel). For older versions of Nim (up to 0.13.0),
use Patty 0.1.7.

Things that do not work (yet)
-----------------------------

Expand Down
12 changes: 7 additions & 5 deletions patty.nim
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,13 @@ macro variantp*(e: expr, body: stmt): stmt {. immediate .} =


proc isObject(tp: NimNode): bool {. compileTime .} =
(tp.kind == nnkObjectTy) and (tp[1][0].kind != nnkRecCase)
(tp.kind == nnkObjectTy) and (tp[2][0].kind != nnkRecCase)

proc isVariant(tp: NimNode): bool {. compileTime .} =
(tp.kind == nnkObjectTy) and (tp[1][0].kind == nnkRecCase)
(tp.kind == nnkObjectTy) and (tp[2][0].kind == nnkRecCase)

proc discriminator(tp: NimNode): NimNode {. compileTime .} =
if (tp.kind == nnkObjectTy) and (tp[1][0].kind == nnkRecCase): tp[1][0][0]
if (tp.kind == nnkObjectTy) and (tp[2][0].kind == nnkRecCase): tp[2][0][0]
else: nil

proc variants(tp: NimNode): seq[NimNode] {. compileTime .} =
Expand All @@ -215,6 +215,7 @@ proc resolveSymbol(id: NimNode, syms: seq[NimNode]): tuple[index: int, sym: NimN
proc findFields(tp: NimNode, index: int): seq[NimNode] {. compileTime .} =
# ObjectTy
# Empty
# Empty
# RecList
# RecCase
# Sym "kind"
Expand All @@ -234,7 +235,7 @@ proc findFields(tp: NimNode, index: int): seq[NimNode] {. compileTime .} =
# RecList
# Sym "side"
let
recCase = tp[1][0]
recCase = tp[2][0]
branch = recCase[index + 1]
recList = branch[1]
result = @[]
Expand All @@ -244,11 +245,12 @@ proc findFields(tp: NimNode, index: int): seq[NimNode] {. compileTime .} =
proc findFields(tp: NimNode): seq[NimNode] {. compileTime .} =
# ObjectTy
# Empty
# Empty
# RecList
# Sym "name"
# Sym "surname"
# Sym "age"
let recList = tp[1]
let recList = tp[2]
result = @[]
for c in recList.children:
result.add(c)
Expand Down
22 changes: 16 additions & 6 deletions patty.nimble
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
[Package]
name = "patty"
version = "0.1.7"
mode = ScriptMode.Verbose

version = "0.1.8"
author = "Andrea Ferretti"
description = "Algebraic data types and pattern matching"
license = "Apache2"
SkipFiles = "test,test.nim,testhelp.nim"
skipFiles = @["test", "test.nim", "testhelp.nim"]

requires "nim >= 0.11.2"


[Deps]
Requires: "nim >= 0.11.2"
task tests, "run tests":
--hints: off
--linedir: on
--stacktrace: on
--linetrace: on
--debuginfo
--path: "."
--run
setCommand "c", "test"

0 comments on commit 6a3ae64

Please sign in to comment.