nendo 0.5.2 → 0.5.3

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/lib/nendo.rb CHANGED
@@ -1339,6 +1339,9 @@ module Nendo
1339
1339
  @lexicalVars = []
1340
1340
  @syntaxHash = {}
1341
1341
  @optimize_level = 2
1342
+ @backtrace = {}
1343
+ @backtrace_counter = 1;
1344
+ @displayErrorsFlag = true;
1342
1345
  @char_table_lisp_to_ruby = {
1343
1346
  # list (! $ % & * + - . / : < = > ? @ ^ _ ~ ...)
1344
1347
  '!' => '_EXMARK',
@@ -1432,7 +1435,11 @@ module Nendo
1432
1435
  def getOptimizeLevel
1433
1436
  @optimize_level
1434
1437
  end
1435
-
1438
+
1439
+ def setDisplayErrors( flag )
1440
+ @displayErrorsFlag = flag
1441
+ end
1442
+
1436
1443
  def lispMethodEntry( name, _log )
1437
1444
  @call_depth += 1
1438
1445
  if @trace_debug and _log
@@ -1535,7 +1542,7 @@ module Nendo
1535
1542
  []
1536
1543
  elsif 0 < num
1537
1544
  if 0 == len
1538
- [ Nil.new ]
1545
+ raise ArgumentError, errorMessageOf_toRubyArgument( origname, 4, num, len )
1539
1546
  else
1540
1547
  raise ArgumentError, errorMessageOf_toRubyArgument( origname, 2, num, len ) if num != len
1541
1548
  args
@@ -1621,6 +1628,22 @@ module Nendo
1621
1628
  [ :define, :set!, :"define-syntax", @core_syntax_hash[ :define ], @core_syntax_hash[ :set! ], @core_syntax_hash[ :"define-syntax" ] ].include?( sym )
1622
1629
  end
1623
1630
 
1631
+ def embedBacktraceInfo( sourcefile, lineno )
1632
+ @backtrace[ sprintf( "%s:%s", sourcefile, lineno ) ] = @backtrace_counter
1633
+ @backtrace_counter += 1
1634
+ end
1635
+
1636
+ def generateEmbedBacktraceInfo( sourcefile, lineno, arr )
1637
+ if sourcefile and lineno
1638
+ [ "begin",
1639
+ [ sprintf( 'embedBacktraceInfo( "%s", %s ); ', sourcefile, lineno ), arr ],
1640
+ "end"
1641
+ ]
1642
+ else
1643
+ arr
1644
+ end
1645
+ end
1646
+
1624
1647
  def optimizedFunc( origname, rubysym, args )
1625
1648
  case origname
1626
1649
  when '+', '-', '*'
@@ -1715,7 +1738,7 @@ module Nendo
1715
1738
  end
1716
1739
  end
1717
1740
  if result
1718
- result
1741
+ generateEmbedBacktraceInfo( sourcefile, lineno, result )
1719
1742
  else
1720
1743
  _call = case execType
1721
1744
  when EXEC_TYPE_NORMAL
@@ -1728,10 +1751,12 @@ module Nendo
1728
1751
  [ sprintf( "delayCall( '%s', ", sym ), ")" ]
1729
1752
  end
1730
1753
 
1731
- [sprintf( "%s '%s',", _call[0], origname ),
1754
+ temp = [
1755
+ sprintf( "%s '%s',", _call[0], origname ),
1732
1756
  [lispSymbolReference( sym, locals, nil, sourcefile, lineno )] + [","],
1733
1757
  "[", arr, "]",
1734
1758
  sprintf( " %s", _call[1] )]
1759
+ generateEmbedBacktraceInfo( sourcefile, lineno, temp )
1735
1760
  end
1736
1761
  end
1737
1762
  end
@@ -2306,16 +2331,29 @@ module Nendo
2306
2331
  end
2307
2332
 
2308
2333
  def displayTopOfCalls( exception )
2309
- STDERR.puts( "\n <<< Top of calls >>>" )
2310
- strs = []
2311
- @call_counters.each_key { |funcname|
2312
- if 0 < @call_counters[ funcname ]
2313
- strs << sprintf( " %7d : %-20s", @call_counters[ funcname ], funcname )
2314
- end
2315
- }
2316
- strs.sort.reverse.each { |str|
2317
- STDERR.puts( str )
2318
- }
2334
+ if @displayErrorsFlag
2335
+ STDERR.puts( "\n <<< Top of calls >>>" )
2336
+ strs = []
2337
+ @call_counters.each_key { |funcname|
2338
+ if 0 < @call_counters[ funcname ]
2339
+ strs << sprintf( " %7d : %-20s", @call_counters[ funcname ], funcname )
2340
+ end
2341
+ }
2342
+ strs.sort.reverse.each { |str|
2343
+ STDERR.puts( str )
2344
+ }
2345
+ end
2346
+ end
2347
+
2348
+ def displayBacktrace( exception )
2349
+ if @displayErrorsFlag
2350
+ STDERR.puts( "\n <<< Backtrace of Nendo >>>" )
2351
+ arr = @backtrace.map { |key,val| [key,val] }.sort_by { |x| x[1] }.reverse
2352
+ arr[0...10].each { |x|
2353
+ STDERR.printf( " from %s \n", x[0] )
2354
+ }
2355
+ STDERR.puts( " ...\n\n" )
2356
+ end
2319
2357
  end
2320
2358
 
2321
2359
  def lispEval( sexp, sourcefile, lineno )
@@ -2358,6 +2396,9 @@ module Nendo
2358
2396
  rescue SystemStackError => e
2359
2397
  displayTopOfCalls( e )
2360
2398
  raise e
2399
+ rescue => e
2400
+ displayBacktrace( e )
2401
+ raise e
2361
2402
  end
2362
2403
  end
2363
2404
 
@@ -2631,6 +2672,12 @@ module Nendo
2631
2672
  "#/" + sexp.source + "/" + (sexp.casefold? ? "i" : "")
2632
2673
  when LispKeyword
2633
2674
  ":" + sexp.key.to_s
2675
+ when LispCoreSyntax
2676
+ "#<Nendo::LispCoreSyntax>"
2677
+ when LispMacro
2678
+ "#<Nendo::LispMacro>"
2679
+ when LispSyntax
2680
+ "#<Nendo::LispSyntax>"
2634
2681
  when Nil
2635
2682
  "()"
2636
2683
  when nil
@@ -2657,7 +2704,7 @@ module Nendo
2657
2704
  end
2658
2705
 
2659
2706
  def self.version
2660
- "0.5.2" ##NENDO-VERSION
2707
+ "0.5.3" ##NENDO-VERSION
2661
2708
  end
2662
2709
 
2663
2710
  attr_reader :evaluator
@@ -2696,7 +2743,11 @@ module Nendo
2696
2743
  def setOptimizeLevel( level )
2697
2744
  @evaluator.setOptimizeLevel( level )
2698
2745
  end
2699
-
2746
+
2747
+ def setDisplayErrors( flag )
2748
+ @evaluator.setDisplayErrors( flag )
2749
+ end
2750
+
2700
2751
  def clean_compiled_code
2701
2752
  @evaluator._clean_MIMARKcompiled_MIMARKcode()
2702
2753
  end