<?xml version="1.0" encoding="UTF-8"?>
<chapter version="5.1" xmlns="http://docbook.org/ns/docbook"
         xmlns:xlink="http://www.w3.org/1999/xlink"
         xmlns:xila="http://www.w3.org/2001/XInclude/local-attributes"
         xmlns:xi="http://www.w3.org/2001/XInclude"
         xmlns:trans="http://docbook.org/ns/transclusion"
         xmlns:svg="http://www.w3.org/2000/svg"
         xmlns:m="http://www.w3.org/1998/Math/MathML"
         xmlns:html="http://www.w3.org/1999/xhtml"
         xmlns:db="http://docbook.org/ns/docbook">
  <?xxe-sn 2b06cb2u4g0 1?>

  <title><?xxe-sn 2b06cb2u4g0 2?>Xreate Manual</title>

  <para><?xxe-sn 2b06cb2u4g0 6?>Xreate is an open source general purpose high
  level programming language designed to write efficient and safe computer
  programs.</para>

  <para><?xxe-sn 2b06cb2u4g0 8?>Here "high level" has very specific meaning as
  an ability to easily write, read, as well as adapt software to a constantly
  changing environment or business goals. In this respect, any software
  product can be evaluated on the basis of the three dimensions: efficiency,
  safety and adaptability. Unfortunately, those properties are proved to be
  largely contradictory for it is manageable to write either efficient(still
  unsafe) or safe(and impractical) code, but not both. Thus, the ultimate goal
  of the language is to allow developers to produce code with all these
  properties at the same time. Xreate's design principles allow to adopt any
  programming technique as long as it does not improve one dimension at the
  expense of another.</para>

  <para><?xxe-sn 2b06cb2u4g0 7?>To achieve aforementioned design goals Xreate
  has tree distinctive layers:</para>

  <itemizedlist>
    <?xxe-sn 2b06cb2u4g0 e?>

    <listitem>
      <?xxe-sn 2b06cb2u4g0 f?>

      <para><?xxe-sn 2b06cb2u4g0 g?><link xlink:href="/w/syntax"><?xxe-sn 2b06cb2u4g0 o?>Brute</link>.
      Lowest layer is called <emphasis><?xxe-sn 2b06cb2u4g0 p?>Brute</emphasis>—
      this is code that is indented to be actually compiled. Code on this
      level implements actual software functionality. It resembles the usual
      imperative languages' apparatus and consists of executable instructions
      such as arithmetic, branching, input/output, etc.</para>
    </listitem>

    <listitem>
      <?xxe-sn 2b06cb2u4g0 i?>

      <para><?xxe-sn 2b06cb2u4g0 j?><link xlink:href="/w/transcend"><?xxe-sn 2b06cb2u4g0 q?>Transcend</link>.
      Brute level alone is not enough to constitute full fledged language
      since a code requires various non executable metadata to express
      developer's intents, check correctness, validity and perform other types
      of analyses. In Xreate everything of this sort belongs to a layer called
      <emphasis><?xxe-sn 2b06cb2u4g0 s?>Transcend</emphasis>. Transcend
      features declarative nature that is appropriate to do management kind of
      work — it analyzes, oversees and controls brute by guiding compilation
      process. Everything that is on this level — logic or transcend facts and
      rules are gathered and sent to an external logic solver to make
      solutions that are brought back in order to guide compilation.</para>
    </listitem>

    <listitem>
      <?xxe-sn 2b06cb2u4g0 l?>

      <para><?xxe-sn 2b06cb2u4g0 m?><link
      xlink:href="/w/concepts/interpretation/"><?xxe-sn 2b06cb2u4g0 r?>Interpretation</link>.
      And there is also <emphasis><?xxe-sn 2b06cb2u4g0 t?>Interpretation</emphasis>
      — intermediate level resembling features of dynamically typed languages
      that is used as a contact point and interpreter between brute and
      transcend and their low level and high level constructs and structures
      respectively.</para>
    </listitem>
  </itemizedlist>

  <para><?xxe-sn 2b06cb2u4g0 u?>On a syntactic level Xreate is procedural
  language with extensive use of <emphasis><?xxe-sn 2b06cb2u4g0 v?><link
  xlink:href="/w/transcend"><?xxe-sn 2b06cb2u4g0 w?>annotations</link></emphasis>
  — arbitrary unconstrained metadata that software developer can attach to a
  different language constructs, variables and code blocks. Annotations are
  completely invisible for the compiler proper and used by transcend rather as
  suggestions conveying additional information.</para>

  <para xlink:href="w/virtualization/"><?xxe-sn 2b3f3osfk74 g?>Most severe and
  hard to resolve problems in software development stem from interaction of
  different components on a different levels. Each individual component often
  is thoroughly tested and works reliably. But combining them with complex
  interaction and extensive IO to build end-user software usually leads to a
  range of runtime errors, security vulnerabilities and performance
  degradation. Thus key emphasis of Xreate is on domain specific component
  level improvements and joint use of external resources. This aspect is
  covered in <link xlink:href="/w/exploitation/"><?xxe-sn 2b3f3osfk74 h?>exploitation</link>
  and <link xlink:href="/w/concepts/containers/"><?xxe-sn 2b3f3osfk74 i?>containers</link>
  chapters. Unlike academic languages, Xreate targets safe and reliable usage
  of effectful computations, such as IO, covered in <link
  xlink:href="/w/virtualization"><?xxe-sn 2b3f3osfk74 j?>virtualization</link>,
  <link xlink:href="/w/exploitation/"><?xxe-sn 2b3f3osfk74 k?>exploitation</link>
  chapters and mutable structures covered in <link
  xlink:href="/w/communication/"><?xxe-sn 2b3f3osfk74 l?>communication</link>.</para>

  <section>
    <?xxe-sn 2b06cb2u4g0 3?>

    <title><?xxe-sn 2b06cb2u4g0 4?>Basic Example</title>

    <para><?xxe-sn 2b06cb2u4g0 5?>To demonstrate what Xreate is all about,
    basic example is given below:</para>

    <programlisting xml:id="Example_1"><?xxe-sn 2b06cb2u4g0 x?>name="tests/introduction.cpp: Introduction.Doc_Example_1", lines=15
