Darren Duncan > Muldis-D-0.41.0 > Muldis::D::Dialect::HDMD_Perl_Tiny

Download:
Muldis-D-0.41.0.tar.gz

Annotate this POD

CPAN RT

Open  0
Report a bug
Source   Latest Release: Muldis-D-0.53.0

NAME ^

Muldis::D::Dialect::HDMD_Perl_Tiny - How to format Perl Hosted Data Muldis D

VERSION ^

This document is Muldis::D::Dialect::HDMD_Perl_Tiny version 0.22.1.

PREFACE ^

This document is part of the Muldis D language specification, whose root document is Muldis::D; you should read that root document before you read this one, which provides subservient details.

DESCRIPTION ^

This document outlines the grammar of the Hosted Data Muldis D dialect named HDMD_Perl_Tiny. The fully-qualified name of this Muldis D dialect, in combination with the base language spec it is bundled with, is Muldis_D:'http://muldis.com':'N.N.N':'HDMD_Perl_Tiny' (when the bundled base language version is substituted for the N.N.N).

This dialect is designed to exactly match the Muldis D system catalog (the possible representation of Muldis D code that is visible to or updateable by Muldis D programs at runtime) as to what non-critical meta-data it explicitly stores; so code in the HDMD_Perl_Tiny dialect should be round-trippable with the system catalog with the result maintaining all the details that were started with. Since it matches the system catalog, this dialect should be able to exactly represent all possible Muldis D base language code (and probably all extensions too), rather than a subset of it. This dialect similarly matches the PTMD_Tiny dialect, which is documented at Muldis::D::Dialect::PTMD_Tiny.

This dialect is designed to be as small as possible while meeting the above criteria, and is designed such that a parser that handles all of this dialect can be tiny, hence the dialect's Tiny name. Likewise, a code generator for this dialect from the system catalog can be tiny.

The HDMD_Perl_Tiny dialect is defined to be hosted in either Perl 5 or Perl 6, and as composed of just|mainly core Perl types. Where Perl 5 and 6 differ, the terminology and examples in this documentation specifically uses Perl 6 terminology and examples by default, and adds analogous Perl 5 terminology as necessary.

Fundamentally, the various Muldis D scalar and collection types are represented by their equivalent Perl 5 or 6 native scalar and collection types. But since Muldis D is more strongly typed, or at least differently typed, than Perl, each Muldis D literal is represented by a Perl Array, whose elements include both the payload Perl literal plus explicit meta-data for how to interpret that Perl literal for mapping to Muldis D.

This document mainly just specifies a way to represent Muldis D values as Perl values. Since the fundamental way to do data definition in Muldis D is to update catalog (information schema) variables, aka the Muldis D meta-model, which are themselves just data, then this document only needs to tell you how to define values to put in the catalog variables. Defining data types or routines are done by defining catalog values describing them.

See instead Muldis::D::Core for how to actually define the tuples and relations that define your data types and routines and queries and so forth.

For the present, this document will use the term PHMD (Perl Hosted Muldis D) for brevity when referring to aspects of the Perl-Tiny dialect.

GENERAL STRUCTURE ^

A PHMD value is composed mainly of a tree of Perl Array, such that each Array is a tree node. The elements of each node/Array include typically a native Perl payload value, which may be a PHMD value itself, plus meta-data for that payload, that meta-data typically including the analogy of a class name, were PHMD nodes instead represented by a tree of PHMD-specific objects. As an exception, one kind of PHMD node is not a Perl Array, but just a Perl Str; if you see a Str where you expect a PHMD node, assume it is a Name node; this exception is for huffmanizing.

It should be emphasized that no Perl undefined values are allowed anywhere in a PHMD value; you must use only defined values instead. This documentation also assumes that only defined values are used, and that supplying a Perl undef will result in an error. If you genuinely want to represent that a value is unknown or inapplicable, then the Nothing node type is provided as one way you can explicitly say so. This policy may be reconsidered.

BOOTLOADER ^

A full or partial Muldis D bootloader routine consists of a language name declaration plus a series of 0..N procedure calls (specifically procedures with no subject-to-update parameters). A bootloader is formatted as a PHMD node having 1..N elements, where the first element is a PHMD node defining a Muldis D "language name", and each remaining element is a PHMD node defining a "bootloader procedure call".

