Skip to content

Commit 233a1c6

Browse files
authored
Merge pull request #84 from jdlangs/jl1.5fix
Restructure some typegen code to fix break in 1.5
2 parents 4df0ab0 + 769b7b1 commit 233a1c6

File tree

4 files changed

+47
-42
lines changed

4 files changed

+47
-42
lines changed

.travis.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
language: julia
22
julia:
33
- 1.0
4-
- 1.2
4+
- 1.5
55
- nightly
66
matrix:
77
allow_failures:
88
- julia: nightly
99
sudo: required
10-
dist: xenial
10+
dist: bionic
1111
env:
1212
global:
1313
- PYTHON=python
1414
before_install:
15-
- sudo apt-add-repository -y "deb http://packages.ros.org/ros/ubuntu xenial main"
16-
- wget https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -O - | sudo apt-key add -
15+
- sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
16+
- sudo apt-add-repository -y "deb http://packages.ros.org/ros/ubuntu bionic main"
1717
- sudo apt-get update
18-
- sudo apt-get -y install ros-kinetic-ros-base ros-kinetic-common-msgs
18+
- sudo apt-get -y install python-rosdep ros-melodic-ros-base ros-melodic-common-msgs
1919
- sudo rosdep init
2020
- rosdep update
2121
before_script:
2222
- export PATH=/usr/bin:$PATH
23-
- source /opt/ros/kinetic/setup.sh
23+
- source /opt/ros/melodic/setup.sh
2424
- roscore &
2525
- sleep 5
2626
- python test/echonode.py &

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "RobotOS"
22
uuid = "22415677-39a4-5241-a37a-00beabbbdae8"
3-
version = "0.7.1"
3+
version = "0.8.0"
44

55
[deps]
66
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"

src/gentypes.jl

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -430,13 +430,21 @@ function buildtype(mod::ROSSrvModule, typename::String)
430430
[reqexprs; respexprs; srvexprs]
431431
end
432432

433+
# Container for the generated expressions for each type
434+
struct ROSTypeExprs
435+
# The contents of the 'struct ... end' block
436+
member_decls::Vector{Expr}
437+
# The default values used for defining a no argument constructor
438+
constructor_defs::Vector{Any}
439+
# The conversions to PyObject
440+
conv_to_pyobj_args::Vector{Expr}
441+
# The conversion from PyObject
442+
conv_from_pyobj_args::Vector{Expr}
443+
end
444+
ROSTypeExprs() = ROSTypeExprs(Expr[], Expr[], Expr[], Expr[])
445+
433446
#Create the core generated expressions for a native Julia message type that has
434-
#data fields and interchanges with a python counterpart:
435-
# (1) the 'type ... end' block
436-
# (2) Default outer constructer with no arguments
437-
# (3) convert(PyObject, ...)
438-
# (4) convert(..., o::PyObject)
439-
# (5) getproperty for accessing member constants
447+
#data fields and interchanges with a python counterpart
440448
function typecode(rosname::String, super::Symbol, members::Vector)
441449
tname = _splittypestr(rosname)[2]
442450
@debug("Type: ", tname)
@@ -448,44 +456,52 @@ function typecode(rosname::String, super::Symbol, members::Vector)
448456
else; "ROS" end
449457
jlsym = Symbol(_jl_safe_name(tname,suffix))
450458

