Commit 2d83e007 authored by Vasantha Ganesh Kanniappan's avatar Vasantha Ganesh Kanniappan
Browse files

added --strict-typing flag

parent c75e4740
Pipeline #7313793 passed with stage
in 9 minutes and 22 seconds
......@@ -503,19 +503,21 @@ public class Compilation implements SourceLocator
* @param value the value to be compiled
*/
public void compileConstant (Object value) {
gnu.bytecode.CodeAttr code = getCode();
if (value == null)
code.emitPushNull();
else if (value instanceof String && ! immediate)
code.emitPushString((String) value);
else {
Literal literal = litTable.findLiteral(value);
// if (immediate) maybe we want to use a differnet approach.
if (literal.field == null)
literal.assign(litTable);
code.emitGetStatic(literal.field);
}
gnu.bytecode.CodeAttr code = getCode();
if (value == null)
code.emitPushNull();
else if (value instanceof String && ! immediate)
code.emitPushString((String) value);
else {
Literal literal = litTable.findLiteral(value);
// if (immediate) maybe we want to use a differnet approach.
if (literal.field == null)
literal.assign(litTable);
code.emitGetStatic(literal.field);
}
}
public static boolean strictTyping = false;
public static boolean inlineOk = true;
......
......@@ -83,9 +83,14 @@ public class InlineCalls extends ExpExpVisitor<Type> {
return checkType(exp, required);
}
public Expression checkType(Expression exp, Type required) {
Type expType = exp.getType();
if (expType == Type.toStringType)
if(Compilation.strictTyping && expType.getName().equals("java.lang.Object")){
throw new Error("Use of Dynamic Type Found in line: " + comp.getLineNumber());
}
if (expType == Type.toStringType)
expType = Type.javalangStringType;
int cmp = required == null || expType == Type.neverReturnsType
|| required == Type.neverReturnsType
......
......@@ -749,7 +749,7 @@ public class LangObjType extends SpecialObjectType implements TypeValue
public Expression convertValue (Expression value)
{
// In these cases, using the coercion metod would by-pass
// In these cases, using the coercion method would by-pass
// the static type-checking in InlineCalls#checkType, to no benefit.
if (typeCode == INTEGER_TYPE_CODE
|| typeCode == NUMERIC_TYPE_CODE
......
......@@ -99,6 +99,7 @@ public class repl extends Procedure0or1 {
printOption(out, "--debug-print-final-expr", "Print expression after any optimizations");
printOption(out, "--debug-error-prints-stack-trace", "Print stack trace with errors");
printOption(out, "--debug-warning-prints-stack-trace", "Print stack trace with warnings");
printOption(out, "--strict-typing", "halt execution on dynamic types, print stack trace");
printOption(out,"--[no-]full-tailcalls", "(Don't) use full tail-calls");
printOption(out, "-C <filename> ...", "Compile named files to Java class files");
printOption(out, "--output-format <format>", "Use <format> when printing top-level output");
......@@ -608,16 +609,18 @@ public class repl extends Procedure0or1 {
CheckConsole.setHaveConsole(true);
else if (arg.equals("--inline")) {
Compilation.inlineOk = true;
} else if (arg.equals("--cps")) {
} else if (arg.equals("--strict-typing")) {
Compilation.strictTyping = true;
} else if (arg.equals("--cps")) {
Compilation.defaultCallConvention
= Compilation.CALL_WITH_CONTINUATIONS;
} else if (arg.equals("--full-tailcalls")) {
Compilation.defaultCallConvention
= Compilation.CALL_WITH_TAILCALLS;
} else if (arg.equals("--no-full-tailcalls")) {
Compilation.defaultCallConvention
= Compilation.CALL_WITH_RETURN;
} else if (arg.equals("--pedantic")) {
Compilation.defaultCallConvention
= Compilation.CALL_WITH_RETURN;
} else if (arg.equals("--pedantic")) {
Language.requirePedantic = true;
} else if (arg.equals("--help")) {
printOptions(System.out);
......
......@@ -29,7 +29,7 @@ check: check2-no-full-tailcalls check1 check2-full-tailcalls check-no-inline \
check-interpreted-cycle check-interpreted-cycleb check-interpreted-cyclebr \
$(SERVLET_TESTS) $(SAX2_TESTS) \
check-inlining check-jmc check-use-slots check-load-require check-sva31180 \
check-bridge check-life-grid check-larceny-tests check-numbers-clisp
check-bridge check-life-grid check-larceny-tests check-numbers-clisp check-strict-typing
check-anf:
$(MAKE) check1 check2 OPTIONS=--enable-anf
......@@ -70,6 +70,9 @@ check-scm: testing.zip
-e "(set! symbol-read-case 'D)" --no-warn-undefined-variable \
-f $(srcdir)/test.scm -e '(test-report)'
check-strict-typing:
$(KAWA) --strict-typing strict-typing-test.scm
check-case: testing.zip
$(KAWATEST) -f "$(srcdir)/case-test.scm" -e '(test-report)'
......
;;; This will pass because of the explicit mention of types
(define (greater-equal x::int y::int)::boolean
(>= x y))
;;; This will fail since x's type in not mentioned
;(define (greater-equal x y)
; (>= x y))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment