aboutsummaryrefslogtreecommitdiff
path: root/lux-jvm/source/luxc/lang/translation/jvm/program.lux
blob: 7e408ecc43f829e8b821131b02f0f965873ef9fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
(.using
  [library
   [lux "*"
    [data
     [text
      ["%" format {"+" format}]]]
    [target
     [jvm
      ["$t" type]]]
    [tool
     [compiler
      [language
       [lux
        [generation {"+" Context}]
        [program {"+" Program}]]]]]]]
  [luxc
   [lang
    [host
     ["_" jvm
      ["$d" def]
      ["$i" inst]]]
    [translation
     ["[0]" jvm
      ["[0]" runtime]]]]])

(def: ^Object ($t.class "java.lang.Object" (list)))

(def: .public (program artifact_name context programI)
  (-> (-> Context Text) (Program _.Inst _.Definition))
  (let [nilI runtime.noneI
        num_inputsI (|>> ($i.ALOAD 0) $i.ARRAYLENGTH)
        --I (|>> ($i.int +1) $i.ISUB)
        headI (|>> $i.DUP
                   ($i.ALOAD 0)
                   $i.SWAP
                   $i.AALOAD
                   $i.SWAP
                   $i.DUP_X2
                   $i.POP)
        pairI (|>> ($i.int +2)
                   ($i.ANEWARRAY ..^Object)
                   $i.DUP_X1
                   $i.SWAP
                   ($i.int +0)
                   $i.SWAP
                   $i.AASTORE
                   $i.DUP_X1
                   $i.SWAP
                   ($i.int +1)
                   $i.SWAP
                   $i.AASTORE)
        consI (|>> ($i.int +0)
                   ($i.string "")
                   $i.DUP2_X1
                   $i.POP2
                   runtime.variantI)
        prepare_input_listI (<| $i.with_label (function (_ @loop))
                                $i.with_label (function (_ @end))
                                (|>> nilI
                                     num_inputsI
                                     ($i.label @loop)
                                     --I
                                     $i.DUP
                                     ($i.IFLT @end)
                                     headI
                                     pairI
                                     consI
                                     $i.SWAP
                                     ($i.GOTO @loop)
                                     ($i.label @end)
                                     $i.POP))
        feed_inputsI ($i.INVOKEVIRTUAL jvm.$Function runtime.apply_method (runtime.apply_signature 1))
        run_ioI (|>> ($i.CHECKCAST jvm.$Function)
                     $i.NULL
                     ($i.INVOKEVIRTUAL jvm.$Function runtime.apply_method (runtime.apply_signature 1)))
        main_type ($t.method [(list)
                              (list ($t.array ($t.class "java.lang.String" (list))))
                              $t.void
                              (list)])
        class (artifact_name context)]
    [class
     ($d.class {_.#V1_6}
               {_.#Public} _.finalC
               class
               (list) ..^Object
               (list)
               (|>> ($d.method {_.#Public} _.staticM "main" main_type
                               (|>> programI
                                    prepare_input_listI
                                    feed_inputsI
                                    run_ioI
                                    $i.RETURN))))]))