nendo 0.3.1 → 0.3.2
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.
- data/bin/nendo +83 -14
- data/emacs/nendo-mode.el +7 -0
- data/example/cgi/dekamoji.cgi +74 -55
- data/example/fact.nnd +2 -5
- data/example/fizzbuzz1.nnd +5 -3
- data/example/nqueen.nnd +71 -0
- data/example/scratch.nnd +1 -2
- data/lib/debug/syslog.nnd +1 -1
- data/lib/debug/syslog.nndc +9 -0
- data/lib/init.nnd +248 -16
- data/lib/init.nndc +7194 -4456
- data/lib/nendo.rb +220 -50
- data/lib/text/html-lite.nndc +74 -57
- data/lib/text/tree.nndc +9 -0
- metadata +6 -12
data/bin/nendo
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# nendo - "interpretter main program"
|
5
5
|
#
|
6
|
-
# Copyright (c)
|
6
|
+
# Copyright (c) 2009-2010 Kiyoka Nishiyama <kiyoka@sumibi.org>
|
7
7
|
#
|
8
8
|
# Redistribution and use in source and binary forms, with or without
|
9
9
|
# modification, are permitted provided that the following conditions
|
@@ -36,45 +36,114 @@
|
|
36
36
|
#
|
37
37
|
require 'nendo'
|
38
38
|
require 'getoptlong'
|
39
|
+
#require 'profile'
|
40
|
+
|
41
|
+
def userOptionEater
|
42
|
+
i = 0
|
43
|
+
while ( i < ARGV.length )
|
44
|
+
case ARGV[i]
|
45
|
+
when '-h'
|
46
|
+
i += 1
|
47
|
+
when '-q'
|
48
|
+
i += 1
|
49
|
+
when '-c'
|
50
|
+
i += 1
|
51
|
+
when '-l'
|
52
|
+
i += 2
|
53
|
+
when /^[^-]/
|
54
|
+
break
|
55
|
+
else
|
56
|
+
break
|
57
|
+
end
|
58
|
+
end
|
59
|
+
userOptions = ARGV.clone[i..ARGV.length]
|
60
|
+
userOptions.length.times { |x|
|
61
|
+
ARGV.pop
|
62
|
+
}
|
63
|
+
return userOptions
|
64
|
+
end
|
65
|
+
|
66
|
+
def cache_exist?( fn )
|
67
|
+
dotdir_path = File.expand_path( "~/.nendo" )
|
68
|
+
cache_path = File.expand_path( "~/.nendo/cache" )
|
69
|
+
Dir.mkdir( dotdir_path ) unless File.exist?( dotdir_path )
|
70
|
+
Dir.mkdir( cache_path ) unless File.exist?( cache_path )
|
71
|
+
sha1 = Digest::SHA1.hexdigest( File.expand_path( fn ))
|
72
|
+
cache_name = cache_path + "/" + sha1 + "_" + File.basename( fn ) + ".rb"
|
73
|
+
if File.exist?( cache_name )
|
74
|
+
[ true, cache_name ]
|
75
|
+
else
|
76
|
+
[ false, cache_name ]
|
77
|
+
end
|
78
|
+
end
|
39
79
|
|
40
80
|
def main
|
41
|
-
loadInit
|
81
|
+
loadInit = true
|
82
|
+
compile = false
|
83
|
+
conflict = 0
|
42
84
|
core = Nendo.new()
|
43
85
|
|
86
|
+
userOptions = userOptionEater
|
44
87
|
opts = GetoptLong.new(
|
45
|
-
[ '
|
46
|
-
[ '
|
47
|
-
[ '
|
88
|
+
[ '-h', GetoptLong::NO_ARGUMENT ],
|
89
|
+
[ '-q', GetoptLong::NO_ARGUMENT ],
|
90
|
+
[ '-c', GetoptLong::NO_ARGUMENT ],
|
91
|
+
[ '-l', GetoptLong::REQUIRED_ARGUMENT ]
|
48
92
|
).each { |opt, arg|
|
49
93
|
case opt
|
50
|
-
when '
|
94
|
+
when '-h'
|
51
95
|
puts <<-EOF
|
52
96
|
|
53
97
|
nendo [OPTION] [script-file]
|
54
98
|
|
55
|
-
-h
|
99
|
+
-h:
|
56
100
|
show help
|
57
101
|
|
58
|
-
-q
|
102
|
+
-q:
|
59
103
|
Does not read the default initialization file.
|
60
104
|
|
61
|
-
-l
|
62
|
-
|
105
|
+
-l file:
|
106
|
+
load nendo script files. ( can specify n times like -l a.nnd -l b.nnd )
|
107
|
+
|
108
|
+
-c:
|
109
|
+
compile nendo script file. (and initialization file was loaded)
|
63
110
|
|
64
111
|
EOF
|
65
|
-
|
112
|
+
exit 0
|
113
|
+
when '-q'
|
66
114
|
loadInit = false
|
67
|
-
|
115
|
+
conflict += 1
|
116
|
+
when '-c'
|
117
|
+
loadInit = true
|
118
|
+
compile = true
|
119
|
+
conflict += 1
|
120
|
+
when '-l'
|
68
121
|
core.load( arg )
|
69
122
|
STDERR.printf( "loaded file [%s]\n", arg )
|
70
123
|
end
|
71
124
|
}
|
125
|
+
|
126
|
+
if 2 <= conflict
|
127
|
+
STDERR.puts( "Error: Can't specify both -q and -c ...\n" )
|
128
|
+
exit( 1 )
|
129
|
+
end
|
72
130
|
|
73
131
|
if loadInit
|
74
132
|
core.loadInitFile
|
75
133
|
end
|
76
|
-
if 0 <
|
77
|
-
|
134
|
+
if 0 < userOptions.length
|
135
|
+
fn = userOptions[0]
|
136
|
+
if compile
|
137
|
+
# compile script file.
|
138
|
+
core.clean_compiled_code( )
|
139
|
+
core.load( fn )
|
140
|
+
core.replStr( sprintf( '(print-compiled-code "%s")', fn ))
|
141
|
+
else
|
142
|
+
# start script file.
|
143
|
+
core.setArgv( userOptions[1..userOptions.length] )
|
144
|
+
core.load( fn )
|
145
|
+
core.replStr( "(if (and (global-defined? 'main) (procedure? main)) (main *argv*) #f)" )
|
146
|
+
end
|
78
147
|
else
|
79
148
|
core.repl
|
80
149
|
end
|
data/emacs/nendo-mode.el
CHANGED
@@ -4,6 +4,12 @@
|
|
4
4
|
;; Copyright (c) 2010 Kiyoka Nishiyama
|
5
5
|
;;
|
6
6
|
;;
|
7
|
+
;; Please add follows to .emacs
|
8
|
+
;; (setq scheme-program-name "nendo")
|
9
|
+
;; (autoload 'scheme-mode "cmuscheme" "Major mode for Scheme." t)
|
10
|
+
;; (autoload 'run-scheme "cmuscheme" "Run an inferior Scheme process." t)
|
11
|
+
;; (require 'nendo-mode)
|
12
|
+
|
7
13
|
|
8
14
|
(require 'comint)
|
9
15
|
(require 'cmuscheme)
|
@@ -42,6 +48,7 @@
|
|
42
48
|
"Major mode for editing nendo code.
|
43
49
|
Editing commands are similar to those of 'scheme-mode'."
|
44
50
|
(make-local-variable 'scheme-buffer)
|
51
|
+
(modify-coding-system-alist 'process "nendo" '(utf-8 . utf-8))
|
45
52
|
(local-set-key "\C-c\C-e" 'nendo-send-definition)
|
46
53
|
(local-set-key "\C-x\C-e" 'nendo-send-last-sexp))
|
47
54
|
|
data/example/cgi/dekamoji.cgi
CHANGED
@@ -15,19 +15,23 @@
|
|
15
15
|
(define font-list `(
|
16
16
|
("1" "ゴシック" ,(+ fontbase "ipagp.ttf"))
|
17
17
|
("2" "明朝" ,(+ fontbase "ipamp.ttf"))
|
18
|
+
("3" "あんず" ,(+ fontbase "APJapanesefont.ttf"))
|
18
19
|
))
|
19
20
|
(define default-fonttype 2)
|
20
21
|
|
21
22
|
(define default-wording "デカ文字")
|
22
23
|
(define default-size 2)
|
23
24
|
(define size-list '(
|
24
|
-
(1 . "
|
25
|
-
(2 . "
|
26
|
-
(3 . "
|
27
|
-
(4 . "
|
25
|
+
(1 . "サイズ極小")
|
26
|
+
(2 . "サイズ小")
|
27
|
+
(3 . "サイズ中")
|
28
|
+
(4 . "サイズ大")
|
29
|
+
(5 . "サイズ特大")
|
28
30
|
))
|
29
31
|
|
30
32
|
(define (response-dekamoji str pointsize fontpath)
|
33
|
+
(define (blur image width)
|
34
|
+
(image.blur_channel 0 width Magick::AllChannels))
|
31
35
|
(let* ((font-dots pointsize)
|
32
36
|
(margin (* pointsize 0.3))
|
33
37
|
(tmp-image (Magick::Image.new 1 1))
|
@@ -42,30 +46,46 @@
|
|
42
46
|
(set! dr.fill "#777799")
|
43
47
|
(set! dr.stroke "#8888AA")
|
44
48
|
(dr.annotate image1 0 0 5 5 str)
|
45
|
-
(let* ((image2 (image1
|
49
|
+
(let* ((image2 (blur image1 3)))
|
46
50
|
(set! dr.fill "#111111")
|
47
51
|
(set! dr.stroke "#606060")
|
48
52
|
(dr.annotate image2 0 0 0 0 str)
|
49
|
-
(image2.
|
53
|
+
(let1 image3 (blur image2 0.5)
|
54
|
+
(image3.to_blob))))))
|
50
55
|
|
51
56
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
+
;; -----------------------------------
|
58
|
+
;; encode & decode
|
59
|
+
;; -----------------------------------
|
60
|
+
(define (encode-wording wording)
|
61
|
+
(string-join
|
62
|
+
(map
|
63
|
+
(lambda (x)
|
64
|
+
(+ "%" (sprintf "%02X" x)))
|
65
|
+
(to-list (wording.unpack "C*")))
|
66
|
+
""))
|
67
|
+
|
68
|
+
(define (decode-wording enc-str)
|
69
|
+
(let1 hex-str (enc-str.gsub "%" "")
|
70
|
+
(. (. (list hex-str) to_arr) pack "H*")))
|
57
71
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
72
|
+
|
73
|
+
;; ----------------------------------
|
74
|
+
;; top page
|
75
|
+
;; -----------------------------------
|
76
|
+
(define (top-page params)
|
77
|
+
(define (calc-limit _start val _end)
|
78
|
+
(min (max _start val) _end))
|
79
|
+
(define (get-param params key default-value)
|
80
|
+
(if (hash-table-exist? params key)
|
81
|
+
(car (to-list (hash-table-get params key)))
|
82
|
+
default-value))
|
83
|
+
|
84
|
+
(let ((size (to-i (get-param params "size" default-size)))
|
85
|
+
(wording (get-param params "w" #f))
|
86
|
+
(fonttype (to-i (get-param params "type" default-fonttype))))
|
87
|
+
(let ((size (calc-limit 1 size (length size-list)))
|
88
|
+
(fonttype (calc-limit 1 fonttype (length font-list))))
|
69
89
|
`(
|
70
90
|
,(html-doctype)
|
71
91
|
,(html:head
|
@@ -73,50 +93,49 @@
|
|
73
93
|
,(html:body
|
74
94
|
(html:div :style "text-align: center; "
|
75
95
|
(html:h1 "デカ文字作成")
|
76
|
-
(html:p
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
(lambda (x)
|
94
|
-
(list
|
95
|
-
(html:input :name "type" :type "radio"
|
96
|
-
:value (car x)
|
97
|
-
:CHECKED (eq? (to-i (car x)) fonttype))
|
98
|
-
(second x)))
|
99
|
-
font-list)
|
100
|
-
(html:br)
|
101
|
-
(html:input :type "submit" :value "画像化"))
|
96
|
+
(html:p "文章を入れて『画像化』ボタンを押して下さい")
|
97
|
+
(html:form :method "POST" :action "./dekamoji.cgi"
|
98
|
+
(html:input :name "w" :type "text" :size 60 :value wording)
|
99
|
+
(html:br)
|
100
|
+
(map (lambda (x) (list
|
101
|
+
(html:input :name "size" :type "radio" :value (car x)
|
102
|
+
:CHECKED (eq? (car x) size))
|
103
|
+
(cdr x)))
|
104
|
+
size-list)
|
105
|
+
(html:br)
|
106
|
+
(map (lambda (x) (list
|
107
|
+
(html:input :name "type" :type "radio" :value (car x)
|
108
|
+
:CHECKED (eq? (to-i (car x)) fonttype))
|
109
|
+
(second x)))
|
110
|
+
font-list)
|
111
|
+
(html:br)
|
112
|
+
(html:input :type "submit" :value "画像化"))
|
102
113
|
(html:hr)
|
103
|
-
(
|
114
|
+
(cond
|
115
|
+
(wording
|
116
|
+
(html:img :src (sprintf "./dekamoji.cgi?img=1&size=%d&type=%s&w=%s" size fonttype (encode-wording wording))))
|
117
|
+
(else
|
118
|
+
(html:p "no image")))
|
104
119
|
(html:hr)))))))
|
105
120
|
|
106
121
|
(define fontsize-alist '(
|
107
|
-
("1" .
|
108
|
-
("2" .
|
109
|
-
("3" .
|
110
|
-
("4" .
|
122
|
+
("1" . 20)
|
123
|
+
("2" . 40)
|
124
|
+
("3" . 80)
|
125
|
+
("4" . 160)
|
126
|
+
("5" . 320)
|
111
127
|
))
|
112
128
|
|
113
|
-
|
129
|
+
;; -----------------------------------
|
130
|
+
;; entry point
|
131
|
+
;; -----------------------------------
|
132
|
+
(if #t
|
114
133
|
;; testing
|
115
134
|
(display
|
116
135
|
(response-dekamoji
|
117
136
|
"デカ文字"
|
118
137
|
80
|
119
|
-
(+ fontbase "
|
138
|
+
(+ fontbase "ipamp.ttf")))
|
120
139
|
;; release
|
121
140
|
(let1 cgi (CGI.new)
|
122
141
|
(cond ((hash-table-exist? cgi.params "img")
|
data/example/fact.nnd
CHANGED
data/example/fizzbuzz1.nnd
CHANGED
data/example/nqueen.nnd
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
:; #-*- mode: nendo; syntax: scheme -*-;;
|
3
|
+
:; exec /usr/local/bin/nendo $0 $*
|
4
|
+
;; -*- coding: utf-8 -*-
|
5
|
+
;; Nqueen
|
6
|
+
;; n×n の互いに効き線上にないクイーンの配列をみつける
|
7
|
+
|
8
|
+
;; SHINYAMA Yusuke (euske@cl.cs.titech.ac.jp)
|
9
|
+
;; This software is public domain.
|
10
|
+
|
11
|
+
(define (decr x) (- x 1))
|
12
|
+
(define (incr x) (+ x 1))
|
13
|
+
|
14
|
+
; rotate: ベクタ x を pos要素 だけ回転させる
|
15
|
+
(define (rotate x pos)
|
16
|
+
(do ((last (decr (vector-length x)))
|
17
|
+
(x0 (vector-ref x pos))
|
18
|
+
(i pos (incr i)))
|
19
|
+
((= i last) (vector-set! x last x0))
|
20
|
+
(vector-set! x i (vector-ref x (incr i)))))
|
21
|
+
|
22
|
+
; rotrec: ベクタ x の要素の、あらゆる配置の組み合わせに func を適用する
|
23
|
+
(define (rotrec func x pos)
|
24
|
+
(let ((last (decr (vector-length x))))
|
25
|
+
(if (= pos last)
|
26
|
+
(func x)
|
27
|
+
(do ((i pos (incr i)))
|
28
|
+
((< last i) #f)
|
29
|
+
(rotrec func x (incr pos))
|
30
|
+
(rotate x pos)))))
|
31
|
+
|
32
|
+
; genpat: n×n の盤の初期パターンを作る
|
33
|
+
(define (genpat n)
|
34
|
+
(let ((x (make-vector n)))
|
35
|
+
(do ((i 0 (incr i)))
|
36
|
+
((= n i) x)
|
37
|
+
(vector-set! x i i))))
|
38
|
+
|
39
|
+
; checkqueen: パターン p がすべて互いに効き線上にないクイーンなら #t
|
40
|
+
(define (checkqueen p)
|
41
|
+
(define (loop i diag0 diag1) ; i はカウンタ, diag0, diag1 はリスト
|
42
|
+
(or (zero? i)
|
43
|
+
(let* ((x (decr i))
|
44
|
+
(y (vector-ref p x))
|
45
|
+
(d0 (+ x y))
|
46
|
+
(d1 (- x y)))
|
47
|
+
;;(printf "check: %s (%d,%d) in %s,%s\n" p x y (write-to-string diag0) (write-to-string diag1))
|
48
|
+
(and (not (or (memv d0 diag0)
|
49
|
+
(memv d1 diag1)))
|
50
|
+
(loop (decr i) (cons d0 diag0) (cons d1 diag1))))))
|
51
|
+
(loop (vector-length p) '() '()))
|
52
|
+
|
53
|
+
; nqueen: メインルーチン
|
54
|
+
(define (nqueen n)
|
55
|
+
(let ((result '()))
|
56
|
+
(rotrec (lambda (p)
|
57
|
+
(if (checkqueen p)
|
58
|
+
(set! result
|
59
|
+
(cons (vector->list p) result))))
|
60
|
+
(genpat n) 0)
|
61
|
+
result))
|
62
|
+
|
63
|
+
; sample
|
64
|
+
;(display (nqueen 8))(newline)(exit)
|
65
|
+
|
66
|
+
(define (main args)
|
67
|
+
(display (nqueen 8))
|
68
|
+
(newline)
|
69
|
+
(exit 0))
|
70
|
+
(main *argv*)
|
71
|
+
|
data/example/scratch.nnd
CHANGED
data/lib/debug/syslog.nnd
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
;;; debug/syslog.nnd - #?= debug message output to syslog
|
4
4
|
;;;
|
5
5
|
;;;
|
6
|
-
;;; Copyright (c)
|
6
|
+
;;; Copyright (c) 2009-2010 Kiyoka Nishiyama <kiyoka@sumibi.org>
|
7
7
|
;;;
|
8
8
|
;;; Redistribution and use in source and binary forms, with or without
|
9
9
|
;;; modification, are permitted provided that the following conditions
|
data/lib/debug/syslog.nndc
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
#
|
2
|
+
# This file is nendo's compiled library file.
|
3
|
+
# generated "nendo -c src" command.
|
4
|
+
#
|
1
5
|
|
2
6
|
callProcedure( 'require',
|
3
7
|
begin
|
@@ -51,3 +55,8 @@
|
|
51
55
|
end
|
52
56
|
}
|
53
57
|
end
|
58
|
+
|
59
|
+
|
60
|
+
# -------------------------------------------------------
|
61
|
+
# [EOF]
|
62
|
+
# -------------------------------------------------------
|