diff options
author | Camil Staps | 2023-01-28 12:48:43 +0100 |
---|---|---|
committer | Camil Staps | 2023-01-28 12:48:43 +0100 |
commit | f84fca3b169d808943b5f329c177870dc87c1d51 (patch) | |
tree | c6af7707ecd8fc52c4ed4804ece707fce941b0be /snug-clean/src/Snug/Compile/ABI.icl | |
parent | Add compilation of constructors and basic values (diff) |
Add stack simulator for compilation
Diffstat (limited to 'snug-clean/src/Snug/Compile/ABI.icl')
-rw-r--r-- | snug-clean/src/Snug/Compile/ABI.icl | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/snug-clean/src/Snug/Compile/ABI.icl b/snug-clean/src/Snug/Compile/ABI.icl new file mode 100644 index 0000000..66a8d5c --- /dev/null +++ b/snug-clean/src/Snug/Compile/ABI.icl @@ -0,0 +1,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] |