Adds System.setErr and LinkageError

This commit is contained in:
konsoletyper 2014-03-01 21:28:40 +04:00
parent d68f78f77d
commit cb8f424339
3 changed files with 56 additions and 4 deletions

View File

@ -17,12 +17,10 @@ package org.teavm.classlib.java.lang;
import java.io.IOException;
import org.teavm.codegen.SourceWriter;
import org.teavm.dependency.DependencyChecker;
import org.teavm.dependency.DependencyNode;
import org.teavm.dependency.DependencyPlugin;
import org.teavm.dependency.MethodDependency;
import org.teavm.dependency.*;
import org.teavm.javascript.ni.Generator;
import org.teavm.javascript.ni.GeneratorContext;
import org.teavm.model.FieldReference;
import org.teavm.model.MethodReference;
/**
@ -39,6 +37,11 @@ public class SystemNativeGenerator implements Generator, DependencyPlugin {
case "currentTimeMillis":
generateCurrentTimeMillis(writer);
break;
case "setErr":
writer.appendClass("java.lang.System").append('.')
.appendField(new FieldReference("java.lang.System", "err"))
.ws().append('=').ws().append(context.getParameterName(1)).append(";").softNewLine();
break;
}
}
@ -48,6 +51,9 @@ public class SystemNativeGenerator implements Generator, DependencyPlugin {
case "doArrayCopy":
achieveArrayCopy(method);
break;
case "setErr":
achieveSetErr(checker, method);
break;
}
}
@ -71,4 +77,9 @@ public class SystemNativeGenerator implements Generator, DependencyPlugin {
DependencyNode dest = method.getVariable(3);
src.getArrayItem().connect(dest.getArrayItem());
}
private void achieveSetErr(DependencyChecker checker, MethodDependency method) {
FieldDependency fieldDep = checker.linkField(new FieldReference("java.lang.System", "err"), method.getStack());
method.getVariable(1).connect(fieldDep.getValue());
}
}

View File

@ -0,0 +1,36 @@
/*
* Copyright 2014 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.classlib.java.lang;
/**
*
* @author Alexey Andreev <konsoletyper@gmail.com>
*/
public class TLinkageError extends TError {
private static final long serialVersionUID = 9176544705010852435L;
public TLinkageError() {
super();
}
public TLinkageError(TString message, TThrowable cause) {
super(message, cause);
}
public TLinkageError(TString message) {
super(message);
}
}

View File

@ -17,6 +17,7 @@ package org.teavm.classlib.java.lang;
import org.teavm.classlib.java.io.TPrintStream;
import org.teavm.classlib.java.lang.reflect.TArray;
import org.teavm.dependency.PluggableDependency;
import org.teavm.javascript.ni.GeneratedBy;
/**
@ -60,4 +61,8 @@ public final class TSystem extends TObject {
// TODO: make implementation
return null;
}
@GeneratedBy(SystemNativeGenerator.class)
@PluggableDependency(SystemNativeGenerator.class)
public static native void setErr(TPrintStream err);
}