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

InterTypes #75

Merged
merged 14 commits into from
Nov 2, 2023
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ Manifest.toml
.DS_Store
.vscode
.ipynb_checkpoints
test/.CondaPkg
test/intertypes/__pycache__
5 changes: 5 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@ version = "0.2.9"

[deps]
AlgebraicInterfaces = "23cfdc9f-0504-424a-be1f-4892b28e2f0c"
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
CompTime = "0fb5dd42-039a-4ca4-a1d7-89a96eae6d39"
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
MLStyle = "d8e11817-5142-5d16-987a-aa16d5891078"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
Permutations = "2ae35dd2-176d-5d53-8349-f30d82d94d4f"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
StructEquality = "6ec83bb0-ed9f-11e9-3b4c-2b04cb4e219c"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/ACSets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ include("PreimageCaches.jl")
include("Columns.jl")
include("ColumnImplementations.jl")
include("Schemas.jl")
include("intertypes/InterTypes.jl")
include("ACSetInterface.jl")
include("DenseACSets.jl")
include("serialization/Serialization.jl")
Expand All @@ -17,6 +18,7 @@ include("NautyInterface.jl")

@reexport using .ColumnImplementations: AttrVar
@reexport using .Schemas
@reexport using .InterTypes
@reexport using .ACSetInterface
@reexport using .DenseACSets
@reexport using .ACSetSerialization
Expand Down
11 changes: 10 additions & 1 deletion src/Schemas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ module Schemas

export Schema, TypeLevelSchema, BasicSchema, TypeLevelBasicSchema, typelevel,
objects, attrtypes, attrtype_instantiation, homs, attrs, arrows, dom, codom,
ob, hom, attrtype, attr, dom_nums, codom_nums, adom_nums, acodom_nums, types
ob, hom, attrtype, attr, dom_nums, codom_nums, adom_nums, acodom_nums, types,
TypedSchema

using StructEquality
import AlgebraicInterfaces: dom, codom, ob, hom, attr, attrtype
Expand Down Expand Up @@ -250,4 +251,12 @@ codom_nums(s) = Tuple(findfirst(objects(s) .== c) for (_,_,c) in homs(s))
adom_nums(s) = Tuple(findfirst(objects(s) .== d) for (_,d,_) in attrs(s))
acodom_nums(s) = Tuple(findfirst(attrtypes(s) .== c) for (_,_,c) in attrs(s))

# Typed Schemas
###############

struct TypedSchema{Name, T}
schema::BasicSchema{Name}
types::Dict{Symbol, T}
end

end
96 changes: 96 additions & 0 deletions src/intertypes/InterTypes.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
module InterTypes
export InterType, InterTypeDecl, Binary, intertype, @intertypes

using MLStyle
using OrderedCollections
using ..Schemas

struct Field{T}
name::Symbol
type::T
end

Base.nameof(field::Field) = field.name

struct Variant{T}
tag::Symbol
fields::Vector{Field{T}}
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
I64
U64
F64
Boolean
Str
Sym
Binary
List(elemtype::InterType)
Map(keytype::InterType, valuetype::InterType)
Record(fields::Vector{Field{InterType}})
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::RefPath)
end

@data InterTypeDecl begin
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

function hashdecls end

struct InterTypeModule
name::Symbol
imports::OrderedDict{Symbol, InterTypeModule}
declarations::OrderedDict{Symbol, InterTypeDecl}
hash::String
function InterTypeModule(
name::Symbol,
imports::OrderedDict{Symbol, InterTypeModule}=OrderedDict{Symbol, InterTypeModule}(),
declarations::OrderedDict{Symbol, InterTypeDecl}=OrderedDict{Symbol, InterTypeDecl}()
)
new(name, imports, declarations, hashdecls(declarations))
end
end

function intertype end

include("json.jl")
include("sexp.jl")
include("julia.jl")
include("python.jl")

end
Loading