Skip to content
Fernando Petrola edited this page Mar 16, 2016 · 6 revisions
//--------------------------------------------------------------------------{}
//---------------------- Humo Runtime Environment --------------------------{}
//-------------------------------------------------------------------------.{}

[te{[t}mp]{emp]}
[exec]{[temp]}
//{[temp]}


#run-main-class
{
    [exec]{#ref instance{main1}}
    [exec]{new Main}
    [exec]{$main1.execute}
}

#class{new}
#method{[do][llar]<*>instance.}
#field{[do][llar]<*>instance.}
#reassign-field{(3)<*>instance.}
#this.{[do][llar]<*>instance.}
#instance-name{#var instance}
#constructor-parameter {<***>}
#set-method-parameter {<***>}
#var {<***>}
#previous-value-of{<****>}
#use-constructor-parameter {<*>}
#use-method-parameter {<**>}
#new{<***>new}
#call{<**>}
#last-result{<**> result}
#return{<***> result}
#ref{<*>}

<**{<*}
<*>{$}
[**{[*}
[*]{}

[dollar]{$}
[do]{[do}
[llar]{llar]}

(3){open-parenthesis2)}
(2){open-parenthesis1)}
(1){$}
open-parenthesis{(}


10[_x_]20{200}
30[_x_]40{1200}

_x_{underscore_x_}
_-_{underscore_-_}
_+_{underscore_+_}
_==_{underscore_==_}

underscore_{_}

#class TableBasedValueSolver
{
    #method solve
    {
        [exec]{#var first{#this.firstValue}}
        [exec]{#var second{#this.secondValue}}
        [exec]{#var combined{$first $operator $second}}

        [exec]{#return {#ref combined}}

        [exec]{#var first{#previous-value-of first}}
        [exec]{#var second{#previous-value-of second}}
        [exec]{#var operator{#previous-value-of operator}}
        [exec]{#var combined{#previous-value-of combined}}
    }

    #field operator {#use-constructor-parameter operator}
    #field firstValue {#use-constructor-parameter p1}
    #field secondValue {#use-constructor-parameter p2}
}



//--------------------------------------------------------------------------{}
//---------------------- Begin of application code -------------------------{}
//--------------------------------------------------------------------------{}

15_-_1{14}
14_-_1{13}
13_-_1{12}
12_-_1{11}
11_-_1{10}
10_-_1{9}
9_-_1{8}
8_-_1{7}
7_-_1{6}
6_-_1{5}
5_-_1{4}
4_-_1{3}
3_-_1{2}
2_-_1{1}
1_-_1{0}
0_-_1{15}

0_+_1{1}
1_+_1{2}
2_+_1{3}
3_+_1{4}
4_+_1{5}
5_+_1{6}
6_+_1{7}
7_+_1{8}
8_+_1{9}
9_+_1{10}
10_+_1{11}
11_+_1{12}
12_+_1{13}
13_+_1{14}
14_+_1{15}
15_+_1{0}

0 _==_ 0{true}
1 _==_ 0{false}
2 _==_ 0{false}
3 _==_ 0{false}
4 _==_ 0{false}
5 _==_ 0{false}
6 _==_ 0{false}
7 _==_ 0{false}
8 _==_ 0{false}
9 _==_ 0{false}
10 _==_ 0{false}
11 _==_ 0{false}
12 _==_ 0{false}
13 _==_ 0{false}
14 _==_ 0{false}
15 _==_ 0{false}

true.not {false}
false.not {true}

#class Nibble
{
    #method setValue
    {
        [exec]{#reassign-field value{#use-method-parameter value}}
    }

    #method dec
    {
        [exec]{#constructor-parameter p1{#this.value}}
        [exec]{#constructor-parameter p2{1}}
        [exec]{#constructor-parameter operator{_-_}}
        [exec]{#instance-name {solver}}
        [exec]{#new TableBasedValueSolver}
        [exec]{#call solver.solve}
        [exec]{#return {#last-result}}
    }

    #method inc
    {
        [exec]{#constructor-parameter p1{#this.value}}
        [exec]{#constructor-parameter p2{1}}
        [exec]{#constructor-parameter operator{_+_}}
        [exec]{#instance-name {solver}}
        [exec]{#new TableBasedValueSolver}
        [exec]{#call solver.solve}
        [exec]{#return {#last-result}}
    }

    #method isZero
    {
        [exec]{#constructor-parameter p1{#this.value}}
        [exec]{#constructor-parameter p2{0}}
        [exec]{#constructor-parameter operator{_==_}}
        [exec]{#instance-name {solver}}
        [exec]{#new TableBasedValueSolver}
        [exec]{#call solver.solve}
        [exec]{#return {#last-result}}
    }

    #method getValue
    {
        [exec]{#return {#this.value}}
    }


    #field value {#use-constructor-parameter value}
}

#class While
{
    #method true
    {
        [exec]{#this.execute}
    }

    #method execute
    {
        [exec]{#var a1{#this.template.body}}
        [exec]{#call a1}
        [exec]{#var a1{#this.template.condition}}
        [exec]{#call a1}
        [exec]{#var b1{#this.}}
        [exec]{#var b2{#ref b1 $result}}
        [exec]{#call b2}
    }

    #field template {#use-constructor-parameter template}
}

#class MultiplicationWhileTemplate
{
  #method condition
  {
    [exec]{#var b1{#this.counter.isZero}}
    [exec]{#call b1}
    [exec]{#var b2{#last-result.not}}
    [exec]{#return {#ref b2}}
  }

  #method body
  {
    [exec]{#var b1{#this.counter.dec}}
    [exec]{#call b1}
    [exec]{#set-method-parameter value{#last-result}}
    [exec]{#var c1{#this.counter.setValue}}
    [exec]{#call c1}
  }

  #field counter {#use-constructor-parameter counter}
}


#class Main
{
    #method execute
    {
        [exec]{#constructor-parameter value{4}}
        [exec]{#instance-name {nibble1}}
        [exec]{#new Nibble}

        [exec]{#constructor-parameter counter{#ref nibble1}}
        [exec]{#instance-name {_template1}}
        [exec]{#new MultiplicationWhileTemplate}

        [exec]{#constructor-parameter template{#ref _template1}}
        [exec]{#instance-name {while1}}
        [exec]{#new While}
        [exec]{#call while1.execute}
        [exec]{#var result1 {#call nibble1.getValue}}

    }
}

[exec]{#run-main-class}

//--------------------------------------------------------------------------{}
//----------------------- End of application code --------------------------{}
//--------------------------------------------------------------------------{}
Clone this wiki locally