Skip to content

Commit

Permalink
intertype modules
Browse files Browse the repository at this point in the history
  • Loading branch information
olynch committed Oct 31, 2023
1 parent 1933a91 commit 97e9a7b
Show file tree
Hide file tree
Showing 6 changed files with 230 additions and 129 deletions.
55 changes: 44 additions & 11 deletions src/intertypes/InterTypes.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module InterTypes
export InterType, InterTypeDecl, Binary, intertype, as_intertypes
export InterType, InterTypeDecl, Binary, intertype, @intertypes

using MLStyle
using OrderedCollections
using ..Schemas

struct Field{T}
Expand All @@ -18,6 +19,29 @@ end

Base.nameof(variant::Variant) = variant.tag

@data RefPath begin
RefHere(name::Symbol)
RefThere(mod::RefPath, name::Symbol)
end

function RefPath(s::Symbol)
RefHere(s)
end

function RefPath(e::Expr)
@match e begin
Expr(:(.), rest, QuoteNode(name)) => RefThere(RefPath(rest), name)
_ => error("could not parse refpath from $e")
end
end

function toexpr(p::RefPath)
@match p begin
RefHere(name) => name
RefThere(mod, name) => Expr(:(.), toexpr(mod), QuoteNode(name))
end
end

@data InterType begin
I32
U32
Expand All @@ -34,23 +58,32 @@ Base.nameof(variant::Variant) = variant.tag
Sum(variants::Vector{Variant{InterType}})

Check warning on line 58 in src/intertypes/InterTypes.jl

View check run for this annotation

Codecov / codecov/patch

src/intertypes/InterTypes.jl#L57-L58

Added lines #L57 - L58 were not covered by tests
ACSetInterType(schema::TypedSchema{InterType})
Annot(desc::String, type::InterType)
TypeRef(to::Symbol)
TypeRef(to::RefPath)
end

@data InterTypeDecl begin
Alias(name::Symbol, type::InterType)
SumType(name::Symbol, variants::Vector{Variant{InterType}})
Struct(name::Symbol, fields::Vector{Field{InterType}})
SchemaDecl(name::Symbol, schema::TypedSchema{Symbol, InterType})
NamedACSetType(name::Symbol, schemaname::Symbol)
Alias(type::InterType)
SumType(variants::Vector{Variant{InterType}})
VariantOf(parent::Symbol)
Struct(fields::Vector{Field{InterType}})
SchemaDecl(schema::TypedSchema{Symbol, InterType})

Check warning on line 69 in src/intertypes/InterTypes.jl

View check run for this annotation

Codecov / codecov/patch

src/intertypes/InterTypes.jl#L69

Added line #L69 was not covered by tests
NamedACSetType(schemaname::Symbol)
end

Base.nameof(decl::InterTypeDecl) = @match decl begin
Alias(name, _) => name
SumType(name, _) => name
Struct(name, _) => name
struct InterTypeModule
name::Symbol
imports::OrderedDict{Symbol, InterTypeModule}
declarations::OrderedDict{Symbol, InterTypeDecl}
function InterTypeModule(
name::Symbol,
imports::OrderedDict{Symbol, InterTypeModule}=OrderedDict{Symbol, InterTypeModule}(),
declarations::OrderedDict{Symbol, InterTypeDecl}=OrderedDict{Symbol, InterTypeDecl}()
)
new(name, imports, declarations)
end
end


function intertype end

include("json.jl")
Expand Down
Loading

0 comments on commit 97e9a7b

Please sign in to comment.