aboutsummaryrefslogtreecommitdiff
path: root/compiler/elymasGlobalSysTyped.ey
blob: c6045321d51ead31f022c54b3cf4ae39f2619c07 (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
<
  <
    # 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
    [[
      /rbx :popqReg

      /rdx :popqReg
      63 /rdx :btrqImm8Reg
      /integerType :jcLbl8

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

      @integerType
      /rdx /rdx :xorqRegReg

      @done
      63 /rdx :btsqImm8Reg
      /rdx :pushqReg

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

  "typed" enterSubScope

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

  leaveSubScope
> --

# vim: syn=elymas