aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source/luxc/lang/translation/jvm/program.lux
blob: 7ac897009db65a8f0081605fddcfe7f0c38dea76 (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
(.module:
  [lux #*
   [target
    [jvm
     ["$t" type]]]]
  [luxc
   [lang
    [host
     ["_" jvm
      ["$d" def]
      ["$i" inst]]]
    [translation
     ["." jvm
      ["." runtime]]]]])

(def: #export class "LuxProgram")

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

(def: #export (program programI)
  (-> _.Inst _.Definition)
  (let [nilI runtime.noneI
        num-inputsI (|>> ($i.ALOAD 0) $i.ARRAYLENGTH)
        decI (|>> ($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 +1)
                   ($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)
                                     decI
                                     $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 ($t.array ($t.class "java.lang.String" (list))))
                              $t.void
                              (list)])]
    [..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))))]))