aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Dessaux2021-09-30 21:41:27 +0200
committerJulien Dessaux2021-09-30 21:41:27 +0200
commit9a5ff5f233e1874860e4ce834e9a8a58ad7eda85 (patch)
tree0cdecd45439510a6183f148490a73a36daca1f7d
parentInitial import (diff)
downloadnimfunge98-9a5ff5f233e1874860e4ce834e9a8a58ad7eda85.tar.gz
nimfunge98-9a5ff5f233e1874860e4ce834e9a8a58ad7eda85.tar.bz2
nimfunge98-9a5ff5f233e1874860e4ce834e9a8a58ad7eda85.zip
Began implementing the funge field
Diffstat (limited to '')
-rw-r--r--README.md64
-rw-r--r--nimfunge98.nimble24
-rw-r--r--src/field.nim37
-rw-r--r--src/nimfunge98.nim5
-rw-r--r--tests/config.nims2
-rw-r--r--tests/testField.nim3
6 files changed, 135 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..7c29829
--- /dev/null
+++ b/README.md
@@ -0,0 +1,64 @@
+# NimFunge98 : a Funge-98 interpreter written in nim
+
+This repository contains code for a nim program that can interpret a valid [Funge-98](https://github.com/catseye/Funge-98/blob/master/doc/funge98.markdown) program. It will soon pass the [mycology test suite](https://github.com/Deewiant/Mycology).
+
+Current limitations are :
+- it is not finished!
+- currently does not implement any fingerprints
+- does not implement concurrent execution with the `t` command
+- does not implement file I/O with the `i` and `o` commands
+- does not implement system execution with the `=` command
+
+## Contents
+
+- [Dependencies](#dependencies)
+- [Quick install](#quick-install)
+- [Usage](#usage)
+- [Building](#building)
+
+## Dependencies
+
+nim is required. Only nim version >= 1.4.8 on linux amd64 (Gentoo) is being regularly tested.
+
+## Quick Install
+
+To install, clone this repository then run :
+```
+nimble install
+```
+
+## Usage
+
+Launching the interpreter is as simple as :
+```
+nimfunge98 -f something.b98
+```
+
+The interpreter will then load and execute the specified Funge-98 program until the program normally terminates or is interrupted or killed.
+
+## Building
+
+For a debug build, use :
+```
+nimble build
+```
+
+For a release build, use :
+```
+nimble build -d:release
+```
+
+To run unit tests, use :
+```
+nimble tests
+```
+
+To run integration tests, use :
+```
+nimble integration
+```
+
+To calculate the code coverage of tests, use :
+```
+nimble coverage
+```
diff --git a/nimfunge98.nimble b/nimfunge98.nimble
new file mode 100644
index 0000000..e860c43
--- /dev/null
+++ b/nimfunge98.nimble
@@ -0,0 +1,24 @@
+# Package
+
+version = "0.1.0"
+author = "Julien Dessaux"
+description = "A Funge-98 interpreter written in nim"
+license = "EUPL-1.2"
+srcDir = "src"
+bin = @["nimfunge98"]
+
+# Dependencies
+
+requires "nim >= 1.4.8"
+
+# Tasks
+
+task integration, "Runs the test suite":
+ exec "testament all"
+
+task coverage, "Run all tests and calculate coverage":
+ exec "coco --target 'tests/**/*.nim' --cov '!tests,!nimcache'"
+
+task clean, "Clean":
+ exec "rm -rf coverage lcov.info nimcache"
+ exec "rm -rf outputGotten.txt testresults tests/megatest tests/megatest.nim"
diff --git a/src/field.nim b/src/field.nim
new file mode 100644
index 0000000..a9d26fc
--- /dev/null
+++ b/src/field.nim
@@ -0,0 +1,37 @@
+type
+ Line = ref object
+ x, l: int
+ columns: seq[int]
+
+ Field* = ref object
+ x, y: int
+ lx, ly: int
+ lines: seq[Line]
+
+proc get*(f: Field, x, y: int): int =
+ if y >= f.y and y < f.y + f.ly:
+ let l = f.lines[y-f.y]
+ if x >= l.x and x < l.x + l.l:
+ return l.columns[x-l.x]
+ return int(' ')
+
+proc isIn*(f: Field, x, y: int): bool =
+ return x >= f.x and y >= f.y and x < f.x+f.lx and y < f.y+f.ly
+
+when defined(unitTesting):
+ let minimal = Field(
+ x: 0,
+ y: 0,
+ lx: 1,
+ ly: 1,
+ lines: @[
+ Line(x: 0, l: 1, columns: @[int('@')])
+ ]
+ )
+ suite "Field":
+ test "Field.get":
+ check minimal.get(0,0) == int('@')
+ check minimal.get(1,0) == int(' ')
+ test "Field.isIn":
+ check minimal.isIn(0, 0) == true
+ check minimal.isIn(1, 0) == false
diff --git a/src/nimfunge98.nim b/src/nimfunge98.nim
new file mode 100644
index 0000000..e8f1ce4
--- /dev/null
+++ b/src/nimfunge98.nim
@@ -0,0 +1,5 @@
+import nimfunge98/field/field
+
+let f:Field
+
+echo f.get(3,2) \ No newline at end of file
diff --git a/tests/config.nims b/tests/config.nims
new file mode 100644
index 0000000..ca28db4
--- /dev/null
+++ b/tests/config.nims
@@ -0,0 +1,2 @@
+switch("path", "$projectDir/../src")
+switch("define", "unitTesting")
diff --git a/tests/testField.nim b/tests/testField.nim
new file mode 100644
index 0000000..74400b8
--- /dev/null
+++ b/tests/testField.nim
@@ -0,0 +1,3 @@
+import unittest
+
+include field