aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source/luxc/generator/procedure/host.jvm.lux
blob: 66b7bc77e1233c55d0681deb85475a9f4dedd78b (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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
(;module:
  lux
  (lux (control [monad #+ do])
       (data [text]
             text/format
             (coll [list "list/" Functor<List>]
                   [dict #+ Dict]))
       [macro #+ with-gensyms]
       (macro [code]
              ["s" syntax #+ syntax:])
       [host])
  (luxc ["&" base]
        (lang ["la" analysis]
              ["ls" synthesis])
        ["&;" analyser]
        ["&;" synthesizer]
        (synthesizer [function])
        (generator ["&;" common]
                   ["&;" runtime]
                   (host ["$" jvm]
                         (jvm ["$t" type]
                              ["$d" def]
                              ["$i" inst]))))
  ["@" ../common])

(do-template [<name> <inst>]
  [(def: <name>
     $;Inst
     <inst>)]

  [L2S (|>. $i;L2I $i;I2S)]
  [L2B (|>. $i;L2I $i;I2B)]
  )

(do-template [<name> <unwrap> <conversion> <wrap>]
  [(def: (<name> inputI)
     @;Unary
     (if (is $i;NOP <conversion>)
       (|>. inputI
            ($i;unwrap <unwrap>)
            ($i;wrap <wrap>))
       (|>. inputI
            ($i;unwrap <unwrap>)
            <conversion>
            ($i;wrap <wrap>))))]
  
  [convert//double-to-float #$;Double $i;D2F #$;Float]
  [convert//double-to-int #$;Double $i;D2I #$;Int]
  [convert//double-to-long #$;Double $i;D2L #$;Long]
  [convert//float-to-double #$;Float $i;F2D #$;Double]
  [convert//float-to-int #$;Float $i;F2I #$;Int]
  [convert//float-to-long #$;Float $i;F2L #$;Long]
  [convert//int-to-byte #$;Int $i;I2B #$;Byte]
  [convert//int-to-char #$;Int $i;I2C #$;Char]
  [convert//int-to-double #$;Int $i;I2D #$;Double]
  [convert//int-to-float #$;Int $i;I2F #$;Float]
  [convert//int-to-long #$;Int $i;I2L #$;Long]
  [convert//int-to-short #$;Int $i;I2S #$;Short]
  [convert//long-to-double #$;Long $i;L2D #$;Double]
  [convert//long-to-float #$;Long $i;L2F #$;Float]
  [convert//long-to-int #$;Long $i;L2I #$;Int]
  [convert//long-to-short #$;Long L2S #$;Short]
  [convert//long-to-byte #$;Long L2B #$;Byte]
  [convert//char-to-byte #$;Char $i;I2B #$;Byte]
  [convert//char-to-short #$;Char $i;I2S #$;Short]
  [convert//char-to-int #$;Char $i;NOP #$;Int]
  [convert//char-to-long #$;Char $i;I2L #$;Long]
  [convert//byte-to-long #$;Byte $i;I2L #$;Long]
  [convert//short-to-long #$;Short $i;I2L #$;Long]
  )

(def: conversion-procs
  @;Bundle
  (<| (@;prefix "convert")
      (|> (dict;new text;Hash<Text>)
          (@;install "double-to-float" (@;unary convert//double-to-float))
          (@;install "double-to-int" (@;unary convert//double-to-int))
          (@;install "double-to-long" (@;unary convert//double-to-long))
          (@;install "float-to-double" (@;unary convert//float-to-double))
          (@;install "float-to-int" (@;unary convert//float-to-int))
          (@;install "float-to-long" (@;unary convert//float-to-long))
          (@;install "int-to-byte" (@;unary convert//int-to-byte))
          (@;install "int-to-char" (@;unary convert//int-to-char))
          (@;install "int-to-double" (@;unary convert//int-to-double))
          (@;install "int-to-float" (@;unary convert//int-to-float))
          (@;install "int-to-long" (@;unary convert//int-to-long))
          (@;install "int-to-short" (@;unary convert//int-to-short))
          (@;install "long-to-double" (@;unary convert//long-to-double))
          (@;install "long-to-float" (@;unary convert//long-to-float))
          (@;install "long-to-int" (@;unary convert//long-to-int))
          (@;install "long-to-short" (@;unary convert//long-to-short))
          (@;install "long-to-byte" (@;unary convert//long-to-byte))
          (@;install "char-to-byte" (@;unary convert//char-to-byte))
          (@;install "char-to-short" (@;unary convert//char-to-short))
          (@;install "char-to-int" (@;unary convert//char-to-int))
          (@;install "char-to-long" (@;unary convert//char-to-long))
          (@;install "byte-to-long" (@;unary convert//byte-to-long))
          (@;install "short-to-long" (@;unary convert//short-to-long))
          )))

(def: #export procedures
  @;Bundle
  (<| (@;prefix "jvm")
      (|> (dict;new text;Hash<Text>)
          (dict;merge conversion-procs)
          )))