guard::                                  iAmVeryFast 
{
  div = function(a:: float, b:: float):: float
  {
    a / b
  } 
}

guard::                                  iAmVerySafe 
{
  div = function(a:: float, b:: float):: float
  {
    if ( b == (0::float)):: float {0::float} else {a / b}
  } 
}

test = function::                        float; entry; iAmVerySecure 
{
  div(10, 5)
}</programlisting>

    <para><?xxe-sn 2b06cb2u4g0 y?>Here entry point of the program is a
    function <code><?xxe-sn 2b06cb2u4g0 z?>test</code> recognized so by the
    compiler because of annotation <code><?xxe-sn 2b06cb2u4g0 10?>entry</code>
    in its signature. There are also two functions <code><?xxe-sn 2b06cb2u4g0 11?>div</code>
    called <emphasis><?xxe-sn 2b06cb2u4g0 12?>specializations</emphasis>. Each
    specialization has a guard that defines condition that has to be met in
    order to invoke this particular specialization. In the example,
    specializations of <code><?xxe-sn 2b06cb2u4g0 13?>div</code> have
    <code><?xxe-sn 2b06cb2u4g0 14?>iAmVeryFast</code> and <code><?xxe-sn 2b06cb2u4g0 15?>iAmVerySafe</code>
    guards respectively. Let's say, developer provides two specializations
    where first is a very fast division implementation and second one is a
    very safe since it checks division by zero but at the same time is
    unbearably slow due to extra check instruction. This is a basis of <link
    xlink:href="/w/concepts/polymorphism/"><?xxe-sn 2b3f3osfk74 2?>polymorphism</link>
    — client's code <code><?xxe-sn 2b3f3osfk74 3?>test</code> is able to work
    with any specialization, and compiler should decide which one to invoke
    with the only hint it has — annotation <code><?xxe-sn 2b3f3osfk74 5?>iAmVerySecure</code>
    in the function <code><?xxe-sn 2b3f3osfk74 7?>test</code>'s signature.
    </para>

    <note>
      <?xxe-sn 2b3f3osfk74 n?>

      <para><?xxe-sn 2b3f3osfk74 o?>All annotations(except <code><?xxe-sn 2b3f3osfk74 m?>entry</code>)
      are custom defined by developer itself.</para>
    </note>

    <para><?xxe-sn 2b3f3osfk74 6?>This is when transcend comes into play. By
    adding transcend rule as shown below it is possible to associate
    annotation <code><?xxe-sn 2b3f3osfk74 8?>iAmVerySecure</code> with
    invocation of specialization guarded by <code><?xxe-sn 2b3f3osfk74 9?>iAmVerySafe:</code></para>

    <programlisting xml:id="Transcend_Example_1"><?xxe-sn 2b3f3osfk74 a?>name="tests/introduction.cpp: Introduction.Doc_Example_1", lines=15
dfa_callguard(SiteInv, iAmVerySafe):-
  dfa_callfn(SiteInv, div);
  SiteInv = s(_, _, ScopeInv);
  cfa_parent(ScopeInv, function(FnInv));
  bind_func(FnInv, iAmVerySecure).</programlisting>

    <para><?xxe-sn 2b3f3osfk74 b?>Transcend rules are written in ASP syntax —
    common syntax to write logic programs. This particular rule reads that for
    any function annotated with <code><?xxe-sn 2b3f3osfk74 c?>iAmVerySecure</code>,
    certain specialization <code><?xxe-sn 2b3f3osfk74 d?>iAmVerySafe</code> is
    chosen for <code><?xxe-sn 2b3f3osfk74 e?>div</code> invocation. </para>

    <note>
      <?xxe-sn 2b3f3osfk74 p?>

      <para><?xxe-sn 2b3f3osfk74 q?>In this example an appropriate
      specialization is statically resolved, so other specialization isn't
      even compiled. </para>
    </note>

    <para><?xxe-sn 2b3f3osfk74 f?>By providing custom rules it is possible to
    implement any polymorphism strategy, be it statically performed or
    dynamically. The example demonstrates basic workflow: transcend gathers
    available information about a program, such as annotations and using
    custom rules makes decisions to guide compilation process particularly by
    selecting appropriate specializations as in this example. </para>
  </section>
</chapter>
