Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use macros to define messages rather than eval #45

Merged
merged 22 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c6aabb1
refactor(msg): use macros to define messages rather than eval (WIP)
mchitre Jan 23, 2024
a3c5363
refactor: improve message implementation
mchitre Jan 28, 2024
d64b36a
fix: register messages defined in Fjage
mchitre Jan 29, 2024
f3eb9cb
style: cosmetic improvements to code
mchitre Jan 29, 2024
630f264
refactor: improve GenericMessages and JSONification
mchitre Jan 29, 2024
d429569
test: fix test cases and cosmetic improvements
mchitre Jan 29, 2024
02fb6ba
refactor: make invalid properties for messages throw errors unless in…
mchitre Jan 31, 2024
1b2a489
refactor: drop unnecessary property handling code
mchitre Jan 31, 2024
12c3fe9
test: fix fjage version for testing
mchitre Jan 31, 2024
eee6eef
fix(msg): drop eval for performative and let it be interpolated in
mchitre Feb 1, 2024
fe5470a
test: add test case that uses performative in message definition
mchitre Feb 1, 2024
51bcd26
fix(msg): only assume Fjage symbol to be in scope of caller
mchitre Feb 1, 2024
7a15935
feat(msg): improve pretty printing
mchitre Feb 1, 2024
bba1083
doc: update docs to reflect new message definition API
mchitre Feb 1, 2024
993e261
refactor: Escape more narrowly in @message
ettersi Feb 2, 2024
030e6c8
fix(kwdef): Copy over Base.isexpr
ettersi Feb 4, 2024
868f916
fix(container): update container to use new message format
mchitre Feb 4, 2024
0088453
fix(msg): handle NaNs, inheritance and fix readonly property in Param…
mchitre Feb 4, 2024
55c290e
refactor(msg): use _Concrete prefix and use applicable() instead of t…
mchitre Feb 5, 2024
9af5a95
refactor: replace reporterror with logerror
mchitre Feb 5, 2024
80bdf6c
fix(kwdef): Delete @show that was added for debugging
ettersi Feb 7, 2024
7c5afd6
docs(kwdef): xref PR
ettersi Feb 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/gw.jl
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ function _inflate(json::AbstractDict)
elseif k == "msgID"
k = "messageID"
end
setproperty!(obj, Symbol(k), v)
setproperty!(obj, Symbol(k), v; ignore_missingfields=true)
end
obj
end
Expand Down
21 changes: 14 additions & 7 deletions src/msg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,18 @@ end
# adds notation message.field

function Base.getproperty(s::Message, p::Symbol)
mchitre marked this conversation as resolved.
Show resolved Hide resolved
hasfield(typeof(s), p) || return nothing
hasfield(typeof(s), p) || error("message $(typeof(s)) has no field $(p)")
getfield(s, p)
end

function Base.setproperty!(s::Message, p::Symbol, v)
hasfield(typeof(s), p) || return s
ftype = fieldtype(typeof(s), p)
setfield!(s, p, convert(ftype, v))
function Base.setproperty!(s::Message, p::Symbol, v; ignore_missingfields=false)
mchitre marked this conversation as resolved.
Show resolved Hide resolved
if hasfield(typeof(s), p)
ftype = fieldtype(typeof(s), p)
setfield!(s, p, convert(ftype, v))
else
ignore_missingfields || error("message $(typeof(s)) has no field $(p)")
s
end
end

# immutable dictionary interface for Messages
Expand Down Expand Up @@ -255,10 +259,13 @@ GenericMessage(clazz::String, perf::Symbol=Performative.INFORM; kwargs...) = Gen
function Base.getproperty(s::GenericMessage, p::Symbol)
hasfield(typeof(s), p) && return getfield(s, p)
haskey(s.__data__, p) && return s.__data__[p]
nothing
clazz = classname(s)
ndx = findlast(".", clazz)
ndx === nothing || (clazz = clazz[ndx[1]+1:end])
error("message $(clazz) has no field $(p)")
end

function Base.setproperty!(s::GenericMessage, p::Symbol, v)
function Base.setproperty!(s::GenericMessage, p::Symbol, v; ignore_missingfields=false)
if hasfield(typeof(s), p)
setfield!(s, p, v)
else
Expand Down
Loading