Examples:

    [
        [ 'Muldis_D', 'http://muldis.com', '1.2.3', 'HDMD_Perl_Tiny', {} ],
        [ 'boot_call', 'sys.std.Core.Cat.create_public_relvar', { ... } ],
    ]

LANGUAGE NAME ^

As per the VERSIONING pod section of Muldis::D, code written in Muldis D must start by declaring the fully-qualified Muldis D language name it is written in. The HDMD_Perl_Tiny dialect formats this name as a PHMD node having the following 5 elements:

Examples:

    [ 'Muldis_D', 'http://muldis.com', '1.2.3', 'HDMD_Perl_Tiny', {} ]

More specifically, a language name PHMD node like the above would generally be the input for a Perl Hosted Muldis D implementating virtual machine's configuration step, which provides a context for subsequent feeding of other PHMD trees to said virtual machine.

BOOTLOADER PROCEDURE CALL ^

This PHMD node specifies one statement of a Muldis D bootloader routine which invokes a procedure, such statements being what the entire body of a bootloader is composed of. A bootloader procedure call is formatted as a PHMD node having the following 3 elements:

Examples

    [ 'boot_call', 'sys.std.Core.Cat.create_public_relvar', { ... } ]

CORE GENERIC SCALAR VALUES ^

sys.std.Core.Type.Scalar

This node type represents a scalar subtype value. It has 4 elements:

