/
Services.boo
63 lines (47 loc) · 2.09 KB
/
Services.boo
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
namespace BooJs.Compiler.TypeSystem
import Boo.Lang.Compiler.TypeSystem(BuiltinFunction, IType)
import Boo.Lang.Compiler.TypeSystem.TypeSystemServices as BooServices
import BooJs.Lang
class Services(BooServices):
override static ErrorEntity = Globals.Error
override ExceptionType:
get: return Map(Globals.Error)
override protected def PreparePrimitives():
# Setup new defaults for primitive types
ObjectType = Map(Globals.Object)
StringType = Map(Globals.String)
ArrayType = Map(Globals.Array)
IntType = Map(Globals.NumberInt)
UIntType = Map(Globals.NumberUInt)
DoubleType = Map(Globals.NumberDouble)
RegExpType = Map(Globals.RegExp)
ICallableType = Map(ICallable) #Map(Globals.Function)
DuckType = Map(Builtins.Duck)
RuntimeServicesType = Map(Runtime.Services)
BuiltinsType = Map(Builtins)
# Add primitive types
AddPrimitiveType("void", VoidType)
AddPrimitiveType("object", ObjectType)
#AddPrimitiveType("list", ArrayType)
AddPrimitiveType("callable", ICallableType)
AddPrimitiveType("duck", DuckType);
AddLiteralPrimitiveType("bool", BoolType)
AddLiteralPrimitiveType("int", IntType)
AddLiteralPrimitiveType("uint", UIntType)
AddLiteralPrimitiveType("double", DoubleType)
AddLiteralPrimitiveType("string", StringType)
AddLiteralPrimitiveType('regex', RegExpType)
override protected def PrepareBuiltinFunctions():
AddBuiltin(BuiltinFunction.Len)
#AddBuiltin(BuiltinFunction.AddressOf);
#AddBuiltin(BuiltinFunction.Eval);
#AddBuiltin(BuiltinFunction.Switch);
/*
# We might need to replace more methods to take into account the new types
new def IsNumberOrBool(type as IType):
return BoolType == type or IsNumber(type)
new def IsNumber(type as IType):
return IsPrimitiveNumber(type) or type == DecimalType
new def IsPrimitiveNumber(type as IType):
return IsIntegerNumber(type) or type == DoubleType or type == Map(Globals.Number)
*/