xtype (halted)

Check-in [90e4f5b8b9]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Minor doc improvements.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 90e4f5b8b97bf39b0f76e2a8db844f5a71cd004ee1190003f72b4d3a117d074c
User & Date: imagic 2021-11-14 18:01:47.950
Original User & Date: imagic 2021-11-14 18:01:48.000
Context
2021-11-14
18:01
Handle multifunction candidates ambiguity. ... (check-in: ac195a58b8 user: imagic tags: trunk)
18:01
Minor doc improvements. ... (check-in: 90e4f5b8b9 user: imagic tags: trunk)
2021-11-11
20:10
Improve check functions to return booleans. ... (check-in: 9470e9e52e user: imagic tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to README.adoc.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
= xtype
ifdef::env-github[]
:tip-caption: :bulb:
:note-caption: :information_source:
:important-caption: :heavy_exclamation_mark:
:caution-caption: :fire:
:warning-caption: :warning:
endif::[]
:toc: left
:toclevels: 5

*xtype*, or Extended Type, is a dynamic type system library for Lua.

Sometimes, advanced type checking code is needed to implement specific abstractions; *xtype* aims to fill that need.

.Incentives:
Automation:: Prevent writing redundant type checking code.
Interoperability:: Having a general low-level type system library can ease the interactions of third-party code.
Metaprogramming / Genericity:: Exploit the dynamic nature of Lua to generate definitions on-the-fly.

See link:src[].

== Concepts














|


|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
= xtype
ifdef::env-github[]
:tip-caption: :bulb:
:note-caption: :information_source:
:important-caption: :heavy_exclamation_mark:
:caution-caption: :fire:
:warning-caption: :warning:
endif::[]
:toc: left
:toclevels: 5

*xtype*, or Extended Type, is a dynamic type system library for Lua.

Sometimes, advanced type checking code is needed to implement specific abstractions; *xtype* aims to fulfill that need.

.Incentives:
Simplification:: Prevent writing redundant type checking code.
Interoperability:: Having a general low-level type system library can ease the interactions of third-party code.
Metaprogramming / Genericity:: Exploit the dynamic nature of Lua to generate definitions on-the-fly.

See link:src[].

== Concepts

44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

A non-primitive type can inherit from other types, building a stack of types. This stack defines the order in which the types are evaluated, from the terminal type to the least specific inherited types.

=== Multifunction

A multifunction is a function that can have multiple definitions, each associated to a specific signature. When called, it resolves the call by selecting a matching definition from the call signature.

WARNING: Ambiguities are ignored.

==== Metaprogramming

We can use Lua as its own metaprogramming language: we can generate Lua code from Lua.

A multifunction can have generators that are called when no definitions could be found, allowing to generate definitions for specific call signatures on-the-fly.








|







44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

A non-primitive type can inherit from other types, building a stack of types. This stack defines the order in which the types are evaluated, from the terminal type to the least specific inherited types.

=== Multifunction

A multifunction is a function that can have multiple definitions, each associated to a specific signature. When called, it resolves the call by selecting a matching definition from the call signature.

WARNING: Ambiguities are ignored. If two definitions are candidates with the same weight, one will be selected arbitrarily.

==== Metaprogramming

We can use Lua as its own metaprogramming language: we can generate Lua code from Lua.

A multifunction can have generators that are called when no definitions could be found, allowing to generate definitions for specific call signatures on-the-fly.

Changes to src/xtype.lua.
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
    __index = multifunction,
    __call = default_call
  }
  return setmetatable({
    hsign = new_hsign(),
    definitions = {}, -- map of sign hash => {.f, .sign}
    generators = {}, -- set of generator functions
    candidates = {}, -- cached candidates, map of hash => {def, dist}
    max_calln = 0, -- maximum call parameters
    call = default_call
  }, multifunction_mt)
end

-- Code generation tools.








|







416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
    __index = multifunction,
    __call = default_call
  }
  return setmetatable({
    hsign = new_hsign(),
    definitions = {}, -- map of sign hash => {.f, .sign}
    generators = {}, -- set of generator functions
    candidates = {}, -- cached candidates, map of call sign hash => {def, dist}
    max_calln = 0, -- maximum call parameters
    call = default_call
  }, multifunction_mt)
end

-- Code generation tools.