aboutsummaryrefslogtreecommitdiff
path: root/snug-clean/src/Snug/Compile/ABI.icl
blob: 66a8d5cd542f3a7917e071c213c6496630f30a92 (plain) (blame)
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
implementation module Snug.Compile.ABI

import StdEnv

import Text

import MIPS.MIPS32
import Snug.Compile

constructorLabel :: !Namespace !ConstructorIdent -> Label
constructorLabel "" id = "_c" +++ id // for built-in constructors
constructorLabel ns id = concat4 "__" (escapeLabel ns) "_c" (escapeLabel id)

functionLabel :: !Namespace !EntryPoint !SymbolIdent -> Label
functionLabel ns entry_point id
	| size ns == 0
		= {#'_',e} +++ escapeLabel id
		= concat4 "__" (escapeLabel ns) {#'_',e} (escapeLabel id)
where
	e = case entry_point of
		NodeEntry -> 'n'

escapeLabel :: !String -> String
escapeLabel s = {#c \\ c <- escape [c \\ c <-: s]}
where
	escape [] = []
	escape [c:cs] | isAlphanum c = [c:escape cs]
	escape ['_':cs] = ['__':escape cs]
	escape ['`':cs] = ['_B':escape cs]
	escape [':':cs] = ['_C':escape cs]
	escape ['.':cs] = ['_D':escape cs]
	escape ['>':cs] = ['_G':escape cs]
	escape ['=':cs] = ['_I':escape cs]
	escape ['<':cs] = ['_L':escape cs]
	escape ['-':cs] = ['_M':escape cs]
	escape ['+':cs] = ['_P':escape cs]
	escape ['\'':cs] = ['_Q':escape cs]
	escape ['~':cs] = ['_T':escape cs]