nendo 0.3.4 → 0.3.5
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/benchmark/benchmark.nnd +57 -0
- data/{example/tak.nnd → benchmark/nendo_benchmark_code.nnd} +6 -2
- data/benchmark/ruby_benchmark_code.rb +58 -0
- data/example/scratch.nnd +52 -6
- data/lib/debug/syslog.nndc +8 -6
- data/lib/init.nnd +14 -14
- data/lib/init.nndc +4142 -2932
- data/lib/nendo/test.nndc +308 -227
- data/lib/nendo.rb +41 -34
- data/lib/srfi-1.nndc +3572 -2599
- data/lib/text/html-lite.nndc +621 -440
- data/lib/text/tree.nndc +38 -27
- data/test/nendo_spec.rb +179 -149
- data/test/nendo_util.nnd +4 -3
- metadata +20 -7
- data/example/tak_ruby_version.rb +0 -14
data/lib/nendo.rb
CHANGED
@@ -38,7 +38,6 @@
|
|
38
38
|
module Nendo
|
39
39
|
require 'stringio'
|
40
40
|
require 'digest/sha1'
|
41
|
-
#require 'profile'
|
42
41
|
|
43
42
|
class Nil
|
44
43
|
include Enumerable
|
@@ -232,12 +231,13 @@ module Nendo
|
|
232
231
|
end
|
233
232
|
|
234
233
|
class DelayedCallPacket
|
235
|
-
def initialize( _origname, _pred, _args )
|
234
|
+
def initialize( _origname, _rubysym, _pred, _args )
|
236
235
|
@origname = _origname
|
236
|
+
@rubysym = _rubysym
|
237
237
|
@pred = _pred
|
238
238
|
@args = _args
|
239
239
|
end
|
240
|
-
attr_reader :origname, :pred, :args
|
240
|
+
attr_reader :origname, :rubysym, :pred, :args
|
241
241
|
end
|
242
242
|
|
243
243
|
class Token
|
@@ -821,7 +821,9 @@ module Nendo
|
|
821
821
|
end
|
822
822
|
|
823
823
|
def _equal_QUMARK( a, b )
|
824
|
-
if a.
|
824
|
+
if a.is_a? String and b.is_a? String
|
825
|
+
a === b
|
826
|
+
elsif a.class != b.class
|
825
827
|
false
|
826
828
|
elsif a.class == Cell
|
827
829
|
if a.isNull and b.isNull
|
@@ -845,7 +847,8 @@ module Nendo
|
|
845
847
|
__assertFlat( arr )
|
846
848
|
arr.each { |x|
|
847
849
|
if not (_number_QUMARK(x) or _string_QUMARK(x))
|
848
|
-
|
850
|
+
##arr.each { |v| STDERR.printf( "__PLMARK: %s\n", v ) }
|
851
|
+
raise TypeError, sprintf( "Error: arg %s is [%s] type",x ,x.class )
|
849
852
|
end
|
850
853
|
}
|
851
854
|
case args[0].length
|
@@ -1029,7 +1032,6 @@ module Nendo
|
|
1029
1032
|
def __GTMARK_EQMARK( a,b ) a >= b end
|
1030
1033
|
def __LTMARK( a,b ) a < b end
|
1031
1034
|
def __LTMARK_EQMARK( a,b ) a <= b end
|
1032
|
-
def _eqv_QUMARK( a,b ) a === b end
|
1033
1035
|
def _eq_QUMARK( a,b ) a == b end
|
1034
1036
|
def _gt_QUMARK( a,b ) a > b end
|
1035
1037
|
def _ge_QUMARK( a,b ) a >= b end
|
@@ -1063,7 +1065,7 @@ module Nendo
|
|
1063
1065
|
end
|
1064
1066
|
def _integer_QUMARK( arg ) arg.is_a? Integer end
|
1065
1067
|
def _number_QUMARK( arg ) arg.is_a? Numeric end
|
1066
|
-
def _string_QUMARK( arg )
|
1068
|
+
def _string_QUMARK( arg ) arg.is_a? String end
|
1067
1069
|
def _macroexpand_MIMARK1( arg )
|
1068
1070
|
if _pair_QUMARK( arg )
|
1069
1071
|
macroexpandInit( 1 )
|
@@ -1106,7 +1108,7 @@ module Nendo
|
|
1106
1108
|
arr = args[0].to_arr
|
1107
1109
|
if 0 < arr.length
|
1108
1110
|
if not arr[0].is_a? String
|
1109
|
-
raise TypeError, "Error string-join's expects delimitter as String."
|
1111
|
+
raise TypeError, "Error: string-join's expects delimitter as String."
|
1110
1112
|
else
|
1111
1113
|
lst.to_a.map{ |x| x.car }.join( arr[0] )
|
1112
1114
|
end
|
@@ -1118,6 +1120,16 @@ module Nendo
|
|
1118
1120
|
require( arg )
|
1119
1121
|
false
|
1120
1122
|
end
|
1123
|
+
def _read_MIMARKfrom_MIMARKstring( str )
|
1124
|
+
if not str.is_a? String
|
1125
|
+
raise TypeError, "Error: read-from-string expects sexp as String."
|
1126
|
+
else
|
1127
|
+
sio = StringIO.open( str )
|
1128
|
+
reader = Reader.new( sio, "(string)", false )
|
1129
|
+
s = reader._read
|
1130
|
+
s[0]
|
1131
|
+
end
|
1132
|
+
end
|
1121
1133
|
def _read( *args )
|
1122
1134
|
lst = args[0].to_arr
|
1123
1135
|
io = if 0 == lst.length
|
@@ -1139,7 +1151,7 @@ module Nendo
|
|
1139
1151
|
end
|
1140
1152
|
|
1141
1153
|
def _apply1( first, arg )
|
1142
|
-
trampCall( callProcedure( "(apply1 genereate func)", first, arg ))
|
1154
|
+
trampCall( callProcedure( "(apply1 genereate func)", first, arg.to_arr ))
|
1143
1155
|
end
|
1144
1156
|
|
1145
1157
|
def _global_MIMARKvariables
|
@@ -1418,11 +1430,11 @@ module Nendo
|
|
1418
1430
|
raise ArgumentError, argument_error_message if 0 != args.length
|
1419
1431
|
[]
|
1420
1432
|
elsif 0 < num
|
1421
|
-
if args.
|
1433
|
+
if 0 == args.length
|
1422
1434
|
[ Nil.new ]
|
1423
1435
|
else
|
1424
1436
|
raise ArgumentError, argument_error_message if num != args.length
|
1425
|
-
args
|
1437
|
+
args
|
1426
1438
|
end
|
1427
1439
|
else
|
1428
1440
|
num = num.abs( )-1
|
@@ -1431,9 +1443,9 @@ module Nendo
|
|
1431
1443
|
rest = []
|
1432
1444
|
args.each_with_index { |x,i|
|
1433
1445
|
if i < num
|
1434
|
-
params << x
|
1446
|
+
params << x
|
1435
1447
|
else
|
1436
|
-
rest << x
|
1448
|
+
rest << x
|
1437
1449
|
end
|
1438
1450
|
}
|
1439
1451
|
result = []
|
@@ -1451,17 +1463,15 @@ module Nendo
|
|
1451
1463
|
|
1452
1464
|
def trampCall( result )
|
1453
1465
|
while result.is_a? DelayedCallPacket
|
1454
|
-
method_name = toRubySymbol( result.origname ) + "_METHOD"
|
1455
1466
|
@tmp_origname = result.origname
|
1456
1467
|
@tmp_pred = result.pred
|
1457
1468
|
@tmp_args = result.args
|
1458
|
-
result = eval( sprintf( "self.%s( @tmp_origname, @tmp_pred, @tmp_args )",
|
1469
|
+
result = eval( sprintf( "self.%s( @tmp_origname, @tmp_pred, @tmp_args )", result.rubysym + "_METHOD" ), @binding )
|
1459
1470
|
end
|
1460
1471
|
result
|
1461
1472
|
end
|
1462
1473
|
|
1463
1474
|
def method_missing( name, *args )
|
1464
|
-
sym = toRubySymbol( name )
|
1465
1475
|
if @global_lisp_binding[name].is_a? Proc
|
1466
1476
|
@global_lisp_binding[name].call( args[0], args[1], args[2] )
|
1467
1477
|
else
|
@@ -1469,12 +1479,12 @@ module Nendo
|
|
1469
1479
|
end
|
1470
1480
|
end
|
1471
1481
|
|
1472
|
-
def delayCall( origname, pred, args )
|
1482
|
+
def delayCall( rubysym, origname, pred, args )
|
1473
1483
|
case @optimize_level
|
1474
1484
|
when 0 # no optimize
|
1475
1485
|
callProcedure( origname, pred, args )
|
1476
1486
|
else # tail call optimization
|
1477
|
-
DelayedCallPacket.new( origname, pred, args )
|
1487
|
+
DelayedCallPacket.new( origname, rubysym, pred, args )
|
1478
1488
|
end
|
1479
1489
|
end
|
1480
1490
|
|
@@ -1537,17 +1547,12 @@ module Nendo
|
|
1537
1547
|
lispSymbolReference( toRubySymbol( funcname ), locals, translatedArr, sourcefile, lineno )
|
1538
1548
|
else
|
1539
1549
|
# Nendo function
|
1540
|
-
|
1541
|
-
arr = [ "Cell.new(" ]
|
1542
|
-
else
|
1543
|
-
arr = separateWith( args.map.with_index { |x,i| x.car }, ",Cell.new(" )
|
1544
|
-
arr[0].unshift( "Cell.new(" )
|
1545
|
-
end
|
1550
|
+
arr = separateWith( args.map { |x| x.car }, "," )
|
1546
1551
|
if EXEC_TYPE_ANONYMOUS == execType
|
1547
1552
|
[sprintf( "trampCall( callProcedure( 'anonymouse', " ),
|
1548
1553
|
[ funcname ] + [ "," ],
|
1549
|
-
arr,
|
1550
|
-
|
1554
|
+
"[", arr, "]",
|
1555
|
+
" ))"]
|
1551
1556
|
else
|
1552
1557
|
origname = funcname.to_s
|
1553
1558
|
funcname = funcname.to_s
|
@@ -1555,17 +1560,17 @@ module Nendo
|
|
1555
1560
|
_call = case execType
|
1556
1561
|
when EXEC_TYPE_NORMAL
|
1557
1562
|
if locals.flatten.include?( sym )
|
1558
|
-
[
|
1563
|
+
[ "trampCall( callProcedure( ", "))" ] # local function
|
1559
1564
|
else
|
1560
1565
|
[ sprintf( "trampCall( self.%s_METHOD( ", sym ), "))" ] # toplevel function
|
1561
1566
|
end
|
1562
1567
|
when EXEC_TYPE_TAILCALL
|
1563
|
-
[ "delayCall(", ")" ]
|
1568
|
+
[ sprintf( "delayCall( '%s', ", sym ), ")" ]
|
1564
1569
|
end
|
1565
1570
|
[sprintf( "%s '%s',", _call[0], origname ),
|
1566
1571
|
[lispSymbolReference( sym, locals, nil, sourcefile, lineno )] + [","],
|
1567
|
-
arr,
|
1568
|
-
sprintf( " %s", _call[1] )
|
1572
|
+
"[", arr, "]",
|
1573
|
+
sprintf( " %s", _call[1] )]
|
1569
1574
|
end
|
1570
1575
|
end
|
1571
1576
|
end
|
@@ -1730,6 +1735,8 @@ module Nendo
|
|
1730
1735
|
str += sprintf( "LispKeyword.new( \"%s\" )", sexp.key.to_s )
|
1731
1736
|
when TrueClass, FalseClass, NilClass # reserved symbols
|
1732
1737
|
str += toRubyValue( sexp )
|
1738
|
+
when Nil
|
1739
|
+
str += "Cell.new()"
|
1733
1740
|
else
|
1734
1741
|
str += sprintf( "%s", sexp )
|
1735
1742
|
end
|
@@ -1774,7 +1781,7 @@ module Nendo
|
|
1774
1781
|
"end"]
|
1775
1782
|
end
|
1776
1783
|
end
|
1777
|
-
|
1784
|
+
|
1778
1785
|
# Lisp->Ruby translater
|
1779
1786
|
# - locals is array of closure's local variable list
|
1780
1787
|
# when S-expression is
|
@@ -1923,7 +1930,7 @@ module Nendo
|
|
1923
1930
|
sexp
|
1924
1931
|
elsif sexp.car.class == Symbol and eval( sprintf( "(defined? @%s and LispMacro == @%s.class)", sym,sym ), @binding )
|
1925
1932
|
eval( sprintf( "@__macro = @%s", sym ), @binding )
|
1926
|
-
newSexp = trampCall( callProcedure( sym, @__macro, sexp.cdr ))
|
1933
|
+
newSexp = trampCall( callProcedure( sym, @__macro, sexp.cdr.to_arr ))
|
1927
1934
|
end
|
1928
1935
|
if _equal_QUMARK( newSexp, sexp )
|
1929
1936
|
sexp.map { |x|
|
@@ -1988,7 +1995,7 @@ module Nendo
|
|
1988
1995
|
sym = toRubySymbol( "%compile-phase" )
|
1989
1996
|
if ( eval( sprintf( "(defined? @%s and Proc == @%s.class)", sym,sym ), @binding ))
|
1990
1997
|
eval( sprintf( "@___tmp = @%s", sym ), @binding )
|
1991
|
-
sexp = trampCall( callProcedure( sym, @___tmp,
|
1998
|
+
sexp = trampCall( callProcedure( sym, @___tmp, [ sexp ]))
|
1992
1999
|
if @debug
|
1993
2000
|
printf( "\n compiled=<<< %s >>>\n", (Printer.new())._print(sexp))
|
1994
2001
|
end
|
@@ -2107,7 +2114,7 @@ module Nendo
|
|
2107
2114
|
|
2108
2115
|
argsStr = (1..(pred.arity)).map { |n| "arg" + n.to_s }.join( "," )
|
2109
2116
|
str = [ "def self." + origname + "(" + argsStr + ")",
|
2110
|
-
sprintf( " trampCall( callProcedure( '%s', @_%s, [ " + argsStr + " ]
|
2117
|
+
sprintf( " trampCall( callProcedure( '%s', @_%s, [ " + argsStr + " ] )) ",
|
2111
2118
|
origname, origname ),
|
2112
2119
|
"end ;",
|
2113
2120
|
"def @core." + origname + "(" + argsStr + ")",
|