mapping .NET/SML#
.NET/SML# is based on OLE/SML# and COM Interop feature of .NET.
Mapping between .NET and SML# is also based on mapping between COM and SML#.
This page describes a part of the mapping scheme which is specific to .NET object access.
data type mapping.
Data types in C# are mapped to SML# data types as follows.
| C# types | SML# types |
|---|---|
| byte | Word8.word |
| sbyte | Int32.int |
| short | Int32.int |
| ushort | Word32.word |
| int | Int32.int |
| uint | Word32.word |
| long | IntInf.int |
| ulong | IntInf.int |
| float | Real32.real |
| double | Real64.real |
| decimal | OLE.decimal |
| char | Word32.word |
| string | OLE.string |
| bool | bool |
| object | OLE.variant |
| t[] | [SML# type of t] OLE.safearray |
property and field mapping.
Properties and fields of .NET objects are mapped to properties in COM, and .NET/SML# generates accessor methods for them.
public class Account
{
private string name_;
public string name{
get{return name_;}
}
public int deposit;
public Account(string n){name_ = n;}
}
For this Account class, .NET/SML# generates a getter and a setter of deposit and a getter of name.
type Account = {
:
getname : unit -> OLE.string,
getdeposit : unit -> Int32.int,
setdeposit : (Int32.int) -> unit,
:
}
enumeration mapping.
.NET/SML# copies elements of enumerations defined in .NET assemblies into generated SML# code as 32-bit integers. For example, an C# enumeration
public enum Days {Sat=1, Sun, Mon, Tue, Wed, Thu, Fri};
is converted to
val Days_Sat = 1 : Int32.int val Days_Sun = 2 : Int32.int val Days_Mon = 3 : Int32.int val Days_Tue = 4 : Int32.int val Days_Wed = 5 : Int32.int val Days_Thu = 6 : Int32.int val Days_Fri = 7 : Int32.int
The default type of elements of an enumeration in C# is int. .NET/SML# casts elements of an enumeration of other type to 32-bit signed integers.
public enum UIEnum : uint {UIMAX = 0xFFFFFFFF};
is converted to
val UIEnum_UIMAX = ~1 : Int32.int
Keyword(s):
References:[mapping .NET/SML#] [Introduction to .NET/SML#]