459+
#First generate the interior expressions for each member separately
460+
member_exprs = ROSTypeExprs()
461+
for (namestr,typ) in members
462+
@debug_addindent
463+
_addtypemember!(member_exprs, namestr, typ)
464+
@debug_subindent
465+
end
466+
467+
#Now build the full expressions
451468
exprs = Expr[]
452-
#First the empty expressions
453-
#(1) Type declaration
469+
# Type declaration
454470
push!(exprs, :(
455471
mutable struct $jlsym <: $super
456-
#Generated code here
472+
$(member_exprs.member_decls...)
457473
end
458474
))
459-
#(2) Default constructor, but only if the type has members
475+
# Default constructor, but only if the type has members
460476
if length(members) > 0
461477
push!(exprs, :(
462478
function $jlsym()
463-
$jlsym() #Generated code inside parens here
479+
$jlsym($(member_exprs.constructor_defs...))
464480
end
465481
))
466482
else
467483
push!(exprs, :())
468484
end
469-
#(3) Convert to PyObject
485+
# Convert to PyObject
470486
push!(exprs, :(
471487
function convert(::Type{PyObject}, o::$jlsym)
472488
py = pycall(RobotOS._rospy_objects[$rosname], PyObject)
473-
#Generated code here
489+
$(member_exprs.conv_to_pyobj_args...)
474490
py
475491
end
476492
))
477-
#(4) Convert from PyObject
493+
# Convert from PyObject
478494
push!(exprs, :(
479495
function convert(jlt::Type{$jlsym}, o::PyObject)
480496
if convert(String, o."_type") != _typerepr(jlt)
481497
throw(InexactError(:convert, $jlsym, o))
482498
end
483499
jl = $jlsym()
484-
#Generated code here
500+
$(member_exprs.conv_from_pyobj_args...)
485501
jl
486502
end
487503
))
488-
#(5) Accessing member variables through getproperty
504+
# Accessing member variables through getproperty
489505
push!(exprs, :(
490506
function getproperty(::Type{$jlsym}, s::Symbol)
491507
try getproperty(RobotOS._rospy_objects[$rosname], s)
@@ -499,28 +515,16 @@ function typecode(rosname::String, super::Symbol, members::Vector)
499515
end
500516
end
501517
))
502-
503-
#Now add the meat to the empty expressions above
504-
for (namestr,typ) in members
505-
@debug_addindent
506-
_addtypemember!(exprs, namestr, typ)
507-
@debug_subindent
508-
end
509518
push!(exprs, :(_typerepr(::Type{$jlsym}) = $rosname))
519+
510520
exprs
511521
end
512522

513-
514523
#Add the generated expression from a single member of a type, either built-in
515524
#or ROS type. `exprs` is the Expr objects of the items created in `typecode`.
516525
#Maybe this can be factored into something nicer.
517-
function _addtypemember!(exprs, namestr, typestr)
526+
function _addtypemember!(exprs::ROSTypeExprs, namestr, typestr)
518527
@debug("$namestr :: $typestr")
519-
typeargs = exprs[1].args[3].args
520-
consargs = exprs[2].args[2].args[2].args
521-
pyconargs = exprs[3].args[2].args
522-
jlconargs = exprs[4].args[2].args
523-
524528
if typestr == "char" || typestr == "byte"
525529
@warn("Use of type '$typestr' is deprecated in message definitions, " *
526530
"use '$(lowercase(string(_ros_builtin_types[typestr])))' instead.")
@@ -564,10 +568,11 @@ function _addtypemember!(exprs, namestr, typestr)
564568
jlconexpr = :(jl.$namesym = convert($j_typ, o.$namestr))
565569
pyconexpr = :(py.$namestr = convert(PyObject, o.$namesym))
566570
end
567-
push!(typeargs, memexpr)
568-
insert!(jlconargs, length(jlconargs), jlconexpr)
569-
insert!(pyconargs, length(pyconargs), pyconexpr)
570-
push!(consargs, defexpr)
571+
572+
push!(exprs.member_decls, memexpr)
573+
push!(exprs.constructor_defs, defexpr)
574+
push!(exprs.conv_to_pyobj_args, pyconexpr)
575+
push!(exprs.conv_from_pyobj_args, jlconexpr)
571576
end
572577

573578
#Build a String => Iterable{String} object from the individual package

test/rospy.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ init_node("jltest", anonymous=true)
66
#Parameters
77
@test length(RobotOS.get_param_names()) > 0
88
@test has_param("rosdistro")
9-
@test chomp(get_param("rosdistro")) in ["hydro", "indigo", "jade", "kinetic", "lunar", "melodic"]
9+
@test chomp(get_param("rosdistro")) in ["kinetic", "melodic", "noetic"]
1010
@test ! has_param("some_param")
1111
@test_throws KeyError get_param("some_param")
1212
@test_throws KeyError delete_param("some_param")

0 commit comments

Comments
 (0)