nendo 0.6.5 → 0.6.6

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.
@@ -41,6 +41,8 @@ module Nendo
41
41
  EXEC_TYPE_ANONYMOUS = 2
42
42
  EXEC_TYPE_TAILCALL = 3
43
43
 
44
+ attr_accessor :runtimeCheck
45
+
44
46
  def initialize( core, debug = false )
45
47
  @core = core
46
48
  @indent = " "
@@ -50,8 +52,9 @@ module Nendo
50
52
  @lexicalVars = []
51
53
  @syntaxHash = {}
52
54
  @optimize_level = 2
53
- @backtrace = {}
54
- @backtrace_counter = 1;
55
+ @runtimeCheck = true
56
+ @backtrace = []
57
+ @backtrace_last = ""
55
58
  @displayErrorsFlag = true;
56
59
  @char_table_lisp_to_ruby = {
57
60
  # list (! $ % & * + - . / : < = > ? @ ^ _ ~ ...)
@@ -340,14 +343,25 @@ module Nendo
340
343
  end
341
344
 
342
345
  def embedBacktraceInfo( sourcefile, lineno )
343
- @backtrace[ sprintf( "%s:%s", sourcefile, lineno ) ] = @backtrace_counter
344
- @backtrace_counter += 1
346
+ str = sourcefile + ":" + lineno.to_s
347
+ if @backtrace_last != str
348
+ @backtrace << str
349
+ if ( 10 < @backtrace.size )
350
+ @backtrace.shift
351
+ end
352
+ #p @backtrace
353
+ end
354
+ @backtrace_last = str
345
355
  end
346
356
 
347
357
  def generateEmbedBacktraceInfo( sourcefile, lineno, arr )
348
358
  if sourcefile and lineno
349
359
  [ "begin",
350
- [ sprintf( 'embedBacktraceInfo( "%s", %s ); ', sourcefile, lineno ), arr ],
360
+ if @runtimeCheck
361
+ [ sprintf( 'embedBacktraceInfo( "%s", %s ); ', sourcefile, lineno ), arr ]
362
+ else
363
+ [arr]
364
+ end,
351
365
  "end"
352
366
  ]
353
367
  else
@@ -689,15 +703,23 @@ module Nendo
689
703
  end
690
704
  if global_cap
691
705
  ["begin",
692
- [sprintf( "if @global_lisp_binding.has_key?('%s') then", variable_sym ),
693
- expression,
694
- sprintf( 'else raise NameError.new( "Error: undefined variable %s", "%s" ) end', variable_sym, variable_sym ),
695
- sprintf( 'rescue => __e ; __e.set_backtrace( ["%s:%d"] + __e.backtrace ) ; raise __e', sourcefile, lineno )],
706
+ if @runtimeCheck
707
+ [sprintf( "if @global_lisp_binding.has_key?('%s') then", variable_sym ),
708
+ expression,
709
+ sprintf( 'else raise NameError.new( "Error: undefined variable %s", "%s" ) end', variable_sym, variable_sym ),
710
+ sprintf( 'rescue => __e ; __e.set_backtrace( ["%s:%d"] + __e.backtrace ) ; raise __e', sourcefile, lineno )]
711
+ else
712
+ [expression]
713
+ end,
696
714
  "end"]
697
715
  else
698
716
  ["begin",
699
- [expression,
700
- sprintf( 'rescue => __e ; __e.set_backtrace( ["%s:%d"] + __e.backtrace ) ; raise __e', sourcefile, lineno )],
717
+ if @runtimeCheck
718
+ [expression,
719
+ sprintf( 'rescue => __e ; __e.set_backtrace( ["%s:%d"] + __e.backtrace ) ; raise __e', sourcefile, lineno )]
720
+ else
721
+ [expression]
722
+ end,
701
723
  "end"]
702
724
  end
703
725
  end
@@ -1073,9 +1095,8 @@ module Nendo
1073
1095
  def displayBacktrace( exception )
1074
1096
  if @displayErrorsFlag
1075
1097
  STDERR.puts( "\n <<< Backtrace of Nendo >>>" )
1076
- arr = @backtrace.map { |key,val| [key,val] }.sort_by { |x| x[1] }.reverse
1077
- arr[0...10].each { |x|
1078
- STDERR.printf( " from %s \n", x[0] )
1098
+ @backtrace.reverse.each { |x|
1099
+ STDERR.printf( " from %s \n", x )
1079
1100
  }
1080
1101
  STDERR.puts( " ...\n\n" )
1081
1102
  end