Skip to content

Instantly share code, notes, and snippets.

@paniq
Last active December 1, 2019 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paniq/a4790427c41273d166532cdfaf0ff9df to your computer and use it in GitHub Desktop.
Save paniq/a4790427c41273d166532cdfaf0ff9df to your computer and use it in GitHub Desktop.
A module consists of three key-value stores mapping following types:
Blob DB: Id (u32) -> blob (arbitrary size...)
Hash DB: SHA-1 Hash (u160) -> Id (u32)
Edge DB: Edge IdId IdId (2 x u64) -> IdId (u64)
All keys and values are aigned to 8 bytes.
An Id is a integer mapping to a unique sequence of bytes. Simultaneously
with the Id, a hash DB is filled that maps the sequence's SHA-1 value to
an Id. Once an Id has been mapped to a blob, the mapping, and the blob itself
must not be mutated.
The same sequence of bytes will always resolve to the same Id locally within
a module. Hashes are compatible across databases, but Ids aren't.
Ids are themselves untyped, but can act as types - without a type, the blob
contents are opaque.
Edges describe directed connections from one typed Id to another using
a typed Id as edge label, in the sense that `source @ label = target`. Edges
are mutable, and therefore can be inserted, removed and changed freely.
An Id is typed when it is paired with a second Id that acts as a type
identifier, which is used to read the schema for the blob. The type
identifier's blob must follow an implicit schema as well.
A type identifier starts with an Id pointing to a zero-terminating string
that uniquely and globally identifies the type kind, followed by an arbitrary
pattern of bytes specific to that type.
Two types are equivalent when their sequences point to the same kind,
and contain the same typed ids.
There are several builtin, fundamental types:
untyped
type.typename <module-uri:StringId> <name:StringId> <super-type:TypeId> <storage-type:TypeId> <memoized-value:Any> ...
type.storage.integer <bitcount:i32> (negative bitcount: signed integer)
type.storage.real <bitcount:u32>
type.storage.pointer <flags:u32> <storage-class:StringId>
type.storage.array <element-type:TypeId> <size:u64>
type.storage.vector <element-type:TypeId> <size:u64>
type.storage.tuple [<element-type:TypeId> ...]
type.function <return-tuple-type:TypeId> <arguments-tuple-type:TypeId>
type.qualify <type:TypeId> <sorted-qualifier:TypeId> ...
subsequently, following builtin typenames are defined:
type.typename "builtin" "Nothing" untyped (type.storage.tuple)
type.typename "builtin" "Id" untyped (type.storage.integer 32)
type.typename "builtin" "Type" untyped (type.storage.integer 32)
type.typename "builtin" "Any" untyped (type.storage.tuple Type Id)
type.typename "builtin" "String" untyped (type.storage.integer 32)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment