Class: Nendo::Core

Inherits:
Object
  • Object
show all
Defined in:
lib/nendo.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(debug_evaluator = false, debug_printer = false) ⇒ Core

Returns a new instance of Core.



2340
2341
2342
2343
2344
# File 'lib/nendo.rb', line 2340

def initialize( debug_evaluator = false, debug_printer = false )
  @debug_evaluator = debug_evaluator
  @evaluator       = Evaluator.new( self, debug_evaluator )
  @debug_printer   = debug_printer
end

Class Method Details

.versionObject



2346
2347
2348
# File 'lib/nendo.rb', line 2346

def self.version
  "0.5.0"  ##NENDO-VERSION
end

Instance Method Details

#clean_compiled_codeObject



2385
2386
2387
# File 'lib/nendo.rb', line 2385

def clean_compiled_code
  @evaluator._clean_MIMARKcompiled_MIMARKcode()
end

#evalStr(str) ⇒ Object



2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
# File 'lib/nendo.rb', line 2417

def evalStr( str )
  printer   = Printer.new( @debug_printer )
  sio       = StringIO.open( str )
  reader    = Reader.new( sio, "(string)", false )
  result    = nil
  while true
    lineno = reader.lineno
    s = reader._read
    if s[1] # EOF?
      break
    elsif not s[0].is_a? Nil
      printf( "\n          readExp=<<< %s >>>\n", printer._write(s[0]) ) if @debug_evaluator
      result = printer._write( @evaluator.lispEval( s[0], reader.sourcefile, lineno )) 
    end
  end
  result
end

#load(path) ⇒ Object



2365
2366
2367
# File 'lib/nendo.rb', line 2365

def load( path )
  @evaluator.__PAMARKload( path )
end

#load_compiled_code(path) ⇒ Object



2369
2370
2371
# File 'lib/nendo.rb', line 2369

def load_compiled_code( path )
  @evaluator.__PAMARKload_MIMARKcompiled_MIMARKcode( path )
end

#load_compiled_code_from_string(rubyExp) ⇒ Object



2373
2374
2375
# File 'lib/nendo.rb', line 2373

def load_compiled_code_from_string( rubyExp )
  @evaluator._load_MIMARKcompiled_MIMARKcode_MIMARKfrom_MIMARKstring( rubyExp )
end

#loadInitFile(use_compiled = true) ⇒ Object



2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
# File 'lib/nendo.rb', line 2350

def loadInitFile( use_compiled = true )
  done = false
  if use_compiled 
    compiled_file = File.dirname(__FILE__) + "/init.nndc"
    if File.exist?( compiled_file )
      @evaluator.__PAMARKload_MIMARKcompiled_MIMARKcode( compiled_file )
      done = true
    end
  end
  unless done
    @evaluator.__PAMARKload( File.dirname(__FILE__) + "/init.nnd" )
    @evaluator.__PAMARKload( File.dirname(__FILE__) + "/init.nnd" ) # for %tailcall compile for init.nnd
  end
end

#promptObject



2389
2390
2391
# File 'lib/nendo.rb', line 2389

def prompt
  STDERR.print "nendo> "
end

#replObject



2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
# File 'lib/nendo.rb', line 2393

def repl
  printer = Printer.new( @debug_printer )
  reader  = Reader.new( STDIN, "(stdin)", false )
  self.prompt
  while true
    begin
      lineno = reader.lineno
      s = reader._read
      if s[1] # EOF?
        break
      elsif not s[0].is_a? Nil
        printf( "\n          readExp=<<< %s >>>\n", printer._write(s[0]) ) if @debug_evaluator
        STDERR.print printer._write( @evaluator.lispEval( s[0], reader.sourcefile, lineno )) + "\n"
        self.prompt
      end
    rescue => e
      print e.message + "\n"
      e.backtrace.each { |x| printf( "\tfrom %s\n", x ) }
      print "\n"
      self.prompt
    end
  end
end

#setArgv(argv) ⇒ Object



2377
2378
2379
# File 'lib/nendo.rb', line 2377

def setArgv( argv )
  @evaluator.setArgv( argv )
end

#setOptimizeLevel(level) ⇒ Object



2381
2382
2383
# File 'lib/nendo.rb', line 2381

def setOptimizeLevel( level )
  @evaluator.setOptimizeLevel( level )
end