本文整理汇总了Java中com.oracle.truffle.api.source.Source类的典型用法代码示例。如果您正苦于以下问题:Java Source类的具体用法?Java Source怎么用?Java Source使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Source类属于com.oracle.truffle.api.source包,在下文中一共展示了Source类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: parse
import com.oracle.truffle.api.source.Source; //导入依赖的package包/类
public static HBSourceRootNode parse(HBLanguage language, Source source) throws Exception {
Parser parser = new Parser(language, source);
HBSourceRootNode program = parser.Parse();
// if (parser.errors.size() > 0) {
// StringBuilder message = new StringBuilder("Error(s) parsing script:\n");
// for (String error : parser.errors) {
// message.append(error).append("\n");
// }
// throw new Exception(message.toString());
// } else {
//
// }
if (parser.errors.count > 0) {
throw new Exception("Error parsing program");
}
return program;
}
开发者ID:dirk,项目名称:hummingbird2,代码行数:21,代码来源:ParserWrapper.java
示例2: parse
import com.oracle.truffle.api.source.Source; //导入依赖的package包/类
@Override
protected CallTarget parse(ParsingRequest request) throws Exception {
Source source = request.getSource();
HBSourceRootNode program = ParserWrapper.parse(this, source);
System.out.println(program.toString());
// Bootstrap the builtin node targets and the builtin types in the
// type-system.
BuiltinNodes builtinNodes = BuiltinNodes.bootstrap(this);
Index index = Index.bootstrap(builtinNodes);
InferenceVisitor visitor = new InferenceVisitor(index);
program.accept(visitor);
return Truffle.getRuntime().createCallTarget(program);
}
开发者ID:dirk,项目名称:hummingbird2,代码行数:18,代码来源:HBLanguage.java
示例3: processCoverage
import com.oracle.truffle.api.source.Source; //导入依赖的package包/类
private void processCoverage(final long counterVal,
final SourceSection sourceSection, final Map<String, Long[]> coverageMap) {
Long[] array;
Source s = sourceSection.getSource();
String path = s.getPath() != null ? s.getPath() : s.getName();
if (coverageMap.containsKey(path)) {
array = coverageMap.get(path);
} else if (s.getLineCount() == 0) {
return;
} else {
array = new Long[s.getLineCount()];
coverageMap.put(path, array);
}
int line = sourceSection.getStartLine() - 1;
updateLine(array, line, counterVal);
}
开发者ID:MetaConc,项目名称:CoverallsTruffle,代码行数:19,代码来源:Coverage.java
示例4: checkCoverageMapForTestSLFile
import com.oracle.truffle.api.source.Source; //导入依赖的package包/类
@Test
public void checkCoverageMapForTestSLFile() throws IOException {
InputStream testSlFile = getClass().getResourceAsStream("test.sl");
Source testSl = Source.newBuilder(new InputStreamReader(testSlFile)).
name(TEST_FILE).mimeType("application/x-sl").
build();
engine.eval(testSl);
Map<String, Long[]> result = covInst.getCoverageMap(new HashMap<>());
assertTrue(result.containsKey(TEST_FILE));
Long[] lines = result.get(TEST_FILE);
assertArrayEquals(new Long[] {
null, 0L, 0L, 0L, null, null,
null, null, 20L, null, 120L, 100L, null, null, 20L, null, null,
null, 1L, null, 21L, 20L, 20L, 20L, 0L, null, null, null}, lines);
}
开发者ID:MetaConc,项目名称:CoverallsTruffle,代码行数:20,代码来源:Tests.java
示例5: loadModule
import com.oracle.truffle.api.source.Source; //导入依赖的package包/类
public MixinDefinition loadModule(final Source source) throws IOException {
URI uri = source.getURI();
if (loadedModules.containsKey(uri)) {
return loadedModules.get(uri);
}
MixinDefinition module;
try {
module = compiler.compileModule(source, structuralProbe);
loadedModules.put(uri, module);
return module;
} catch (ProgramDefinitionError e) {
vm.errorExit(e.toString());
throw new IOException(e);
}
}
开发者ID:smarr,项目名称:SOMns,代码行数:17,代码来源:ObjectSystem.java
示例6: addSyntheticInitializerWithoutSuperSendOnlyForThingClass
import com.oracle.truffle.api.source.Source; //导入依赖的package包/类
public void addSyntheticInitializerWithoutSuperSendOnlyForThingClass() {
SSymbol init = MixinBuilder.getInitializerName(Symbols.NEW);
MethodBuilder builder = new MethodBuilder(true, initializerBuilder.getLanguage());
builder.setSignature(init);
builder.addArgument("self",
SomLanguage.getSyntheticSource("self read", "super-class-resolution")
.createSection(1));
Source source = SomLanguage.getSyntheticSource("self", "Thing>>" + init.getString());
SourceSection ss = source.createSection(0, 4);
builder.setVarsOnMethodScope();
builder.finalizeMethodScope();
SInvokable thingInitNew = builder.assembleInitializer(
builder.getSelfRead(ss), AccessModifier.PROTECTED, ss);
instanceDispatchables.put(init, thingInitNew);
}
开发者ID:smarr,项目名称:SOMns,代码行数:17,代码来源:MixinDefinition.java
示例7: Parser
import com.oracle.truffle.api.source.Source; //导入依赖的package包/类
public Parser(final String content, final long fileSize, final Source source,
final StructuralProbe structuralProbe, final SomLanguage language) throws ParseError {
this.source = source;
this.language = language;
sym = NONE;
nextSym = NONE;
if (fileSize == 0) {
throw new ParseError("Provided file is empty.", NONE, this);
}
lexer = new Lexer(content);
getSymbolFromLexer();
this.syntaxAnnotations = new HashSet<>();
this.structuralProbe = structuralProbe;
}
开发者ID:smarr,项目名称:SOMns,代码行数:20,代码来源:Parser.java
示例8: processCoverage
import com.oracle.truffle.api.source.Source; //导入依赖的package包/类
private static void processCoverage(final long counterVal,
final SourceSection sourceSection, final Map<Source, Long[]> coverageMap) {
Long[] array;
Source src = sourceSection.getSource();
if (coverageMap.containsKey(src)) {
array = coverageMap.get(src);
} else if (src.getLineCount() == 0) {
return;
} else {
array = new Long[src.getLineCount()];
coverageMap.put(src, array);
}
int line = sourceSection.getStartLine() - 1;
if (array[line] == null) {
array[line] = counterVal;
} else {
array[line] = Math.max(counterVal, array[line]);
}
}
开发者ID:smarr,项目名称:SOMns,代码行数:21,代码来源:MetricsCsvWriter.java
示例9: getCoverageStats
import com.oracle.truffle.api.source.Source; //导入依赖的package包/类
private CovStats getCoverageStats(final Map<Source, Long[]> coverageMap) {
int linesLoaded = 0;
int linesExecuted = 0;
int linesWithStatements = 0;
for (Entry<Source, Long[]> e : coverageMap.entrySet()) {
Long[] lines = e.getValue();
linesLoaded += lines.length;
for (Long l : lines) {
if (l != null) {
linesWithStatements += 1;
long val = l;
if (val > 0) {
linesExecuted += 1;
}
}
}
}
return new CovStats(linesLoaded, linesExecuted, linesWithStatements);
}
开发者ID:smarr,项目名称:SOMns,代码行数:24,代码来源:MetricsCsvWriter.java
示例10: sectionToJson
import com.oracle.truffle.api.source.Source; //导入依赖的package包/类
private JSONObjectBuilder sectionToJson(final SourceSection ss, final String id,
final Map<Source, String> sourceToId) {
JSONObjectBuilder builder = JSONHelper.object();
builder.add("id", id);
builder.add("firstIndex", ss.getCharIndex());
builder.add("length", ss.getCharLength());
builder.add("sourceId", sourceToId.get(ss.getSource()));
// TODO: add tags to section, need to get it from some tag map, I think
// if (ss.getTags() != null && ss.getTags().length > 0) {
// JSONArrayBuilder arr = JSONHelper.array();
// for (String tag : ss.getTags()) {
// arr.add(tag);
// }
// builder.add("tags", arr);
// }
builder.add("data", collectDataForSection(ss));
return builder;
}
开发者ID:smarr,项目名称:SOMns,代码行数:23,代码来源:JsonWriter.java
示例11: prepareVM
import com.oracle.truffle.api.source.Source; //导入依赖的package包/类
@Override
protected PolyglotEngine prepareVM(final PolyglotEngine.Builder preparedBuilder)
throws IOException {
VM vm = new VM(new VmOptions(new String[] {
"--kernel", VmOptions.STANDARD_KERNEL_FILE,
"--platform", VmOptions.STANDARD_PLATFORM_FILE}), true);
preparedBuilder.config(SomLanguage.MIME_TYPE, SomLanguage.VM_OBJECT, vm);
InputStream in = getClass().getResourceAsStream("TruffleSomTCK.ns");
Source source = Source.newBuilder(new InputStreamReader(in)).mimeType(
mimeType()).name("TruffleSomTCK.ns").build();
PolyglotEngine engine = preparedBuilder.build();
Value tckModule = engine.eval(source);
SClass tck = tckModule.as(SClass.class);
ObjectTransitionSafepoint.INSTANCE.register();
tck.getMixinDefinition().instantiateObject(tck, vm.getVmMirror());
ObjectTransitionSafepoint.INSTANCE.unregister();
return engine;
}
开发者ID:smarr,项目名称:SOMns,代码行数:23,代码来源:TruffleSomTCK.java
示例12: fillInStackTrace
import com.oracle.truffle.api.source.Source; //导入依赖的package包/类
@Override
public Throwable fillInStackTrace() {
SourceSection sourceSection = this.getSourceSection();
Source source = sourceSection != null ? sourceSection.getSource() : null;
String sourceName = source != null ? source.getName() : null;
int lineNumber;
try {
lineNumber = sourceSection != null ? sourceSection.getLineLocation().getLineNumber() : -1;
} catch (UnsupportedOperationException e) {
/*
* SourceSection#getLineLocation() may throw an UnsupportedOperationException.
*/
lineNumber = -1;
}
StackTraceElement[] traces = new StackTraceElement[] {
new StackTraceElement(filename(sourceName),
this.getMethodName(),
sourceName,
lineNumber)
};
this.setStackTrace(traces);
return this;
}
开发者ID:cesquivias,项目名称:mumbler,代码行数:24,代码来源:MumblerReadException.java
示例13: startREPL
import com.oracle.truffle.api.source.Source; //导入依赖的package包/类
private static void startREPL() throws IOException {
Console console = System.console();
while (true) {
// READ
String data = console.readLine(PROMPT);
if (data == null) {
// EOF sent
break;
}
MumblerContext context = new MumblerContext();
Source source = Source.fromText(data, "<console>");
ListSyntax sexp = Reader.read(source);
// TODO : replace with MumblerLanguage#parse
Converter converter = new Converter(flags.tailCallOptimizationEnabled);
MumblerNode[] nodes = converter.convertSexp(context, sexp);
// EVAL
Object result = execute(nodes, context.getGlobalFrame());
// PRINT
if (result != MumblerList.EMPTY) {
System.out.println(result);
}
}
}
开发者ID:cesquivias,项目名称:mumbler,代码行数:26,代码来源:TruffleMumblerMain.java
示例14: parse
import com.oracle.truffle.api.source.Source; //导入依赖的package包/类
@Override
public IStrategoTerm parse(Source src, @Nullable String overridingStartSymbol) {
if (parser == null) {
createParser();
}
String startSymbol = this.startSymbol;
if (overridingStartSymbol != null) {
startSymbol = overridingStartSymbol;
}
try {
final Disambiguator disambiguator = parser.getDisambiguator();
disambiguator.setFilterPriorities(false);
SGLRParseResult parseResult = parser.parse(IOUtils.toString(src.getInputStream(), Charset.defaultCharset()),
src.getPath(), startSymbol);
IStrategoTerm term = (IStrategoTerm) parseResult.output;
return term;
} catch (SGLRException | InterruptedException | IOException e) {
throw new IllegalStateException("File failed to parse", e);
}
}
开发者ID:metaborg,项目名称:dynsem,代码行数:23,代码来源:DynSemLanguageParser.java
示例15: compileClass
import com.oracle.truffle.api.source.Source; //导入依赖的package包/类
@TruffleBoundary
public static SClass compileClass(final String path, final String file,
final SClass systemClass, final Universe universe)
throws IOException {
String fname = path + File.separator + file + ".som";
FileReader stream = new FileReader(fname);
File f = new File(fname);
Source source = Source.newBuilder(f).build();
Parser parser = new Parser(stream, f.length(), source, universe);
SClass result = compile(parser, systemClass, universe);
SSymbol cname = result.getName();
String cnameC = cname.getString();
if (file != cnameC) {
throw new IllegalStateException("File name " + file
+ " does not match class name " + cnameC);
}
return result;
}
开发者ID:smarr,项目名称:TruffleSOM,代码行数:24,代码来源:SourcecodeCompiler.java
示例16: parse
import com.oracle.truffle.api.source.Source; //导入依赖的package包/类
@Override
protected CallTarget parse(ParsingRequest request) throws Exception {
Source source = request.getSource();
try(IndexedPushbackReader r = new IndexedPushbackReader(source.getReader())) {
List<CallTarget> callTargets = new ArrayList<>();
while(true) {
int startIndex = r.getPosition();
Object form = Reader.read(r);
if (form == null) {
break;
}
RootNode expr = Analyzer.analyzeRoot(this, form, source.createSection(startIndex, r.getPosition()-startIndex-1));
callTargets.add(Truffle.getRuntime().createCallTarget(expr));
}
SequenceNode node = new SequenceNode(callTargets.toArray(new CallTarget[0]));
RootNode root = new RootNode(this, null, node);
//NodeUtil.printCompactTree(System.out, root);
return Truffle.getRuntime().createCallTarget(root);
//return Truffle.getRuntime().createCallTarget(new RootNode(null, null, doNode));
}
}
开发者ID:ragnard,项目名称:shen-truffle,代码行数:29,代码来源:Language.java
示例17: eval
import com.oracle.truffle.api.source.Source; //导入依赖的package包/类
public Object eval(String s) {
Source code = Source.newBuilder(s)
.name("<eval>")
.interactive()
.mimeType(Language.MIME_TYPE)
.build();
return eval(code);
}
开发者ID:ragnard,项目名称:shen-truffle,代码行数:10,代码来源:KLambda.java
示例18: Source
import com.oracle.truffle.api.source.Source; //导入依赖的package包/类
HBSourceRootNode Source() {
HBSourceRootNode result;
HBStatementNode[] statements = SourceStatements();
result = HBSourceRootNodeFactory.create(
this.language,
source.createUnavailableSection(),
statements);
return result;
}
开发者ID:dirk,项目名称:hummingbird2,代码行数:10,代码来源:Parser.java
示例19: getSource
import com.oracle.truffle.api.source.Source; //导入依赖的package包/类
private static Source getSource(SLFunction function) {
SourceSection section = function.getCallTarget().getRootNode().getSourceSection();
if (section != null) {
return section.getSource();
}
return null;
}
开发者ID:graalvm,项目名称:graal-core,代码行数:8,代码来源:SLCallFunctionsWithBuiltin.java
示例20: SomParser
import com.oracle.truffle.api.source.Source; //导入依赖的package包/类
public SomParser(final String content, final long fileSize, final Source source,
final SomStructures structuralProbe, final SomLanguage lang) throws ParseError {
super(content, fileSize, source, structuralProbe, lang);
// assert structuralProbe != null : "Needed for this extended parser.";
this.struturalProbe = structuralProbe;
sourceSections = new ArrayDeque<>();
}
开发者ID:smarr,项目名称:SOMns-vscode,代码行数:8,代码来源:SomParser.java
注:本文中的com.oracle.truffle.api.source.Source类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论