Class: VirtualModule::JuliaSourceProvider
- Inherits:
-
BaseSourceProvider
- Object
- BaseSourceProvider
- VirtualModule::JuliaSourceProvider
- Defined in:
- lib/virtual_module.rb
Constant Summary collapse
- EXT =
"jl"
Instance Attribute Summary
Attributes inherited from BaseSourceProvider
Instance Method Summary collapse
- #compile(vars = nil, type_info = nil, params = nil, script = nil, auto_binding = nil) ⇒ Object
- #generate_message(input_queue_path, receiver, name, *args, **kwargs) ⇒ Object
- #lib_script(ipc = nil) ⇒ Object
- #load_packages ⇒ Object
- #main_loop(input_queue_path, output_queue_path, lib_script = nil) ⇒ Object
- #to_a ⇒ Object
- #to_s ⇒ Object
- #vclass ⇒ Object
Methods inherited from BaseSourceProvider
Constructor Details
This class inherits a constructor from VirtualModule::BaseSourceProvider
Instance Method Details
#compile(vars = nil, type_info = nil, params = nil, script = nil, auto_binding = nil) ⇒ Object
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 |
# File 'lib/virtual_module.rb', line 446 def compile(vars=nil, type_info=nil, params=nil, script=nil, auto_binding=nil) @compiled_lib = File.read(File.dirname(__FILE__)+"/virtual_module/bridge.jl") + ";" + load_packages.join(";\n") + @transpiler.call(@source.join(";\n")) if !vars.nil? && !type_info.nil? && !params.nil? && !script.nil? && !auto_binding.nil? @compiled_lib += <<EOS function ___convert_type(name, typename, params) if length(findin(#{type_info[:params].keys.map{|e| e.to_s}},[name]))>0 if typename=="FloatArray" convert(Array{Float64,1}, params[name]) elseif typename=="IntArray" convert(Array{Int64,1}, params[name]) end else params[name] end end function vm_builtin_eval_func(params) #{vars.map{|e| e.to_s + '=___convert_type("'+e.to_s+'","'+(type_info[:params][e]||"")+'", params[1])'}.join(";")} ##{vars.map{|e| 'println("'+e.to_s+'=", typeof('+e.to_s+'))' }.join(";")} ___evaluated = (#{@transpiler.call(script)}) #{vars.map{|e| 'params[1]["'+e.to_s+'"]='+e.to_s }.join(";") if auto_binding} (___evaluated,#{auto_binding ? "params[1]" : "-1" }) end EOS end end |
#generate_message(input_queue_path, receiver, name, *args, **kwargs) ⇒ Object
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 |
# File 'lib/virtual_module.rb', line 477 def (input_queue_path, receiver, name, *args, **kwargs) script, params = ["", ""] if args.count + kwargs.count > 0 gen_driver = ->(arg, input_queue_path, i, type, param_name){ val = case arg.class.to_s when "Module" then ( (table_index = arg.___proxy_object_transmitter.get_index(@builder.object_id)).nil? ? "deserialize(fp)" : "object_lookup_table[#{table_index}]" ) when "Symbol" then "convert(Symbol, unpack(readall(fp)))" else "unpack(readall(fp))" end script += "#{param_name} =open( \"#{input_queue_path}.#{i}.#{type}\", \"r\" ) do fp; #{val}; end;" } conv_kwargs = KwargsConverter.new("Dict{Symbol,Any}()", ->(k){"kwargs[:#{k}]"}, ";kwargs...") script, params = prepare_params(input_queue_path, gen_driver, conv_kwargs, name, *args, **kwargs) end callee = "#{name}" if !receiver.nil? if receiver[0..5]=="\xC1VMOBJ" script += "receiver=object_lookup_table[#{receiver[6..-1]}];" else File.write("#{input_queue_path}_serialized", receiver) script += "receiver =open( \"#{input_queue_path}_serialized\", \"r\" ) do fp; deserialize(fp); end;" end if name==:[] callee = "receiver" else callee = "receiver.#{name}" end end script += "#{callee}#{params};" end |
#lib_script(ipc = nil) ⇒ Object
432 433 434 435 436 437 438 439 440 441 442 443 444 |
# File 'lib/virtual_module.rb', line 432 def lib_script(ipc=nil) if ipc!=:rpc @compiled_lib else <<EOS import MsgPackRpcServer module RemoteFunctions #{@compiled_lib} end MsgPackRpcServer.run(parse(ARGS[1]), RemoteFunctions) EOS end end |
#load_packages ⇒ Object
374 375 376 |
# File 'lib/virtual_module.rb', line 374 def load_packages @pkgs.map{|e| "import #{e}"} end |
#main_loop(input_queue_path, output_queue_path, lib_script = nil) ⇒ Object
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 |
# File 'lib/virtual_module.rb', line 390 def main_loop(input_queue_path, output_queue_path, lib_script=nil) <<EOS using MsgPack object_lookup_table = Dict() while true try source = open( "#{input_queue_path}", "r" ) do fp readall(fp) end if source[1]=='\n' open( "#{output_queue_path}", "w" ) do fp serialize(fp, object_lookup_table[parse(Int,source[2:length(source)])]) end else result = eval(parse(source)) open( "#{output_queue_path}", "w" ) do fp try write(fp,pack(result)) catch object_lookup_table[object_id(result)] = result write(fp, 0xc1) write(fp, "VMOBJ") write(fp, string(object_id(result))) end end end catch err print(typeof(err)) if !isa(err, InterruptException) open( "#{output_queue_path}", "w" ) do fp write(fp, 0xc1) write(fp, "VMERR") write(fp, string(err)) end else exit end end end EOS end |
#to_a ⇒ Object
378 379 380 |
# File 'lib/virtual_module.rb', line 378 def to_a :tuple end |
#to_s ⇒ Object
382 383 384 |
# File 'lib/virtual_module.rb', line 382 def to_s :string end |
#vclass ⇒ Object
386 387 388 |
# File 'lib/virtual_module.rb', line 386 def vclass :summary end |