Skip to content

Commit

Permalink
Implement some missing LocalePlugin primitives
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Dec 17, 2019
1 parent a83b747 commit 902640d
Showing 1 changed file with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@
*/
package de.hpi.swa.graal.squeak.nodes.plugins;

import java.text.NumberFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;

import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.Specialization;

import de.hpi.swa.graal.squeak.exceptions.PrimitiveExceptions.PrimitiveFailed;
import de.hpi.swa.graal.squeak.model.BooleanObject;
import de.hpi.swa.graal.squeak.model.CompiledMethodObject;
import de.hpi.swa.graal.squeak.nodes.primitives.AbstractPrimitiveFactoryHolder;
import de.hpi.swa.graal.squeak.nodes.primitives.AbstractPrimitiveNode;
Expand All @@ -34,6 +39,7 @@ protected PrimCountryNode(final CompiledMethodObject method) {
}

@Specialization
@TruffleBoundary
protected final Object doCountry(@SuppressWarnings("unused") final Object receiver) {
final String country = Locale.getDefault().getCountry();
if (country.isEmpty()) {
Expand Down Expand Up @@ -64,8 +70,9 @@ protected PrimCurrencySymbolNode(final CompiledMethodObject method) {
}

@Specialization
protected static final Object fail(@SuppressWarnings("unused") final Object receiver) {
throw PrimitiveFailed.GENERIC_ERROR; // TODO: implement primitive
@TruffleBoundary
protected final Object doCurrencySymbol(@SuppressWarnings("unused") final Object receiver) {
return method.image.asByteString(NumberFormat.getCurrencyInstance().getCurrency().getCurrencyCode());
}
}

Expand All @@ -77,8 +84,9 @@ protected PrimDaylightSavingsNode(final CompiledMethodObject method) {
}

@Specialization
protected static final Object fail(@SuppressWarnings("unused") final Object receiver) {
throw PrimitiveFailed.GENERIC_ERROR; // TODO: implement primitive
@TruffleBoundary
protected static final Object doDaylightSavings(@SuppressWarnings("unused") final Object receiver) {
return BooleanObject.wrap(TimeZone.getDefault().inDaylightTime(new Date()));
}
}

Expand Down Expand Up @@ -116,6 +124,7 @@ protected PrimLanguageNode(final CompiledMethodObject method) {
}

@Specialization
@TruffleBoundary
protected final Object doLanguage(@SuppressWarnings("unused") final Object receiver) {
final String language = Locale.getDefault().getLanguage();
if (language.isEmpty()) {
Expand Down Expand Up @@ -185,8 +194,9 @@ protected PrimTimezoneOffsetNode(final CompiledMethodObject method) {
}

@Specialization
protected static final Object fail(@SuppressWarnings("unused") final Object receiver) {
throw PrimitiveFailed.GENERIC_ERROR; // TODO: implement primitive
@TruffleBoundary
protected static final long doTimezoneOffset(@SuppressWarnings("unused") final Object receiver) {
return TimeZone.getDefault().getRawOffset() / 60 / 1000;
}
}

Expand All @@ -198,8 +208,8 @@ protected PrimVMOffsetToUTCNode(final CompiledMethodObject method) {
}

@Specialization
protected static final Object fail(@SuppressWarnings("unused") final Object receiver) {
throw PrimitiveFailed.GENERIC_ERROR; // TODO: implement primitive
protected static final long doVMOffsetToUTC(@SuppressWarnings("unused") final Object receiver) {
return 0L;
}
}
}

0 comments on commit 902640d

Please sign in to comment.