13514
|
1 /*
|
|
2 * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved. This
|
|
3 * code is released under a tri EPL/GPL/LGPL license. You can use it,
|
|
4 * redistribute it and/or modify it under the terms of the:
|
|
5 *
|
|
6 * Eclipse Public License version 1.0
|
|
7 * GNU General Public License version 2
|
|
8 * GNU Lesser General Public License version 2.1
|
|
9 */
|
|
10 package com.oracle.truffle.ruby.nodes.core;
|
|
11
|
|
12 import com.oracle.truffle.api.*;
|
|
13 import com.oracle.truffle.api.dsl.*;
|
|
14 import com.oracle.truffle.ruby.runtime.*;
|
|
15 import com.oracle.truffle.ruby.runtime.core.*;
|
|
16 import com.oracle.truffle.ruby.runtime.core.array.*;
|
|
17
|
|
18 @CoreClass(name = "Exception")
|
|
19 public abstract class ExceptionNodes {
|
|
20
|
|
21 @CoreMethod(names = "initialize", minArgs = 0, maxArgs = 1)
|
|
22 public abstract static class InitializeNode extends CoreMethodNode {
|
|
23
|
|
24 public InitializeNode(RubyContext context, SourceSection sourceSection) {
|
|
25 super(context, sourceSection);
|
|
26 }
|
|
27
|
|
28 public InitializeNode(InitializeNode prev) {
|
|
29 super(prev);
|
|
30 }
|
|
31
|
|
32 @Specialization
|
|
33 public NilPlaceholder initialize(RubyException exception, @SuppressWarnings("unused") UndefinedPlaceholder message) {
|
|
34 exception.initialize(getContext().makeString(" "));
|
|
35 return NilPlaceholder.INSTANCE;
|
|
36 }
|
|
37
|
|
38 @Specialization
|
|
39 public NilPlaceholder initialize(RubyException exception, RubyString message) {
|
|
40 exception.initialize(message);
|
|
41 return NilPlaceholder.INSTANCE;
|
|
42 }
|
|
43
|
|
44 }
|
|
45
|
|
46 @CoreMethod(names = "backtrace", needsSelf = false, maxArgs = 0)
|
|
47 public abstract static class BacktraceNode extends CoreMethodNode {
|
|
48
|
|
49 public BacktraceNode(RubyContext context, SourceSection sourceSection) {
|
|
50 super(context, sourceSection);
|
|
51 }
|
|
52
|
|
53 public BacktraceNode(BacktraceNode prev) {
|
|
54 super(prev);
|
|
55 }
|
|
56
|
|
57 @Specialization
|
|
58 public RubyArray backtrace() {
|
|
59 return new RubyArray(getContext().getCoreLibrary().getArrayClass());
|
|
60 }
|
|
61
|
|
62 }
|
|
63
|
|
64 @CoreMethod(names = "message", maxArgs = 0)
|
|
65 public abstract static class MessageNode extends CoreMethodNode {
|
|
66
|
|
67 public MessageNode(RubyContext context, SourceSection sourceSection) {
|
|
68 super(context, sourceSection);
|
|
69 }
|
|
70
|
|
71 public MessageNode(MessageNode prev) {
|
|
72 super(prev);
|
|
73 }
|
|
74
|
|
75 @Specialization
|
|
76 public RubyString message(RubyException exception) {
|
|
77 return exception.getMessage();
|
|
78 }
|
|
79
|
|
80 }
|
|
81
|
|
82 }
|