Browse Source

mote tests

Vladislav Folts 10 years ago
parent
commit
c84a50f6de

BIN
bin/compiled.zip


+ 2 - 2
src/context.js

@@ -17,11 +17,11 @@ var nullCodeGenerator = Code.nullGenerator();
 var nilType = Type.nil();
 
 var castOperations = op.castOperations();
-/*
+
 function log(s){
     console.info(s);
 }
-*/
+
 function getSymbolAndScope(context, id){
     var s = context.findSymbol(id);
     if (!s)

+ 5 - 17
src/eberon/EberonTypes.ob

@@ -15,8 +15,7 @@ TYPE
     END;
     PMethodType = POINTER TO MethodType;
 
-    MethodVariable* = RECORD(Types.Variable)
-        mType: Types.PType
+    MethodVariable* = RECORD(Types.ProcedureId)
     END;
 
     DynamicArray* = RECORD(Types.Array)
@@ -81,7 +80,7 @@ PROCEDURE MethodType.result(): Types.PType;
 END MethodType.result;
 
 PROCEDURE MethodType.description(): STRING;
-    RETURN "method " + SELF.name
+    RETURN "method '" + SELF.name + "'"
 END MethodType.description;
 
 PROCEDURE MethodType.procDescription(): STRING;
@@ -103,28 +102,16 @@ BEGIN
     RETURN result
 END makeMethodType;
 
-PROCEDURE MethodVariable.type(): Types.PType;
-    RETURN SELF.mType
-END MethodVariable.type;
-
-PROCEDURE MethodVariable.isReadOnly(): BOOLEAN;
-    RETURN TRUE
-END MethodVariable.isReadOnly;
-
 PROCEDURE MethodVariable.idType(): STRING;
     RETURN "method"
 END MethodVariable.idType;
 
-PROCEDURE MethodVariable.isReference(): BOOLEAN;
-    RETURN FALSE
-END MethodVariable.isReference;
-
-PROCEDURE makeMethodVariable*(type: Types.PType): Types.PVariable;
+PROCEDURE makeMethodVariable*(type: Types.PType): Types.PProcedureId;
 VAR
     result: POINTER TO MethodVariable;
 BEGIN
     NEW(result);
-    result.mType := type;
+    result.type := type;
     RETURN result
 END makeMethodVariable;
 
@@ -186,5 +173,6 @@ END DynamicArrayMethod.callGenerator;
 
 BEGIN
     NEW(dynamicArrayAddMethod);
+    dynamicArrayAddMethod.name := "'add'";
     NEW(dynamicArrayAdd);
 END EberonTypes.

+ 1 - 1
src/ob/Procedure.ob

@@ -287,7 +287,7 @@ PROCEDURE makeProcCallGenerator*(
 END makeProcCallGenerator;
 
 PROCEDURE Std.description(): STRING;
-    RETURN "standard procedure " + Types.typeName(SELF)
+    RETURN "standard procedure " + SELF.name
 END Std.description;
 
 PROCEDURE Std.callGenerator(cx: LanguageContext.PType): PCallGenerator;

+ 1 - 1
src/ob/Types.ob

@@ -70,7 +70,7 @@ TYPE
     PExportedVariable = POINTER TO ExportedVariable;
 
     ProcedureId* = RECORD(Id)
-        type: PType
+        type*: PType
     END;
 
     PProcedureId* = POINTER TO ProcedureId;

+ 1 - 0
test/expected/eberon/method.js

@@ -56,4 +56,5 @@ D.prototype.p2 = function(i/*INTEGER*/){
 }
 dp = new D();
 dp.p();
+dp.p();
 }();

+ 1 - 0
test/input/eberon/method.ob

@@ -51,4 +51,5 @@ END D.p2;
 BEGIN
     NEW(dp);
     dp.p();
+    dp.p;
 END m.

+ 16 - 3
test/test_unit_eberon.js

@@ -205,6 +205,16 @@ exports.suite = {
     pass("o.f()"),
     fail(["o.p()", "procedure returning no result cannot be used in an expression"])
     ),
+"method call as statement": testWithContext(
+    context(grammar.statement,
+              "TYPE T = RECORD PROCEDURE p(); PROCEDURE f(): INTEGER END;"
+            + "VAR o: T;"
+            + "PROCEDURE T.p(); END T.p;"
+            + "PROCEDURE T.f(): INTEGER; RETURN 0 END T.f;"
+            ),
+    pass("o.p"),
+    fail(["o.f", "procedure returning a result cannot be used as a statement"])
+    ),
 "cannot assign to method": testWithContext(
     context(grammar.statement,
               "TYPE T = RECORD PROCEDURE p() END;"
@@ -212,7 +222,7 @@ exports.suite = {
             + "PROCEDURE T.p(); END T.p;"
             ),
     pass(),
-    fail(["o.p := o.p", "cannot assign to method"],
+    fail(["o.p := o.p", "method 'p' cannot be referenced"],
          ["o.p := NIL", "cannot assign to method"])
     ),
 "method cannot be referenced": testWithContext(
@@ -224,7 +234,8 @@ exports.suite = {
             + "PROCEDURE proc(p: Proc); END proc;"
             ),
     pass(),
-    fail(["proc(o.p)", "type mismatch for argument 1: 'method p' cannot be converted to 'Proc'"])
+    fail(["proc(o.p)", "method 'p' cannot be referenced"],
+         ["v <- o.p", "method 'p' cannot be referenced"])
     ),
 "method super call": testWithContext(
     context(grammar.declarationSequence,
@@ -922,7 +933,9 @@ exports.suite = {
             context(grammar.statement, 
                     "VAR a: ARRAY * OF INTEGER;"),
             pass("a.add(123)"),
-            fail(["a.add := a.add", "cannot assign to method"])
+            fail(["a.add := NIL", "cannot assign to method"],
+                 ["v <- a.add", "standard procedure 'add' cannot be referenced"]                
+                )
         )
     }
 };