@@ -102,7 +102,9 @@ public static Module getPreludeModule() {
102
102
103
103
private static SeqExpr getPrelude () {
104
104
if (!usePrelude ) {
105
- return new SeqExpr ();
105
+ SeqExpr result = new SeqExpr ();
106
+ result .addBinding (new BindingSite ("system" ), Globals .getSystemType (), Globals .getSystemValue (), false );
107
+ return result ;
106
108
}
107
109
if (prelude == null ) {
108
110
if (gettingPrelude ) {
@@ -115,6 +117,7 @@ private static SeqExpr getPrelude() {
115
117
preludeModule = ModuleResolver .getLocal ().load ("<prelude>" , file , true );
116
118
prelude = ModuleResolver .getLocal ().wrap (preludeModule .getExpression (), preludeModule .getDependencies ());
117
119
TailCallVisitor .annotate (prelude );
120
+ prelude .addBinding (new BindingSite ("system" ), Globals .getSystemType (), Globals .getSystemValue (), false );
118
121
}
119
122
return prelude ;
120
123
}
@@ -160,7 +163,7 @@ public static BindingSite getSystemSite() {
160
163
return system ;
161
164
}
162
165
163
- private static ValueType getSystemType () {
166
+ public static ValueType getSystemType () {
164
167
List <FormalArg > ifTrueArgs = Arrays .asList (
165
168
new FormalArg ("trueBranch" , Util .unitToDynType ()),
166
169
new FormalArg ("falseBranch" , Util .unitToDynType ()));
@@ -225,7 +228,7 @@ private static ValueType getSystemType() {
225
228
declTypes .add (new ConcreteTypeMember ("Dyn" , new DynamicType ()));
226
229
ExtensibleTagType platformType = new ExtensibleTagType (null , Util .unitType ());
227
230
declTypes .add (new ConcreteTypeMember ("Platform" , platformType ));
228
- NominalType systemPlatform = new NominalType ("system " , "Platform" );
231
+ NominalType systemPlatform = new NominalType ("this " , "Platform" );
229
232
ExtensibleTagType javaType = new ExtensibleTagType (systemPlatform , Util .unitType ());
230
233
declTypes .add (new ConcreteTypeMember ("Java" , javaType ));
231
234
ExtensibleTagType javascriptType = new ExtensibleTagType (systemPlatform , Util .unitType ());
@@ -242,7 +245,7 @@ private static ValueType getSystemType() {
242
245
declTypes .add (new AbstractTypeMember ("Context" ));
243
246
declTypes .add (new ValDeclType ("unit" , Util .unitType ()));
244
247
declTypes .add (new EffectDeclType ("ffiEffect" , null , null ));
245
- ValueType systemType = new StructuralType (system , declTypes );
248
+ ValueType systemType = new StructuralType (new BindingSite ( "this" ) , declTypes );
246
249
return systemType ;
247
250
}
248
251
@@ -257,15 +260,18 @@ public static TypeContext getStandardTypeContext() {
257
260
258
261
public static EvalContext getStandardEvalContext () {
259
262
EvalContext ctx = EvalContext .empty ();
260
- ctx = ctx .extend (system , Globals .getSystemValue ());
261
263
SeqExpr sexpr = prelude ;
262
264
if (sexpr != null ) {
263
265
ctx = sexpr .interpretCtx (ctx ).getSecond ();
264
266
}
265
267
return ctx ;
266
268
}
267
269
268
- private static ObjectValue getSystemValue () {
270
+ private static Declaration platformTypeDeclaration (String platform ) {
271
+ return new TypeDeclaration (platform , ((ConcreteTypeMember ) getSystemType ().findDecl (platform , null )).getSourceType (), FileLocation .UNKNOWN );
272
+ }
273
+
274
+ public static ObjectValue getSystemValue () {
269
275
// construct a type for the system object
270
276
List <Declaration > decls = new LinkedList <Declaration >();
271
277
decls .add (new TypeDeclaration ("Int" , new NominalType ("this" , "Int" ), FileLocation .UNKNOWN ));
@@ -275,10 +281,10 @@ private static ObjectValue getSystemValue() {
275
281
decls .add (new TypeDeclaration ("Character" , new NominalType ("this" , "Character" ), FileLocation .UNKNOWN ));
276
282
decls .add (new TypeDeclaration ("Dyn" , new DynamicType (), FileLocation .UNKNOWN ));
277
283
decls .add (new TypeDeclaration ("Nothing" , new BottomType (), FileLocation .UNKNOWN ));
278
- decls .add (new TypeDeclaration ( "Java" , new NominalType ( "this" , "Java" ), FileLocation . UNKNOWN ));
279
- decls .add (new TypeDeclaration ( "Platform" , new NominalType ( "this" , "Platform" ), FileLocation . UNKNOWN ));
280
- decls .add (new TypeDeclaration ("Python" , new NominalType ( "this" , "Python" ), FileLocation . UNKNOWN ));
281
- decls .add (new TypeDeclaration ("JavaScript" , new NominalType ( "this" , "JavaScript" ), FileLocation . UNKNOWN ));
284
+ decls .add (platformTypeDeclaration ( "Platform" ));
285
+ decls .add (platformTypeDeclaration ( "Java" ));
286
+ decls .add (platformTypeDeclaration ("Python" ));
287
+ decls .add (platformTypeDeclaration ("JavaScript" ));
282
288
decls .add (new ValDeclaration ("unit" , Util .unitType (), Util .unitValue (), null ));
283
289
ObjectValue systemVal = new ObjectValue (decls , new BindingSite ("this" ), getSystemType (), null , null , EvalContext .empty ());
284
290
return systemVal ;
0 commit comments