Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add NanoTimeFunctionElement #27

Merged
merged 1 commit into from
May 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* NanoTimeFunctionElement.java 1.0
*
* Copyright (C) 2006 Roozbeh Farahbod
*
* Last modified by $Author: rfarahbod $ on $Date: 2011-03-29 02:05:21 +0200 (Di, 29 Mrz 2011) $.
*
* Licensed under the Academic Free License version 3.0
* http://www.opensource.org/licenses/afl-3.0.php
* http://www.coreasm.org/afl-3.0.php
*
*/

package org.coreasm.engine.plugins.time;

import org.coreasm.engine.absstorage.Element;
import org.coreasm.engine.absstorage.FunctionElement;
import org.coreasm.engine.plugins.number.NumberElement;

import java.util.List;

/**
* Implements 'nanoTime' as a monitored function that returns the current value of the running Java Virtual Machine's
* high-resolution time source, in nanoseconds.
*
* @author André Wolski
*
*/
public class NanoTimeFunctionElement extends FunctionElement {

/** Name of this function */
public static final String NANOTIME_FUNC_NAME = "nanoTime";

public NanoTimeFunctionElement() {
super();
setFClass(FunctionClass.fcMonitored);
}

/* (non-Javadoc)
* @see org.coreasm.engine.absstorage.FunctionElement#getValue(java.util.List)
*/
@Override
public Element getValue(List<? extends Element> args) {
if (args.size() > 0)
return Element.UNDEF;
else
return NumberElement.getInstance(System.nanoTime());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
*/
public class TimePlugin extends Plugin implements VocabularyExtender {

public static final VersionInfo VERSION_INFO = new VersionInfo(0, 2, 0, "");
public static final VersionInfo VERSION_INFO = new VersionInfo(0, 3, 0, "");

private final Set<String> dependencyList;

Expand Down Expand Up @@ -75,6 +75,7 @@ public Map<String,FunctionElement> getFunctions() {
if (functions == null) {
functions = new HashMap<String,FunctionElement>();
functions.put(NowFunctionElement.NOW_FUNC_NAME, new NowFunctionElement());
functions.put(NanoTimeFunctionElement.NANOTIME_FUNC_NAME, new NanoTimeFunctionElement());
functions.put(StepCountFunctionElement.FUNC_NAME, new StepCountFunctionElement(capi));
}
return functions;
Expand Down