Skip to content

Improvements to static-show #239

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

Merged
merged 3 commits into from
Jun 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions base/namedtuple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,8 @@ function convert(::Type{NT}, nt::NamedTuple{names}) where {names, T<:Tuple, NT<:
end

if nameof(@__MODULE__) === :Base
Tuple(nt::NamedTuple) = (nt...,)
(::Type{T})(nt::NamedTuple) where {T <: Tuple} = (t = Tuple(nt); t isa T ? t : convert(T, t)::T)
end
Tuple(nt::NamedTuple) = (nt...,)
(::Type{T})(nt::NamedTuple) where {T <: Tuple} = (t = Tuple(nt); t isa T ? t : convert(T, t)::T)

function show(io::IO, t::NamedTuple)
n = nfields(t)
Expand Down Expand Up @@ -233,6 +232,7 @@ function show(io::IO, t::NamedTuple)
print(io, ")")
end
end
end

eltype(::Type{T}) where T<:NamedTuple = nteltype(T)
nteltype(::Type) = Any
Expand Down
2 changes: 1 addition & 1 deletion base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1744,7 +1744,7 @@ function show_sym(io::IO, sym::Symbol; allow_macroname=false)
print(io, '@')
show_sym(io, Symbol(sym_str[2:end]))
else
print(io, "var", repr(string(sym)))
print(io, "var", repr(string(sym))) # TODO: this is not quite right, since repr uses String escaping rules, and Symbol uses raw string rules
end
end

Expand Down
10 changes: 5 additions & 5 deletions src/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ JL_DLLEXPORT jl_value_t *jl_copy_ast(jl_value_t *expr)
return expr;
}

JL_DLLEXPORT int jl_is_operator(char *sym)
JL_DLLEXPORT int jl_is_operator(const char *sym)
{
jl_ast_context_t *ctx = jl_ast_ctx_enter(NULL);
fl_context_t *fl_ctx = &ctx->fl;
Expand All @@ -987,7 +987,7 @@ JL_DLLEXPORT int jl_is_operator(char *sym)
return res;
}

JL_DLLEXPORT int jl_is_unary_operator(char *sym)
JL_DLLEXPORT int jl_is_unary_operator(const char *sym)
{
jl_ast_context_t *ctx = jl_ast_ctx_enter(NULL);
fl_context_t *fl_ctx = &ctx->fl;
Expand All @@ -996,7 +996,7 @@ JL_DLLEXPORT int jl_is_unary_operator(char *sym)
return res;
}

JL_DLLEXPORT int jl_is_unary_and_binary_operator(char *sym)
JL_DLLEXPORT int jl_is_unary_and_binary_operator(const char *sym)
{
jl_ast_context_t *ctx = jl_ast_ctx_enter(NULL);
fl_context_t *fl_ctx = &ctx->fl;
Expand All @@ -1005,7 +1005,7 @@ JL_DLLEXPORT int jl_is_unary_and_binary_operator(char *sym)
return res;
}

JL_DLLEXPORT int jl_is_syntactic_operator(char *sym)
JL_DLLEXPORT int jl_is_syntactic_operator(const char *sym)
{
jl_ast_context_t *ctx = jl_ast_ctx_enter(NULL);
fl_context_t *fl_ctx = &ctx->fl;
Expand All @@ -1014,7 +1014,7 @@ JL_DLLEXPORT int jl_is_syntactic_operator(char *sym)
return res;
}

JL_DLLEXPORT int jl_operator_precedence(char *sym)
JL_DLLEXPORT int jl_operator_precedence(const char *sym)
{
jl_ast_context_t *ctx = jl_ast_ctx_enter(NULL);
fl_context_t *fl_ctx = &ctx->fl;
Expand Down
2 changes: 1 addition & 1 deletion src/flisp/print.c
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ static void print_string(fl_context_t *fl_ctx, ios_t *f, char *str, size_t sz)
}
else {
while (i < sz) {
size_t n = u8_escape(buf, sizeof(buf), str, &i, sz, 1, 0);
size_t n = u8_escape(buf, sizeof(buf), str, &i, sz, "\"", 0);
outsn(fl_ctx, buf, f, n-1);
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -1961,11 +1961,11 @@ JL_DLLEXPORT jl_array_t *jl_uncompress_argnames(jl_value_t *syms);
JL_DLLEXPORT jl_value_t *jl_uncompress_argname_n(jl_value_t *syms, size_t i);


JL_DLLEXPORT int jl_is_operator(char *sym);
JL_DLLEXPORT int jl_is_unary_operator(char *sym);
JL_DLLEXPORT int jl_is_unary_and_binary_operator(char *sym);
JL_DLLEXPORT int jl_is_syntactic_operator(char *sym);
JL_DLLEXPORT int jl_operator_precedence(char *sym);
JL_DLLEXPORT int jl_is_operator(const char *sym);
JL_DLLEXPORT int jl_is_unary_operator(const char *sym);
JL_DLLEXPORT int jl_is_unary_and_binary_operator(const char *sym);
JL_DLLEXPORT int jl_is_syntactic_operator(const char *sym);
JL_DLLEXPORT int jl_operator_precedence(const char *sym);

STATIC_INLINE int jl_vinfo_sa(uint8_t vi)
{
Expand Down
Loading