Skip to content

Commit

Permalink
Update Nim compiler, using more modern nimble features
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Felsing committed Dec 8, 2017
1 parent 5debc38 commit 989b529
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 24 deletions.
5 changes: 1 addition & 4 deletions brainfuck.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Package

version = "1.0"
version = "1.1"
author = "Dennis Felsing"
description = "A brainfuck interpreter and compiler"
license = "MIT"
Expand All @@ -12,6 +12,3 @@ bin = @["brainfuck"]

requires "nim >= 0.10.0"
requires "docopt >= 0.1.0"

task tests, "Run the Brainfuck tester":
exec "nim c -r tests/all"
18 changes: 4 additions & 14 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,22 @@ dependencies:
pre:
- |
if [ ! -x ~/nim/bin/nim ]; then
git clone -b devel --depth 1 git://github.com/araq/nim ~/nim/
git clone -b devel --depth 1 git://github.com/nim-lang/Nim ~/nim/
git clone -b devel --depth 1 git://github.com/nim-lang/csources ~/nim/csources/
cd ~/nim/csources; sh build.sh; cd ..; rm -rf csources
ln -fs ~/nim/bin/nim ~/bin/nim
bin/nim c koch; ./koch boot -d:release
bin/nim c koch; ./koch boot -d:release; ./koch nimble
else
cd ~/nim; git fetch origin
git merge FETCH_HEAD | grep "Already up-to-date" || (bin/nim c koch; ./koch boot -d:release)
fi
if [ ! -x ~/nimble ]; then
git clone --depth 1 https://github.com/nim-lang/nimble ~/nimble/
cd ~/nimble
nim -d:release c -r src/nimble -y install
ln -fs ~/.nimble/bin/nimble ~/bin/nimble
else
cd ~/nimble; git fetch origin
git merge FETCH_HEAD | grep "Already up-to-date" || (nim -d:release c -r src/nimble -y install)
git merge FETCH_HEAD | grep "Already up-to-date" || (bin/nim c koch; ./koch boot -d:release; ./koch nimble)
fi
cache_directories:
- "~/bin/"
- "~/nim/"
- "~/nimble/"
- "~/.nimble/"

## Customize test commands
test:
override:
- nimble tests
- nimble test
10 changes: 5 additions & 5 deletions src/brainfuck.nim
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ import macros
proc compile(code, input, output: string): NimNode {.compiletime.} =
var stmts = @[newStmtList()]

template addStmt(text): stmt =
template addStmt(text): typed =
stmts[stmts.high].add parseStmt(text)

addStmt """
Expand Down Expand Up @@ -137,21 +137,21 @@ proc compile(code, input, output: string): NimNode {.compiletime.} =
result = stmts[0]
#echo result.repr

macro compileString*(code: string; input, output: expr): stmt =
macro compileString*(code: string; input, output: untyped): typed =
## Compiles the brainfuck code read from `filename` at compile time into Nim
## code that reads from the `input` variable and writes to the `output`
## variable, both of which have to be strings.
result = compile($code,
"newStringStream(" & $input & ")", "newStringStream()")
result.add parseStmt($output & " = outStream.data")

macro compileString*(code: string): stmt =
macro compileString*(code: string): typed =
## Compiles the brainfuck `code` string into Nim code that reads from stdin
## and writes to stdout.
echo code
compile($code, "stdin.newFileStream", "stdout.newFileStream")

macro compileFile*(filename: string; input, output: expr): stmt =
macro compileFile*(filename: string; input, output: untyped): typed =
## Compiles the brainfuck code read from `filename` at compile time into Nim
## code that reads from the `input` variable and writes to the `output`
## variable, both of which have to be strings.
Expand All @@ -166,7 +166,7 @@ macro compileFile*(filename: string; input, output: expr): stmt =
"newStringStream(" & $input & ")", "newStringStream()")
result.add parseStmt($output & " = outStream.data")

macro compileFile*(filename: string): stmt =
macro compileFile*(filename: string): typed =
## Compiles the brainfuck code read from `filename` at compile time into Nim
## code that reads from stdin and writes to stdout.
##
Expand Down
1 change: 0 additions & 1 deletion tests/all.nim

This file was deleted.

0 comments on commit 989b529

Please sign in to comment.