aboutsummaryrefslogtreecommitdiff
path: root/compiler/elymasGlobalSysTyped.ey
blob: 97dab28a05329962c8ec5f575a17ab1e8168cbfc (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<
  <
    # return the array of input types of a function
    # 0 -> the function object to analyze
    # 0 <- the array of input types
    [[
      /rbx :popqReg

      /rdx :popqReg
      16 /rdx /rdx :movqMemDisp8Reg
      /rdx /rdx :testqRegReg
      /typed :jnzLbl8

      # untyped functions, it does not officially take any arguments
      /rdi /rdi :xorqRegReg
      ::internalAllocateArray /rax :movqImmReg
      /rax :callqReg
      /rax :pushqReg
      /rbx :pushqReg
      :retn

      @typed
      8 /rdx /rdi :movqMemDisp8Reg
      3 /rdi :shlqImm8Reg
      16 /rdx /rsi :leaqMemDisp8Reg
      /rsi :pushqReg
      ::internalAllocateArray /rax :movqImmReg
      /rax :callqReg

      /rsi :popqReg
      /rax :pushqReg

      8 /rax /rdi :leaqMemDisp8Reg
      /rax /ecx :movlMemReg
      8 /rcx :subqImm8Reg
      :reprcx :movsb

      /rbx :pushqReg
      :retn
    ]] /eyinputs defv

    # return the array of output types of a function
    # 0 -> the function object to analyze
    # 0 <- the array of output types
    [[
      /rbx :popqReg

      /rdx :popqReg
      16 /rdx /rdx :movqMemDisp8Reg
      /rdx /rdx :testqRegReg
      /typed :jnzLbl8

      # untyped functions, it does not officially produce any objects
      /rdi /rdi :xorqRegReg
      ::internalAllocateArray /rax :movqImmReg
      /rax :callqReg
      /rax :pushqReg
      /rbx :pushqReg
      :retn

      @typed
      8 /rdx /rax :movqMemDisp8Reg
      16 8 /rax /rdx /rdx :leaqMemIndexScaleDisp8Reg
      /rdx /rdi :movqMemReg
      3 /rdi :shlqImm8Reg
      8 /rdx /rsi :leaqMemDisp8Reg
      /rsi :pushqReg
      ::internalAllocateArray /rax :movqImmReg
      /rax :callqReg

      /rsi :popqReg
      /rax :pushqReg

      8 /rax /rdi :leaqMemDisp8Reg
      /rax /ecx :movlMemReg
      8 /rcx :subqImm8Reg
      :reprcx :movsb

      /rbx :pushqReg
      :retn
    ]] /eyoutputs defv

    # return the type of an object
    # 0 -> the object to analyze
    # 0 <- an integer from
    #   0 - 15 for normal heap objects (as per doc/notes object header)
    #   16 for array begin marker
    #   17 for quote begin marker
    #   18 for bottom of stack marker
    #   19 for error data marker
    #   -1 for unknown object
    [[
      /rbx :popqReg

      /rdx :popqReg
      63 /rdx :btrqImm8Reg
      /integerType :jcLbl32

      /rdx /rax :movqRegReg
      44 /rax :shrqImm8Reg
      6 /rax :cmpqImm8Reg
      /markers :jnzLbl8

      7 /rdx /rdx :movzxMem8Disp8Reg64
      4 /rdx :shrqImm8Reg
      /done :jmpLbl8

      @markers
      1 /rdx :cmpqImm8Reg
      /arrayMarker :jzLbl8
      2 /rdx :cmpqImm8Reg
      /quoteMarker :jzLbl8
      %5555555555555555 /rax :movqImmReg
      /rax /rdx :cmpqRegReg
      /bottomMarker :jzLbl8
      emptyArray /rax :movqImmReg
      /rax /rdx :cmpqRegReg
      /emptyArrayConst :jzLbl8

      4 /rdx :cmpqImm8Reg
      /errorMarker :jzLbl8
      /unknown :jmpLbl8

      @errorMarker
      19 /rdx :movqImmReg
      /done :jmpLbl8

      @bottomMarker
      18 /rdx :movqImmReg
      /done :jmpLbl8

      @quoteMarker
      17 /rdx :movqImmReg
      /done :jmpLbl8

      @arrayMarker
      16 /rdx :movqImmReg
      /done :jmpLbl8

      @emptyArrayConst
      7 /rdx :movqImmReg
      /done :jmpLbl8

      @integerType
      /rdx /rdx :xorqRegReg

      @done
      63 /rdx :btsqImm8Reg
      /rdx :pushqReg

      /rbx :pushqReg
      :retn

      @unknown
      ::internalAllocateInteger /rax :movqImmReg
      /rax :callqReg
      /rdx /rdx :xorqRegReg
      1 /rdx :subqImm8Reg
      /rdx 8 /rax :movqRegMemDisp8
      /rax :pushqReg

      /rbx :pushqReg
      :retn
    ]] /eytype defv
  > _ ==globalFunctions { defv }' ::allocateOffsetStruct

  "typed" enterSubScope

  [
    globalFunctions keys eydeff { | }' createScopeEntries
    createScopeExtensionEntries
  ] :execute

  leaveSubScope
> --

# vim: syn=elymas