nydp 0.0.9 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/lisp/boot.nydp +23 -18
- data/lib/lisp/tests/boot-tests.nydp +27 -1
- data/lib/lisp/tests/foundation-test.nydp +4 -0
- data/lib/nydp.rb +7 -3
- data/lib/nydp/builtin/error.rb +1 -2
- data/lib/nydp/date.rb +1 -0
- data/lib/nydp/interpreted_function.rb +1 -1
- data/lib/nydp/runner.rb +17 -9
- data/lib/nydp/symbol.rb +0 -1
- data/lib/nydp/version.rb +1 -1
- data/lib/nydp/vm.rb +10 -8
- data/spec/date_spec.rb +1 -0
- data/spec/error_spec.rb +19 -0
- data/spec/nydp_spec.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 878f0dba9573b146bf3bf438d5c8d7792f9fc1e9
|
4
|
+
data.tar.gz: 57c14a21f93ec56968f9f4e3bae5ee634eac9608
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f8fa342fe36104a3d957bb3bd354b79f185948fc9779abd7c146dbe092065a29ad31cb4193ae8a8aeded94b4a4671c3075d05e9a112404dde554dbbe1887290
|
7
|
+
data.tar.gz: 6999b8761df3c3d19909d0341d208b08fb9793e926066838ab99329c6b87fece28dd085e56ba82970e96ebbd10a439137ce76b12f6513c853fd83f09eb7dbbff
|
data/lib/lisp/boot.nydp
CHANGED
@@ -23,7 +23,6 @@
|
|
23
23
|
(assign cddr (fn (arg) (cdr (cdr arg))))
|
24
24
|
(assign no (fn (arg) (cond arg nil t)))
|
25
25
|
(assign just (fn (arg) arg))
|
26
|
-
(assign pargs (fn args (apply p args) (last args)))
|
27
26
|
|
28
27
|
(assign mac-expand (fn (macfn name body)
|
29
28
|
(cond macfn
|
@@ -32,12 +31,6 @@
|
|
32
31
|
|
33
32
|
(assign macs (hash))
|
34
33
|
|
35
|
-
(assign debug-pre-compile
|
36
|
-
(fn (arg)
|
37
|
-
(assign *debug-pre-compile* arg)))
|
38
|
-
|
39
|
-
(assign *debug-pre-compile* nil)
|
40
|
-
|
41
34
|
(assign pre-compile-expr
|
42
35
|
(fn (name body)
|
43
36
|
(mac-expand (hash-get macs name) name body)))
|
@@ -51,18 +44,27 @@
|
|
51
44
|
args))))
|
52
45
|
|
53
46
|
(assign pre-compile-msg
|
54
|
-
(fn
|
55
|
-
(
|
56
|
-
|
47
|
+
(fn (src compiled)
|
48
|
+
(pre-compile-msg "pre-compile" src "\n -> " compiled)
|
49
|
+
compiled))
|
50
|
+
|
51
|
+
(assign pre-compile-raw
|
52
|
+
(fn (arg)
|
53
|
+
(cond (pair? arg)
|
54
|
+
(cond (eq? (car arg) 'quote)
|
55
|
+
arg
|
56
|
+
(pre-compile-each (pre-compile-expr (car arg) (cdr arg))))
|
57
|
+
arg)))
|
57
58
|
|
58
|
-
(assign pre-compile
|
59
|
+
(assign pre-compile-debug
|
59
60
|
(fn (arg)
|
60
|
-
(pre-compile-msg
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
61
|
+
(pre-compile-msg arg (pre-compile-raw arg))))
|
62
|
+
|
63
|
+
(assign debug-pre-compile
|
64
|
+
(fn (arg)
|
65
|
+
(assign pre-compile (cond arg pre-compile-debug pre-compile-raw))))
|
66
|
+
|
67
|
+
(debug-pre-compile nil)
|
66
68
|
|
67
69
|
(hash-set macs 'def
|
68
70
|
(fn (name args . body)
|
@@ -151,6 +153,9 @@
|
|
151
153
|
`(cond ,(car args) ,(cadr args)))
|
152
154
|
(car args))))
|
153
155
|
|
156
|
+
(mac unless (arg . body)
|
157
|
+
`(if (no ,arg) (do ,@body)))
|
158
|
+
|
154
159
|
(def expand-colon-syntax (first rest)
|
155
160
|
(if (no rest)
|
156
161
|
`(apply ,first args)
|
@@ -351,7 +356,7 @@
|
|
351
356
|
(def dot-syntax-assignment (names value-expr)
|
352
357
|
(let rnames (rev names)
|
353
358
|
`(hash-set ,(build-hash-getters (rev (cdr rnames)) nil)
|
354
|
-
|
359
|
+
,(build-hash-get-key:car rnames)
|
355
360
|
,value-expr)))
|
356
361
|
|
357
362
|
(mac = (name value)
|
@@ -31,6 +31,31 @@
|
|
31
31
|
|
32
32
|
(register-test
|
33
33
|
'(suite "Boot Tests"
|
34
|
+
(suite "conditionals"
|
35
|
+
("single-expr 'if is just the expr"
|
36
|
+
(pre-compile '(if a))
|
37
|
+
a)
|
38
|
+
|
39
|
+
("two-expr 'if expands to 'cond"
|
40
|
+
(pre-compile '(if a b))
|
41
|
+
(cond a b))
|
42
|
+
|
43
|
+
("three-expr 'if expands to 'cond"
|
44
|
+
(pre-compile '(if a b c))
|
45
|
+
(cond a b c))
|
46
|
+
|
47
|
+
("four-expr 'if expands to nested 'cond"
|
48
|
+
(pre-compile '(if a b c d))
|
49
|
+
(cond a b (cond c d)))
|
50
|
+
|
51
|
+
("five-expr 'if expands to nested 'cond"
|
52
|
+
(pre-compile '(if a b c d e))
|
53
|
+
(cond a b (cond c d e)))
|
54
|
+
|
55
|
+
("'unless expands to 'if"
|
56
|
+
(pre-compile '(unless x y z))
|
57
|
+
(cond (no x) ((fn () y z)))))
|
58
|
+
|
34
59
|
(suite "hashtables"
|
35
60
|
("build a hash table from brace-list syntax"
|
36
61
|
(let hsh { foo 1 bar 2 }
|
@@ -111,7 +136,8 @@
|
|
111
136
|
(suite "mapx"
|
112
137
|
("provides a convenient simplification for 'map"
|
113
138
|
(mapx '(1 2 3 4) n (* n 2))
|
114
|
-
(2 4 6 8)))
|
139
|
+
(2 4 6 8))))
|
140
|
+
|
115
141
|
|
116
142
|
(suite "pre-compile"
|
117
143
|
(suite "bang-syntax"
|
@@ -88,6 +88,10 @@
|
|
88
88
|
(pre-compile '(= a.b 42))
|
89
89
|
(hash-set a 'b 42))
|
90
90
|
|
91
|
+
("hash assignment with unquote"
|
92
|
+
(pre-compile '(= a.,b 42))
|
93
|
+
(hash-set a b 42))
|
94
|
+
|
91
95
|
("recursive hash assignment"
|
92
96
|
(pre-compile '(= a.b.c.d 42))
|
93
97
|
(hash-set (hash-get (hash-get a 'b) 'c) 'd 42))
|
data/lib/nydp.rb
CHANGED
@@ -24,12 +24,16 @@ module Nydp
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def self.apply_function ns, function_name, *args
|
27
|
-
function =
|
28
|
-
args =
|
27
|
+
function = r2n(function_name.to_sym, ns).value
|
28
|
+
args = r2n args, ns
|
29
29
|
vm = VM.new
|
30
30
|
|
31
31
|
function.invoke vm, args
|
32
|
-
|
32
|
+
vm.thread
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.eval_src ns, src_txt
|
36
|
+
Nydp::Runner.new(VM.new, ns, Nydp::StringReader.new(src_txt)).run
|
33
37
|
end
|
34
38
|
|
35
39
|
def self.repl
|
data/lib/nydp/builtin/error.rb
CHANGED
data/lib/nydp/date.rb
CHANGED
data/lib/nydp/runner.rb
CHANGED
@@ -47,14 +47,12 @@ module Nydp
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def compile_and_eval expr
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
if e
|
50
|
+
begin
|
51
|
+
vm.thread Pair.new(Compiler.compile(expr, Nydp.NIL), Nydp.NIL)
|
52
|
+
rescue Exception => e
|
54
53
|
new_msg = "failed to eval #{expr.inspect}\nerror was #{Nydp.indent_text e.message}"
|
55
54
|
raise e.class, new_msg, e.backtrace
|
56
55
|
end
|
57
|
-
result
|
58
56
|
end
|
59
57
|
|
60
58
|
def quote expr
|
@@ -86,6 +84,13 @@ module Nydp
|
|
86
84
|
@printer.puts val.inspect if @printer
|
87
85
|
end
|
88
86
|
|
87
|
+
def handle_run_error e
|
88
|
+
puts e.message
|
89
|
+
e.backtrace.each do |b|
|
90
|
+
puts b
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
89
94
|
def run
|
90
95
|
res = Nydp.NIL
|
91
96
|
while !@tokens.finished
|
@@ -94,14 +99,17 @@ module Nydp
|
|
94
99
|
begin
|
95
100
|
print(res = evaluate(expr))
|
96
101
|
rescue Exception => e
|
97
|
-
|
98
|
-
e.backtrace.each do |b|
|
99
|
-
puts b
|
100
|
-
end
|
102
|
+
handle_run_error e
|
101
103
|
end
|
102
104
|
end
|
103
105
|
end
|
104
106
|
res
|
105
107
|
end
|
106
108
|
end
|
109
|
+
|
110
|
+
class ExplodeRunner < Runner
|
111
|
+
def handle_run_error e
|
112
|
+
raise e
|
113
|
+
end
|
114
|
+
end
|
107
115
|
end
|
data/lib/nydp/symbol.rb
CHANGED
data/lib/nydp/version.rb
CHANGED
data/lib/nydp/vm.rb
CHANGED
@@ -10,11 +10,11 @@ module Nydp
|
|
10
10
|
@instructions = []
|
11
11
|
@args = []
|
12
12
|
@contexts = []
|
13
|
-
@locals =
|
13
|
+
@locals = Nydp::Hash.new
|
14
14
|
end
|
15
15
|
|
16
|
-
def thread expr
|
17
|
-
instructions.push expr
|
16
|
+
def thread expr=nil
|
17
|
+
instructions.push expr if expr
|
18
18
|
while instructions.length > 0
|
19
19
|
begin
|
20
20
|
self.current_context = contexts.last
|
@@ -26,6 +26,7 @@ module Nydp
|
|
26
26
|
handle_error e
|
27
27
|
end
|
28
28
|
end
|
29
|
+
raise unhandled_error if unhandled_error
|
29
30
|
pop_arg
|
30
31
|
end
|
31
32
|
|
@@ -50,11 +51,12 @@ module Nydp
|
|
50
51
|
end
|
51
52
|
end
|
52
53
|
|
53
|
-
def peek_context;
|
54
|
-
def pop_context;
|
55
|
-
def push_arg a;
|
56
|
-
def
|
57
|
-
def
|
54
|
+
def peek_context ; current_context ; end
|
55
|
+
def pop_context ; contexts.pop ; end
|
56
|
+
def push_arg a ; args.push a ; end
|
57
|
+
def args! ; args.empty? ? (raise "illegal operation: no args") : args ; end
|
58
|
+
def peek_arg ; args!.last ; end
|
59
|
+
def pop_arg ; args!.pop ; end
|
58
60
|
|
59
61
|
def push_instructions ii, ctx
|
60
62
|
instructions.push ii
|
data/spec/date_spec.rb
CHANGED
@@ -11,6 +11,7 @@ describe Nydp::Date do
|
|
11
11
|
expect(nd). to be_a Nydp::Date
|
12
12
|
expect(nd.to_s). to eq "2015-06-08"
|
13
13
|
expect(nd.inspect).to eq "#<Date: 2015-06-08 ((2457182j,0s,0n),+0s,2299161j)>"
|
14
|
+
expect(nd.to_ruby).to eq Date.parse("2015-06-08")
|
14
15
|
end
|
15
16
|
|
16
17
|
it "returns date components" do
|
data/spec/error_spec.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Nydp::VM do
|
4
|
+
let(:ns) { { } }
|
5
|
+
let(:vm) { Nydp::VM.new }
|
6
|
+
|
7
|
+
def run txt
|
8
|
+
Nydp.setup ns
|
9
|
+
Nydp::ExplodeRunner.new(vm, ns, Nydp::StringReader.new(txt)).run
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "unhandled_error" do
|
13
|
+
it "raises a helpful error" do
|
14
|
+
proc = Proc.new { run "dflkjdgjeirgjeoi" }
|
15
|
+
msg = "failed to eval dflkjdgjeirgjeoi\nerror was unbound symbol: dflkjdgjeirgjeoi"
|
16
|
+
expect(proc).to raise_error RuntimeError, msg
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/spec/nydp_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nydp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Conan Dalton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -160,6 +160,7 @@ files:
|
|
160
160
|
- nydp.gemspec
|
161
161
|
- spec/date_spec.rb
|
162
162
|
- spec/embedded_spec.rb
|
163
|
+
- spec/error_spec.rb
|
163
164
|
- spec/hash_spec.rb
|
164
165
|
- spec/literal_spec.rb
|
165
166
|
- spec/nydp_spec.rb
|
@@ -197,6 +198,7 @@ summary: A civilised yet somewhat dangerous kind of Lisp for a new generation
|
|
197
198
|
test_files:
|
198
199
|
- spec/date_spec.rb
|
199
200
|
- spec/embedded_spec.rb
|
201
|
+
- spec/error_spec.rb
|
200
202
|
- spec/hash_spec.rb
|
201
203
|
- spec/literal_spec.rb
|
202
204
|
- spec/nydp_spec.rb
|