This node is interpreted as a Muldis D sys.std.Core.Type.Scalar subtype value whose declared type is specified by the scalar type name (second node element) and whose attributes are defined by the payload. The Scalar PHMD node type can only be used for scalar types that have at least 1 possrep, and the payload is interpreted specifically as attributes of the declared type's possrep which is specified by the possrep name (third node element). Each key+value pair of the payload defines a named possrep attribute of the new scalar; the pair's key and value are, respectively, a Perl Str that specifies the possrep attribute name, and a PHMD node that specifies the possrep attribute value. (Note that most scalar types have at least 1 possrep; the only ones that don't are either union types of types having possreps, or they are core system-defined types, and those all have their own dedicated syntax for literals.)

Examples:

    [ 'Scalar', 'sys.std.Rational.Type.Rat', 'float', {
        'mantissa' => [ 'Int', 'perl_int', 45207196 ],
        'radix'    => [ 'Int', 'perl_int', 10 ],
        'exponent' => [ 'Int', 'perl_int', 37 ],
    } ]

    [ 'Scalar', 'fed.lib.the_db.WeekDay', 'name', {
        '' => [ 'Text', 'monday' ],
    } ]

    [ 'Scalar', 'fed.lib.the_db.WeekDay', 'number', {
        '' => [ 'Int', 'perl_int', 5 ],
    } ]

sys.std.Core.Type.Bool

This node type represents a logical boolean value. It has 3 elements:

This node is interpreted as a Muldis D sys.std.Core.Type.Bool value as follows:

Examples:

    [ 'Bool', 'md_enum', 'true' ]

    [ 'Bool', 'perl_bool', Bool::False ] # Perl 6 only

    [ 'Bool', 'perl_bool', (1 == 0) ]

    [ 'Bool', 'perl_any', 42 ]

sys.std.Core.Type.Int

This node type represents an integer value. It has 3-4 elements:

This node is interpreted as a Muldis D sys.std.Core.Type.Int value as follows:

Examples:

    [ 'Int', 'md_int', '1', '11001001' ] # binary

    [ 'Int', 'md_int', '7', '0' ] # octal

    [ 'Int', 'md_int', '7', '644' ] # octal

    [ 'Int', 'md_int', '9', '-34' ] # decimal

    [ 'Int', 'md_int', '9', '42' ] # decimal

    [ 'Int', 'md_int', 'F', 'DEADBEEF' ] # hexadecimal

    [ 'Int', 'md_int', 'Z', '-HELLOWORLD' ] # base-36

    [ 'Int', 'perl_int', 21 ]

    [ 'Int', 'any_perl', ' 171 ' ]

    [ 'Int', 'md_int', '3', '301' ] # base-4

    [ 'Int', 'perl_int', 0 ]

    [ 'Int', 'md_int', 'B', 'A09B' ] # base-12

    [ 'Int', 'perl_int', 101 ]

sys.std.Core.Type.Blob

This node type represents a bit string. It has 3-4 elements:

This node is interpreted as a Muldis D sys.std.Core.Type.Blob value as follows:

Examples:

    [ 'Blob', 'md_blob', '1', '00101110100010' ] # binary

    [ 'Blob', 'md_blob', '3', '' ]

    [ 'Blob', 'md_blob', 'F', 'A705E' ] # hexadecimal

    [ 'Blob', 'perl_blob', (pack 'H2', 'P') ]

    [ 'Blob', 'md_blob', '7', '523504376' ]

    [ 'Blob', 'perl_blob', (pack 'H2', 'Z') ]

sys.std.Core.Type.Text

This node type represents a character string. It has 2 elements:

This node is interpreted as a Muldis D sys.std.Core.Type.Text value by directly mapping the payload. Note that, while Plain Text Muldis D may contain a few escape sequences, those would be replaced with what they represent prior to making a PHMD node. Under Perl 6, the payload must be a Perl Str, which is mapped directly. Under Perl 5, the payload must be just a canonical Perl character string, which is a scalar whose utf-8 flag is true, or that doesn't contain any octets with a 1-valued highest bit.

Examples:

    [ 'Text', 'Ceres' ]

    [ 'Text', 'サンプル' ] # note: Perl 5 needs "use utf8;" pragma to work

    [ 'Text', '' ]

    [ 'Text', 'Perl' ]

CORE GENERIC NONSCALAR VALUES ^

sys.std.Core.Type.Tuple

This node type represents a tuple value. It has 2 elements:

This node is interpreted as a Muldis D sys.std.Core.Type.Tuple value whose attributes are defined by the payload. Each key+value pair of the payload defines a named attribute of the new tuple; the pair's key and value are, respectively, a Perl Str that specifies the attribute name, and a PHMD node that specifies the attribute value.

Examples:

    [ 'Tuple', {} ]

    [ 'Tuple', {
        'login_name' => [ 'Text', 'hartmark' ],
        'login_pass' => [ 'Text', 'letmein' ],
        'is_special' => [ 'Bool', 'md_enum', 'true' ],
    } ]

    [ 'Tuple', {
        'name' => [ 'Text', 'Michelle' ],
        'age'  => [ 'Int', 'perl_int', 17 ],
    } ]

sys.std.Core.Type.Relation

This node type represents a relation value. It has 2-3 elements:

This node is interpreted as a Muldis D sys.std.Core.Type.Relation value as follows:

Examples:

    [ 'Relation', [] ]

    [ 'Relation', [ {}, ] ]

    [ 'Relation', [ 'x', 'y', 'z', ] ]

    [ 'Relation', [
        {
            'login_name' => [ 'Text', 'hartmark' ],
            'login_pass' => [ 'Text', 'letmein' ],
            'is_special' => [ 'Bool', 'md_enum', 'true' ],
        },
    ] ]

    [ 'Relation', [ 'name', 'age', ], [
        [ [ 'Text', 'Michelle' ], [ 'Int', 'perl_int', 17 ], ],
    ] ]

sys.std.Core.Type.Set

This node type represents a set value. It has 2 elements:

This node is interpreted as a Muldis D sys.std.Core.Type.Set value whose elements are defined by the payload. Each element of the payload defines a unary tuple of the new set; each element is a PHMD node that defines the value attribute of the tuple.

Examples:

    [ 'Set', [
        [ 'Text', 'Canada' ],
        [ 'Text', 'Spain' ],
        [ 'Text', 'Jordan' ],
        [ 'Text', 'Thailand' ],
    ] ]

    [ 'Set', [
        [ 'Int', 'perl_int', 3 ],
        [ 'Int', 'perl_int', 16 ],
        [ 'Int', 'perl_int', 85 ],
    ] ]

sys.std.Core.Type.Nothing

This node type represents a 'nothing' value; it is interpreted as a Muldis D sys.std.Core.Type.Nothing. It has 1 element, which is the Perl Str value Nothing.

Examples:

    [ 'Nothing' ]

sys.std.Core.Type.Single

This node type represents a 'single' value. It has 2 elements:

This node is interpreted as a Muldis D sys.std.Core.Type.Single value whose element is defined by the payload. The payload is a PHMD node that defines the value attribute of the single tuple of the new 'single'.

Examples:

    [ 'Single', [ 'Text', '2003.07.24' ] ]

sys.std.Core.Type.Array

This node type represents a sequence value. It has 2 elements:

This node is interpreted as a Muldis D sys.std.Core.Type.Array value whose elements are defined by the payload. Each element of the payload defines a binary tuple of the new sequence; the element value is a PHMD node that defines the value attribute of the tuple, and the element index is used as the index attribute of the tuple.

Examples:

    [ 'Array', [
        [ 'Text', 'Alphonse' ],
        [ 'Text', 'Edward' ],
        [ 'Text', 'Winry' ],
    ] ]

    [ 'Array', [
        [ 'Int', 'perl_int', 57 ],
        [ 'Int', 'perl_int', 45 ],
        [ 'Int', 'perl_int', 63 ],
        [ 'Int', 'perl_int', 61 ],
    ] ]

sys.std.Core.Type.Bag

This node type represents a bag value. It has 3 elements:

This node is interpreted as a Muldis D sys.std.Core.Type.Bag value whose elements are defined by the payload. The payload is interpreted as follows:

Examples:

    [ 'Bag', 'aoa_counted', [
        [
            [ 'Text', 'Apple' ],
            [ 'md_int', '9', '500' ],
        ],
        [
            [ 'Text', 'Orange' ],
            [ 'perl_int', 300 ],
        ],
        [
            [ 'Text', 'Banana' ],
            [ 'perl_int', 400 ],
        ],
    ] ]

    [ 'Bag', 'array_repeated', [
        [ 'Text', 'Foo' ],
        [ 'Text', 'Quux' ],
        [ 'Text', 'Foo' ],
        [ 'Text', 'Bar' ],
        [ 'Text', 'Baz' ],
        [ 'Text', 'Baz' ],
    ] ]

QUASI- VALUES ^

Every PHMD node type for a generic scalar or nonscalar literal has a corresponding extra PHMD node type for a quasi- literal. The corresponding extra quasi- node types are exactly the same in format to the non-quasi types but that for each one of them, the value of its first element has the Perl Str value Quasi prepended. So PHMD nodes whose first elements each are [QuasiScalar, QuasiTuple, QuasiRelation, QuasiSet, QuasiNothing, QuasiSingle, QuasiArray, QuasiBag] are interpreted as Muldis D [sys.std.Core.Type.QuasiScalar, sys.std.Core.Type.QuasiTuple, sys.std.Core.Type.QuasiRelation, sys.std.Core.Type.QuasiSet, sys.std.Core.Type.QuasiNothing, sys.std.Core.Type.QuasiSingle, sys.std.Core.Type.QuasiArray, sys.std.Core.Type.QuasiBag] values, respectively.

CATALOG SCALAR VALUES ^

sys.std.Core.Type.Cat.Name

This node type represents a canonical short name for any kind of DBMS entity when declaring it; it is a character string type, that is disjoint from Text.

Unlike every other PHMD node type, a canonical short name is simply a Perl Str value, which is its payload; it is not encapsulated in a Perl Array; this difference is done for huffmanizing reasons, since a short name is probably the most often used node type, and moreover this change allows for simplifying other parts of the grammar.

This node is interpreted as a Muldis D sys.std.Core.Type.Cat.Name value by directly mapping itself / the payload. Note that, while Plain Text Muldis D may contain a few escape sequences, those would be replaced with what they represent prior to making a PHMD node. The node / its payload must be as per the payload of a Text PHMD node.

Examples:

    'login_pass'

    'First Name'

sys.std.Core.Type.Cat.NameChain

This node type represents a canonical long name for invoking a DBMS entity in some contexts; it is conceptually a sequence of entity short names. It has 2 elements:

This node is interpreted as a Muldis D sys.std.Core.Type.Cat.NameChain value as follows:

Examples:

    [ 'NameChain', ['fed','data','the_db','gene','sorted_person_name'] ]

    [ 'NameChain', 'fed.data.the_db.stats.samples_by_order' ]

sys.std.Core.Type.Cat.DeclNameChain

This node type represents a canonical long name for declaring a DBMS entity in N-depth contexts; it is conceptually a sequence of entity short names. It has 2 elements:

This node is interpreted as a Muldis D sys.std.Core.Type.Cat.DeclNameChain value as follows:

Examples:

    [ 'DeclNameChain', ['gene','sorted_person_name'] ]

    [ 'DeclNameChain', '.stats.samples_by_order.' ]

sys.std.Core.Type.Cat.Comment

This node type represents the text of a Muldis D code comment; it is a character string type, that is disjoint from both Text and Name. It has 2 elements:

This node is interpreted as a Muldis D sys.std.Core.Type.Cat.Comment value by directly mapping the payload. Note that, while Plain Text Muldis D may contain a few escape sequences, those would be replaced with what they represent prior to making a PHMD node. The payload must be as per the payload of a Text PHMD node.

Examples:

    [ 'Comment', 'This does something.' ]

sys.std.Core.Type.Cat.Order

This node type represents an order-determination. It has 3 elements:

This node is interpreted as a Muldis D sys.std.Core.Type.Cat.Order value as follows:

Examples:

    [ 'Order', 'md_enum', 'same' ]

    [ 'Order', 'perl_order', Order::Increase ] # Perl 6 only

    [ 'Order', 'perl_order', (2 <=> 1) ]

RATIONAL EXTENSION SCALAR VALUES ^

sys.std.Rational.Type.Rat

This node type represents a rational value. It has 3-4 elements:

This node is interpreted as a Muldis D sys.std.Rational.Type.Rat value as follows:

Examples:

    [ 'Rat', 'md_radix', '1', '-1.1' ]

    [ 'Rat', 'md_radix', '9', '-1.5' ] # same val as prev

    [ 'Rat', 'md_radix', '9', '3.14159' ]

    [ 'Rat', 'md_radix', 'A', '0.0' ]

    [ 'Rat', 'md_radix', 'F', 'DEADBEEF.FACE' ]

    [ 'Rat', 'md_radix', 'Z', '0.000AZE' ]

    [ 'Rat', 'md_ratio', '6', [ '500001', '1000' ] ]

    [ 'Rat', 'md_ratio', 'B', [ 'A09B', 'A' ] ]

    [ 'Rat', 'md_float', '1', [ '1011101101', '10', '-11011' ] ]

    [ 'Rat', 'md_float', '9', [ '45207196', '10', '37' ] ]

    [ 'Rat', 'perl_rat', 21.003 ]

    [ 'Rat', 'perl_float', 5.428**295 ]

    [ 'Rat', 'perl_int_ratio', [ 1, 43 ] ]

    [ 'Rat', 'perl_int_float', [ 314159, 10, -5 ] ]

    [ 'Rat', 'any_perl', ' 54.67 ' ]

    [ 'Rat', 'any_perl_ratio', [ ' 57 ', ' 71 ' ] ]

    [ 'Rat', 'any_perl_float', [ ' 656573456 ', ' 8 ', ' 243323 ' ] ]

sys.std.Rational.Type.RatRoundMeth

This node type represents a rounding method. It has 2 elements:

This node is interpreted as a Muldis D sys.std.Rational.Type.RatRoundMeth value by directly mapping the payload. The payload must be a Perl Str having one of the 7 values half_down, half_up, half_even, to_floor, to_ceiling, to_zero, to_inf.

Examples:

    [ 'RatRoundMeth', 'half_up' ]

SEE ALSO ^

Go to Muldis::D for the majority of distribution-internal references, and Muldis::D::SeeAlso for the majority of distribution-external references.

AUTHOR ^

Darren Duncan (perl@DarrenDuncan.net)

LICENSE AND COPYRIGHT ^

This file is part of the formal specification of the Muldis D language.

Muldis D is Copyright © 2002-2008, Darren Duncan.

See the LICENSE AND COPYRIGHT of Muldis::D for details.

TRADEMARK POLICY ^

The TRADEMARK POLICY in Muldis::D applies to this file too.

ACKNOWLEDGEMENTS ^

The ACKNOWLEDGEMENTS in Muldis::D apply to this file too.