bugged
stringlengths
6
599k
fixed
stringlengths
6
40.8M
__index_level_0__
int64
0
3.24M
void setCurMax(int v) { curMax = "end: "+v; super.repaint(0, 0, leftBorder, HEIGHT); }
void setCurMax(int v) { curMax = "end: "+v; super.repaint(0, 0, leftBorder, HEIGHT); }
3,238,648
void setCurMin(int v) { curMin = "start: "+v; super.repaint(0, 0, leftBorder, HEIGHT); }
void setCurMin(int v) { curMin = "start: "+v; super.repaint(0, 0, leftBorder, HEIGHT); }
3,238,649
public void gt() { System.err.println ("build: >"); newData (); _currentData.setType (WikiDataTypes.GT); }
public void gt() { newData (); _currentData.setType (WikiDataTypes.GT); }
3,238,650
public void lt() { System.err.println ("build: <"); newData (); _currentData.setType (WikiDataTypes.LT); }
public void lt() { newData (); _currentData.setType (WikiDataTypes.LT); }
3,238,651
public RubyObject eval(Ruby ruby, RubyObject self) { // TMP_PROTECT; if (ruby.getRubyFrame().getLastClass() == null) { throw new RubyNameException("superclass method '" + ruby.getRubyFrame().getLastFunc().toName() + "' disabled"); } RubyBlock tmpBlock = ArgsUtil.beginCallArgs(ruby); RubyObject[] argsObj = ArgsUtil.setupArgs(ruby, self, getArgsNode()); ArgsUtil.endCallArgs(ruby, tmpBlock); ruby.getIter().push(ruby.getIter().getIter() != RubyIter.ITER_NOT ? RubyIter.ITER_PRE : RubyIter.ITER_NOT); RubyObject result = ruby.getRubyFrame().getLastClass().getSuperClass().call( ruby.getRubyFrame().getSelf(), ruby.getRubyFrame().getLastFunc(), argsObj, 3); ruby.getIter().pop(); return result; }
public RubyObject eval(Ruby ruby, RubyObject self) { // TMP_PROTECT; if (ruby.getRubyFrame().getLastClass() == null) { throw new RubyNameException("superclass method '" + ruby.getRubyFrame().getLastFunc().toName() + "' disabled"); } RubyBlock tmpBlock = ArgsUtil.beginCallArgs(ruby); RubyPointer args = ArgsUtil.setupArgs(ruby, self, getArgsNode()); ArgsUtil.endCallArgs(ruby, tmpBlock); ruby.getIter().push(ruby.getIter().getIter() != RubyIter.ITER_NOT ? RubyIter.ITER_PRE : RubyIter.ITER_NOT); RubyObject result = ruby.getRubyFrame().getLastClass().getSuperClass().call( ruby.getRubyFrame().getSelf(), ruby.getRubyFrame().getLastFunc(), argsObj, 3); ruby.getIter().pop(); return result; }
3,238,653
public RubyObject eval(Ruby ruby, RubyObject self) { // TMP_PROTECT; if (ruby.getRubyFrame().getLastClass() == null) { throw new RubyNameException("superclass method '" + ruby.getRubyFrame().getLastFunc().toName() + "' disabled"); } RubyBlock tmpBlock = ArgsUtil.beginCallArgs(ruby); RubyObject[] argsObj = ArgsUtil.setupArgs(ruby, self, getArgsNode()); ArgsUtil.endCallArgs(ruby, tmpBlock); ruby.getIter().push(ruby.getIter().getIter() != RubyIter.ITER_NOT ? RubyIter.ITER_PRE : RubyIter.ITER_NOT); RubyObject result = ruby.getRubyFrame().getLastClass().getSuperClass().call( ruby.getRubyFrame().getSelf(), ruby.getRubyFrame().getLastFunc(), argsObj, 3); ruby.getIter().pop(); return result; }
public RubyObject eval(Ruby ruby, RubyObject self) { // TMP_PROTECT; if (ruby.getRubyFrame().getLastClass() == null) { throw new RubyNameException("superclass method '" + ruby.getRubyFrame().getLastFunc().toName() + "' disabled"); } RubyBlock tmpBlock = ArgsUtil.beginCallArgs(ruby); RubyObject[] argsObj = ArgsUtil.setupArgs(ruby, self, getArgsNode()); ArgsUtil.endCallArgs(ruby, tmpBlock); ruby.getIter().push(ruby.getIter().getIter() != RubyIter.ITER_NOT ? RubyIter.ITER_PRE : RubyIter.ITER_NOT); RubyObject result = ruby.getRubyFrame().getLastClass().getSuperClass().call( ruby.getRubyFrame().getSelf(), ruby.getRubyFrame().getLastFunc(), args, 3); ruby.getIter().pop(); return result; }
3,238,654
private void addTransport(final Transport transport) { final StatusBar statusBar = SparkManager.getWorkspace().getStatusBar(); final JPanel commandPanel = statusBar.getCommandPanel(); final boolean isRegistered = TransportManager.isRegistered(SparkManager.getConnection(), transport); final RolloverButton button = new RolloverButton(); if (!isRegistered) { button.setIcon(transport.getInactiveIcon()); } else { button.setIcon(transport.getIcon()); } button.setToolTipText(transport.getInstructions()); commandPanel.add(button); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { boolean reg = TransportManager.isRegistered(SparkManager.getConnection(), transport); if (!reg) { TransportRegistrationDialog regDialog = new TransportRegistrationDialog(transport.getServiceName()); regDialog.invoke(); } else { int confirm = JOptionPane.showConfirmDialog(SparkManager.getMainWindow(), Res.getString("message.disable.transport"), Res.getString("title.disable.transport"), JOptionPane.YES_NO_OPTION); if (confirm == JOptionPane.YES_OPTION) { try { TransportManager.unregister(SparkManager.getConnection(), transport.getServiceName()); } catch (XMPPException e1) { Log.error(e1); } } } } }); uiMap.put(transport, button); statusBar.invalidate(); statusBar.validate(); statusBar.repaint(); }
private void addTransport(final Transport transport) { final StatusBar statusBar = SparkManager.getWorkspace().getStatusBar(); final JPanel commandPanel = statusBar.getCommandPanel(); final RolloverButton button = new RolloverButton(); if (!isRegistered) { button.setIcon(transport.getInactiveIcon()); } else { button.setIcon(transport.getIcon()); } button.setToolTipText(transport.getInstructions()); commandPanel.add(button); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { boolean reg = TransportManager.isRegistered(SparkManager.getConnection(), transport); if (!reg) { TransportRegistrationDialog regDialog = new TransportRegistrationDialog(transport.getServiceName()); regDialog.invoke(); } else { int confirm = JOptionPane.showConfirmDialog(SparkManager.getMainWindow(), Res.getString("message.disable.transport"), Res.getString("title.disable.transport"), JOptionPane.YES_NO_OPTION); if (confirm == JOptionPane.YES_OPTION) { try { TransportManager.unregister(SparkManager.getConnection(), transport.getServiceName()); } catch (XMPPException e1) { Log.error(e1); } } } } }); uiMap.put(transport, button); statusBar.invalidate(); statusBar.validate(); statusBar.repaint(); }
3,238,655
private void addTransport(final Transport transport) { final StatusBar statusBar = SparkManager.getWorkspace().getStatusBar(); final JPanel commandPanel = statusBar.getCommandPanel(); final boolean isRegistered = TransportManager.isRegistered(SparkManager.getConnection(), transport); final RolloverButton button = new RolloverButton(); if (!isRegistered) { button.setIcon(transport.getInactiveIcon()); } else { button.setIcon(transport.getIcon()); } button.setToolTipText(transport.getInstructions()); commandPanel.add(button); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { boolean reg = TransportManager.isRegistered(SparkManager.getConnection(), transport); if (!reg) { TransportRegistrationDialog regDialog = new TransportRegistrationDialog(transport.getServiceName()); regDialog.invoke(); } else { int confirm = JOptionPane.showConfirmDialog(SparkManager.getMainWindow(), Res.getString("message.disable.transport"), Res.getString("title.disable.transport"), JOptionPane.YES_NO_OPTION); if (confirm == JOptionPane.YES_OPTION) { try { TransportManager.unregister(SparkManager.getConnection(), transport.getServiceName()); } catch (XMPPException e1) { Log.error(e1); } } } } }); uiMap.put(transport, button); statusBar.invalidate(); statusBar.validate(); statusBar.repaint(); }
private void addTransport(final Transport transport) { final StatusBar statusBar = SparkManager.getWorkspace().getStatusBar(); final JPanel commandPanel = statusBar.getCommandPanel(); final boolean isRegistered = TransportManager.isRegistered(SparkManager.getConnection(), transport); final RolloverButton button = new RolloverButton(); if (!isRegistered) { button.setIcon(transport.getInactiveIcon()); } else { button.setIcon(transport.getIcon()); } button.setToolTipText(transport.getInstructions()); commandPanel.add(button); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { boolean reg = TransportManager.isRegistered(SparkManager.getConnection(), transport); if (!reg) { TransportRegistrationDialog regDialog = new TransportRegistrationDialog(transport.getServiceName()); regDialog.invoke(); } else { int confirm = JOptionPane.showConfirmDialog(SparkManager.getMainWindow(), Res.getString("message.disable.transport"), Res.getString("title.disable.transport"), JOptionPane.YES_NO_OPTION); if (confirm == JOptionPane.YES_OPTION) { try { TransportManager.unregister(SparkManager.getConnection(), transport.getServiceName()); } catch (XMPPException e1) { Log.error(e1); } } } } }); uiMap.put(transport, button); statusBar.invalidate(); statusBar.validate(); statusBar.repaint(); }
3,238,656
private void addTransport(final Transport transport) { final StatusBar statusBar = SparkManager.getWorkspace().getStatusBar(); final JPanel commandPanel = statusBar.getCommandPanel(); final boolean isRegistered = TransportManager.isRegistered(SparkManager.getConnection(), transport); final RolloverButton button = new RolloverButton(); if (!isRegistered) { button.setIcon(transport.getInactiveIcon()); } else { button.setIcon(transport.getIcon()); } button.setToolTipText(transport.getInstructions()); commandPanel.add(button); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { boolean reg = TransportManager.isRegistered(SparkManager.getConnection(), transport); if (!reg) { TransportRegistrationDialog regDialog = new TransportRegistrationDialog(transport.getServiceName()); regDialog.invoke(); } else { int confirm = JOptionPane.showConfirmDialog(SparkManager.getMainWindow(), Res.getString("message.disable.transport"), Res.getString("title.disable.transport"), JOptionPane.YES_NO_OPTION); if (confirm == JOptionPane.YES_OPTION) { try { TransportManager.unregister(SparkManager.getConnection(), transport.getServiceName()); } catch (XMPPException e1) { Log.error(e1); } } } } }); uiMap.put(transport, button); statusBar.invalidate(); statusBar.validate(); statusBar.repaint(); }
private void addTransport(final Transport transport) { final StatusBar statusBar = SparkManager.getWorkspace().getStatusBar(); final JPanel commandPanel = statusBar.getCommandPanel(); final boolean isRegistered = TransportManager.isRegistered(SparkManager.getConnection(), transport); final RolloverButton button = new RolloverButton(); if (!isRegistered) { button.setIcon(transport.getInactiveIcon()); } else { button.setIcon(transport.getIcon()); } button.setToolTipText(transport.getInstructions()); commandPanel.add(button); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { boolean reg = TransportUtils.isRegistered(SparkManager.getConnection(), transport); if (!reg) { TransportRegistrationDialog regDialog = new TransportRegistrationDialog(transport.getServiceName()); regDialog.invoke(); } else { int confirm = JOptionPane.showConfirmDialog(SparkManager.getMainWindow(), Res.getString("message.disable.transport"), Res.getString("title.disable.transport"), JOptionPane.YES_NO_OPTION); if (confirm == JOptionPane.YES_OPTION) { try { TransportManager.unregister(SparkManager.getConnection(), transport.getServiceName()); } catch (XMPPException e1) { Log.error(e1); } } } } }); uiMap.put(transport, button); statusBar.invalidate(); statusBar.validate(); statusBar.repaint(); }
3,238,657
private void addTransport(final Transport transport) { final StatusBar statusBar = SparkManager.getWorkspace().getStatusBar(); final JPanel commandPanel = statusBar.getCommandPanel(); final boolean isRegistered = TransportManager.isRegistered(SparkManager.getConnection(), transport); final RolloverButton button = new RolloverButton(); if (!isRegistered) { button.setIcon(transport.getInactiveIcon()); } else { button.setIcon(transport.getIcon()); } button.setToolTipText(transport.getInstructions()); commandPanel.add(button); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { boolean reg = TransportManager.isRegistered(SparkManager.getConnection(), transport); if (!reg) { TransportRegistrationDialog regDialog = new TransportRegistrationDialog(transport.getServiceName()); regDialog.invoke(); } else { int confirm = JOptionPane.showConfirmDialog(SparkManager.getMainWindow(), Res.getString("message.disable.transport"), Res.getString("title.disable.transport"), JOptionPane.YES_NO_OPTION); if (confirm == JOptionPane.YES_OPTION) { try { TransportManager.unregister(SparkManager.getConnection(), transport.getServiceName()); } catch (XMPPException e1) { Log.error(e1); } } } } }); uiMap.put(transport, button); statusBar.invalidate(); statusBar.validate(); statusBar.repaint(); }
private void addTransport(final Transport transport) { final StatusBar statusBar = SparkManager.getWorkspace().getStatusBar(); final JPanel commandPanel = statusBar.getCommandPanel(); final boolean isRegistered = TransportManager.isRegistered(SparkManager.getConnection(), transport); final RolloverButton button = new RolloverButton(); if (!isRegistered) { button.setIcon(transport.getInactiveIcon()); } else { button.setIcon(transport.getIcon()); } button.setToolTipText(transport.getInstructions()); commandPanel.add(button); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { boolean reg = TransportManager.isRegistered(SparkManager.getConnection(), transport); if (!reg) { TransportRegistrationDialog regDialog = new TransportRegistrationDialog(transport.getServiceName()); regDialog.invoke(); } else { int confirm = JOptionPane.showConfirmDialog(SparkManager.getMainWindow(), Res.getString("message.disable.transport"), Res.getString("title.disable.transport"), JOptionPane.YES_NO_OPTION); if (confirm == JOptionPane.YES_OPTION) { try { TransportUtils.unregister(SparkManager.getConnection(), transport.getServiceName()); } catch (XMPPException e1) { Log.error(e1); } } } } }); uiMap.put(transport, button); statusBar.invalidate(); statusBar.validate(); statusBar.repaint(); }
3,238,658
public void actionPerformed(ActionEvent e) { boolean reg = TransportManager.isRegistered(SparkManager.getConnection(), transport); if (!reg) { TransportRegistrationDialog regDialog = new TransportRegistrationDialog(transport.getServiceName()); regDialog.invoke(); } else { int confirm = JOptionPane.showConfirmDialog(SparkManager.getMainWindow(), Res.getString("message.disable.transport"), Res.getString("title.disable.transport"), JOptionPane.YES_NO_OPTION); if (confirm == JOptionPane.YES_OPTION) { try { TransportManager.unregister(SparkManager.getConnection(), transport.getServiceName()); } catch (XMPPException e1) { Log.error(e1); } } } }
public void actionPerformed(ActionEvent e) { boolean reg = TransportUtils.isRegistered(SparkManager.getConnection(), transport); if (!reg) { TransportRegistrationDialog regDialog = new TransportRegistrationDialog(transport.getServiceName()); regDialog.invoke(); } else { int confirm = JOptionPane.showConfirmDialog(SparkManager.getMainWindow(), Res.getString("message.disable.transport"), Res.getString("title.disable.transport"), JOptionPane.YES_NO_OPTION); if (confirm == JOptionPane.YES_OPTION) { try { TransportManager.unregister(SparkManager.getConnection(), transport.getServiceName()); } catch (XMPPException e1) { Log.error(e1); } } } }
3,238,660
public void actionPerformed(ActionEvent e) { boolean reg = TransportManager.isRegistered(SparkManager.getConnection(), transport); if (!reg) { TransportRegistrationDialog regDialog = new TransportRegistrationDialog(transport.getServiceName()); regDialog.invoke(); } else { int confirm = JOptionPane.showConfirmDialog(SparkManager.getMainWindow(), Res.getString("message.disable.transport"), Res.getString("title.disable.transport"), JOptionPane.YES_NO_OPTION); if (confirm == JOptionPane.YES_OPTION) { try { TransportManager.unregister(SparkManager.getConnection(), transport.getServiceName()); } catch (XMPPException e1) { Log.error(e1); } } } }
public void actionPerformed(ActionEvent e) { boolean reg = TransportManager.isRegistered(SparkManager.getConnection(), transport); if (!reg) { TransportRegistrationDialog regDialog = new TransportRegistrationDialog(transport.getServiceName()); regDialog.invoke(); } else { int confirm = JOptionPane.showConfirmDialog(SparkManager.getMainWindow(), Res.getString("message.disable.transport"), Res.getString("title.disable.transport"), JOptionPane.YES_NO_OPTION); if (confirm == JOptionPane.YES_OPTION) { try { TransportUtils.unregister(SparkManager.getConnection(), transport.getServiceName()); } catch (XMPPException e1) { Log.error(e1); } } } }
3,238,661
public Icon getIcon(String jid) { Roster roster = SparkManager.getConnection().getRoster(); Presence presence = roster.getPresence(jid); String domain = StringUtils.parseServer(jid); Transport transport = TransportManager.getTransport(domain); if (transport != null) { if (presence != null && presence.getType() == Presence.Type.available) { return transport.getIcon(); } else { return transport.getInactiveIcon(); } } return null; }
public Icon getIcon(String jid) { Roster roster = SparkManager.getConnection().getRoster(); Presence presence = roster.getPresence(jid); String domain = StringUtils.parseServer(jid); Transport transport = TransportUtils.getTransport(domain); if (transport != null) { if (presence != null && presence.getType() == Presence.Type.available) { return transport.getIcon(); } else { return transport.getInactiveIcon(); } } return null; }
3,238,662
public boolean handlePresence(ContactItem item, Presence presence) { if (presence != null) { String domain = StringUtils.parseServer(presence.getFrom()); Transport transport = TransportManager.getTransport(domain); if (transport != null) { if (presence.getType() == Presence.Type.available) { item.setSideIcon(transport.getIcon()); } else { item.setSideIcon(transport.getInactiveIcon()); } return false; } } return false; }
public boolean handlePresence(ContactItem item, Presence presence) { if (presence != null) { String domain = StringUtils.parseServer(presence.getFrom()); Transport transport = TransportUtils.getTransport(domain); if (transport != null) { if (presence.getType() == Presence.Type.available) { item.setSideIcon(transport.getIcon()); } else { item.setSideIcon(transport.getInactiveIcon()); } return false; } } return false; }
3,238,663
public void initialize() { SwingWorker thread = new SwingWorker() { public Object construct() { try { populateTransports(SparkManager.getConnection()); for (final Transport transport : TransportManager.getTransports()) { addTransport(transport); } } catch (Exception e) { Log.error(e); return false; } return true; } public void finished() { Boolean transportExists = (Boolean)get(); if (!transportExists) { return; } // Register presences. registerPresences(); } }; thread.start(); }
public void initialize() { SwingWorker thread = new SwingWorker() { public Object construct() { try { populateTransports(SparkManager.getConnection()); for (final Transport transport : TransportUtils.getTransports()) { addTransport(transport); } } catch (Exception e) { Log.error(e); return false; } return true; } public void finished() { Boolean transportExists = (Boolean)get(); if (!transportExists) { return; } // Register presences. registerPresences(); } }; thread.start(); }
3,238,664
public void initialize() { SwingWorker thread = new SwingWorker() { public Object construct() { try { populateTransports(SparkManager.getConnection()); for (final Transport transport : TransportManager.getTransports()) { addTransport(transport); } } catch (Exception e) { Log.error(e); return false; } return true; } public void finished() { Boolean transportExists = (Boolean)get(); if (!transportExists) { return; } // Register presences. registerPresences(); } }; thread.start(); }
public void initialize() { SwingWorker thread = new SwingWorker() { public Object construct() { try { populateTransports(SparkManager.getConnection()); for (final Transport transport : TransportManager.getTransports()) { addTransport(transport); } } catch (Exception e) { Log.error(e); return false; } return true; } public void finished() { Boolean transportExists = (Boolean)get(); if (!transportExists) { return; } // Register presences. registerPresenceListener(); } }; thread.start(); }
3,238,665
public Object construct() { try { populateTransports(SparkManager.getConnection()); for (final Transport transport : TransportManager.getTransports()) { addTransport(transport); } } catch (Exception e) { Log.error(e); return false; } return true; }
public Object construct() { try { populateTransports(SparkManager.getConnection()); for (final Transport transport : TransportUtils.getTransports()) { addTransport(transport); } } catch (Exception e) { Log.error(e); return false; } return true; }
3,238,666
public void finished() { Boolean transportExists = (Boolean)get(); if (!transportExists) { return; } // Register presences. registerPresences(); }
public void finished() { Boolean transportExists = (Boolean)get(); if (!transportExists) { return; } // Register presences. registerPresenceListener(); }
3,238,667
private void populateTransports(XMPPConnection con) throws Exception { ServiceDiscoveryManager discoveryManager = ServiceDiscoveryManager.getInstanceFor(con); DiscoverItems discoItems = SparkManager.getSessionManager().getDiscoveredItems(); DiscoverItems.Item item; DiscoverInfo info; DiscoverInfo.Identity identity; Iterator items = discoItems.getItems(); while (items.hasNext()) { item = (Item)items.next(); try { info = discoveryManager.discoverInfo(item.getEntityID()); } catch (XMPPException e) { Log.error(e); continue; } Iterator identities = info.getIdentities(); while (identities.hasNext()) { identity = (Identity)identities.next(); if (identity.getCategory().equalsIgnoreCase(GATEWAY)) { if ("aim".equals(identity.getType())) { AIMTransport aim = new AIMTransport(item.getEntityID()); TransportManager.addTransport(item.getEntityID(), aim); } else if ("msn".equals(identity.getType())) { MSNTransport msn = new MSNTransport(item.getEntityID()); TransportManager.addTransport(item.getEntityID(), msn); } else if ("yahoo".equals(identity.getType())) { YahooTransport yahoo = new YahooTransport(item.getEntityID()); TransportManager.addTransport(item.getEntityID(), yahoo); } else if ("icq".equals(identity.getType())) { ICQTransport icq = new ICQTransport(item.getEntityID()); TransportManager.addTransport(item.getEntityID(), icq); } } } } }
private void populateTransports(XMPPConnection con) throws Exception { ServiceDiscoveryManager discoveryManager = ServiceDiscoveryManager.getInstanceFor(con); DiscoverItems discoItems = SparkManager.getSessionManager().getDiscoveredItems(); DiscoverItems.Item item; DiscoverInfo info; DiscoverInfo.Identity identity; Iterator items = discoItems.getItems(); while (items.hasNext()) { item = (Item)items.next(); try { info = discoveryManager.discoverInfo(item.getEntityID()); } catch (XMPPException e) { Log.error(e); continue; } Iterator identities = info.getIdentities(); while (identities.hasNext()) { identity = (Identity)identities.next(); if (identity.getCategory().equalsIgnoreCase(GATEWAY)) { if ("aim".equals(identity.getType())) { AIMTransport aim = new AIMTransport(item.getEntityID()); TransportUtils.addTransport(item.getEntityID(), aim); } else if ("msn".equals(identity.getType())) { MSNTransport msn = new MSNTransport(item.getEntityID()); TransportManager.addTransport(item.getEntityID(), msn); } else if ("yahoo".equals(identity.getType())) { YahooTransport yahoo = new YahooTransport(item.getEntityID()); TransportManager.addTransport(item.getEntityID(), yahoo); } else if ("icq".equals(identity.getType())) { ICQTransport icq = new ICQTransport(item.getEntityID()); TransportManager.addTransport(item.getEntityID(), icq); } } } } }
3,238,668
private void populateTransports(XMPPConnection con) throws Exception { ServiceDiscoveryManager discoveryManager = ServiceDiscoveryManager.getInstanceFor(con); DiscoverItems discoItems = SparkManager.getSessionManager().getDiscoveredItems(); DiscoverItems.Item item; DiscoverInfo info; DiscoverInfo.Identity identity; Iterator items = discoItems.getItems(); while (items.hasNext()) { item = (Item)items.next(); try { info = discoveryManager.discoverInfo(item.getEntityID()); } catch (XMPPException e) { Log.error(e); continue; } Iterator identities = info.getIdentities(); while (identities.hasNext()) { identity = (Identity)identities.next(); if (identity.getCategory().equalsIgnoreCase(GATEWAY)) { if ("aim".equals(identity.getType())) { AIMTransport aim = new AIMTransport(item.getEntityID()); TransportManager.addTransport(item.getEntityID(), aim); } else if ("msn".equals(identity.getType())) { MSNTransport msn = new MSNTransport(item.getEntityID()); TransportManager.addTransport(item.getEntityID(), msn); } else if ("yahoo".equals(identity.getType())) { YahooTransport yahoo = new YahooTransport(item.getEntityID()); TransportManager.addTransport(item.getEntityID(), yahoo); } else if ("icq".equals(identity.getType())) { ICQTransport icq = new ICQTransport(item.getEntityID()); TransportManager.addTransport(item.getEntityID(), icq); } } } } }
private void populateTransports(XMPPConnection con) throws Exception { ServiceDiscoveryManager discoveryManager = ServiceDiscoveryManager.getInstanceFor(con); DiscoverItems discoItems = SparkManager.getSessionManager().getDiscoveredItems(); DiscoverItems.Item item; DiscoverInfo info; DiscoverInfo.Identity identity; Iterator items = discoItems.getItems(); while (items.hasNext()) { item = (Item)items.next(); try { info = discoveryManager.discoverInfo(item.getEntityID()); } catch (XMPPException e) { Log.error(e); continue; } Iterator identities = info.getIdentities(); while (identities.hasNext()) { identity = (Identity)identities.next(); if (identity.getCategory().equalsIgnoreCase(GATEWAY)) { if ("aim".equals(identity.getType())) { AIMTransport aim = new AIMTransport(item.getEntityID()); TransportManager.addTransport(item.getEntityID(), aim); } else if ("msn".equals(identity.getType())) { MSNTransport msn = new MSNTransport(item.getEntityID()); TransportUtils.addTransport(item.getEntityID(), msn); } else if ("yahoo".equals(identity.getType())) { YahooTransport yahoo = new YahooTransport(item.getEntityID()); TransportManager.addTransport(item.getEntityID(), yahoo); } else if ("icq".equals(identity.getType())) { ICQTransport icq = new ICQTransport(item.getEntityID()); TransportManager.addTransport(item.getEntityID(), icq); } } } } }
3,238,669
private void populateTransports(XMPPConnection con) throws Exception { ServiceDiscoveryManager discoveryManager = ServiceDiscoveryManager.getInstanceFor(con); DiscoverItems discoItems = SparkManager.getSessionManager().getDiscoveredItems(); DiscoverItems.Item item; DiscoverInfo info; DiscoverInfo.Identity identity; Iterator items = discoItems.getItems(); while (items.hasNext()) { item = (Item)items.next(); try { info = discoveryManager.discoverInfo(item.getEntityID()); } catch (XMPPException e) { Log.error(e); continue; } Iterator identities = info.getIdentities(); while (identities.hasNext()) { identity = (Identity)identities.next(); if (identity.getCategory().equalsIgnoreCase(GATEWAY)) { if ("aim".equals(identity.getType())) { AIMTransport aim = new AIMTransport(item.getEntityID()); TransportManager.addTransport(item.getEntityID(), aim); } else if ("msn".equals(identity.getType())) { MSNTransport msn = new MSNTransport(item.getEntityID()); TransportManager.addTransport(item.getEntityID(), msn); } else if ("yahoo".equals(identity.getType())) { YahooTransport yahoo = new YahooTransport(item.getEntityID()); TransportManager.addTransport(item.getEntityID(), yahoo); } else if ("icq".equals(identity.getType())) { ICQTransport icq = new ICQTransport(item.getEntityID()); TransportManager.addTransport(item.getEntityID(), icq); } } } } }
private void populateTransports(XMPPConnection con) throws Exception { ServiceDiscoveryManager discoveryManager = ServiceDiscoveryManager.getInstanceFor(con); DiscoverItems discoItems = SparkManager.getSessionManager().getDiscoveredItems(); DiscoverItems.Item item; DiscoverInfo info; DiscoverInfo.Identity identity; Iterator items = discoItems.getItems(); while (items.hasNext()) { item = (Item)items.next(); try { info = discoveryManager.discoverInfo(item.getEntityID()); } catch (XMPPException e) { Log.error(e); continue; } Iterator identities = info.getIdentities(); while (identities.hasNext()) { identity = (Identity)identities.next(); if (identity.getCategory().equalsIgnoreCase(GATEWAY)) { if ("aim".equals(identity.getType())) { AIMTransport aim = new AIMTransport(item.getEntityID()); TransportManager.addTransport(item.getEntityID(), aim); } else if ("msn".equals(identity.getType())) { MSNTransport msn = new MSNTransport(item.getEntityID()); TransportManager.addTransport(item.getEntityID(), msn); } else if ("yahoo".equals(identity.getType())) { YahooTransport yahoo = new YahooTransport(item.getEntityID()); TransportUtils.addTransport(item.getEntityID(), yahoo); } else if ("icq".equals(identity.getType())) { ICQTransport icq = new ICQTransport(item.getEntityID()); TransportManager.addTransport(item.getEntityID(), icq); } } } } }
3,238,670
private void populateTransports(XMPPConnection con) throws Exception { ServiceDiscoveryManager discoveryManager = ServiceDiscoveryManager.getInstanceFor(con); DiscoverItems discoItems = SparkManager.getSessionManager().getDiscoveredItems(); DiscoverItems.Item item; DiscoverInfo info; DiscoverInfo.Identity identity; Iterator items = discoItems.getItems(); while (items.hasNext()) { item = (Item)items.next(); try { info = discoveryManager.discoverInfo(item.getEntityID()); } catch (XMPPException e) { Log.error(e); continue; } Iterator identities = info.getIdentities(); while (identities.hasNext()) { identity = (Identity)identities.next(); if (identity.getCategory().equalsIgnoreCase(GATEWAY)) { if ("aim".equals(identity.getType())) { AIMTransport aim = new AIMTransport(item.getEntityID()); TransportManager.addTransport(item.getEntityID(), aim); } else if ("msn".equals(identity.getType())) { MSNTransport msn = new MSNTransport(item.getEntityID()); TransportManager.addTransport(item.getEntityID(), msn); } else if ("yahoo".equals(identity.getType())) { YahooTransport yahoo = new YahooTransport(item.getEntityID()); TransportManager.addTransport(item.getEntityID(), yahoo); } else if ("icq".equals(identity.getType())) { ICQTransport icq = new ICQTransport(item.getEntityID()); TransportManager.addTransport(item.getEntityID(), icq); } } } } }
private void populateTransports(XMPPConnection con) throws Exception { ServiceDiscoveryManager discoveryManager = ServiceDiscoveryManager.getInstanceFor(con); DiscoverItems discoItems = SparkManager.getSessionManager().getDiscoveredItems(); DiscoverItems.Item item; DiscoverInfo info; DiscoverInfo.Identity identity; Iterator items = discoItems.getItems(); while (items.hasNext()) { item = (Item)items.next(); try { info = discoveryManager.discoverInfo(item.getEntityID()); } catch (XMPPException e) { Log.error(e); continue; } Iterator identities = info.getIdentities(); while (identities.hasNext()) { identity = (Identity)identities.next(); if (identity.getCategory().equalsIgnoreCase(GATEWAY)) { if ("aim".equals(identity.getType())) { AIMTransport aim = new AIMTransport(item.getEntityID()); TransportManager.addTransport(item.getEntityID(), aim); } else if ("msn".equals(identity.getType())) { MSNTransport msn = new MSNTransport(item.getEntityID()); TransportManager.addTransport(item.getEntityID(), msn); } else if ("yahoo".equals(identity.getType())) { YahooTransport yahoo = new YahooTransport(item.getEntityID()); TransportManager.addTransport(item.getEntityID(), yahoo); } else if ("icq".equals(identity.getType())) { ICQTransport icq = new ICQTransport(item.getEntityID()); TransportUtils.addTransport(item.getEntityID(), icq); } } } } }
3,238,671
public void processPacket(Packet packet) { Presence presence = (Presence)packet; Transport transport = TransportManager.getTransport(packet.getFrom()); if (transport != null) { boolean registered = presence != null && presence.getMode() != null; if (presence.getType() == Presence.Type.unavailable) { registered = false; } RolloverButton button = uiMap.get(transport); if (!registered) { button.setIcon(transport.getInactiveIcon()); } else { button.setIcon(transport.getIcon()); } } }
public void processPacket(Packet packet) { Presence presence = (Presence)packet; Transport transport = TransportUtils.getTransport(packet.getFrom()); if (transport != null) { boolean registered = presence != null && presence.getMode() != null; if (presence.getType() == Presence.Type.unavailable) { registered = false; } RolloverButton button = uiMap.get(transport); if (!registered) { button.setIcon(transport.getInactiveIcon()); } else { button.setIcon(transport.getIcon()); } } }
3,238,672
public void fromColor(Color c) { float min, max, delta; min = findMin(c.getRed(), c.getGreen(), c.getBlue()); max = findMax(c.getRed(), c.getGreen(), c.getBlue()); v = max; delta = max-min; if (max != 0.0f) s = delta/max; else { v = 0.0f; s = 0.0f; h = 0.0f; } if (c.getRed()==max) h = (c.getGreen()-c.getBlue())/delta; else if (c.getGreen() == max) h = 2.0f + (c.getBlue()-c.getRed())/delta; else h = 4.0f+(c.getRed()-c.getGreen())/delta; h = h * 60.0f; if (h < 0) h += 360.0f; h = h/360.0f; v = v/255.0f; s = s/255.0f; a = c.getAlpha()/255.0f; }
public void fromColor(Color c) { float min, max, delta; min = findMin(c.getRed(), c.getGreen(), c.getBlue()); max = findMax(c.getRed(), c.getGreen(), c.getBlue()); v = max; delta = max-min; if (max != 0.0f) s = delta/max; else { v = 0.0f; s = 0.0f; h = 0.0f; } if (c.getRed()==max) h = (c.getGreen()-c.getBlue())/delta; else if (c.getGreen() == max) h = 2.0f + (c.getBlue()-c.getRed())/delta; else h = 4.0f+(c.getRed()-c.getGreen())/delta; h = h * 60.0f; if (h < 0) h += 360.0f; h = h/360.0f; v = v/255.0f; a = c.getAlpha()/255.0f; }
3,238,674
private void buildGUI(JComponent filterComponent) { JPanel contentPanel = new JPanel(); contentPanel.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createEtchedBorder(), BorderFactory.createEmptyBorder(5, 5, 15, 10))); contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS)); IconManager im = IconManager.getInstance(); TitlePanel tp = new TitlePanel(TITLE, NOTE, createMessage(), im.getIcon(IconManager.FILTER_BIG)); //Set the layout and add components Container c = getContentPane(); c.setLayout(new BorderLayout(0, 0)); c.add(tp, BorderLayout.NORTH); c.add(filterComponent, BorderLayout.CENTER); JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); p.setBorder(BorderFactory.createEtchedBorder()); p.add(UIUtilities.buildComponentPanel(buildLeftToolBar())); p.add(UIUtilities.buildComponentPanelRight(buildRightToolBar())); p.setOpaque(true); c.add(p, BorderLayout.SOUTH); }
private void buildGUI(JComponent filterComponent) { JPanel contentPanel = new JPanel(); contentPanel.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createEtchedBorder(), BorderFactory.createEmptyBorder(5, 5, 15, 10))); contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS)); IconManager im = IconManager.getInstance(); TitlePanel tp = new TitlePanel(TITLE, NOTE, getContainerString(), im.getIcon(IconManager.FILTER_BIG)); //Set the layout and add components Container c = getContentPane(); c.setLayout(new BorderLayout(0, 0)); c.add(tp, BorderLayout.NORTH); c.add(filterComponent, BorderLayout.CENTER); JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); p.setBorder(BorderFactory.createEtchedBorder()); p.add(UIUtilities.buildComponentPanel(buildLeftToolBar())); p.add(UIUtilities.buildComponentPanelRight(buildRightToolBar())); p.setOpaque(true); c.add(p, BorderLayout.SOUTH); }
3,238,675
private JToolBar buildLeftToolBar() { JToolBar bar = new JToolBar(); bar.setRollover(true); bar.setBorder(null); bar.setFloatable(false); bar.add(selectAll); bar.add(Box.createRigidArea(H_SPACER_SIZE)); bar.add(clearAll); return bar; }
private JPanel buildLeftToolBar() { JToolBar bar = new JToolBar(); bar.setRollover(true); bar.setBorder(null); bar.setFloatable(false); bar.add(selectAll); bar.add(Box.createRigidArea(H_SPACER_SIZE)); bar.add(clearAll); return bar; }
3,238,676
private JToolBar buildLeftToolBar() { JToolBar bar = new JToolBar(); bar.setRollover(true); bar.setBorder(null); bar.setFloatable(false); bar.add(selectAll); bar.add(Box.createRigidArea(H_SPACER_SIZE)); bar.add(clearAll); return bar; }
private JToolBar buildLeftToolBar() { JToolBar bar = new JToolBar(); bar.setRollover(true); bar.setBorder(null); bar.setFloatable(false); bar.add(selectAll); bar.add(Box.createRigidArea(H_SPACER_SIZE)); bar.add(clearAll); return bar; }
3,238,677
private JToolBar buildLeftToolBar() { JToolBar bar = new JToolBar(); bar.setRollover(true); bar.setBorder(null); bar.setFloatable(false); bar.add(selectAll); bar.add(Box.createRigidArea(H_SPACER_SIZE)); bar.add(clearAll); return bar; }
private JToolBar buildLeftToolBar() { JToolBar bar = new JToolBar(); bar.setRollover(true); bar.setBorder(null); bar.add(selectAll); bar.add(Box.createRigidArea(H_SPACER_SIZE)); bar.add(clearAll); return bar; }
3,238,678
private JToolBar buildRightToolBar() { JToolBar bar = new JToolBar(); bar.setRollover(true); bar.setBorder(null); bar.setFloatable(false); bar.add(setButton); bar.add(Box.createRigidArea(H_SPACER_SIZE)); bar.add(cancelButton); return bar; }
private JPanel buildRightToolBar() { JToolBar bar = new JToolBar(); bar.setRollover(true); bar.setBorder(null); bar.setFloatable(false); bar.add(setButton); bar.add(Box.createRigidArea(H_SPACER_SIZE)); bar.add(cancelButton); return bar; }
3,238,679
private JToolBar buildRightToolBar() { JToolBar bar = new JToolBar(); bar.setRollover(true); bar.setBorder(null); bar.setFloatable(false); bar.add(setButton); bar.add(Box.createRigidArea(H_SPACER_SIZE)); bar.add(cancelButton); return bar; }
private JToolBar buildRightToolBar() { JToolBar bar = new JToolBar(); bar.setRollover(true); bar.setBorder(null); bar.setFloatable(false); bar.add(setButton); bar.add(Box.createRigidArea(H_SPACER_SIZE)); bar.add(cancelButton); return bar; }
3,238,680
private JToolBar buildRightToolBar() { JToolBar bar = new JToolBar(); bar.setRollover(true); bar.setBorder(null); bar.setFloatable(false); bar.add(setButton); bar.add(Box.createRigidArea(H_SPACER_SIZE)); bar.add(cancelButton); return bar; }
private JToolBar buildRightToolBar() { JToolBar bar = new JToolBar(); bar.setRollover(true); bar.setBorder(null); bar.add(setButton); bar.add(Box.createRigidArea(H_SPACER_SIZE)); bar.add(cancelButton); return bar; }
3,238,681
private String getContainerString() { switch (containerType) { case DATASET: return DATASET_MSG; case CATEGORY: return CATEGORY_MSG; } return ""; }
private String getContainerString() { switch (containerType) { case DATASET: return DATASET_MSG; case CATEGORY: return CATEGORY_MSG; } return ""; }
3,238,682
public void initialize() { ProviderManager.addExtensionProvider("phone-event", "http://jivesoftware.com/xmlns/phone", new PhoneEventPacketExtensionProvider()); ProviderManager.addIQProvider("phone-action", "http://jivesoftware.com/xmlns/phone", new PhoneActionIQProvider()); final XMPPConnection con = SparkManager.getConnection(); SwingWorker worker = new SwingWorker() { public Object construct() { try { phoneClient = new PhoneClient(con); // Add BaseListener phoneClient.addEventListener(new PhoneListener()); } catch (Exception e) { // Ignore because the user does not have support. Log.error(e); } return phoneClient; } public void finished() { if (phoneClient != null) { setupPhoneSystem(); } } }; worker.start(); }
public void initialize() { ProviderManager.addExtensionProvider("phone-event", "http://jivesoftware.com/xmlns/phone", new PhoneEventPacketExtensionProvider()); ProviderManager.addIQProvider("phone-action", "http://jivesoftware.com/xmlns/phone", new PhoneActionIQProvider()); final XMPPConnection con = SparkManager.getConnection(); SwingWorker worker = new SwingWorker() { public Object construct() { try { phoneClient = new PhoneClient(con); // Add BaseListener phoneClient.addEventListener(new PhoneListener()); } catch (Exception e) { // Ignore because the user does not have support. } return phoneClient; } public void finished() { if (phoneClient != null) { setupPhoneSystem(); } } }; worker.start(); }
3,238,683
public Object construct() { try { phoneClient = new PhoneClient(con); // Add BaseListener phoneClient.addEventListener(new PhoneListener()); } catch (Exception e) { // Ignore because the user does not have support. Log.error(e); } return phoneClient; }
public Object construct() { try { phoneClient = new PhoneClient(con); // Add BaseListener phoneClient.addEventListener(new PhoneListener()); } catch (Exception e) { // Ignore because the user does not have support. } return phoneClient; }
3,238,684
public Arity getArity() { if (getNode() instanceof AttrSetNode) { return Arity.singleArgument(); } else if (getNode() instanceof InstVarNode) { return Arity.noArguments(); } else { // FIXME: Not sure this case can happen. // Should do polymorphic call to node instead anyway. return Arity.optional(); } }
public Arity getArity() {if (getNode() instanceof AttrSetNode) {return Arity.singleArgument();} else if (getNode() instanceof InstVarNode) {return Arity.noArguments();} else {// FIXME: Not sure this case can happen.// Should do polymorphic call to node instead anyway.return Arity.optional();}}
3,238,686
public String getChildElementXML() { StringBuffer buf = new StringBuffer(); buf.append("<query xmlns=\"" + NAMESPACE + "\">"); buf.append("<prompt>[email protected]</prompt>"); buf.append("</query>"); return buf.toString(); }
public String getChildElementXML() { StringBuffer buf = new StringBuffer(); buf.append("<query xmlns=\"" + NAMESPACE + "\">"); buf.append("<prompt>" + username + "</prompt>"); buf.append("</query>"); return buf.toString(); }
3,238,688
public void removeMappingFor(Widget source) { srcToEvtToMethod.remove(source); }
public void removeMappingFor(Widget source) { srcToEvtToMethod.remove(source); }
3,238,690
public RubyHash each() { for (Iterator iter = entryIterator(); iter.hasNext();) { checkRehashing(); Map.Entry entry = (Map.Entry) iter.next(); getRuntime().getCurrentContext().yieldCurrentBlock(getRuntime().newArray((IRubyObject)entry.getKey(), (IRubyObject)entry.getValue()), null, null, true); } return this; }
public RubyHash each() { for (Iterator iter = entryIterator(); iter.hasNext();) { checkRehashing(); Map.Entry entry = (Map.Entry) iter.next(); getRuntime().getCurrentContext().yield(getRuntime().newArray((IRubyObject)entry.getKey(), (IRubyObject)entry.getValue())); } return this; }
3,238,691
public static void main(String args[]) { //@START int N = Integer.parseInt(args[0]); System.out.println(fib(N)); //@END }
public static void main(String args[]) { //@START int N = Integer.parseInt(args[0]); System.out.println(fib(N)); //@END }
3,238,692
private void buildToolBar() { setFloatable(false); setLayout(new FlowLayout(FlowLayout.LEFT, 0, 5)); putClientProperty("JToolBar.isRollover", new Boolean(true)); add(greyButton); add(rgbButton); add(hsbButton); add(separator); add(resetButton); //add(saveButton); }
privateadd(saveButton); voidadd(saveButton); buildToolBar() { setFloatable(false); setLayout(newadd(saveButton); FlowLayout(FlowLayout.LEFT,add(saveButton); 0,add(saveButton); 5)); putClientProperty("JToolBar.isRollover",add(saveButton); newadd(saveButton); Boolean(true)); add(greyButton); add(rgbButton); add(hsbButton); add(separator); add(resetButton); //add(saveButton); }
3,238,693
public RubyObject getConstant(RubyId id) { boolean mod_retry = false; RubyModule tmp = this; while (true) { while (tmp != null) { if (tmp.getInstanceVariables().get(id) != null) { return (RubyObject) tmp.getInstanceVariables().get(id); } if (tmp == getRuby().getClasses().getObjectClass() && getRuby().getTopConstant(id) != null) { return getRuby().getTopConstant(id); } tmp = tmp.getSuperClass(); } if (!mod_retry && isModule()) { mod_retry = true; tmp = getRuby().getClasses().getObjectClass(); continue; } break; } /* Uninitialized constant */ if (this != getRuby().getClasses().getObjectClass()) { throw new RubyNameException(getRuby(), "uninitialized constant " + id.toName() + " at " + getClassPath().getValue()); } else { throw new RubyNameException(getRuby(), "uninitialized constant " + id.toName()); } // return getRuby().getNil(); }
public RubyObject getConstant(RubyId id) { boolean mod_retry = false; RubyModule tmp = this; while (true) { while (tmp != null) { if (tmp.getInstanceVariables().get(id) != null) { return (RubyObject) tmp.getInstanceVariables().get(id); } if (tmp == getRuby().getClasses().getObjectClass() && getRuby().getTopConstant(id) != null) { return getRuby().getTopConstant(id); } tmp = tmp.getSuperClass(); } if (!mod_retry && isModule()) { mod_retry = true; tmp = getRuby().getClasses().getObjectClass(); continue; } break; } /* Uninitialized constant */ if (this != getRuby().getClasses().getObjectClass()) { throw new RubyNameException(getRuby(), "uninitialized constant " + id.toName() + " at " + getClassPath().getValue()); } else { throw new RubyNameException(getRuby(), "uninitialized constant " + id.toName() + " at " + getClassPath().getValue()); } // return getRuby().getNil(); }
3,238,694
public IParser borrowParser() { synchronized (pool) { Iterator iter = pool.iterator(); while (iter.hasNext()) { IParser parser = (IParser) ((Reference) iter.next()).get(); if (parser != null) { return parser; } else { iter.remove(); } } } return new DefaultRubyParser(); }
public IParser borrowParser() { synchronized (pool) { Iterator iter = pool.iterator(); while (iter.hasNext()) { IParser parser = (IParser) ((Reference) iter.next()).get(); if (parser != null) { return parser; } else { iter.remove(); } } } return new DefaultRubyParser(); }
3,238,695
void setSelectedPane(int index) { tabPane.setSelectedIndex(index); }
void setSelectedPane(int index) { tabPane.setSelectedIndex(index); }
3,238,696
protected void checkManagedState( IObject obj ) { if ( obj.getId() == null) throw new ValidationException( "Id required on all detached instances."); // Throws an exception if does not exist IObject original = (IObject) ht.load( Utils.trueClass( obj.getClass() ), obj.getId() ); if ( obj == original) return; // Early exit. Obj is in session. Details oldDetails = original.getDetails(); // must exist! Details updatedDetails = obj.getDetails(); /* FIXME temporary this shouldn't be null */ if ( oldDetails == null ) { //obj.setDetails( null ); log.warn( " Original details null for: " + original ); } // TODO perhaps this should throw an exception. But we have // defaults to handle this kind of thing, so currently, not throwing. else if ( updatedDetails == null ) { obj.setDetails( oldDetails ); log.warn( " Updated details null for: " + original ); // Now we have to make sure certain things do not happen: } else { if ( ! idEqual( oldDetails.getOwner(), updatedDetails.getOwner() )) { updatedDetails.setOwner( oldDetails.getOwner() ); log.warn( " Resetting owner for: " + original ); } if ( ! idEqual( oldDetails.getGroup(), updatedDetails.getGroup() )) { updatedDetails.setGroup( oldDetails.getGroup() ); log.warn( " Resetting group for: " + original ); } if ( ! idEqual( oldDetails.getCreationEvent(), updatedDetails.getCreationEvent())) { updatedDetails.setCreationEvent( oldDetails.getCreationEvent() ); log.warn( " Resetting creation for: " + original ); } } if ( obj instanceof IMutable ) { Integer version = ((IMutable) obj).getVersion(); if ( version == null || version.intValue() < 0 ) throw new ValidationException( "Version must properly be set on managed objects :\n"+ obj.toString() ); } }
protected void checkManagedState( IObject obj ) { if ( obj.getId() == null) throw new ValidationException( "Id required on all detached instances."); // Throws an exception if does not exist IObject original = (IObject) ht.load( Utils.trueClass( obj.getClass() ), obj.getId() ); if ( obj == original) return; // Early exit. Obj is in session. Details oldDetails = original.getDetails(); // must exist! Details updatedDetails = obj.getDetails(); /* FIXME temporary this shouldn't be null */ if ( oldDetails == null ) { //obj.setDetails( null ); log.warn( " Original details null for: " + original ); } // TODO perhaps this should throw an exception. But we have // defaults to handle this kind of thing, so currently, not throwing. else if ( updatedDetails == null ) { obj.setDetails( oldDetails ); log.warn( " Updated details null for: " + original ); // Now we have to make sure certain things do not happen: } else { if ( ! idEqual( oldDetails.getOwner(), updatedDetails.getOwner() )) { updatedDetails.setOwner( oldDetails.getOwner() ); log.warn( " Resetting owner for: " + original ); } if ( ! idEqual( oldDetails.getGroup(), updatedDetails.getGroup() )) { updatedDetails.setGroup( oldDetails.getGroup() ); log.warn( " Resetting group for: " + original ); } if ( ! idEqual( oldDetails.getCreationEvent(), updatedDetails.getCreationEvent())) { updatedDetails.setCreationEvent( oldDetails.getCreationEvent() ); log.warn( " Resetting creation for: " + original ); } } if ( obj instanceof IMutable ) { Integer version = ((IMutable) obj).getVersion(); if ( version == null || version.intValue() < 0 ) throw new ValidationException( "Version must properly be set on managed objects :\n"+ obj.toString() ); } }
3,238,697
public RubyObject eval(RubyObject self, NODE n) { NODE node = n; RubyBoolean cond = null; RubyObject[] args = null; RubyObject value = null; RubyObject result = null; RubyModule rubyClass = null; // int state; // RubyOriginalMethods rom = getRuby().getOriginalMethods(); while (true) { if (node == null) { return getRuby().getNil(); } switch (node.nd_type()) { case NODE_BLOCK: while (node.nd_next() != null) { eval(self, node.nd_head()); node = node.nd_next(); } node = node.nd_head(); break; case NODE_POSTEXE: // rb_f_END(); node.nd_set_type(NODE_NIL); /* exec just once */ return getRuby().getNil(); /* begin .. end without clauses */ case NODE_BEGIN: node = node.nd_body(); break; /* nodes for speed-up(default match) */ case NODE_MATCH: //return rom.rb_reg_match2(node.nd_head().nd_lit()); return getRuby().getNil(); /* nodes for speed-up(literal match) */ case NODE_MATCH2: //return rom.rb_reg_match(eval(node.nd_recv()), eval(node.nd_value())); return getRuby().getNil(); /* nodes for speed-up(literal match) */ case NODE_MATCH3: //VALUE r = eval(node.nd_recv()); //VALUE l = eval(node.nd_value()); //if (r instanceof RubyString) { // return rom.rb_reg_match(l, r); //} else { // return rom.rb_funcall(r, match, 1, l); //} return getRuby().getNil(); /* node for speed-up(top-level loop for -n/-p) */ case NODE_OPT_N: while (true) { try { // while (!rb_gets().isNil() false) { // HACK +++ if (true) { // HACK --- try { eval(self, node.nd_body()); } catch (RedoException rExcptn) { } } break; } catch (NextException nExcptn) { } catch (BreakException bExcptn) { break; } } return getRuby().getNil(); case NODE_SELF: return self; case NODE_NIL: return getRuby().getNil(); case NODE_TRUE: return getRuby().getTrue(); case NODE_FALSE: return getRuby().getFalse(); case NODE_IF: // ruby_sourceline = node.nd_line(); cond = (RubyBoolean)eval(self, node.nd_cond()); if (cond.isTrue()) { node = node.nd_body(); } else { node = node.nd_else(); } break; case NODE_WHEN: while (node != null) { NODE tag; if (node.nd_type() != NODE_WHEN) { break; } tag = node.nd_head(); while (tag != null) {/* if (trace_func) { call_trace_func("line", tag->nd_file, nd_line(tag), self, ruby_frame->last_func, ruby_frame->last_class); }*/ // ruby_sourcefile = tag.nd_file; // ruby_sourceline = tag.nd_line(); if (tag.nd_head().nd_type() == NODE_WHEN) { RubyObject obj = eval(self, tag.nd_head().nd_head()); if (!(obj instanceof RubyArray)) { obj = RubyArray.m_newArray(getRuby(), obj); } for (int i = 0; i < ((RubyArray)obj).length(); i++) { if (((RubyBoolean)((RubyArray)obj).entry(i)).isTrue()) { node = node.nd_body(); break; } } tag = tag.nd_next(); continue; } if (((RubyBoolean)eval(self, tag.nd_head())).isTrue()) { node = node.nd_body(); break; } tag = tag.nd_next(); } node = node.nd_next(); } return getRuby().getNil(); case NODE_CASE: RubyObject obj = eval(self, node.nd_head()); node = node.nd_body(); while (node != null) { NODE tag; if (node.nd_type() != NODE_WHEN) { break; } tag = node.nd_head(); while (tag != null) {/* if (trace_func) { call_trace_func("line", tag->nd_file, nd_line(tag), self, ruby_frame->last_func, ruby_frame->last_class); } ruby_sourcefile = tag->nd_file; ruby_sourceline = nd_line(tag);*/ if (tag.nd_head().nd_type() == NODE_WHEN) { RubyObject obj2 = eval(self, tag.nd_head().nd_head()); if (!(obj2 instanceof RubyArray)) { obj2 = RubyArray.m_newArray(getRuby(), obj2); } for (int i = 0; i < ((RubyArray)obj).length(); i++) { RubyBoolean eqq = (RubyBoolean)((RubyArray)obj2).entry(i).funcall(getRuby().intern("==="), obj); if (eqq.isTrue()) { node = node.nd_body(); break; } } tag = tag.nd_next(); continue; } if (((RubyBoolean)eval(self, tag.nd_head()).funcall(getRuby().intern("==="), obj)).isTrue()) { node = node.nd_body(); break; } tag = tag.nd_next(); } node = node.nd_next(); } return getRuby().getNil(); case NODE_WHILE: while (eval(self, node.nd_cond()).isTrue()) { while (true) { try { eval(self, node.nd_body()); break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { break; } catch (BreakException bExcptn) { return getRuby().getNil(); } } } return getRuby().getNil(); case NODE_UNTIL: while (eval(self, node.nd_cond()).isFalse()) { while (true) { try { eval(self, node.nd_body()); break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { break; } catch (BreakException bExcptn) { return getRuby().getNil(); } } } return getRuby().getNil(); case NODE_BLOCK_PASS: //return block_pass(node); return null; case NODE_ITER: case NODE_FOR: rubyBlock.push(node.nd_var(), node.nd_body(), self); rubyIter.push(Iter.ITER_PRE); while (true) { try { if (node.nd_type() == NODE_ITER) { result = eval(self, node.nd_iter()); } else { // String file = // int line = rubyBlock.flags &= ~RubyBlock.BLOCK_D_SCOPE; RubyBlock tmpBlock = beginCallargs(); RubyObject recv = eval(self, node.nd_iter()); endCallArgs(tmpBlock); // = file; // = line; result = recv.getRubyClass().call(recv, ruby.intern("each"), null, 0); } break; } catch (RetryException rExcptn) { } catch (ReturnException rExcptn) { result = rExcptn.getReturnValue(); break; } catch (BreakException bExcptn) { result = ruby.getNil(); break; } } rubyIter.pop(); rubyBlock.pop(); return result; case NODE_BREAK: throw new BreakException(); case NODE_NEXT: throw new NextException(); case NODE_REDO: throw new RedoException(); case NODE_RETRY: throw new RetryException(); case NODE_RESTARGS: result = eval(self, node.nd_head()); if (!(result instanceof RubyArray)) { result = obj = RubyArray.m_newArray(getRuby(), result); } return result; case NODE_YIELD: if (node.nd_stts() != null) { result = eval(self, node.nd_stts()); if (node.nd_stts().nd_type() == NODE_RESTARGS && ((RubyArray)result).length() == 1) { result = ((RubyArray)result).entry(0); } } else { result = ruby.getNil(); } return yield0(result, null, null, false); case NODE_RESCUE:/* retry_entry: { volatile VALUE e_info = ruby_errinfo; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, node->nd_head); } POP_TAG(); if (state == TAG_RAISE) { NODE * volatile resq = node->nd_resq; ruby_sourceline = nd_line(node); while (resq) { if (handle_rescue(self, resq)) { state = 0; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, resq->nd_body); } POP_TAG(); if (state == TAG_RETRY) { state = 0; ruby_errinfo = Qnil; goto retry_entry; } if (state != TAG_RAISE) { ruby_errinfo = e_info; } break; } resq = resq->nd_head; /* next rescue */ /** } * } * else if (node->nd_else) { /* else clause given *//* if (!state) { /* no exception raised *//* result = rb_eval(self, node->nd_else); } } if (state) JUMP_TAG(state); } break;*/ case NODE_ENSURE:/* PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = eval(node.nd_head()); } POP_TAG(); if (node.nd_ensr()) { VALUE retval = prot_tag->retval; /* save retval *//* VALUE errinfo = ruby_errinfo; rb_eval(self, node->nd_ensr); return_value(retval); ruby_errinfo = errinfo; } if (state) JUMP_TAG(state); break;*/ case NODE_AND: cond = (RubyBoolean)eval(self, node.nd_1st()); if (cond.isFalse()) { return cond; } node = node.nd_2nd(); break; case NODE_OR: cond = (RubyBoolean)eval(self, node.nd_1st()); if (cond.isTrue()) { return cond; } node = node.nd_2nd(); break; case NODE_NOT: return RubyBoolean.m_newBoolean(getRuby(), eval(self, node.nd_1st()).isFalse()); case NODE_DOT2: case NODE_DOT3: result = RubyRange.m_newRange(getRuby(), eval(self, node.nd_beg()), eval(self, node.nd_end()), node.nd_type() == NODE_DOT3); if (node.nd_state() != 0) { return result; } if (node.nd_beg().nd_type() == NODE_LIT && (node.nd_beg().nd_lit() instanceof RubyFixnum) && node.nd_end().nd_type() == NODE_LIT && (node.nd_end().nd_lit() instanceof RubyFixnum)) { node.nd_set_type(NODE_LIT); node.nd_lit(result); } else { node.nd_state(1L); } return result; case NODE_FLIP2: /* like AWK */ /*if (ruby_scope->local_vars == 0) { rb_bug("unexpected local variable"); }*/ if (ruby.rubyScope.getLocalVars(node.nd_cnt()).isFalse()) { if (eval(self, node.nd_beg()).isTrue()) { ruby.rubyScope.setLocalVars(node.nd_cnt(), eval(self, node.nd_end()).isTrue() ? ruby.getFalse() : ruby.getTrue()); result = ruby.getTrue(); } else { result = ruby.getFalse(); } } else { if (eval(self, node.nd_end()).isTrue()) { ruby.rubyScope.setLocalVars(node.nd_cnt(), ruby.getFalse()); } result = ruby.getTrue(); } return result; case NODE_FLIP3: /* like SED */ /*if (ruby_scope->local_vars == 0) { rb_bug("unexpected local variable"); }*/ if (ruby.rubyScope.getLocalVars(node.nd_cnt()).isFalse()) { result = eval(self, node.nd_beg()).isTrue() ? ruby.getFalse() : ruby.getTrue(); ruby.rubyScope.setLocalVars(node.nd_cnt(), result); } else { if (eval(self, node.nd_end()).isTrue()) { ruby.rubyScope.setLocalVars(node.nd_cnt(), ruby.getFalse()); } result = ruby.getTrue(); } return result; case NODE_RETURN: if (node.nd_stts() != null) { result = eval(self, node.nd_stts()); } else { result = ruby.getNil(); } throw new ReturnException(result); case NODE_ARGSCAT: return ((RubyArray)eval(self, node.nd_head())).m_concat(eval(self, node.nd_body())); case NODE_ARGSPUSH: return ((RubyArray)eval(self, node.nd_head()).m_dup()).push(eval(self, node.nd_body())); case NODE_CALL: // TMP_PROTECT; RubyBlock tmpBlock = beginCallargs(); RubyObject recv = eval(self, node.nd_recv()); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); return recv.getRubyClass().call(recv, (RubyId)node.nd_mid(), args, 0); case NODE_FCALL: // TMP_PROTECT; tmpBlock = beginCallargs(); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); return self.getRubyClass().call(self, (RubyId)node.nd_mid(), args, 1); case NODE_VCALL: return self.getRubyClass().call(self, (RubyId)node.nd_mid(), null, 2); case NODE_SUPER: case NODE_ZSUPER: // TMP_PROTECT; if (rubyFrame.getLastClass() == null) { throw new RubyNameException("superclass method '" + rubyFrame.getLastFunc().toName() + "' disabled"); } if (node.nd_type() == NODE_ZSUPER) { List argsList = rubyFrame.getArgs(); args = (RubyObject[])argsList.toArray(new RubyObject[argsList.size()]); } else { tmpBlock = beginCallargs(); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); } rubyIter.push(rubyIter.getIter() != Iter.ITER_NOT ? Iter.ITER_PRE : Iter.ITER_NOT); result = rubyFrame.getLastClass().getSuperClass().call(rubyFrame.getSelf(), rubyFrame.getLastFunc(), args, 3); rubyIter.pop(); return result; case NODE_SCOPE: NODE saved_cref = null; Frame frame = rubyFrame; frame.setTmp(rubyFrame); rubyFrame = frame; ruby.rubyScope.push(); if (node.nd_rval() != null) { saved_cref = ruby_cref; ruby_cref = (NODE)node.nd_rval(); rubyFrame.setCbase(node.nd_rval()); } if (node.nd_tbl() != null) { List tmp = Collections.nCopies(node.nd_tbl()[0].intValue() + 1, ruby.getNil()); ShiftableList vars = new ShiftableList(new ArrayList(tmp)); vars.set(0, (VALUE)node); vars.shift(1); getRuby().rubyScope.setLocalVars(vars); getRuby().rubyScope.setLocalTbl(node.nd_tbl()); } else { getRuby().rubyScope.setLocalVars(null); getRuby().rubyScope.setLocalTbl(null); } result = eval(self, node.nd_next()); ruby.rubyScope.pop(); rubyFrame = frame.getTmp(); if (saved_cref != null) { ruby_cref = saved_cref; } return result; case NODE_OP_ASGN1: // TMP_PROTECT; recv = eval(self, node.nd_recv()); NODE rval = node.nd_args().nd_head(); args = setupArgs(self, node.nd_args().nd_next()); ArrayList argsList = new ArrayList(Arrays.asList(args)); argsList.remove(args.length - 1); RubyBoolean val = (RubyBoolean)recv.funcall(getRuby().intern("[]"), (RubyObject[])argsList.toArray(new RubyObject[argsList.size()])); switch (node.nd_mid().intValue()) { case 0: /* OR */ if (val.isTrue()) { return val; } val = (RubyBoolean)eval(self, rval); break; case 1: /* AND */ if (val.isFalse()) { return val; } val = (RubyBoolean)eval(self, rval); break; default: val = (RubyBoolean)val.funcall((RubyId)node.nd_mid(), eval(self, rval)); } args[args.length - 1] = val; return recv.funcall(getRuby().intern("[]="), args); case NODE_OP_ASGN2: ID id = node.nd_next().nd_vid(); recv = eval(self, node.nd_recv()); val = (RubyBoolean)recv.funcall((RubyId)id, (RubyObject[])null); switch (node.nd_next().nd_mid().intValue()) { case 0: /* OR */ if (val.isTrue()) { return val; } val = (RubyBoolean)eval(self, node.nd_value()); break; case 1: /* AND */ if (val.isFalse()) { return val; } val = (RubyBoolean)eval(self, node.nd_value()); break; default: val = (RubyBoolean)val.funcall((RubyId)node.nd_mid(), eval(self, node.nd_value())); } // HACK +++ val = (RubyBoolean)recv.funcall((RubyId)node.nd_next().nd_aid(), val); // HACK --- return val; case NODE_OP_ASGN_AND: cond = (RubyBoolean)eval(self, node.nd_head()); if (cond.isFalse()) { return cond; } node = node.nd_value(); break; case NODE_OP_ASGN_OR: cond = (RubyBoolean)eval(self, node.nd_head()); if ((node.nd_aid() != null && !self.isInstanceVarDefined((RubyId)node.nd_aid())) || cond.isFalse()) { node = node.nd_value(); break; } return cond; case NODE_MASGN: return massign(self, node, eval(self, node.nd_value()), false); case NODE_LASGN: // if (ruby.ruby_scope.local_vars == null) { // rb_bug("unexpected local variable assignment"); // } result = eval(self, node.nd_value()); getRuby().rubyScope.setLocalVars(node.nd_cnt(), result); return result; case NODE_DASGN: result = eval(self, node.nd_value()); RubyVarmap.assign(ruby, (RubyId)node.nd_vid(), result); return result; case NODE_DASGN_CURR: result = eval(self, node.nd_value()); RubyVarmap.assignCurrent(ruby, (RubyId)node.nd_vid(), result); return result; case NODE_GASGN: result = eval(self, node.nd_value()); ((RubyGlobalEntry)node.nd_entry()).set(result); return result; case NODE_IASGN: result = eval(self, node.nd_value()); self.setInstanceVar((RubyId)node.nd_vid(), result); return result; case NODE_CDECL: if (ruby_class == null) { throw new RubyTypeException("no class/module to define constant"); } result = eval(self, node.nd_value()); ruby_class.setConstant((RubyId)node.nd_vid(), result); return result; case NODE_CVDECL: if (ruby_cbase == null) { throw new RubyTypeException("no class/module to define class variable"); } result = eval(self, node.nd_value()); if (ruby_cbase.isSingleton()) { ruby_cbase.getInstanceVar("__attached__").getClassVarSingleton().declareClassVar((RubyId)node.nd_vid(), result); return result; } ruby_cbase.declareClassVar((RubyId)node.nd_vid(), result); return result; case NODE_CVASGN: result = eval(self, node.nd_value()); self.getClassVarSingleton().setClassVar((RubyId)node.nd_vid(), result); return result; case NODE_LVAR: //if (getRuby().ruby_scope.local_vars == null) { // rb_bug("unexpected local variable"); // } return (RubyObject)getRuby().rubyScope.getLocalVars(node.nd_cnt()); case NODE_DVAR: return getDynamicVars().getRef((RubyId)node.nd_vid()); case NODE_GVAR: return ((RubyGlobalEntry)node.nd_entry()).get(); case NODE_IVAR: return self.getInstanceVar((RubyId)node.nd_vid()); case NODE_CONST: return getConstant((NODE)rubyFrame.getCbase(), (RubyId)node.nd_vid(), self); case NODE_CVAR: /* normal method */ if (ruby_cbase == null) { return self.getRubyClass().getClassVar((RubyId)node.nd_vid()); } if (!ruby_cbase.isSingleton()) { return ruby_cbase.getClassVar((RubyId)node.nd_vid()); } return ruby_cbase.getInstanceVar("__attached__").getClassVarSingleton().getClassVar((RubyId)node.nd_vid()); case NODE_CVAR2: /* singleton method */ return self.getClassVarSingleton().getClassVar((RubyId)node.nd_vid()); case NODE_BLOCK_ARG: if (ruby.rubyScope.getLocalVars() == null) { throw new RuntimeException("BUG: unexpected block argument"); } if (isBlockGiven()) { result = getRuby().getNil(); // Create Proc object ruby.rubyScope.setLocalVars(node.nd_cnt(), result); return result; } else { return getRuby().getNil(); } case NODE_COLON2: value = eval(self, node.nd_head()); if (value instanceof RubyModule) { return ((RubyModule)value).getConstant((RubyId)node.nd_mid()); } else { return value.funcall((RubyId)node.nd_mid()); } case NODE_COLON3: return getRuby().getObjectClass().getConstant((RubyId)node.nd_mid()); case NODE_NTH_REF: // return rom.rb_reg_nth_match(node.nd_nth(), MATCH_DATA); return null; case NODE_BACK_REF: /*switch ((char)node.nd_nth()) { case '&': return rom.rb_reg_last_match(MATCH_DATA); case '`': return rom.rb_reg_match_pre(MATCH_DATA); case '\'': return rom.rb_reg_match_post(MATCH_DATA); case '+': return rom.rb_reg_match_last(MATCH_DATA); default: rom.rb_bug("unexpected back-ref"); }*/ case NODE_HASH: RubyHash hash = RubyHash.m_newHash(ruby); NODE list = node.nd_head(); while(list != null) { RubyObject key = eval(self, list.nd_head()); list = list.nd_next(); if (list == null) { // HACK +++ throw new RubyArgumentException("odd number list for Hash"); // HACK --- } value = eval(self, list.nd_head()); hash.m_aset(key, value); list = list.nd_next(); } return hash; case NODE_ZARRAY: /* zero length list */ return RubyArray.m_newArray(getRuby()); case NODE_ARRAY: ArrayList ary = new ArrayList(node.nd_alen()); for (; node != null ; node = node.nd_next()) { ary.add(eval(self, node.nd_head())); } return RubyArray.m_newArray(getRuby(), ary); case NODE_STR: return ((RubyObject)node.nd_lit()).m_to_s(); case NODE_DSTR: case NODE_DXSTR: case NODE_DREGX: case NODE_DREGX_ONCE:/* NODE list = node.nd_next(); RubyString str = RubyString.m_newString(getRuby(), (RubyObject)node.nd_lit()); RubyString str2; while (list != null) { if (list.nd_head() != null) { switch (list.nd_head().nd_type()) { case NODE_STR: str2 = (RubyString)list.nd_head().nd_lit(); break; case NODE_EVSTR: result = ruby_errinfo; ruby_errinfo = Qnil; ruby_sourceline = nd_line(node); ruby_in_eval++; list.nd_head(compile(list.nd_head().nd_lit(), ruby_sourcefile,ruby_sourceline)); ruby_eval_tree = 0; ruby_in_eval--; if (ruby_nerrs > 0) { compile_error("string expansion"); } if (!NIL_P(result)) ruby_errinfo = result; /* fall through *//* default: str2 = (RubyString)rom.rb_obj_as_string(eval(list.nd_head())); break; } str.append(str2); str.infectObject(str2); } list = list.nd_next(); } switch (node.nd_type()) { case NODE_DREGX: return rom.rb_reg_new(str.getString(), str.getString().length(), node.nd_cflag()); case NODE_DREGX_ONCE: /* regexp expand once *//* VALUE result = rom.rb_reg_new(str.getString(), str.getString().length(), node.nd_cflag()); node.nd_set_type(NODE_LIT); node.nd_lit(result); return result; case NODE_DXSTR: return rom.rb_funcall(this, '`', 1, str); default: return str; }*/ return null; case NODE_XSTR: return self.funcall(getRuby().intern("`"), (RubyObject)node.nd_lit()); case NODE_LIT: return (RubyObject)node.nd_lit(); case NODE_ATTRSET: if (rubyFrame.getArgs().size() != 1) { throw new RubyArgumentException("wrong # of arguments(" + rubyFrame.getArgs().size() + "for 1)"); } return self.setInstanceVar((RubyId)node.nd_vid(), (RubyObject)rubyFrame.getArgs().get(0)); case NODE_DEFN: if (node.nd_defn() != null) { int noex; if (ruby_class == null) { throw new RubyTypeException("no class to add method"); } //if (ruby_class == getRuby().getObjectClass() && node.nd_mid() == init) { // rom.rb_warn("redefining Object#initialize may cause infinite loop"); //} //if (node.nd_mid() == __id__ || node.nd_mid() == __send__) { // rom.rb_warn("redefining `%s' may cause serious problem", ((RubyId)node.nd_mid()).toName()); //} // ruby_class.setFrozen(true); NODE body = ruby_class.searchMethod((RubyId)node.nd_mid()); RubyObject origin = ruby_class.getMethodOrigin((RubyId)node.nd_mid()); if (body != null){ // if (ruby_verbose.isTrue() && ruby_class == origin && body.nd_cnt() == 0) { // rom.rb_warning("discarding old %s", ((RubyId)node.nd_mid()).toName()); // } // if (node.nd_noex() != 0) { /* toplevel */ /* should upgrade to rb_warn() if no super was called inside? */ // rom.rb_warning("overriding global function `%s'", ((RubyId)node.nd_mid()).toName()); // } } if (isScope(SCOPE_PRIVATE) || node.nd_mid().equals(ruby.intern("initialize"))) { noex = NOEX_PRIVATE; } else if (isScope(SCOPE_PROTECTED)) { noex = NOEX_PROTECTED; } else if (ruby_class == getRuby().getObjectClass()) { noex = node.nd_noex(); } else { noex = NOEX_PUBLIC; } if (body != null && origin == ruby_class && (body.nd_noex() & NOEX_UNDEF) != 0) { noex |= NOEX_UNDEF; } NODE defn = node.nd_defn().copyNodeScope(ruby_cref); ruby_class.addMethod((RubyId)node.nd_mid(), defn, noex); // rb_clear_cache_by_id(node.nd_mid()); if (scope_vmode == SCOPE_MODFUNC) { ruby_class.getSingletonClass().addMethod((RubyId)node.nd_mid(), defn, NOEX_PUBLIC); ruby_class.funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } if (ruby_class.isSingleton()) { ruby_class.getInstanceVar("__attached__").funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } else { ruby_class.funcall(getRuby().intern("method_added"), ((RubyId)node.nd_mid()).toSymbol()); } } return getRuby().getNil(); case NODE_DEFS: if (node.nd_defn() != null) { recv = eval(self, node.nd_recv()); if (getRuby().getSecurityLevel() >= 4 && !recv.isTaint()) { throw new RubySecurityException("Insecure; can't define singleton method"); } /*if (FIXNUM_P(recv) || SYMBOL_P(recv)) { rb_raise(rb_eTypeError, "can't define singleton method \"%s\" for %s", rb_id2name(node.nd_mid()), rb_class2name(CLASS_OF(recv))); }*/ // not needed in jruby if (recv.isFrozen()) { throw new RubyFrozenException("object"); } rubyClass = recv.getSingletonClass(); NODE body = (NODE)rubyClass.getMethods().get((RubyId)node.nd_mid()); if (body != null) { if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("redefining method prohibited"); } /*if (RTEST(ruby_verbose)) { rb_warning("redefine %s", rb_id2name(node.nd_mid())); }*/ } NODE defn = node.nd_defn().copyNodeScope(ruby_cref); defn.nd_rval(ruby_cref); rubyClass.addMethod((RubyId)node.nd_mid(), defn, NOEX_PUBLIC | (body != null ? body.nd_noex() & NOEX_UNDEF : 0)); // rb_clear_cache_by_id(node.nd_mid()); recv.funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } return getRuby().getNil(); case NODE_UNDEF: if (ruby_class == null) { throw new RubyTypeException("no class to undef method"); } ruby_class.undef((RubyId)node.nd_mid()); return getRuby().getNil(); case NODE_ALIAS: if (ruby_class == null) { throw new RubyTypeException("no class to make alias"); } ruby_class.aliasMethod((RubyId)node.nd_new(), (RubyId)node.nd_old()); ruby_class.funcall(getRuby().intern("method_added"), ((RubyId)node.nd_mid()).toSymbol()); return getRuby().getNil(); case NODE_VALIAS: RubyGlobalEntry.getGlobalEntry((RubyId)node.nd_old()).alias((RubyId)node.nd_new()); return getRuby().getNil(); case NODE_CLASS: RubyModule superClass; if (ruby_class == null) { throw new RubyTypeException("no outer class/module"); } if (node.nd_super() != null) { superClass = getSuperClass(self, node.nd_super()); } else { superClass = null; } rubyClass = null; // if ((ruby_class == getRuby().getObjectClass()) && rb_autoload_defined(node.nd_cname())) { // rb_autoload_load(node.nd_cname()); // } if (ruby_class.isConstantDefined((RubyId)node.nd_cname())) { rubyClass = (RubyClass)ruby_class.getConstant((RubyId)node.nd_cname()); } if (rubyClass != null) { if (!rubyClass.isClass()) { throw new RubyTypeException(((RubyId)node.nd_cname()).toName() + " is not a class"); } if (superClass != null) { RubyModule tmp = rubyClass.getSuperClass(); if (tmp.isSingleton()) { tmp = tmp.getSuperClass(); } while (tmp.isIncluded()) { tmp = tmp.getSuperClass(); } if (tmp != superClass) { superClass = tmp; //goto override_class; if (superClass == null) { superClass = getRuby().getObjectClass(); } rubyClass = getRuby().defineClassId((RubyId)node.nd_cname(), (RubyClass)superClass); ruby_class.setConstant((RubyId)node.nd_cname(), rubyClass); rubyClass.setClassPath((RubyClass)ruby_class, ((RubyId)node.nd_cname()).toName()); // end goto } } if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("extending class prohibited"); } // rb_clear_cache(); } else { //override_class: if (superClass == null) { superClass = getRuby().getObjectClass(); } rubyClass = getRuby().defineClassId((RubyId)node.nd_cname(), (RubyClass)superClass); ruby_class.setConstant((RubyId)node.nd_cname(), rubyClass); rubyClass.setClassPath((RubyClass)ruby_class, ((RubyId)node.nd_cname()).toName()); } if (ruby_wrapper != null) { rubyClass.getSingletonClass().includeModule(ruby_wrapper); rubyClass.includeModule(ruby_wrapper); } return setupModule(rubyClass, node.nd_body()); case NODE_MODULE: if (ruby_class == null) { throw new RubyTypeException("no outer class/module"); } RubyModule module = null; if ((ruby_class == getRuby().getObjectClass()) && getRuby().isAutoloadDefined((RubyId)node.nd_cname())) { // getRuby().rb_autoload_load(node.nd_cname()); } if (ruby_class.isConstantDefined((RubyId)node.nd_cname())) { module = (RubyModule)ruby_class.getConstant((RubyId)node.nd_cname()); } if (module != null) { if (!(module instanceof RubyModule)) { throw new RubyTypeException(((RubyId)node.nd_cname()).toName() + " is not a module"); } if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("extending module prohibited"); } } else { module = getRuby().defineModuleId((RubyId)node.nd_cname()); ruby_class.setConstant((RubyId)node.nd_cname(), module); module.setClassPath(ruby_class, ((RubyId)node.nd_cname()).toName()); } if (ruby_wrapper != null) { module.getSingletonClass().includeModule(ruby_wrapper); module.includeModule(ruby_wrapper); } return setupModule(module, node.nd_body()); case NODE_SCLASS: rubyClass = (RubyClass)eval(self, node.nd_recv()); if (rubyClass.isSpecialConst()) { throw new RubyTypeException("no virtual class for " + rubyClass.getRubyClass().toName()); } if (getRuby().getSecurityLevel() >= 4 && !rubyClass.isTaint()) { throw new RubySecurityException("Insecure: can't extend object"); } if (rubyClass.getRubyClass().isSingleton()) { // rb_clear_cache(); } rubyClass = rubyClass.getSingletonClass(); if (ruby_wrapper != null) { rubyClass.getSingletonClass().includeModule(ruby_wrapper); rubyClass.includeModule(ruby_wrapper); } return setupModule(rubyClass, node.nd_body()); case NODE_DEFINED: // String buf; // String desc = is_defined(self, node.nd_head(), buf); // // if (desc) { // result = rb_str_new2(desc); // } else { // result = Qnil; // } case NODE_NEWLINE: // ruby_sourcefile = node.nd_file; // ruby_sourceline = node.nd_nth(); // if (trace_func) { // call_trace_func("line", ruby_sourcefile, ruby_sourceline, self, // ruby_frame.last_func(), // ruby_frame.last_class()); // } node = node.nd_next(); break; default: // rom.rb_bug("unknown node type %d", nd_type(node)); } } }
public RubyObject eval(RubyObject self, NODE n) { NODE node = n; RubyBoolean cond = null; RubyObject[] args = null; RubyObject value = null; RubyObject result = null; RubyModule rubyClass = null; // int state; // RubyOriginalMethods rom = getRuby().getOriginalMethods(); while (true) { if (node == null) { return getRuby().getNil(); } switch (node.nd_type()) { case NODE_BLOCK: while (node.nd_next() != null) { eval(self, node.nd_head()); node = node.nd_next(); } node = node.nd_head(); break; case NODE_POSTEXE: // rb_f_END(); node.nd_set_type(NODE_NIL); /* exec just once */ return getRuby().getNil(); /* begin .. end without clauses */ case NODE_BEGIN: node = node.nd_body(); break; /* nodes for speed-up(default match) */ case NODE_MATCH: //return rom.rb_reg_match2(node.nd_head().nd_lit()); return getRuby().getNil(); /* nodes for speed-up(literal match) */ case NODE_MATCH2: //return rom.rb_reg_match(eval(node.nd_recv()), eval(node.nd_value())); return getRuby().getNil(); /* nodes for speed-up(literal match) */ case NODE_MATCH3: //VALUE r = eval(node.nd_recv()); //VALUE l = eval(node.nd_value()); //if (r instanceof RubyString) { // return rom.rb_reg_match(l, r); //} else { // return rom.rb_funcall(r, match, 1, l); //} return getRuby().getNil(); /* node for speed-up(top-level loop for -n/-p) */ case NODE_OPT_N: while (true) { try { // while (!rb_gets().isNil() false) { // HACK +++ if (true) { // HACK --- try { eval(self, node.nd_body()); } catch (RedoException rExcptn) { } } break; } catch (NextException nExcptn) { } catch (BreakException bExcptn) { break; } } return getRuby().getNil(); case NODE_SELF: return self; case NODE_NIL: return getRuby().getNil(); case NODE_TRUE: return getRuby().getTrue(); case NODE_FALSE: return getRuby().getFalse(); case NODE_IF: // ruby_sourceline = node.nd_line(); cond = (RubyBoolean)eval(self, node.nd_cond()); if (cond.isTrue()) { node = node.nd_body(); } else { node = node.nd_else(); } break; case NODE_WHEN: while (node != null) { NODE tag; if (node.nd_type() != NODE_WHEN) { break; } tag = node.nd_head(); while (tag != null) {/* if (trace_func) { call_trace_func("line", tag->nd_file, nd_line(tag), self, ruby_frame->last_func, ruby_frame->last_class); }*/ // ruby_sourcefile = tag.nd_file; // ruby_sourceline = tag.nd_line(); if (tag.nd_head().nd_type() == NODE_WHEN) { RubyObject obj = eval(self, tag.nd_head().nd_head()); if (!(obj instanceof RubyArray)) { obj = RubyArray.m_newArray(getRuby(), obj); } for (int i = 0; i < ((RubyArray)obj).length(); i++) { if (((RubyBoolean)((RubyArray)obj).entry(i)).isTrue()) { node = node.nd_body(); break; } } tag = tag.nd_next(); continue; } if (((RubyBoolean)eval(self, tag.nd_head())).isTrue()) { node = node.nd_body(); break; } tag = tag.nd_next(); } node = node.nd_next(); } return getRuby().getNil(); case NODE_CASE: RubyObject obj = eval(self, node.nd_head()); node = node.nd_body(); while (node != null) { NODE tag; if (node.nd_type() != NODE_WHEN) { break; } tag = node.nd_head(); while (tag != null) {/* if (trace_func) { call_trace_func("line", tag->nd_file, nd_line(tag), self, ruby_frame->last_func, ruby_frame->last_class); } ruby_sourcefile = tag->nd_file; ruby_sourceline = nd_line(tag);*/ if (tag.nd_head().nd_type() == NODE_WHEN) { RubyObject obj2 = eval(self, tag.nd_head().nd_head()); if (!(obj2 instanceof RubyArray)) { obj2 = RubyArray.m_newArray(getRuby(), obj2); } for (int i = 0; i < ((RubyArray)obj).length(); i++) { RubyBoolean eqq = (RubyBoolean)((RubyArray)obj2).entry(i).funcall(getRuby().intern("==="), obj); if (eqq.isTrue()) { node = node.nd_body(); break; } } tag = tag.nd_next(); continue; } if (((RubyBoolean)eval(self, tag.nd_head()).funcall(getRuby().intern("==="), obj)).isTrue()) { node = node.nd_body(); break; } tag = tag.nd_next(); } node = node.nd_next(); } return getRuby().getNil(); case NODE_WHILE: while (eval(self, node.nd_cond()).isTrue()) { while (true) { try { eval(self, node.nd_body()); break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { break; } catch (BreakException bExcptn) { return getRuby().getNil(); } } } return getRuby().getNil(); case NODE_UNTIL: while (eval(self, node.nd_cond()).isFalse()) { while (true) { try { eval(self, node.nd_body()); break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { break; } catch (BreakException bExcptn) { return getRuby().getNil(); } } } return getRuby().getNil(); case NODE_BLOCK_PASS: //return block_pass(node); return null; case NODE_ITER: case NODE_FOR: rubyBlock.push(node.nd_var(), node.nd_body(), self); rubyIter.push(Iter.ITER_PRE); while (true) { try { if (node.nd_type() == NODE_ITER) { result = eval(self, node.nd_iter()); } else { // String file = // int line = rubyBlock.flags &= ~RubyBlock.BLOCK_D_SCOPE; RubyBlock tmpBlock = beginCallargs(); RubyObject recv = eval(self, node.nd_iter()); endCallArgs(tmpBlock); // = file; // = line; result = recv.getRubyClass().call(recv, ruby.intern("each"), null, 0); } break; } catch (RetryException rExcptn) { } catch (ReturnException rExcptn) { result = rExcptn.getReturnValue(); break; } catch (BreakException bExcptn) { result = ruby.getNil(); break; } } rubyIter.pop(); rubyBlock.pop(); return result; case NODE_BREAK: throw new BreakException(); case NODE_NEXT: throw new NextException(); case NODE_REDO: throw new RedoException(); case NODE_RETRY: throw new RetryException(); case NODE_RESTARGS: result = eval(self, node.nd_head()); if (!(result instanceof RubyArray)) { result = obj = RubyArray.m_newArray(getRuby(), result); } return result; case NODE_YIELD: if (node.nd_stts() != null) { result = eval(self, node.nd_stts()); if (node.nd_stts().nd_type() == NODE_RESTARGS && ((RubyArray)result).length() == 1) { result = ((RubyArray)result).entry(0); } } else { result = ruby.getNil(); } return yield0(result, null, null, false); case NODE_RESCUE:/* retry_entry: { volatile VALUE e_info = ruby_errinfo; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, node->nd_head); } POP_TAG(); if (state == TAG_RAISE) { NODE * volatile resq = node->nd_resq; ruby_sourceline = nd_line(node); while (resq) { if (handle_rescue(self, resq)) { state = 0; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, resq->nd_body); } POP_TAG(); if (state == TAG_RETRY) { state = 0; ruby_errinfo = Qnil; goto retry_entry; } if (state != TAG_RAISE) { ruby_errinfo = e_info; } break; } resq = resq->nd_head; /* next rescue */ /** } * } * else if (node->nd_else) { /* else clause given *//* if (!state) { /* no exception raised *//* result = rb_eval(self, node->nd_else); } } if (state) JUMP_TAG(state); } break;*/ case NODE_ENSURE:/* PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = eval(node.nd_head()); } POP_TAG(); if (node.nd_ensr()) { VALUE retval = prot_tag->retval; /* save retval *//* VALUE errinfo = ruby_errinfo; rb_eval(self, node->nd_ensr); return_value(retval); ruby_errinfo = errinfo; } if (state) JUMP_TAG(state); break;*/ case NODE_AND: cond = (RubyBoolean)eval(self, node.nd_1st()); if (cond.isFalse()) { return cond; } node = node.nd_2nd(); break; case NODE_OR: cond = (RubyBoolean)eval(self, node.nd_1st()); if (cond.isTrue()) { return cond; } node = node.nd_2nd(); break; case NODE_NOT: return RubyBoolean.m_newBoolean(getRuby(), eval(self, node.nd_1st()).isFalse()); case NODE_DOT2: case NODE_DOT3: result = RubyRange.m_newRange(getRuby(), eval(self, node.nd_beg()), eval(self, node.nd_end()), node.nd_type() == NODE_DOT3); if (node.nd_state() != 0) { return result; } if (node.nd_beg().nd_type() == NODE_LIT && (node.nd_beg().nd_lit() instanceof RubyFixnum) && node.nd_end().nd_type() == NODE_LIT && (node.nd_end().nd_lit() instanceof RubyFixnum)) { node.nd_set_type(NODE_LIT); node.nd_lit(result); } else { node.nd_state(1L); } return result; case NODE_FLIP2: /* like AWK */ /*if (ruby_scope->local_vars == 0) { rb_bug("unexpected local variable"); }*/ if (ruby.rubyScope.getLocalVars(node.nd_cnt()).isFalse()) { if (eval(self, node.nd_beg()).isTrue()) { ruby.rubyScope.setLocalVars(node.nd_cnt(), eval(self, node.nd_end()).isTrue() ? ruby.getFalse() : ruby.getTrue()); result = ruby.getTrue(); } else { result = ruby.getFalse(); } } else { if (eval(self, node.nd_end()).isTrue()) { ruby.rubyScope.setLocalVars(node.nd_cnt(), ruby.getFalse()); } result = ruby.getTrue(); } return result; case NODE_FLIP3: /* like SED */ /*if (ruby_scope->local_vars == 0) { rb_bug("unexpected local variable"); }*/ if (ruby.rubyScope.getLocalVars(node.nd_cnt()).isFalse()) { result = eval(self, node.nd_beg()).isTrue() ? ruby.getFalse() : ruby.getTrue(); ruby.rubyScope.setLocalVars(node.nd_cnt(), result); } else { if (eval(self, node.nd_end()).isTrue()) { ruby.rubyScope.setLocalVars(node.nd_cnt(), ruby.getFalse()); } result = ruby.getTrue(); } return result; case NODE_RETURN: if (node.nd_stts() != null) { result = eval(self, node.nd_stts()); } else { result = ruby.getNil(); } throw new ReturnException(result); case NODE_ARGSCAT: return ((RubyArray)eval(self, node.nd_head())).m_concat(eval(self, node.nd_body())); case NODE_ARGSPUSH: return ((RubyArray)eval(self, node.nd_head()).m_dup()).push(eval(self, node.nd_body())); case NODE_CALL: // TMP_PROTECT; RubyBlock tmpBlock = beginCallargs(); RubyObject recv = eval(self, node.nd_recv()); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); return recv.getRubyClass().call(recv, (RubyId)node.nd_mid(), args, 0); case NODE_FCALL: // TMP_PROTECT; tmpBlock = beginCallargs(); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); return self.getRubyClass().call(self, (RubyId)node.nd_mid(), args, 1); case NODE_VCALL: return self.getRubyClass().call(self, (RubyId)node.nd_mid(), null, 2); case NODE_SUPER: case NODE_ZSUPER: // TMP_PROTECT; if (getRubyFrame().getLastClass() == null) { throw new RubyNameException("superclass method '" + rubyFrame.getLastFunc().toName() + "' disabled"); } if (node.nd_type() == NODE_ZSUPER) { List argsList = rubyFrame.getArgs(); args = (RubyObject[])argsList.toArray(new RubyObject[argsList.size()]); } else { tmpBlock = beginCallargs(); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); } rubyIter.push(rubyIter.getIter() != Iter.ITER_NOT ? Iter.ITER_PRE : Iter.ITER_NOT); result = rubyFrame.getLastClass().getSuperClass().call(rubyFrame.getSelf(), rubyFrame.getLastFunc(), args, 3); rubyIter.pop(); return result; case NODE_SCOPE: NODE saved_cref = null; Frame frame = rubyFrame; frame.setTmp(rubyFrame); rubyFrame = frame; ruby.rubyScope.push(); if (node.nd_rval() != null) { saved_cref = ruby_cref; ruby_cref = (NODE)node.nd_rval(); rubyFrame.setCbase(node.nd_rval()); } if (node.nd_tbl() != null) { List tmp = Collections.nCopies(node.nd_tbl()[0].intValue() + 1, ruby.getNil()); ShiftableList vars = new ShiftableList(new ArrayList(tmp)); vars.set(0, (VALUE)node); vars.shift(1); getRuby().rubyScope.setLocalVars(vars); getRuby().rubyScope.setLocalTbl(node.nd_tbl()); } else { getRuby().rubyScope.setLocalVars(null); getRuby().rubyScope.setLocalTbl(null); } result = eval(self, node.nd_next()); ruby.rubyScope.pop(); rubyFrame = frame.getTmp(); if (saved_cref != null) { ruby_cref = saved_cref; } return result; case NODE_OP_ASGN1: // TMP_PROTECT; recv = eval(self, node.nd_recv()); NODE rval = node.nd_args().nd_head(); args = setupArgs(self, node.nd_args().nd_next()); ArrayList argsList = new ArrayList(Arrays.asList(args)); argsList.remove(args.length - 1); RubyBoolean val = (RubyBoolean)recv.funcall(getRuby().intern("[]"), (RubyObject[])argsList.toArray(new RubyObject[argsList.size()])); switch (node.nd_mid().intValue()) { case 0: /* OR */ if (val.isTrue()) { return val; } val = (RubyBoolean)eval(self, rval); break; case 1: /* AND */ if (val.isFalse()) { return val; } val = (RubyBoolean)eval(self, rval); break; default: val = (RubyBoolean)val.funcall((RubyId)node.nd_mid(), eval(self, rval)); } args[args.length - 1] = val; return recv.funcall(getRuby().intern("[]="), args); case NODE_OP_ASGN2: ID id = node.nd_next().nd_vid(); recv = eval(self, node.nd_recv()); val = (RubyBoolean)recv.funcall((RubyId)id, (RubyObject[])null); switch (node.nd_next().nd_mid().intValue()) { case 0: /* OR */ if (val.isTrue()) { return val; } val = (RubyBoolean)eval(self, node.nd_value()); break; case 1: /* AND */ if (val.isFalse()) { return val; } val = (RubyBoolean)eval(self, node.nd_value()); break; default: val = (RubyBoolean)val.funcall((RubyId)node.nd_mid(), eval(self, node.nd_value())); } // HACK +++ val = (RubyBoolean)recv.funcall((RubyId)node.nd_next().nd_aid(), val); // HACK --- return val; case NODE_OP_ASGN_AND: cond = (RubyBoolean)eval(self, node.nd_head()); if (cond.isFalse()) { return cond; } node = node.nd_value(); break; case NODE_OP_ASGN_OR: cond = (RubyBoolean)eval(self, node.nd_head()); if ((node.nd_aid() != null && !self.isInstanceVarDefined((RubyId)node.nd_aid())) || cond.isFalse()) { node = node.nd_value(); break; } return cond; case NODE_MASGN: return massign(self, node, eval(self, node.nd_value()), false); case NODE_LASGN: // if (ruby.ruby_scope.local_vars == null) { // rb_bug("unexpected local variable assignment"); // } result = eval(self, node.nd_value()); getRuby().rubyScope.setLocalVars(node.nd_cnt(), result); return result; case NODE_DASGN: result = eval(self, node.nd_value()); RubyVarmap.assign(ruby, (RubyId)node.nd_vid(), result); return result; case NODE_DASGN_CURR: result = eval(self, node.nd_value()); RubyVarmap.assignCurrent(ruby, (RubyId)node.nd_vid(), result); return result; case NODE_GASGN: result = eval(self, node.nd_value()); ((RubyGlobalEntry)node.nd_entry()).set(result); return result; case NODE_IASGN: result = eval(self, node.nd_value()); self.setInstanceVar((RubyId)node.nd_vid(), result); return result; case NODE_CDECL: if (ruby_class == null) { throw new RubyTypeException("no class/module to define constant"); } result = eval(self, node.nd_value()); ruby_class.setConstant((RubyId)node.nd_vid(), result); return result; case NODE_CVDECL: if (ruby_cbase == null) { throw new RubyTypeException("no class/module to define class variable"); } result = eval(self, node.nd_value()); if (ruby_cbase.isSingleton()) { ruby_cbase.getInstanceVar("__attached__").getClassVarSingleton().declareClassVar((RubyId)node.nd_vid(), result); return result; } ruby_cbase.declareClassVar((RubyId)node.nd_vid(), result); return result; case NODE_CVASGN: result = eval(self, node.nd_value()); self.getClassVarSingleton().setClassVar((RubyId)node.nd_vid(), result); return result; case NODE_LVAR: //if (getRuby().ruby_scope.local_vars == null) { // rb_bug("unexpected local variable"); // } return (RubyObject)getRuby().rubyScope.getLocalVars(node.nd_cnt()); case NODE_DVAR: return getDynamicVars().getRef((RubyId)node.nd_vid()); case NODE_GVAR: return ((RubyGlobalEntry)node.nd_entry()).get(); case NODE_IVAR: return self.getInstanceVar((RubyId)node.nd_vid()); case NODE_CONST: return getConstant((NODE)rubyFrame.getCbase(), (RubyId)node.nd_vid(), self); case NODE_CVAR: /* normal method */ if (ruby_cbase == null) { return self.getRubyClass().getClassVar((RubyId)node.nd_vid()); } if (!ruby_cbase.isSingleton()) { return ruby_cbase.getClassVar((RubyId)node.nd_vid()); } return ruby_cbase.getInstanceVar("__attached__").getClassVarSingleton().getClassVar((RubyId)node.nd_vid()); case NODE_CVAR2: /* singleton method */ return self.getClassVarSingleton().getClassVar((RubyId)node.nd_vid()); case NODE_BLOCK_ARG: if (ruby.rubyScope.getLocalVars() == null) { throw new RuntimeException("BUG: unexpected block argument"); } if (isBlockGiven()) { result = getRuby().getNil(); // Create Proc object ruby.rubyScope.setLocalVars(node.nd_cnt(), result); return result; } else { return getRuby().getNil(); } case NODE_COLON2: value = eval(self, node.nd_head()); if (value instanceof RubyModule) { return ((RubyModule)value).getConstant((RubyId)node.nd_mid()); } else { return value.funcall((RubyId)node.nd_mid()); } case NODE_COLON3: return getRuby().getObjectClass().getConstant((RubyId)node.nd_mid()); case NODE_NTH_REF: // return rom.rb_reg_nth_match(node.nd_nth(), MATCH_DATA); return null; case NODE_BACK_REF: /*switch ((char)node.nd_nth()) { case '&': return rom.rb_reg_last_match(MATCH_DATA); case '`': return rom.rb_reg_match_pre(MATCH_DATA); case '\'': return rom.rb_reg_match_post(MATCH_DATA); case '+': return rom.rb_reg_match_last(MATCH_DATA); default: rom.rb_bug("unexpected back-ref"); }*/ case NODE_HASH: RubyHash hash = RubyHash.m_newHash(ruby); NODE list = node.nd_head(); while(list != null) { RubyObject key = eval(self, list.nd_head()); list = list.nd_next(); if (list == null) { // HACK +++ throw new RubyArgumentException("odd number list for Hash"); // HACK --- } value = eval(self, list.nd_head()); hash.m_aset(key, value); list = list.nd_next(); } return hash; case NODE_ZARRAY: /* zero length list */ return RubyArray.m_newArray(getRuby()); case NODE_ARRAY: ArrayList ary = new ArrayList(node.nd_alen()); for (; node != null ; node = node.nd_next()) { ary.add(eval(self, node.nd_head())); } return RubyArray.m_newArray(getRuby(), ary); case NODE_STR: return ((RubyObject)node.nd_lit()).m_to_s(); case NODE_DSTR: case NODE_DXSTR: case NODE_DREGX: case NODE_DREGX_ONCE:/* NODE list = node.nd_next(); RubyString str = RubyString.m_newString(getRuby(), (RubyObject)node.nd_lit()); RubyString str2; while (list != null) { if (list.nd_head() != null) { switch (list.nd_head().nd_type()) { case NODE_STR: str2 = (RubyString)list.nd_head().nd_lit(); break; case NODE_EVSTR: result = ruby_errinfo; ruby_errinfo = Qnil; ruby_sourceline = nd_line(node); ruby_in_eval++; list.nd_head(compile(list.nd_head().nd_lit(), ruby_sourcefile,ruby_sourceline)); ruby_eval_tree = 0; ruby_in_eval--; if (ruby_nerrs > 0) { compile_error("string expansion"); } if (!NIL_P(result)) ruby_errinfo = result; /* fall through *//* default: str2 = (RubyString)rom.rb_obj_as_string(eval(list.nd_head())); break; } str.append(str2); str.infectObject(str2); } list = list.nd_next(); } switch (node.nd_type()) { case NODE_DREGX: return rom.rb_reg_new(str.getString(), str.getString().length(), node.nd_cflag()); case NODE_DREGX_ONCE: /* regexp expand once *//* VALUE result = rom.rb_reg_new(str.getString(), str.getString().length(), node.nd_cflag()); node.nd_set_type(NODE_LIT); node.nd_lit(result); return result; case NODE_DXSTR: return rom.rb_funcall(this, '`', 1, str); default: return str; }*/ return null; case NODE_XSTR: return self.funcall(getRuby().intern("`"), (RubyObject)node.nd_lit()); case NODE_LIT: return (RubyObject)node.nd_lit(); case NODE_ATTRSET: if (rubyFrame.getArgs().size() != 1) { throw new RubyArgumentException("wrong # of arguments(" + rubyFrame.getArgs().size() + "for 1)"); } return self.setInstanceVar((RubyId)node.nd_vid(), (RubyObject)rubyFrame.getArgs().get(0)); case NODE_DEFN: if (node.nd_defn() != null) { int noex; if (ruby_class == null) { throw new RubyTypeException("no class to add method"); } //if (ruby_class == getRuby().getObjectClass() && node.nd_mid() == init) { // rom.rb_warn("redefining Object#initialize may cause infinite loop"); //} //if (node.nd_mid() == __id__ || node.nd_mid() == __send__) { // rom.rb_warn("redefining `%s' may cause serious problem", ((RubyId)node.nd_mid()).toName()); //} // ruby_class.setFrozen(true); NODE body = ruby_class.searchMethod((RubyId)node.nd_mid()); RubyObject origin = ruby_class.getMethodOrigin((RubyId)node.nd_mid()); if (body != null){ // if (ruby_verbose.isTrue() && ruby_class == origin && body.nd_cnt() == 0) { // rom.rb_warning("discarding old %s", ((RubyId)node.nd_mid()).toName()); // } // if (node.nd_noex() != 0) { /* toplevel */ /* should upgrade to rb_warn() if no super was called inside? */ // rom.rb_warning("overriding global function `%s'", ((RubyId)node.nd_mid()).toName()); // } } if (isScope(SCOPE_PRIVATE) || node.nd_mid().equals(ruby.intern("initialize"))) { noex = NOEX_PRIVATE; } else if (isScope(SCOPE_PROTECTED)) { noex = NOEX_PROTECTED; } else if (ruby_class == getRuby().getObjectClass()) { noex = node.nd_noex(); } else { noex = NOEX_PUBLIC; } if (body != null && origin == ruby_class && (body.nd_noex() & NOEX_UNDEF) != 0) { noex |= NOEX_UNDEF; } NODE defn = node.nd_defn().copyNodeScope(ruby_cref); ruby_class.addMethod((RubyId)node.nd_mid(), defn, noex); // rb_clear_cache_by_id(node.nd_mid()); if (scope_vmode == SCOPE_MODFUNC) { ruby_class.getSingletonClass().addMethod((RubyId)node.nd_mid(), defn, NOEX_PUBLIC); ruby_class.funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } if (ruby_class.isSingleton()) { ruby_class.getInstanceVar("__attached__").funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } else { ruby_class.funcall(getRuby().intern("method_added"), ((RubyId)node.nd_mid()).toSymbol()); } } return getRuby().getNil(); case NODE_DEFS: if (node.nd_defn() != null) { recv = eval(self, node.nd_recv()); if (getRuby().getSecurityLevel() >= 4 && !recv.isTaint()) { throw new RubySecurityException("Insecure; can't define singleton method"); } /*if (FIXNUM_P(recv) || SYMBOL_P(recv)) { rb_raise(rb_eTypeError, "can't define singleton method \"%s\" for %s", rb_id2name(node.nd_mid()), rb_class2name(CLASS_OF(recv))); }*/ // not needed in jruby if (recv.isFrozen()) { throw new RubyFrozenException("object"); } rubyClass = recv.getSingletonClass(); NODE body = (NODE)rubyClass.getMethods().get((RubyId)node.nd_mid()); if (body != null) { if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("redefining method prohibited"); } /*if (RTEST(ruby_verbose)) { rb_warning("redefine %s", rb_id2name(node.nd_mid())); }*/ } NODE defn = node.nd_defn().copyNodeScope(ruby_cref); defn.nd_rval(ruby_cref); rubyClass.addMethod((RubyId)node.nd_mid(), defn, NOEX_PUBLIC | (body != null ? body.nd_noex() & NOEX_UNDEF : 0)); // rb_clear_cache_by_id(node.nd_mid()); recv.funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } return getRuby().getNil(); case NODE_UNDEF: if (ruby_class == null) { throw new RubyTypeException("no class to undef method"); } ruby_class.undef((RubyId)node.nd_mid()); return getRuby().getNil(); case NODE_ALIAS: if (ruby_class == null) { throw new RubyTypeException("no class to make alias"); } ruby_class.aliasMethod((RubyId)node.nd_new(), (RubyId)node.nd_old()); ruby_class.funcall(getRuby().intern("method_added"), ((RubyId)node.nd_mid()).toSymbol()); return getRuby().getNil(); case NODE_VALIAS: RubyGlobalEntry.getGlobalEntry((RubyId)node.nd_old()).alias((RubyId)node.nd_new()); return getRuby().getNil(); case NODE_CLASS: RubyModule superClass; if (ruby_class == null) { throw new RubyTypeException("no outer class/module"); } if (node.nd_super() != null) { superClass = getSuperClass(self, node.nd_super()); } else { superClass = null; } rubyClass = null; // if ((ruby_class == getRuby().getObjectClass()) && rb_autoload_defined(node.nd_cname())) { // rb_autoload_load(node.nd_cname()); // } if (ruby_class.isConstantDefined((RubyId)node.nd_cname())) { rubyClass = (RubyClass)ruby_class.getConstant((RubyId)node.nd_cname()); } if (rubyClass != null) { if (!rubyClass.isClass()) { throw new RubyTypeException(((RubyId)node.nd_cname()).toName() + " is not a class"); } if (superClass != null) { RubyModule tmp = rubyClass.getSuperClass(); if (tmp.isSingleton()) { tmp = tmp.getSuperClass(); } while (tmp.isIncluded()) { tmp = tmp.getSuperClass(); } if (tmp != superClass) { superClass = tmp; //goto override_class; if (superClass == null) { superClass = getRuby().getObjectClass(); } rubyClass = getRuby().defineClassId((RubyId)node.nd_cname(), (RubyClass)superClass); ruby_class.setConstant((RubyId)node.nd_cname(), rubyClass); rubyClass.setClassPath((RubyClass)ruby_class, ((RubyId)node.nd_cname()).toName()); // end goto } } if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("extending class prohibited"); } // rb_clear_cache(); } else { //override_class: if (superClass == null) { superClass = getRuby().getObjectClass(); } rubyClass = getRuby().defineClassId((RubyId)node.nd_cname(), (RubyClass)superClass); ruby_class.setConstant((RubyId)node.nd_cname(), rubyClass); rubyClass.setClassPath((RubyClass)ruby_class, ((RubyId)node.nd_cname()).toName()); } if (ruby_wrapper != null) { rubyClass.getSingletonClass().includeModule(ruby_wrapper); rubyClass.includeModule(ruby_wrapper); } return setupModule(rubyClass, node.nd_body()); case NODE_MODULE: if (ruby_class == null) { throw new RubyTypeException("no outer class/module"); } RubyModule module = null; if ((ruby_class == getRuby().getObjectClass()) && getRuby().isAutoloadDefined((RubyId)node.nd_cname())) { // getRuby().rb_autoload_load(node.nd_cname()); } if (ruby_class.isConstantDefined((RubyId)node.nd_cname())) { module = (RubyModule)ruby_class.getConstant((RubyId)node.nd_cname()); } if (module != null) { if (!(module instanceof RubyModule)) { throw new RubyTypeException(((RubyId)node.nd_cname()).toName() + " is not a module"); } if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("extending module prohibited"); } } else { module = getRuby().defineModuleId((RubyId)node.nd_cname()); ruby_class.setConstant((RubyId)node.nd_cname(), module); module.setClassPath(ruby_class, ((RubyId)node.nd_cname()).toName()); } if (ruby_wrapper != null) { module.getSingletonClass().includeModule(ruby_wrapper); module.includeModule(ruby_wrapper); } return setupModule(module, node.nd_body()); case NODE_SCLASS: rubyClass = (RubyClass)eval(self, node.nd_recv()); if (rubyClass.isSpecialConst()) { throw new RubyTypeException("no virtual class for " + rubyClass.getRubyClass().toName()); } if (getRuby().getSecurityLevel() >= 4 && !rubyClass.isTaint()) { throw new RubySecurityException("Insecure: can't extend object"); } if (rubyClass.getRubyClass().isSingleton()) { // rb_clear_cache(); } rubyClass = rubyClass.getSingletonClass(); if (ruby_wrapper != null) { rubyClass.getSingletonClass().includeModule(ruby_wrapper); rubyClass.includeModule(ruby_wrapper); } return setupModule(rubyClass, node.nd_body()); case NODE_DEFINED: // String buf; // String desc = is_defined(self, node.nd_head(), buf); // // if (desc) { // result = rb_str_new2(desc); // } else { // result = Qnil; // } case NODE_NEWLINE: // ruby_sourcefile = node.nd_file; // ruby_sourceline = node.nd_nth(); // if (trace_func) { // call_trace_func("line", ruby_sourcefile, ruby_sourceline, self, // ruby_frame.last_func(), // ruby_frame.last_class()); // } node = node.nd_next(); break; default: // rom.rb_bug("unknown node type %d", nd_type(node)); } } }
3,238,698
public RubyObject eval(RubyObject self, NODE n) { NODE node = n; RubyBoolean cond = null; RubyObject[] args = null; RubyObject value = null; RubyObject result = null; RubyModule rubyClass = null; // int state; // RubyOriginalMethods rom = getRuby().getOriginalMethods(); while (true) { if (node == null) { return getRuby().getNil(); } switch (node.nd_type()) { case NODE_BLOCK: while (node.nd_next() != null) { eval(self, node.nd_head()); node = node.nd_next(); } node = node.nd_head(); break; case NODE_POSTEXE: // rb_f_END(); node.nd_set_type(NODE_NIL); /* exec just once */ return getRuby().getNil(); /* begin .. end without clauses */ case NODE_BEGIN: node = node.nd_body(); break; /* nodes for speed-up(default match) */ case NODE_MATCH: //return rom.rb_reg_match2(node.nd_head().nd_lit()); return getRuby().getNil(); /* nodes for speed-up(literal match) */ case NODE_MATCH2: //return rom.rb_reg_match(eval(node.nd_recv()), eval(node.nd_value())); return getRuby().getNil(); /* nodes for speed-up(literal match) */ case NODE_MATCH3: //VALUE r = eval(node.nd_recv()); //VALUE l = eval(node.nd_value()); //if (r instanceof RubyString) { // return rom.rb_reg_match(l, r); //} else { // return rom.rb_funcall(r, match, 1, l); //} return getRuby().getNil(); /* node for speed-up(top-level loop for -n/-p) */ case NODE_OPT_N: while (true) { try { // while (!rb_gets().isNil() false) { // HACK +++ if (true) { // HACK --- try { eval(self, node.nd_body()); } catch (RedoException rExcptn) { } } break; } catch (NextException nExcptn) { } catch (BreakException bExcptn) { break; } } return getRuby().getNil(); case NODE_SELF: return self; case NODE_NIL: return getRuby().getNil(); case NODE_TRUE: return getRuby().getTrue(); case NODE_FALSE: return getRuby().getFalse(); case NODE_IF: // ruby_sourceline = node.nd_line(); cond = (RubyBoolean)eval(self, node.nd_cond()); if (cond.isTrue()) { node = node.nd_body(); } else { node = node.nd_else(); } break; case NODE_WHEN: while (node != null) { NODE tag; if (node.nd_type() != NODE_WHEN) { break; } tag = node.nd_head(); while (tag != null) {/* if (trace_func) { call_trace_func("line", tag->nd_file, nd_line(tag), self, ruby_frame->last_func, ruby_frame->last_class); }*/ // ruby_sourcefile = tag.nd_file; // ruby_sourceline = tag.nd_line(); if (tag.nd_head().nd_type() == NODE_WHEN) { RubyObject obj = eval(self, tag.nd_head().nd_head()); if (!(obj instanceof RubyArray)) { obj = RubyArray.m_newArray(getRuby(), obj); } for (int i = 0; i < ((RubyArray)obj).length(); i++) { if (((RubyBoolean)((RubyArray)obj).entry(i)).isTrue()) { node = node.nd_body(); break; } } tag = tag.nd_next(); continue; } if (((RubyBoolean)eval(self, tag.nd_head())).isTrue()) { node = node.nd_body(); break; } tag = tag.nd_next(); } node = node.nd_next(); } return getRuby().getNil(); case NODE_CASE: RubyObject obj = eval(self, node.nd_head()); node = node.nd_body(); while (node != null) { NODE tag; if (node.nd_type() != NODE_WHEN) { break; } tag = node.nd_head(); while (tag != null) {/* if (trace_func) { call_trace_func("line", tag->nd_file, nd_line(tag), self, ruby_frame->last_func, ruby_frame->last_class); } ruby_sourcefile = tag->nd_file; ruby_sourceline = nd_line(tag);*/ if (tag.nd_head().nd_type() == NODE_WHEN) { RubyObject obj2 = eval(self, tag.nd_head().nd_head()); if (!(obj2 instanceof RubyArray)) { obj2 = RubyArray.m_newArray(getRuby(), obj2); } for (int i = 0; i < ((RubyArray)obj).length(); i++) { RubyBoolean eqq = (RubyBoolean)((RubyArray)obj2).entry(i).funcall(getRuby().intern("==="), obj); if (eqq.isTrue()) { node = node.nd_body(); break; } } tag = tag.nd_next(); continue; } if (((RubyBoolean)eval(self, tag.nd_head()).funcall(getRuby().intern("==="), obj)).isTrue()) { node = node.nd_body(); break; } tag = tag.nd_next(); } node = node.nd_next(); } return getRuby().getNil(); case NODE_WHILE: while (eval(self, node.nd_cond()).isTrue()) { while (true) { try { eval(self, node.nd_body()); break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { break; } catch (BreakException bExcptn) { return getRuby().getNil(); } } } return getRuby().getNil(); case NODE_UNTIL: while (eval(self, node.nd_cond()).isFalse()) { while (true) { try { eval(self, node.nd_body()); break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { break; } catch (BreakException bExcptn) { return getRuby().getNil(); } } } return getRuby().getNil(); case NODE_BLOCK_PASS: //return block_pass(node); return null; case NODE_ITER: case NODE_FOR: rubyBlock.push(node.nd_var(), node.nd_body(), self); rubyIter.push(Iter.ITER_PRE); while (true) { try { if (node.nd_type() == NODE_ITER) { result = eval(self, node.nd_iter()); } else { // String file = // int line = rubyBlock.flags &= ~RubyBlock.BLOCK_D_SCOPE; RubyBlock tmpBlock = beginCallargs(); RubyObject recv = eval(self, node.nd_iter()); endCallArgs(tmpBlock); // = file; // = line; result = recv.getRubyClass().call(recv, ruby.intern("each"), null, 0); } break; } catch (RetryException rExcptn) { } catch (ReturnException rExcptn) { result = rExcptn.getReturnValue(); break; } catch (BreakException bExcptn) { result = ruby.getNil(); break; } } rubyIter.pop(); rubyBlock.pop(); return result; case NODE_BREAK: throw new BreakException(); case NODE_NEXT: throw new NextException(); case NODE_REDO: throw new RedoException(); case NODE_RETRY: throw new RetryException(); case NODE_RESTARGS: result = eval(self, node.nd_head()); if (!(result instanceof RubyArray)) { result = obj = RubyArray.m_newArray(getRuby(), result); } return result; case NODE_YIELD: if (node.nd_stts() != null) { result = eval(self, node.nd_stts()); if (node.nd_stts().nd_type() == NODE_RESTARGS && ((RubyArray)result).length() == 1) { result = ((RubyArray)result).entry(0); } } else { result = ruby.getNil(); } return yield0(result, null, null, false); case NODE_RESCUE:/* retry_entry: { volatile VALUE e_info = ruby_errinfo; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, node->nd_head); } POP_TAG(); if (state == TAG_RAISE) { NODE * volatile resq = node->nd_resq; ruby_sourceline = nd_line(node); while (resq) { if (handle_rescue(self, resq)) { state = 0; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, resq->nd_body); } POP_TAG(); if (state == TAG_RETRY) { state = 0; ruby_errinfo = Qnil; goto retry_entry; } if (state != TAG_RAISE) { ruby_errinfo = e_info; } break; } resq = resq->nd_head; /* next rescue */ /** } * } * else if (node->nd_else) { /* else clause given *//* if (!state) { /* no exception raised *//* result = rb_eval(self, node->nd_else); } } if (state) JUMP_TAG(state); } break;*/ case NODE_ENSURE:/* PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = eval(node.nd_head()); } POP_TAG(); if (node.nd_ensr()) { VALUE retval = prot_tag->retval; /* save retval *//* VALUE errinfo = ruby_errinfo; rb_eval(self, node->nd_ensr); return_value(retval); ruby_errinfo = errinfo; } if (state) JUMP_TAG(state); break;*/ case NODE_AND: cond = (RubyBoolean)eval(self, node.nd_1st()); if (cond.isFalse()) { return cond; } node = node.nd_2nd(); break; case NODE_OR: cond = (RubyBoolean)eval(self, node.nd_1st()); if (cond.isTrue()) { return cond; } node = node.nd_2nd(); break; case NODE_NOT: return RubyBoolean.m_newBoolean(getRuby(), eval(self, node.nd_1st()).isFalse()); case NODE_DOT2: case NODE_DOT3: result = RubyRange.m_newRange(getRuby(), eval(self, node.nd_beg()), eval(self, node.nd_end()), node.nd_type() == NODE_DOT3); if (node.nd_state() != 0) { return result; } if (node.nd_beg().nd_type() == NODE_LIT && (node.nd_beg().nd_lit() instanceof RubyFixnum) && node.nd_end().nd_type() == NODE_LIT && (node.nd_end().nd_lit() instanceof RubyFixnum)) { node.nd_set_type(NODE_LIT); node.nd_lit(result); } else { node.nd_state(1L); } return result; case NODE_FLIP2: /* like AWK */ /*if (ruby_scope->local_vars == 0) { rb_bug("unexpected local variable"); }*/ if (ruby.rubyScope.getLocalVars(node.nd_cnt()).isFalse()) { if (eval(self, node.nd_beg()).isTrue()) { ruby.rubyScope.setLocalVars(node.nd_cnt(), eval(self, node.nd_end()).isTrue() ? ruby.getFalse() : ruby.getTrue()); result = ruby.getTrue(); } else { result = ruby.getFalse(); } } else { if (eval(self, node.nd_end()).isTrue()) { ruby.rubyScope.setLocalVars(node.nd_cnt(), ruby.getFalse()); } result = ruby.getTrue(); } return result; case NODE_FLIP3: /* like SED */ /*if (ruby_scope->local_vars == 0) { rb_bug("unexpected local variable"); }*/ if (ruby.rubyScope.getLocalVars(node.nd_cnt()).isFalse()) { result = eval(self, node.nd_beg()).isTrue() ? ruby.getFalse() : ruby.getTrue(); ruby.rubyScope.setLocalVars(node.nd_cnt(), result); } else { if (eval(self, node.nd_end()).isTrue()) { ruby.rubyScope.setLocalVars(node.nd_cnt(), ruby.getFalse()); } result = ruby.getTrue(); } return result; case NODE_RETURN: if (node.nd_stts() != null) { result = eval(self, node.nd_stts()); } else { result = ruby.getNil(); } throw new ReturnException(result); case NODE_ARGSCAT: return ((RubyArray)eval(self, node.nd_head())).m_concat(eval(self, node.nd_body())); case NODE_ARGSPUSH: return ((RubyArray)eval(self, node.nd_head()).m_dup()).push(eval(self, node.nd_body())); case NODE_CALL: // TMP_PROTECT; RubyBlock tmpBlock = beginCallargs(); RubyObject recv = eval(self, node.nd_recv()); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); return recv.getRubyClass().call(recv, (RubyId)node.nd_mid(), args, 0); case NODE_FCALL: // TMP_PROTECT; tmpBlock = beginCallargs(); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); return self.getRubyClass().call(self, (RubyId)node.nd_mid(), args, 1); case NODE_VCALL: return self.getRubyClass().call(self, (RubyId)node.nd_mid(), null, 2); case NODE_SUPER: case NODE_ZSUPER: // TMP_PROTECT; if (rubyFrame.getLastClass() == null) { throw new RubyNameException("superclass method '" + rubyFrame.getLastFunc().toName() + "' disabled"); } if (node.nd_type() == NODE_ZSUPER) { List argsList = rubyFrame.getArgs(); args = (RubyObject[])argsList.toArray(new RubyObject[argsList.size()]); } else { tmpBlock = beginCallargs(); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); } rubyIter.push(rubyIter.getIter() != Iter.ITER_NOT ? Iter.ITER_PRE : Iter.ITER_NOT); result = rubyFrame.getLastClass().getSuperClass().call(rubyFrame.getSelf(), rubyFrame.getLastFunc(), args, 3); rubyIter.pop(); return result; case NODE_SCOPE: NODE saved_cref = null; Frame frame = rubyFrame; frame.setTmp(rubyFrame); rubyFrame = frame; ruby.rubyScope.push(); if (node.nd_rval() != null) { saved_cref = ruby_cref; ruby_cref = (NODE)node.nd_rval(); rubyFrame.setCbase(node.nd_rval()); } if (node.nd_tbl() != null) { List tmp = Collections.nCopies(node.nd_tbl()[0].intValue() + 1, ruby.getNil()); ShiftableList vars = new ShiftableList(new ArrayList(tmp)); vars.set(0, (VALUE)node); vars.shift(1); getRuby().rubyScope.setLocalVars(vars); getRuby().rubyScope.setLocalTbl(node.nd_tbl()); } else { getRuby().rubyScope.setLocalVars(null); getRuby().rubyScope.setLocalTbl(null); } result = eval(self, node.nd_next()); ruby.rubyScope.pop(); rubyFrame = frame.getTmp(); if (saved_cref != null) { ruby_cref = saved_cref; } return result; case NODE_OP_ASGN1: // TMP_PROTECT; recv = eval(self, node.nd_recv()); NODE rval = node.nd_args().nd_head(); args = setupArgs(self, node.nd_args().nd_next()); ArrayList argsList = new ArrayList(Arrays.asList(args)); argsList.remove(args.length - 1); RubyBoolean val = (RubyBoolean)recv.funcall(getRuby().intern("[]"), (RubyObject[])argsList.toArray(new RubyObject[argsList.size()])); switch (node.nd_mid().intValue()) { case 0: /* OR */ if (val.isTrue()) { return val; } val = (RubyBoolean)eval(self, rval); break; case 1: /* AND */ if (val.isFalse()) { return val; } val = (RubyBoolean)eval(self, rval); break; default: val = (RubyBoolean)val.funcall((RubyId)node.nd_mid(), eval(self, rval)); } args[args.length - 1] = val; return recv.funcall(getRuby().intern("[]="), args); case NODE_OP_ASGN2: ID id = node.nd_next().nd_vid(); recv = eval(self, node.nd_recv()); val = (RubyBoolean)recv.funcall((RubyId)id, (RubyObject[])null); switch (node.nd_next().nd_mid().intValue()) { case 0: /* OR */ if (val.isTrue()) { return val; } val = (RubyBoolean)eval(self, node.nd_value()); break; case 1: /* AND */ if (val.isFalse()) { return val; } val = (RubyBoolean)eval(self, node.nd_value()); break; default: val = (RubyBoolean)val.funcall((RubyId)node.nd_mid(), eval(self, node.nd_value())); } // HACK +++ val = (RubyBoolean)recv.funcall((RubyId)node.nd_next().nd_aid(), val); // HACK --- return val; case NODE_OP_ASGN_AND: cond = (RubyBoolean)eval(self, node.nd_head()); if (cond.isFalse()) { return cond; } node = node.nd_value(); break; case NODE_OP_ASGN_OR: cond = (RubyBoolean)eval(self, node.nd_head()); if ((node.nd_aid() != null && !self.isInstanceVarDefined((RubyId)node.nd_aid())) || cond.isFalse()) { node = node.nd_value(); break; } return cond; case NODE_MASGN: return massign(self, node, eval(self, node.nd_value()), false); case NODE_LASGN: // if (ruby.ruby_scope.local_vars == null) { // rb_bug("unexpected local variable assignment"); // } result = eval(self, node.nd_value()); getRuby().rubyScope.setLocalVars(node.nd_cnt(), result); return result; case NODE_DASGN: result = eval(self, node.nd_value()); RubyVarmap.assign(ruby, (RubyId)node.nd_vid(), result); return result; case NODE_DASGN_CURR: result = eval(self, node.nd_value()); RubyVarmap.assignCurrent(ruby, (RubyId)node.nd_vid(), result); return result; case NODE_GASGN: result = eval(self, node.nd_value()); ((RubyGlobalEntry)node.nd_entry()).set(result); return result; case NODE_IASGN: result = eval(self, node.nd_value()); self.setInstanceVar((RubyId)node.nd_vid(), result); return result; case NODE_CDECL: if (ruby_class == null) { throw new RubyTypeException("no class/module to define constant"); } result = eval(self, node.nd_value()); ruby_class.setConstant((RubyId)node.nd_vid(), result); return result; case NODE_CVDECL: if (ruby_cbase == null) { throw new RubyTypeException("no class/module to define class variable"); } result = eval(self, node.nd_value()); if (ruby_cbase.isSingleton()) { ruby_cbase.getInstanceVar("__attached__").getClassVarSingleton().declareClassVar((RubyId)node.nd_vid(), result); return result; } ruby_cbase.declareClassVar((RubyId)node.nd_vid(), result); return result; case NODE_CVASGN: result = eval(self, node.nd_value()); self.getClassVarSingleton().setClassVar((RubyId)node.nd_vid(), result); return result; case NODE_LVAR: //if (getRuby().ruby_scope.local_vars == null) { // rb_bug("unexpected local variable"); // } return (RubyObject)getRuby().rubyScope.getLocalVars(node.nd_cnt()); case NODE_DVAR: return getDynamicVars().getRef((RubyId)node.nd_vid()); case NODE_GVAR: return ((RubyGlobalEntry)node.nd_entry()).get(); case NODE_IVAR: return self.getInstanceVar((RubyId)node.nd_vid()); case NODE_CONST: return getConstant((NODE)rubyFrame.getCbase(), (RubyId)node.nd_vid(), self); case NODE_CVAR: /* normal method */ if (ruby_cbase == null) { return self.getRubyClass().getClassVar((RubyId)node.nd_vid()); } if (!ruby_cbase.isSingleton()) { return ruby_cbase.getClassVar((RubyId)node.nd_vid()); } return ruby_cbase.getInstanceVar("__attached__").getClassVarSingleton().getClassVar((RubyId)node.nd_vid()); case NODE_CVAR2: /* singleton method */ return self.getClassVarSingleton().getClassVar((RubyId)node.nd_vid()); case NODE_BLOCK_ARG: if (ruby.rubyScope.getLocalVars() == null) { throw new RuntimeException("BUG: unexpected block argument"); } if (isBlockGiven()) { result = getRuby().getNil(); // Create Proc object ruby.rubyScope.setLocalVars(node.nd_cnt(), result); return result; } else { return getRuby().getNil(); } case NODE_COLON2: value = eval(self, node.nd_head()); if (value instanceof RubyModule) { return ((RubyModule)value).getConstant((RubyId)node.nd_mid()); } else { return value.funcall((RubyId)node.nd_mid()); } case NODE_COLON3: return getRuby().getObjectClass().getConstant((RubyId)node.nd_mid()); case NODE_NTH_REF: // return rom.rb_reg_nth_match(node.nd_nth(), MATCH_DATA); return null; case NODE_BACK_REF: /*switch ((char)node.nd_nth()) { case '&': return rom.rb_reg_last_match(MATCH_DATA); case '`': return rom.rb_reg_match_pre(MATCH_DATA); case '\'': return rom.rb_reg_match_post(MATCH_DATA); case '+': return rom.rb_reg_match_last(MATCH_DATA); default: rom.rb_bug("unexpected back-ref"); }*/ case NODE_HASH: RubyHash hash = RubyHash.m_newHash(ruby); NODE list = node.nd_head(); while(list != null) { RubyObject key = eval(self, list.nd_head()); list = list.nd_next(); if (list == null) { // HACK +++ throw new RubyArgumentException("odd number list for Hash"); // HACK --- } value = eval(self, list.nd_head()); hash.m_aset(key, value); list = list.nd_next(); } return hash; case NODE_ZARRAY: /* zero length list */ return RubyArray.m_newArray(getRuby()); case NODE_ARRAY: ArrayList ary = new ArrayList(node.nd_alen()); for (; node != null ; node = node.nd_next()) { ary.add(eval(self, node.nd_head())); } return RubyArray.m_newArray(getRuby(), ary); case NODE_STR: return ((RubyObject)node.nd_lit()).m_to_s(); case NODE_DSTR: case NODE_DXSTR: case NODE_DREGX: case NODE_DREGX_ONCE:/* NODE list = node.nd_next(); RubyString str = RubyString.m_newString(getRuby(), (RubyObject)node.nd_lit()); RubyString str2; while (list != null) { if (list.nd_head() != null) { switch (list.nd_head().nd_type()) { case NODE_STR: str2 = (RubyString)list.nd_head().nd_lit(); break; case NODE_EVSTR: result = ruby_errinfo; ruby_errinfo = Qnil; ruby_sourceline = nd_line(node); ruby_in_eval++; list.nd_head(compile(list.nd_head().nd_lit(), ruby_sourcefile,ruby_sourceline)); ruby_eval_tree = 0; ruby_in_eval--; if (ruby_nerrs > 0) { compile_error("string expansion"); } if (!NIL_P(result)) ruby_errinfo = result; /* fall through *//* default: str2 = (RubyString)rom.rb_obj_as_string(eval(list.nd_head())); break; } str.append(str2); str.infectObject(str2); } list = list.nd_next(); } switch (node.nd_type()) { case NODE_DREGX: return rom.rb_reg_new(str.getString(), str.getString().length(), node.nd_cflag()); case NODE_DREGX_ONCE: /* regexp expand once *//* VALUE result = rom.rb_reg_new(str.getString(), str.getString().length(), node.nd_cflag()); node.nd_set_type(NODE_LIT); node.nd_lit(result); return result; case NODE_DXSTR: return rom.rb_funcall(this, '`', 1, str); default: return str; }*/ return null; case NODE_XSTR: return self.funcall(getRuby().intern("`"), (RubyObject)node.nd_lit()); case NODE_LIT: return (RubyObject)node.nd_lit(); case NODE_ATTRSET: if (rubyFrame.getArgs().size() != 1) { throw new RubyArgumentException("wrong # of arguments(" + rubyFrame.getArgs().size() + "for 1)"); } return self.setInstanceVar((RubyId)node.nd_vid(), (RubyObject)rubyFrame.getArgs().get(0)); case NODE_DEFN: if (node.nd_defn() != null) { int noex; if (ruby_class == null) { throw new RubyTypeException("no class to add method"); } //if (ruby_class == getRuby().getObjectClass() && node.nd_mid() == init) { // rom.rb_warn("redefining Object#initialize may cause infinite loop"); //} //if (node.nd_mid() == __id__ || node.nd_mid() == __send__) { // rom.rb_warn("redefining `%s' may cause serious problem", ((RubyId)node.nd_mid()).toName()); //} // ruby_class.setFrozen(true); NODE body = ruby_class.searchMethod((RubyId)node.nd_mid()); RubyObject origin = ruby_class.getMethodOrigin((RubyId)node.nd_mid()); if (body != null){ // if (ruby_verbose.isTrue() && ruby_class == origin && body.nd_cnt() == 0) { // rom.rb_warning("discarding old %s", ((RubyId)node.nd_mid()).toName()); // } // if (node.nd_noex() != 0) { /* toplevel */ /* should upgrade to rb_warn() if no super was called inside? */ // rom.rb_warning("overriding global function `%s'", ((RubyId)node.nd_mid()).toName()); // } } if (isScope(SCOPE_PRIVATE) || node.nd_mid().equals(ruby.intern("initialize"))) { noex = NOEX_PRIVATE; } else if (isScope(SCOPE_PROTECTED)) { noex = NOEX_PROTECTED; } else if (ruby_class == getRuby().getObjectClass()) { noex = node.nd_noex(); } else { noex = NOEX_PUBLIC; } if (body != null && origin == ruby_class && (body.nd_noex() & NOEX_UNDEF) != 0) { noex |= NOEX_UNDEF; } NODE defn = node.nd_defn().copyNodeScope(ruby_cref); ruby_class.addMethod((RubyId)node.nd_mid(), defn, noex); // rb_clear_cache_by_id(node.nd_mid()); if (scope_vmode == SCOPE_MODFUNC) { ruby_class.getSingletonClass().addMethod((RubyId)node.nd_mid(), defn, NOEX_PUBLIC); ruby_class.funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } if (ruby_class.isSingleton()) { ruby_class.getInstanceVar("__attached__").funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } else { ruby_class.funcall(getRuby().intern("method_added"), ((RubyId)node.nd_mid()).toSymbol()); } } return getRuby().getNil(); case NODE_DEFS: if (node.nd_defn() != null) { recv = eval(self, node.nd_recv()); if (getRuby().getSecurityLevel() >= 4 && !recv.isTaint()) { throw new RubySecurityException("Insecure; can't define singleton method"); } /*if (FIXNUM_P(recv) || SYMBOL_P(recv)) { rb_raise(rb_eTypeError, "can't define singleton method \"%s\" for %s", rb_id2name(node.nd_mid()), rb_class2name(CLASS_OF(recv))); }*/ // not needed in jruby if (recv.isFrozen()) { throw new RubyFrozenException("object"); } rubyClass = recv.getSingletonClass(); NODE body = (NODE)rubyClass.getMethods().get((RubyId)node.nd_mid()); if (body != null) { if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("redefining method prohibited"); } /*if (RTEST(ruby_verbose)) { rb_warning("redefine %s", rb_id2name(node.nd_mid())); }*/ } NODE defn = node.nd_defn().copyNodeScope(ruby_cref); defn.nd_rval(ruby_cref); rubyClass.addMethod((RubyId)node.nd_mid(), defn, NOEX_PUBLIC | (body != null ? body.nd_noex() & NOEX_UNDEF : 0)); // rb_clear_cache_by_id(node.nd_mid()); recv.funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } return getRuby().getNil(); case NODE_UNDEF: if (ruby_class == null) { throw new RubyTypeException("no class to undef method"); } ruby_class.undef((RubyId)node.nd_mid()); return getRuby().getNil(); case NODE_ALIAS: if (ruby_class == null) { throw new RubyTypeException("no class to make alias"); } ruby_class.aliasMethod((RubyId)node.nd_new(), (RubyId)node.nd_old()); ruby_class.funcall(getRuby().intern("method_added"), ((RubyId)node.nd_mid()).toSymbol()); return getRuby().getNil(); case NODE_VALIAS: RubyGlobalEntry.getGlobalEntry((RubyId)node.nd_old()).alias((RubyId)node.nd_new()); return getRuby().getNil(); case NODE_CLASS: RubyModule superClass; if (ruby_class == null) { throw new RubyTypeException("no outer class/module"); } if (node.nd_super() != null) { superClass = getSuperClass(self, node.nd_super()); } else { superClass = null; } rubyClass = null; // if ((ruby_class == getRuby().getObjectClass()) && rb_autoload_defined(node.nd_cname())) { // rb_autoload_load(node.nd_cname()); // } if (ruby_class.isConstantDefined((RubyId)node.nd_cname())) { rubyClass = (RubyClass)ruby_class.getConstant((RubyId)node.nd_cname()); } if (rubyClass != null) { if (!rubyClass.isClass()) { throw new RubyTypeException(((RubyId)node.nd_cname()).toName() + " is not a class"); } if (superClass != null) { RubyModule tmp = rubyClass.getSuperClass(); if (tmp.isSingleton()) { tmp = tmp.getSuperClass(); } while (tmp.isIncluded()) { tmp = tmp.getSuperClass(); } if (tmp != superClass) { superClass = tmp; //goto override_class; if (superClass == null) { superClass = getRuby().getObjectClass(); } rubyClass = getRuby().defineClassId((RubyId)node.nd_cname(), (RubyClass)superClass); ruby_class.setConstant((RubyId)node.nd_cname(), rubyClass); rubyClass.setClassPath((RubyClass)ruby_class, ((RubyId)node.nd_cname()).toName()); // end goto } } if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("extending class prohibited"); } // rb_clear_cache(); } else { //override_class: if (superClass == null) { superClass = getRuby().getObjectClass(); } rubyClass = getRuby().defineClassId((RubyId)node.nd_cname(), (RubyClass)superClass); ruby_class.setConstant((RubyId)node.nd_cname(), rubyClass); rubyClass.setClassPath((RubyClass)ruby_class, ((RubyId)node.nd_cname()).toName()); } if (ruby_wrapper != null) { rubyClass.getSingletonClass().includeModule(ruby_wrapper); rubyClass.includeModule(ruby_wrapper); } return setupModule(rubyClass, node.nd_body()); case NODE_MODULE: if (ruby_class == null) { throw new RubyTypeException("no outer class/module"); } RubyModule module = null; if ((ruby_class == getRuby().getObjectClass()) && getRuby().isAutoloadDefined((RubyId)node.nd_cname())) { // getRuby().rb_autoload_load(node.nd_cname()); } if (ruby_class.isConstantDefined((RubyId)node.nd_cname())) { module = (RubyModule)ruby_class.getConstant((RubyId)node.nd_cname()); } if (module != null) { if (!(module instanceof RubyModule)) { throw new RubyTypeException(((RubyId)node.nd_cname()).toName() + " is not a module"); } if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("extending module prohibited"); } } else { module = getRuby().defineModuleId((RubyId)node.nd_cname()); ruby_class.setConstant((RubyId)node.nd_cname(), module); module.setClassPath(ruby_class, ((RubyId)node.nd_cname()).toName()); } if (ruby_wrapper != null) { module.getSingletonClass().includeModule(ruby_wrapper); module.includeModule(ruby_wrapper); } return setupModule(module, node.nd_body()); case NODE_SCLASS: rubyClass = (RubyClass)eval(self, node.nd_recv()); if (rubyClass.isSpecialConst()) { throw new RubyTypeException("no virtual class for " + rubyClass.getRubyClass().toName()); } if (getRuby().getSecurityLevel() >= 4 && !rubyClass.isTaint()) { throw new RubySecurityException("Insecure: can't extend object"); } if (rubyClass.getRubyClass().isSingleton()) { // rb_clear_cache(); } rubyClass = rubyClass.getSingletonClass(); if (ruby_wrapper != null) { rubyClass.getSingletonClass().includeModule(ruby_wrapper); rubyClass.includeModule(ruby_wrapper); } return setupModule(rubyClass, node.nd_body()); case NODE_DEFINED: // String buf; // String desc = is_defined(self, node.nd_head(), buf); // // if (desc) { // result = rb_str_new2(desc); // } else { // result = Qnil; // } case NODE_NEWLINE: // ruby_sourcefile = node.nd_file; // ruby_sourceline = node.nd_nth(); // if (trace_func) { // call_trace_func("line", ruby_sourcefile, ruby_sourceline, self, // ruby_frame.last_func(), // ruby_frame.last_class()); // } node = node.nd_next(); break; default: // rom.rb_bug("unknown node type %d", nd_type(node)); } } }
public RubyObject eval(RubyObject self, NODE n) { NODE node = n; RubyBoolean cond = null; RubyObject[] args = null; RubyObject value = null; RubyObject result = null; RubyModule rubyClass = null; // int state; // RubyOriginalMethods rom = getRuby().getOriginalMethods(); while (true) { if (node == null) { return getRuby().getNil(); } switch (node.nd_type()) { case NODE_BLOCK: while (node.nd_next() != null) { eval(self, node.nd_head()); node = node.nd_next(); } node = node.nd_head(); break; case NODE_POSTEXE: // rb_f_END(); node.nd_set_type(NODE_NIL); /* exec just once */ return getRuby().getNil(); /* begin .. end without clauses */ case NODE_BEGIN: node = node.nd_body(); break; /* nodes for speed-up(default match) */ case NODE_MATCH: //return rom.rb_reg_match2(node.nd_head().nd_lit()); return getRuby().getNil(); /* nodes for speed-up(literal match) */ case NODE_MATCH2: //return rom.rb_reg_match(eval(node.nd_recv()), eval(node.nd_value())); return getRuby().getNil(); /* nodes for speed-up(literal match) */ case NODE_MATCH3: //VALUE r = eval(node.nd_recv()); //VALUE l = eval(node.nd_value()); //if (r instanceof RubyString) { // return rom.rb_reg_match(l, r); //} else { // return rom.rb_funcall(r, match, 1, l); //} return getRuby().getNil(); /* node for speed-up(top-level loop for -n/-p) */ case NODE_OPT_N: while (true) { try { // while (!rb_gets().isNil() false) { // HACK +++ if (true) { // HACK --- try { eval(self, node.nd_body()); } catch (RedoException rExcptn) { } } break; } catch (NextException nExcptn) { } catch (BreakException bExcptn) { break; } } return getRuby().getNil(); case NODE_SELF: return self; case NODE_NIL: return getRuby().getNil(); case NODE_TRUE: return getRuby().getTrue(); case NODE_FALSE: return getRuby().getFalse(); case NODE_IF: // ruby_sourceline = node.nd_line(); cond = (RubyBoolean)eval(self, node.nd_cond()); if (cond.isTrue()) { node = node.nd_body(); } else { node = node.nd_else(); } break; case NODE_WHEN: while (node != null) { NODE tag; if (node.nd_type() != NODE_WHEN) { break; } tag = node.nd_head(); while (tag != null) {/* if (trace_func) { call_trace_func("line", tag->nd_file, nd_line(tag), self, ruby_frame->last_func, ruby_frame->last_class); }*/ // ruby_sourcefile = tag.nd_file; // ruby_sourceline = tag.nd_line(); if (tag.nd_head().nd_type() == NODE_WHEN) { RubyObject obj = eval(self, tag.nd_head().nd_head()); if (!(obj instanceof RubyArray)) { obj = RubyArray.m_newArray(getRuby(), obj); } for (int i = 0; i < ((RubyArray)obj).length(); i++) { if (((RubyBoolean)((RubyArray)obj).entry(i)).isTrue()) { node = node.nd_body(); break; } } tag = tag.nd_next(); continue; } if (((RubyBoolean)eval(self, tag.nd_head())).isTrue()) { node = node.nd_body(); break; } tag = tag.nd_next(); } node = node.nd_next(); } return getRuby().getNil(); case NODE_CASE: RubyObject obj = eval(self, node.nd_head()); node = node.nd_body(); while (node != null) { NODE tag; if (node.nd_type() != NODE_WHEN) { break; } tag = node.nd_head(); while (tag != null) {/* if (trace_func) { call_trace_func("line", tag->nd_file, nd_line(tag), self, ruby_frame->last_func, ruby_frame->last_class); } ruby_sourcefile = tag->nd_file; ruby_sourceline = nd_line(tag);*/ if (tag.nd_head().nd_type() == NODE_WHEN) { RubyObject obj2 = eval(self, tag.nd_head().nd_head()); if (!(obj2 instanceof RubyArray)) { obj2 = RubyArray.m_newArray(getRuby(), obj2); } for (int i = 0; i < ((RubyArray)obj).length(); i++) { RubyBoolean eqq = (RubyBoolean)((RubyArray)obj2).entry(i).funcall(getRuby().intern("==="), obj); if (eqq.isTrue()) { node = node.nd_body(); break; } } tag = tag.nd_next(); continue; } if (((RubyBoolean)eval(self, tag.nd_head()).funcall(getRuby().intern("==="), obj)).isTrue()) { node = node.nd_body(); break; } tag = tag.nd_next(); } node = node.nd_next(); } return getRuby().getNil(); case NODE_WHILE: while (eval(self, node.nd_cond()).isTrue()) { while (true) { try { eval(self, node.nd_body()); break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { break; } catch (BreakException bExcptn) { return getRuby().getNil(); } } } return getRuby().getNil(); case NODE_UNTIL: while (eval(self, node.nd_cond()).isFalse()) { while (true) { try { eval(self, node.nd_body()); break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { break; } catch (BreakException bExcptn) { return getRuby().getNil(); } } } return getRuby().getNil(); case NODE_BLOCK_PASS: //return block_pass(node); return null; case NODE_ITER: case NODE_FOR: rubyBlock.push(node.nd_var(), node.nd_body(), self); rubyIter.push(Iter.ITER_PRE); while (true) { try { if (node.nd_type() == NODE_ITER) { result = eval(self, node.nd_iter()); } else { // String file = // int line = rubyBlock.flags &= ~RubyBlock.BLOCK_D_SCOPE; RubyBlock tmpBlock = beginCallargs(); RubyObject recv = eval(self, node.nd_iter()); endCallArgs(tmpBlock); // = file; // = line; result = recv.getRubyClass().call(recv, ruby.intern("each"), null, 0); } break; } catch (RetryException rExcptn) { } catch (ReturnException rExcptn) { result = rExcptn.getReturnValue(); break; } catch (BreakException bExcptn) { result = ruby.getNil(); break; } } rubyIter.pop(); rubyBlock.pop(); return result; case NODE_BREAK: throw new BreakException(); case NODE_NEXT: throw new NextException(); case NODE_REDO: throw new RedoException(); case NODE_RETRY: throw new RetryException(); case NODE_RESTARGS: result = eval(self, node.nd_head()); if (!(result instanceof RubyArray)) { result = obj = RubyArray.m_newArray(getRuby(), result); } return result; case NODE_YIELD: if (node.nd_stts() != null) { result = eval(self, node.nd_stts()); if (node.nd_stts().nd_type() == NODE_RESTARGS && ((RubyArray)result).length() == 1) { result = ((RubyArray)result).entry(0); } } else { result = ruby.getNil(); } return yield0(result, null, null, false); case NODE_RESCUE:/* retry_entry: { volatile VALUE e_info = ruby_errinfo; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, node->nd_head); } POP_TAG(); if (state == TAG_RAISE) { NODE * volatile resq = node->nd_resq; ruby_sourceline = nd_line(node); while (resq) { if (handle_rescue(self, resq)) { state = 0; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, resq->nd_body); } POP_TAG(); if (state == TAG_RETRY) { state = 0; ruby_errinfo = Qnil; goto retry_entry; } if (state != TAG_RAISE) { ruby_errinfo = e_info; } break; } resq = resq->nd_head; /* next rescue */ /** } * } * else if (node->nd_else) { /* else clause given *//* if (!state) { /* no exception raised *//* result = rb_eval(self, node->nd_else); } } if (state) JUMP_TAG(state); } break;*/ case NODE_ENSURE:/* PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = eval(node.nd_head()); } POP_TAG(); if (node.nd_ensr()) { VALUE retval = prot_tag->retval; /* save retval *//* VALUE errinfo = ruby_errinfo; rb_eval(self, node->nd_ensr); return_value(retval); ruby_errinfo = errinfo; } if (state) JUMP_TAG(state); break;*/ case NODE_AND: cond = (RubyBoolean)eval(self, node.nd_1st()); if (cond.isFalse()) { return cond; } node = node.nd_2nd(); break; case NODE_OR: cond = (RubyBoolean)eval(self, node.nd_1st()); if (cond.isTrue()) { return cond; } node = node.nd_2nd(); break; case NODE_NOT: return RubyBoolean.m_newBoolean(getRuby(), eval(self, node.nd_1st()).isFalse()); case NODE_DOT2: case NODE_DOT3: result = RubyRange.m_newRange(getRuby(), eval(self, node.nd_beg()), eval(self, node.nd_end()), node.nd_type() == NODE_DOT3); if (node.nd_state() != 0) { return result; } if (node.nd_beg().nd_type() == NODE_LIT && (node.nd_beg().nd_lit() instanceof RubyFixnum) && node.nd_end().nd_type() == NODE_LIT && (node.nd_end().nd_lit() instanceof RubyFixnum)) { node.nd_set_type(NODE_LIT); node.nd_lit(result); } else { node.nd_state(1L); } return result; case NODE_FLIP2: /* like AWK */ /*if (ruby_scope->local_vars == 0) { rb_bug("unexpected local variable"); }*/ if (ruby.rubyScope.getLocalVars(node.nd_cnt()).isFalse()) { if (eval(self, node.nd_beg()).isTrue()) { ruby.rubyScope.setLocalVars(node.nd_cnt(), eval(self, node.nd_end()).isTrue() ? ruby.getFalse() : ruby.getTrue()); result = ruby.getTrue(); } else { result = ruby.getFalse(); } } else { if (eval(self, node.nd_end()).isTrue()) { ruby.rubyScope.setLocalVars(node.nd_cnt(), ruby.getFalse()); } result = ruby.getTrue(); } return result; case NODE_FLIP3: /* like SED */ /*if (ruby_scope->local_vars == 0) { rb_bug("unexpected local variable"); }*/ if (ruby.rubyScope.getLocalVars(node.nd_cnt()).isFalse()) { result = eval(self, node.nd_beg()).isTrue() ? ruby.getFalse() : ruby.getTrue(); ruby.rubyScope.setLocalVars(node.nd_cnt(), result); } else { if (eval(self, node.nd_end()).isTrue()) { ruby.rubyScope.setLocalVars(node.nd_cnt(), ruby.getFalse()); } result = ruby.getTrue(); } return result; case NODE_RETURN: if (node.nd_stts() != null) { result = eval(self, node.nd_stts()); } else { result = ruby.getNil(); } throw new ReturnException(result); case NODE_ARGSCAT: return ((RubyArray)eval(self, node.nd_head())).m_concat(eval(self, node.nd_body())); case NODE_ARGSPUSH: return ((RubyArray)eval(self, node.nd_head()).m_dup()).push(eval(self, node.nd_body())); case NODE_CALL: // TMP_PROTECT; RubyBlock tmpBlock = beginCallargs(); RubyObject recv = eval(self, node.nd_recv()); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); return recv.getRubyClass().call(recv, (RubyId)node.nd_mid(), args, 0); case NODE_FCALL: // TMP_PROTECT; tmpBlock = beginCallargs(); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); return self.getRubyClass().call(self, (RubyId)node.nd_mid(), args, 1); case NODE_VCALL: return self.getRubyClass().call(self, (RubyId)node.nd_mid(), null, 2); case NODE_SUPER: case NODE_ZSUPER: // TMP_PROTECT; if (rubyFrame.getLastClass() == null) { throw new RubyNameException("superclass method '" + rubyFrame.getLastFunc().toName() + "' disabled"); } if (node.nd_type() == NODE_ZSUPER) { List argsList = getRubyFrame().getArgs(); args = (RubyObject[])argsList.toArray(new RubyObject[argsList.size()]); } else { tmpBlock = beginCallargs(); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); } rubyIter.push(rubyIter.getIter() != Iter.ITER_NOT ? Iter.ITER_PRE : Iter.ITER_NOT); result = rubyFrame.getLastClass().getSuperClass().call(rubyFrame.getSelf(), rubyFrame.getLastFunc(), args, 3); rubyIter.pop(); return result; case NODE_SCOPE: NODE saved_cref = null; Frame frame = rubyFrame; frame.setTmp(rubyFrame); rubyFrame = frame; ruby.rubyScope.push(); if (node.nd_rval() != null) { saved_cref = ruby_cref; ruby_cref = (NODE)node.nd_rval(); rubyFrame.setCbase(node.nd_rval()); } if (node.nd_tbl() != null) { List tmp = Collections.nCopies(node.nd_tbl()[0].intValue() + 1, ruby.getNil()); ShiftableList vars = new ShiftableList(new ArrayList(tmp)); vars.set(0, (VALUE)node); vars.shift(1); getRuby().rubyScope.setLocalVars(vars); getRuby().rubyScope.setLocalTbl(node.nd_tbl()); } else { getRuby().rubyScope.setLocalVars(null); getRuby().rubyScope.setLocalTbl(null); } result = eval(self, node.nd_next()); ruby.rubyScope.pop(); rubyFrame = frame.getTmp(); if (saved_cref != null) { ruby_cref = saved_cref; } return result; case NODE_OP_ASGN1: // TMP_PROTECT; recv = eval(self, node.nd_recv()); NODE rval = node.nd_args().nd_head(); args = setupArgs(self, node.nd_args().nd_next()); ArrayList argsList = new ArrayList(Arrays.asList(args)); argsList.remove(args.length - 1); RubyBoolean val = (RubyBoolean)recv.funcall(getRuby().intern("[]"), (RubyObject[])argsList.toArray(new RubyObject[argsList.size()])); switch (node.nd_mid().intValue()) { case 0: /* OR */ if (val.isTrue()) { return val; } val = (RubyBoolean)eval(self, rval); break; case 1: /* AND */ if (val.isFalse()) { return val; } val = (RubyBoolean)eval(self, rval); break; default: val = (RubyBoolean)val.funcall((RubyId)node.nd_mid(), eval(self, rval)); } args[args.length - 1] = val; return recv.funcall(getRuby().intern("[]="), args); case NODE_OP_ASGN2: ID id = node.nd_next().nd_vid(); recv = eval(self, node.nd_recv()); val = (RubyBoolean)recv.funcall((RubyId)id, (RubyObject[])null); switch (node.nd_next().nd_mid().intValue()) { case 0: /* OR */ if (val.isTrue()) { return val; } val = (RubyBoolean)eval(self, node.nd_value()); break; case 1: /* AND */ if (val.isFalse()) { return val; } val = (RubyBoolean)eval(self, node.nd_value()); break; default: val = (RubyBoolean)val.funcall((RubyId)node.nd_mid(), eval(self, node.nd_value())); } // HACK +++ val = (RubyBoolean)recv.funcall((RubyId)node.nd_next().nd_aid(), val); // HACK --- return val; case NODE_OP_ASGN_AND: cond = (RubyBoolean)eval(self, node.nd_head()); if (cond.isFalse()) { return cond; } node = node.nd_value(); break; case NODE_OP_ASGN_OR: cond = (RubyBoolean)eval(self, node.nd_head()); if ((node.nd_aid() != null && !self.isInstanceVarDefined((RubyId)node.nd_aid())) || cond.isFalse()) { node = node.nd_value(); break; } return cond; case NODE_MASGN: return massign(self, node, eval(self, node.nd_value()), false); case NODE_LASGN: // if (ruby.ruby_scope.local_vars == null) { // rb_bug("unexpected local variable assignment"); // } result = eval(self, node.nd_value()); getRuby().rubyScope.setLocalVars(node.nd_cnt(), result); return result; case NODE_DASGN: result = eval(self, node.nd_value()); RubyVarmap.assign(ruby, (RubyId)node.nd_vid(), result); return result; case NODE_DASGN_CURR: result = eval(self, node.nd_value()); RubyVarmap.assignCurrent(ruby, (RubyId)node.nd_vid(), result); return result; case NODE_GASGN: result = eval(self, node.nd_value()); ((RubyGlobalEntry)node.nd_entry()).set(result); return result; case NODE_IASGN: result = eval(self, node.nd_value()); self.setInstanceVar((RubyId)node.nd_vid(), result); return result; case NODE_CDECL: if (ruby_class == null) { throw new RubyTypeException("no class/module to define constant"); } result = eval(self, node.nd_value()); ruby_class.setConstant((RubyId)node.nd_vid(), result); return result; case NODE_CVDECL: if (ruby_cbase == null) { throw new RubyTypeException("no class/module to define class variable"); } result = eval(self, node.nd_value()); if (ruby_cbase.isSingleton()) { ruby_cbase.getInstanceVar("__attached__").getClassVarSingleton().declareClassVar((RubyId)node.nd_vid(), result); return result; } ruby_cbase.declareClassVar((RubyId)node.nd_vid(), result); return result; case NODE_CVASGN: result = eval(self, node.nd_value()); self.getClassVarSingleton().setClassVar((RubyId)node.nd_vid(), result); return result; case NODE_LVAR: //if (getRuby().ruby_scope.local_vars == null) { // rb_bug("unexpected local variable"); // } return (RubyObject)getRuby().rubyScope.getLocalVars(node.nd_cnt()); case NODE_DVAR: return getDynamicVars().getRef((RubyId)node.nd_vid()); case NODE_GVAR: return ((RubyGlobalEntry)node.nd_entry()).get(); case NODE_IVAR: return self.getInstanceVar((RubyId)node.nd_vid()); case NODE_CONST: return getConstant((NODE)rubyFrame.getCbase(), (RubyId)node.nd_vid(), self); case NODE_CVAR: /* normal method */ if (ruby_cbase == null) { return self.getRubyClass().getClassVar((RubyId)node.nd_vid()); } if (!ruby_cbase.isSingleton()) { return ruby_cbase.getClassVar((RubyId)node.nd_vid()); } return ruby_cbase.getInstanceVar("__attached__").getClassVarSingleton().getClassVar((RubyId)node.nd_vid()); case NODE_CVAR2: /* singleton method */ return self.getClassVarSingleton().getClassVar((RubyId)node.nd_vid()); case NODE_BLOCK_ARG: if (ruby.rubyScope.getLocalVars() == null) { throw new RuntimeException("BUG: unexpected block argument"); } if (isBlockGiven()) { result = getRuby().getNil(); // Create Proc object ruby.rubyScope.setLocalVars(node.nd_cnt(), result); return result; } else { return getRuby().getNil(); } case NODE_COLON2: value = eval(self, node.nd_head()); if (value instanceof RubyModule) { return ((RubyModule)value).getConstant((RubyId)node.nd_mid()); } else { return value.funcall((RubyId)node.nd_mid()); } case NODE_COLON3: return getRuby().getObjectClass().getConstant((RubyId)node.nd_mid()); case NODE_NTH_REF: // return rom.rb_reg_nth_match(node.nd_nth(), MATCH_DATA); return null; case NODE_BACK_REF: /*switch ((char)node.nd_nth()) { case '&': return rom.rb_reg_last_match(MATCH_DATA); case '`': return rom.rb_reg_match_pre(MATCH_DATA); case '\'': return rom.rb_reg_match_post(MATCH_DATA); case '+': return rom.rb_reg_match_last(MATCH_DATA); default: rom.rb_bug("unexpected back-ref"); }*/ case NODE_HASH: RubyHash hash = RubyHash.m_newHash(ruby); NODE list = node.nd_head(); while(list != null) { RubyObject key = eval(self, list.nd_head()); list = list.nd_next(); if (list == null) { // HACK +++ throw new RubyArgumentException("odd number list for Hash"); // HACK --- } value = eval(self, list.nd_head()); hash.m_aset(key, value); list = list.nd_next(); } return hash; case NODE_ZARRAY: /* zero length list */ return RubyArray.m_newArray(getRuby()); case NODE_ARRAY: ArrayList ary = new ArrayList(node.nd_alen()); for (; node != null ; node = node.nd_next()) { ary.add(eval(self, node.nd_head())); } return RubyArray.m_newArray(getRuby(), ary); case NODE_STR: return ((RubyObject)node.nd_lit()).m_to_s(); case NODE_DSTR: case NODE_DXSTR: case NODE_DREGX: case NODE_DREGX_ONCE:/* NODE list = node.nd_next(); RubyString str = RubyString.m_newString(getRuby(), (RubyObject)node.nd_lit()); RubyString str2; while (list != null) { if (list.nd_head() != null) { switch (list.nd_head().nd_type()) { case NODE_STR: str2 = (RubyString)list.nd_head().nd_lit(); break; case NODE_EVSTR: result = ruby_errinfo; ruby_errinfo = Qnil; ruby_sourceline = nd_line(node); ruby_in_eval++; list.nd_head(compile(list.nd_head().nd_lit(), ruby_sourcefile,ruby_sourceline)); ruby_eval_tree = 0; ruby_in_eval--; if (ruby_nerrs > 0) { compile_error("string expansion"); } if (!NIL_P(result)) ruby_errinfo = result; /* fall through *//* default: str2 = (RubyString)rom.rb_obj_as_string(eval(list.nd_head())); break; } str.append(str2); str.infectObject(str2); } list = list.nd_next(); } switch (node.nd_type()) { case NODE_DREGX: return rom.rb_reg_new(str.getString(), str.getString().length(), node.nd_cflag()); case NODE_DREGX_ONCE: /* regexp expand once *//* VALUE result = rom.rb_reg_new(str.getString(), str.getString().length(), node.nd_cflag()); node.nd_set_type(NODE_LIT); node.nd_lit(result); return result; case NODE_DXSTR: return rom.rb_funcall(this, '`', 1, str); default: return str; }*/ return null; case NODE_XSTR: return self.funcall(getRuby().intern("`"), (RubyObject)node.nd_lit()); case NODE_LIT: return (RubyObject)node.nd_lit(); case NODE_ATTRSET: if (rubyFrame.getArgs().size() != 1) { throw new RubyArgumentException("wrong # of arguments(" + rubyFrame.getArgs().size() + "for 1)"); } return self.setInstanceVar((RubyId)node.nd_vid(), (RubyObject)rubyFrame.getArgs().get(0)); case NODE_DEFN: if (node.nd_defn() != null) { int noex; if (ruby_class == null) { throw new RubyTypeException("no class to add method"); } //if (ruby_class == getRuby().getObjectClass() && node.nd_mid() == init) { // rom.rb_warn("redefining Object#initialize may cause infinite loop"); //} //if (node.nd_mid() == __id__ || node.nd_mid() == __send__) { // rom.rb_warn("redefining `%s' may cause serious problem", ((RubyId)node.nd_mid()).toName()); //} // ruby_class.setFrozen(true); NODE body = ruby_class.searchMethod((RubyId)node.nd_mid()); RubyObject origin = ruby_class.getMethodOrigin((RubyId)node.nd_mid()); if (body != null){ // if (ruby_verbose.isTrue() && ruby_class == origin && body.nd_cnt() == 0) { // rom.rb_warning("discarding old %s", ((RubyId)node.nd_mid()).toName()); // } // if (node.nd_noex() != 0) { /* toplevel */ /* should upgrade to rb_warn() if no super was called inside? */ // rom.rb_warning("overriding global function `%s'", ((RubyId)node.nd_mid()).toName()); // } } if (isScope(SCOPE_PRIVATE) || node.nd_mid().equals(ruby.intern("initialize"))) { noex = NOEX_PRIVATE; } else if (isScope(SCOPE_PROTECTED)) { noex = NOEX_PROTECTED; } else if (ruby_class == getRuby().getObjectClass()) { noex = node.nd_noex(); } else { noex = NOEX_PUBLIC; } if (body != null && origin == ruby_class && (body.nd_noex() & NOEX_UNDEF) != 0) { noex |= NOEX_UNDEF; } NODE defn = node.nd_defn().copyNodeScope(ruby_cref); ruby_class.addMethod((RubyId)node.nd_mid(), defn, noex); // rb_clear_cache_by_id(node.nd_mid()); if (scope_vmode == SCOPE_MODFUNC) { ruby_class.getSingletonClass().addMethod((RubyId)node.nd_mid(), defn, NOEX_PUBLIC); ruby_class.funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } if (ruby_class.isSingleton()) { ruby_class.getInstanceVar("__attached__").funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } else { ruby_class.funcall(getRuby().intern("method_added"), ((RubyId)node.nd_mid()).toSymbol()); } } return getRuby().getNil(); case NODE_DEFS: if (node.nd_defn() != null) { recv = eval(self, node.nd_recv()); if (getRuby().getSecurityLevel() >= 4 && !recv.isTaint()) { throw new RubySecurityException("Insecure; can't define singleton method"); } /*if (FIXNUM_P(recv) || SYMBOL_P(recv)) { rb_raise(rb_eTypeError, "can't define singleton method \"%s\" for %s", rb_id2name(node.nd_mid()), rb_class2name(CLASS_OF(recv))); }*/ // not needed in jruby if (recv.isFrozen()) { throw new RubyFrozenException("object"); } rubyClass = recv.getSingletonClass(); NODE body = (NODE)rubyClass.getMethods().get((RubyId)node.nd_mid()); if (body != null) { if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("redefining method prohibited"); } /*if (RTEST(ruby_verbose)) { rb_warning("redefine %s", rb_id2name(node.nd_mid())); }*/ } NODE defn = node.nd_defn().copyNodeScope(ruby_cref); defn.nd_rval(ruby_cref); rubyClass.addMethod((RubyId)node.nd_mid(), defn, NOEX_PUBLIC | (body != null ? body.nd_noex() & NOEX_UNDEF : 0)); // rb_clear_cache_by_id(node.nd_mid()); recv.funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } return getRuby().getNil(); case NODE_UNDEF: if (ruby_class == null) { throw new RubyTypeException("no class to undef method"); } ruby_class.undef((RubyId)node.nd_mid()); return getRuby().getNil(); case NODE_ALIAS: if (ruby_class == null) { throw new RubyTypeException("no class to make alias"); } ruby_class.aliasMethod((RubyId)node.nd_new(), (RubyId)node.nd_old()); ruby_class.funcall(getRuby().intern("method_added"), ((RubyId)node.nd_mid()).toSymbol()); return getRuby().getNil(); case NODE_VALIAS: RubyGlobalEntry.getGlobalEntry((RubyId)node.nd_old()).alias((RubyId)node.nd_new()); return getRuby().getNil(); case NODE_CLASS: RubyModule superClass; if (ruby_class == null) { throw new RubyTypeException("no outer class/module"); } if (node.nd_super() != null) { superClass = getSuperClass(self, node.nd_super()); } else { superClass = null; } rubyClass = null; // if ((ruby_class == getRuby().getObjectClass()) && rb_autoload_defined(node.nd_cname())) { // rb_autoload_load(node.nd_cname()); // } if (ruby_class.isConstantDefined((RubyId)node.nd_cname())) { rubyClass = (RubyClass)ruby_class.getConstant((RubyId)node.nd_cname()); } if (rubyClass != null) { if (!rubyClass.isClass()) { throw new RubyTypeException(((RubyId)node.nd_cname()).toName() + " is not a class"); } if (superClass != null) { RubyModule tmp = rubyClass.getSuperClass(); if (tmp.isSingleton()) { tmp = tmp.getSuperClass(); } while (tmp.isIncluded()) { tmp = tmp.getSuperClass(); } if (tmp != superClass) { superClass = tmp; //goto override_class; if (superClass == null) { superClass = getRuby().getObjectClass(); } rubyClass = getRuby().defineClassId((RubyId)node.nd_cname(), (RubyClass)superClass); ruby_class.setConstant((RubyId)node.nd_cname(), rubyClass); rubyClass.setClassPath((RubyClass)ruby_class, ((RubyId)node.nd_cname()).toName()); // end goto } } if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("extending class prohibited"); } // rb_clear_cache(); } else { //override_class: if (superClass == null) { superClass = getRuby().getObjectClass(); } rubyClass = getRuby().defineClassId((RubyId)node.nd_cname(), (RubyClass)superClass); ruby_class.setConstant((RubyId)node.nd_cname(), rubyClass); rubyClass.setClassPath((RubyClass)ruby_class, ((RubyId)node.nd_cname()).toName()); } if (ruby_wrapper != null) { rubyClass.getSingletonClass().includeModule(ruby_wrapper); rubyClass.includeModule(ruby_wrapper); } return setupModule(rubyClass, node.nd_body()); case NODE_MODULE: if (ruby_class == null) { throw new RubyTypeException("no outer class/module"); } RubyModule module = null; if ((ruby_class == getRuby().getObjectClass()) && getRuby().isAutoloadDefined((RubyId)node.nd_cname())) { // getRuby().rb_autoload_load(node.nd_cname()); } if (ruby_class.isConstantDefined((RubyId)node.nd_cname())) { module = (RubyModule)ruby_class.getConstant((RubyId)node.nd_cname()); } if (module != null) { if (!(module instanceof RubyModule)) { throw new RubyTypeException(((RubyId)node.nd_cname()).toName() + " is not a module"); } if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("extending module prohibited"); } } else { module = getRuby().defineModuleId((RubyId)node.nd_cname()); ruby_class.setConstant((RubyId)node.nd_cname(), module); module.setClassPath(ruby_class, ((RubyId)node.nd_cname()).toName()); } if (ruby_wrapper != null) { module.getSingletonClass().includeModule(ruby_wrapper); module.includeModule(ruby_wrapper); } return setupModule(module, node.nd_body()); case NODE_SCLASS: rubyClass = (RubyClass)eval(self, node.nd_recv()); if (rubyClass.isSpecialConst()) { throw new RubyTypeException("no virtual class for " + rubyClass.getRubyClass().toName()); } if (getRuby().getSecurityLevel() >= 4 && !rubyClass.isTaint()) { throw new RubySecurityException("Insecure: can't extend object"); } if (rubyClass.getRubyClass().isSingleton()) { // rb_clear_cache(); } rubyClass = rubyClass.getSingletonClass(); if (ruby_wrapper != null) { rubyClass.getSingletonClass().includeModule(ruby_wrapper); rubyClass.includeModule(ruby_wrapper); } return setupModule(rubyClass, node.nd_body()); case NODE_DEFINED: // String buf; // String desc = is_defined(self, node.nd_head(), buf); // // if (desc) { // result = rb_str_new2(desc); // } else { // result = Qnil; // } case NODE_NEWLINE: // ruby_sourcefile = node.nd_file; // ruby_sourceline = node.nd_nth(); // if (trace_func) { // call_trace_func("line", ruby_sourcefile, ruby_sourceline, self, // ruby_frame.last_func(), // ruby_frame.last_class()); // } node = node.nd_next(); break; default: // rom.rb_bug("unknown node type %d", nd_type(node)); } } }
3,238,699
public RubyObject eval(RubyObject self, NODE n) { NODE node = n; RubyBoolean cond = null; RubyObject[] args = null; RubyObject value = null; RubyObject result = null; RubyModule rubyClass = null; // int state; // RubyOriginalMethods rom = getRuby().getOriginalMethods(); while (true) { if (node == null) { return getRuby().getNil(); } switch (node.nd_type()) { case NODE_BLOCK: while (node.nd_next() != null) { eval(self, node.nd_head()); node = node.nd_next(); } node = node.nd_head(); break; case NODE_POSTEXE: // rb_f_END(); node.nd_set_type(NODE_NIL); /* exec just once */ return getRuby().getNil(); /* begin .. end without clauses */ case NODE_BEGIN: node = node.nd_body(); break; /* nodes for speed-up(default match) */ case NODE_MATCH: //return rom.rb_reg_match2(node.nd_head().nd_lit()); return getRuby().getNil(); /* nodes for speed-up(literal match) */ case NODE_MATCH2: //return rom.rb_reg_match(eval(node.nd_recv()), eval(node.nd_value())); return getRuby().getNil(); /* nodes for speed-up(literal match) */ case NODE_MATCH3: //VALUE r = eval(node.nd_recv()); //VALUE l = eval(node.nd_value()); //if (r instanceof RubyString) { // return rom.rb_reg_match(l, r); //} else { // return rom.rb_funcall(r, match, 1, l); //} return getRuby().getNil(); /* node for speed-up(top-level loop for -n/-p) */ case NODE_OPT_N: while (true) { try { // while (!rb_gets().isNil() false) { // HACK +++ if (true) { // HACK --- try { eval(self, node.nd_body()); } catch (RedoException rExcptn) { } } break; } catch (NextException nExcptn) { } catch (BreakException bExcptn) { break; } } return getRuby().getNil(); case NODE_SELF: return self; case NODE_NIL: return getRuby().getNil(); case NODE_TRUE: return getRuby().getTrue(); case NODE_FALSE: return getRuby().getFalse(); case NODE_IF: // ruby_sourceline = node.nd_line(); cond = (RubyBoolean)eval(self, node.nd_cond()); if (cond.isTrue()) { node = node.nd_body(); } else { node = node.nd_else(); } break; case NODE_WHEN: while (node != null) { NODE tag; if (node.nd_type() != NODE_WHEN) { break; } tag = node.nd_head(); while (tag != null) {/* if (trace_func) { call_trace_func("line", tag->nd_file, nd_line(tag), self, ruby_frame->last_func, ruby_frame->last_class); }*/ // ruby_sourcefile = tag.nd_file; // ruby_sourceline = tag.nd_line(); if (tag.nd_head().nd_type() == NODE_WHEN) { RubyObject obj = eval(self, tag.nd_head().nd_head()); if (!(obj instanceof RubyArray)) { obj = RubyArray.m_newArray(getRuby(), obj); } for (int i = 0; i < ((RubyArray)obj).length(); i++) { if (((RubyBoolean)((RubyArray)obj).entry(i)).isTrue()) { node = node.nd_body(); break; } } tag = tag.nd_next(); continue; } if (((RubyBoolean)eval(self, tag.nd_head())).isTrue()) { node = node.nd_body(); break; } tag = tag.nd_next(); } node = node.nd_next(); } return getRuby().getNil(); case NODE_CASE: RubyObject obj = eval(self, node.nd_head()); node = node.nd_body(); while (node != null) { NODE tag; if (node.nd_type() != NODE_WHEN) { break; } tag = node.nd_head(); while (tag != null) {/* if (trace_func) { call_trace_func("line", tag->nd_file, nd_line(tag), self, ruby_frame->last_func, ruby_frame->last_class); } ruby_sourcefile = tag->nd_file; ruby_sourceline = nd_line(tag);*/ if (tag.nd_head().nd_type() == NODE_WHEN) { RubyObject obj2 = eval(self, tag.nd_head().nd_head()); if (!(obj2 instanceof RubyArray)) { obj2 = RubyArray.m_newArray(getRuby(), obj2); } for (int i = 0; i < ((RubyArray)obj).length(); i++) { RubyBoolean eqq = (RubyBoolean)((RubyArray)obj2).entry(i).funcall(getRuby().intern("==="), obj); if (eqq.isTrue()) { node = node.nd_body(); break; } } tag = tag.nd_next(); continue; } if (((RubyBoolean)eval(self, tag.nd_head()).funcall(getRuby().intern("==="), obj)).isTrue()) { node = node.nd_body(); break; } tag = tag.nd_next(); } node = node.nd_next(); } return getRuby().getNil(); case NODE_WHILE: while (eval(self, node.nd_cond()).isTrue()) { while (true) { try { eval(self, node.nd_body()); break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { break; } catch (BreakException bExcptn) { return getRuby().getNil(); } } } return getRuby().getNil(); case NODE_UNTIL: while (eval(self, node.nd_cond()).isFalse()) { while (true) { try { eval(self, node.nd_body()); break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { break; } catch (BreakException bExcptn) { return getRuby().getNil(); } } } return getRuby().getNil(); case NODE_BLOCK_PASS: //return block_pass(node); return null; case NODE_ITER: case NODE_FOR: rubyBlock.push(node.nd_var(), node.nd_body(), self); rubyIter.push(Iter.ITER_PRE); while (true) { try { if (node.nd_type() == NODE_ITER) { result = eval(self, node.nd_iter()); } else { // String file = // int line = rubyBlock.flags &= ~RubyBlock.BLOCK_D_SCOPE; RubyBlock tmpBlock = beginCallargs(); RubyObject recv = eval(self, node.nd_iter()); endCallArgs(tmpBlock); // = file; // = line; result = recv.getRubyClass().call(recv, ruby.intern("each"), null, 0); } break; } catch (RetryException rExcptn) { } catch (ReturnException rExcptn) { result = rExcptn.getReturnValue(); break; } catch (BreakException bExcptn) { result = ruby.getNil(); break; } } rubyIter.pop(); rubyBlock.pop(); return result; case NODE_BREAK: throw new BreakException(); case NODE_NEXT: throw new NextException(); case NODE_REDO: throw new RedoException(); case NODE_RETRY: throw new RetryException(); case NODE_RESTARGS: result = eval(self, node.nd_head()); if (!(result instanceof RubyArray)) { result = obj = RubyArray.m_newArray(getRuby(), result); } return result; case NODE_YIELD: if (node.nd_stts() != null) { result = eval(self, node.nd_stts()); if (node.nd_stts().nd_type() == NODE_RESTARGS && ((RubyArray)result).length() == 1) { result = ((RubyArray)result).entry(0); } } else { result = ruby.getNil(); } return yield0(result, null, null, false); case NODE_RESCUE:/* retry_entry: { volatile VALUE e_info = ruby_errinfo; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, node->nd_head); } POP_TAG(); if (state == TAG_RAISE) { NODE * volatile resq = node->nd_resq; ruby_sourceline = nd_line(node); while (resq) { if (handle_rescue(self, resq)) { state = 0; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, resq->nd_body); } POP_TAG(); if (state == TAG_RETRY) { state = 0; ruby_errinfo = Qnil; goto retry_entry; } if (state != TAG_RAISE) { ruby_errinfo = e_info; } break; } resq = resq->nd_head; /* next rescue */ /** } * } * else if (node->nd_else) { /* else clause given *//* if (!state) { /* no exception raised *//* result = rb_eval(self, node->nd_else); } } if (state) JUMP_TAG(state); } break;*/ case NODE_ENSURE:/* PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = eval(node.nd_head()); } POP_TAG(); if (node.nd_ensr()) { VALUE retval = prot_tag->retval; /* save retval *//* VALUE errinfo = ruby_errinfo; rb_eval(self, node->nd_ensr); return_value(retval); ruby_errinfo = errinfo; } if (state) JUMP_TAG(state); break;*/ case NODE_AND: cond = (RubyBoolean)eval(self, node.nd_1st()); if (cond.isFalse()) { return cond; } node = node.nd_2nd(); break; case NODE_OR: cond = (RubyBoolean)eval(self, node.nd_1st()); if (cond.isTrue()) { return cond; } node = node.nd_2nd(); break; case NODE_NOT: return RubyBoolean.m_newBoolean(getRuby(), eval(self, node.nd_1st()).isFalse()); case NODE_DOT2: case NODE_DOT3: result = RubyRange.m_newRange(getRuby(), eval(self, node.nd_beg()), eval(self, node.nd_end()), node.nd_type() == NODE_DOT3); if (node.nd_state() != 0) { return result; } if (node.nd_beg().nd_type() == NODE_LIT && (node.nd_beg().nd_lit() instanceof RubyFixnum) && node.nd_end().nd_type() == NODE_LIT && (node.nd_end().nd_lit() instanceof RubyFixnum)) { node.nd_set_type(NODE_LIT); node.nd_lit(result); } else { node.nd_state(1L); } return result; case NODE_FLIP2: /* like AWK */ /*if (ruby_scope->local_vars == 0) { rb_bug("unexpected local variable"); }*/ if (ruby.rubyScope.getLocalVars(node.nd_cnt()).isFalse()) { if (eval(self, node.nd_beg()).isTrue()) { ruby.rubyScope.setLocalVars(node.nd_cnt(), eval(self, node.nd_end()).isTrue() ? ruby.getFalse() : ruby.getTrue()); result = ruby.getTrue(); } else { result = ruby.getFalse(); } } else { if (eval(self, node.nd_end()).isTrue()) { ruby.rubyScope.setLocalVars(node.nd_cnt(), ruby.getFalse()); } result = ruby.getTrue(); } return result; case NODE_FLIP3: /* like SED */ /*if (ruby_scope->local_vars == 0) { rb_bug("unexpected local variable"); }*/ if (ruby.rubyScope.getLocalVars(node.nd_cnt()).isFalse()) { result = eval(self, node.nd_beg()).isTrue() ? ruby.getFalse() : ruby.getTrue(); ruby.rubyScope.setLocalVars(node.nd_cnt(), result); } else { if (eval(self, node.nd_end()).isTrue()) { ruby.rubyScope.setLocalVars(node.nd_cnt(), ruby.getFalse()); } result = ruby.getTrue(); } return result; case NODE_RETURN: if (node.nd_stts() != null) { result = eval(self, node.nd_stts()); } else { result = ruby.getNil(); } throw new ReturnException(result); case NODE_ARGSCAT: return ((RubyArray)eval(self, node.nd_head())).m_concat(eval(self, node.nd_body())); case NODE_ARGSPUSH: return ((RubyArray)eval(self, node.nd_head()).m_dup()).push(eval(self, node.nd_body())); case NODE_CALL: // TMP_PROTECT; RubyBlock tmpBlock = beginCallargs(); RubyObject recv = eval(self, node.nd_recv()); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); return recv.getRubyClass().call(recv, (RubyId)node.nd_mid(), args, 0); case NODE_FCALL: // TMP_PROTECT; tmpBlock = beginCallargs(); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); return self.getRubyClass().call(self, (RubyId)node.nd_mid(), args, 1); case NODE_VCALL: return self.getRubyClass().call(self, (RubyId)node.nd_mid(), null, 2); case NODE_SUPER: case NODE_ZSUPER: // TMP_PROTECT; if (rubyFrame.getLastClass() == null) { throw new RubyNameException("superclass method '" + rubyFrame.getLastFunc().toName() + "' disabled"); } if (node.nd_type() == NODE_ZSUPER) { List argsList = rubyFrame.getArgs(); args = (RubyObject[])argsList.toArray(new RubyObject[argsList.size()]); } else { tmpBlock = beginCallargs(); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); } rubyIter.push(rubyIter.getIter() != Iter.ITER_NOT ? Iter.ITER_PRE : Iter.ITER_NOT); result = rubyFrame.getLastClass().getSuperClass().call(rubyFrame.getSelf(), rubyFrame.getLastFunc(), args, 3); rubyIter.pop(); return result; case NODE_SCOPE: NODE saved_cref = null; Frame frame = rubyFrame; frame.setTmp(rubyFrame); rubyFrame = frame; ruby.rubyScope.push(); if (node.nd_rval() != null) { saved_cref = ruby_cref; ruby_cref = (NODE)node.nd_rval(); rubyFrame.setCbase(node.nd_rval()); } if (node.nd_tbl() != null) { List tmp = Collections.nCopies(node.nd_tbl()[0].intValue() + 1, ruby.getNil()); ShiftableList vars = new ShiftableList(new ArrayList(tmp)); vars.set(0, (VALUE)node); vars.shift(1); getRuby().rubyScope.setLocalVars(vars); getRuby().rubyScope.setLocalTbl(node.nd_tbl()); } else { getRuby().rubyScope.setLocalVars(null); getRuby().rubyScope.setLocalTbl(null); } result = eval(self, node.nd_next()); ruby.rubyScope.pop(); rubyFrame = frame.getTmp(); if (saved_cref != null) { ruby_cref = saved_cref; } return result; case NODE_OP_ASGN1: // TMP_PROTECT; recv = eval(self, node.nd_recv()); NODE rval = node.nd_args().nd_head(); args = setupArgs(self, node.nd_args().nd_next()); ArrayList argsList = new ArrayList(Arrays.asList(args)); argsList.remove(args.length - 1); RubyBoolean val = (RubyBoolean)recv.funcall(getRuby().intern("[]"), (RubyObject[])argsList.toArray(new RubyObject[argsList.size()])); switch (node.nd_mid().intValue()) { case 0: /* OR */ if (val.isTrue()) { return val; } val = (RubyBoolean)eval(self, rval); break; case 1: /* AND */ if (val.isFalse()) { return val; } val = (RubyBoolean)eval(self, rval); break; default: val = (RubyBoolean)val.funcall((RubyId)node.nd_mid(), eval(self, rval)); } args[args.length - 1] = val; return recv.funcall(getRuby().intern("[]="), args); case NODE_OP_ASGN2: ID id = node.nd_next().nd_vid(); recv = eval(self, node.nd_recv()); val = (RubyBoolean)recv.funcall((RubyId)id, (RubyObject[])null); switch (node.nd_next().nd_mid().intValue()) { case 0: /* OR */ if (val.isTrue()) { return val; } val = (RubyBoolean)eval(self, node.nd_value()); break; case 1: /* AND */ if (val.isFalse()) { return val; } val = (RubyBoolean)eval(self, node.nd_value()); break; default: val = (RubyBoolean)val.funcall((RubyId)node.nd_mid(), eval(self, node.nd_value())); } // HACK +++ val = (RubyBoolean)recv.funcall((RubyId)node.nd_next().nd_aid(), val); // HACK --- return val; case NODE_OP_ASGN_AND: cond = (RubyBoolean)eval(self, node.nd_head()); if (cond.isFalse()) { return cond; } node = node.nd_value(); break; case NODE_OP_ASGN_OR: cond = (RubyBoolean)eval(self, node.nd_head()); if ((node.nd_aid() != null && !self.isInstanceVarDefined((RubyId)node.nd_aid())) || cond.isFalse()) { node = node.nd_value(); break; } return cond; case NODE_MASGN: return massign(self, node, eval(self, node.nd_value()), false); case NODE_LASGN: // if (ruby.ruby_scope.local_vars == null) { // rb_bug("unexpected local variable assignment"); // } result = eval(self, node.nd_value()); getRuby().rubyScope.setLocalVars(node.nd_cnt(), result); return result; case NODE_DASGN: result = eval(self, node.nd_value()); RubyVarmap.assign(ruby, (RubyId)node.nd_vid(), result); return result; case NODE_DASGN_CURR: result = eval(self, node.nd_value()); RubyVarmap.assignCurrent(ruby, (RubyId)node.nd_vid(), result); return result; case NODE_GASGN: result = eval(self, node.nd_value()); ((RubyGlobalEntry)node.nd_entry()).set(result); return result; case NODE_IASGN: result = eval(self, node.nd_value()); self.setInstanceVar((RubyId)node.nd_vid(), result); return result; case NODE_CDECL: if (ruby_class == null) { throw new RubyTypeException("no class/module to define constant"); } result = eval(self, node.nd_value()); ruby_class.setConstant((RubyId)node.nd_vid(), result); return result; case NODE_CVDECL: if (ruby_cbase == null) { throw new RubyTypeException("no class/module to define class variable"); } result = eval(self, node.nd_value()); if (ruby_cbase.isSingleton()) { ruby_cbase.getInstanceVar("__attached__").getClassVarSingleton().declareClassVar((RubyId)node.nd_vid(), result); return result; } ruby_cbase.declareClassVar((RubyId)node.nd_vid(), result); return result; case NODE_CVASGN: result = eval(self, node.nd_value()); self.getClassVarSingleton().setClassVar((RubyId)node.nd_vid(), result); return result; case NODE_LVAR: //if (getRuby().ruby_scope.local_vars == null) { // rb_bug("unexpected local variable"); // } return (RubyObject)getRuby().rubyScope.getLocalVars(node.nd_cnt()); case NODE_DVAR: return getDynamicVars().getRef((RubyId)node.nd_vid()); case NODE_GVAR: return ((RubyGlobalEntry)node.nd_entry()).get(); case NODE_IVAR: return self.getInstanceVar((RubyId)node.nd_vid()); case NODE_CONST: return getConstant((NODE)rubyFrame.getCbase(), (RubyId)node.nd_vid(), self); case NODE_CVAR: /* normal method */ if (ruby_cbase == null) { return self.getRubyClass().getClassVar((RubyId)node.nd_vid()); } if (!ruby_cbase.isSingleton()) { return ruby_cbase.getClassVar((RubyId)node.nd_vid()); } return ruby_cbase.getInstanceVar("__attached__").getClassVarSingleton().getClassVar((RubyId)node.nd_vid()); case NODE_CVAR2: /* singleton method */ return self.getClassVarSingleton().getClassVar((RubyId)node.nd_vid()); case NODE_BLOCK_ARG: if (ruby.rubyScope.getLocalVars() == null) { throw new RuntimeException("BUG: unexpected block argument"); } if (isBlockGiven()) { result = getRuby().getNil(); // Create Proc object ruby.rubyScope.setLocalVars(node.nd_cnt(), result); return result; } else { return getRuby().getNil(); } case NODE_COLON2: value = eval(self, node.nd_head()); if (value instanceof RubyModule) { return ((RubyModule)value).getConstant((RubyId)node.nd_mid()); } else { return value.funcall((RubyId)node.nd_mid()); } case NODE_COLON3: return getRuby().getObjectClass().getConstant((RubyId)node.nd_mid()); case NODE_NTH_REF: // return rom.rb_reg_nth_match(node.nd_nth(), MATCH_DATA); return null; case NODE_BACK_REF: /*switch ((char)node.nd_nth()) { case '&': return rom.rb_reg_last_match(MATCH_DATA); case '`': return rom.rb_reg_match_pre(MATCH_DATA); case '\'': return rom.rb_reg_match_post(MATCH_DATA); case '+': return rom.rb_reg_match_last(MATCH_DATA); default: rom.rb_bug("unexpected back-ref"); }*/ case NODE_HASH: RubyHash hash = RubyHash.m_newHash(ruby); NODE list = node.nd_head(); while(list != null) { RubyObject key = eval(self, list.nd_head()); list = list.nd_next(); if (list == null) { // HACK +++ throw new RubyArgumentException("odd number list for Hash"); // HACK --- } value = eval(self, list.nd_head()); hash.m_aset(key, value); list = list.nd_next(); } return hash; case NODE_ZARRAY: /* zero length list */ return RubyArray.m_newArray(getRuby()); case NODE_ARRAY: ArrayList ary = new ArrayList(node.nd_alen()); for (; node != null ; node = node.nd_next()) { ary.add(eval(self, node.nd_head())); } return RubyArray.m_newArray(getRuby(), ary); case NODE_STR: return ((RubyObject)node.nd_lit()).m_to_s(); case NODE_DSTR: case NODE_DXSTR: case NODE_DREGX: case NODE_DREGX_ONCE:/* NODE list = node.nd_next(); RubyString str = RubyString.m_newString(getRuby(), (RubyObject)node.nd_lit()); RubyString str2; while (list != null) { if (list.nd_head() != null) { switch (list.nd_head().nd_type()) { case NODE_STR: str2 = (RubyString)list.nd_head().nd_lit(); break; case NODE_EVSTR: result = ruby_errinfo; ruby_errinfo = Qnil; ruby_sourceline = nd_line(node); ruby_in_eval++; list.nd_head(compile(list.nd_head().nd_lit(), ruby_sourcefile,ruby_sourceline)); ruby_eval_tree = 0; ruby_in_eval--; if (ruby_nerrs > 0) { compile_error("string expansion"); } if (!NIL_P(result)) ruby_errinfo = result; /* fall through *//* default: str2 = (RubyString)rom.rb_obj_as_string(eval(list.nd_head())); break; } str.append(str2); str.infectObject(str2); } list = list.nd_next(); } switch (node.nd_type()) { case NODE_DREGX: return rom.rb_reg_new(str.getString(), str.getString().length(), node.nd_cflag()); case NODE_DREGX_ONCE: /* regexp expand once *//* VALUE result = rom.rb_reg_new(str.getString(), str.getString().length(), node.nd_cflag()); node.nd_set_type(NODE_LIT); node.nd_lit(result); return result; case NODE_DXSTR: return rom.rb_funcall(this, '`', 1, str); default: return str; }*/ return null; case NODE_XSTR: return self.funcall(getRuby().intern("`"), (RubyObject)node.nd_lit()); case NODE_LIT: return (RubyObject)node.nd_lit(); case NODE_ATTRSET: if (rubyFrame.getArgs().size() != 1) { throw new RubyArgumentException("wrong # of arguments(" + rubyFrame.getArgs().size() + "for 1)"); } return self.setInstanceVar((RubyId)node.nd_vid(), (RubyObject)rubyFrame.getArgs().get(0)); case NODE_DEFN: if (node.nd_defn() != null) { int noex; if (ruby_class == null) { throw new RubyTypeException("no class to add method"); } //if (ruby_class == getRuby().getObjectClass() && node.nd_mid() == init) { // rom.rb_warn("redefining Object#initialize may cause infinite loop"); //} //if (node.nd_mid() == __id__ || node.nd_mid() == __send__) { // rom.rb_warn("redefining `%s' may cause serious problem", ((RubyId)node.nd_mid()).toName()); //} // ruby_class.setFrozen(true); NODE body = ruby_class.searchMethod((RubyId)node.nd_mid()); RubyObject origin = ruby_class.getMethodOrigin((RubyId)node.nd_mid()); if (body != null){ // if (ruby_verbose.isTrue() && ruby_class == origin && body.nd_cnt() == 0) { // rom.rb_warning("discarding old %s", ((RubyId)node.nd_mid()).toName()); // } // if (node.nd_noex() != 0) { /* toplevel */ /* should upgrade to rb_warn() if no super was called inside? */ // rom.rb_warning("overriding global function `%s'", ((RubyId)node.nd_mid()).toName()); // } } if (isScope(SCOPE_PRIVATE) || node.nd_mid().equals(ruby.intern("initialize"))) { noex = NOEX_PRIVATE; } else if (isScope(SCOPE_PROTECTED)) { noex = NOEX_PROTECTED; } else if (ruby_class == getRuby().getObjectClass()) { noex = node.nd_noex(); } else { noex = NOEX_PUBLIC; } if (body != null && origin == ruby_class && (body.nd_noex() & NOEX_UNDEF) != 0) { noex |= NOEX_UNDEF; } NODE defn = node.nd_defn().copyNodeScope(ruby_cref); ruby_class.addMethod((RubyId)node.nd_mid(), defn, noex); // rb_clear_cache_by_id(node.nd_mid()); if (scope_vmode == SCOPE_MODFUNC) { ruby_class.getSingletonClass().addMethod((RubyId)node.nd_mid(), defn, NOEX_PUBLIC); ruby_class.funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } if (ruby_class.isSingleton()) { ruby_class.getInstanceVar("__attached__").funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } else { ruby_class.funcall(getRuby().intern("method_added"), ((RubyId)node.nd_mid()).toSymbol()); } } return getRuby().getNil(); case NODE_DEFS: if (node.nd_defn() != null) { recv = eval(self, node.nd_recv()); if (getRuby().getSecurityLevel() >= 4 && !recv.isTaint()) { throw new RubySecurityException("Insecure; can't define singleton method"); } /*if (FIXNUM_P(recv) || SYMBOL_P(recv)) { rb_raise(rb_eTypeError, "can't define singleton method \"%s\" for %s", rb_id2name(node.nd_mid()), rb_class2name(CLASS_OF(recv))); }*/ // not needed in jruby if (recv.isFrozen()) { throw new RubyFrozenException("object"); } rubyClass = recv.getSingletonClass(); NODE body = (NODE)rubyClass.getMethods().get((RubyId)node.nd_mid()); if (body != null) { if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("redefining method prohibited"); } /*if (RTEST(ruby_verbose)) { rb_warning("redefine %s", rb_id2name(node.nd_mid())); }*/ } NODE defn = node.nd_defn().copyNodeScope(ruby_cref); defn.nd_rval(ruby_cref); rubyClass.addMethod((RubyId)node.nd_mid(), defn, NOEX_PUBLIC | (body != null ? body.nd_noex() & NOEX_UNDEF : 0)); // rb_clear_cache_by_id(node.nd_mid()); recv.funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } return getRuby().getNil(); case NODE_UNDEF: if (ruby_class == null) { throw new RubyTypeException("no class to undef method"); } ruby_class.undef((RubyId)node.nd_mid()); return getRuby().getNil(); case NODE_ALIAS: if (ruby_class == null) { throw new RubyTypeException("no class to make alias"); } ruby_class.aliasMethod((RubyId)node.nd_new(), (RubyId)node.nd_old()); ruby_class.funcall(getRuby().intern("method_added"), ((RubyId)node.nd_mid()).toSymbol()); return getRuby().getNil(); case NODE_VALIAS: RubyGlobalEntry.getGlobalEntry((RubyId)node.nd_old()).alias((RubyId)node.nd_new()); return getRuby().getNil(); case NODE_CLASS: RubyModule superClass; if (ruby_class == null) { throw new RubyTypeException("no outer class/module"); } if (node.nd_super() != null) { superClass = getSuperClass(self, node.nd_super()); } else { superClass = null; } rubyClass = null; // if ((ruby_class == getRuby().getObjectClass()) && rb_autoload_defined(node.nd_cname())) { // rb_autoload_load(node.nd_cname()); // } if (ruby_class.isConstantDefined((RubyId)node.nd_cname())) { rubyClass = (RubyClass)ruby_class.getConstant((RubyId)node.nd_cname()); } if (rubyClass != null) { if (!rubyClass.isClass()) { throw new RubyTypeException(((RubyId)node.nd_cname()).toName() + " is not a class"); } if (superClass != null) { RubyModule tmp = rubyClass.getSuperClass(); if (tmp.isSingleton()) { tmp = tmp.getSuperClass(); } while (tmp.isIncluded()) { tmp = tmp.getSuperClass(); } if (tmp != superClass) { superClass = tmp; //goto override_class; if (superClass == null) { superClass = getRuby().getObjectClass(); } rubyClass = getRuby().defineClassId((RubyId)node.nd_cname(), (RubyClass)superClass); ruby_class.setConstant((RubyId)node.nd_cname(), rubyClass); rubyClass.setClassPath((RubyClass)ruby_class, ((RubyId)node.nd_cname()).toName()); // end goto } } if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("extending class prohibited"); } // rb_clear_cache(); } else { //override_class: if (superClass == null) { superClass = getRuby().getObjectClass(); } rubyClass = getRuby().defineClassId((RubyId)node.nd_cname(), (RubyClass)superClass); ruby_class.setConstant((RubyId)node.nd_cname(), rubyClass); rubyClass.setClassPath((RubyClass)ruby_class, ((RubyId)node.nd_cname()).toName()); } if (ruby_wrapper != null) { rubyClass.getSingletonClass().includeModule(ruby_wrapper); rubyClass.includeModule(ruby_wrapper); } return setupModule(rubyClass, node.nd_body()); case NODE_MODULE: if (ruby_class == null) { throw new RubyTypeException("no outer class/module"); } RubyModule module = null; if ((ruby_class == getRuby().getObjectClass()) && getRuby().isAutoloadDefined((RubyId)node.nd_cname())) { // getRuby().rb_autoload_load(node.nd_cname()); } if (ruby_class.isConstantDefined((RubyId)node.nd_cname())) { module = (RubyModule)ruby_class.getConstant((RubyId)node.nd_cname()); } if (module != null) { if (!(module instanceof RubyModule)) { throw new RubyTypeException(((RubyId)node.nd_cname()).toName() + " is not a module"); } if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("extending module prohibited"); } } else { module = getRuby().defineModuleId((RubyId)node.nd_cname()); ruby_class.setConstant((RubyId)node.nd_cname(), module); module.setClassPath(ruby_class, ((RubyId)node.nd_cname()).toName()); } if (ruby_wrapper != null) { module.getSingletonClass().includeModule(ruby_wrapper); module.includeModule(ruby_wrapper); } return setupModule(module, node.nd_body()); case NODE_SCLASS: rubyClass = (RubyClass)eval(self, node.nd_recv()); if (rubyClass.isSpecialConst()) { throw new RubyTypeException("no virtual class for " + rubyClass.getRubyClass().toName()); } if (getRuby().getSecurityLevel() >= 4 && !rubyClass.isTaint()) { throw new RubySecurityException("Insecure: can't extend object"); } if (rubyClass.getRubyClass().isSingleton()) { // rb_clear_cache(); } rubyClass = rubyClass.getSingletonClass(); if (ruby_wrapper != null) { rubyClass.getSingletonClass().includeModule(ruby_wrapper); rubyClass.includeModule(ruby_wrapper); } return setupModule(rubyClass, node.nd_body()); case NODE_DEFINED: // String buf; // String desc = is_defined(self, node.nd_head(), buf); // // if (desc) { // result = rb_str_new2(desc); // } else { // result = Qnil; // } case NODE_NEWLINE: // ruby_sourcefile = node.nd_file; // ruby_sourceline = node.nd_nth(); // if (trace_func) { // call_trace_func("line", ruby_sourcefile, ruby_sourceline, self, // ruby_frame.last_func(), // ruby_frame.last_class()); // } node = node.nd_next(); break; default: // rom.rb_bug("unknown node type %d", nd_type(node)); } } }
public RubyObject eval(RubyObject self, NODE n) { NODE node = n; RubyBoolean cond = null; RubyObject[] args = null; RubyObject value = null; RubyObject result = null; RubyModule rubyClass = null; // int state; // RubyOriginalMethods rom = getRuby().getOriginalMethods(); while (true) { if (node == null) { return getRuby().getNil(); } switch (node.nd_type()) { case NODE_BLOCK: while (node.nd_next() != null) { eval(self, node.nd_head()); node = node.nd_next(); } node = node.nd_head(); break; case NODE_POSTEXE: // rb_f_END(); node.nd_set_type(NODE_NIL); /* exec just once */ return getRuby().getNil(); /* begin .. end without clauses */ case NODE_BEGIN: node = node.nd_body(); break; /* nodes for speed-up(default match) */ case NODE_MATCH: //return rom.rb_reg_match2(node.nd_head().nd_lit()); return getRuby().getNil(); /* nodes for speed-up(literal match) */ case NODE_MATCH2: //return rom.rb_reg_match(eval(node.nd_recv()), eval(node.nd_value())); return getRuby().getNil(); /* nodes for speed-up(literal match) */ case NODE_MATCH3: //VALUE r = eval(node.nd_recv()); //VALUE l = eval(node.nd_value()); //if (r instanceof RubyString) { // return rom.rb_reg_match(l, r); //} else { // return rom.rb_funcall(r, match, 1, l); //} return getRuby().getNil(); /* node for speed-up(top-level loop for -n/-p) */ case NODE_OPT_N: while (true) { try { // while (!rb_gets().isNil() false) { // HACK +++ if (true) { // HACK --- try { eval(self, node.nd_body()); } catch (RedoException rExcptn) { } } break; } catch (NextException nExcptn) { } catch (BreakException bExcptn) { break; } } return getRuby().getNil(); case NODE_SELF: return self; case NODE_NIL: return getRuby().getNil(); case NODE_TRUE: return getRuby().getTrue(); case NODE_FALSE: return getRuby().getFalse(); case NODE_IF: // ruby_sourceline = node.nd_line(); cond = (RubyBoolean)eval(self, node.nd_cond()); if (cond.isTrue()) { node = node.nd_body(); } else { node = node.nd_else(); } break; case NODE_WHEN: while (node != null) { NODE tag; if (node.nd_type() != NODE_WHEN) { break; } tag = node.nd_head(); while (tag != null) {/* if (trace_func) { call_trace_func("line", tag->nd_file, nd_line(tag), self, ruby_frame->last_func, ruby_frame->last_class); }*/ // ruby_sourcefile = tag.nd_file; // ruby_sourceline = tag.nd_line(); if (tag.nd_head().nd_type() == NODE_WHEN) { RubyObject obj = eval(self, tag.nd_head().nd_head()); if (!(obj instanceof RubyArray)) { obj = RubyArray.m_newArray(getRuby(), obj); } for (int i = 0; i < ((RubyArray)obj).length(); i++) { if (((RubyBoolean)((RubyArray)obj).entry(i)).isTrue()) { node = node.nd_body(); break; } } tag = tag.nd_next(); continue; } if (((RubyBoolean)eval(self, tag.nd_head())).isTrue()) { node = node.nd_body(); break; } tag = tag.nd_next(); } node = node.nd_next(); } return getRuby().getNil(); case NODE_CASE: RubyObject obj = eval(self, node.nd_head()); node = node.nd_body(); while (node != null) { NODE tag; if (node.nd_type() != NODE_WHEN) { break; } tag = node.nd_head(); while (tag != null) {/* if (trace_func) { call_trace_func("line", tag->nd_file, nd_line(tag), self, ruby_frame->last_func, ruby_frame->last_class); } ruby_sourcefile = tag->nd_file; ruby_sourceline = nd_line(tag);*/ if (tag.nd_head().nd_type() == NODE_WHEN) { RubyObject obj2 = eval(self, tag.nd_head().nd_head()); if (!(obj2 instanceof RubyArray)) { obj2 = RubyArray.m_newArray(getRuby(), obj2); } for (int i = 0; i < ((RubyArray)obj).length(); i++) { RubyBoolean eqq = (RubyBoolean)((RubyArray)obj2).entry(i).funcall(getRuby().intern("==="), obj); if (eqq.isTrue()) { node = node.nd_body(); break; } } tag = tag.nd_next(); continue; } if (((RubyBoolean)eval(self, tag.nd_head()).funcall(getRuby().intern("==="), obj)).isTrue()) { node = node.nd_body(); break; } tag = tag.nd_next(); } node = node.nd_next(); } return getRuby().getNil(); case NODE_WHILE: while (eval(self, node.nd_cond()).isTrue()) { while (true) { try { eval(self, node.nd_body()); break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { break; } catch (BreakException bExcptn) { return getRuby().getNil(); } } } return getRuby().getNil(); case NODE_UNTIL: while (eval(self, node.nd_cond()).isFalse()) { while (true) { try { eval(self, node.nd_body()); break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { break; } catch (BreakException bExcptn) { return getRuby().getNil(); } } } return getRuby().getNil(); case NODE_BLOCK_PASS: //return block_pass(node); return null; case NODE_ITER: case NODE_FOR: rubyBlock.push(node.nd_var(), node.nd_body(), self); rubyIter.push(Iter.ITER_PRE); while (true) { try { if (node.nd_type() == NODE_ITER) { result = eval(self, node.nd_iter()); } else { // String file = // int line = rubyBlock.flags &= ~RubyBlock.BLOCK_D_SCOPE; RubyBlock tmpBlock = beginCallargs(); RubyObject recv = eval(self, node.nd_iter()); endCallArgs(tmpBlock); // = file; // = line; result = recv.getRubyClass().call(recv, ruby.intern("each"), null, 0); } break; } catch (RetryException rExcptn) { } catch (ReturnException rExcptn) { result = rExcptn.getReturnValue(); break; } catch (BreakException bExcptn) { result = ruby.getNil(); break; } } rubyIter.pop(); rubyBlock.pop(); return result; case NODE_BREAK: throw new BreakException(); case NODE_NEXT: throw new NextException(); case NODE_REDO: throw new RedoException(); case NODE_RETRY: throw new RetryException(); case NODE_RESTARGS: result = eval(self, node.nd_head()); if (!(result instanceof RubyArray)) { result = obj = RubyArray.m_newArray(getRuby(), result); } return result; case NODE_YIELD: if (node.nd_stts() != null) { result = eval(self, node.nd_stts()); if (node.nd_stts().nd_type() == NODE_RESTARGS && ((RubyArray)result).length() == 1) { result = ((RubyArray)result).entry(0); } } else { result = ruby.getNil(); } return yield0(result, null, null, false); case NODE_RESCUE:/* retry_entry: { volatile VALUE e_info = ruby_errinfo; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, node->nd_head); } POP_TAG(); if (state == TAG_RAISE) { NODE * volatile resq = node->nd_resq; ruby_sourceline = nd_line(node); while (resq) { if (handle_rescue(self, resq)) { state = 0; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, resq->nd_body); } POP_TAG(); if (state == TAG_RETRY) { state = 0; ruby_errinfo = Qnil; goto retry_entry; } if (state != TAG_RAISE) { ruby_errinfo = e_info; } break; } resq = resq->nd_head; /* next rescue */ /** } * } * else if (node->nd_else) { /* else clause given *//* if (!state) { /* no exception raised *//* result = rb_eval(self, node->nd_else); } } if (state) JUMP_TAG(state); } break;*/ case NODE_ENSURE:/* PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = eval(node.nd_head()); } POP_TAG(); if (node.nd_ensr()) { VALUE retval = prot_tag->retval; /* save retval *//* VALUE errinfo = ruby_errinfo; rb_eval(self, node->nd_ensr); return_value(retval); ruby_errinfo = errinfo; } if (state) JUMP_TAG(state); break;*/ case NODE_AND: cond = (RubyBoolean)eval(self, node.nd_1st()); if (cond.isFalse()) { return cond; } node = node.nd_2nd(); break; case NODE_OR: cond = (RubyBoolean)eval(self, node.nd_1st()); if (cond.isTrue()) { return cond; } node = node.nd_2nd(); break; case NODE_NOT: return RubyBoolean.m_newBoolean(getRuby(), eval(self, node.nd_1st()).isFalse()); case NODE_DOT2: case NODE_DOT3: result = RubyRange.m_newRange(getRuby(), eval(self, node.nd_beg()), eval(self, node.nd_end()), node.nd_type() == NODE_DOT3); if (node.nd_state() != 0) { return result; } if (node.nd_beg().nd_type() == NODE_LIT && (node.nd_beg().nd_lit() instanceof RubyFixnum) && node.nd_end().nd_type() == NODE_LIT && (node.nd_end().nd_lit() instanceof RubyFixnum)) { node.nd_set_type(NODE_LIT); node.nd_lit(result); } else { node.nd_state(1L); } return result; case NODE_FLIP2: /* like AWK */ /*if (ruby_scope->local_vars == 0) { rb_bug("unexpected local variable"); }*/ if (ruby.rubyScope.getLocalVars(node.nd_cnt()).isFalse()) { if (eval(self, node.nd_beg()).isTrue()) { ruby.rubyScope.setLocalVars(node.nd_cnt(), eval(self, node.nd_end()).isTrue() ? ruby.getFalse() : ruby.getTrue()); result = ruby.getTrue(); } else { result = ruby.getFalse(); } } else { if (eval(self, node.nd_end()).isTrue()) { ruby.rubyScope.setLocalVars(node.nd_cnt(), ruby.getFalse()); } result = ruby.getTrue(); } return result; case NODE_FLIP3: /* like SED */ /*if (ruby_scope->local_vars == 0) { rb_bug("unexpected local variable"); }*/ if (ruby.rubyScope.getLocalVars(node.nd_cnt()).isFalse()) { result = eval(self, node.nd_beg()).isTrue() ? ruby.getFalse() : ruby.getTrue(); ruby.rubyScope.setLocalVars(node.nd_cnt(), result); } else { if (eval(self, node.nd_end()).isTrue()) { ruby.rubyScope.setLocalVars(node.nd_cnt(), ruby.getFalse()); } result = ruby.getTrue(); } return result; case NODE_RETURN: if (node.nd_stts() != null) { result = eval(self, node.nd_stts()); } else { result = ruby.getNil(); } throw new ReturnException(result); case NODE_ARGSCAT: return ((RubyArray)eval(self, node.nd_head())).m_concat(eval(self, node.nd_body())); case NODE_ARGSPUSH: return ((RubyArray)eval(self, node.nd_head()).m_dup()).push(eval(self, node.nd_body())); case NODE_CALL: // TMP_PROTECT; RubyBlock tmpBlock = beginCallargs(); RubyObject recv = eval(self, node.nd_recv()); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); return recv.getRubyClass().call(recv, (RubyId)node.nd_mid(), args, 0); case NODE_FCALL: // TMP_PROTECT; tmpBlock = beginCallargs(); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); return self.getRubyClass().call(self, (RubyId)node.nd_mid(), args, 1); case NODE_VCALL: return self.getRubyClass().call(self, (RubyId)node.nd_mid(), null, 2); case NODE_SUPER: case NODE_ZSUPER: // TMP_PROTECT; if (rubyFrame.getLastClass() == null) { throw new RubyNameException("superclass method '" + rubyFrame.getLastFunc().toName() + "' disabled"); } if (node.nd_type() == NODE_ZSUPER) { List argsList = rubyFrame.getArgs(); args = (RubyObject[])argsList.toArray(new RubyObject[argsList.size()]); } else { tmpBlock = beginCallargs(); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); } rubyIter.push(rubyIter.getIter() != Iter.ITER_NOT ? Iter.ITER_PRE : Iter.ITER_NOT); result = getRubyFrame().getLastClass().getSuperClass().call(rubyFrame.getSelf(), rubyFrame.getLastFunc(), args, 3); rubyIter.pop(); return result; case NODE_SCOPE: NODE saved_cref = null; Frame frame = rubyFrame; frame.setTmp(rubyFrame); rubyFrame = frame; ruby.rubyScope.push(); if (node.nd_rval() != null) { saved_cref = ruby_cref; ruby_cref = (NODE)node.nd_rval(); rubyFrame.setCbase(node.nd_rval()); } if (node.nd_tbl() != null) { List tmp = Collections.nCopies(node.nd_tbl()[0].intValue() + 1, ruby.getNil()); ShiftableList vars = new ShiftableList(new ArrayList(tmp)); vars.set(0, (VALUE)node); vars.shift(1); getRuby().rubyScope.setLocalVars(vars); getRuby().rubyScope.setLocalTbl(node.nd_tbl()); } else { getRuby().rubyScope.setLocalVars(null); getRuby().rubyScope.setLocalTbl(null); } result = eval(self, node.nd_next()); ruby.rubyScope.pop(); rubyFrame = frame.getTmp(); if (saved_cref != null) { ruby_cref = saved_cref; } return result; case NODE_OP_ASGN1: // TMP_PROTECT; recv = eval(self, node.nd_recv()); NODE rval = node.nd_args().nd_head(); args = setupArgs(self, node.nd_args().nd_next()); ArrayList argsList = new ArrayList(Arrays.asList(args)); argsList.remove(args.length - 1); RubyBoolean val = (RubyBoolean)recv.funcall(getRuby().intern("[]"), (RubyObject[])argsList.toArray(new RubyObject[argsList.size()])); switch (node.nd_mid().intValue()) { case 0: /* OR */ if (val.isTrue()) { return val; } val = (RubyBoolean)eval(self, rval); break; case 1: /* AND */ if (val.isFalse()) { return val; } val = (RubyBoolean)eval(self, rval); break; default: val = (RubyBoolean)val.funcall((RubyId)node.nd_mid(), eval(self, rval)); } args[args.length - 1] = val; return recv.funcall(getRuby().intern("[]="), args); case NODE_OP_ASGN2: ID id = node.nd_next().nd_vid(); recv = eval(self, node.nd_recv()); val = (RubyBoolean)recv.funcall((RubyId)id, (RubyObject[])null); switch (node.nd_next().nd_mid().intValue()) { case 0: /* OR */ if (val.isTrue()) { return val; } val = (RubyBoolean)eval(self, node.nd_value()); break; case 1: /* AND */ if (val.isFalse()) { return val; } val = (RubyBoolean)eval(self, node.nd_value()); break; default: val = (RubyBoolean)val.funcall((RubyId)node.nd_mid(), eval(self, node.nd_value())); } // HACK +++ val = (RubyBoolean)recv.funcall((RubyId)node.nd_next().nd_aid(), val); // HACK --- return val; case NODE_OP_ASGN_AND: cond = (RubyBoolean)eval(self, node.nd_head()); if (cond.isFalse()) { return cond; } node = node.nd_value(); break; case NODE_OP_ASGN_OR: cond = (RubyBoolean)eval(self, node.nd_head()); if ((node.nd_aid() != null && !self.isInstanceVarDefined((RubyId)node.nd_aid())) || cond.isFalse()) { node = node.nd_value(); break; } return cond; case NODE_MASGN: return massign(self, node, eval(self, node.nd_value()), false); case NODE_LASGN: // if (ruby.ruby_scope.local_vars == null) { // rb_bug("unexpected local variable assignment"); // } result = eval(self, node.nd_value()); getRuby().rubyScope.setLocalVars(node.nd_cnt(), result); return result; case NODE_DASGN: result = eval(self, node.nd_value()); RubyVarmap.assign(ruby, (RubyId)node.nd_vid(), result); return result; case NODE_DASGN_CURR: result = eval(self, node.nd_value()); RubyVarmap.assignCurrent(ruby, (RubyId)node.nd_vid(), result); return result; case NODE_GASGN: result = eval(self, node.nd_value()); ((RubyGlobalEntry)node.nd_entry()).set(result); return result; case NODE_IASGN: result = eval(self, node.nd_value()); self.setInstanceVar((RubyId)node.nd_vid(), result); return result; case NODE_CDECL: if (ruby_class == null) { throw new RubyTypeException("no class/module to define constant"); } result = eval(self, node.nd_value()); ruby_class.setConstant((RubyId)node.nd_vid(), result); return result; case NODE_CVDECL: if (ruby_cbase == null) { throw new RubyTypeException("no class/module to define class variable"); } result = eval(self, node.nd_value()); if (ruby_cbase.isSingleton()) { ruby_cbase.getInstanceVar("__attached__").getClassVarSingleton().declareClassVar((RubyId)node.nd_vid(), result); return result; } ruby_cbase.declareClassVar((RubyId)node.nd_vid(), result); return result; case NODE_CVASGN: result = eval(self, node.nd_value()); self.getClassVarSingleton().setClassVar((RubyId)node.nd_vid(), result); return result; case NODE_LVAR: //if (getRuby().ruby_scope.local_vars == null) { // rb_bug("unexpected local variable"); // } return (RubyObject)getRuby().rubyScope.getLocalVars(node.nd_cnt()); case NODE_DVAR: return getDynamicVars().getRef((RubyId)node.nd_vid()); case NODE_GVAR: return ((RubyGlobalEntry)node.nd_entry()).get(); case NODE_IVAR: return self.getInstanceVar((RubyId)node.nd_vid()); case NODE_CONST: return getConstant((NODE)rubyFrame.getCbase(), (RubyId)node.nd_vid(), self); case NODE_CVAR: /* normal method */ if (ruby_cbase == null) { return self.getRubyClass().getClassVar((RubyId)node.nd_vid()); } if (!ruby_cbase.isSingleton()) { return ruby_cbase.getClassVar((RubyId)node.nd_vid()); } return ruby_cbase.getInstanceVar("__attached__").getClassVarSingleton().getClassVar((RubyId)node.nd_vid()); case NODE_CVAR2: /* singleton method */ return self.getClassVarSingleton().getClassVar((RubyId)node.nd_vid()); case NODE_BLOCK_ARG: if (ruby.rubyScope.getLocalVars() == null) { throw new RuntimeException("BUG: unexpected block argument"); } if (isBlockGiven()) { result = getRuby().getNil(); // Create Proc object ruby.rubyScope.setLocalVars(node.nd_cnt(), result); return result; } else { return getRuby().getNil(); } case NODE_COLON2: value = eval(self, node.nd_head()); if (value instanceof RubyModule) { return ((RubyModule)value).getConstant((RubyId)node.nd_mid()); } else { return value.funcall((RubyId)node.nd_mid()); } case NODE_COLON3: return getRuby().getObjectClass().getConstant((RubyId)node.nd_mid()); case NODE_NTH_REF: // return rom.rb_reg_nth_match(node.nd_nth(), MATCH_DATA); return null; case NODE_BACK_REF: /*switch ((char)node.nd_nth()) { case '&': return rom.rb_reg_last_match(MATCH_DATA); case '`': return rom.rb_reg_match_pre(MATCH_DATA); case '\'': return rom.rb_reg_match_post(MATCH_DATA); case '+': return rom.rb_reg_match_last(MATCH_DATA); default: rom.rb_bug("unexpected back-ref"); }*/ case NODE_HASH: RubyHash hash = RubyHash.m_newHash(ruby); NODE list = node.nd_head(); while(list != null) { RubyObject key = eval(self, list.nd_head()); list = list.nd_next(); if (list == null) { // HACK +++ throw new RubyArgumentException("odd number list for Hash"); // HACK --- } value = eval(self, list.nd_head()); hash.m_aset(key, value); list = list.nd_next(); } return hash; case NODE_ZARRAY: /* zero length list */ return RubyArray.m_newArray(getRuby()); case NODE_ARRAY: ArrayList ary = new ArrayList(node.nd_alen()); for (; node != null ; node = node.nd_next()) { ary.add(eval(self, node.nd_head())); } return RubyArray.m_newArray(getRuby(), ary); case NODE_STR: return ((RubyObject)node.nd_lit()).m_to_s(); case NODE_DSTR: case NODE_DXSTR: case NODE_DREGX: case NODE_DREGX_ONCE:/* NODE list = node.nd_next(); RubyString str = RubyString.m_newString(getRuby(), (RubyObject)node.nd_lit()); RubyString str2; while (list != null) { if (list.nd_head() != null) { switch (list.nd_head().nd_type()) { case NODE_STR: str2 = (RubyString)list.nd_head().nd_lit(); break; case NODE_EVSTR: result = ruby_errinfo; ruby_errinfo = Qnil; ruby_sourceline = nd_line(node); ruby_in_eval++; list.nd_head(compile(list.nd_head().nd_lit(), ruby_sourcefile,ruby_sourceline)); ruby_eval_tree = 0; ruby_in_eval--; if (ruby_nerrs > 0) { compile_error("string expansion"); } if (!NIL_P(result)) ruby_errinfo = result; /* fall through *//* default: str2 = (RubyString)rom.rb_obj_as_string(eval(list.nd_head())); break; } str.append(str2); str.infectObject(str2); } list = list.nd_next(); } switch (node.nd_type()) { case NODE_DREGX: return rom.rb_reg_new(str.getString(), str.getString().length(), node.nd_cflag()); case NODE_DREGX_ONCE: /* regexp expand once *//* VALUE result = rom.rb_reg_new(str.getString(), str.getString().length(), node.nd_cflag()); node.nd_set_type(NODE_LIT); node.nd_lit(result); return result; case NODE_DXSTR: return rom.rb_funcall(this, '`', 1, str); default: return str; }*/ return null; case NODE_XSTR: return self.funcall(getRuby().intern("`"), (RubyObject)node.nd_lit()); case NODE_LIT: return (RubyObject)node.nd_lit(); case NODE_ATTRSET: if (rubyFrame.getArgs().size() != 1) { throw new RubyArgumentException("wrong # of arguments(" + rubyFrame.getArgs().size() + "for 1)"); } return self.setInstanceVar((RubyId)node.nd_vid(), (RubyObject)rubyFrame.getArgs().get(0)); case NODE_DEFN: if (node.nd_defn() != null) { int noex; if (ruby_class == null) { throw new RubyTypeException("no class to add method"); } //if (ruby_class == getRuby().getObjectClass() && node.nd_mid() == init) { // rom.rb_warn("redefining Object#initialize may cause infinite loop"); //} //if (node.nd_mid() == __id__ || node.nd_mid() == __send__) { // rom.rb_warn("redefining `%s' may cause serious problem", ((RubyId)node.nd_mid()).toName()); //} // ruby_class.setFrozen(true); NODE body = ruby_class.searchMethod((RubyId)node.nd_mid()); RubyObject origin = ruby_class.getMethodOrigin((RubyId)node.nd_mid()); if (body != null){ // if (ruby_verbose.isTrue() && ruby_class == origin && body.nd_cnt() == 0) { // rom.rb_warning("discarding old %s", ((RubyId)node.nd_mid()).toName()); // } // if (node.nd_noex() != 0) { /* toplevel */ /* should upgrade to rb_warn() if no super was called inside? */ // rom.rb_warning("overriding global function `%s'", ((RubyId)node.nd_mid()).toName()); // } } if (isScope(SCOPE_PRIVATE) || node.nd_mid().equals(ruby.intern("initialize"))) { noex = NOEX_PRIVATE; } else if (isScope(SCOPE_PROTECTED)) { noex = NOEX_PROTECTED; } else if (ruby_class == getRuby().getObjectClass()) { noex = node.nd_noex(); } else { noex = NOEX_PUBLIC; } if (body != null && origin == ruby_class && (body.nd_noex() & NOEX_UNDEF) != 0) { noex |= NOEX_UNDEF; } NODE defn = node.nd_defn().copyNodeScope(ruby_cref); ruby_class.addMethod((RubyId)node.nd_mid(), defn, noex); // rb_clear_cache_by_id(node.nd_mid()); if (scope_vmode == SCOPE_MODFUNC) { ruby_class.getSingletonClass().addMethod((RubyId)node.nd_mid(), defn, NOEX_PUBLIC); ruby_class.funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } if (ruby_class.isSingleton()) { ruby_class.getInstanceVar("__attached__").funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } else { ruby_class.funcall(getRuby().intern("method_added"), ((RubyId)node.nd_mid()).toSymbol()); } } return getRuby().getNil(); case NODE_DEFS: if (node.nd_defn() != null) { recv = eval(self, node.nd_recv()); if (getRuby().getSecurityLevel() >= 4 && !recv.isTaint()) { throw new RubySecurityException("Insecure; can't define singleton method"); } /*if (FIXNUM_P(recv) || SYMBOL_P(recv)) { rb_raise(rb_eTypeError, "can't define singleton method \"%s\" for %s", rb_id2name(node.nd_mid()), rb_class2name(CLASS_OF(recv))); }*/ // not needed in jruby if (recv.isFrozen()) { throw new RubyFrozenException("object"); } rubyClass = recv.getSingletonClass(); NODE body = (NODE)rubyClass.getMethods().get((RubyId)node.nd_mid()); if (body != null) { if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("redefining method prohibited"); } /*if (RTEST(ruby_verbose)) { rb_warning("redefine %s", rb_id2name(node.nd_mid())); }*/ } NODE defn = node.nd_defn().copyNodeScope(ruby_cref); defn.nd_rval(ruby_cref); rubyClass.addMethod((RubyId)node.nd_mid(), defn, NOEX_PUBLIC | (body != null ? body.nd_noex() & NOEX_UNDEF : 0)); // rb_clear_cache_by_id(node.nd_mid()); recv.funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } return getRuby().getNil(); case NODE_UNDEF: if (ruby_class == null) { throw new RubyTypeException("no class to undef method"); } ruby_class.undef((RubyId)node.nd_mid()); return getRuby().getNil(); case NODE_ALIAS: if (ruby_class == null) { throw new RubyTypeException("no class to make alias"); } ruby_class.aliasMethod((RubyId)node.nd_new(), (RubyId)node.nd_old()); ruby_class.funcall(getRuby().intern("method_added"), ((RubyId)node.nd_mid()).toSymbol()); return getRuby().getNil(); case NODE_VALIAS: RubyGlobalEntry.getGlobalEntry((RubyId)node.nd_old()).alias((RubyId)node.nd_new()); return getRuby().getNil(); case NODE_CLASS: RubyModule superClass; if (ruby_class == null) { throw new RubyTypeException("no outer class/module"); } if (node.nd_super() != null) { superClass = getSuperClass(self, node.nd_super()); } else { superClass = null; } rubyClass = null; // if ((ruby_class == getRuby().getObjectClass()) && rb_autoload_defined(node.nd_cname())) { // rb_autoload_load(node.nd_cname()); // } if (ruby_class.isConstantDefined((RubyId)node.nd_cname())) { rubyClass = (RubyClass)ruby_class.getConstant((RubyId)node.nd_cname()); } if (rubyClass != null) { if (!rubyClass.isClass()) { throw new RubyTypeException(((RubyId)node.nd_cname()).toName() + " is not a class"); } if (superClass != null) { RubyModule tmp = rubyClass.getSuperClass(); if (tmp.isSingleton()) { tmp = tmp.getSuperClass(); } while (tmp.isIncluded()) { tmp = tmp.getSuperClass(); } if (tmp != superClass) { superClass = tmp; //goto override_class; if (superClass == null) { superClass = getRuby().getObjectClass(); } rubyClass = getRuby().defineClassId((RubyId)node.nd_cname(), (RubyClass)superClass); ruby_class.setConstant((RubyId)node.nd_cname(), rubyClass); rubyClass.setClassPath((RubyClass)ruby_class, ((RubyId)node.nd_cname()).toName()); // end goto } } if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("extending class prohibited"); } // rb_clear_cache(); } else { //override_class: if (superClass == null) { superClass = getRuby().getObjectClass(); } rubyClass = getRuby().defineClassId((RubyId)node.nd_cname(), (RubyClass)superClass); ruby_class.setConstant((RubyId)node.nd_cname(), rubyClass); rubyClass.setClassPath((RubyClass)ruby_class, ((RubyId)node.nd_cname()).toName()); } if (ruby_wrapper != null) { rubyClass.getSingletonClass().includeModule(ruby_wrapper); rubyClass.includeModule(ruby_wrapper); } return setupModule(rubyClass, node.nd_body()); case NODE_MODULE: if (ruby_class == null) { throw new RubyTypeException("no outer class/module"); } RubyModule module = null; if ((ruby_class == getRuby().getObjectClass()) && getRuby().isAutoloadDefined((RubyId)node.nd_cname())) { // getRuby().rb_autoload_load(node.nd_cname()); } if (ruby_class.isConstantDefined((RubyId)node.nd_cname())) { module = (RubyModule)ruby_class.getConstant((RubyId)node.nd_cname()); } if (module != null) { if (!(module instanceof RubyModule)) { throw new RubyTypeException(((RubyId)node.nd_cname()).toName() + " is not a module"); } if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("extending module prohibited"); } } else { module = getRuby().defineModuleId((RubyId)node.nd_cname()); ruby_class.setConstant((RubyId)node.nd_cname(), module); module.setClassPath(ruby_class, ((RubyId)node.nd_cname()).toName()); } if (ruby_wrapper != null) { module.getSingletonClass().includeModule(ruby_wrapper); module.includeModule(ruby_wrapper); } return setupModule(module, node.nd_body()); case NODE_SCLASS: rubyClass = (RubyClass)eval(self, node.nd_recv()); if (rubyClass.isSpecialConst()) { throw new RubyTypeException("no virtual class for " + rubyClass.getRubyClass().toName()); } if (getRuby().getSecurityLevel() >= 4 && !rubyClass.isTaint()) { throw new RubySecurityException("Insecure: can't extend object"); } if (rubyClass.getRubyClass().isSingleton()) { // rb_clear_cache(); } rubyClass = rubyClass.getSingletonClass(); if (ruby_wrapper != null) { rubyClass.getSingletonClass().includeModule(ruby_wrapper); rubyClass.includeModule(ruby_wrapper); } return setupModule(rubyClass, node.nd_body()); case NODE_DEFINED: // String buf; // String desc = is_defined(self, node.nd_head(), buf); // // if (desc) { // result = rb_str_new2(desc); // } else { // result = Qnil; // } case NODE_NEWLINE: // ruby_sourcefile = node.nd_file; // ruby_sourceline = node.nd_nth(); // if (trace_func) { // call_trace_func("line", ruby_sourcefile, ruby_sourceline, self, // ruby_frame.last_func(), // ruby_frame.last_class()); // } node = node.nd_next(); break; default: // rom.rb_bug("unknown node type %d", nd_type(node)); } } }
3,238,700
public RubyObject eval(RubyObject self, NODE n) { NODE node = n; RubyBoolean cond = null; RubyObject[] args = null; RubyObject value = null; RubyObject result = null; RubyModule rubyClass = null; // int state; // RubyOriginalMethods rom = getRuby().getOriginalMethods(); while (true) { if (node == null) { return getRuby().getNil(); } switch (node.nd_type()) { case NODE_BLOCK: while (node.nd_next() != null) { eval(self, node.nd_head()); node = node.nd_next(); } node = node.nd_head(); break; case NODE_POSTEXE: // rb_f_END(); node.nd_set_type(NODE_NIL); /* exec just once */ return getRuby().getNil(); /* begin .. end without clauses */ case NODE_BEGIN: node = node.nd_body(); break; /* nodes for speed-up(default match) */ case NODE_MATCH: //return rom.rb_reg_match2(node.nd_head().nd_lit()); return getRuby().getNil(); /* nodes for speed-up(literal match) */ case NODE_MATCH2: //return rom.rb_reg_match(eval(node.nd_recv()), eval(node.nd_value())); return getRuby().getNil(); /* nodes for speed-up(literal match) */ case NODE_MATCH3: //VALUE r = eval(node.nd_recv()); //VALUE l = eval(node.nd_value()); //if (r instanceof RubyString) { // return rom.rb_reg_match(l, r); //} else { // return rom.rb_funcall(r, match, 1, l); //} return getRuby().getNil(); /* node for speed-up(top-level loop for -n/-p) */ case NODE_OPT_N: while (true) { try { // while (!rb_gets().isNil() false) { // HACK +++ if (true) { // HACK --- try { eval(self, node.nd_body()); } catch (RedoException rExcptn) { } } break; } catch (NextException nExcptn) { } catch (BreakException bExcptn) { break; } } return getRuby().getNil(); case NODE_SELF: return self; case NODE_NIL: return getRuby().getNil(); case NODE_TRUE: return getRuby().getTrue(); case NODE_FALSE: return getRuby().getFalse(); case NODE_IF: // ruby_sourceline = node.nd_line(); cond = (RubyBoolean)eval(self, node.nd_cond()); if (cond.isTrue()) { node = node.nd_body(); } else { node = node.nd_else(); } break; case NODE_WHEN: while (node != null) { NODE tag; if (node.nd_type() != NODE_WHEN) { break; } tag = node.nd_head(); while (tag != null) {/* if (trace_func) { call_trace_func("line", tag->nd_file, nd_line(tag), self, ruby_frame->last_func, ruby_frame->last_class); }*/ // ruby_sourcefile = tag.nd_file; // ruby_sourceline = tag.nd_line(); if (tag.nd_head().nd_type() == NODE_WHEN) { RubyObject obj = eval(self, tag.nd_head().nd_head()); if (!(obj instanceof RubyArray)) { obj = RubyArray.m_newArray(getRuby(), obj); } for (int i = 0; i < ((RubyArray)obj).length(); i++) { if (((RubyBoolean)((RubyArray)obj).entry(i)).isTrue()) { node = node.nd_body(); break; } } tag = tag.nd_next(); continue; } if (((RubyBoolean)eval(self, tag.nd_head())).isTrue()) { node = node.nd_body(); break; } tag = tag.nd_next(); } node = node.nd_next(); } return getRuby().getNil(); case NODE_CASE: RubyObject obj = eval(self, node.nd_head()); node = node.nd_body(); while (node != null) { NODE tag; if (node.nd_type() != NODE_WHEN) { break; } tag = node.nd_head(); while (tag != null) {/* if (trace_func) { call_trace_func("line", tag->nd_file, nd_line(tag), self, ruby_frame->last_func, ruby_frame->last_class); } ruby_sourcefile = tag->nd_file; ruby_sourceline = nd_line(tag);*/ if (tag.nd_head().nd_type() == NODE_WHEN) { RubyObject obj2 = eval(self, tag.nd_head().nd_head()); if (!(obj2 instanceof RubyArray)) { obj2 = RubyArray.m_newArray(getRuby(), obj2); } for (int i = 0; i < ((RubyArray)obj).length(); i++) { RubyBoolean eqq = (RubyBoolean)((RubyArray)obj2).entry(i).funcall(getRuby().intern("==="), obj); if (eqq.isTrue()) { node = node.nd_body(); break; } } tag = tag.nd_next(); continue; } if (((RubyBoolean)eval(self, tag.nd_head()).funcall(getRuby().intern("==="), obj)).isTrue()) { node = node.nd_body(); break; } tag = tag.nd_next(); } node = node.nd_next(); } return getRuby().getNil(); case NODE_WHILE: while (eval(self, node.nd_cond()).isTrue()) { while (true) { try { eval(self, node.nd_body()); break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { break; } catch (BreakException bExcptn) { return getRuby().getNil(); } } } return getRuby().getNil(); case NODE_UNTIL: while (eval(self, node.nd_cond()).isFalse()) { while (true) { try { eval(self, node.nd_body()); break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { break; } catch (BreakException bExcptn) { return getRuby().getNil(); } } } return getRuby().getNil(); case NODE_BLOCK_PASS: //return block_pass(node); return null; case NODE_ITER: case NODE_FOR: rubyBlock.push(node.nd_var(), node.nd_body(), self); rubyIter.push(Iter.ITER_PRE); while (true) { try { if (node.nd_type() == NODE_ITER) { result = eval(self, node.nd_iter()); } else { // String file = // int line = rubyBlock.flags &= ~RubyBlock.BLOCK_D_SCOPE; RubyBlock tmpBlock = beginCallargs(); RubyObject recv = eval(self, node.nd_iter()); endCallArgs(tmpBlock); // = file; // = line; result = recv.getRubyClass().call(recv, ruby.intern("each"), null, 0); } break; } catch (RetryException rExcptn) { } catch (ReturnException rExcptn) { result = rExcptn.getReturnValue(); break; } catch (BreakException bExcptn) { result = ruby.getNil(); break; } } rubyIter.pop(); rubyBlock.pop(); return result; case NODE_BREAK: throw new BreakException(); case NODE_NEXT: throw new NextException(); case NODE_REDO: throw new RedoException(); case NODE_RETRY: throw new RetryException(); case NODE_RESTARGS: result = eval(self, node.nd_head()); if (!(result instanceof RubyArray)) { result = obj = RubyArray.m_newArray(getRuby(), result); } return result; case NODE_YIELD: if (node.nd_stts() != null) { result = eval(self, node.nd_stts()); if (node.nd_stts().nd_type() == NODE_RESTARGS && ((RubyArray)result).length() == 1) { result = ((RubyArray)result).entry(0); } } else { result = ruby.getNil(); } return yield0(result, null, null, false); case NODE_RESCUE:/* retry_entry: { volatile VALUE e_info = ruby_errinfo; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, node->nd_head); } POP_TAG(); if (state == TAG_RAISE) { NODE * volatile resq = node->nd_resq; ruby_sourceline = nd_line(node); while (resq) { if (handle_rescue(self, resq)) { state = 0; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, resq->nd_body); } POP_TAG(); if (state == TAG_RETRY) { state = 0; ruby_errinfo = Qnil; goto retry_entry; } if (state != TAG_RAISE) { ruby_errinfo = e_info; } break; } resq = resq->nd_head; /* next rescue */ /** } * } * else if (node->nd_else) { /* else clause given *//* if (!state) { /* no exception raised *//* result = rb_eval(self, node->nd_else); } } if (state) JUMP_TAG(state); } break;*/ case NODE_ENSURE:/* PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = eval(node.nd_head()); } POP_TAG(); if (node.nd_ensr()) { VALUE retval = prot_tag->retval; /* save retval *//* VALUE errinfo = ruby_errinfo; rb_eval(self, node->nd_ensr); return_value(retval); ruby_errinfo = errinfo; } if (state) JUMP_TAG(state); break;*/ case NODE_AND: cond = (RubyBoolean)eval(self, node.nd_1st()); if (cond.isFalse()) { return cond; } node = node.nd_2nd(); break; case NODE_OR: cond = (RubyBoolean)eval(self, node.nd_1st()); if (cond.isTrue()) { return cond; } node = node.nd_2nd(); break; case NODE_NOT: return RubyBoolean.m_newBoolean(getRuby(), eval(self, node.nd_1st()).isFalse()); case NODE_DOT2: case NODE_DOT3: result = RubyRange.m_newRange(getRuby(), eval(self, node.nd_beg()), eval(self, node.nd_end()), node.nd_type() == NODE_DOT3); if (node.nd_state() != 0) { return result; } if (node.nd_beg().nd_type() == NODE_LIT && (node.nd_beg().nd_lit() instanceof RubyFixnum) && node.nd_end().nd_type() == NODE_LIT && (node.nd_end().nd_lit() instanceof RubyFixnum)) { node.nd_set_type(NODE_LIT); node.nd_lit(result); } else { node.nd_state(1L); } return result; case NODE_FLIP2: /* like AWK */ /*if (ruby_scope->local_vars == 0) { rb_bug("unexpected local variable"); }*/ if (ruby.rubyScope.getLocalVars(node.nd_cnt()).isFalse()) { if (eval(self, node.nd_beg()).isTrue()) { ruby.rubyScope.setLocalVars(node.nd_cnt(), eval(self, node.nd_end()).isTrue() ? ruby.getFalse() : ruby.getTrue()); result = ruby.getTrue(); } else { result = ruby.getFalse(); } } else { if (eval(self, node.nd_end()).isTrue()) { ruby.rubyScope.setLocalVars(node.nd_cnt(), ruby.getFalse()); } result = ruby.getTrue(); } return result; case NODE_FLIP3: /* like SED */ /*if (ruby_scope->local_vars == 0) { rb_bug("unexpected local variable"); }*/ if (ruby.rubyScope.getLocalVars(node.nd_cnt()).isFalse()) { result = eval(self, node.nd_beg()).isTrue() ? ruby.getFalse() : ruby.getTrue(); ruby.rubyScope.setLocalVars(node.nd_cnt(), result); } else { if (eval(self, node.nd_end()).isTrue()) { ruby.rubyScope.setLocalVars(node.nd_cnt(), ruby.getFalse()); } result = ruby.getTrue(); } return result; case NODE_RETURN: if (node.nd_stts() != null) { result = eval(self, node.nd_stts()); } else { result = ruby.getNil(); } throw new ReturnException(result); case NODE_ARGSCAT: return ((RubyArray)eval(self, node.nd_head())).m_concat(eval(self, node.nd_body())); case NODE_ARGSPUSH: return ((RubyArray)eval(self, node.nd_head()).m_dup()).push(eval(self, node.nd_body())); case NODE_CALL: // TMP_PROTECT; RubyBlock tmpBlock = beginCallargs(); RubyObject recv = eval(self, node.nd_recv()); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); return recv.getRubyClass().call(recv, (RubyId)node.nd_mid(), args, 0); case NODE_FCALL: // TMP_PROTECT; tmpBlock = beginCallargs(); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); return self.getRubyClass().call(self, (RubyId)node.nd_mid(), args, 1); case NODE_VCALL: return self.getRubyClass().call(self, (RubyId)node.nd_mid(), null, 2); case NODE_SUPER: case NODE_ZSUPER: // TMP_PROTECT; if (rubyFrame.getLastClass() == null) { throw new RubyNameException("superclass method '" + rubyFrame.getLastFunc().toName() + "' disabled"); } if (node.nd_type() == NODE_ZSUPER) { List argsList = rubyFrame.getArgs(); args = (RubyObject[])argsList.toArray(new RubyObject[argsList.size()]); } else { tmpBlock = beginCallargs(); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); } rubyIter.push(rubyIter.getIter() != Iter.ITER_NOT ? Iter.ITER_PRE : Iter.ITER_NOT); result = rubyFrame.getLastClass().getSuperClass().call(rubyFrame.getSelf(), rubyFrame.getLastFunc(), args, 3); rubyIter.pop(); return result; case NODE_SCOPE: NODE saved_cref = null; Frame frame = rubyFrame; frame.setTmp(rubyFrame); rubyFrame = frame; ruby.rubyScope.push(); if (node.nd_rval() != null) { saved_cref = ruby_cref; ruby_cref = (NODE)node.nd_rval(); rubyFrame.setCbase(node.nd_rval()); } if (node.nd_tbl() != null) { List tmp = Collections.nCopies(node.nd_tbl()[0].intValue() + 1, ruby.getNil()); ShiftableList vars = new ShiftableList(new ArrayList(tmp)); vars.set(0, (VALUE)node); vars.shift(1); getRuby().rubyScope.setLocalVars(vars); getRuby().rubyScope.setLocalTbl(node.nd_tbl()); } else { getRuby().rubyScope.setLocalVars(null); getRuby().rubyScope.setLocalTbl(null); } result = eval(self, node.nd_next()); ruby.rubyScope.pop(); rubyFrame = frame.getTmp(); if (saved_cref != null) { ruby_cref = saved_cref; } return result; case NODE_OP_ASGN1: // TMP_PROTECT; recv = eval(self, node.nd_recv()); NODE rval = node.nd_args().nd_head(); args = setupArgs(self, node.nd_args().nd_next()); ArrayList argsList = new ArrayList(Arrays.asList(args)); argsList.remove(args.length - 1); RubyBoolean val = (RubyBoolean)recv.funcall(getRuby().intern("[]"), (RubyObject[])argsList.toArray(new RubyObject[argsList.size()])); switch (node.nd_mid().intValue()) { case 0: /* OR */ if (val.isTrue()) { return val; } val = (RubyBoolean)eval(self, rval); break; case 1: /* AND */ if (val.isFalse()) { return val; } val = (RubyBoolean)eval(self, rval); break; default: val = (RubyBoolean)val.funcall((RubyId)node.nd_mid(), eval(self, rval)); } args[args.length - 1] = val; return recv.funcall(getRuby().intern("[]="), args); case NODE_OP_ASGN2: ID id = node.nd_next().nd_vid(); recv = eval(self, node.nd_recv()); val = (RubyBoolean)recv.funcall((RubyId)id, (RubyObject[])null); switch (node.nd_next().nd_mid().intValue()) { case 0: /* OR */ if (val.isTrue()) { return val; } val = (RubyBoolean)eval(self, node.nd_value()); break; case 1: /* AND */ if (val.isFalse()) { return val; } val = (RubyBoolean)eval(self, node.nd_value()); break; default: val = (RubyBoolean)val.funcall((RubyId)node.nd_mid(), eval(self, node.nd_value())); } // HACK +++ val = (RubyBoolean)recv.funcall((RubyId)node.nd_next().nd_aid(), val); // HACK --- return val; case NODE_OP_ASGN_AND: cond = (RubyBoolean)eval(self, node.nd_head()); if (cond.isFalse()) { return cond; } node = node.nd_value(); break; case NODE_OP_ASGN_OR: cond = (RubyBoolean)eval(self, node.nd_head()); if ((node.nd_aid() != null && !self.isInstanceVarDefined((RubyId)node.nd_aid())) || cond.isFalse()) { node = node.nd_value(); break; } return cond; case NODE_MASGN: return massign(self, node, eval(self, node.nd_value()), false); case NODE_LASGN: // if (ruby.ruby_scope.local_vars == null) { // rb_bug("unexpected local variable assignment"); // } result = eval(self, node.nd_value()); getRuby().rubyScope.setLocalVars(node.nd_cnt(), result); return result; case NODE_DASGN: result = eval(self, node.nd_value()); RubyVarmap.assign(ruby, (RubyId)node.nd_vid(), result); return result; case NODE_DASGN_CURR: result = eval(self, node.nd_value()); RubyVarmap.assignCurrent(ruby, (RubyId)node.nd_vid(), result); return result; case NODE_GASGN: result = eval(self, node.nd_value()); ((RubyGlobalEntry)node.nd_entry()).set(result); return result; case NODE_IASGN: result = eval(self, node.nd_value()); self.setInstanceVar((RubyId)node.nd_vid(), result); return result; case NODE_CDECL: if (ruby_class == null) { throw new RubyTypeException("no class/module to define constant"); } result = eval(self, node.nd_value()); ruby_class.setConstant((RubyId)node.nd_vid(), result); return result; case NODE_CVDECL: if (ruby_cbase == null) { throw new RubyTypeException("no class/module to define class variable"); } result = eval(self, node.nd_value()); if (ruby_cbase.isSingleton()) { ruby_cbase.getInstanceVar("__attached__").getClassVarSingleton().declareClassVar((RubyId)node.nd_vid(), result); return result; } ruby_cbase.declareClassVar((RubyId)node.nd_vid(), result); return result; case NODE_CVASGN: result = eval(self, node.nd_value()); self.getClassVarSingleton().setClassVar((RubyId)node.nd_vid(), result); return result; case NODE_LVAR: //if (getRuby().ruby_scope.local_vars == null) { // rb_bug("unexpected local variable"); // } return (RubyObject)getRuby().rubyScope.getLocalVars(node.nd_cnt()); case NODE_DVAR: return getDynamicVars().getRef((RubyId)node.nd_vid()); case NODE_GVAR: return ((RubyGlobalEntry)node.nd_entry()).get(); case NODE_IVAR: return self.getInstanceVar((RubyId)node.nd_vid()); case NODE_CONST: return getConstant((NODE)rubyFrame.getCbase(), (RubyId)node.nd_vid(), self); case NODE_CVAR: /* normal method */ if (ruby_cbase == null) { return self.getRubyClass().getClassVar((RubyId)node.nd_vid()); } if (!ruby_cbase.isSingleton()) { return ruby_cbase.getClassVar((RubyId)node.nd_vid()); } return ruby_cbase.getInstanceVar("__attached__").getClassVarSingleton().getClassVar((RubyId)node.nd_vid()); case NODE_CVAR2: /* singleton method */ return self.getClassVarSingleton().getClassVar((RubyId)node.nd_vid()); case NODE_BLOCK_ARG: if (ruby.rubyScope.getLocalVars() == null) { throw new RuntimeException("BUG: unexpected block argument"); } if (isBlockGiven()) { result = getRuby().getNil(); // Create Proc object ruby.rubyScope.setLocalVars(node.nd_cnt(), result); return result; } else { return getRuby().getNil(); } case NODE_COLON2: value = eval(self, node.nd_head()); if (value instanceof RubyModule) { return ((RubyModule)value).getConstant((RubyId)node.nd_mid()); } else { return value.funcall((RubyId)node.nd_mid()); } case NODE_COLON3: return getRuby().getObjectClass().getConstant((RubyId)node.nd_mid()); case NODE_NTH_REF: // return rom.rb_reg_nth_match(node.nd_nth(), MATCH_DATA); return null; case NODE_BACK_REF: /*switch ((char)node.nd_nth()) { case '&': return rom.rb_reg_last_match(MATCH_DATA); case '`': return rom.rb_reg_match_pre(MATCH_DATA); case '\'': return rom.rb_reg_match_post(MATCH_DATA); case '+': return rom.rb_reg_match_last(MATCH_DATA); default: rom.rb_bug("unexpected back-ref"); }*/ case NODE_HASH: RubyHash hash = RubyHash.m_newHash(ruby); NODE list = node.nd_head(); while(list != null) { RubyObject key = eval(self, list.nd_head()); list = list.nd_next(); if (list == null) { // HACK +++ throw new RubyArgumentException("odd number list for Hash"); // HACK --- } value = eval(self, list.nd_head()); hash.m_aset(key, value); list = list.nd_next(); } return hash; case NODE_ZARRAY: /* zero length list */ return RubyArray.m_newArray(getRuby()); case NODE_ARRAY: ArrayList ary = new ArrayList(node.nd_alen()); for (; node != null ; node = node.nd_next()) { ary.add(eval(self, node.nd_head())); } return RubyArray.m_newArray(getRuby(), ary); case NODE_STR: return ((RubyObject)node.nd_lit()).m_to_s(); case NODE_DSTR: case NODE_DXSTR: case NODE_DREGX: case NODE_DREGX_ONCE:/* NODE list = node.nd_next(); RubyString str = RubyString.m_newString(getRuby(), (RubyObject)node.nd_lit()); RubyString str2; while (list != null) { if (list.nd_head() != null) { switch (list.nd_head().nd_type()) { case NODE_STR: str2 = (RubyString)list.nd_head().nd_lit(); break; case NODE_EVSTR: result = ruby_errinfo; ruby_errinfo = Qnil; ruby_sourceline = nd_line(node); ruby_in_eval++; list.nd_head(compile(list.nd_head().nd_lit(), ruby_sourcefile,ruby_sourceline)); ruby_eval_tree = 0; ruby_in_eval--; if (ruby_nerrs > 0) { compile_error("string expansion"); } if (!NIL_P(result)) ruby_errinfo = result; /* fall through *//* default: str2 = (RubyString)rom.rb_obj_as_string(eval(list.nd_head())); break; } str.append(str2); str.infectObject(str2); } list = list.nd_next(); } switch (node.nd_type()) { case NODE_DREGX: return rom.rb_reg_new(str.getString(), str.getString().length(), node.nd_cflag()); case NODE_DREGX_ONCE: /* regexp expand once *//* VALUE result = rom.rb_reg_new(str.getString(), str.getString().length(), node.nd_cflag()); node.nd_set_type(NODE_LIT); node.nd_lit(result); return result; case NODE_DXSTR: return rom.rb_funcall(this, '`', 1, str); default: return str; }*/ return null; case NODE_XSTR: return self.funcall(getRuby().intern("`"), (RubyObject)node.nd_lit()); case NODE_LIT: return (RubyObject)node.nd_lit(); case NODE_ATTRSET: if (rubyFrame.getArgs().size() != 1) { throw new RubyArgumentException("wrong # of arguments(" + rubyFrame.getArgs().size() + "for 1)"); } return self.setInstanceVar((RubyId)node.nd_vid(), (RubyObject)rubyFrame.getArgs().get(0)); case NODE_DEFN: if (node.nd_defn() != null) { int noex; if (ruby_class == null) { throw new RubyTypeException("no class to add method"); } //if (ruby_class == getRuby().getObjectClass() && node.nd_mid() == init) { // rom.rb_warn("redefining Object#initialize may cause infinite loop"); //} //if (node.nd_mid() == __id__ || node.nd_mid() == __send__) { // rom.rb_warn("redefining `%s' may cause serious problem", ((RubyId)node.nd_mid()).toName()); //} // ruby_class.setFrozen(true); NODE body = ruby_class.searchMethod((RubyId)node.nd_mid()); RubyObject origin = ruby_class.getMethodOrigin((RubyId)node.nd_mid()); if (body != null){ // if (ruby_verbose.isTrue() && ruby_class == origin && body.nd_cnt() == 0) { // rom.rb_warning("discarding old %s", ((RubyId)node.nd_mid()).toName()); // } // if (node.nd_noex() != 0) { /* toplevel */ /* should upgrade to rb_warn() if no super was called inside? */ // rom.rb_warning("overriding global function `%s'", ((RubyId)node.nd_mid()).toName()); // } } if (isScope(SCOPE_PRIVATE) || node.nd_mid().equals(ruby.intern("initialize"))) { noex = NOEX_PRIVATE; } else if (isScope(SCOPE_PROTECTED)) { noex = NOEX_PROTECTED; } else if (ruby_class == getRuby().getObjectClass()) { noex = node.nd_noex(); } else { noex = NOEX_PUBLIC; } if (body != null && origin == ruby_class && (body.nd_noex() & NOEX_UNDEF) != 0) { noex |= NOEX_UNDEF; } NODE defn = node.nd_defn().copyNodeScope(ruby_cref); ruby_class.addMethod((RubyId)node.nd_mid(), defn, noex); // rb_clear_cache_by_id(node.nd_mid()); if (scope_vmode == SCOPE_MODFUNC) { ruby_class.getSingletonClass().addMethod((RubyId)node.nd_mid(), defn, NOEX_PUBLIC); ruby_class.funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } if (ruby_class.isSingleton()) { ruby_class.getInstanceVar("__attached__").funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } else { ruby_class.funcall(getRuby().intern("method_added"), ((RubyId)node.nd_mid()).toSymbol()); } } return getRuby().getNil(); case NODE_DEFS: if (node.nd_defn() != null) { recv = eval(self, node.nd_recv()); if (getRuby().getSecurityLevel() >= 4 && !recv.isTaint()) { throw new RubySecurityException("Insecure; can't define singleton method"); } /*if (FIXNUM_P(recv) || SYMBOL_P(recv)) { rb_raise(rb_eTypeError, "can't define singleton method \"%s\" for %s", rb_id2name(node.nd_mid()), rb_class2name(CLASS_OF(recv))); }*/ // not needed in jruby if (recv.isFrozen()) { throw new RubyFrozenException("object"); } rubyClass = recv.getSingletonClass(); NODE body = (NODE)rubyClass.getMethods().get((RubyId)node.nd_mid()); if (body != null) { if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("redefining method prohibited"); } /*if (RTEST(ruby_verbose)) { rb_warning("redefine %s", rb_id2name(node.nd_mid())); }*/ } NODE defn = node.nd_defn().copyNodeScope(ruby_cref); defn.nd_rval(ruby_cref); rubyClass.addMethod((RubyId)node.nd_mid(), defn, NOEX_PUBLIC | (body != null ? body.nd_noex() & NOEX_UNDEF : 0)); // rb_clear_cache_by_id(node.nd_mid()); recv.funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } return getRuby().getNil(); case NODE_UNDEF: if (ruby_class == null) { throw new RubyTypeException("no class to undef method"); } ruby_class.undef((RubyId)node.nd_mid()); return getRuby().getNil(); case NODE_ALIAS: if (ruby_class == null) { throw new RubyTypeException("no class to make alias"); } ruby_class.aliasMethod((RubyId)node.nd_new(), (RubyId)node.nd_old()); ruby_class.funcall(getRuby().intern("method_added"), ((RubyId)node.nd_mid()).toSymbol()); return getRuby().getNil(); case NODE_VALIAS: RubyGlobalEntry.getGlobalEntry((RubyId)node.nd_old()).alias((RubyId)node.nd_new()); return getRuby().getNil(); case NODE_CLASS: RubyModule superClass; if (ruby_class == null) { throw new RubyTypeException("no outer class/module"); } if (node.nd_super() != null) { superClass = getSuperClass(self, node.nd_super()); } else { superClass = null; } rubyClass = null; // if ((ruby_class == getRuby().getObjectClass()) && rb_autoload_defined(node.nd_cname())) { // rb_autoload_load(node.nd_cname()); // } if (ruby_class.isConstantDefined((RubyId)node.nd_cname())) { rubyClass = (RubyClass)ruby_class.getConstant((RubyId)node.nd_cname()); } if (rubyClass != null) { if (!rubyClass.isClass()) { throw new RubyTypeException(((RubyId)node.nd_cname()).toName() + " is not a class"); } if (superClass != null) { RubyModule tmp = rubyClass.getSuperClass(); if (tmp.isSingleton()) { tmp = tmp.getSuperClass(); } while (tmp.isIncluded()) { tmp = tmp.getSuperClass(); } if (tmp != superClass) { superClass = tmp; //goto override_class; if (superClass == null) { superClass = getRuby().getObjectClass(); } rubyClass = getRuby().defineClassId((RubyId)node.nd_cname(), (RubyClass)superClass); ruby_class.setConstant((RubyId)node.nd_cname(), rubyClass); rubyClass.setClassPath((RubyClass)ruby_class, ((RubyId)node.nd_cname()).toName()); // end goto } } if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("extending class prohibited"); } // rb_clear_cache(); } else { //override_class: if (superClass == null) { superClass = getRuby().getObjectClass(); } rubyClass = getRuby().defineClassId((RubyId)node.nd_cname(), (RubyClass)superClass); ruby_class.setConstant((RubyId)node.nd_cname(), rubyClass); rubyClass.setClassPath((RubyClass)ruby_class, ((RubyId)node.nd_cname()).toName()); } if (ruby_wrapper != null) { rubyClass.getSingletonClass().includeModule(ruby_wrapper); rubyClass.includeModule(ruby_wrapper); } return setupModule(rubyClass, node.nd_body()); case NODE_MODULE: if (ruby_class == null) { throw new RubyTypeException("no outer class/module"); } RubyModule module = null; if ((ruby_class == getRuby().getObjectClass()) && getRuby().isAutoloadDefined((RubyId)node.nd_cname())) { // getRuby().rb_autoload_load(node.nd_cname()); } if (ruby_class.isConstantDefined((RubyId)node.nd_cname())) { module = (RubyModule)ruby_class.getConstant((RubyId)node.nd_cname()); } if (module != null) { if (!(module instanceof RubyModule)) { throw new RubyTypeException(((RubyId)node.nd_cname()).toName() + " is not a module"); } if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("extending module prohibited"); } } else { module = getRuby().defineModuleId((RubyId)node.nd_cname()); ruby_class.setConstant((RubyId)node.nd_cname(), module); module.setClassPath(ruby_class, ((RubyId)node.nd_cname()).toName()); } if (ruby_wrapper != null) { module.getSingletonClass().includeModule(ruby_wrapper); module.includeModule(ruby_wrapper); } return setupModule(module, node.nd_body()); case NODE_SCLASS: rubyClass = (RubyClass)eval(self, node.nd_recv()); if (rubyClass.isSpecialConst()) { throw new RubyTypeException("no virtual class for " + rubyClass.getRubyClass().toName()); } if (getRuby().getSecurityLevel() >= 4 && !rubyClass.isTaint()) { throw new RubySecurityException("Insecure: can't extend object"); } if (rubyClass.getRubyClass().isSingleton()) { // rb_clear_cache(); } rubyClass = rubyClass.getSingletonClass(); if (ruby_wrapper != null) { rubyClass.getSingletonClass().includeModule(ruby_wrapper); rubyClass.includeModule(ruby_wrapper); } return setupModule(rubyClass, node.nd_body()); case NODE_DEFINED: // String buf; // String desc = is_defined(self, node.nd_head(), buf); // // if (desc) { // result = rb_str_new2(desc); // } else { // result = Qnil; // } case NODE_NEWLINE: // ruby_sourcefile = node.nd_file; // ruby_sourceline = node.nd_nth(); // if (trace_func) { // call_trace_func("line", ruby_sourcefile, ruby_sourceline, self, // ruby_frame.last_func(), // ruby_frame.last_class()); // } node = node.nd_next(); break; default: // rom.rb_bug("unknown node type %d", nd_type(node)); } } }
public RubyObject eval(RubyObject self, NODE n) { NODE node = n; RubyBoolean cond = null; RubyObject[] args = null; RubyObject value = null; RubyObject result = null; RubyModule rubyClass = null; // int state; // RubyOriginalMethods rom = getRuby().getOriginalMethods(); while (true) { if (node == null) { return getRuby().getNil(); } switch (node.nd_type()) { case NODE_BLOCK: while (node.nd_next() != null) { eval(self, node.nd_head()); node = node.nd_next(); } node = node.nd_head(); break; case NODE_POSTEXE: // rb_f_END(); node.nd_set_type(NODE_NIL); /* exec just once */ return getRuby().getNil(); /* begin .. end without clauses */ case NODE_BEGIN: node = node.nd_body(); break; /* nodes for speed-up(default match) */ case NODE_MATCH: //return rom.rb_reg_match2(node.nd_head().nd_lit()); return getRuby().getNil(); /* nodes for speed-up(literal match) */ case NODE_MATCH2: //return rom.rb_reg_match(eval(node.nd_recv()), eval(node.nd_value())); return getRuby().getNil(); /* nodes for speed-up(literal match) */ case NODE_MATCH3: //VALUE r = eval(node.nd_recv()); //VALUE l = eval(node.nd_value()); //if (r instanceof RubyString) { // return rom.rb_reg_match(l, r); //} else { // return rom.rb_funcall(r, match, 1, l); //} return getRuby().getNil(); /* node for speed-up(top-level loop for -n/-p) */ case NODE_OPT_N: while (true) { try { // while (!rb_gets().isNil() false) { // HACK +++ if (true) { // HACK --- try { eval(self, node.nd_body()); } catch (RedoException rExcptn) { } } break; } catch (NextException nExcptn) { } catch (BreakException bExcptn) { break; } } return getRuby().getNil(); case NODE_SELF: return self; case NODE_NIL: return getRuby().getNil(); case NODE_TRUE: return getRuby().getTrue(); case NODE_FALSE: return getRuby().getFalse(); case NODE_IF: // ruby_sourceline = node.nd_line(); cond = (RubyBoolean)eval(self, node.nd_cond()); if (cond.isTrue()) { node = node.nd_body(); } else { node = node.nd_else(); } break; case NODE_WHEN: while (node != null) { NODE tag; if (node.nd_type() != NODE_WHEN) { break; } tag = node.nd_head(); while (tag != null) {/* if (trace_func) { call_trace_func("line", tag->nd_file, nd_line(tag), self, ruby_frame->last_func, ruby_frame->last_class); }*/ // ruby_sourcefile = tag.nd_file; // ruby_sourceline = tag.nd_line(); if (tag.nd_head().nd_type() == NODE_WHEN) { RubyObject obj = eval(self, tag.nd_head().nd_head()); if (!(obj instanceof RubyArray)) { obj = RubyArray.m_newArray(getRuby(), obj); } for (int i = 0; i < ((RubyArray)obj).length(); i++) { if (((RubyBoolean)((RubyArray)obj).entry(i)).isTrue()) { node = node.nd_body(); break; } } tag = tag.nd_next(); continue; } if (((RubyBoolean)eval(self, tag.nd_head())).isTrue()) { node = node.nd_body(); break; } tag = tag.nd_next(); } node = node.nd_next(); } return getRuby().getNil(); case NODE_CASE: RubyObject obj = eval(self, node.nd_head()); node = node.nd_body(); while (node != null) { NODE tag; if (node.nd_type() != NODE_WHEN) { break; } tag = node.nd_head(); while (tag != null) {/* if (trace_func) { call_trace_func("line", tag->nd_file, nd_line(tag), self, ruby_frame->last_func, ruby_frame->last_class); } ruby_sourcefile = tag->nd_file; ruby_sourceline = nd_line(tag);*/ if (tag.nd_head().nd_type() == NODE_WHEN) { RubyObject obj2 = eval(self, tag.nd_head().nd_head()); if (!(obj2 instanceof RubyArray)) { obj2 = RubyArray.m_newArray(getRuby(), obj2); } for (int i = 0; i < ((RubyArray)obj).length(); i++) { RubyBoolean eqq = (RubyBoolean)((RubyArray)obj2).entry(i).funcall(getRuby().intern("==="), obj); if (eqq.isTrue()) { node = node.nd_body(); break; } } tag = tag.nd_next(); continue; } if (((RubyBoolean)eval(self, tag.nd_head()).funcall(getRuby().intern("==="), obj)).isTrue()) { node = node.nd_body(); break; } tag = tag.nd_next(); } node = node.nd_next(); } return getRuby().getNil(); case NODE_WHILE: while (eval(self, node.nd_cond()).isTrue()) { while (true) { try { eval(self, node.nd_body()); break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { break; } catch (BreakException bExcptn) { return getRuby().getNil(); } } } return getRuby().getNil(); case NODE_UNTIL: while (eval(self, node.nd_cond()).isFalse()) { while (true) { try { eval(self, node.nd_body()); break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { break; } catch (BreakException bExcptn) { return getRuby().getNil(); } } } return getRuby().getNil(); case NODE_BLOCK_PASS: //return block_pass(node); return null; case NODE_ITER: case NODE_FOR: rubyBlock.push(node.nd_var(), node.nd_body(), self); rubyIter.push(Iter.ITER_PRE); while (true) { try { if (node.nd_type() == NODE_ITER) { result = eval(self, node.nd_iter()); } else { // String file = // int line = rubyBlock.flags &= ~RubyBlock.BLOCK_D_SCOPE; RubyBlock tmpBlock = beginCallargs(); RubyObject recv = eval(self, node.nd_iter()); endCallArgs(tmpBlock); // = file; // = line; result = recv.getRubyClass().call(recv, ruby.intern("each"), null, 0); } break; } catch (RetryException rExcptn) { } catch (ReturnException rExcptn) { result = rExcptn.getReturnValue(); break; } catch (BreakException bExcptn) { result = ruby.getNil(); break; } } rubyIter.pop(); rubyBlock.pop(); return result; case NODE_BREAK: throw new BreakException(); case NODE_NEXT: throw new NextException(); case NODE_REDO: throw new RedoException(); case NODE_RETRY: throw new RetryException(); case NODE_RESTARGS: result = eval(self, node.nd_head()); if (!(result instanceof RubyArray)) { result = obj = RubyArray.m_newArray(getRuby(), result); } return result; case NODE_YIELD: if (node.nd_stts() != null) { result = eval(self, node.nd_stts()); if (node.nd_stts().nd_type() == NODE_RESTARGS && ((RubyArray)result).length() == 1) { result = ((RubyArray)result).entry(0); } } else { result = ruby.getNil(); } return yield0(result, null, null, false); case NODE_RESCUE:/* retry_entry: { volatile VALUE e_info = ruby_errinfo; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, node->nd_head); } POP_TAG(); if (state == TAG_RAISE) { NODE * volatile resq = node->nd_resq; ruby_sourceline = nd_line(node); while (resq) { if (handle_rescue(self, resq)) { state = 0; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, resq->nd_body); } POP_TAG(); if (state == TAG_RETRY) { state = 0; ruby_errinfo = Qnil; goto retry_entry; } if (state != TAG_RAISE) { ruby_errinfo = e_info; } break; } resq = resq->nd_head; /* next rescue */ /** } * } * else if (node->nd_else) { /* else clause given *//* if (!state) { /* no exception raised *//* result = rb_eval(self, node->nd_else); } } if (state) JUMP_TAG(state); } break;*/ case NODE_ENSURE:/* PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = eval(node.nd_head()); } POP_TAG(); if (node.nd_ensr()) { VALUE retval = prot_tag->retval; /* save retval *//* VALUE errinfo = ruby_errinfo; rb_eval(self, node->nd_ensr); return_value(retval); ruby_errinfo = errinfo; } if (state) JUMP_TAG(state); break;*/ case NODE_AND: cond = (RubyBoolean)eval(self, node.nd_1st()); if (cond.isFalse()) { return cond; } node = node.nd_2nd(); break; case NODE_OR: cond = (RubyBoolean)eval(self, node.nd_1st()); if (cond.isTrue()) { return cond; } node = node.nd_2nd(); break; case NODE_NOT: return RubyBoolean.m_newBoolean(getRuby(), eval(self, node.nd_1st()).isFalse()); case NODE_DOT2: case NODE_DOT3: result = RubyRange.m_newRange(getRuby(), eval(self, node.nd_beg()), eval(self, node.nd_end()), node.nd_type() == NODE_DOT3); if (node.nd_state() != 0) { return result; } if (node.nd_beg().nd_type() == NODE_LIT && (node.nd_beg().nd_lit() instanceof RubyFixnum) && node.nd_end().nd_type() == NODE_LIT && (node.nd_end().nd_lit() instanceof RubyFixnum)) { node.nd_set_type(NODE_LIT); node.nd_lit(result); } else { node.nd_state(1L); } return result; case NODE_FLIP2: /* like AWK */ /*if (ruby_scope->local_vars == 0) { rb_bug("unexpected local variable"); }*/ if (ruby.rubyScope.getLocalVars(node.nd_cnt()).isFalse()) { if (eval(self, node.nd_beg()).isTrue()) { ruby.rubyScope.setLocalVars(node.nd_cnt(), eval(self, node.nd_end()).isTrue() ? ruby.getFalse() : ruby.getTrue()); result = ruby.getTrue(); } else { result = ruby.getFalse(); } } else { if (eval(self, node.nd_end()).isTrue()) { ruby.rubyScope.setLocalVars(node.nd_cnt(), ruby.getFalse()); } result = ruby.getTrue(); } return result; case NODE_FLIP3: /* like SED */ /*if (ruby_scope->local_vars == 0) { rb_bug("unexpected local variable"); }*/ if (ruby.rubyScope.getLocalVars(node.nd_cnt()).isFalse()) { result = eval(self, node.nd_beg()).isTrue() ? ruby.getFalse() : ruby.getTrue(); ruby.rubyScope.setLocalVars(node.nd_cnt(), result); } else { if (eval(self, node.nd_end()).isTrue()) { ruby.rubyScope.setLocalVars(node.nd_cnt(), ruby.getFalse()); } result = ruby.getTrue(); } return result; case NODE_RETURN: if (node.nd_stts() != null) { result = eval(self, node.nd_stts()); } else { result = ruby.getNil(); } throw new ReturnException(result); case NODE_ARGSCAT: return ((RubyArray)eval(self, node.nd_head())).m_concat(eval(self, node.nd_body())); case NODE_ARGSPUSH: return ((RubyArray)eval(self, node.nd_head()).m_dup()).push(eval(self, node.nd_body())); case NODE_CALL: // TMP_PROTECT; RubyBlock tmpBlock = beginCallargs(); RubyObject recv = eval(self, node.nd_recv()); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); return recv.getRubyClass().call(recv, (RubyId)node.nd_mid(), args, 0); case NODE_FCALL: // TMP_PROTECT; tmpBlock = beginCallargs(); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); return self.getRubyClass().call(self, (RubyId)node.nd_mid(), args, 1); case NODE_VCALL: return self.getRubyClass().call(self, (RubyId)node.nd_mid(), null, 2); case NODE_SUPER: case NODE_ZSUPER: // TMP_PROTECT; if (rubyFrame.getLastClass() == null) { throw new RubyNameException("superclass method '" + rubyFrame.getLastFunc().toName() + "' disabled"); } if (node.nd_type() == NODE_ZSUPER) { List argsList = rubyFrame.getArgs(); args = (RubyObject[])argsList.toArray(new RubyObject[argsList.size()]); } else { tmpBlock = beginCallargs(); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); } rubyIter.push(rubyIter.getIter() != Iter.ITER_NOT ? Iter.ITER_PRE : Iter.ITER_NOT); result = rubyFrame.getLastClass().getSuperClass().call(rubyFrame.getSelf(), rubyFrame.getLastFunc(), args, 3); rubyIter.pop(); return result; case NODE_SCOPE: NODE saved_cref = null; Frame frame = rubyFrame; frame.setTmp(rubyFrame); rubyFrame = frame; ruby.rubyScope.push(); if (node.nd_rval() != null) { saved_cref = ruby_cref; ruby_cref = (NODE)node.nd_rval(); rubyFrame.setCbase(node.nd_rval()); } if (node.nd_tbl() != null) { List tmp = Collections.nCopies(node.nd_tbl()[0].intValue() + 1, ruby.getNil()); ShiftableList vars = new ShiftableList(new ArrayList(tmp)); vars.set(0, (VALUE)node); vars.shift(1); getRuby().rubyScope.setLocalVars(vars); getRuby().rubyScope.setLocalTbl(node.nd_tbl()); } else { getRuby().rubyScope.setLocalVars(null); getRuby().rubyScope.setLocalTbl(null); } result = eval(self, node.nd_next()); ruby.rubyScope.pop(); rubyFrame = frame.getTmp(); if (saved_cref != null) { ruby_cref = saved_cref; } return result; case NODE_OP_ASGN1: // TMP_PROTECT; recv = eval(self, node.nd_recv()); NODE rval = node.nd_args().nd_head(); args = setupArgs(self, node.nd_args().nd_next()); ArrayList argsList = new ArrayList(Arrays.asList(args)); argsList.remove(args.length - 1); RubyBoolean val = (RubyBoolean)recv.funcall(getRuby().intern("[]"), (RubyObject[])argsList.toArray(new RubyObject[argsList.size()])); switch (node.nd_mid().intValue()) { case 0: /* OR */ if (val.isTrue()) { return val; } val = (RubyBoolean)eval(self, rval); break; case 1: /* AND */ if (val.isFalse()) { return val; } val = (RubyBoolean)eval(self, rval); break; default: val = (RubyBoolean)val.funcall((RubyId)node.nd_mid(), eval(self, rval)); } args[args.length - 1] = val; return recv.funcall(getRuby().intern("[]="), args); case NODE_OP_ASGN2: ID id = node.nd_next().nd_vid(); recv = eval(self, node.nd_recv()); val = (RubyBoolean)recv.funcall((RubyId)id, (RubyObject[])null); switch (node.nd_next().nd_mid().intValue()) { case 0: /* OR */ if (val.isTrue()) { return val; } val = (RubyBoolean)eval(self, node.nd_value()); break; case 1: /* AND */ if (val.isFalse()) { return val; } val = (RubyBoolean)eval(self, node.nd_value()); break; default: val = (RubyBoolean)val.funcall((RubyId)node.nd_mid(), eval(self, node.nd_value())); } // HACK +++ val = (RubyBoolean)recv.funcall((RubyId)node.nd_next().nd_aid(), val); // HACK --- return val; case NODE_OP_ASGN_AND: cond = (RubyBoolean)eval(self, node.nd_head()); if (cond.isFalse()) { return cond; } node = node.nd_value(); break; case NODE_OP_ASGN_OR: cond = (RubyBoolean)eval(self, node.nd_head()); if ((node.nd_aid() != null && !self.isInstanceVarDefined((RubyId)node.nd_aid())) || cond.isFalse()) { node = node.nd_value(); break; } return cond; case NODE_MASGN: return massign(self, node, eval(self, node.nd_value()), false); case NODE_LASGN: // if (ruby.ruby_scope.local_vars == null) { // rb_bug("unexpected local variable assignment"); // } result = eval(self, node.nd_value()); getRuby().rubyScope.setLocalVars(node.nd_cnt(), result); return result; case NODE_DASGN: result = eval(self, node.nd_value()); RubyVarmap.assign(ruby, (RubyId)node.nd_vid(), result); return result; case NODE_DASGN_CURR: result = eval(self, node.nd_value()); RubyVarmap.assignCurrent(ruby, (RubyId)node.nd_vid(), result); return result; case NODE_GASGN: result = eval(self, node.nd_value()); ((RubyGlobalEntry)node.nd_entry()).set(result); return result; case NODE_IASGN: result = eval(self, node.nd_value()); self.setInstanceVar((RubyId)node.nd_vid(), result); return result; case NODE_CDECL: if (ruby_class == null) { throw new RubyTypeException("no class/module to define constant"); } result = eval(self, node.nd_value()); ruby_class.setConstant((RubyId)node.nd_vid(), result); return result; case NODE_CVDECL: if (ruby_cbase == null) { throw new RubyTypeException("no class/module to define class variable"); } result = eval(self, node.nd_value()); if (ruby_cbase.isSingleton()) { ruby_cbase.getInstanceVar("__attached__").getClassVarSingleton().declareClassVar((RubyId)node.nd_vid(), result); return result; } ruby_cbase.declareClassVar((RubyId)node.nd_vid(), result); return result; case NODE_CVASGN: result = eval(self, node.nd_value()); self.getClassVarSingleton().setClassVar((RubyId)node.nd_vid(), result); return result; case NODE_LVAR: //if (getRuby().ruby_scope.local_vars == null) { // rb_bug("unexpected local variable"); // } return (RubyObject)getRuby().rubyScope.getLocalVars(node.nd_cnt()); case NODE_DVAR: return getDynamicVars().getRef((RubyId)node.nd_vid()); case NODE_GVAR: return ((RubyGlobalEntry)node.nd_entry()).get(); case NODE_IVAR: return self.getInstanceVar((RubyId)node.nd_vid()); case NODE_CONST: return getConstant((NODE)rubyFrame.getCbase(), (RubyId)node.nd_vid(), self); case NODE_CVAR: /* normal method */ if (ruby_cbase == null) { return self.getRubyClass().getClassVar((RubyId)node.nd_vid()); } if (!ruby_cbase.isSingleton()) { return ruby_cbase.getClassVar((RubyId)node.nd_vid()); } return ruby_cbase.getInstanceVar("__attached__").getClassVarSingleton().getClassVar((RubyId)node.nd_vid()); case NODE_CVAR2: /* singleton method */ return self.getClassVarSingleton().getClassVar((RubyId)node.nd_vid()); case NODE_BLOCK_ARG: if (ruby.rubyScope.getLocalVars() == null) { throw new RuntimeException("BUG: unexpected block argument"); } if (isBlockGiven()) { result = getRuby().getNil(); // Create Proc object ruby.rubyScope.setLocalVars(node.nd_cnt(), result); return result; } else { return getRuby().getNil(); } case NODE_COLON2: value = eval(self, node.nd_head()); if (value instanceof RubyModule) { return ((RubyModule)value).getConstant((RubyId)node.nd_mid()); } else { return value.funcall((RubyId)node.nd_mid()); } case NODE_COLON3: return getRuby().getObjectClass().getConstant((RubyId)node.nd_mid()); case NODE_NTH_REF: // return rom.rb_reg_nth_match(node.nd_nth(), MATCH_DATA); return null; case NODE_BACK_REF: /*switch ((char)node.nd_nth()) { case '&': return rom.rb_reg_last_match(MATCH_DATA); case '`': return rom.rb_reg_match_pre(MATCH_DATA); case '\'': return rom.rb_reg_match_post(MATCH_DATA); case '+': return rom.rb_reg_match_last(MATCH_DATA); default: rom.rb_bug("unexpected back-ref"); }*/ case NODE_HASH: RubyHash hash = RubyHash.m_newHash(ruby); NODE list = node.nd_head(); while(list != null) { RubyObject key = eval(self, list.nd_head()); list = list.nd_next(); if (list == null) { // HACK +++ throw new RubyArgumentException("odd number list for Hash"); // HACK --- } value = eval(self, list.nd_head()); hash.m_aset(key, value); list = list.nd_next(); } return hash; case NODE_ZARRAY: /* zero length list */ return RubyArray.m_newArray(getRuby()); case NODE_ARRAY: ArrayList ary = new ArrayList(node.nd_alen()); for (; node != null ; node = node.nd_next()) { ary.add(eval(self, node.nd_head())); } return RubyArray.m_newArray(getRuby(), ary); case NODE_STR: return ((RubyObject)node.nd_lit()).m_to_s(); case NODE_DSTR: case NODE_DXSTR: case NODE_DREGX: case NODE_DREGX_ONCE:/* NODE list = node.nd_next(); RubyString str = RubyString.m_newString(getRuby(), (RubyObject)node.nd_lit()); RubyString str2; while (list != null) { if (list.nd_head() != null) { switch (list.nd_head().nd_type()) { case NODE_STR: str2 = (RubyString)list.nd_head().nd_lit(); break; case NODE_EVSTR: result = ruby_errinfo; ruby_errinfo = Qnil; ruby_sourceline = nd_line(node); ruby_in_eval++; list.nd_head(compile(list.nd_head().nd_lit(), ruby_sourcefile,ruby_sourceline)); ruby_eval_tree = 0; ruby_in_eval--; if (ruby_nerrs > 0) { compile_error("string expansion"); } if (!NIL_P(result)) ruby_errinfo = result; /* fall through *//* default: str2 = (RubyString)rom.rb_obj_as_string(eval(list.nd_head())); break; } str.append(str2); str.infectObject(str2); } list = list.nd_next(); } switch (node.nd_type()) { case NODE_DREGX: return rom.rb_reg_new(str.getString(), str.getString().length(), node.nd_cflag()); case NODE_DREGX_ONCE: /* regexp expand once *//* VALUE result = rom.rb_reg_new(str.getString(), str.getString().length(), node.nd_cflag()); node.nd_set_type(NODE_LIT); node.nd_lit(result); return result; case NODE_DXSTR: return rom.rb_funcall(this, '`', 1, str); default: return str; }*/ return null; case NODE_XSTR: return self.funcall(getRuby().intern("`"), (RubyObject)node.nd_lit()); case NODE_LIT: return (RubyObject)node.nd_lit(); case NODE_ATTRSET: if (rubyFrame.getArgs().size() != 1) { throw new RubyArgumentException("wrong # of arguments(" + rubyFrame.getArgs().size() + "for 1)"); } return self.setInstanceVar((RubyId)node.nd_vid(), (RubyObject)rubyFrame.getArgs().get(0)); case NODE_DEFN: if (node.nd_defn() != null) { int noex; if (ruby_class == null) { throw new RubyTypeException("no class to add method"); } //if (ruby_class == getRuby().getObjectClass() && node.nd_mid() == init) { // rom.rb_warn("redefining Object#initialize may cause infinite loop"); //} //if (node.nd_mid() == __id__ || node.nd_mid() == __send__) { // rom.rb_warn("redefining `%s' may cause serious problem", ((RubyId)node.nd_mid()).toName()); //} // ruby_class.setFrozen(true); NODE body = ruby_class.searchMethod((RubyId)node.nd_mid()); RubyObject origin = ruby_class.getMethodOrigin((RubyId)node.nd_mid()); if (body != null){ // if (ruby_verbose.isTrue() && ruby_class == origin && body.nd_cnt() == 0) { // rom.rb_warning("discarding old %s", ((RubyId)node.nd_mid()).toName()); // } // if (node.nd_noex() != 0) { /* toplevel */ /* should upgrade to rb_warn() if no super was called inside? */ // rom.rb_warning("overriding global function `%s'", ((RubyId)node.nd_mid()).toName()); // } } if (isScope(SCOPE_PRIVATE) || node.nd_mid().equals(ruby.intern("initialize"))) { noex = NOEX_PRIVATE; } else if (isScope(SCOPE_PROTECTED)) { noex = NOEX_PROTECTED; } else if (ruby_class == getRuby().getObjectClass()) { noex = node.nd_noex(); } else { noex = NOEX_PUBLIC; } if (body != null && origin == ruby_class && (body.nd_noex() & NOEX_UNDEF) != 0) { noex |= NOEX_UNDEF; } NODE defn = node.nd_defn().copyNodeScope(ruby_cref); ruby_class.addMethod((RubyId)node.nd_mid(), defn, noex); // rb_clear_cache_by_id(node.nd_mid()); if (scope_vmode == SCOPE_MODFUNC) { ruby_class.getSingletonClass().addMethod((RubyId)node.nd_mid(), defn, NOEX_PUBLIC); ruby_class.funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } if (ruby_class.isSingleton()) { ruby_class.getInstanceVar("__attached__").funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } else { ruby_class.funcall(getRuby().intern("method_added"), ((RubyId)node.nd_mid()).toSymbol()); } } return getRuby().getNil(); case NODE_DEFS: if (node.nd_defn() != null) { recv = eval(self, node.nd_recv()); if (getRuby().getSecurityLevel() >= 4 && !recv.isTaint()) { throw new RubySecurityException("Insecure; can't define singleton method"); } /*if (FIXNUM_P(recv) || SYMBOL_P(recv)) { rb_raise(rb_eTypeError, "can't define singleton method \"%s\" for %s", rb_id2name(node.nd_mid()), rb_class2name(CLASS_OF(recv))); }*/ // not needed in jruby if (recv.isFrozen()) { throw new RubyFrozenException("object"); } rubyClass = recv.getSingletonClass(); NODE body = (NODE)rubyClass.getMethods().get((RubyId)node.nd_mid()); if (body != null) { if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("redefining method prohibited"); } /*if (RTEST(ruby_verbose)) { rb_warning("redefine %s", rb_id2name(node.nd_mid())); }*/ } NODE defn = node.nd_defn().copyNodeScope(ruby_cref); defn.nd_rval(ruby_cref); rubyClass.addMethod((RubyId)node.nd_mid(), defn, NOEX_PUBLIC | (body != null ? body.nd_noex() & NOEX_UNDEF : 0)); // rb_clear_cache_by_id(node.nd_mid()); recv.funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } return getRuby().getNil(); case NODE_UNDEF: if (ruby_class == null) { throw new RubyTypeException("no class to undef method"); } ruby_class.undef((RubyId)node.nd_mid()); return getRuby().getNil(); case NODE_ALIAS: if (ruby_class == null) { throw new RubyTypeException("no class to make alias"); } ruby_class.aliasMethod((RubyId)node.nd_new(), (RubyId)node.nd_old()); ruby_class.funcall(getRuby().intern("method_added"), ((RubyId)node.nd_mid()).toSymbol()); return getRuby().getNil(); case NODE_VALIAS: RubyGlobalEntry.getGlobalEntry((RubyId)node.nd_old()).alias((RubyId)node.nd_new()); return getRuby().getNil(); case NODE_CLASS: RubyModule superClass; if (ruby_class == null) { throw new RubyTypeException("no outer class/module"); } if (node.nd_super() != null) { superClass = getSuperClass(self, node.nd_super()); } else { superClass = null; } rubyClass = null; // if ((ruby_class == getRuby().getObjectClass()) && rb_autoload_defined(node.nd_cname())) { // rb_autoload_load(node.nd_cname()); // } if (ruby_class.isConstantDefined((RubyId)node.nd_cname())) { rubyClass = (RubyClass)ruby_class.getConstant((RubyId)node.nd_cname()); } if (rubyClass != null) { if (!rubyClass.isClass()) { throw new RubyTypeException(((RubyId)node.nd_cname()).toName() + " is not a class"); } if (superClass != null) { RubyModule tmp = rubyClass.getSuperClass(); if (tmp.isSingleton()) { tmp = tmp.getSuperClass(); } while (tmp.isIncluded()) { tmp = tmp.getSuperClass(); } if (tmp != superClass) { superClass = tmp; //goto override_class; if (superClass == null) { superClass = getRuby().getObjectClass(); } rubyClass = getRuby().defineClassId((RubyId)node.nd_cname(), (RubyClass)superClass); ruby_class.setConstant((RubyId)node.nd_cname(), rubyClass); rubyClass.setClassPath((RubyClass)ruby_class, ((RubyId)node.nd_cname()).toName()); // end goto } } if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("extending class prohibited"); } // rb_clear_cache(); } else { //override_class: if (superClass == null) { superClass = getRuby().getObjectClass(); } rubyClass = getRuby().defineClassId((RubyId)node.nd_cname(), (RubyClass)superClass); ruby_class.setConstant((RubyId)node.nd_cname(), rubyClass); rubyClass.setClassPath((RubyClass)ruby_class, ((RubyId)node.nd_cname()).toName()); } if (ruby_wrapper != null) { rubyClass.getSingletonClass().includeModule(ruby_wrapper); rubyClass.includeModule(ruby_wrapper); } return setupModule(rubyClass, node.nd_body()); case NODE_MODULE: if (ruby_class == null) { throw new RubyTypeException("no outer class/module"); } RubyModule module = null; if ((ruby_class == getRuby().getObjectClass()) && getRuby().isAutoloadDefined((RubyId)node.nd_cname())) { // getRuby().rb_autoload_load(node.nd_cname()); } if (ruby_class.isConstantDefined((RubyId)node.nd_cname())) { module = (RubyModule)ruby_class.getConstant((RubyId)node.nd_cname()); } if (module != null) { if (!(module instanceof RubyModule)) { throw new RubyTypeException(((RubyId)node.nd_cname()).toName() + " is not a module"); } if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("extending module prohibited"); } } else { module = getRuby().defineModuleId((RubyId)node.nd_cname()); ruby_class.setConstant((RubyId)node.nd_cname(), module); module.setClassPath(ruby_class, ((RubyId)node.nd_cname()).toName()); } if (ruby_wrapper != null) { module.getSingletonClass().includeModule(ruby_wrapper); module.includeModule(ruby_wrapper); } return setupModule(module, node.nd_body()); case NODE_SCLASS: rubyClass = (RubyClass)eval(self, node.nd_recv()); if (rubyClass.isSpecialConst()) { throw new RubyTypeException("no virtual class for " + rubyClass.getRubyClass().toName()); } if (getRuby().getSecurityLevel() >= 4 && !rubyClass.isTaint()) { throw new RubySecurityException("Insecure: can't extend object"); } if (rubyClass.getRubyClass().isSingleton()) { // rb_clear_cache(); } rubyClass = rubyClass.getSingletonClass(); if (ruby_wrapper != null) { rubyClass.getSingletonClass().includeModule(ruby_wrapper); rubyClass.includeModule(ruby_wrapper); } return setupModule(rubyClass, node.nd_body()); case NODE_DEFINED: // String buf; // String desc = is_defined(self, node.nd_head(), buf); // // if (desc) { // result = rb_str_new2(desc); // } else { // result = Qnil; // } case NODE_NEWLINE: // ruby_sourcefile = node.nd_file; // ruby_sourceline = node.nd_nth(); // if (trace_func) { // call_trace_func("line", ruby_sourcefile, ruby_sourceline, self, // ruby_frame.last_func(), // ruby_frame.last_class()); // } node = node.nd_next(); break; default: // rom.rb_bug("unknown node type %d", nd_type(node)); } } }
3,238,701
public RubyObject eval(RubyObject self, NODE n) { NODE node = n; RubyBoolean cond = null; RubyObject[] args = null; RubyObject value = null; RubyObject result = null; RubyModule rubyClass = null; // int state; // RubyOriginalMethods rom = getRuby().getOriginalMethods(); while (true) { if (node == null) { return getRuby().getNil(); } switch (node.nd_type()) { case NODE_BLOCK: while (node.nd_next() != null) { eval(self, node.nd_head()); node = node.nd_next(); } node = node.nd_head(); break; case NODE_POSTEXE: // rb_f_END(); node.nd_set_type(NODE_NIL); /* exec just once */ return getRuby().getNil(); /* begin .. end without clauses */ case NODE_BEGIN: node = node.nd_body(); break; /* nodes for speed-up(default match) */ case NODE_MATCH: //return rom.rb_reg_match2(node.nd_head().nd_lit()); return getRuby().getNil(); /* nodes for speed-up(literal match) */ case NODE_MATCH2: //return rom.rb_reg_match(eval(node.nd_recv()), eval(node.nd_value())); return getRuby().getNil(); /* nodes for speed-up(literal match) */ case NODE_MATCH3: //VALUE r = eval(node.nd_recv()); //VALUE l = eval(node.nd_value()); //if (r instanceof RubyString) { // return rom.rb_reg_match(l, r); //} else { // return rom.rb_funcall(r, match, 1, l); //} return getRuby().getNil(); /* node for speed-up(top-level loop for -n/-p) */ case NODE_OPT_N: while (true) { try { // while (!rb_gets().isNil() false) { // HACK +++ if (true) { // HACK --- try { eval(self, node.nd_body()); } catch (RedoException rExcptn) { } } break; } catch (NextException nExcptn) { } catch (BreakException bExcptn) { break; } } return getRuby().getNil(); case NODE_SELF: return self; case NODE_NIL: return getRuby().getNil(); case NODE_TRUE: return getRuby().getTrue(); case NODE_FALSE: return getRuby().getFalse(); case NODE_IF: // ruby_sourceline = node.nd_line(); cond = (RubyBoolean)eval(self, node.nd_cond()); if (cond.isTrue()) { node = node.nd_body(); } else { node = node.nd_else(); } break; case NODE_WHEN: while (node != null) { NODE tag; if (node.nd_type() != NODE_WHEN) { break; } tag = node.nd_head(); while (tag != null) {/* if (trace_func) { call_trace_func("line", tag->nd_file, nd_line(tag), self, ruby_frame->last_func, ruby_frame->last_class); }*/ // ruby_sourcefile = tag.nd_file; // ruby_sourceline = tag.nd_line(); if (tag.nd_head().nd_type() == NODE_WHEN) { RubyObject obj = eval(self, tag.nd_head().nd_head()); if (!(obj instanceof RubyArray)) { obj = RubyArray.m_newArray(getRuby(), obj); } for (int i = 0; i < ((RubyArray)obj).length(); i++) { if (((RubyBoolean)((RubyArray)obj).entry(i)).isTrue()) { node = node.nd_body(); break; } } tag = tag.nd_next(); continue; } if (((RubyBoolean)eval(self, tag.nd_head())).isTrue()) { node = node.nd_body(); break; } tag = tag.nd_next(); } node = node.nd_next(); } return getRuby().getNil(); case NODE_CASE: RubyObject obj = eval(self, node.nd_head()); node = node.nd_body(); while (node != null) { NODE tag; if (node.nd_type() != NODE_WHEN) { break; } tag = node.nd_head(); while (tag != null) {/* if (trace_func) { call_trace_func("line", tag->nd_file, nd_line(tag), self, ruby_frame->last_func, ruby_frame->last_class); } ruby_sourcefile = tag->nd_file; ruby_sourceline = nd_line(tag);*/ if (tag.nd_head().nd_type() == NODE_WHEN) { RubyObject obj2 = eval(self, tag.nd_head().nd_head()); if (!(obj2 instanceof RubyArray)) { obj2 = RubyArray.m_newArray(getRuby(), obj2); } for (int i = 0; i < ((RubyArray)obj).length(); i++) { RubyBoolean eqq = (RubyBoolean)((RubyArray)obj2).entry(i).funcall(getRuby().intern("==="), obj); if (eqq.isTrue()) { node = node.nd_body(); break; } } tag = tag.nd_next(); continue; } if (((RubyBoolean)eval(self, tag.nd_head()).funcall(getRuby().intern("==="), obj)).isTrue()) { node = node.nd_body(); break; } tag = tag.nd_next(); } node = node.nd_next(); } return getRuby().getNil(); case NODE_WHILE: while (eval(self, node.nd_cond()).isTrue()) { while (true) { try { eval(self, node.nd_body()); break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { break; } catch (BreakException bExcptn) { return getRuby().getNil(); } } } return getRuby().getNil(); case NODE_UNTIL: while (eval(self, node.nd_cond()).isFalse()) { while (true) { try { eval(self, node.nd_body()); break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { break; } catch (BreakException bExcptn) { return getRuby().getNil(); } } } return getRuby().getNil(); case NODE_BLOCK_PASS: //return block_pass(node); return null; case NODE_ITER: case NODE_FOR: rubyBlock.push(node.nd_var(), node.nd_body(), self); rubyIter.push(Iter.ITER_PRE); while (true) { try { if (node.nd_type() == NODE_ITER) { result = eval(self, node.nd_iter()); } else { // String file = // int line = rubyBlock.flags &= ~RubyBlock.BLOCK_D_SCOPE; RubyBlock tmpBlock = beginCallargs(); RubyObject recv = eval(self, node.nd_iter()); endCallArgs(tmpBlock); // = file; // = line; result = recv.getRubyClass().call(recv, ruby.intern("each"), null, 0); } break; } catch (RetryException rExcptn) { } catch (ReturnException rExcptn) { result = rExcptn.getReturnValue(); break; } catch (BreakException bExcptn) { result = ruby.getNil(); break; } } rubyIter.pop(); rubyBlock.pop(); return result; case NODE_BREAK: throw new BreakException(); case NODE_NEXT: throw new NextException(); case NODE_REDO: throw new RedoException(); case NODE_RETRY: throw new RetryException(); case NODE_RESTARGS: result = eval(self, node.nd_head()); if (!(result instanceof RubyArray)) { result = obj = RubyArray.m_newArray(getRuby(), result); } return result; case NODE_YIELD: if (node.nd_stts() != null) { result = eval(self, node.nd_stts()); if (node.nd_stts().nd_type() == NODE_RESTARGS && ((RubyArray)result).length() == 1) { result = ((RubyArray)result).entry(0); } } else { result = ruby.getNil(); } return yield0(result, null, null, false); case NODE_RESCUE:/* retry_entry: { volatile VALUE e_info = ruby_errinfo; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, node->nd_head); } POP_TAG(); if (state == TAG_RAISE) { NODE * volatile resq = node->nd_resq; ruby_sourceline = nd_line(node); while (resq) { if (handle_rescue(self, resq)) { state = 0; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, resq->nd_body); } POP_TAG(); if (state == TAG_RETRY) { state = 0; ruby_errinfo = Qnil; goto retry_entry; } if (state != TAG_RAISE) { ruby_errinfo = e_info; } break; } resq = resq->nd_head; /* next rescue */ /** } * } * else if (node->nd_else) { /* else clause given *//* if (!state) { /* no exception raised *//* result = rb_eval(self, node->nd_else); } } if (state) JUMP_TAG(state); } break;*/ case NODE_ENSURE:/* PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = eval(node.nd_head()); } POP_TAG(); if (node.nd_ensr()) { VALUE retval = prot_tag->retval; /* save retval *//* VALUE errinfo = ruby_errinfo; rb_eval(self, node->nd_ensr); return_value(retval); ruby_errinfo = errinfo; } if (state) JUMP_TAG(state); break;*/ case NODE_AND: cond = (RubyBoolean)eval(self, node.nd_1st()); if (cond.isFalse()) { return cond; } node = node.nd_2nd(); break; case NODE_OR: cond = (RubyBoolean)eval(self, node.nd_1st()); if (cond.isTrue()) { return cond; } node = node.nd_2nd(); break; case NODE_NOT: return RubyBoolean.m_newBoolean(getRuby(), eval(self, node.nd_1st()).isFalse()); case NODE_DOT2: case NODE_DOT3: result = RubyRange.m_newRange(getRuby(), eval(self, node.nd_beg()), eval(self, node.nd_end()), node.nd_type() == NODE_DOT3); if (node.nd_state() != 0) { return result; } if (node.nd_beg().nd_type() == NODE_LIT && (node.nd_beg().nd_lit() instanceof RubyFixnum) && node.nd_end().nd_type() == NODE_LIT && (node.nd_end().nd_lit() instanceof RubyFixnum)) { node.nd_set_type(NODE_LIT); node.nd_lit(result); } else { node.nd_state(1L); } return result; case NODE_FLIP2: /* like AWK */ /*if (ruby_scope->local_vars == 0) { rb_bug("unexpected local variable"); }*/ if (ruby.rubyScope.getLocalVars(node.nd_cnt()).isFalse()) { if (eval(self, node.nd_beg()).isTrue()) { ruby.rubyScope.setLocalVars(node.nd_cnt(), eval(self, node.nd_end()).isTrue() ? ruby.getFalse() : ruby.getTrue()); result = ruby.getTrue(); } else { result = ruby.getFalse(); } } else { if (eval(self, node.nd_end()).isTrue()) { ruby.rubyScope.setLocalVars(node.nd_cnt(), ruby.getFalse()); } result = ruby.getTrue(); } return result; case NODE_FLIP3: /* like SED */ /*if (ruby_scope->local_vars == 0) { rb_bug("unexpected local variable"); }*/ if (ruby.rubyScope.getLocalVars(node.nd_cnt()).isFalse()) { result = eval(self, node.nd_beg()).isTrue() ? ruby.getFalse() : ruby.getTrue(); ruby.rubyScope.setLocalVars(node.nd_cnt(), result); } else { if (eval(self, node.nd_end()).isTrue()) { ruby.rubyScope.setLocalVars(node.nd_cnt(), ruby.getFalse()); } result = ruby.getTrue(); } return result; case NODE_RETURN: if (node.nd_stts() != null) { result = eval(self, node.nd_stts()); } else { result = ruby.getNil(); } throw new ReturnException(result); case NODE_ARGSCAT: return ((RubyArray)eval(self, node.nd_head())).m_concat(eval(self, node.nd_body())); case NODE_ARGSPUSH: return ((RubyArray)eval(self, node.nd_head()).m_dup()).push(eval(self, node.nd_body())); case NODE_CALL: // TMP_PROTECT; RubyBlock tmpBlock = beginCallargs(); RubyObject recv = eval(self, node.nd_recv()); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); return recv.getRubyClass().call(recv, (RubyId)node.nd_mid(), args, 0); case NODE_FCALL: // TMP_PROTECT; tmpBlock = beginCallargs(); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); return self.getRubyClass().call(self, (RubyId)node.nd_mid(), args, 1); case NODE_VCALL: return self.getRubyClass().call(self, (RubyId)node.nd_mid(), null, 2); case NODE_SUPER: case NODE_ZSUPER: // TMP_PROTECT; if (rubyFrame.getLastClass() == null) { throw new RubyNameException("superclass method '" + rubyFrame.getLastFunc().toName() + "' disabled"); } if (node.nd_type() == NODE_ZSUPER) { List argsList = rubyFrame.getArgs(); args = (RubyObject[])argsList.toArray(new RubyObject[argsList.size()]); } else { tmpBlock = beginCallargs(); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); } rubyIter.push(rubyIter.getIter() != Iter.ITER_NOT ? Iter.ITER_PRE : Iter.ITER_NOT); result = rubyFrame.getLastClass().getSuperClass().call(rubyFrame.getSelf(), rubyFrame.getLastFunc(), args, 3); rubyIter.pop(); return result; case NODE_SCOPE: NODE saved_cref = null; Frame frame = rubyFrame; frame.setTmp(rubyFrame); rubyFrame = frame; ruby.rubyScope.push(); if (node.nd_rval() != null) { saved_cref = ruby_cref; ruby_cref = (NODE)node.nd_rval(); rubyFrame.setCbase(node.nd_rval()); } if (node.nd_tbl() != null) { List tmp = Collections.nCopies(node.nd_tbl()[0].intValue() + 1, ruby.getNil()); ShiftableList vars = new ShiftableList(new ArrayList(tmp)); vars.set(0, (VALUE)node); vars.shift(1); getRuby().rubyScope.setLocalVars(vars); getRuby().rubyScope.setLocalTbl(node.nd_tbl()); } else { getRuby().rubyScope.setLocalVars(null); getRuby().rubyScope.setLocalTbl(null); } result = eval(self, node.nd_next()); ruby.rubyScope.pop(); rubyFrame = frame.getTmp(); if (saved_cref != null) { ruby_cref = saved_cref; } return result; case NODE_OP_ASGN1: // TMP_PROTECT; recv = eval(self, node.nd_recv()); NODE rval = node.nd_args().nd_head(); args = setupArgs(self, node.nd_args().nd_next()); ArrayList argsList = new ArrayList(Arrays.asList(args)); argsList.remove(args.length - 1); RubyBoolean val = (RubyBoolean)recv.funcall(getRuby().intern("[]"), (RubyObject[])argsList.toArray(new RubyObject[argsList.size()])); switch (node.nd_mid().intValue()) { case 0: /* OR */ if (val.isTrue()) { return val; } val = (RubyBoolean)eval(self, rval); break; case 1: /* AND */ if (val.isFalse()) { return val; } val = (RubyBoolean)eval(self, rval); break; default: val = (RubyBoolean)val.funcall((RubyId)node.nd_mid(), eval(self, rval)); } args[args.length - 1] = val; return recv.funcall(getRuby().intern("[]="), args); case NODE_OP_ASGN2: ID id = node.nd_next().nd_vid(); recv = eval(self, node.nd_recv()); val = (RubyBoolean)recv.funcall((RubyId)id, (RubyObject[])null); switch (node.nd_next().nd_mid().intValue()) { case 0: /* OR */ if (val.isTrue()) { return val; } val = (RubyBoolean)eval(self, node.nd_value()); break; case 1: /* AND */ if (val.isFalse()) { return val; } val = (RubyBoolean)eval(self, node.nd_value()); break; default: val = (RubyBoolean)val.funcall((RubyId)node.nd_mid(), eval(self, node.nd_value())); } // HACK +++ val = (RubyBoolean)recv.funcall((RubyId)node.nd_next().nd_aid(), val); // HACK --- return val; case NODE_OP_ASGN_AND: cond = (RubyBoolean)eval(self, node.nd_head()); if (cond.isFalse()) { return cond; } node = node.nd_value(); break; case NODE_OP_ASGN_OR: cond = (RubyBoolean)eval(self, node.nd_head()); if ((node.nd_aid() != null && !self.isInstanceVarDefined((RubyId)node.nd_aid())) || cond.isFalse()) { node = node.nd_value(); break; } return cond; case NODE_MASGN: return massign(self, node, eval(self, node.nd_value()), false); case NODE_LASGN: // if (ruby.ruby_scope.local_vars == null) { // rb_bug("unexpected local variable assignment"); // } result = eval(self, node.nd_value()); getRuby().rubyScope.setLocalVars(node.nd_cnt(), result); return result; case NODE_DASGN: result = eval(self, node.nd_value()); RubyVarmap.assign(ruby, (RubyId)node.nd_vid(), result); return result; case NODE_DASGN_CURR: result = eval(self, node.nd_value()); RubyVarmap.assignCurrent(ruby, (RubyId)node.nd_vid(), result); return result; case NODE_GASGN: result = eval(self, node.nd_value()); ((RubyGlobalEntry)node.nd_entry()).set(result); return result; case NODE_IASGN: result = eval(self, node.nd_value()); self.setInstanceVar((RubyId)node.nd_vid(), result); return result; case NODE_CDECL: if (ruby_class == null) { throw new RubyTypeException("no class/module to define constant"); } result = eval(self, node.nd_value()); ruby_class.setConstant((RubyId)node.nd_vid(), result); return result; case NODE_CVDECL: if (ruby_cbase == null) { throw new RubyTypeException("no class/module to define class variable"); } result = eval(self, node.nd_value()); if (ruby_cbase.isSingleton()) { ruby_cbase.getInstanceVar("__attached__").getClassVarSingleton().declareClassVar((RubyId)node.nd_vid(), result); return result; } ruby_cbase.declareClassVar((RubyId)node.nd_vid(), result); return result; case NODE_CVASGN: result = eval(self, node.nd_value()); self.getClassVarSingleton().setClassVar((RubyId)node.nd_vid(), result); return result; case NODE_LVAR: //if (getRuby().ruby_scope.local_vars == null) { // rb_bug("unexpected local variable"); // } return (RubyObject)getRuby().rubyScope.getLocalVars(node.nd_cnt()); case NODE_DVAR: return getDynamicVars().getRef((RubyId)node.nd_vid()); case NODE_GVAR: return ((RubyGlobalEntry)node.nd_entry()).get(); case NODE_IVAR: return self.getInstanceVar((RubyId)node.nd_vid()); case NODE_CONST: return getConstant((NODE)rubyFrame.getCbase(), (RubyId)node.nd_vid(), self); case NODE_CVAR: /* normal method */ if (ruby_cbase == null) { return self.getRubyClass().getClassVar((RubyId)node.nd_vid()); } if (!ruby_cbase.isSingleton()) { return ruby_cbase.getClassVar((RubyId)node.nd_vid()); } return ruby_cbase.getInstanceVar("__attached__").getClassVarSingleton().getClassVar((RubyId)node.nd_vid()); case NODE_CVAR2: /* singleton method */ return self.getClassVarSingleton().getClassVar((RubyId)node.nd_vid()); case NODE_BLOCK_ARG: if (ruby.rubyScope.getLocalVars() == null) { throw new RuntimeException("BUG: unexpected block argument"); } if (isBlockGiven()) { result = getRuby().getNil(); // Create Proc object ruby.rubyScope.setLocalVars(node.nd_cnt(), result); return result; } else { return getRuby().getNil(); } case NODE_COLON2: value = eval(self, node.nd_head()); if (value instanceof RubyModule) { return ((RubyModule)value).getConstant((RubyId)node.nd_mid()); } else { return value.funcall((RubyId)node.nd_mid()); } case NODE_COLON3: return getRuby().getObjectClass().getConstant((RubyId)node.nd_mid()); case NODE_NTH_REF: // return rom.rb_reg_nth_match(node.nd_nth(), MATCH_DATA); return null; case NODE_BACK_REF: /*switch ((char)node.nd_nth()) { case '&': return rom.rb_reg_last_match(MATCH_DATA); case '`': return rom.rb_reg_match_pre(MATCH_DATA); case '\'': return rom.rb_reg_match_post(MATCH_DATA); case '+': return rom.rb_reg_match_last(MATCH_DATA); default: rom.rb_bug("unexpected back-ref"); }*/ case NODE_HASH: RubyHash hash = RubyHash.m_newHash(ruby); NODE list = node.nd_head(); while(list != null) { RubyObject key = eval(self, list.nd_head()); list = list.nd_next(); if (list == null) { // HACK +++ throw new RubyArgumentException("odd number list for Hash"); // HACK --- } value = eval(self, list.nd_head()); hash.m_aset(key, value); list = list.nd_next(); } return hash; case NODE_ZARRAY: /* zero length list */ return RubyArray.m_newArray(getRuby()); case NODE_ARRAY: ArrayList ary = new ArrayList(node.nd_alen()); for (; node != null ; node = node.nd_next()) { ary.add(eval(self, node.nd_head())); } return RubyArray.m_newArray(getRuby(), ary); case NODE_STR: return ((RubyObject)node.nd_lit()).m_to_s(); case NODE_DSTR: case NODE_DXSTR: case NODE_DREGX: case NODE_DREGX_ONCE:/* NODE list = node.nd_next(); RubyString str = RubyString.m_newString(getRuby(), (RubyObject)node.nd_lit()); RubyString str2; while (list != null) { if (list.nd_head() != null) { switch (list.nd_head().nd_type()) { case NODE_STR: str2 = (RubyString)list.nd_head().nd_lit(); break; case NODE_EVSTR: result = ruby_errinfo; ruby_errinfo = Qnil; ruby_sourceline = nd_line(node); ruby_in_eval++; list.nd_head(compile(list.nd_head().nd_lit(), ruby_sourcefile,ruby_sourceline)); ruby_eval_tree = 0; ruby_in_eval--; if (ruby_nerrs > 0) { compile_error("string expansion"); } if (!NIL_P(result)) ruby_errinfo = result; /* fall through *//* default: str2 = (RubyString)rom.rb_obj_as_string(eval(list.nd_head())); break; } str.append(str2); str.infectObject(str2); } list = list.nd_next(); } switch (node.nd_type()) { case NODE_DREGX: return rom.rb_reg_new(str.getString(), str.getString().length(), node.nd_cflag()); case NODE_DREGX_ONCE: /* regexp expand once *//* VALUE result = rom.rb_reg_new(str.getString(), str.getString().length(), node.nd_cflag()); node.nd_set_type(NODE_LIT); node.nd_lit(result); return result; case NODE_DXSTR: return rom.rb_funcall(this, '`', 1, str); default: return str; }*/ return null; case NODE_XSTR: return self.funcall(getRuby().intern("`"), (RubyObject)node.nd_lit()); case NODE_LIT: return (RubyObject)node.nd_lit(); case NODE_ATTRSET: if (rubyFrame.getArgs().size() != 1) { throw new RubyArgumentException("wrong # of arguments(" + rubyFrame.getArgs().size() + "for 1)"); } return self.setInstanceVar((RubyId)node.nd_vid(), (RubyObject)rubyFrame.getArgs().get(0)); case NODE_DEFN: if (node.nd_defn() != null) { int noex; if (ruby_class == null) { throw new RubyTypeException("no class to add method"); } //if (ruby_class == getRuby().getObjectClass() && node.nd_mid() == init) { // rom.rb_warn("redefining Object#initialize may cause infinite loop"); //} //if (node.nd_mid() == __id__ || node.nd_mid() == __send__) { // rom.rb_warn("redefining `%s' may cause serious problem", ((RubyId)node.nd_mid()).toName()); //} // ruby_class.setFrozen(true); NODE body = ruby_class.searchMethod((RubyId)node.nd_mid()); RubyObject origin = ruby_class.getMethodOrigin((RubyId)node.nd_mid()); if (body != null){ // if (ruby_verbose.isTrue() && ruby_class == origin && body.nd_cnt() == 0) { // rom.rb_warning("discarding old %s", ((RubyId)node.nd_mid()).toName()); // } // if (node.nd_noex() != 0) { /* toplevel */ /* should upgrade to rb_warn() if no super was called inside? */ // rom.rb_warning("overriding global function `%s'", ((RubyId)node.nd_mid()).toName()); // } } if (isScope(SCOPE_PRIVATE) || node.nd_mid().equals(ruby.intern("initialize"))) { noex = NOEX_PRIVATE; } else if (isScope(SCOPE_PROTECTED)) { noex = NOEX_PROTECTED; } else if (ruby_class == getRuby().getObjectClass()) { noex = node.nd_noex(); } else { noex = NOEX_PUBLIC; } if (body != null && origin == ruby_class && (body.nd_noex() & NOEX_UNDEF) != 0) { noex |= NOEX_UNDEF; } NODE defn = node.nd_defn().copyNodeScope(ruby_cref); ruby_class.addMethod((RubyId)node.nd_mid(), defn, noex); // rb_clear_cache_by_id(node.nd_mid()); if (scope_vmode == SCOPE_MODFUNC) { ruby_class.getSingletonClass().addMethod((RubyId)node.nd_mid(), defn, NOEX_PUBLIC); ruby_class.funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } if (ruby_class.isSingleton()) { ruby_class.getInstanceVar("__attached__").funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } else { ruby_class.funcall(getRuby().intern("method_added"), ((RubyId)node.nd_mid()).toSymbol()); } } return getRuby().getNil(); case NODE_DEFS: if (node.nd_defn() != null) { recv = eval(self, node.nd_recv()); if (getRuby().getSecurityLevel() >= 4 && !recv.isTaint()) { throw new RubySecurityException("Insecure; can't define singleton method"); } /*if (FIXNUM_P(recv) || SYMBOL_P(recv)) { rb_raise(rb_eTypeError, "can't define singleton method \"%s\" for %s", rb_id2name(node.nd_mid()), rb_class2name(CLASS_OF(recv))); }*/ // not needed in jruby if (recv.isFrozen()) { throw new RubyFrozenException("object"); } rubyClass = recv.getSingletonClass(); NODE body = (NODE)rubyClass.getMethods().get((RubyId)node.nd_mid()); if (body != null) { if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("redefining method prohibited"); } /*if (RTEST(ruby_verbose)) { rb_warning("redefine %s", rb_id2name(node.nd_mid())); }*/ } NODE defn = node.nd_defn().copyNodeScope(ruby_cref); defn.nd_rval(ruby_cref); rubyClass.addMethod((RubyId)node.nd_mid(), defn, NOEX_PUBLIC | (body != null ? body.nd_noex() & NOEX_UNDEF : 0)); // rb_clear_cache_by_id(node.nd_mid()); recv.funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } return getRuby().getNil(); case NODE_UNDEF: if (ruby_class == null) { throw new RubyTypeException("no class to undef method"); } ruby_class.undef((RubyId)node.nd_mid()); return getRuby().getNil(); case NODE_ALIAS: if (ruby_class == null) { throw new RubyTypeException("no class to make alias"); } ruby_class.aliasMethod((RubyId)node.nd_new(), (RubyId)node.nd_old()); ruby_class.funcall(getRuby().intern("method_added"), ((RubyId)node.nd_mid()).toSymbol()); return getRuby().getNil(); case NODE_VALIAS: RubyGlobalEntry.getGlobalEntry((RubyId)node.nd_old()).alias((RubyId)node.nd_new()); return getRuby().getNil(); case NODE_CLASS: RubyModule superClass; if (ruby_class == null) { throw new RubyTypeException("no outer class/module"); } if (node.nd_super() != null) { superClass = getSuperClass(self, node.nd_super()); } else { superClass = null; } rubyClass = null; // if ((ruby_class == getRuby().getObjectClass()) && rb_autoload_defined(node.nd_cname())) { // rb_autoload_load(node.nd_cname()); // } if (ruby_class.isConstantDefined((RubyId)node.nd_cname())) { rubyClass = (RubyClass)ruby_class.getConstant((RubyId)node.nd_cname()); } if (rubyClass != null) { if (!rubyClass.isClass()) { throw new RubyTypeException(((RubyId)node.nd_cname()).toName() + " is not a class"); } if (superClass != null) { RubyModule tmp = rubyClass.getSuperClass(); if (tmp.isSingleton()) { tmp = tmp.getSuperClass(); } while (tmp.isIncluded()) { tmp = tmp.getSuperClass(); } if (tmp != superClass) { superClass = tmp; //goto override_class; if (superClass == null) { superClass = getRuby().getObjectClass(); } rubyClass = getRuby().defineClassId((RubyId)node.nd_cname(), (RubyClass)superClass); ruby_class.setConstant((RubyId)node.nd_cname(), rubyClass); rubyClass.setClassPath((RubyClass)ruby_class, ((RubyId)node.nd_cname()).toName()); // end goto } } if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("extending class prohibited"); } // rb_clear_cache(); } else { //override_class: if (superClass == null) { superClass = getRuby().getObjectClass(); } rubyClass = getRuby().defineClassId((RubyId)node.nd_cname(), (RubyClass)superClass); ruby_class.setConstant((RubyId)node.nd_cname(), rubyClass); rubyClass.setClassPath((RubyClass)ruby_class, ((RubyId)node.nd_cname()).toName()); } if (ruby_wrapper != null) { rubyClass.getSingletonClass().includeModule(ruby_wrapper); rubyClass.includeModule(ruby_wrapper); } return setupModule(rubyClass, node.nd_body()); case NODE_MODULE: if (ruby_class == null) { throw new RubyTypeException("no outer class/module"); } RubyModule module = null; if ((ruby_class == getRuby().getObjectClass()) && getRuby().isAutoloadDefined((RubyId)node.nd_cname())) { // getRuby().rb_autoload_load(node.nd_cname()); } if (ruby_class.isConstantDefined((RubyId)node.nd_cname())) { module = (RubyModule)ruby_class.getConstant((RubyId)node.nd_cname()); } if (module != null) { if (!(module instanceof RubyModule)) { throw new RubyTypeException(((RubyId)node.nd_cname()).toName() + " is not a module"); } if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("extending module prohibited"); } } else { module = getRuby().defineModuleId((RubyId)node.nd_cname()); ruby_class.setConstant((RubyId)node.nd_cname(), module); module.setClassPath(ruby_class, ((RubyId)node.nd_cname()).toName()); } if (ruby_wrapper != null) { module.getSingletonClass().includeModule(ruby_wrapper); module.includeModule(ruby_wrapper); } return setupModule(module, node.nd_body()); case NODE_SCLASS: rubyClass = (RubyClass)eval(self, node.nd_recv()); if (rubyClass.isSpecialConst()) { throw new RubyTypeException("no virtual class for " + rubyClass.getRubyClass().toName()); } if (getRuby().getSecurityLevel() >= 4 && !rubyClass.isTaint()) { throw new RubySecurityException("Insecure: can't extend object"); } if (rubyClass.getRubyClass().isSingleton()) { // rb_clear_cache(); } rubyClass = rubyClass.getSingletonClass(); if (ruby_wrapper != null) { rubyClass.getSingletonClass().includeModule(ruby_wrapper); rubyClass.includeModule(ruby_wrapper); } return setupModule(rubyClass, node.nd_body()); case NODE_DEFINED: // String buf; // String desc = is_defined(self, node.nd_head(), buf); // // if (desc) { // result = rb_str_new2(desc); // } else { // result = Qnil; // } case NODE_NEWLINE: // ruby_sourcefile = node.nd_file; // ruby_sourceline = node.nd_nth(); // if (trace_func) { // call_trace_func("line", ruby_sourcefile, ruby_sourceline, self, // ruby_frame.last_func(), // ruby_frame.last_class()); // } node = node.nd_next(); break; default: // rom.rb_bug("unknown node type %d", nd_type(node)); } } }
public RubyObject eval(RubyObject self, NODE n) { NODE node = n; RubyBoolean cond = null; RubyObject[] args = null; RubyObject value = null; RubyObject result = null; RubyModule rubyClass = null; // int state; // RubyOriginalMethods rom = getRuby().getOriginalMethods(); while (true) { if (node == null) { return getRuby().getNil(); } switch (node.nd_type()) { case NODE_BLOCK: while (node.nd_next() != null) { eval(self, node.nd_head()); node = node.nd_next(); } node = node.nd_head(); break; case NODE_POSTEXE: // rb_f_END(); node.nd_set_type(NODE_NIL); /* exec just once */ return getRuby().getNil(); /* begin .. end without clauses */ case NODE_BEGIN: node = node.nd_body(); break; /* nodes for speed-up(default match) */ case NODE_MATCH: //return rom.rb_reg_match2(node.nd_head().nd_lit()); return getRuby().getNil(); /* nodes for speed-up(literal match) */ case NODE_MATCH2: //return rom.rb_reg_match(eval(node.nd_recv()), eval(node.nd_value())); return getRuby().getNil(); /* nodes for speed-up(literal match) */ case NODE_MATCH3: //VALUE r = eval(node.nd_recv()); //VALUE l = eval(node.nd_value()); //if (r instanceof RubyString) { // return rom.rb_reg_match(l, r); //} else { // return rom.rb_funcall(r, match, 1, l); //} return getRuby().getNil(); /* node for speed-up(top-level loop for -n/-p) */ case NODE_OPT_N: while (true) { try { // while (!rb_gets().isNil() false) { // HACK +++ if (true) { // HACK --- try { eval(self, node.nd_body()); } catch (RedoException rExcptn) { } } break; } catch (NextException nExcptn) { } catch (BreakException bExcptn) { break; } } return getRuby().getNil(); case NODE_SELF: return self; case NODE_NIL: return getRuby().getNil(); case NODE_TRUE: return getRuby().getTrue(); case NODE_FALSE: return getRuby().getFalse(); case NODE_IF: // ruby_sourceline = node.nd_line(); cond = (RubyBoolean)eval(self, node.nd_cond()); if (cond.isTrue()) { node = node.nd_body(); } else { node = node.nd_else(); } break; case NODE_WHEN: while (node != null) { NODE tag; if (node.nd_type() != NODE_WHEN) { break; } tag = node.nd_head(); while (tag != null) {/* if (trace_func) { call_trace_func("line", tag->nd_file, nd_line(tag), self, ruby_frame->last_func, ruby_frame->last_class); }*/ // ruby_sourcefile = tag.nd_file; // ruby_sourceline = tag.nd_line(); if (tag.nd_head().nd_type() == NODE_WHEN) { RubyObject obj = eval(self, tag.nd_head().nd_head()); if (!(obj instanceof RubyArray)) { obj = RubyArray.m_newArray(getRuby(), obj); } for (int i = 0; i < ((RubyArray)obj).length(); i++) { if (((RubyBoolean)((RubyArray)obj).entry(i)).isTrue()) { node = node.nd_body(); break; } } tag = tag.nd_next(); continue; } if (((RubyBoolean)eval(self, tag.nd_head())).isTrue()) { node = node.nd_body(); break; } tag = tag.nd_next(); } node = node.nd_next(); } return getRuby().getNil(); case NODE_CASE: RubyObject obj = eval(self, node.nd_head()); node = node.nd_body(); while (node != null) { NODE tag; if (node.nd_type() != NODE_WHEN) { break; } tag = node.nd_head(); while (tag != null) {/* if (trace_func) { call_trace_func("line", tag->nd_file, nd_line(tag), self, ruby_frame->last_func, ruby_frame->last_class); } ruby_sourcefile = tag->nd_file; ruby_sourceline = nd_line(tag);*/ if (tag.nd_head().nd_type() == NODE_WHEN) { RubyObject obj2 = eval(self, tag.nd_head().nd_head()); if (!(obj2 instanceof RubyArray)) { obj2 = RubyArray.m_newArray(getRuby(), obj2); } for (int i = 0; i < ((RubyArray)obj).length(); i++) { RubyBoolean eqq = (RubyBoolean)((RubyArray)obj2).entry(i).funcall(getRuby().intern("==="), obj); if (eqq.isTrue()) { node = node.nd_body(); break; } } tag = tag.nd_next(); continue; } if (((RubyBoolean)eval(self, tag.nd_head()).funcall(getRuby().intern("==="), obj)).isTrue()) { node = node.nd_body(); break; } tag = tag.nd_next(); } node = node.nd_next(); } return getRuby().getNil(); case NODE_WHILE: while (eval(self, node.nd_cond()).isTrue()) { while (true) { try { eval(self, node.nd_body()); break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { break; } catch (BreakException bExcptn) { return getRuby().getNil(); } } } return getRuby().getNil(); case NODE_UNTIL: while (eval(self, node.nd_cond()).isFalse()) { while (true) { try { eval(self, node.nd_body()); break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { break; } catch (BreakException bExcptn) { return getRuby().getNil(); } } } return getRuby().getNil(); case NODE_BLOCK_PASS: //return block_pass(node); return null; case NODE_ITER: case NODE_FOR: rubyBlock.push(node.nd_var(), node.nd_body(), self); rubyIter.push(Iter.ITER_PRE); while (true) { try { if (node.nd_type() == NODE_ITER) { result = eval(self, node.nd_iter()); } else { // String file = // int line = rubyBlock.flags &= ~RubyBlock.BLOCK_D_SCOPE; RubyBlock tmpBlock = beginCallargs(); RubyObject recv = eval(self, node.nd_iter()); endCallArgs(tmpBlock); // = file; // = line; result = recv.getRubyClass().call(recv, ruby.intern("each"), null, 0); } break; } catch (RetryException rExcptn) { } catch (ReturnException rExcptn) { result = rExcptn.getReturnValue(); break; } catch (BreakException bExcptn) { result = ruby.getNil(); break; } } rubyIter.pop(); rubyBlock.pop(); return result; case NODE_BREAK: throw new BreakException(); case NODE_NEXT: throw new NextException(); case NODE_REDO: throw new RedoException(); case NODE_RETRY: throw new RetryException(); case NODE_RESTARGS: result = eval(self, node.nd_head()); if (!(result instanceof RubyArray)) { result = obj = RubyArray.m_newArray(getRuby(), result); } return result; case NODE_YIELD: if (node.nd_stts() != null) { result = eval(self, node.nd_stts()); if (node.nd_stts().nd_type() == NODE_RESTARGS && ((RubyArray)result).length() == 1) { result = ((RubyArray)result).entry(0); } } else { result = ruby.getNil(); } return yield0(result, null, null, false); case NODE_RESCUE:/* retry_entry: { volatile VALUE e_info = ruby_errinfo; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, node->nd_head); } POP_TAG(); if (state == TAG_RAISE) { NODE * volatile resq = node->nd_resq; ruby_sourceline = nd_line(node); while (resq) { if (handle_rescue(self, resq)) { state = 0; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, resq->nd_body); } POP_TAG(); if (state == TAG_RETRY) { state = 0; ruby_errinfo = Qnil; goto retry_entry; } if (state != TAG_RAISE) { ruby_errinfo = e_info; } break; } resq = resq->nd_head; /* next rescue */ /** } * } * else if (node->nd_else) { /* else clause given *//* if (!state) { /* no exception raised *//* result = rb_eval(self, node->nd_else); } } if (state) JUMP_TAG(state); } break;*/ case NODE_ENSURE:/* PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = eval(node.nd_head()); } POP_TAG(); if (node.nd_ensr()) { VALUE retval = prot_tag->retval; /* save retval *//* VALUE errinfo = ruby_errinfo; rb_eval(self, node->nd_ensr); return_value(retval); ruby_errinfo = errinfo; } if (state) JUMP_TAG(state); break;*/ case NODE_AND: cond = (RubyBoolean)eval(self, node.nd_1st()); if (cond.isFalse()) { return cond; } node = node.nd_2nd(); break; case NODE_OR: cond = (RubyBoolean)eval(self, node.nd_1st()); if (cond.isTrue()) { return cond; } node = node.nd_2nd(); break; case NODE_NOT: return RubyBoolean.m_newBoolean(getRuby(), eval(self, node.nd_1st()).isFalse()); case NODE_DOT2: case NODE_DOT3: result = RubyRange.m_newRange(getRuby(), eval(self, node.nd_beg()), eval(self, node.nd_end()), node.nd_type() == NODE_DOT3); if (node.nd_state() != 0) { return result; } if (node.nd_beg().nd_type() == NODE_LIT && (node.nd_beg().nd_lit() instanceof RubyFixnum) && node.nd_end().nd_type() == NODE_LIT && (node.nd_end().nd_lit() instanceof RubyFixnum)) { node.nd_set_type(NODE_LIT); node.nd_lit(result); } else { node.nd_state(1L); } return result; case NODE_FLIP2: /* like AWK */ /*if (ruby_scope->local_vars == 0) { rb_bug("unexpected local variable"); }*/ if (ruby.rubyScope.getLocalVars(node.nd_cnt()).isFalse()) { if (eval(self, node.nd_beg()).isTrue()) { ruby.rubyScope.setLocalVars(node.nd_cnt(), eval(self, node.nd_end()).isTrue() ? ruby.getFalse() : ruby.getTrue()); result = ruby.getTrue(); } else { result = ruby.getFalse(); } } else { if (eval(self, node.nd_end()).isTrue()) { ruby.rubyScope.setLocalVars(node.nd_cnt(), ruby.getFalse()); } result = ruby.getTrue(); } return result; case NODE_FLIP3: /* like SED */ /*if (ruby_scope->local_vars == 0) { rb_bug("unexpected local variable"); }*/ if (ruby.rubyScope.getLocalVars(node.nd_cnt()).isFalse()) { result = eval(self, node.nd_beg()).isTrue() ? ruby.getFalse() : ruby.getTrue(); ruby.rubyScope.setLocalVars(node.nd_cnt(), result); } else { if (eval(self, node.nd_end()).isTrue()) { ruby.rubyScope.setLocalVars(node.nd_cnt(), ruby.getFalse()); } result = ruby.getTrue(); } return result; case NODE_RETURN: if (node.nd_stts() != null) { result = eval(self, node.nd_stts()); } else { result = ruby.getNil(); } throw new ReturnException(result); case NODE_ARGSCAT: return ((RubyArray)eval(self, node.nd_head())).m_concat(eval(self, node.nd_body())); case NODE_ARGSPUSH: return ((RubyArray)eval(self, node.nd_head()).m_dup()).push(eval(self, node.nd_body())); case NODE_CALL: // TMP_PROTECT; RubyBlock tmpBlock = beginCallargs(); RubyObject recv = eval(self, node.nd_recv()); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); return recv.getRubyClass().call(recv, (RubyId)node.nd_mid(), args, 0); case NODE_FCALL: // TMP_PROTECT; tmpBlock = beginCallargs(); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); return self.getRubyClass().call(self, (RubyId)node.nd_mid(), args, 1); case NODE_VCALL: return self.getRubyClass().call(self, (RubyId)node.nd_mid(), null, 2); case NODE_SUPER: case NODE_ZSUPER: // TMP_PROTECT; if (rubyFrame.getLastClass() == null) { throw new RubyNameException("superclass method '" + rubyFrame.getLastFunc().toName() + "' disabled"); } if (node.nd_type() == NODE_ZSUPER) { List argsList = rubyFrame.getArgs(); args = (RubyObject[])argsList.toArray(new RubyObject[argsList.size()]); } else { tmpBlock = beginCallargs(); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); } rubyIter.push(rubyIter.getIter() != Iter.ITER_NOT ? Iter.ITER_PRE : Iter.ITER_NOT); result = rubyFrame.getLastClass().getSuperClass().call(rubyFrame.getSelf(), rubyFrame.getLastFunc(), args, 3); rubyIter.pop(); return result; case NODE_SCOPE: NODE saved_cref = null; Frame frame = rubyFrame; frame.setTmp(rubyFrame); rubyFrame = frame; ruby.rubyScope.push(); if (node.nd_rval() != null) { saved_cref = ruby_cref; ruby_cref = (NODE)node.nd_rval(); getRubyFrame().setCbase(node.nd_rval()); } if (node.nd_tbl() != null) { List tmp = Collections.nCopies(node.nd_tbl()[0].intValue() + 1, ruby.getNil()); ShiftableList vars = new ShiftableList(new ArrayList(tmp)); vars.set(0, (VALUE)node); vars.shift(1); getRuby().rubyScope.setLocalVars(vars); getRuby().rubyScope.setLocalTbl(node.nd_tbl()); } else { getRuby().rubyScope.setLocalVars(null); getRuby().rubyScope.setLocalTbl(null); } result = eval(self, node.nd_next()); ruby.rubyScope.pop(); rubyFrame = frame.getTmp(); if (saved_cref != null) { ruby_cref = saved_cref; } return result; case NODE_OP_ASGN1: // TMP_PROTECT; recv = eval(self, node.nd_recv()); NODE rval = node.nd_args().nd_head(); args = setupArgs(self, node.nd_args().nd_next()); ArrayList argsList = new ArrayList(Arrays.asList(args)); argsList.remove(args.length - 1); RubyBoolean val = (RubyBoolean)recv.funcall(getRuby().intern("[]"), (RubyObject[])argsList.toArray(new RubyObject[argsList.size()])); switch (node.nd_mid().intValue()) { case 0: /* OR */ if (val.isTrue()) { return val; } val = (RubyBoolean)eval(self, rval); break; case 1: /* AND */ if (val.isFalse()) { return val; } val = (RubyBoolean)eval(self, rval); break; default: val = (RubyBoolean)val.funcall((RubyId)node.nd_mid(), eval(self, rval)); } args[args.length - 1] = val; return recv.funcall(getRuby().intern("[]="), args); case NODE_OP_ASGN2: ID id = node.nd_next().nd_vid(); recv = eval(self, node.nd_recv()); val = (RubyBoolean)recv.funcall((RubyId)id, (RubyObject[])null); switch (node.nd_next().nd_mid().intValue()) { case 0: /* OR */ if (val.isTrue()) { return val; } val = (RubyBoolean)eval(self, node.nd_value()); break; case 1: /* AND */ if (val.isFalse()) { return val; } val = (RubyBoolean)eval(self, node.nd_value()); break; default: val = (RubyBoolean)val.funcall((RubyId)node.nd_mid(), eval(self, node.nd_value())); } // HACK +++ val = (RubyBoolean)recv.funcall((RubyId)node.nd_next().nd_aid(), val); // HACK --- return val; case NODE_OP_ASGN_AND: cond = (RubyBoolean)eval(self, node.nd_head()); if (cond.isFalse()) { return cond; } node = node.nd_value(); break; case NODE_OP_ASGN_OR: cond = (RubyBoolean)eval(self, node.nd_head()); if ((node.nd_aid() != null && !self.isInstanceVarDefined((RubyId)node.nd_aid())) || cond.isFalse()) { node = node.nd_value(); break; } return cond; case NODE_MASGN: return massign(self, node, eval(self, node.nd_value()), false); case NODE_LASGN: // if (ruby.ruby_scope.local_vars == null) { // rb_bug("unexpected local variable assignment"); // } result = eval(self, node.nd_value()); getRuby().rubyScope.setLocalVars(node.nd_cnt(), result); return result; case NODE_DASGN: result = eval(self, node.nd_value()); RubyVarmap.assign(ruby, (RubyId)node.nd_vid(), result); return result; case NODE_DASGN_CURR: result = eval(self, node.nd_value()); RubyVarmap.assignCurrent(ruby, (RubyId)node.nd_vid(), result); return result; case NODE_GASGN: result = eval(self, node.nd_value()); ((RubyGlobalEntry)node.nd_entry()).set(result); return result; case NODE_IASGN: result = eval(self, node.nd_value()); self.setInstanceVar((RubyId)node.nd_vid(), result); return result; case NODE_CDECL: if (ruby_class == null) { throw new RubyTypeException("no class/module to define constant"); } result = eval(self, node.nd_value()); ruby_class.setConstant((RubyId)node.nd_vid(), result); return result; case NODE_CVDECL: if (ruby_cbase == null) { throw new RubyTypeException("no class/module to define class variable"); } result = eval(self, node.nd_value()); if (ruby_cbase.isSingleton()) { ruby_cbase.getInstanceVar("__attached__").getClassVarSingleton().declareClassVar((RubyId)node.nd_vid(), result); return result; } ruby_cbase.declareClassVar((RubyId)node.nd_vid(), result); return result; case NODE_CVASGN: result = eval(self, node.nd_value()); self.getClassVarSingleton().setClassVar((RubyId)node.nd_vid(), result); return result; case NODE_LVAR: //if (getRuby().ruby_scope.local_vars == null) { // rb_bug("unexpected local variable"); // } return (RubyObject)getRuby().rubyScope.getLocalVars(node.nd_cnt()); case NODE_DVAR: return getDynamicVars().getRef((RubyId)node.nd_vid()); case NODE_GVAR: return ((RubyGlobalEntry)node.nd_entry()).get(); case NODE_IVAR: return self.getInstanceVar((RubyId)node.nd_vid()); case NODE_CONST: return getConstant((NODE)rubyFrame.getCbase(), (RubyId)node.nd_vid(), self); case NODE_CVAR: /* normal method */ if (ruby_cbase == null) { return self.getRubyClass().getClassVar((RubyId)node.nd_vid()); } if (!ruby_cbase.isSingleton()) { return ruby_cbase.getClassVar((RubyId)node.nd_vid()); } return ruby_cbase.getInstanceVar("__attached__").getClassVarSingleton().getClassVar((RubyId)node.nd_vid()); case NODE_CVAR2: /* singleton method */ return self.getClassVarSingleton().getClassVar((RubyId)node.nd_vid()); case NODE_BLOCK_ARG: if (ruby.rubyScope.getLocalVars() == null) { throw new RuntimeException("BUG: unexpected block argument"); } if (isBlockGiven()) { result = getRuby().getNil(); // Create Proc object ruby.rubyScope.setLocalVars(node.nd_cnt(), result); return result; } else { return getRuby().getNil(); } case NODE_COLON2: value = eval(self, node.nd_head()); if (value instanceof RubyModule) { return ((RubyModule)value).getConstant((RubyId)node.nd_mid()); } else { return value.funcall((RubyId)node.nd_mid()); } case NODE_COLON3: return getRuby().getObjectClass().getConstant((RubyId)node.nd_mid()); case NODE_NTH_REF: // return rom.rb_reg_nth_match(node.nd_nth(), MATCH_DATA); return null; case NODE_BACK_REF: /*switch ((char)node.nd_nth()) { case '&': return rom.rb_reg_last_match(MATCH_DATA); case '`': return rom.rb_reg_match_pre(MATCH_DATA); case '\'': return rom.rb_reg_match_post(MATCH_DATA); case '+': return rom.rb_reg_match_last(MATCH_DATA); default: rom.rb_bug("unexpected back-ref"); }*/ case NODE_HASH: RubyHash hash = RubyHash.m_newHash(ruby); NODE list = node.nd_head(); while(list != null) { RubyObject key = eval(self, list.nd_head()); list = list.nd_next(); if (list == null) { // HACK +++ throw new RubyArgumentException("odd number list for Hash"); // HACK --- } value = eval(self, list.nd_head()); hash.m_aset(key, value); list = list.nd_next(); } return hash; case NODE_ZARRAY: /* zero length list */ return RubyArray.m_newArray(getRuby()); case NODE_ARRAY: ArrayList ary = new ArrayList(node.nd_alen()); for (; node != null ; node = node.nd_next()) { ary.add(eval(self, node.nd_head())); } return RubyArray.m_newArray(getRuby(), ary); case NODE_STR: return ((RubyObject)node.nd_lit()).m_to_s(); case NODE_DSTR: case NODE_DXSTR: case NODE_DREGX: case NODE_DREGX_ONCE:/* NODE list = node.nd_next(); RubyString str = RubyString.m_newString(getRuby(), (RubyObject)node.nd_lit()); RubyString str2; while (list != null) { if (list.nd_head() != null) { switch (list.nd_head().nd_type()) { case NODE_STR: str2 = (RubyString)list.nd_head().nd_lit(); break; case NODE_EVSTR: result = ruby_errinfo; ruby_errinfo = Qnil; ruby_sourceline = nd_line(node); ruby_in_eval++; list.nd_head(compile(list.nd_head().nd_lit(), ruby_sourcefile,ruby_sourceline)); ruby_eval_tree = 0; ruby_in_eval--; if (ruby_nerrs > 0) { compile_error("string expansion"); } if (!NIL_P(result)) ruby_errinfo = result; /* fall through *//* default: str2 = (RubyString)rom.rb_obj_as_string(eval(list.nd_head())); break; } str.append(str2); str.infectObject(str2); } list = list.nd_next(); } switch (node.nd_type()) { case NODE_DREGX: return rom.rb_reg_new(str.getString(), str.getString().length(), node.nd_cflag()); case NODE_DREGX_ONCE: /* regexp expand once *//* VALUE result = rom.rb_reg_new(str.getString(), str.getString().length(), node.nd_cflag()); node.nd_set_type(NODE_LIT); node.nd_lit(result); return result; case NODE_DXSTR: return rom.rb_funcall(this, '`', 1, str); default: return str; }*/ return null; case NODE_XSTR: return self.funcall(getRuby().intern("`"), (RubyObject)node.nd_lit()); case NODE_LIT: return (RubyObject)node.nd_lit(); case NODE_ATTRSET: if (rubyFrame.getArgs().size() != 1) { throw new RubyArgumentException("wrong # of arguments(" + rubyFrame.getArgs().size() + "for 1)"); } return self.setInstanceVar((RubyId)node.nd_vid(), (RubyObject)rubyFrame.getArgs().get(0)); case NODE_DEFN: if (node.nd_defn() != null) { int noex; if (ruby_class == null) { throw new RubyTypeException("no class to add method"); } //if (ruby_class == getRuby().getObjectClass() && node.nd_mid() == init) { // rom.rb_warn("redefining Object#initialize may cause infinite loop"); //} //if (node.nd_mid() == __id__ || node.nd_mid() == __send__) { // rom.rb_warn("redefining `%s' may cause serious problem", ((RubyId)node.nd_mid()).toName()); //} // ruby_class.setFrozen(true); NODE body = ruby_class.searchMethod((RubyId)node.nd_mid()); RubyObject origin = ruby_class.getMethodOrigin((RubyId)node.nd_mid()); if (body != null){ // if (ruby_verbose.isTrue() && ruby_class == origin && body.nd_cnt() == 0) { // rom.rb_warning("discarding old %s", ((RubyId)node.nd_mid()).toName()); // } // if (node.nd_noex() != 0) { /* toplevel */ /* should upgrade to rb_warn() if no super was called inside? */ // rom.rb_warning("overriding global function `%s'", ((RubyId)node.nd_mid()).toName()); // } } if (isScope(SCOPE_PRIVATE) || node.nd_mid().equals(ruby.intern("initialize"))) { noex = NOEX_PRIVATE; } else if (isScope(SCOPE_PROTECTED)) { noex = NOEX_PROTECTED; } else if (ruby_class == getRuby().getObjectClass()) { noex = node.nd_noex(); } else { noex = NOEX_PUBLIC; } if (body != null && origin == ruby_class && (body.nd_noex() & NOEX_UNDEF) != 0) { noex |= NOEX_UNDEF; } NODE defn = node.nd_defn().copyNodeScope(ruby_cref); ruby_class.addMethod((RubyId)node.nd_mid(), defn, noex); // rb_clear_cache_by_id(node.nd_mid()); if (scope_vmode == SCOPE_MODFUNC) { ruby_class.getSingletonClass().addMethod((RubyId)node.nd_mid(), defn, NOEX_PUBLIC); ruby_class.funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } if (ruby_class.isSingleton()) { ruby_class.getInstanceVar("__attached__").funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } else { ruby_class.funcall(getRuby().intern("method_added"), ((RubyId)node.nd_mid()).toSymbol()); } } return getRuby().getNil(); case NODE_DEFS: if (node.nd_defn() != null) { recv = eval(self, node.nd_recv()); if (getRuby().getSecurityLevel() >= 4 && !recv.isTaint()) { throw new RubySecurityException("Insecure; can't define singleton method"); } /*if (FIXNUM_P(recv) || SYMBOL_P(recv)) { rb_raise(rb_eTypeError, "can't define singleton method \"%s\" for %s", rb_id2name(node.nd_mid()), rb_class2name(CLASS_OF(recv))); }*/ // not needed in jruby if (recv.isFrozen()) { throw new RubyFrozenException("object"); } rubyClass = recv.getSingletonClass(); NODE body = (NODE)rubyClass.getMethods().get((RubyId)node.nd_mid()); if (body != null) { if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("redefining method prohibited"); } /*if (RTEST(ruby_verbose)) { rb_warning("redefine %s", rb_id2name(node.nd_mid())); }*/ } NODE defn = node.nd_defn().copyNodeScope(ruby_cref); defn.nd_rval(ruby_cref); rubyClass.addMethod((RubyId)node.nd_mid(), defn, NOEX_PUBLIC | (body != null ? body.nd_noex() & NOEX_UNDEF : 0)); // rb_clear_cache_by_id(node.nd_mid()); recv.funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } return getRuby().getNil(); case NODE_UNDEF: if (ruby_class == null) { throw new RubyTypeException("no class to undef method"); } ruby_class.undef((RubyId)node.nd_mid()); return getRuby().getNil(); case NODE_ALIAS: if (ruby_class == null) { throw new RubyTypeException("no class to make alias"); } ruby_class.aliasMethod((RubyId)node.nd_new(), (RubyId)node.nd_old()); ruby_class.funcall(getRuby().intern("method_added"), ((RubyId)node.nd_mid()).toSymbol()); return getRuby().getNil(); case NODE_VALIAS: RubyGlobalEntry.getGlobalEntry((RubyId)node.nd_old()).alias((RubyId)node.nd_new()); return getRuby().getNil(); case NODE_CLASS: RubyModule superClass; if (ruby_class == null) { throw new RubyTypeException("no outer class/module"); } if (node.nd_super() != null) { superClass = getSuperClass(self, node.nd_super()); } else { superClass = null; } rubyClass = null; // if ((ruby_class == getRuby().getObjectClass()) && rb_autoload_defined(node.nd_cname())) { // rb_autoload_load(node.nd_cname()); // } if (ruby_class.isConstantDefined((RubyId)node.nd_cname())) { rubyClass = (RubyClass)ruby_class.getConstant((RubyId)node.nd_cname()); } if (rubyClass != null) { if (!rubyClass.isClass()) { throw new RubyTypeException(((RubyId)node.nd_cname()).toName() + " is not a class"); } if (superClass != null) { RubyModule tmp = rubyClass.getSuperClass(); if (tmp.isSingleton()) { tmp = tmp.getSuperClass(); } while (tmp.isIncluded()) { tmp = tmp.getSuperClass(); } if (tmp != superClass) { superClass = tmp; //goto override_class; if (superClass == null) { superClass = getRuby().getObjectClass(); } rubyClass = getRuby().defineClassId((RubyId)node.nd_cname(), (RubyClass)superClass); ruby_class.setConstant((RubyId)node.nd_cname(), rubyClass); rubyClass.setClassPath((RubyClass)ruby_class, ((RubyId)node.nd_cname()).toName()); // end goto } } if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("extending class prohibited"); } // rb_clear_cache(); } else { //override_class: if (superClass == null) { superClass = getRuby().getObjectClass(); } rubyClass = getRuby().defineClassId((RubyId)node.nd_cname(), (RubyClass)superClass); ruby_class.setConstant((RubyId)node.nd_cname(), rubyClass); rubyClass.setClassPath((RubyClass)ruby_class, ((RubyId)node.nd_cname()).toName()); } if (ruby_wrapper != null) { rubyClass.getSingletonClass().includeModule(ruby_wrapper); rubyClass.includeModule(ruby_wrapper); } return setupModule(rubyClass, node.nd_body()); case NODE_MODULE: if (ruby_class == null) { throw new RubyTypeException("no outer class/module"); } RubyModule module = null; if ((ruby_class == getRuby().getObjectClass()) && getRuby().isAutoloadDefined((RubyId)node.nd_cname())) { // getRuby().rb_autoload_load(node.nd_cname()); } if (ruby_class.isConstantDefined((RubyId)node.nd_cname())) { module = (RubyModule)ruby_class.getConstant((RubyId)node.nd_cname()); } if (module != null) { if (!(module instanceof RubyModule)) { throw new RubyTypeException(((RubyId)node.nd_cname()).toName() + " is not a module"); } if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("extending module prohibited"); } } else { module = getRuby().defineModuleId((RubyId)node.nd_cname()); ruby_class.setConstant((RubyId)node.nd_cname(), module); module.setClassPath(ruby_class, ((RubyId)node.nd_cname()).toName()); } if (ruby_wrapper != null) { module.getSingletonClass().includeModule(ruby_wrapper); module.includeModule(ruby_wrapper); } return setupModule(module, node.nd_body()); case NODE_SCLASS: rubyClass = (RubyClass)eval(self, node.nd_recv()); if (rubyClass.isSpecialConst()) { throw new RubyTypeException("no virtual class for " + rubyClass.getRubyClass().toName()); } if (getRuby().getSecurityLevel() >= 4 && !rubyClass.isTaint()) { throw new RubySecurityException("Insecure: can't extend object"); } if (rubyClass.getRubyClass().isSingleton()) { // rb_clear_cache(); } rubyClass = rubyClass.getSingletonClass(); if (ruby_wrapper != null) { rubyClass.getSingletonClass().includeModule(ruby_wrapper); rubyClass.includeModule(ruby_wrapper); } return setupModule(rubyClass, node.nd_body()); case NODE_DEFINED: // String buf; // String desc = is_defined(self, node.nd_head(), buf); // // if (desc) { // result = rb_str_new2(desc); // } else { // result = Qnil; // } case NODE_NEWLINE: // ruby_sourcefile = node.nd_file; // ruby_sourceline = node.nd_nth(); // if (trace_func) { // call_trace_func("line", ruby_sourcefile, ruby_sourceline, self, // ruby_frame.last_func(), // ruby_frame.last_class()); // } node = node.nd_next(); break; default: // rom.rb_bug("unknown node type %d", nd_type(node)); } } }
3,238,702
public RubyObject eval(RubyObject self, NODE n) { NODE node = n; RubyBoolean cond = null; RubyObject[] args = null; RubyObject value = null; RubyObject result = null; RubyModule rubyClass = null; // int state; // RubyOriginalMethods rom = getRuby().getOriginalMethods(); while (true) { if (node == null) { return getRuby().getNil(); } switch (node.nd_type()) { case NODE_BLOCK: while (node.nd_next() != null) { eval(self, node.nd_head()); node = node.nd_next(); } node = node.nd_head(); break; case NODE_POSTEXE: // rb_f_END(); node.nd_set_type(NODE_NIL); /* exec just once */ return getRuby().getNil(); /* begin .. end without clauses */ case NODE_BEGIN: node = node.nd_body(); break; /* nodes for speed-up(default match) */ case NODE_MATCH: //return rom.rb_reg_match2(node.nd_head().nd_lit()); return getRuby().getNil(); /* nodes for speed-up(literal match) */ case NODE_MATCH2: //return rom.rb_reg_match(eval(node.nd_recv()), eval(node.nd_value())); return getRuby().getNil(); /* nodes for speed-up(literal match) */ case NODE_MATCH3: //VALUE r = eval(node.nd_recv()); //VALUE l = eval(node.nd_value()); //if (r instanceof RubyString) { // return rom.rb_reg_match(l, r); //} else { // return rom.rb_funcall(r, match, 1, l); //} return getRuby().getNil(); /* node for speed-up(top-level loop for -n/-p) */ case NODE_OPT_N: while (true) { try { // while (!rb_gets().isNil() false) { // HACK +++ if (true) { // HACK --- try { eval(self, node.nd_body()); } catch (RedoException rExcptn) { } } break; } catch (NextException nExcptn) { } catch (BreakException bExcptn) { break; } } return getRuby().getNil(); case NODE_SELF: return self; case NODE_NIL: return getRuby().getNil(); case NODE_TRUE: return getRuby().getTrue(); case NODE_FALSE: return getRuby().getFalse(); case NODE_IF: // ruby_sourceline = node.nd_line(); cond = (RubyBoolean)eval(self, node.nd_cond()); if (cond.isTrue()) { node = node.nd_body(); } else { node = node.nd_else(); } break; case NODE_WHEN: while (node != null) { NODE tag; if (node.nd_type() != NODE_WHEN) { break; } tag = node.nd_head(); while (tag != null) {/* if (trace_func) { call_trace_func("line", tag->nd_file, nd_line(tag), self, ruby_frame->last_func, ruby_frame->last_class); }*/ // ruby_sourcefile = tag.nd_file; // ruby_sourceline = tag.nd_line(); if (tag.nd_head().nd_type() == NODE_WHEN) { RubyObject obj = eval(self, tag.nd_head().nd_head()); if (!(obj instanceof RubyArray)) { obj = RubyArray.m_newArray(getRuby(), obj); } for (int i = 0; i < ((RubyArray)obj).length(); i++) { if (((RubyBoolean)((RubyArray)obj).entry(i)).isTrue()) { node = node.nd_body(); break; } } tag = tag.nd_next(); continue; } if (((RubyBoolean)eval(self, tag.nd_head())).isTrue()) { node = node.nd_body(); break; } tag = tag.nd_next(); } node = node.nd_next(); } return getRuby().getNil(); case NODE_CASE: RubyObject obj = eval(self, node.nd_head()); node = node.nd_body(); while (node != null) { NODE tag; if (node.nd_type() != NODE_WHEN) { break; } tag = node.nd_head(); while (tag != null) {/* if (trace_func) { call_trace_func("line", tag->nd_file, nd_line(tag), self, ruby_frame->last_func, ruby_frame->last_class); } ruby_sourcefile = tag->nd_file; ruby_sourceline = nd_line(tag);*/ if (tag.nd_head().nd_type() == NODE_WHEN) { RubyObject obj2 = eval(self, tag.nd_head().nd_head()); if (!(obj2 instanceof RubyArray)) { obj2 = RubyArray.m_newArray(getRuby(), obj2); } for (int i = 0; i < ((RubyArray)obj).length(); i++) { RubyBoolean eqq = (RubyBoolean)((RubyArray)obj2).entry(i).funcall(getRuby().intern("==="), obj); if (eqq.isTrue()) { node = node.nd_body(); break; } } tag = tag.nd_next(); continue; } if (((RubyBoolean)eval(self, tag.nd_head()).funcall(getRuby().intern("==="), obj)).isTrue()) { node = node.nd_body(); break; } tag = tag.nd_next(); } node = node.nd_next(); } return getRuby().getNil(); case NODE_WHILE: while (eval(self, node.nd_cond()).isTrue()) { while (true) { try { eval(self, node.nd_body()); break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { break; } catch (BreakException bExcptn) { return getRuby().getNil(); } } } return getRuby().getNil(); case NODE_UNTIL: while (eval(self, node.nd_cond()).isFalse()) { while (true) { try { eval(self, node.nd_body()); break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { break; } catch (BreakException bExcptn) { return getRuby().getNil(); } } } return getRuby().getNil(); case NODE_BLOCK_PASS: //return block_pass(node); return null; case NODE_ITER: case NODE_FOR: rubyBlock.push(node.nd_var(), node.nd_body(), self); rubyIter.push(Iter.ITER_PRE); while (true) { try { if (node.nd_type() == NODE_ITER) { result = eval(self, node.nd_iter()); } else { // String file = // int line = rubyBlock.flags &= ~RubyBlock.BLOCK_D_SCOPE; RubyBlock tmpBlock = beginCallargs(); RubyObject recv = eval(self, node.nd_iter()); endCallArgs(tmpBlock); // = file; // = line; result = recv.getRubyClass().call(recv, ruby.intern("each"), null, 0); } break; } catch (RetryException rExcptn) { } catch (ReturnException rExcptn) { result = rExcptn.getReturnValue(); break; } catch (BreakException bExcptn) { result = ruby.getNil(); break; } } rubyIter.pop(); rubyBlock.pop(); return result; case NODE_BREAK: throw new BreakException(); case NODE_NEXT: throw new NextException(); case NODE_REDO: throw new RedoException(); case NODE_RETRY: throw new RetryException(); case NODE_RESTARGS: result = eval(self, node.nd_head()); if (!(result instanceof RubyArray)) { result = obj = RubyArray.m_newArray(getRuby(), result); } return result; case NODE_YIELD: if (node.nd_stts() != null) { result = eval(self, node.nd_stts()); if (node.nd_stts().nd_type() == NODE_RESTARGS && ((RubyArray)result).length() == 1) { result = ((RubyArray)result).entry(0); } } else { result = ruby.getNil(); } return yield0(result, null, null, false); case NODE_RESCUE:/* retry_entry: { volatile VALUE e_info = ruby_errinfo; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, node->nd_head); } POP_TAG(); if (state == TAG_RAISE) { NODE * volatile resq = node->nd_resq; ruby_sourceline = nd_line(node); while (resq) { if (handle_rescue(self, resq)) { state = 0; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, resq->nd_body); } POP_TAG(); if (state == TAG_RETRY) { state = 0; ruby_errinfo = Qnil; goto retry_entry; } if (state != TAG_RAISE) { ruby_errinfo = e_info; } break; } resq = resq->nd_head; /* next rescue */ /** } * } * else if (node->nd_else) { /* else clause given *//* if (!state) { /* no exception raised *//* result = rb_eval(self, node->nd_else); } } if (state) JUMP_TAG(state); } break;*/ case NODE_ENSURE:/* PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = eval(node.nd_head()); } POP_TAG(); if (node.nd_ensr()) { VALUE retval = prot_tag->retval; /* save retval *//* VALUE errinfo = ruby_errinfo; rb_eval(self, node->nd_ensr); return_value(retval); ruby_errinfo = errinfo; } if (state) JUMP_TAG(state); break;*/ case NODE_AND: cond = (RubyBoolean)eval(self, node.nd_1st()); if (cond.isFalse()) { return cond; } node = node.nd_2nd(); break; case NODE_OR: cond = (RubyBoolean)eval(self, node.nd_1st()); if (cond.isTrue()) { return cond; } node = node.nd_2nd(); break; case NODE_NOT: return RubyBoolean.m_newBoolean(getRuby(), eval(self, node.nd_1st()).isFalse()); case NODE_DOT2: case NODE_DOT3: result = RubyRange.m_newRange(getRuby(), eval(self, node.nd_beg()), eval(self, node.nd_end()), node.nd_type() == NODE_DOT3); if (node.nd_state() != 0) { return result; } if (node.nd_beg().nd_type() == NODE_LIT && (node.nd_beg().nd_lit() instanceof RubyFixnum) && node.nd_end().nd_type() == NODE_LIT && (node.nd_end().nd_lit() instanceof RubyFixnum)) { node.nd_set_type(NODE_LIT); node.nd_lit(result); } else { node.nd_state(1L); } return result; case NODE_FLIP2: /* like AWK */ /*if (ruby_scope->local_vars == 0) { rb_bug("unexpected local variable"); }*/ if (ruby.rubyScope.getLocalVars(node.nd_cnt()).isFalse()) { if (eval(self, node.nd_beg()).isTrue()) { ruby.rubyScope.setLocalVars(node.nd_cnt(), eval(self, node.nd_end()).isTrue() ? ruby.getFalse() : ruby.getTrue()); result = ruby.getTrue(); } else { result = ruby.getFalse(); } } else { if (eval(self, node.nd_end()).isTrue()) { ruby.rubyScope.setLocalVars(node.nd_cnt(), ruby.getFalse()); } result = ruby.getTrue(); } return result; case NODE_FLIP3: /* like SED */ /*if (ruby_scope->local_vars == 0) { rb_bug("unexpected local variable"); }*/ if (ruby.rubyScope.getLocalVars(node.nd_cnt()).isFalse()) { result = eval(self, node.nd_beg()).isTrue() ? ruby.getFalse() : ruby.getTrue(); ruby.rubyScope.setLocalVars(node.nd_cnt(), result); } else { if (eval(self, node.nd_end()).isTrue()) { ruby.rubyScope.setLocalVars(node.nd_cnt(), ruby.getFalse()); } result = ruby.getTrue(); } return result; case NODE_RETURN: if (node.nd_stts() != null) { result = eval(self, node.nd_stts()); } else { result = ruby.getNil(); } throw new ReturnException(result); case NODE_ARGSCAT: return ((RubyArray)eval(self, node.nd_head())).m_concat(eval(self, node.nd_body())); case NODE_ARGSPUSH: return ((RubyArray)eval(self, node.nd_head()).m_dup()).push(eval(self, node.nd_body())); case NODE_CALL: // TMP_PROTECT; RubyBlock tmpBlock = beginCallargs(); RubyObject recv = eval(self, node.nd_recv()); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); return recv.getRubyClass().call(recv, (RubyId)node.nd_mid(), args, 0); case NODE_FCALL: // TMP_PROTECT; tmpBlock = beginCallargs(); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); return self.getRubyClass().call(self, (RubyId)node.nd_mid(), args, 1); case NODE_VCALL: return self.getRubyClass().call(self, (RubyId)node.nd_mid(), null, 2); case NODE_SUPER: case NODE_ZSUPER: // TMP_PROTECT; if (rubyFrame.getLastClass() == null) { throw new RubyNameException("superclass method '" + rubyFrame.getLastFunc().toName() + "' disabled"); } if (node.nd_type() == NODE_ZSUPER) { List argsList = rubyFrame.getArgs(); args = (RubyObject[])argsList.toArray(new RubyObject[argsList.size()]); } else { tmpBlock = beginCallargs(); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); } rubyIter.push(rubyIter.getIter() != Iter.ITER_NOT ? Iter.ITER_PRE : Iter.ITER_NOT); result = rubyFrame.getLastClass().getSuperClass().call(rubyFrame.getSelf(), rubyFrame.getLastFunc(), args, 3); rubyIter.pop(); return result; case NODE_SCOPE: NODE saved_cref = null; Frame frame = rubyFrame; frame.setTmp(rubyFrame); rubyFrame = frame; ruby.rubyScope.push(); if (node.nd_rval() != null) { saved_cref = ruby_cref; ruby_cref = (NODE)node.nd_rval(); rubyFrame.setCbase(node.nd_rval()); } if (node.nd_tbl() != null) { List tmp = Collections.nCopies(node.nd_tbl()[0].intValue() + 1, ruby.getNil()); ShiftableList vars = new ShiftableList(new ArrayList(tmp)); vars.set(0, (VALUE)node); vars.shift(1); getRuby().rubyScope.setLocalVars(vars); getRuby().rubyScope.setLocalTbl(node.nd_tbl()); } else { getRuby().rubyScope.setLocalVars(null); getRuby().rubyScope.setLocalTbl(null); } result = eval(self, node.nd_next()); ruby.rubyScope.pop(); rubyFrame = frame.getTmp(); if (saved_cref != null) { ruby_cref = saved_cref; } return result; case NODE_OP_ASGN1: // TMP_PROTECT; recv = eval(self, node.nd_recv()); NODE rval = node.nd_args().nd_head(); args = setupArgs(self, node.nd_args().nd_next()); ArrayList argsList = new ArrayList(Arrays.asList(args)); argsList.remove(args.length - 1); RubyBoolean val = (RubyBoolean)recv.funcall(getRuby().intern("[]"), (RubyObject[])argsList.toArray(new RubyObject[argsList.size()])); switch (node.nd_mid().intValue()) { case 0: /* OR */ if (val.isTrue()) { return val; } val = (RubyBoolean)eval(self, rval); break; case 1: /* AND */ if (val.isFalse()) { return val; } val = (RubyBoolean)eval(self, rval); break; default: val = (RubyBoolean)val.funcall((RubyId)node.nd_mid(), eval(self, rval)); } args[args.length - 1] = val; return recv.funcall(getRuby().intern("[]="), args); case NODE_OP_ASGN2: ID id = node.nd_next().nd_vid(); recv = eval(self, node.nd_recv()); val = (RubyBoolean)recv.funcall((RubyId)id, (RubyObject[])null); switch (node.nd_next().nd_mid().intValue()) { case 0: /* OR */ if (val.isTrue()) { return val; } val = (RubyBoolean)eval(self, node.nd_value()); break; case 1: /* AND */ if (val.isFalse()) { return val; } val = (RubyBoolean)eval(self, node.nd_value()); break; default: val = (RubyBoolean)val.funcall((RubyId)node.nd_mid(), eval(self, node.nd_value())); } // HACK +++ val = (RubyBoolean)recv.funcall((RubyId)node.nd_next().nd_aid(), val); // HACK --- return val; case NODE_OP_ASGN_AND: cond = (RubyBoolean)eval(self, node.nd_head()); if (cond.isFalse()) { return cond; } node = node.nd_value(); break; case NODE_OP_ASGN_OR: cond = (RubyBoolean)eval(self, node.nd_head()); if ((node.nd_aid() != null && !self.isInstanceVarDefined((RubyId)node.nd_aid())) || cond.isFalse()) { node = node.nd_value(); break; } return cond; case NODE_MASGN: return massign(self, node, eval(self, node.nd_value()), false); case NODE_LASGN: // if (ruby.ruby_scope.local_vars == null) { // rb_bug("unexpected local variable assignment"); // } result = eval(self, node.nd_value()); getRuby().rubyScope.setLocalVars(node.nd_cnt(), result); return result; case NODE_DASGN: result = eval(self, node.nd_value()); RubyVarmap.assign(ruby, (RubyId)node.nd_vid(), result); return result; case NODE_DASGN_CURR: result = eval(self, node.nd_value()); RubyVarmap.assignCurrent(ruby, (RubyId)node.nd_vid(), result); return result; case NODE_GASGN: result = eval(self, node.nd_value()); ((RubyGlobalEntry)node.nd_entry()).set(result); return result; case NODE_IASGN: result = eval(self, node.nd_value()); self.setInstanceVar((RubyId)node.nd_vid(), result); return result; case NODE_CDECL: if (ruby_class == null) { throw new RubyTypeException("no class/module to define constant"); } result = eval(self, node.nd_value()); ruby_class.setConstant((RubyId)node.nd_vid(), result); return result; case NODE_CVDECL: if (ruby_cbase == null) { throw new RubyTypeException("no class/module to define class variable"); } result = eval(self, node.nd_value()); if (ruby_cbase.isSingleton()) { ruby_cbase.getInstanceVar("__attached__").getClassVarSingleton().declareClassVar((RubyId)node.nd_vid(), result); return result; } ruby_cbase.declareClassVar((RubyId)node.nd_vid(), result); return result; case NODE_CVASGN: result = eval(self, node.nd_value()); self.getClassVarSingleton().setClassVar((RubyId)node.nd_vid(), result); return result; case NODE_LVAR: //if (getRuby().ruby_scope.local_vars == null) { // rb_bug("unexpected local variable"); // } return (RubyObject)getRuby().rubyScope.getLocalVars(node.nd_cnt()); case NODE_DVAR: return getDynamicVars().getRef((RubyId)node.nd_vid()); case NODE_GVAR: return ((RubyGlobalEntry)node.nd_entry()).get(); case NODE_IVAR: return self.getInstanceVar((RubyId)node.nd_vid()); case NODE_CONST: return getConstant((NODE)rubyFrame.getCbase(), (RubyId)node.nd_vid(), self); case NODE_CVAR: /* normal method */ if (ruby_cbase == null) { return self.getRubyClass().getClassVar((RubyId)node.nd_vid()); } if (!ruby_cbase.isSingleton()) { return ruby_cbase.getClassVar((RubyId)node.nd_vid()); } return ruby_cbase.getInstanceVar("__attached__").getClassVarSingleton().getClassVar((RubyId)node.nd_vid()); case NODE_CVAR2: /* singleton method */ return self.getClassVarSingleton().getClassVar((RubyId)node.nd_vid()); case NODE_BLOCK_ARG: if (ruby.rubyScope.getLocalVars() == null) { throw new RuntimeException("BUG: unexpected block argument"); } if (isBlockGiven()) { result = getRuby().getNil(); // Create Proc object ruby.rubyScope.setLocalVars(node.nd_cnt(), result); return result; } else { return getRuby().getNil(); } case NODE_COLON2: value = eval(self, node.nd_head()); if (value instanceof RubyModule) { return ((RubyModule)value).getConstant((RubyId)node.nd_mid()); } else { return value.funcall((RubyId)node.nd_mid()); } case NODE_COLON3: return getRuby().getObjectClass().getConstant((RubyId)node.nd_mid()); case NODE_NTH_REF: // return rom.rb_reg_nth_match(node.nd_nth(), MATCH_DATA); return null; case NODE_BACK_REF: /*switch ((char)node.nd_nth()) { case '&': return rom.rb_reg_last_match(MATCH_DATA); case '`': return rom.rb_reg_match_pre(MATCH_DATA); case '\'': return rom.rb_reg_match_post(MATCH_DATA); case '+': return rom.rb_reg_match_last(MATCH_DATA); default: rom.rb_bug("unexpected back-ref"); }*/ case NODE_HASH: RubyHash hash = RubyHash.m_newHash(ruby); NODE list = node.nd_head(); while(list != null) { RubyObject key = eval(self, list.nd_head()); list = list.nd_next(); if (list == null) { // HACK +++ throw new RubyArgumentException("odd number list for Hash"); // HACK --- } value = eval(self, list.nd_head()); hash.m_aset(key, value); list = list.nd_next(); } return hash; case NODE_ZARRAY: /* zero length list */ return RubyArray.m_newArray(getRuby()); case NODE_ARRAY: ArrayList ary = new ArrayList(node.nd_alen()); for (; node != null ; node = node.nd_next()) { ary.add(eval(self, node.nd_head())); } return RubyArray.m_newArray(getRuby(), ary); case NODE_STR: return ((RubyObject)node.nd_lit()).m_to_s(); case NODE_DSTR: case NODE_DXSTR: case NODE_DREGX: case NODE_DREGX_ONCE:/* NODE list = node.nd_next(); RubyString str = RubyString.m_newString(getRuby(), (RubyObject)node.nd_lit()); RubyString str2; while (list != null) { if (list.nd_head() != null) { switch (list.nd_head().nd_type()) { case NODE_STR: str2 = (RubyString)list.nd_head().nd_lit(); break; case NODE_EVSTR: result = ruby_errinfo; ruby_errinfo = Qnil; ruby_sourceline = nd_line(node); ruby_in_eval++; list.nd_head(compile(list.nd_head().nd_lit(), ruby_sourcefile,ruby_sourceline)); ruby_eval_tree = 0; ruby_in_eval--; if (ruby_nerrs > 0) { compile_error("string expansion"); } if (!NIL_P(result)) ruby_errinfo = result; /* fall through *//* default: str2 = (RubyString)rom.rb_obj_as_string(eval(list.nd_head())); break; } str.append(str2); str.infectObject(str2); } list = list.nd_next(); } switch (node.nd_type()) { case NODE_DREGX: return rom.rb_reg_new(str.getString(), str.getString().length(), node.nd_cflag()); case NODE_DREGX_ONCE: /* regexp expand once *//* VALUE result = rom.rb_reg_new(str.getString(), str.getString().length(), node.nd_cflag()); node.nd_set_type(NODE_LIT); node.nd_lit(result); return result; case NODE_DXSTR: return rom.rb_funcall(this, '`', 1, str); default: return str; }*/ return null; case NODE_XSTR: return self.funcall(getRuby().intern("`"), (RubyObject)node.nd_lit()); case NODE_LIT: return (RubyObject)node.nd_lit(); case NODE_ATTRSET: if (rubyFrame.getArgs().size() != 1) { throw new RubyArgumentException("wrong # of arguments(" + rubyFrame.getArgs().size() + "for 1)"); } return self.setInstanceVar((RubyId)node.nd_vid(), (RubyObject)rubyFrame.getArgs().get(0)); case NODE_DEFN: if (node.nd_defn() != null) { int noex; if (ruby_class == null) { throw new RubyTypeException("no class to add method"); } //if (ruby_class == getRuby().getObjectClass() && node.nd_mid() == init) { // rom.rb_warn("redefining Object#initialize may cause infinite loop"); //} //if (node.nd_mid() == __id__ || node.nd_mid() == __send__) { // rom.rb_warn("redefining `%s' may cause serious problem", ((RubyId)node.nd_mid()).toName()); //} // ruby_class.setFrozen(true); NODE body = ruby_class.searchMethod((RubyId)node.nd_mid()); RubyObject origin = ruby_class.getMethodOrigin((RubyId)node.nd_mid()); if (body != null){ // if (ruby_verbose.isTrue() && ruby_class == origin && body.nd_cnt() == 0) { // rom.rb_warning("discarding old %s", ((RubyId)node.nd_mid()).toName()); // } // if (node.nd_noex() != 0) { /* toplevel */ /* should upgrade to rb_warn() if no super was called inside? */ // rom.rb_warning("overriding global function `%s'", ((RubyId)node.nd_mid()).toName()); // } } if (isScope(SCOPE_PRIVATE) || node.nd_mid().equals(ruby.intern("initialize"))) { noex = NOEX_PRIVATE; } else if (isScope(SCOPE_PROTECTED)) { noex = NOEX_PROTECTED; } else if (ruby_class == getRuby().getObjectClass()) { noex = node.nd_noex(); } else { noex = NOEX_PUBLIC; } if (body != null && origin == ruby_class && (body.nd_noex() & NOEX_UNDEF) != 0) { noex |= NOEX_UNDEF; } NODE defn = node.nd_defn().copyNodeScope(ruby_cref); ruby_class.addMethod((RubyId)node.nd_mid(), defn, noex); // rb_clear_cache_by_id(node.nd_mid()); if (scope_vmode == SCOPE_MODFUNC) { ruby_class.getSingletonClass().addMethod((RubyId)node.nd_mid(), defn, NOEX_PUBLIC); ruby_class.funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } if (ruby_class.isSingleton()) { ruby_class.getInstanceVar("__attached__").funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } else { ruby_class.funcall(getRuby().intern("method_added"), ((RubyId)node.nd_mid()).toSymbol()); } } return getRuby().getNil(); case NODE_DEFS: if (node.nd_defn() != null) { recv = eval(self, node.nd_recv()); if (getRuby().getSecurityLevel() >= 4 && !recv.isTaint()) { throw new RubySecurityException("Insecure; can't define singleton method"); } /*if (FIXNUM_P(recv) || SYMBOL_P(recv)) { rb_raise(rb_eTypeError, "can't define singleton method \"%s\" for %s", rb_id2name(node.nd_mid()), rb_class2name(CLASS_OF(recv))); }*/ // not needed in jruby if (recv.isFrozen()) { throw new RubyFrozenException("object"); } rubyClass = recv.getSingletonClass(); NODE body = (NODE)rubyClass.getMethods().get((RubyId)node.nd_mid()); if (body != null) { if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("redefining method prohibited"); } /*if (RTEST(ruby_verbose)) { rb_warning("redefine %s", rb_id2name(node.nd_mid())); }*/ } NODE defn = node.nd_defn().copyNodeScope(ruby_cref); defn.nd_rval(ruby_cref); rubyClass.addMethod((RubyId)node.nd_mid(), defn, NOEX_PUBLIC | (body != null ? body.nd_noex() & NOEX_UNDEF : 0)); // rb_clear_cache_by_id(node.nd_mid()); recv.funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } return getRuby().getNil(); case NODE_UNDEF: if (ruby_class == null) { throw new RubyTypeException("no class to undef method"); } ruby_class.undef((RubyId)node.nd_mid()); return getRuby().getNil(); case NODE_ALIAS: if (ruby_class == null) { throw new RubyTypeException("no class to make alias"); } ruby_class.aliasMethod((RubyId)node.nd_new(), (RubyId)node.nd_old()); ruby_class.funcall(getRuby().intern("method_added"), ((RubyId)node.nd_mid()).toSymbol()); return getRuby().getNil(); case NODE_VALIAS: RubyGlobalEntry.getGlobalEntry((RubyId)node.nd_old()).alias((RubyId)node.nd_new()); return getRuby().getNil(); case NODE_CLASS: RubyModule superClass; if (ruby_class == null) { throw new RubyTypeException("no outer class/module"); } if (node.nd_super() != null) { superClass = getSuperClass(self, node.nd_super()); } else { superClass = null; } rubyClass = null; // if ((ruby_class == getRuby().getObjectClass()) && rb_autoload_defined(node.nd_cname())) { // rb_autoload_load(node.nd_cname()); // } if (ruby_class.isConstantDefined((RubyId)node.nd_cname())) { rubyClass = (RubyClass)ruby_class.getConstant((RubyId)node.nd_cname()); } if (rubyClass != null) { if (!rubyClass.isClass()) { throw new RubyTypeException(((RubyId)node.nd_cname()).toName() + " is not a class"); } if (superClass != null) { RubyModule tmp = rubyClass.getSuperClass(); if (tmp.isSingleton()) { tmp = tmp.getSuperClass(); } while (tmp.isIncluded()) { tmp = tmp.getSuperClass(); } if (tmp != superClass) { superClass = tmp; //goto override_class; if (superClass == null) { superClass = getRuby().getObjectClass(); } rubyClass = getRuby().defineClassId((RubyId)node.nd_cname(), (RubyClass)superClass); ruby_class.setConstant((RubyId)node.nd_cname(), rubyClass); rubyClass.setClassPath((RubyClass)ruby_class, ((RubyId)node.nd_cname()).toName()); // end goto } } if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("extending class prohibited"); } // rb_clear_cache(); } else { //override_class: if (superClass == null) { superClass = getRuby().getObjectClass(); } rubyClass = getRuby().defineClassId((RubyId)node.nd_cname(), (RubyClass)superClass); ruby_class.setConstant((RubyId)node.nd_cname(), rubyClass); rubyClass.setClassPath((RubyClass)ruby_class, ((RubyId)node.nd_cname()).toName()); } if (ruby_wrapper != null) { rubyClass.getSingletonClass().includeModule(ruby_wrapper); rubyClass.includeModule(ruby_wrapper); } return setupModule(rubyClass, node.nd_body()); case NODE_MODULE: if (ruby_class == null) { throw new RubyTypeException("no outer class/module"); } RubyModule module = null; if ((ruby_class == getRuby().getObjectClass()) && getRuby().isAutoloadDefined((RubyId)node.nd_cname())) { // getRuby().rb_autoload_load(node.nd_cname()); } if (ruby_class.isConstantDefined((RubyId)node.nd_cname())) { module = (RubyModule)ruby_class.getConstant((RubyId)node.nd_cname()); } if (module != null) { if (!(module instanceof RubyModule)) { throw new RubyTypeException(((RubyId)node.nd_cname()).toName() + " is not a module"); } if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("extending module prohibited"); } } else { module = getRuby().defineModuleId((RubyId)node.nd_cname()); ruby_class.setConstant((RubyId)node.nd_cname(), module); module.setClassPath(ruby_class, ((RubyId)node.nd_cname()).toName()); } if (ruby_wrapper != null) { module.getSingletonClass().includeModule(ruby_wrapper); module.includeModule(ruby_wrapper); } return setupModule(module, node.nd_body()); case NODE_SCLASS: rubyClass = (RubyClass)eval(self, node.nd_recv()); if (rubyClass.isSpecialConst()) { throw new RubyTypeException("no virtual class for " + rubyClass.getRubyClass().toName()); } if (getRuby().getSecurityLevel() >= 4 && !rubyClass.isTaint()) { throw new RubySecurityException("Insecure: can't extend object"); } if (rubyClass.getRubyClass().isSingleton()) { // rb_clear_cache(); } rubyClass = rubyClass.getSingletonClass(); if (ruby_wrapper != null) { rubyClass.getSingletonClass().includeModule(ruby_wrapper); rubyClass.includeModule(ruby_wrapper); } return setupModule(rubyClass, node.nd_body()); case NODE_DEFINED: // String buf; // String desc = is_defined(self, node.nd_head(), buf); // // if (desc) { // result = rb_str_new2(desc); // } else { // result = Qnil; // } case NODE_NEWLINE: // ruby_sourcefile = node.nd_file; // ruby_sourceline = node.nd_nth(); // if (trace_func) { // call_trace_func("line", ruby_sourcefile, ruby_sourceline, self, // ruby_frame.last_func(), // ruby_frame.last_class()); // } node = node.nd_next(); break; default: // rom.rb_bug("unknown node type %d", nd_type(node)); } } }
public RubyObject eval(RubyObject self, NODE n) { NODE node = n; RubyBoolean cond = null; RubyObject[] args = null; RubyObject value = null; RubyObject result = null; RubyModule rubyClass = null; // int state; // RubyOriginalMethods rom = getRuby().getOriginalMethods(); while (true) { if (node == null) { return getRuby().getNil(); } switch (node.nd_type()) { case NODE_BLOCK: while (node.nd_next() != null) { eval(self, node.nd_head()); node = node.nd_next(); } node = node.nd_head(); break; case NODE_POSTEXE: // rb_f_END(); node.nd_set_type(NODE_NIL); /* exec just once */ return getRuby().getNil(); /* begin .. end without clauses */ case NODE_BEGIN: node = node.nd_body(); break; /* nodes for speed-up(default match) */ case NODE_MATCH: //return rom.rb_reg_match2(node.nd_head().nd_lit()); return getRuby().getNil(); /* nodes for speed-up(literal match) */ case NODE_MATCH2: //return rom.rb_reg_match(eval(node.nd_recv()), eval(node.nd_value())); return getRuby().getNil(); /* nodes for speed-up(literal match) */ case NODE_MATCH3: //VALUE r = eval(node.nd_recv()); //VALUE l = eval(node.nd_value()); //if (r instanceof RubyString) { // return rom.rb_reg_match(l, r); //} else { // return rom.rb_funcall(r, match, 1, l); //} return getRuby().getNil(); /* node for speed-up(top-level loop for -n/-p) */ case NODE_OPT_N: while (true) { try { // while (!rb_gets().isNil() false) { // HACK +++ if (true) { // HACK --- try { eval(self, node.nd_body()); } catch (RedoException rExcptn) { } } break; } catch (NextException nExcptn) { } catch (BreakException bExcptn) { break; } } return getRuby().getNil(); case NODE_SELF: return self; case NODE_NIL: return getRuby().getNil(); case NODE_TRUE: return getRuby().getTrue(); case NODE_FALSE: return getRuby().getFalse(); case NODE_IF: // ruby_sourceline = node.nd_line(); cond = (RubyBoolean)eval(self, node.nd_cond()); if (cond.isTrue()) { node = node.nd_body(); } else { node = node.nd_else(); } break; case NODE_WHEN: while (node != null) { NODE tag; if (node.nd_type() != NODE_WHEN) { break; } tag = node.nd_head(); while (tag != null) {/* if (trace_func) { call_trace_func("line", tag->nd_file, nd_line(tag), self, ruby_frame->last_func, ruby_frame->last_class); }*/ // ruby_sourcefile = tag.nd_file; // ruby_sourceline = tag.nd_line(); if (tag.nd_head().nd_type() == NODE_WHEN) { RubyObject obj = eval(self, tag.nd_head().nd_head()); if (!(obj instanceof RubyArray)) { obj = RubyArray.m_newArray(getRuby(), obj); } for (int i = 0; i < ((RubyArray)obj).length(); i++) { if (((RubyBoolean)((RubyArray)obj).entry(i)).isTrue()) { node = node.nd_body(); break; } } tag = tag.nd_next(); continue; } if (((RubyBoolean)eval(self, tag.nd_head())).isTrue()) { node = node.nd_body(); break; } tag = tag.nd_next(); } node = node.nd_next(); } return getRuby().getNil(); case NODE_CASE: RubyObject obj = eval(self, node.nd_head()); node = node.nd_body(); while (node != null) { NODE tag; if (node.nd_type() != NODE_WHEN) { break; } tag = node.nd_head(); while (tag != null) {/* if (trace_func) { call_trace_func("line", tag->nd_file, nd_line(tag), self, ruby_frame->last_func, ruby_frame->last_class); } ruby_sourcefile = tag->nd_file; ruby_sourceline = nd_line(tag);*/ if (tag.nd_head().nd_type() == NODE_WHEN) { RubyObject obj2 = eval(self, tag.nd_head().nd_head()); if (!(obj2 instanceof RubyArray)) { obj2 = RubyArray.m_newArray(getRuby(), obj2); } for (int i = 0; i < ((RubyArray)obj).length(); i++) { RubyBoolean eqq = (RubyBoolean)((RubyArray)obj2).entry(i).funcall(getRuby().intern("==="), obj); if (eqq.isTrue()) { node = node.nd_body(); break; } } tag = tag.nd_next(); continue; } if (((RubyBoolean)eval(self, tag.nd_head()).funcall(getRuby().intern("==="), obj)).isTrue()) { node = node.nd_body(); break; } tag = tag.nd_next(); } node = node.nd_next(); } return getRuby().getNil(); case NODE_WHILE: while (eval(self, node.nd_cond()).isTrue()) { while (true) { try { eval(self, node.nd_body()); break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { break; } catch (BreakException bExcptn) { return getRuby().getNil(); } } } return getRuby().getNil(); case NODE_UNTIL: while (eval(self, node.nd_cond()).isFalse()) { while (true) { try { eval(self, node.nd_body()); break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { break; } catch (BreakException bExcptn) { return getRuby().getNil(); } } } return getRuby().getNil(); case NODE_BLOCK_PASS: //return block_pass(node); return null; case NODE_ITER: case NODE_FOR: rubyBlock.push(node.nd_var(), node.nd_body(), self); rubyIter.push(Iter.ITER_PRE); while (true) { try { if (node.nd_type() == NODE_ITER) { result = eval(self, node.nd_iter()); } else { // String file = // int line = rubyBlock.flags &= ~RubyBlock.BLOCK_D_SCOPE; RubyBlock tmpBlock = beginCallargs(); RubyObject recv = eval(self, node.nd_iter()); endCallArgs(tmpBlock); // = file; // = line; result = recv.getRubyClass().call(recv, ruby.intern("each"), null, 0); } break; } catch (RetryException rExcptn) { } catch (ReturnException rExcptn) { result = rExcptn.getReturnValue(); break; } catch (BreakException bExcptn) { result = ruby.getNil(); break; } } rubyIter.pop(); rubyBlock.pop(); return result; case NODE_BREAK: throw new BreakException(); case NODE_NEXT: throw new NextException(); case NODE_REDO: throw new RedoException(); case NODE_RETRY: throw new RetryException(); case NODE_RESTARGS: result = eval(self, node.nd_head()); if (!(result instanceof RubyArray)) { result = obj = RubyArray.m_newArray(getRuby(), result); } return result; case NODE_YIELD: if (node.nd_stts() != null) { result = eval(self, node.nd_stts()); if (node.nd_stts().nd_type() == NODE_RESTARGS && ((RubyArray)result).length() == 1) { result = ((RubyArray)result).entry(0); } } else { result = ruby.getNil(); } return yield0(result, null, null, false); case NODE_RESCUE:/* retry_entry: { volatile VALUE e_info = ruby_errinfo; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, node->nd_head); } POP_TAG(); if (state == TAG_RAISE) { NODE * volatile resq = node->nd_resq; ruby_sourceline = nd_line(node); while (resq) { if (handle_rescue(self, resq)) { state = 0; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, resq->nd_body); } POP_TAG(); if (state == TAG_RETRY) { state = 0; ruby_errinfo = Qnil; goto retry_entry; } if (state != TAG_RAISE) { ruby_errinfo = e_info; } break; } resq = resq->nd_head; /* next rescue */ /** } * } * else if (node->nd_else) { /* else clause given *//* if (!state) { /* no exception raised *//* result = rb_eval(self, node->nd_else); } } if (state) JUMP_TAG(state); } break;*/ case NODE_ENSURE:/* PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = eval(node.nd_head()); } POP_TAG(); if (node.nd_ensr()) { VALUE retval = prot_tag->retval; /* save retval *//* VALUE errinfo = ruby_errinfo; rb_eval(self, node->nd_ensr); return_value(retval); ruby_errinfo = errinfo; } if (state) JUMP_TAG(state); break;*/ case NODE_AND: cond = (RubyBoolean)eval(self, node.nd_1st()); if (cond.isFalse()) { return cond; } node = node.nd_2nd(); break; case NODE_OR: cond = (RubyBoolean)eval(self, node.nd_1st()); if (cond.isTrue()) { return cond; } node = node.nd_2nd(); break; case NODE_NOT: return RubyBoolean.m_newBoolean(getRuby(), eval(self, node.nd_1st()).isFalse()); case NODE_DOT2: case NODE_DOT3: result = RubyRange.m_newRange(getRuby(), eval(self, node.nd_beg()), eval(self, node.nd_end()), node.nd_type() == NODE_DOT3); if (node.nd_state() != 0) { return result; } if (node.nd_beg().nd_type() == NODE_LIT && (node.nd_beg().nd_lit() instanceof RubyFixnum) && node.nd_end().nd_type() == NODE_LIT && (node.nd_end().nd_lit() instanceof RubyFixnum)) { node.nd_set_type(NODE_LIT); node.nd_lit(result); } else { node.nd_state(1L); } return result; case NODE_FLIP2: /* like AWK */ /*if (ruby_scope->local_vars == 0) { rb_bug("unexpected local variable"); }*/ if (ruby.rubyScope.getLocalVars(node.nd_cnt()).isFalse()) { if (eval(self, node.nd_beg()).isTrue()) { ruby.rubyScope.setLocalVars(node.nd_cnt(), eval(self, node.nd_end()).isTrue() ? ruby.getFalse() : ruby.getTrue()); result = ruby.getTrue(); } else { result = ruby.getFalse(); } } else { if (eval(self, node.nd_end()).isTrue()) { ruby.rubyScope.setLocalVars(node.nd_cnt(), ruby.getFalse()); } result = ruby.getTrue(); } return result; case NODE_FLIP3: /* like SED */ /*if (ruby_scope->local_vars == 0) { rb_bug("unexpected local variable"); }*/ if (ruby.rubyScope.getLocalVars(node.nd_cnt()).isFalse()) { result = eval(self, node.nd_beg()).isTrue() ? ruby.getFalse() : ruby.getTrue(); ruby.rubyScope.setLocalVars(node.nd_cnt(), result); } else { if (eval(self, node.nd_end()).isTrue()) { ruby.rubyScope.setLocalVars(node.nd_cnt(), ruby.getFalse()); } result = ruby.getTrue(); } return result; case NODE_RETURN: if (node.nd_stts() != null) { result = eval(self, node.nd_stts()); } else { result = ruby.getNil(); } throw new ReturnException(result); case NODE_ARGSCAT: return ((RubyArray)eval(self, node.nd_head())).m_concat(eval(self, node.nd_body())); case NODE_ARGSPUSH: return ((RubyArray)eval(self, node.nd_head()).m_dup()).push(eval(self, node.nd_body())); case NODE_CALL: // TMP_PROTECT; RubyBlock tmpBlock = beginCallargs(); RubyObject recv = eval(self, node.nd_recv()); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); return recv.getRubyClass().call(recv, (RubyId)node.nd_mid(), args, 0); case NODE_FCALL: // TMP_PROTECT; tmpBlock = beginCallargs(); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); return self.getRubyClass().call(self, (RubyId)node.nd_mid(), args, 1); case NODE_VCALL: return self.getRubyClass().call(self, (RubyId)node.nd_mid(), null, 2); case NODE_SUPER: case NODE_ZSUPER: // TMP_PROTECT; if (rubyFrame.getLastClass() == null) { throw new RubyNameException("superclass method '" + rubyFrame.getLastFunc().toName() + "' disabled"); } if (node.nd_type() == NODE_ZSUPER) { List argsList = rubyFrame.getArgs(); args = (RubyObject[])argsList.toArray(new RubyObject[argsList.size()]); } else { tmpBlock = beginCallargs(); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); } rubyIter.push(rubyIter.getIter() != Iter.ITER_NOT ? Iter.ITER_PRE : Iter.ITER_NOT); result = rubyFrame.getLastClass().getSuperClass().call(rubyFrame.getSelf(), rubyFrame.getLastFunc(), args, 3); rubyIter.pop(); return result; case NODE_SCOPE: NODE saved_cref = null; Frame frame = rubyFrame; frame.setTmp(rubyFrame); rubyFrame = frame; ruby.rubyScope.push(); if (node.nd_rval() != null) { saved_cref = ruby_cref; ruby_cref = (NODE)node.nd_rval(); rubyFrame.setCbase(node.nd_rval()); } if (node.nd_tbl() != null) { List tmp = Collections.nCopies(node.nd_tbl()[0].intValue() + 1, ruby.getNil()); ShiftableList vars = new ShiftableList(new ArrayList(tmp)); vars.set(0, (VALUE)node); vars.shift(1); getRuby().rubyScope.setLocalVars(vars); getRuby().rubyScope.setLocalTbl(node.nd_tbl()); } else { getRuby().rubyScope.setLocalVars(null); getRuby().rubyScope.setLocalTbl(null); } result = eval(self, node.nd_next()); ruby.rubyScope.pop(); rubyFrame = frame.getTmp(); if (saved_cref != null) { ruby_cref = saved_cref; } return result; case NODE_OP_ASGN1: // TMP_PROTECT; recv = eval(self, node.nd_recv()); NODE rval = node.nd_args().nd_head(); args = setupArgs(self, node.nd_args().nd_next()); ArrayList argsList = new ArrayList(Arrays.asList(args)); argsList.remove(args.length - 1); RubyBoolean val = (RubyBoolean)recv.funcall(getRuby().intern("[]"), (RubyObject[])argsList.toArray(new RubyObject[argsList.size()])); switch (node.nd_mid().intValue()) { case 0: /* OR */ if (val.isTrue()) { return val; } val = (RubyBoolean)eval(self, rval); break; case 1: /* AND */ if (val.isFalse()) { return val; } val = (RubyBoolean)eval(self, rval); break; default: val = (RubyBoolean)val.funcall((RubyId)node.nd_mid(), eval(self, rval)); } args[args.length - 1] = val; return recv.funcall(getRuby().intern("[]="), args); case NODE_OP_ASGN2: ID id = node.nd_next().nd_vid(); recv = eval(self, node.nd_recv()); val = (RubyBoolean)recv.funcall((RubyId)id, (RubyObject[])null); switch (node.nd_next().nd_mid().intValue()) { case 0: /* OR */ if (val.isTrue()) { return val; } val = (RubyBoolean)eval(self, node.nd_value()); break; case 1: /* AND */ if (val.isFalse()) { return val; } val = (RubyBoolean)eval(self, node.nd_value()); break; default: val = (RubyBoolean)val.funcall((RubyId)node.nd_mid(), eval(self, node.nd_value())); } // HACK +++ val = (RubyBoolean)recv.funcall((RubyId)node.nd_next().nd_aid(), val); // HACK --- return val; case NODE_OP_ASGN_AND: cond = (RubyBoolean)eval(self, node.nd_head()); if (cond.isFalse()) { return cond; } node = node.nd_value(); break; case NODE_OP_ASGN_OR: cond = (RubyBoolean)eval(self, node.nd_head()); if ((node.nd_aid() != null && !self.isInstanceVarDefined((RubyId)node.nd_aid())) || cond.isFalse()) { node = node.nd_value(); break; } return cond; case NODE_MASGN: return massign(self, node, eval(self, node.nd_value()), false); case NODE_LASGN: // if (ruby.ruby_scope.local_vars == null) { // rb_bug("unexpected local variable assignment"); // } result = eval(self, node.nd_value()); getRuby().rubyScope.setLocalVars(node.nd_cnt(), result); return result; case NODE_DASGN: result = eval(self, node.nd_value()); RubyVarmap.assign(ruby, (RubyId)node.nd_vid(), result); return result; case NODE_DASGN_CURR: result = eval(self, node.nd_value()); RubyVarmap.assignCurrent(ruby, (RubyId)node.nd_vid(), result); return result; case NODE_GASGN: result = eval(self, node.nd_value()); ((RubyGlobalEntry)node.nd_entry()).set(result); return result; case NODE_IASGN: result = eval(self, node.nd_value()); self.setInstanceVar((RubyId)node.nd_vid(), result); return result; case NODE_CDECL: if (ruby_class == null) { throw new RubyTypeException("no class/module to define constant"); } result = eval(self, node.nd_value()); ruby_class.setConstant((RubyId)node.nd_vid(), result); return result; case NODE_CVDECL: if (ruby_cbase == null) { throw new RubyTypeException("no class/module to define class variable"); } result = eval(self, node.nd_value()); if (ruby_cbase.isSingleton()) { ruby_cbase.getInstanceVar("__attached__").getClassVarSingleton().declareClassVar((RubyId)node.nd_vid(), result); return result; } ruby_cbase.declareClassVar((RubyId)node.nd_vid(), result); return result; case NODE_CVASGN: result = eval(self, node.nd_value()); self.getClassVarSingleton().setClassVar((RubyId)node.nd_vid(), result); return result; case NODE_LVAR: //if (getRuby().ruby_scope.local_vars == null) { // rb_bug("unexpected local variable"); // } return (RubyObject)getRuby().rubyScope.getLocalVars(node.nd_cnt()); case NODE_DVAR: return getDynamicVars().getRef((RubyId)node.nd_vid()); case NODE_GVAR: return ((RubyGlobalEntry)node.nd_entry()).get(); case NODE_IVAR: return self.getInstanceVar((RubyId)node.nd_vid()); case NODE_CONST: return getConstant((NODE)getRubyFrame().getCbase(), (RubyId)node.nd_vid(), self); case NODE_CVAR: /* normal method */ if (ruby_cbase == null) { return self.getRubyClass().getClassVar((RubyId)node.nd_vid()); } if (!ruby_cbase.isSingleton()) { return ruby_cbase.getClassVar((RubyId)node.nd_vid()); } return ruby_cbase.getInstanceVar("__attached__").getClassVarSingleton().getClassVar((RubyId)node.nd_vid()); case NODE_CVAR2: /* singleton method */ return self.getClassVarSingleton().getClassVar((RubyId)node.nd_vid()); case NODE_BLOCK_ARG: if (ruby.rubyScope.getLocalVars() == null) { throw new RuntimeException("BUG: unexpected block argument"); } if (isBlockGiven()) { result = getRuby().getNil(); // Create Proc object ruby.rubyScope.setLocalVars(node.nd_cnt(), result); return result; } else { return getRuby().getNil(); } case NODE_COLON2: value = eval(self, node.nd_head()); if (value instanceof RubyModule) { return ((RubyModule)value).getConstant((RubyId)node.nd_mid()); } else { return value.funcall((RubyId)node.nd_mid()); } case NODE_COLON3: return getRuby().getObjectClass().getConstant((RubyId)node.nd_mid()); case NODE_NTH_REF: // return rom.rb_reg_nth_match(node.nd_nth(), MATCH_DATA); return null; case NODE_BACK_REF: /*switch ((char)node.nd_nth()) { case '&': return rom.rb_reg_last_match(MATCH_DATA); case '`': return rom.rb_reg_match_pre(MATCH_DATA); case '\'': return rom.rb_reg_match_post(MATCH_DATA); case '+': return rom.rb_reg_match_last(MATCH_DATA); default: rom.rb_bug("unexpected back-ref"); }*/ case NODE_HASH: RubyHash hash = RubyHash.m_newHash(ruby); NODE list = node.nd_head(); while(list != null) { RubyObject key = eval(self, list.nd_head()); list = list.nd_next(); if (list == null) { // HACK +++ throw new RubyArgumentException("odd number list for Hash"); // HACK --- } value = eval(self, list.nd_head()); hash.m_aset(key, value); list = list.nd_next(); } return hash; case NODE_ZARRAY: /* zero length list */ return RubyArray.m_newArray(getRuby()); case NODE_ARRAY: ArrayList ary = new ArrayList(node.nd_alen()); for (; node != null ; node = node.nd_next()) { ary.add(eval(self, node.nd_head())); } return RubyArray.m_newArray(getRuby(), ary); case NODE_STR: return ((RubyObject)node.nd_lit()).m_to_s(); case NODE_DSTR: case NODE_DXSTR: case NODE_DREGX: case NODE_DREGX_ONCE:/* NODE list = node.nd_next(); RubyString str = RubyString.m_newString(getRuby(), (RubyObject)node.nd_lit()); RubyString str2; while (list != null) { if (list.nd_head() != null) { switch (list.nd_head().nd_type()) { case NODE_STR: str2 = (RubyString)list.nd_head().nd_lit(); break; case NODE_EVSTR: result = ruby_errinfo; ruby_errinfo = Qnil; ruby_sourceline = nd_line(node); ruby_in_eval++; list.nd_head(compile(list.nd_head().nd_lit(), ruby_sourcefile,ruby_sourceline)); ruby_eval_tree = 0; ruby_in_eval--; if (ruby_nerrs > 0) { compile_error("string expansion"); } if (!NIL_P(result)) ruby_errinfo = result; /* fall through *//* default: str2 = (RubyString)rom.rb_obj_as_string(eval(list.nd_head())); break; } str.append(str2); str.infectObject(str2); } list = list.nd_next(); } switch (node.nd_type()) { case NODE_DREGX: return rom.rb_reg_new(str.getString(), str.getString().length(), node.nd_cflag()); case NODE_DREGX_ONCE: /* regexp expand once *//* VALUE result = rom.rb_reg_new(str.getString(), str.getString().length(), node.nd_cflag()); node.nd_set_type(NODE_LIT); node.nd_lit(result); return result; case NODE_DXSTR: return rom.rb_funcall(this, '`', 1, str); default: return str; }*/ return null; case NODE_XSTR: return self.funcall(getRuby().intern("`"), (RubyObject)node.nd_lit()); case NODE_LIT: return (RubyObject)node.nd_lit(); case NODE_ATTRSET: if (rubyFrame.getArgs().size() != 1) { throw new RubyArgumentException("wrong # of arguments(" + rubyFrame.getArgs().size() + "for 1)"); } return self.setInstanceVar((RubyId)node.nd_vid(), (RubyObject)rubyFrame.getArgs().get(0)); case NODE_DEFN: if (node.nd_defn() != null) { int noex; if (ruby_class == null) { throw new RubyTypeException("no class to add method"); } //if (ruby_class == getRuby().getObjectClass() && node.nd_mid() == init) { // rom.rb_warn("redefining Object#initialize may cause infinite loop"); //} //if (node.nd_mid() == __id__ || node.nd_mid() == __send__) { // rom.rb_warn("redefining `%s' may cause serious problem", ((RubyId)node.nd_mid()).toName()); //} // ruby_class.setFrozen(true); NODE body = ruby_class.searchMethod((RubyId)node.nd_mid()); RubyObject origin = ruby_class.getMethodOrigin((RubyId)node.nd_mid()); if (body != null){ // if (ruby_verbose.isTrue() && ruby_class == origin && body.nd_cnt() == 0) { // rom.rb_warning("discarding old %s", ((RubyId)node.nd_mid()).toName()); // } // if (node.nd_noex() != 0) { /* toplevel */ /* should upgrade to rb_warn() if no super was called inside? */ // rom.rb_warning("overriding global function `%s'", ((RubyId)node.nd_mid()).toName()); // } } if (isScope(SCOPE_PRIVATE) || node.nd_mid().equals(ruby.intern("initialize"))) { noex = NOEX_PRIVATE; } else if (isScope(SCOPE_PROTECTED)) { noex = NOEX_PROTECTED; } else if (ruby_class == getRuby().getObjectClass()) { noex = node.nd_noex(); } else { noex = NOEX_PUBLIC; } if (body != null && origin == ruby_class && (body.nd_noex() & NOEX_UNDEF) != 0) { noex |= NOEX_UNDEF; } NODE defn = node.nd_defn().copyNodeScope(ruby_cref); ruby_class.addMethod((RubyId)node.nd_mid(), defn, noex); // rb_clear_cache_by_id(node.nd_mid()); if (scope_vmode == SCOPE_MODFUNC) { ruby_class.getSingletonClass().addMethod((RubyId)node.nd_mid(), defn, NOEX_PUBLIC); ruby_class.funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } if (ruby_class.isSingleton()) { ruby_class.getInstanceVar("__attached__").funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } else { ruby_class.funcall(getRuby().intern("method_added"), ((RubyId)node.nd_mid()).toSymbol()); } } return getRuby().getNil(); case NODE_DEFS: if (node.nd_defn() != null) { recv = eval(self, node.nd_recv()); if (getRuby().getSecurityLevel() >= 4 && !recv.isTaint()) { throw new RubySecurityException("Insecure; can't define singleton method"); } /*if (FIXNUM_P(recv) || SYMBOL_P(recv)) { rb_raise(rb_eTypeError, "can't define singleton method \"%s\" for %s", rb_id2name(node.nd_mid()), rb_class2name(CLASS_OF(recv))); }*/ // not needed in jruby if (recv.isFrozen()) { throw new RubyFrozenException("object"); } rubyClass = recv.getSingletonClass(); NODE body = (NODE)rubyClass.getMethods().get((RubyId)node.nd_mid()); if (body != null) { if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("redefining method prohibited"); } /*if (RTEST(ruby_verbose)) { rb_warning("redefine %s", rb_id2name(node.nd_mid())); }*/ } NODE defn = node.nd_defn().copyNodeScope(ruby_cref); defn.nd_rval(ruby_cref); rubyClass.addMethod((RubyId)node.nd_mid(), defn, NOEX_PUBLIC | (body != null ? body.nd_noex() & NOEX_UNDEF : 0)); // rb_clear_cache_by_id(node.nd_mid()); recv.funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } return getRuby().getNil(); case NODE_UNDEF: if (ruby_class == null) { throw new RubyTypeException("no class to undef method"); } ruby_class.undef((RubyId)node.nd_mid()); return getRuby().getNil(); case NODE_ALIAS: if (ruby_class == null) { throw new RubyTypeException("no class to make alias"); } ruby_class.aliasMethod((RubyId)node.nd_new(), (RubyId)node.nd_old()); ruby_class.funcall(getRuby().intern("method_added"), ((RubyId)node.nd_mid()).toSymbol()); return getRuby().getNil(); case NODE_VALIAS: RubyGlobalEntry.getGlobalEntry((RubyId)node.nd_old()).alias((RubyId)node.nd_new()); return getRuby().getNil(); case NODE_CLASS: RubyModule superClass; if (ruby_class == null) { throw new RubyTypeException("no outer class/module"); } if (node.nd_super() != null) { superClass = getSuperClass(self, node.nd_super()); } else { superClass = null; } rubyClass = null; // if ((ruby_class == getRuby().getObjectClass()) && rb_autoload_defined(node.nd_cname())) { // rb_autoload_load(node.nd_cname()); // } if (ruby_class.isConstantDefined((RubyId)node.nd_cname())) { rubyClass = (RubyClass)ruby_class.getConstant((RubyId)node.nd_cname()); } if (rubyClass != null) { if (!rubyClass.isClass()) { throw new RubyTypeException(((RubyId)node.nd_cname()).toName() + " is not a class"); } if (superClass != null) { RubyModule tmp = rubyClass.getSuperClass(); if (tmp.isSingleton()) { tmp = tmp.getSuperClass(); } while (tmp.isIncluded()) { tmp = tmp.getSuperClass(); } if (tmp != superClass) { superClass = tmp; //goto override_class; if (superClass == null) { superClass = getRuby().getObjectClass(); } rubyClass = getRuby().defineClassId((RubyId)node.nd_cname(), (RubyClass)superClass); ruby_class.setConstant((RubyId)node.nd_cname(), rubyClass); rubyClass.setClassPath((RubyClass)ruby_class, ((RubyId)node.nd_cname()).toName()); // end goto } } if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("extending class prohibited"); } // rb_clear_cache(); } else { //override_class: if (superClass == null) { superClass = getRuby().getObjectClass(); } rubyClass = getRuby().defineClassId((RubyId)node.nd_cname(), (RubyClass)superClass); ruby_class.setConstant((RubyId)node.nd_cname(), rubyClass); rubyClass.setClassPath((RubyClass)ruby_class, ((RubyId)node.nd_cname()).toName()); } if (ruby_wrapper != null) { rubyClass.getSingletonClass().includeModule(ruby_wrapper); rubyClass.includeModule(ruby_wrapper); } return setupModule(rubyClass, node.nd_body()); case NODE_MODULE: if (ruby_class == null) { throw new RubyTypeException("no outer class/module"); } RubyModule module = null; if ((ruby_class == getRuby().getObjectClass()) && getRuby().isAutoloadDefined((RubyId)node.nd_cname())) { // getRuby().rb_autoload_load(node.nd_cname()); } if (ruby_class.isConstantDefined((RubyId)node.nd_cname())) { module = (RubyModule)ruby_class.getConstant((RubyId)node.nd_cname()); } if (module != null) { if (!(module instanceof RubyModule)) { throw new RubyTypeException(((RubyId)node.nd_cname()).toName() + " is not a module"); } if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("extending module prohibited"); } } else { module = getRuby().defineModuleId((RubyId)node.nd_cname()); ruby_class.setConstant((RubyId)node.nd_cname(), module); module.setClassPath(ruby_class, ((RubyId)node.nd_cname()).toName()); } if (ruby_wrapper != null) { module.getSingletonClass().includeModule(ruby_wrapper); module.includeModule(ruby_wrapper); } return setupModule(module, node.nd_body()); case NODE_SCLASS: rubyClass = (RubyClass)eval(self, node.nd_recv()); if (rubyClass.isSpecialConst()) { throw new RubyTypeException("no virtual class for " + rubyClass.getRubyClass().toName()); } if (getRuby().getSecurityLevel() >= 4 && !rubyClass.isTaint()) { throw new RubySecurityException("Insecure: can't extend object"); } if (rubyClass.getRubyClass().isSingleton()) { // rb_clear_cache(); } rubyClass = rubyClass.getSingletonClass(); if (ruby_wrapper != null) { rubyClass.getSingletonClass().includeModule(ruby_wrapper); rubyClass.includeModule(ruby_wrapper); } return setupModule(rubyClass, node.nd_body()); case NODE_DEFINED: // String buf; // String desc = is_defined(self, node.nd_head(), buf); // // if (desc) { // result = rb_str_new2(desc); // } else { // result = Qnil; // } case NODE_NEWLINE: // ruby_sourcefile = node.nd_file; // ruby_sourceline = node.nd_nth(); // if (trace_func) { // call_trace_func("line", ruby_sourcefile, ruby_sourceline, self, // ruby_frame.last_func(), // ruby_frame.last_class()); // } node = node.nd_next(); break; default: // rom.rb_bug("unknown node type %d", nd_type(node)); } } }
3,238,703
public RubyObject eval(RubyObject self, NODE n) { NODE node = n; RubyBoolean cond = null; RubyObject[] args = null; RubyObject value = null; RubyObject result = null; RubyModule rubyClass = null; // int state; // RubyOriginalMethods rom = getRuby().getOriginalMethods(); while (true) { if (node == null) { return getRuby().getNil(); } switch (node.nd_type()) { case NODE_BLOCK: while (node.nd_next() != null) { eval(self, node.nd_head()); node = node.nd_next(); } node = node.nd_head(); break; case NODE_POSTEXE: // rb_f_END(); node.nd_set_type(NODE_NIL); /* exec just once */ return getRuby().getNil(); /* begin .. end without clauses */ case NODE_BEGIN: node = node.nd_body(); break; /* nodes for speed-up(default match) */ case NODE_MATCH: //return rom.rb_reg_match2(node.nd_head().nd_lit()); return getRuby().getNil(); /* nodes for speed-up(literal match) */ case NODE_MATCH2: //return rom.rb_reg_match(eval(node.nd_recv()), eval(node.nd_value())); return getRuby().getNil(); /* nodes for speed-up(literal match) */ case NODE_MATCH3: //VALUE r = eval(node.nd_recv()); //VALUE l = eval(node.nd_value()); //if (r instanceof RubyString) { // return rom.rb_reg_match(l, r); //} else { // return rom.rb_funcall(r, match, 1, l); //} return getRuby().getNil(); /* node for speed-up(top-level loop for -n/-p) */ case NODE_OPT_N: while (true) { try { // while (!rb_gets().isNil() false) { // HACK +++ if (true) { // HACK --- try { eval(self, node.nd_body()); } catch (RedoException rExcptn) { } } break; } catch (NextException nExcptn) { } catch (BreakException bExcptn) { break; } } return getRuby().getNil(); case NODE_SELF: return self; case NODE_NIL: return getRuby().getNil(); case NODE_TRUE: return getRuby().getTrue(); case NODE_FALSE: return getRuby().getFalse(); case NODE_IF: // ruby_sourceline = node.nd_line(); cond = (RubyBoolean)eval(self, node.nd_cond()); if (cond.isTrue()) { node = node.nd_body(); } else { node = node.nd_else(); } break; case NODE_WHEN: while (node != null) { NODE tag; if (node.nd_type() != NODE_WHEN) { break; } tag = node.nd_head(); while (tag != null) {/* if (trace_func) { call_trace_func("line", tag->nd_file, nd_line(tag), self, ruby_frame->last_func, ruby_frame->last_class); }*/ // ruby_sourcefile = tag.nd_file; // ruby_sourceline = tag.nd_line(); if (tag.nd_head().nd_type() == NODE_WHEN) { RubyObject obj = eval(self, tag.nd_head().nd_head()); if (!(obj instanceof RubyArray)) { obj = RubyArray.m_newArray(getRuby(), obj); } for (int i = 0; i < ((RubyArray)obj).length(); i++) { if (((RubyBoolean)((RubyArray)obj).entry(i)).isTrue()) { node = node.nd_body(); break; } } tag = tag.nd_next(); continue; } if (((RubyBoolean)eval(self, tag.nd_head())).isTrue()) { node = node.nd_body(); break; } tag = tag.nd_next(); } node = node.nd_next(); } return getRuby().getNil(); case NODE_CASE: RubyObject obj = eval(self, node.nd_head()); node = node.nd_body(); while (node != null) { NODE tag; if (node.nd_type() != NODE_WHEN) { break; } tag = node.nd_head(); while (tag != null) {/* if (trace_func) { call_trace_func("line", tag->nd_file, nd_line(tag), self, ruby_frame->last_func, ruby_frame->last_class); } ruby_sourcefile = tag->nd_file; ruby_sourceline = nd_line(tag);*/ if (tag.nd_head().nd_type() == NODE_WHEN) { RubyObject obj2 = eval(self, tag.nd_head().nd_head()); if (!(obj2 instanceof RubyArray)) { obj2 = RubyArray.m_newArray(getRuby(), obj2); } for (int i = 0; i < ((RubyArray)obj).length(); i++) { RubyBoolean eqq = (RubyBoolean)((RubyArray)obj2).entry(i).funcall(getRuby().intern("==="), obj); if (eqq.isTrue()) { node = node.nd_body(); break; } } tag = tag.nd_next(); continue; } if (((RubyBoolean)eval(self, tag.nd_head()).funcall(getRuby().intern("==="), obj)).isTrue()) { node = node.nd_body(); break; } tag = tag.nd_next(); } node = node.nd_next(); } return getRuby().getNil(); case NODE_WHILE: while (eval(self, node.nd_cond()).isTrue()) { while (true) { try { eval(self, node.nd_body()); break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { break; } catch (BreakException bExcptn) { return getRuby().getNil(); } } } return getRuby().getNil(); case NODE_UNTIL: while (eval(self, node.nd_cond()).isFalse()) { while (true) { try { eval(self, node.nd_body()); break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { break; } catch (BreakException bExcptn) { return getRuby().getNil(); } } } return getRuby().getNil(); case NODE_BLOCK_PASS: //return block_pass(node); return null; case NODE_ITER: case NODE_FOR: rubyBlock.push(node.nd_var(), node.nd_body(), self); rubyIter.push(Iter.ITER_PRE); while (true) { try { if (node.nd_type() == NODE_ITER) { result = eval(self, node.nd_iter()); } else { // String file = // int line = rubyBlock.flags &= ~RubyBlock.BLOCK_D_SCOPE; RubyBlock tmpBlock = beginCallargs(); RubyObject recv = eval(self, node.nd_iter()); endCallArgs(tmpBlock); // = file; // = line; result = recv.getRubyClass().call(recv, ruby.intern("each"), null, 0); } break; } catch (RetryException rExcptn) { } catch (ReturnException rExcptn) { result = rExcptn.getReturnValue(); break; } catch (BreakException bExcptn) { result = ruby.getNil(); break; } } rubyIter.pop(); rubyBlock.pop(); return result; case NODE_BREAK: throw new BreakException(); case NODE_NEXT: throw new NextException(); case NODE_REDO: throw new RedoException(); case NODE_RETRY: throw new RetryException(); case NODE_RESTARGS: result = eval(self, node.nd_head()); if (!(result instanceof RubyArray)) { result = obj = RubyArray.m_newArray(getRuby(), result); } return result; case NODE_YIELD: if (node.nd_stts() != null) { result = eval(self, node.nd_stts()); if (node.nd_stts().nd_type() == NODE_RESTARGS && ((RubyArray)result).length() == 1) { result = ((RubyArray)result).entry(0); } } else { result = ruby.getNil(); } return yield0(result, null, null, false); case NODE_RESCUE:/* retry_entry: { volatile VALUE e_info = ruby_errinfo; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, node->nd_head); } POP_TAG(); if (state == TAG_RAISE) { NODE * volatile resq = node->nd_resq; ruby_sourceline = nd_line(node); while (resq) { if (handle_rescue(self, resq)) { state = 0; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, resq->nd_body); } POP_TAG(); if (state == TAG_RETRY) { state = 0; ruby_errinfo = Qnil; goto retry_entry; } if (state != TAG_RAISE) { ruby_errinfo = e_info; } break; } resq = resq->nd_head; /* next rescue */ /** } * } * else if (node->nd_else) { /* else clause given *//* if (!state) { /* no exception raised *//* result = rb_eval(self, node->nd_else); } } if (state) JUMP_TAG(state); } break;*/ case NODE_ENSURE:/* PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = eval(node.nd_head()); } POP_TAG(); if (node.nd_ensr()) { VALUE retval = prot_tag->retval; /* save retval *//* VALUE errinfo = ruby_errinfo; rb_eval(self, node->nd_ensr); return_value(retval); ruby_errinfo = errinfo; } if (state) JUMP_TAG(state); break;*/ case NODE_AND: cond = (RubyBoolean)eval(self, node.nd_1st()); if (cond.isFalse()) { return cond; } node = node.nd_2nd(); break; case NODE_OR: cond = (RubyBoolean)eval(self, node.nd_1st()); if (cond.isTrue()) { return cond; } node = node.nd_2nd(); break; case NODE_NOT: return RubyBoolean.m_newBoolean(getRuby(), eval(self, node.nd_1st()).isFalse()); case NODE_DOT2: case NODE_DOT3: result = RubyRange.m_newRange(getRuby(), eval(self, node.nd_beg()), eval(self, node.nd_end()), node.nd_type() == NODE_DOT3); if (node.nd_state() != 0) { return result; } if (node.nd_beg().nd_type() == NODE_LIT && (node.nd_beg().nd_lit() instanceof RubyFixnum) && node.nd_end().nd_type() == NODE_LIT && (node.nd_end().nd_lit() instanceof RubyFixnum)) { node.nd_set_type(NODE_LIT); node.nd_lit(result); } else { node.nd_state(1L); } return result; case NODE_FLIP2: /* like AWK */ /*if (ruby_scope->local_vars == 0) { rb_bug("unexpected local variable"); }*/ if (ruby.rubyScope.getLocalVars(node.nd_cnt()).isFalse()) { if (eval(self, node.nd_beg()).isTrue()) { ruby.rubyScope.setLocalVars(node.nd_cnt(), eval(self, node.nd_end()).isTrue() ? ruby.getFalse() : ruby.getTrue()); result = ruby.getTrue(); } else { result = ruby.getFalse(); } } else { if (eval(self, node.nd_end()).isTrue()) { ruby.rubyScope.setLocalVars(node.nd_cnt(), ruby.getFalse()); } result = ruby.getTrue(); } return result; case NODE_FLIP3: /* like SED */ /*if (ruby_scope->local_vars == 0) { rb_bug("unexpected local variable"); }*/ if (ruby.rubyScope.getLocalVars(node.nd_cnt()).isFalse()) { result = eval(self, node.nd_beg()).isTrue() ? ruby.getFalse() : ruby.getTrue(); ruby.rubyScope.setLocalVars(node.nd_cnt(), result); } else { if (eval(self, node.nd_end()).isTrue()) { ruby.rubyScope.setLocalVars(node.nd_cnt(), ruby.getFalse()); } result = ruby.getTrue(); } return result; case NODE_RETURN: if (node.nd_stts() != null) { result = eval(self, node.nd_stts()); } else { result = ruby.getNil(); } throw new ReturnException(result); case NODE_ARGSCAT: return ((RubyArray)eval(self, node.nd_head())).m_concat(eval(self, node.nd_body())); case NODE_ARGSPUSH: return ((RubyArray)eval(self, node.nd_head()).m_dup()).push(eval(self, node.nd_body())); case NODE_CALL: // TMP_PROTECT; RubyBlock tmpBlock = beginCallargs(); RubyObject recv = eval(self, node.nd_recv()); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); return recv.getRubyClass().call(recv, (RubyId)node.nd_mid(), args, 0); case NODE_FCALL: // TMP_PROTECT; tmpBlock = beginCallargs(); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); return self.getRubyClass().call(self, (RubyId)node.nd_mid(), args, 1); case NODE_VCALL: return self.getRubyClass().call(self, (RubyId)node.nd_mid(), null, 2); case NODE_SUPER: case NODE_ZSUPER: // TMP_PROTECT; if (rubyFrame.getLastClass() == null) { throw new RubyNameException("superclass method '" + rubyFrame.getLastFunc().toName() + "' disabled"); } if (node.nd_type() == NODE_ZSUPER) { List argsList = rubyFrame.getArgs(); args = (RubyObject[])argsList.toArray(new RubyObject[argsList.size()]); } else { tmpBlock = beginCallargs(); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); } rubyIter.push(rubyIter.getIter() != Iter.ITER_NOT ? Iter.ITER_PRE : Iter.ITER_NOT); result = rubyFrame.getLastClass().getSuperClass().call(rubyFrame.getSelf(), rubyFrame.getLastFunc(), args, 3); rubyIter.pop(); return result; case NODE_SCOPE: NODE saved_cref = null; Frame frame = rubyFrame; frame.setTmp(rubyFrame); rubyFrame = frame; ruby.rubyScope.push(); if (node.nd_rval() != null) { saved_cref = ruby_cref; ruby_cref = (NODE)node.nd_rval(); rubyFrame.setCbase(node.nd_rval()); } if (node.nd_tbl() != null) { List tmp = Collections.nCopies(node.nd_tbl()[0].intValue() + 1, ruby.getNil()); ShiftableList vars = new ShiftableList(new ArrayList(tmp)); vars.set(0, (VALUE)node); vars.shift(1); getRuby().rubyScope.setLocalVars(vars); getRuby().rubyScope.setLocalTbl(node.nd_tbl()); } else { getRuby().rubyScope.setLocalVars(null); getRuby().rubyScope.setLocalTbl(null); } result = eval(self, node.nd_next()); ruby.rubyScope.pop(); rubyFrame = frame.getTmp(); if (saved_cref != null) { ruby_cref = saved_cref; } return result; case NODE_OP_ASGN1: // TMP_PROTECT; recv = eval(self, node.nd_recv()); NODE rval = node.nd_args().nd_head(); args = setupArgs(self, node.nd_args().nd_next()); ArrayList argsList = new ArrayList(Arrays.asList(args)); argsList.remove(args.length - 1); RubyBoolean val = (RubyBoolean)recv.funcall(getRuby().intern("[]"), (RubyObject[])argsList.toArray(new RubyObject[argsList.size()])); switch (node.nd_mid().intValue()) { case 0: /* OR */ if (val.isTrue()) { return val; } val = (RubyBoolean)eval(self, rval); break; case 1: /* AND */ if (val.isFalse()) { return val; } val = (RubyBoolean)eval(self, rval); break; default: val = (RubyBoolean)val.funcall((RubyId)node.nd_mid(), eval(self, rval)); } args[args.length - 1] = val; return recv.funcall(getRuby().intern("[]="), args); case NODE_OP_ASGN2: ID id = node.nd_next().nd_vid(); recv = eval(self, node.nd_recv()); val = (RubyBoolean)recv.funcall((RubyId)id, (RubyObject[])null); switch (node.nd_next().nd_mid().intValue()) { case 0: /* OR */ if (val.isTrue()) { return val; } val = (RubyBoolean)eval(self, node.nd_value()); break; case 1: /* AND */ if (val.isFalse()) { return val; } val = (RubyBoolean)eval(self, node.nd_value()); break; default: val = (RubyBoolean)val.funcall((RubyId)node.nd_mid(), eval(self, node.nd_value())); } // HACK +++ val = (RubyBoolean)recv.funcall((RubyId)node.nd_next().nd_aid(), val); // HACK --- return val; case NODE_OP_ASGN_AND: cond = (RubyBoolean)eval(self, node.nd_head()); if (cond.isFalse()) { return cond; } node = node.nd_value(); break; case NODE_OP_ASGN_OR: cond = (RubyBoolean)eval(self, node.nd_head()); if ((node.nd_aid() != null && !self.isInstanceVarDefined((RubyId)node.nd_aid())) || cond.isFalse()) { node = node.nd_value(); break; } return cond; case NODE_MASGN: return massign(self, node, eval(self, node.nd_value()), false); case NODE_LASGN: // if (ruby.ruby_scope.local_vars == null) { // rb_bug("unexpected local variable assignment"); // } result = eval(self, node.nd_value()); getRuby().rubyScope.setLocalVars(node.nd_cnt(), result); return result; case NODE_DASGN: result = eval(self, node.nd_value()); RubyVarmap.assign(ruby, (RubyId)node.nd_vid(), result); return result; case NODE_DASGN_CURR: result = eval(self, node.nd_value()); RubyVarmap.assignCurrent(ruby, (RubyId)node.nd_vid(), result); return result; case NODE_GASGN: result = eval(self, node.nd_value()); ((RubyGlobalEntry)node.nd_entry()).set(result); return result; case NODE_IASGN: result = eval(self, node.nd_value()); self.setInstanceVar((RubyId)node.nd_vid(), result); return result; case NODE_CDECL: if (ruby_class == null) { throw new RubyTypeException("no class/module to define constant"); } result = eval(self, node.nd_value()); ruby_class.setConstant((RubyId)node.nd_vid(), result); return result; case NODE_CVDECL: if (ruby_cbase == null) { throw new RubyTypeException("no class/module to define class variable"); } result = eval(self, node.nd_value()); if (ruby_cbase.isSingleton()) { ruby_cbase.getInstanceVar("__attached__").getClassVarSingleton().declareClassVar((RubyId)node.nd_vid(), result); return result; } ruby_cbase.declareClassVar((RubyId)node.nd_vid(), result); return result; case NODE_CVASGN: result = eval(self, node.nd_value()); self.getClassVarSingleton().setClassVar((RubyId)node.nd_vid(), result); return result; case NODE_LVAR: //if (getRuby().ruby_scope.local_vars == null) { // rb_bug("unexpected local variable"); // } return (RubyObject)getRuby().rubyScope.getLocalVars(node.nd_cnt()); case NODE_DVAR: return getDynamicVars().getRef((RubyId)node.nd_vid()); case NODE_GVAR: return ((RubyGlobalEntry)node.nd_entry()).get(); case NODE_IVAR: return self.getInstanceVar((RubyId)node.nd_vid()); case NODE_CONST: return getConstant((NODE)rubyFrame.getCbase(), (RubyId)node.nd_vid(), self); case NODE_CVAR: /* normal method */ if (ruby_cbase == null) { return self.getRubyClass().getClassVar((RubyId)node.nd_vid()); } if (!ruby_cbase.isSingleton()) { return ruby_cbase.getClassVar((RubyId)node.nd_vid()); } return ruby_cbase.getInstanceVar("__attached__").getClassVarSingleton().getClassVar((RubyId)node.nd_vid()); case NODE_CVAR2: /* singleton method */ return self.getClassVarSingleton().getClassVar((RubyId)node.nd_vid()); case NODE_BLOCK_ARG: if (ruby.rubyScope.getLocalVars() == null) { throw new RuntimeException("BUG: unexpected block argument"); } if (isBlockGiven()) { result = getRuby().getNil(); // Create Proc object ruby.rubyScope.setLocalVars(node.nd_cnt(), result); return result; } else { return getRuby().getNil(); } case NODE_COLON2: value = eval(self, node.nd_head()); if (value instanceof RubyModule) { return ((RubyModule)value).getConstant((RubyId)node.nd_mid()); } else { return value.funcall((RubyId)node.nd_mid()); } case NODE_COLON3: return getRuby().getObjectClass().getConstant((RubyId)node.nd_mid()); case NODE_NTH_REF: // return rom.rb_reg_nth_match(node.nd_nth(), MATCH_DATA); return null; case NODE_BACK_REF: /*switch ((char)node.nd_nth()) { case '&': return rom.rb_reg_last_match(MATCH_DATA); case '`': return rom.rb_reg_match_pre(MATCH_DATA); case '\'': return rom.rb_reg_match_post(MATCH_DATA); case '+': return rom.rb_reg_match_last(MATCH_DATA); default: rom.rb_bug("unexpected back-ref"); }*/ case NODE_HASH: RubyHash hash = RubyHash.m_newHash(ruby); NODE list = node.nd_head(); while(list != null) { RubyObject key = eval(self, list.nd_head()); list = list.nd_next(); if (list == null) { // HACK +++ throw new RubyArgumentException("odd number list for Hash"); // HACK --- } value = eval(self, list.nd_head()); hash.m_aset(key, value); list = list.nd_next(); } return hash; case NODE_ZARRAY: /* zero length list */ return RubyArray.m_newArray(getRuby()); case NODE_ARRAY: ArrayList ary = new ArrayList(node.nd_alen()); for (; node != null ; node = node.nd_next()) { ary.add(eval(self, node.nd_head())); } return RubyArray.m_newArray(getRuby(), ary); case NODE_STR: return ((RubyObject)node.nd_lit()).m_to_s(); case NODE_DSTR: case NODE_DXSTR: case NODE_DREGX: case NODE_DREGX_ONCE:/* NODE list = node.nd_next(); RubyString str = RubyString.m_newString(getRuby(), (RubyObject)node.nd_lit()); RubyString str2; while (list != null) { if (list.nd_head() != null) { switch (list.nd_head().nd_type()) { case NODE_STR: str2 = (RubyString)list.nd_head().nd_lit(); break; case NODE_EVSTR: result = ruby_errinfo; ruby_errinfo = Qnil; ruby_sourceline = nd_line(node); ruby_in_eval++; list.nd_head(compile(list.nd_head().nd_lit(), ruby_sourcefile,ruby_sourceline)); ruby_eval_tree = 0; ruby_in_eval--; if (ruby_nerrs > 0) { compile_error("string expansion"); } if (!NIL_P(result)) ruby_errinfo = result; /* fall through *//* default: str2 = (RubyString)rom.rb_obj_as_string(eval(list.nd_head())); break; } str.append(str2); str.infectObject(str2); } list = list.nd_next(); } switch (node.nd_type()) { case NODE_DREGX: return rom.rb_reg_new(str.getString(), str.getString().length(), node.nd_cflag()); case NODE_DREGX_ONCE: /* regexp expand once *//* VALUE result = rom.rb_reg_new(str.getString(), str.getString().length(), node.nd_cflag()); node.nd_set_type(NODE_LIT); node.nd_lit(result); return result; case NODE_DXSTR: return rom.rb_funcall(this, '`', 1, str); default: return str; }*/ return null; case NODE_XSTR: return self.funcall(getRuby().intern("`"), (RubyObject)node.nd_lit()); case NODE_LIT: return (RubyObject)node.nd_lit(); case NODE_ATTRSET: if (rubyFrame.getArgs().size() != 1) { throw new RubyArgumentException("wrong # of arguments(" + rubyFrame.getArgs().size() + "for 1)"); } return self.setInstanceVar((RubyId)node.nd_vid(), (RubyObject)rubyFrame.getArgs().get(0)); case NODE_DEFN: if (node.nd_defn() != null) { int noex; if (ruby_class == null) { throw new RubyTypeException("no class to add method"); } //if (ruby_class == getRuby().getObjectClass() && node.nd_mid() == init) { // rom.rb_warn("redefining Object#initialize may cause infinite loop"); //} //if (node.nd_mid() == __id__ || node.nd_mid() == __send__) { // rom.rb_warn("redefining `%s' may cause serious problem", ((RubyId)node.nd_mid()).toName()); //} // ruby_class.setFrozen(true); NODE body = ruby_class.searchMethod((RubyId)node.nd_mid()); RubyObject origin = ruby_class.getMethodOrigin((RubyId)node.nd_mid()); if (body != null){ // if (ruby_verbose.isTrue() && ruby_class == origin && body.nd_cnt() == 0) { // rom.rb_warning("discarding old %s", ((RubyId)node.nd_mid()).toName()); // } // if (node.nd_noex() != 0) { /* toplevel */ /* should upgrade to rb_warn() if no super was called inside? */ // rom.rb_warning("overriding global function `%s'", ((RubyId)node.nd_mid()).toName()); // } } if (isScope(SCOPE_PRIVATE) || node.nd_mid().equals(ruby.intern("initialize"))) { noex = NOEX_PRIVATE; } else if (isScope(SCOPE_PROTECTED)) { noex = NOEX_PROTECTED; } else if (ruby_class == getRuby().getObjectClass()) { noex = node.nd_noex(); } else { noex = NOEX_PUBLIC; } if (body != null && origin == ruby_class && (body.nd_noex() & NOEX_UNDEF) != 0) { noex |= NOEX_UNDEF; } NODE defn = node.nd_defn().copyNodeScope(ruby_cref); ruby_class.addMethod((RubyId)node.nd_mid(), defn, noex); // rb_clear_cache_by_id(node.nd_mid()); if (scope_vmode == SCOPE_MODFUNC) { ruby_class.getSingletonClass().addMethod((RubyId)node.nd_mid(), defn, NOEX_PUBLIC); ruby_class.funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } if (ruby_class.isSingleton()) { ruby_class.getInstanceVar("__attached__").funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } else { ruby_class.funcall(getRuby().intern("method_added"), ((RubyId)node.nd_mid()).toSymbol()); } } return getRuby().getNil(); case NODE_DEFS: if (node.nd_defn() != null) { recv = eval(self, node.nd_recv()); if (getRuby().getSecurityLevel() >= 4 && !recv.isTaint()) { throw new RubySecurityException("Insecure; can't define singleton method"); } /*if (FIXNUM_P(recv) || SYMBOL_P(recv)) { rb_raise(rb_eTypeError, "can't define singleton method \"%s\" for %s", rb_id2name(node.nd_mid()), rb_class2name(CLASS_OF(recv))); }*/ // not needed in jruby if (recv.isFrozen()) { throw new RubyFrozenException("object"); } rubyClass = recv.getSingletonClass(); NODE body = (NODE)rubyClass.getMethods().get((RubyId)node.nd_mid()); if (body != null) { if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("redefining method prohibited"); } /*if (RTEST(ruby_verbose)) { rb_warning("redefine %s", rb_id2name(node.nd_mid())); }*/ } NODE defn = node.nd_defn().copyNodeScope(ruby_cref); defn.nd_rval(ruby_cref); rubyClass.addMethod((RubyId)node.nd_mid(), defn, NOEX_PUBLIC | (body != null ? body.nd_noex() & NOEX_UNDEF : 0)); // rb_clear_cache_by_id(node.nd_mid()); recv.funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } return getRuby().getNil(); case NODE_UNDEF: if (ruby_class == null) { throw new RubyTypeException("no class to undef method"); } ruby_class.undef((RubyId)node.nd_mid()); return getRuby().getNil(); case NODE_ALIAS: if (ruby_class == null) { throw new RubyTypeException("no class to make alias"); } ruby_class.aliasMethod((RubyId)node.nd_new(), (RubyId)node.nd_old()); ruby_class.funcall(getRuby().intern("method_added"), ((RubyId)node.nd_mid()).toSymbol()); return getRuby().getNil(); case NODE_VALIAS: RubyGlobalEntry.getGlobalEntry((RubyId)node.nd_old()).alias((RubyId)node.nd_new()); return getRuby().getNil(); case NODE_CLASS: RubyModule superClass; if (ruby_class == null) { throw new RubyTypeException("no outer class/module"); } if (node.nd_super() != null) { superClass = getSuperClass(self, node.nd_super()); } else { superClass = null; } rubyClass = null; // if ((ruby_class == getRuby().getObjectClass()) && rb_autoload_defined(node.nd_cname())) { // rb_autoload_load(node.nd_cname()); // } if (ruby_class.isConstantDefined((RubyId)node.nd_cname())) { rubyClass = (RubyClass)ruby_class.getConstant((RubyId)node.nd_cname()); } if (rubyClass != null) { if (!rubyClass.isClass()) { throw new RubyTypeException(((RubyId)node.nd_cname()).toName() + " is not a class"); } if (superClass != null) { RubyModule tmp = rubyClass.getSuperClass(); if (tmp.isSingleton()) { tmp = tmp.getSuperClass(); } while (tmp.isIncluded()) { tmp = tmp.getSuperClass(); } if (tmp != superClass) { superClass = tmp; //goto override_class; if (superClass == null) { superClass = getRuby().getObjectClass(); } rubyClass = getRuby().defineClassId((RubyId)node.nd_cname(), (RubyClass)superClass); ruby_class.setConstant((RubyId)node.nd_cname(), rubyClass); rubyClass.setClassPath((RubyClass)ruby_class, ((RubyId)node.nd_cname()).toName()); // end goto } } if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("extending class prohibited"); } // rb_clear_cache(); } else { //override_class: if (superClass == null) { superClass = getRuby().getObjectClass(); } rubyClass = getRuby().defineClassId((RubyId)node.nd_cname(), (RubyClass)superClass); ruby_class.setConstant((RubyId)node.nd_cname(), rubyClass); rubyClass.setClassPath((RubyClass)ruby_class, ((RubyId)node.nd_cname()).toName()); } if (ruby_wrapper != null) { rubyClass.getSingletonClass().includeModule(ruby_wrapper); rubyClass.includeModule(ruby_wrapper); } return setupModule(rubyClass, node.nd_body()); case NODE_MODULE: if (ruby_class == null) { throw new RubyTypeException("no outer class/module"); } RubyModule module = null; if ((ruby_class == getRuby().getObjectClass()) && getRuby().isAutoloadDefined((RubyId)node.nd_cname())) { // getRuby().rb_autoload_load(node.nd_cname()); } if (ruby_class.isConstantDefined((RubyId)node.nd_cname())) { module = (RubyModule)ruby_class.getConstant((RubyId)node.nd_cname()); } if (module != null) { if (!(module instanceof RubyModule)) { throw new RubyTypeException(((RubyId)node.nd_cname()).toName() + " is not a module"); } if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("extending module prohibited"); } } else { module = getRuby().defineModuleId((RubyId)node.nd_cname()); ruby_class.setConstant((RubyId)node.nd_cname(), module); module.setClassPath(ruby_class, ((RubyId)node.nd_cname()).toName()); } if (ruby_wrapper != null) { module.getSingletonClass().includeModule(ruby_wrapper); module.includeModule(ruby_wrapper); } return setupModule(module, node.nd_body()); case NODE_SCLASS: rubyClass = (RubyClass)eval(self, node.nd_recv()); if (rubyClass.isSpecialConst()) { throw new RubyTypeException("no virtual class for " + rubyClass.getRubyClass().toName()); } if (getRuby().getSecurityLevel() >= 4 && !rubyClass.isTaint()) { throw new RubySecurityException("Insecure: can't extend object"); } if (rubyClass.getRubyClass().isSingleton()) { // rb_clear_cache(); } rubyClass = rubyClass.getSingletonClass(); if (ruby_wrapper != null) { rubyClass.getSingletonClass().includeModule(ruby_wrapper); rubyClass.includeModule(ruby_wrapper); } return setupModule(rubyClass, node.nd_body()); case NODE_DEFINED: // String buf; // String desc = is_defined(self, node.nd_head(), buf); // // if (desc) { // result = rb_str_new2(desc); // } else { // result = Qnil; // } case NODE_NEWLINE: // ruby_sourcefile = node.nd_file; // ruby_sourceline = node.nd_nth(); // if (trace_func) { // call_trace_func("line", ruby_sourcefile, ruby_sourceline, self, // ruby_frame.last_func(), // ruby_frame.last_class()); // } node = node.nd_next(); break; default: // rom.rb_bug("unknown node type %d", nd_type(node)); } } }
public RubyObject eval(RubyObject self, NODE n) { NODE node = n; RubyBoolean cond = null; RubyObject[] args = null; RubyObject value = null; RubyObject result = null; RubyModule rubyClass = null; // int state; // RubyOriginalMethods rom = getRuby().getOriginalMethods(); while (true) { if (node == null) { return getRuby().getNil(); } switch (node.nd_type()) { case NODE_BLOCK: while (node.nd_next() != null) { eval(self, node.nd_head()); node = node.nd_next(); } node = node.nd_head(); break; case NODE_POSTEXE: // rb_f_END(); node.nd_set_type(NODE_NIL); /* exec just once */ return getRuby().getNil(); /* begin .. end without clauses */ case NODE_BEGIN: node = node.nd_body(); break; /* nodes for speed-up(default match) */ case NODE_MATCH: //return rom.rb_reg_match2(node.nd_head().nd_lit()); return getRuby().getNil(); /* nodes for speed-up(literal match) */ case NODE_MATCH2: //return rom.rb_reg_match(eval(node.nd_recv()), eval(node.nd_value())); return getRuby().getNil(); /* nodes for speed-up(literal match) */ case NODE_MATCH3: //VALUE r = eval(node.nd_recv()); //VALUE l = eval(node.nd_value()); //if (r instanceof RubyString) { // return rom.rb_reg_match(l, r); //} else { // return rom.rb_funcall(r, match, 1, l); //} return getRuby().getNil(); /* node for speed-up(top-level loop for -n/-p) */ case NODE_OPT_N: while (true) { try { // while (!rb_gets().isNil() false) { // HACK +++ if (true) { // HACK --- try { eval(self, node.nd_body()); } catch (RedoException rExcptn) { } } break; } catch (NextException nExcptn) { } catch (BreakException bExcptn) { break; } } return getRuby().getNil(); case NODE_SELF: return self; case NODE_NIL: return getRuby().getNil(); case NODE_TRUE: return getRuby().getTrue(); case NODE_FALSE: return getRuby().getFalse(); case NODE_IF: // ruby_sourceline = node.nd_line(); cond = (RubyBoolean)eval(self, node.nd_cond()); if (cond.isTrue()) { node = node.nd_body(); } else { node = node.nd_else(); } break; case NODE_WHEN: while (node != null) { NODE tag; if (node.nd_type() != NODE_WHEN) { break; } tag = node.nd_head(); while (tag != null) {/* if (trace_func) { call_trace_func("line", tag->nd_file, nd_line(tag), self, ruby_frame->last_func, ruby_frame->last_class); }*/ // ruby_sourcefile = tag.nd_file; // ruby_sourceline = tag.nd_line(); if (tag.nd_head().nd_type() == NODE_WHEN) { RubyObject obj = eval(self, tag.nd_head().nd_head()); if (!(obj instanceof RubyArray)) { obj = RubyArray.m_newArray(getRuby(), obj); } for (int i = 0; i < ((RubyArray)obj).length(); i++) { if (((RubyBoolean)((RubyArray)obj).entry(i)).isTrue()) { node = node.nd_body(); break; } } tag = tag.nd_next(); continue; } if (((RubyBoolean)eval(self, tag.nd_head())).isTrue()) { node = node.nd_body(); break; } tag = tag.nd_next(); } node = node.nd_next(); } return getRuby().getNil(); case NODE_CASE: RubyObject obj = eval(self, node.nd_head()); node = node.nd_body(); while (node != null) { NODE tag; if (node.nd_type() != NODE_WHEN) { break; } tag = node.nd_head(); while (tag != null) {/* if (trace_func) { call_trace_func("line", tag->nd_file, nd_line(tag), self, ruby_frame->last_func, ruby_frame->last_class); } ruby_sourcefile = tag->nd_file; ruby_sourceline = nd_line(tag);*/ if (tag.nd_head().nd_type() == NODE_WHEN) { RubyObject obj2 = eval(self, tag.nd_head().nd_head()); if (!(obj2 instanceof RubyArray)) { obj2 = RubyArray.m_newArray(getRuby(), obj2); } for (int i = 0; i < ((RubyArray)obj).length(); i++) { RubyBoolean eqq = (RubyBoolean)((RubyArray)obj2).entry(i).funcall(getRuby().intern("==="), obj); if (eqq.isTrue()) { node = node.nd_body(); break; } } tag = tag.nd_next(); continue; } if (((RubyBoolean)eval(self, tag.nd_head()).funcall(getRuby().intern("==="), obj)).isTrue()) { node = node.nd_body(); break; } tag = tag.nd_next(); } node = node.nd_next(); } return getRuby().getNil(); case NODE_WHILE: while (eval(self, node.nd_cond()).isTrue()) { while (true) { try { eval(self, node.nd_body()); break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { break; } catch (BreakException bExcptn) { return getRuby().getNil(); } } } return getRuby().getNil(); case NODE_UNTIL: while (eval(self, node.nd_cond()).isFalse()) { while (true) { try { eval(self, node.nd_body()); break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { break; } catch (BreakException bExcptn) { return getRuby().getNil(); } } } return getRuby().getNil(); case NODE_BLOCK_PASS: //return block_pass(node); return null; case NODE_ITER: case NODE_FOR: rubyBlock.push(node.nd_var(), node.nd_body(), self); rubyIter.push(Iter.ITER_PRE); while (true) { try { if (node.nd_type() == NODE_ITER) { result = eval(self, node.nd_iter()); } else { // String file = // int line = rubyBlock.flags &= ~RubyBlock.BLOCK_D_SCOPE; RubyBlock tmpBlock = beginCallargs(); RubyObject recv = eval(self, node.nd_iter()); endCallArgs(tmpBlock); // = file; // = line; result = recv.getRubyClass().call(recv, ruby.intern("each"), null, 0); } break; } catch (RetryException rExcptn) { } catch (ReturnException rExcptn) { result = rExcptn.getReturnValue(); break; } catch (BreakException bExcptn) { result = ruby.getNil(); break; } } rubyIter.pop(); rubyBlock.pop(); return result; case NODE_BREAK: throw new BreakException(); case NODE_NEXT: throw new NextException(); case NODE_REDO: throw new RedoException(); case NODE_RETRY: throw new RetryException(); case NODE_RESTARGS: result = eval(self, node.nd_head()); if (!(result instanceof RubyArray)) { result = obj = RubyArray.m_newArray(getRuby(), result); } return result; case NODE_YIELD: if (node.nd_stts() != null) { result = eval(self, node.nd_stts()); if (node.nd_stts().nd_type() == NODE_RESTARGS && ((RubyArray)result).length() == 1) { result = ((RubyArray)result).entry(0); } } else { result = ruby.getNil(); } return yield0(result, null, null, false); case NODE_RESCUE:/* retry_entry: { volatile VALUE e_info = ruby_errinfo; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, node->nd_head); } POP_TAG(); if (state == TAG_RAISE) { NODE * volatile resq = node->nd_resq; ruby_sourceline = nd_line(node); while (resq) { if (handle_rescue(self, resq)) { state = 0; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, resq->nd_body); } POP_TAG(); if (state == TAG_RETRY) { state = 0; ruby_errinfo = Qnil; goto retry_entry; } if (state != TAG_RAISE) { ruby_errinfo = e_info; } break; } resq = resq->nd_head; /* next rescue */ /** } * } * else if (node->nd_else) { /* else clause given *//* if (!state) { /* no exception raised *//* result = rb_eval(self, node->nd_else); } } if (state) JUMP_TAG(state); } break;*/ case NODE_ENSURE:/* PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = eval(node.nd_head()); } POP_TAG(); if (node.nd_ensr()) { VALUE retval = prot_tag->retval; /* save retval *//* VALUE errinfo = ruby_errinfo; rb_eval(self, node->nd_ensr); return_value(retval); ruby_errinfo = errinfo; } if (state) JUMP_TAG(state); break;*/ case NODE_AND: cond = (RubyBoolean)eval(self, node.nd_1st()); if (cond.isFalse()) { return cond; } node = node.nd_2nd(); break; case NODE_OR: cond = (RubyBoolean)eval(self, node.nd_1st()); if (cond.isTrue()) { return cond; } node = node.nd_2nd(); break; case NODE_NOT: return RubyBoolean.m_newBoolean(getRuby(), eval(self, node.nd_1st()).isFalse()); case NODE_DOT2: case NODE_DOT3: result = RubyRange.m_newRange(getRuby(), eval(self, node.nd_beg()), eval(self, node.nd_end()), node.nd_type() == NODE_DOT3); if (node.nd_state() != 0) { return result; } if (node.nd_beg().nd_type() == NODE_LIT && (node.nd_beg().nd_lit() instanceof RubyFixnum) && node.nd_end().nd_type() == NODE_LIT && (node.nd_end().nd_lit() instanceof RubyFixnum)) { node.nd_set_type(NODE_LIT); node.nd_lit(result); } else { node.nd_state(1L); } return result; case NODE_FLIP2: /* like AWK */ /*if (ruby_scope->local_vars == 0) { rb_bug("unexpected local variable"); }*/ if (ruby.rubyScope.getLocalVars(node.nd_cnt()).isFalse()) { if (eval(self, node.nd_beg()).isTrue()) { ruby.rubyScope.setLocalVars(node.nd_cnt(), eval(self, node.nd_end()).isTrue() ? ruby.getFalse() : ruby.getTrue()); result = ruby.getTrue(); } else { result = ruby.getFalse(); } } else { if (eval(self, node.nd_end()).isTrue()) { ruby.rubyScope.setLocalVars(node.nd_cnt(), ruby.getFalse()); } result = ruby.getTrue(); } return result; case NODE_FLIP3: /* like SED */ /*if (ruby_scope->local_vars == 0) { rb_bug("unexpected local variable"); }*/ if (ruby.rubyScope.getLocalVars(node.nd_cnt()).isFalse()) { result = eval(self, node.nd_beg()).isTrue() ? ruby.getFalse() : ruby.getTrue(); ruby.rubyScope.setLocalVars(node.nd_cnt(), result); } else { if (eval(self, node.nd_end()).isTrue()) { ruby.rubyScope.setLocalVars(node.nd_cnt(), ruby.getFalse()); } result = ruby.getTrue(); } return result; case NODE_RETURN: if (node.nd_stts() != null) { result = eval(self, node.nd_stts()); } else { result = ruby.getNil(); } throw new ReturnException(result); case NODE_ARGSCAT: return ((RubyArray)eval(self, node.nd_head())).m_concat(eval(self, node.nd_body())); case NODE_ARGSPUSH: return ((RubyArray)eval(self, node.nd_head()).m_dup()).push(eval(self, node.nd_body())); case NODE_CALL: // TMP_PROTECT; RubyBlock tmpBlock = beginCallargs(); RubyObject recv = eval(self, node.nd_recv()); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); return recv.getRubyClass().call(recv, (RubyId)node.nd_mid(), args, 0); case NODE_FCALL: // TMP_PROTECT; tmpBlock = beginCallargs(); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); return self.getRubyClass().call(self, (RubyId)node.nd_mid(), args, 1); case NODE_VCALL: return self.getRubyClass().call(self, (RubyId)node.nd_mid(), null, 2); case NODE_SUPER: case NODE_ZSUPER: // TMP_PROTECT; if (rubyFrame.getLastClass() == null) { throw new RubyNameException("superclass method '" + rubyFrame.getLastFunc().toName() + "' disabled"); } if (node.nd_type() == NODE_ZSUPER) { List argsList = rubyFrame.getArgs(); args = (RubyObject[])argsList.toArray(new RubyObject[argsList.size()]); } else { tmpBlock = beginCallargs(); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); } rubyIter.push(rubyIter.getIter() != Iter.ITER_NOT ? Iter.ITER_PRE : Iter.ITER_NOT); result = rubyFrame.getLastClass().getSuperClass().call(rubyFrame.getSelf(), rubyFrame.getLastFunc(), args, 3); rubyIter.pop(); return result; case NODE_SCOPE: NODE saved_cref = null; Frame frame = rubyFrame; frame.setTmp(rubyFrame); rubyFrame = frame; ruby.rubyScope.push(); if (node.nd_rval() != null) { saved_cref = ruby_cref; ruby_cref = (NODE)node.nd_rval(); rubyFrame.setCbase(node.nd_rval()); } if (node.nd_tbl() != null) { List tmp = Collections.nCopies(node.nd_tbl()[0].intValue() + 1, ruby.getNil()); ShiftableList vars = new ShiftableList(new ArrayList(tmp)); vars.set(0, (VALUE)node); vars.shift(1); getRuby().rubyScope.setLocalVars(vars); getRuby().rubyScope.setLocalTbl(node.nd_tbl()); } else { getRuby().rubyScope.setLocalVars(null); getRuby().rubyScope.setLocalTbl(null); } result = eval(self, node.nd_next()); ruby.rubyScope.pop(); rubyFrame = frame.getTmp(); if (saved_cref != null) { ruby_cref = saved_cref; } return result; case NODE_OP_ASGN1: // TMP_PROTECT; recv = eval(self, node.nd_recv()); NODE rval = node.nd_args().nd_head(); args = setupArgs(self, node.nd_args().nd_next()); ArrayList argsList = new ArrayList(Arrays.asList(args)); argsList.remove(args.length - 1); RubyBoolean val = (RubyBoolean)recv.funcall(getRuby().intern("[]"), (RubyObject[])argsList.toArray(new RubyObject[argsList.size()])); switch (node.nd_mid().intValue()) { case 0: /* OR */ if (val.isTrue()) { return val; } val = (RubyBoolean)eval(self, rval); break; case 1: /* AND */ if (val.isFalse()) { return val; } val = (RubyBoolean)eval(self, rval); break; default: val = (RubyBoolean)val.funcall((RubyId)node.nd_mid(), eval(self, rval)); } args[args.length - 1] = val; return recv.funcall(getRuby().intern("[]="), args); case NODE_OP_ASGN2: ID id = node.nd_next().nd_vid(); recv = eval(self, node.nd_recv()); val = (RubyBoolean)recv.funcall((RubyId)id, (RubyObject[])null); switch (node.nd_next().nd_mid().intValue()) { case 0: /* OR */ if (val.isTrue()) { return val; } val = (RubyBoolean)eval(self, node.nd_value()); break; case 1: /* AND */ if (val.isFalse()) { return val; } val = (RubyBoolean)eval(self, node.nd_value()); break; default: val = (RubyBoolean)val.funcall((RubyId)node.nd_mid(), eval(self, node.nd_value())); } // HACK +++ val = (RubyBoolean)recv.funcall((RubyId)node.nd_next().nd_aid(), val); // HACK --- return val; case NODE_OP_ASGN_AND: cond = (RubyBoolean)eval(self, node.nd_head()); if (cond.isFalse()) { return cond; } node = node.nd_value(); break; case NODE_OP_ASGN_OR: cond = (RubyBoolean)eval(self, node.nd_head()); if ((node.nd_aid() != null && !self.isInstanceVarDefined((RubyId)node.nd_aid())) || cond.isFalse()) { node = node.nd_value(); break; } return cond; case NODE_MASGN: return massign(self, node, eval(self, node.nd_value()), false); case NODE_LASGN: // if (ruby.ruby_scope.local_vars == null) { // rb_bug("unexpected local variable assignment"); // } result = eval(self, node.nd_value()); getRuby().rubyScope.setLocalVars(node.nd_cnt(), result); return result; case NODE_DASGN: result = eval(self, node.nd_value()); RubyVarmap.assign(ruby, (RubyId)node.nd_vid(), result); return result; case NODE_DASGN_CURR: result = eval(self, node.nd_value()); RubyVarmap.assignCurrent(ruby, (RubyId)node.nd_vid(), result); return result; case NODE_GASGN: result = eval(self, node.nd_value()); ((RubyGlobalEntry)node.nd_entry()).set(result); return result; case NODE_IASGN: result = eval(self, node.nd_value()); self.setInstanceVar((RubyId)node.nd_vid(), result); return result; case NODE_CDECL: if (ruby_class == null) { throw new RubyTypeException("no class/module to define constant"); } result = eval(self, node.nd_value()); ruby_class.setConstant((RubyId)node.nd_vid(), result); return result; case NODE_CVDECL: if (ruby_cbase == null) { throw new RubyTypeException("no class/module to define class variable"); } result = eval(self, node.nd_value()); if (ruby_cbase.isSingleton()) { ruby_cbase.getInstanceVar("__attached__").getClassVarSingleton().declareClassVar((RubyId)node.nd_vid(), result); return result; } ruby_cbase.declareClassVar((RubyId)node.nd_vid(), result); return result; case NODE_CVASGN: result = eval(self, node.nd_value()); self.getClassVarSingleton().setClassVar((RubyId)node.nd_vid(), result); return result; case NODE_LVAR: //if (getRuby().ruby_scope.local_vars == null) { // rb_bug("unexpected local variable"); // } return (RubyObject)getRuby().rubyScope.getLocalVars(node.nd_cnt()); case NODE_DVAR: return getDynamicVars().getRef((RubyId)node.nd_vid()); case NODE_GVAR: return ((RubyGlobalEntry)node.nd_entry()).get(); case NODE_IVAR: return self.getInstanceVar((RubyId)node.nd_vid()); case NODE_CONST: return getConstant((NODE)rubyFrame.getCbase(), (RubyId)node.nd_vid(), self); case NODE_CVAR: /* normal method */ if (ruby_cbase == null) { return self.getRubyClass().getClassVar((RubyId)node.nd_vid()); } if (!ruby_cbase.isSingleton()) { return ruby_cbase.getClassVar((RubyId)node.nd_vid()); } return ruby_cbase.getInstanceVar("__attached__").getClassVarSingleton().getClassVar((RubyId)node.nd_vid()); case NODE_CVAR2: /* singleton method */ return self.getClassVarSingleton().getClassVar((RubyId)node.nd_vid()); case NODE_BLOCK_ARG: if (ruby.rubyScope.getLocalVars() == null) { throw new RuntimeException("BUG: unexpected block argument"); } if (isBlockGiven()) { result = getRuby().getNil(); // Create Proc object ruby.rubyScope.setLocalVars(node.nd_cnt(), result); return result; } else { return getRuby().getNil(); } case NODE_COLON2: value = eval(self, node.nd_head()); if (value instanceof RubyModule) { return ((RubyModule)value).getConstant((RubyId)node.nd_mid()); } else { return value.funcall((RubyId)node.nd_mid()); } case NODE_COLON3: return getRuby().getObjectClass().getConstant((RubyId)node.nd_mid()); case NODE_NTH_REF: // return rom.rb_reg_nth_match(node.nd_nth(), MATCH_DATA); return null; case NODE_BACK_REF: /*switch ((char)node.nd_nth()) { case '&': return rom.rb_reg_last_match(MATCH_DATA); case '`': return rom.rb_reg_match_pre(MATCH_DATA); case '\'': return rom.rb_reg_match_post(MATCH_DATA); case '+': return rom.rb_reg_match_last(MATCH_DATA); default: rom.rb_bug("unexpected back-ref"); }*/ case NODE_HASH: RubyHash hash = RubyHash.m_newHash(ruby); NODE list = node.nd_head(); while(list != null) { RubyObject key = eval(self, list.nd_head()); list = list.nd_next(); if (list == null) { // HACK +++ throw new RubyArgumentException("odd number list for Hash"); // HACK --- } value = eval(self, list.nd_head()); hash.m_aset(key, value); list = list.nd_next(); } return hash; case NODE_ZARRAY: /* zero length list */ return RubyArray.m_newArray(getRuby()); case NODE_ARRAY: ArrayList ary = new ArrayList(node.nd_alen()); for (; node != null ; node = node.nd_next()) { ary.add(eval(self, node.nd_head())); } return RubyArray.m_newArray(getRuby(), ary); case NODE_STR: return ((RubyObject)node.nd_lit()).m_to_s(); case NODE_DSTR: case NODE_DXSTR: case NODE_DREGX: case NODE_DREGX_ONCE:/* NODE list = node.nd_next(); RubyString str = RubyString.m_newString(getRuby(), (RubyObject)node.nd_lit()); RubyString str2; while (list != null) { if (list.nd_head() != null) { switch (list.nd_head().nd_type()) { case NODE_STR: str2 = (RubyString)list.nd_head().nd_lit(); break; case NODE_EVSTR: result = ruby_errinfo; ruby_errinfo = Qnil; ruby_sourceline = nd_line(node); ruby_in_eval++; list.nd_head(compile(list.nd_head().nd_lit(), ruby_sourcefile,ruby_sourceline)); ruby_eval_tree = 0; ruby_in_eval--; if (ruby_nerrs > 0) { compile_error("string expansion"); } if (!NIL_P(result)) ruby_errinfo = result; /* fall through *//* default: str2 = (RubyString)rom.rb_obj_as_string(eval(list.nd_head())); break; } str.append(str2); str.infectObject(str2); } list = list.nd_next(); } switch (node.nd_type()) { case NODE_DREGX: return rom.rb_reg_new(str.getString(), str.getString().length(), node.nd_cflag()); case NODE_DREGX_ONCE: /* regexp expand once *//* VALUE result = rom.rb_reg_new(str.getString(), str.getString().length(), node.nd_cflag()); node.nd_set_type(NODE_LIT); node.nd_lit(result); return result; case NODE_DXSTR: return rom.rb_funcall(this, '`', 1, str); default: return str; }*/ return null; case NODE_XSTR: return self.funcall(getRuby().intern("`"), (RubyObject)node.nd_lit()); case NODE_LIT: return (RubyObject)node.nd_lit(); case NODE_ATTRSET: if (getRubyFrame().getArgs().size() != 1) { throw new RubyArgumentException("wrong # of arguments(" + rubyFrame.getArgs().size() + "for 1)"); } return self.setInstanceVar((RubyId)node.nd_vid(), (RubyObject)rubyFrame.getArgs().get(0)); case NODE_DEFN: if (node.nd_defn() != null) { int noex; if (ruby_class == null) { throw new RubyTypeException("no class to add method"); } //if (ruby_class == getRuby().getObjectClass() && node.nd_mid() == init) { // rom.rb_warn("redefining Object#initialize may cause infinite loop"); //} //if (node.nd_mid() == __id__ || node.nd_mid() == __send__) { // rom.rb_warn("redefining `%s' may cause serious problem", ((RubyId)node.nd_mid()).toName()); //} // ruby_class.setFrozen(true); NODE body = ruby_class.searchMethod((RubyId)node.nd_mid()); RubyObject origin = ruby_class.getMethodOrigin((RubyId)node.nd_mid()); if (body != null){ // if (ruby_verbose.isTrue() && ruby_class == origin && body.nd_cnt() == 0) { // rom.rb_warning("discarding old %s", ((RubyId)node.nd_mid()).toName()); // } // if (node.nd_noex() != 0) { /* toplevel */ /* should upgrade to rb_warn() if no super was called inside? */ // rom.rb_warning("overriding global function `%s'", ((RubyId)node.nd_mid()).toName()); // } } if (isScope(SCOPE_PRIVATE) || node.nd_mid().equals(ruby.intern("initialize"))) { noex = NOEX_PRIVATE; } else if (isScope(SCOPE_PROTECTED)) { noex = NOEX_PROTECTED; } else if (ruby_class == getRuby().getObjectClass()) { noex = node.nd_noex(); } else { noex = NOEX_PUBLIC; } if (body != null && origin == ruby_class && (body.nd_noex() & NOEX_UNDEF) != 0) { noex |= NOEX_UNDEF; } NODE defn = node.nd_defn().copyNodeScope(ruby_cref); ruby_class.addMethod((RubyId)node.nd_mid(), defn, noex); // rb_clear_cache_by_id(node.nd_mid()); if (scope_vmode == SCOPE_MODFUNC) { ruby_class.getSingletonClass().addMethod((RubyId)node.nd_mid(), defn, NOEX_PUBLIC); ruby_class.funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } if (ruby_class.isSingleton()) { ruby_class.getInstanceVar("__attached__").funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } else { ruby_class.funcall(getRuby().intern("method_added"), ((RubyId)node.nd_mid()).toSymbol()); } } return getRuby().getNil(); case NODE_DEFS: if (node.nd_defn() != null) { recv = eval(self, node.nd_recv()); if (getRuby().getSecurityLevel() >= 4 && !recv.isTaint()) { throw new RubySecurityException("Insecure; can't define singleton method"); } /*if (FIXNUM_P(recv) || SYMBOL_P(recv)) { rb_raise(rb_eTypeError, "can't define singleton method \"%s\" for %s", rb_id2name(node.nd_mid()), rb_class2name(CLASS_OF(recv))); }*/ // not needed in jruby if (recv.isFrozen()) { throw new RubyFrozenException("object"); } rubyClass = recv.getSingletonClass(); NODE body = (NODE)rubyClass.getMethods().get((RubyId)node.nd_mid()); if (body != null) { if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("redefining method prohibited"); } /*if (RTEST(ruby_verbose)) { rb_warning("redefine %s", rb_id2name(node.nd_mid())); }*/ } NODE defn = node.nd_defn().copyNodeScope(ruby_cref); defn.nd_rval(ruby_cref); rubyClass.addMethod((RubyId)node.nd_mid(), defn, NOEX_PUBLIC | (body != null ? body.nd_noex() & NOEX_UNDEF : 0)); // rb_clear_cache_by_id(node.nd_mid()); recv.funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } return getRuby().getNil(); case NODE_UNDEF: if (ruby_class == null) { throw new RubyTypeException("no class to undef method"); } ruby_class.undef((RubyId)node.nd_mid()); return getRuby().getNil(); case NODE_ALIAS: if (ruby_class == null) { throw new RubyTypeException("no class to make alias"); } ruby_class.aliasMethod((RubyId)node.nd_new(), (RubyId)node.nd_old()); ruby_class.funcall(getRuby().intern("method_added"), ((RubyId)node.nd_mid()).toSymbol()); return getRuby().getNil(); case NODE_VALIAS: RubyGlobalEntry.getGlobalEntry((RubyId)node.nd_old()).alias((RubyId)node.nd_new()); return getRuby().getNil(); case NODE_CLASS: RubyModule superClass; if (ruby_class == null) { throw new RubyTypeException("no outer class/module"); } if (node.nd_super() != null) { superClass = getSuperClass(self, node.nd_super()); } else { superClass = null; } rubyClass = null; // if ((ruby_class == getRuby().getObjectClass()) && rb_autoload_defined(node.nd_cname())) { // rb_autoload_load(node.nd_cname()); // } if (ruby_class.isConstantDefined((RubyId)node.nd_cname())) { rubyClass = (RubyClass)ruby_class.getConstant((RubyId)node.nd_cname()); } if (rubyClass != null) { if (!rubyClass.isClass()) { throw new RubyTypeException(((RubyId)node.nd_cname()).toName() + " is not a class"); } if (superClass != null) { RubyModule tmp = rubyClass.getSuperClass(); if (tmp.isSingleton()) { tmp = tmp.getSuperClass(); } while (tmp.isIncluded()) { tmp = tmp.getSuperClass(); } if (tmp != superClass) { superClass = tmp; //goto override_class; if (superClass == null) { superClass = getRuby().getObjectClass(); } rubyClass = getRuby().defineClassId((RubyId)node.nd_cname(), (RubyClass)superClass); ruby_class.setConstant((RubyId)node.nd_cname(), rubyClass); rubyClass.setClassPath((RubyClass)ruby_class, ((RubyId)node.nd_cname()).toName()); // end goto } } if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("extending class prohibited"); } // rb_clear_cache(); } else { //override_class: if (superClass == null) { superClass = getRuby().getObjectClass(); } rubyClass = getRuby().defineClassId((RubyId)node.nd_cname(), (RubyClass)superClass); ruby_class.setConstant((RubyId)node.nd_cname(), rubyClass); rubyClass.setClassPath((RubyClass)ruby_class, ((RubyId)node.nd_cname()).toName()); } if (ruby_wrapper != null) { rubyClass.getSingletonClass().includeModule(ruby_wrapper); rubyClass.includeModule(ruby_wrapper); } return setupModule(rubyClass, node.nd_body()); case NODE_MODULE: if (ruby_class == null) { throw new RubyTypeException("no outer class/module"); } RubyModule module = null; if ((ruby_class == getRuby().getObjectClass()) && getRuby().isAutoloadDefined((RubyId)node.nd_cname())) { // getRuby().rb_autoload_load(node.nd_cname()); } if (ruby_class.isConstantDefined((RubyId)node.nd_cname())) { module = (RubyModule)ruby_class.getConstant((RubyId)node.nd_cname()); } if (module != null) { if (!(module instanceof RubyModule)) { throw new RubyTypeException(((RubyId)node.nd_cname()).toName() + " is not a module"); } if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("extending module prohibited"); } } else { module = getRuby().defineModuleId((RubyId)node.nd_cname()); ruby_class.setConstant((RubyId)node.nd_cname(), module); module.setClassPath(ruby_class, ((RubyId)node.nd_cname()).toName()); } if (ruby_wrapper != null) { module.getSingletonClass().includeModule(ruby_wrapper); module.includeModule(ruby_wrapper); } return setupModule(module, node.nd_body()); case NODE_SCLASS: rubyClass = (RubyClass)eval(self, node.nd_recv()); if (rubyClass.isSpecialConst()) { throw new RubyTypeException("no virtual class for " + rubyClass.getRubyClass().toName()); } if (getRuby().getSecurityLevel() >= 4 && !rubyClass.isTaint()) { throw new RubySecurityException("Insecure: can't extend object"); } if (rubyClass.getRubyClass().isSingleton()) { // rb_clear_cache(); } rubyClass = rubyClass.getSingletonClass(); if (ruby_wrapper != null) { rubyClass.getSingletonClass().includeModule(ruby_wrapper); rubyClass.includeModule(ruby_wrapper); } return setupModule(rubyClass, node.nd_body()); case NODE_DEFINED: // String buf; // String desc = is_defined(self, node.nd_head(), buf); // // if (desc) { // result = rb_str_new2(desc); // } else { // result = Qnil; // } case NODE_NEWLINE: // ruby_sourcefile = node.nd_file; // ruby_sourceline = node.nd_nth(); // if (trace_func) { // call_trace_func("line", ruby_sourcefile, ruby_sourceline, self, // ruby_frame.last_func(), // ruby_frame.last_class()); // } node = node.nd_next(); break; default: // rom.rb_bug("unknown node type %d", nd_type(node)); } } }
3,238,704
public void init() { int state; if (initialized) { return; } initialized = true; topFrame = getRubyFrame(); rubyIter = new Iter(); // rb_origenviron = environ; // Init_stack(0); // Init_heap(); getRuby().rubyScope.push();// PUSH_SCOPE(); getRuby().rubyScope.setLocalVars(null); getRuby().rubyScope.setLocalVars(null); // top_scope = getRuby().ruby_scope; /* default visibility is private at toplevel */ // SET_SCOPE(SCOPE_PRIVATE); // PUSH_TAG( PROT_NONE ); // if ((state = EXEC_TAG()) == 0) { // rb_call_inits(); ruby_class = getRuby().getObjectClass(); // ruby_frame.self = ruby_top_self; top_cref = new NODE(NODE_CREF, getRuby().getObjectClass(), null, null); ruby_cref = top_cref; rubyFrame.setCbase((VALUE)ruby_cref); // rb_define_global_const( "TOPLEVEL_BINDING", rb_f_binding( ruby_top_self ) ); // ruby_prog_init(); // } // POP_TAG(); // if (state != 0) { // error_print(); // } getRuby().rubyScope.pop();// POP_SCOPE(); // ruby_scope = top_scope; }
public void init() { int state; if (initialized) { return; } initialized = true; topFrame = getRubyFrame(); rubyIter = new Iter(); // rb_origenviron = environ; // Init_stack(0); // Init_heap(); getRuby().rubyScope.push();// PUSH_SCOPE(); getRuby().rubyScope.setLocalVars(null); getRuby().rubyScope.setLocalVars(null); // top_scope = getRuby().ruby_scope; /* default visibility is private at toplevel */ // SET_SCOPE(SCOPE_PRIVATE); // PUSH_TAG( PROT_NONE ); // if ((state = EXEC_TAG()) == 0) { // rb_call_inits(); ruby_class = getRuby().getObjectClass(); // ruby_frame.self = ruby_top_self; top_cref = new NODE(NODE_CREF, getRuby().getObjectClass(), null, null); ruby_cref = top_cref; getRubyFrame().setCbase((VALUE)ruby_cref); // rb_define_global_const( "TOPLEVEL_BINDING", rb_f_binding( ruby_top_self ) ); // ruby_prog_init(); // } // POP_TAG(); // if (state != 0) { // error_print(); // } getRuby().rubyScope.pop();// POP_SCOPE(); // ruby_scope = top_scope; }
3,238,705
public boolean isBlockGiven() { return rubyFrame.getIter() != Iter.ITER_NOT; }
public boolean isBlockGiven() { return getRubyFrame().getIter() != Iter.ITER_NOT; }
3,238,706
public boolean isFBlockGiven() { return (rubyFrame.getPrev() != null) && (rubyFrame.getPrev().getIter() != Iter.ITER_NOT); }
public boolean isFBlockGiven() { return (getRubyFrame().getPrev() != null) && (getRubyFrame().getPrev().getIter() != Iter.ITER_NOT); }
3,238,707
public RubyObject setupModule(RubyModule module, NODE n) { NODE node = n; // String file = ruby_sourcefile; // int line = ruby_sourceline; // TMP_PROTECT; Frame frame = rubyFrame; frame.setTmp(rubyFrame); rubyFrame = frame; pushClass(); ruby_class = module; getRuby().rubyScope.push(); RubyVarmap.push(ruby); if (node.nd_tbl() != null) { List tmp = Collections.nCopies(node.nd_tbl()[0].intValue() + 1, ruby.getNil()); ShiftableList vars = new ShiftableList(new ArrayList(tmp)); vars.set(0, (VALUE)node); vars.shift(1); getRuby().rubyScope.setLocalTbl(node.nd_tbl()); } else { getRuby().rubyScope.setLocalVars(null); getRuby().rubyScope.setLocalTbl(null); } PUSH_CREF(module); rubyFrame.setCbase((VALUE)ruby_cref); // PUSH_TAG(PROT_NONE); RubyObject result = null; // if (( state = EXEC_TAG()) == 0 ) { // if (trace_func) { // call_trace_func("class", file, line, ruby_class, // ruby_frame->last_func, ruby_frame->last_class ); // } result = eval(ruby_class, node.nd_next()); // } // POP_TAG(); POP_CREF(); RubyVarmap.pop(ruby); getRuby().rubyScope.pop(); popClass(); rubyFrame = frame.getTmp();// if (trace_func) {// call_trace_func("end", file, line, 0, ruby_frame->last_func, ruby_frame->last_class );// } // if (state != 0) { // JUMP_TAG(state); // } return result; }
public RubyObject setupModule(RubyModule module, NODE n) { NODE node = n; // String file = ruby_sourcefile; // int line = ruby_sourceline; // TMP_PROTECT; Frame frame = rubyFrame; frame.setTmp(rubyFrame); rubyFrame = frame; pushClass(); ruby_class = module; getRuby().rubyScope.push(); RubyVarmap.push(ruby); if (node.nd_tbl() != null) { List tmp = Collections.nCopies(node.nd_tbl()[0].intValue() + 1, ruby.getNil()); ShiftableList vars = new ShiftableList(new ArrayList(tmp)); vars.set(0, (VALUE)node); vars.shift(1); getRuby().rubyScope.setLocalTbl(node.nd_tbl()); } else { getRuby().rubyScope.setLocalVars(null); getRuby().rubyScope.setLocalTbl(null); } PUSH_CREF(module); rubyFrame.setCbase((VALUE)ruby_cref); // PUSH_TAG(PROT_NONE); RubyObject result = null; // if (( state = EXEC_TAG()) == 0 ) { // if (trace_func) { // call_trace_func("class", file, line, ruby_class, // ruby_frame->last_func, ruby_frame->last_class ); // } result = eval(ruby_class, node.nd_next()); // } // POP_TAG(); POP_CREF(); RubyVarmap.pop(ruby); getRuby().rubyScope.pop(); popClass(); rubyFrame = frame.getTmp();// if (trace_func) {// call_trace_func("end", file, line, 0, ruby_frame->last_func, ruby_frame->last_class );// } // if (state != 0) { // JUMP_TAG(state); // } return result; }
3,238,708
public RubyObject setupModule(RubyModule module, NODE n) { NODE node = n; // String file = ruby_sourcefile; // int line = ruby_sourceline; // TMP_PROTECT; Frame frame = rubyFrame; frame.setTmp(rubyFrame); rubyFrame = frame; pushClass(); ruby_class = module; getRuby().rubyScope.push(); RubyVarmap.push(ruby); if (node.nd_tbl() != null) { List tmp = Collections.nCopies(node.nd_tbl()[0].intValue() + 1, ruby.getNil()); ShiftableList vars = new ShiftableList(new ArrayList(tmp)); vars.set(0, (VALUE)node); vars.shift(1); getRuby().rubyScope.setLocalTbl(node.nd_tbl()); } else { getRuby().rubyScope.setLocalVars(null); getRuby().rubyScope.setLocalTbl(null); } PUSH_CREF(module); rubyFrame.setCbase((VALUE)ruby_cref); // PUSH_TAG(PROT_NONE); RubyObject result = null; // if (( state = EXEC_TAG()) == 0 ) { // if (trace_func) { // call_trace_func("class", file, line, ruby_class, // ruby_frame->last_func, ruby_frame->last_class ); // } result = eval(ruby_class, node.nd_next()); // } // POP_TAG(); POP_CREF(); RubyVarmap.pop(ruby); getRuby().rubyScope.pop(); popClass(); rubyFrame = frame.getTmp();// if (trace_func) {// call_trace_func("end", file, line, 0, ruby_frame->last_func, ruby_frame->last_class );// } // if (state != 0) { // JUMP_TAG(state); // } return result; }
public RubyObject setupModule(RubyModule module, NODE n) { NODE node = n; // String file = ruby_sourcefile; // int line = ruby_sourceline; // TMP_PROTECT; Frame frame = rubyFrame; frame.setTmp(rubyFrame); rubyFrame = frame; pushClass(); ruby_class = module; getRuby().rubyScope.push(); RubyVarmap.push(ruby); if (node.nd_tbl() != null) { List tmp = Collections.nCopies(node.nd_tbl()[0].intValue() + 1, ruby.getNil()); ShiftableList vars = new ShiftableList(new ArrayList(tmp)); vars.set(0, (VALUE)node); vars.shift(1); getRuby().rubyScope.setLocalTbl(node.nd_tbl()); } else { getRuby().rubyScope.setLocalVars(null); getRuby().rubyScope.setLocalTbl(null); } PUSH_CREF(module); getRubyFrame().setCbase((VALUE)ruby_cref); // PUSH_TAG(PROT_NONE); RubyObject result = null; // if (( state = EXEC_TAG()) == 0 ) { // if (trace_func) { // call_trace_func("class", file, line, ruby_class, // ruby_frame->last_func, ruby_frame->last_class ); // } result = eval(ruby_class, node.nd_next()); // } // POP_TAG(); POP_CREF(); RubyVarmap.pop(ruby); getRuby().rubyScope.pop(); popClass(); rubyFrame = frame.getTmp();// if (trace_func) {// call_trace_func("end", file, line, 0, ruby_frame->last_func, ruby_frame->last_class );// } // if (state != 0) { // JUMP_TAG(state); // } return result; }
3,238,709
public RubyObject yield0(RubyObject value, RubyObject self, RubyModule klass, boolean acheck) { RubyObject result = ruby.getNil(); if (!(isBlockGiven() || isFBlockGiven()) || (rubyBlock == null)) { throw new RuntimeException("yield called out of block"); } RubyVarmap.push(ruby); pushClass(); RubyBlock block = rubyBlock.getTmp(); Frame frame = block.frame; frame.setPrev(rubyFrame); rubyFrame = frame; VALUE old_cref = ruby_cref; ruby_cref = (NODE)rubyFrame.getCbase(); RubyScope oldScope = ruby.rubyScope; ruby.rubyScope = block.scope; rubyBlock.pop(); if ((block.flags & RubyBlock.BLOCK_D_SCOPE) != 0) { dynamicVars = new RubyVarmap(null, null, block.dynamicVars); } else { dynamicVars = block.dynamicVars; } ruby_class = (klass != null) ? klass : block.klass; if (klass == null) { self = (RubyObject)block.self; } NODE node = block.body; if (block.var != null) { // try { if (block.var == NODE.ONE) { if (acheck && value != null && value instanceof RubyArray && ((RubyArray)value).length() != 0) { throw new RubyArgumentException("wrong # of arguments ("+ ((RubyArray)value).length() + " for 0)"); } } else { if (block.var.nd_type() == NODE_MASGN) { massign(self, block.var, value, acheck); } else { if (acheck && value != null && value instanceof RubyArray && ((RubyArray)value).length() == 1) { value = ((RubyArray)value).entry(0); } assign(self, block.var, value, acheck); } } // } catch () { // goto pop_state; // } } else { if (acheck && value != null && value instanceof RubyArray && ((RubyArray)value).length() == 1) { value = ((RubyArray)value).entry(0); } } rubyIter.push(block.iter); while (true) { try { if (node == null) { result = ruby.getNil(); } else if (node.nd_type() == NODE_CFUNC || node.nd_type() == NODE_IFUNC) { if (value == null) { value = RubyArray.m_newArray(ruby, 0); } result = ((RubyCallbackMethod)node.nd_cfnc()).execute(value, new RubyObject[] {(RubyObject)node.nd_tval(), self}, ruby); } else { result = eval(self, node); } break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { result = ruby.getNil(); break; } catch (BreakException bExcptn) { break; } catch (ReturnException rExcptn) { break; } } // pop_state: rubyIter.pop(); popClass(); RubyVarmap.pop(ruby); rubyBlock.setTmp(block); rubyFrame = rubyFrame.getPrev(); ruby_cref = (NODE)old_cref; // if (ruby_scope->flag & SCOPE_DONT_RECYCLE) // scope_dup(old_scope); ruby.rubyScope = oldScope; /* * if (state) { * if (!block->tag) { * switch (state & TAG_MASK) { * case TAG_BREAK: * case TAG_RETURN: * jump_tag_but_local_jump(state & TAG_MASK); * break; * } * } * JUMP_TAG(state); * } */ return result; }
public RubyObject yield0(RubyObject value, RubyObject self, RubyModule klass, boolean acheck) { RubyObject result = ruby.getNil(); if (!(isBlockGiven() || isFBlockGiven()) || (rubyBlock == null)) { throw new RuntimeException("yield called out of block"); } RubyVarmap.push(ruby); pushClass(); RubyBlock block = rubyBlock.getTmp(); Frame frame = block.frame; frame.setPrev(getRubyFrame()); rubyFrame = frame; VALUE old_cref = ruby_cref; ruby_cref = (NODE)rubyFrame.getCbase(); RubyScope oldScope = ruby.rubyScope; ruby.rubyScope = block.scope; rubyBlock.pop(); if ((block.flags & RubyBlock.BLOCK_D_SCOPE) != 0) { dynamicVars = new RubyVarmap(null, null, block.dynamicVars); } else { dynamicVars = block.dynamicVars; } ruby_class = (klass != null) ? klass : block.klass; if (klass == null) { self = (RubyObject)block.self; } NODE node = block.body; if (block.var != null) { // try { if (block.var == NODE.ONE) { if (acheck && value != null && value instanceof RubyArray && ((RubyArray)value).length() != 0) { throw new RubyArgumentException("wrong # of arguments ("+ ((RubyArray)value).length() + " for 0)"); } } else { if (block.var.nd_type() == NODE_MASGN) { massign(self, block.var, value, acheck); } else { if (acheck && value != null && value instanceof RubyArray && ((RubyArray)value).length() == 1) { value = ((RubyArray)value).entry(0); } assign(self, block.var, value, acheck); } } // } catch () { // goto pop_state; // } } else { if (acheck && value != null && value instanceof RubyArray && ((RubyArray)value).length() == 1) { value = ((RubyArray)value).entry(0); } } rubyIter.push(block.iter); while (true) { try { if (node == null) { result = ruby.getNil(); } else if (node.nd_type() == NODE_CFUNC || node.nd_type() == NODE_IFUNC) { if (value == null) { value = RubyArray.m_newArray(ruby, 0); } result = ((RubyCallbackMethod)node.nd_cfnc()).execute(value, new RubyObject[] {(RubyObject)node.nd_tval(), self}, ruby); } else { result = eval(self, node); } break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { result = ruby.getNil(); break; } catch (BreakException bExcptn) { break; } catch (ReturnException rExcptn) { break; } } // pop_state: rubyIter.pop(); popClass(); RubyVarmap.pop(ruby); rubyBlock.setTmp(block); rubyFrame = rubyFrame.getPrev(); ruby_cref = (NODE)old_cref; // if (ruby_scope->flag & SCOPE_DONT_RECYCLE) // scope_dup(old_scope); ruby.rubyScope = oldScope; /* * if (state) { * if (!block->tag) { * switch (state & TAG_MASK) { * case TAG_BREAK: * case TAG_RETURN: * jump_tag_but_local_jump(state & TAG_MASK); * break; * } * } * JUMP_TAG(state); * } */ return result; }
3,238,710
public RubyObject yield0(RubyObject value, RubyObject self, RubyModule klass, boolean acheck) { RubyObject result = ruby.getNil(); if (!(isBlockGiven() || isFBlockGiven()) || (rubyBlock == null)) { throw new RuntimeException("yield called out of block"); } RubyVarmap.push(ruby); pushClass(); RubyBlock block = rubyBlock.getTmp(); Frame frame = block.frame; frame.setPrev(rubyFrame); rubyFrame = frame; VALUE old_cref = ruby_cref; ruby_cref = (NODE)rubyFrame.getCbase(); RubyScope oldScope = ruby.rubyScope; ruby.rubyScope = block.scope; rubyBlock.pop(); if ((block.flags & RubyBlock.BLOCK_D_SCOPE) != 0) { dynamicVars = new RubyVarmap(null, null, block.dynamicVars); } else { dynamicVars = block.dynamicVars; } ruby_class = (klass != null) ? klass : block.klass; if (klass == null) { self = (RubyObject)block.self; } NODE node = block.body; if (block.var != null) { // try { if (block.var == NODE.ONE) { if (acheck && value != null && value instanceof RubyArray && ((RubyArray)value).length() != 0) { throw new RubyArgumentException("wrong # of arguments ("+ ((RubyArray)value).length() + " for 0)"); } } else { if (block.var.nd_type() == NODE_MASGN) { massign(self, block.var, value, acheck); } else { if (acheck && value != null && value instanceof RubyArray && ((RubyArray)value).length() == 1) { value = ((RubyArray)value).entry(0); } assign(self, block.var, value, acheck); } } // } catch () { // goto pop_state; // } } else { if (acheck && value != null && value instanceof RubyArray && ((RubyArray)value).length() == 1) { value = ((RubyArray)value).entry(0); } } rubyIter.push(block.iter); while (true) { try { if (node == null) { result = ruby.getNil(); } else if (node.nd_type() == NODE_CFUNC || node.nd_type() == NODE_IFUNC) { if (value == null) { value = RubyArray.m_newArray(ruby, 0); } result = ((RubyCallbackMethod)node.nd_cfnc()).execute(value, new RubyObject[] {(RubyObject)node.nd_tval(), self}, ruby); } else { result = eval(self, node); } break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { result = ruby.getNil(); break; } catch (BreakException bExcptn) { break; } catch (ReturnException rExcptn) { break; } } // pop_state: rubyIter.pop(); popClass(); RubyVarmap.pop(ruby); rubyBlock.setTmp(block); rubyFrame = rubyFrame.getPrev(); ruby_cref = (NODE)old_cref; // if (ruby_scope->flag & SCOPE_DONT_RECYCLE) // scope_dup(old_scope); ruby.rubyScope = oldScope; /* * if (state) { * if (!block->tag) { * switch (state & TAG_MASK) { * case TAG_BREAK: * case TAG_RETURN: * jump_tag_but_local_jump(state & TAG_MASK); * break; * } * } * JUMP_TAG(state); * } */ return result; }
public RubyObject yield0(RubyObject value, RubyObject self, RubyModule klass, boolean acheck) { RubyObject result = ruby.getNil(); if (!(isBlockGiven() || isFBlockGiven()) || (rubyBlock == null)) { throw new RuntimeException("yield called out of block"); } RubyVarmap.push(ruby); pushClass(); RubyBlock block = rubyBlock.getTmp(); Frame frame = block.frame; frame.setPrev(rubyFrame); rubyFrame = frame; VALUE old_cref = ruby_cref; ruby_cref = (NODE)getRubyFrame().getCbase(); RubyScope oldScope = ruby.rubyScope; ruby.rubyScope = block.scope; rubyBlock.pop(); if ((block.flags & RubyBlock.BLOCK_D_SCOPE) != 0) { dynamicVars = new RubyVarmap(null, null, block.dynamicVars); } else { dynamicVars = block.dynamicVars; } ruby_class = (klass != null) ? klass : block.klass; if (klass == null) { self = (RubyObject)block.self; } NODE node = block.body; if (block.var != null) { // try { if (block.var == NODE.ONE) { if (acheck && value != null && value instanceof RubyArray && ((RubyArray)value).length() != 0) { throw new RubyArgumentException("wrong # of arguments ("+ ((RubyArray)value).length() + " for 0)"); } } else { if (block.var.nd_type() == NODE_MASGN) { massign(self, block.var, value, acheck); } else { if (acheck && value != null && value instanceof RubyArray && ((RubyArray)value).length() == 1) { value = ((RubyArray)value).entry(0); } assign(self, block.var, value, acheck); } } // } catch () { // goto pop_state; // } } else { if (acheck && value != null && value instanceof RubyArray && ((RubyArray)value).length() == 1) { value = ((RubyArray)value).entry(0); } } rubyIter.push(block.iter); while (true) { try { if (node == null) { result = ruby.getNil(); } else if (node.nd_type() == NODE_CFUNC || node.nd_type() == NODE_IFUNC) { if (value == null) { value = RubyArray.m_newArray(ruby, 0); } result = ((RubyCallbackMethod)node.nd_cfnc()).execute(value, new RubyObject[] {(RubyObject)node.nd_tval(), self}, ruby); } else { result = eval(self, node); } break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { result = ruby.getNil(); break; } catch (BreakException bExcptn) { break; } catch (ReturnException rExcptn) { break; } } // pop_state: rubyIter.pop(); popClass(); RubyVarmap.pop(ruby); rubyBlock.setTmp(block); rubyFrame = rubyFrame.getPrev(); ruby_cref = (NODE)old_cref; // if (ruby_scope->flag & SCOPE_DONT_RECYCLE) // scope_dup(old_scope); ruby.rubyScope = oldScope; /* * if (state) { * if (!block->tag) { * switch (state & TAG_MASK) { * case TAG_BREAK: * case TAG_RETURN: * jump_tag_but_local_jump(state & TAG_MASK); * break; * } * } * JUMP_TAG(state); * } */ return result; }
3,238,711
public RubyObject yield0(RubyObject value, RubyObject self, RubyModule klass, boolean acheck) { RubyObject result = ruby.getNil(); if (!(isBlockGiven() || isFBlockGiven()) || (rubyBlock == null)) { throw new RuntimeException("yield called out of block"); } RubyVarmap.push(ruby); pushClass(); RubyBlock block = rubyBlock.getTmp(); Frame frame = block.frame; frame.setPrev(rubyFrame); rubyFrame = frame; VALUE old_cref = ruby_cref; ruby_cref = (NODE)rubyFrame.getCbase(); RubyScope oldScope = ruby.rubyScope; ruby.rubyScope = block.scope; rubyBlock.pop(); if ((block.flags & RubyBlock.BLOCK_D_SCOPE) != 0) { dynamicVars = new RubyVarmap(null, null, block.dynamicVars); } else { dynamicVars = block.dynamicVars; } ruby_class = (klass != null) ? klass : block.klass; if (klass == null) { self = (RubyObject)block.self; } NODE node = block.body; if (block.var != null) { // try { if (block.var == NODE.ONE) { if (acheck && value != null && value instanceof RubyArray && ((RubyArray)value).length() != 0) { throw new RubyArgumentException("wrong # of arguments ("+ ((RubyArray)value).length() + " for 0)"); } } else { if (block.var.nd_type() == NODE_MASGN) { massign(self, block.var, value, acheck); } else { if (acheck && value != null && value instanceof RubyArray && ((RubyArray)value).length() == 1) { value = ((RubyArray)value).entry(0); } assign(self, block.var, value, acheck); } } // } catch () { // goto pop_state; // } } else { if (acheck && value != null && value instanceof RubyArray && ((RubyArray)value).length() == 1) { value = ((RubyArray)value).entry(0); } } rubyIter.push(block.iter); while (true) { try { if (node == null) { result = ruby.getNil(); } else if (node.nd_type() == NODE_CFUNC || node.nd_type() == NODE_IFUNC) { if (value == null) { value = RubyArray.m_newArray(ruby, 0); } result = ((RubyCallbackMethod)node.nd_cfnc()).execute(value, new RubyObject[] {(RubyObject)node.nd_tval(), self}, ruby); } else { result = eval(self, node); } break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { result = ruby.getNil(); break; } catch (BreakException bExcptn) { break; } catch (ReturnException rExcptn) { break; } } // pop_state: rubyIter.pop(); popClass(); RubyVarmap.pop(ruby); rubyBlock.setTmp(block); rubyFrame = rubyFrame.getPrev(); ruby_cref = (NODE)old_cref; // if (ruby_scope->flag & SCOPE_DONT_RECYCLE) // scope_dup(old_scope); ruby.rubyScope = oldScope; /* * if (state) { * if (!block->tag) { * switch (state & TAG_MASK) { * case TAG_BREAK: * case TAG_RETURN: * jump_tag_but_local_jump(state & TAG_MASK); * break; * } * } * JUMP_TAG(state); * } */ return result; }
public RubyObject yield0(RubyObject value, RubyObject self, RubyModule klass, boolean acheck) { RubyObject result = ruby.getNil(); if (!(isBlockGiven() || isFBlockGiven()) || (rubyBlock == null)) { throw new RuntimeException("yield called out of block"); } RubyVarmap.push(ruby); pushClass(); RubyBlock block = rubyBlock.getTmp(); Frame frame = block.frame; frame.setPrev(rubyFrame); rubyFrame = frame; VALUE old_cref = ruby_cref; ruby_cref = (NODE)rubyFrame.getCbase(); RubyScope oldScope = ruby.rubyScope; ruby.rubyScope = block.scope; rubyBlock.pop(); if ((block.flags & RubyBlock.BLOCK_D_SCOPE) != 0) { dynamicVars = new RubyVarmap(null, null, block.dynamicVars); } else { dynamicVars = block.dynamicVars; } ruby_class = (klass != null) ? klass : block.klass; if (klass == null) { self = (RubyObject)block.self; } NODE node = block.body; if (block.var != null) { // try { if (block.var == NODE.ONE) { if (acheck && value != null && value instanceof RubyArray && ((RubyArray)value).length() != 0) { throw new RubyArgumentException("wrong # of arguments ("+ ((RubyArray)value).length() + " for 0)"); } } else { if (block.var.nd_type() == NODE_MASGN) { massign(self, block.var, value, acheck); } else { if (acheck && value != null && value instanceof RubyArray && ((RubyArray)value).length() == 1) { value = ((RubyArray)value).entry(0); } assign(self, block.var, value, acheck); } } // } catch () { // goto pop_state; // } } else { if (acheck && value != null && value instanceof RubyArray && ((RubyArray)value).length() == 1) { value = ((RubyArray)value).entry(0); } } rubyIter.push(block.iter); while (true) { try { if (node == null) { result = ruby.getNil(); } else if (node.nd_type() == NODE_CFUNC || node.nd_type() == NODE_IFUNC) { if (value == null) { value = RubyArray.m_newArray(ruby, 0); } result = ((RubyCallbackMethod)node.nd_cfnc()).execute(value, new RubyObject[] {(RubyObject)node.nd_tval(), self}, ruby); } else { result = eval(self, node); } break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { result = ruby.getNil(); break; } catch (BreakException bExcptn) { break; } catch (ReturnException rExcptn) { break; } } // pop_state: rubyIter.pop(); popClass(); RubyVarmap.pop(ruby); rubyBlock.setTmp(block); rubyFrame = getRubyFrame().getPrev(); ruby_cref = (NODE)old_cref; // if (ruby_scope->flag & SCOPE_DONT_RECYCLE) // scope_dup(old_scope); ruby.rubyScope = oldScope; /* * if (state) { * if (!block->tag) { * switch (state & TAG_MASK) { * case TAG_BREAK: * case TAG_RETURN: * jump_tag_but_local_jump(state & TAG_MASK); * break; * } * } * JUMP_TAG(state); * } */ return result; }
3,238,712
public static RubyObject m_load_class(Ruby ruby, RubyModule rubyClass, RubyString className, RubyObject[] args) { String javaName = className.getString(); String rubyName = javaName.substring(javaName.lastIndexOf('.') + 1); if (args.length > 0) { rubyName = ((RubyString)args[0]).getString(); } try { final Class c = Class.forName(javaName); final RubyClass newRubyClass = ruby.defineClass(rubyName, (RubyClass)ruby.getRubyClass("JavaObject")); Method[] methods = c.getMethods(); for (int i = 0; i < methods.length; i++) { String methodName = methods[i].getName(); if (methods[i].getDeclaringClass() != Object.class) { newRubyClass.defineMethod(methodName, new JavaReflectionMethod(methods[i])); } } newRubyClass.defineSingletonMethod("new", new RubyCallbackMethod() { public RubyObject execute(RubyObject recv, RubyObject[] args, Ruby ruby) { try { Object value = c.newInstance(); RubyJavaObject javaObject = new RubyJavaObject(ruby, (RubyModule)recv, value); javaObject.callInit(args); return javaObject; } catch (Exception excptn) { } return ruby.getNil(); } }); return newRubyClass; } catch (ClassNotFoundException cnfExcptn) { throw new RubyNameException("cannot found Java class: " + javaName); } catch (SecurityException sExcptn) { } return ruby.getNil(); }
public static RubyObject m_load_class(Ruby ruby, RubyObject recv, RubyString className, RubyObject[] args) { String javaName = className.getString(); String rubyName = javaName.substring(javaName.lastIndexOf('.') + 1); if (args.length > 0) { rubyName = ((RubyString)args[0]).getString(); } try { final Class c = Class.forName(javaName); final RubyClass newRubyClass = ruby.defineClass(rubyName, (RubyClass)ruby.getRubyClass("JavaObject")); Method[] methods = c.getMethods(); for (int i = 0; i < methods.length; i++) { String methodName = methods[i].getName(); if (methods[i].getDeclaringClass() != Object.class) { newRubyClass.defineMethod(methodName, new JavaReflectionMethod(methods[i])); } } newRubyClass.defineSingletonMethod("new", new RubyCallbackMethod() { public RubyObject execute(RubyObject recv, RubyObject[] args, Ruby ruby) { try { Object value = c.newInstance(); RubyJavaObject javaObject = new RubyJavaObject(ruby, (RubyModule)recv, value); javaObject.callInit(args); return javaObject; } catch (Exception excptn) { } return ruby.getNil(); } }); return newRubyClass; } catch (ClassNotFoundException cnfExcptn) { throw new RubyNameException("cannot found Java class: " + javaName); } catch (SecurityException sExcptn) { } return ruby.getNil(); }
3,238,713
public static RubyObject m_load_class(Ruby ruby, RubyModule rubyClass, RubyString className, RubyObject[] args) { String javaName = className.getString(); String rubyName = javaName.substring(javaName.lastIndexOf('.') + 1); if (args.length > 0) { rubyName = ((RubyString)args[0]).getString(); } try { final Class c = Class.forName(javaName); final RubyClass newRubyClass = ruby.defineClass(rubyName, (RubyClass)ruby.getRubyClass("JavaObject")); Method[] methods = c.getMethods(); for (int i = 0; i < methods.length; i++) { String methodName = methods[i].getName(); if (methods[i].getDeclaringClass() != Object.class) { newRubyClass.defineMethod(methodName, new JavaReflectionMethod(methods[i])); } } newRubyClass.defineSingletonMethod("new", new RubyCallbackMethod() { public RubyObject execute(RubyObject recv, RubyObject[] args, Ruby ruby) { try { Object value = c.newInstance(); RubyJavaObject javaObject = new RubyJavaObject(ruby, (RubyModule)recv, value); javaObject.callInit(args); return javaObject; } catch (Exception excptn) { } return ruby.getNil(); } }); return newRubyClass; } catch (ClassNotFoundException cnfExcptn) { throw new RubyNameException("cannot found Java class: " + javaName); } catch (SecurityException sExcptn) { } return ruby.getNil(); }
public static RubyObject m_load_class(Ruby ruby, RubyModule rubyClass, RubyString className, RubyObject[] args) { String javaName = className.getString(); String rubyName = javaName.substring(javaName.lastIndexOf('.') + 1); if (args.length > 0) { rubyName = ((RubyString)args[0]).getString(); } try { Class c = Class.forName(javaName); final RubyClass newRubyClass = ruby.defineClass(rubyName, (RubyClass)ruby.getRubyClass("JavaObject")); Method[] methods = c.getMethods(); for (int i = 0; i < methods.length; i++) { String methodName = methods[i].getName(); if (methods[i].getDeclaringClass() != Object.class) { newRubyClass.defineMethod(methodName, new JavaReflectionMethod(methods[i])); } } newRubyClass.defineSingletonMethod("new", new RubyCallbackMethod() { public RubyObject execute(RubyObject recv, RubyObject[] args, Ruby ruby) { try { Object value = c.newInstance(); RubyJavaObject javaObject = new RubyJavaObject(ruby, (RubyModule)recv, value); javaObject.callInit(args); return javaObject; } catch (Exception excptn) { } return ruby.getNil(); } }); return newRubyClass; } catch (ClassNotFoundException cnfExcptn) { throw new RubyNameException("cannot found Java class: " + javaName); } catch (SecurityException sExcptn) { } return ruby.getNil(); }
3,238,714
public static RubyObject m_load_class(Ruby ruby, RubyModule rubyClass, RubyString className, RubyObject[] args) { String javaName = className.getString(); String rubyName = javaName.substring(javaName.lastIndexOf('.') + 1); if (args.length > 0) { rubyName = ((RubyString)args[0]).getString(); } try { final Class c = Class.forName(javaName); final RubyClass newRubyClass = ruby.defineClass(rubyName, (RubyClass)ruby.getRubyClass("JavaObject")); Method[] methods = c.getMethods(); for (int i = 0; i < methods.length; i++) { String methodName = methods[i].getName(); if (methods[i].getDeclaringClass() != Object.class) { newRubyClass.defineMethod(methodName, new JavaReflectionMethod(methods[i])); } } newRubyClass.defineSingletonMethod("new", new RubyCallbackMethod() { public RubyObject execute(RubyObject recv, RubyObject[] args, Ruby ruby) { try { Object value = c.newInstance(); RubyJavaObject javaObject = new RubyJavaObject(ruby, (RubyModule)recv, value); javaObject.callInit(args); return javaObject; } catch (Exception excptn) { } return ruby.getNil(); } }); return newRubyClass; } catch (ClassNotFoundException cnfExcptn) { throw new RubyNameException("cannot found Java class: " + javaName); } catch (SecurityException sExcptn) { } return ruby.getNil(); }
public static RubyObject m_load_class(Ruby ruby, RubyModule rubyClass, RubyString className, RubyObject[] args) { String javaName = className.getString(); String rubyName = javaName.substring(javaName.lastIndexOf('.') + 1); if (args.length > 0) { rubyName = ((RubyString)args[0]).getString(); } try { final Class c = Class.forName(javaName); Map methodMap = new HashMap(); Map singletonMethodMap = new HashMap(); Method[] methods = c.getMethods(); for (int i = 0; i < methods.length; i++) { String methodName = methods[i].getName(); if (methods[i].getDeclaringClass() != Object.class) { newRubyClass.defineMethod(methodName, new JavaReflectionMethod(methods[i])); } } newRubyClass.defineSingletonMethod("new", new RubyCallbackMethod() { public RubyObject execute(RubyObject recv, RubyObject[] args, Ruby ruby) { try { Object value = c.newInstance(); RubyJavaObject javaObject = new RubyJavaObject(ruby, (RubyModule)recv, value); javaObject.callInit(args); return javaObject; } catch (Exception excptn) { } return ruby.getNil(); } }); return newRubyClass; } catch (ClassNotFoundException cnfExcptn) { throw new RubyNameException("cannot found Java class: " + javaName); } catch (SecurityException sExcptn) { } return ruby.getNil(); }
3,238,715
public static RubyObject m_load_class(Ruby ruby, RubyModule rubyClass, RubyString className, RubyObject[] args) { String javaName = className.getString(); String rubyName = javaName.substring(javaName.lastIndexOf('.') + 1); if (args.length > 0) { rubyName = ((RubyString)args[0]).getString(); } try { final Class c = Class.forName(javaName); final RubyClass newRubyClass = ruby.defineClass(rubyName, (RubyClass)ruby.getRubyClass("JavaObject")); Method[] methods = c.getMethods(); for (int i = 0; i < methods.length; i++) { String methodName = methods[i].getName(); if (methods[i].getDeclaringClass() != Object.class) { newRubyClass.defineMethod(methodName, new JavaReflectionMethod(methods[i])); } } newRubyClass.defineSingletonMethod("new", new RubyCallbackMethod() { public RubyObject execute(RubyObject recv, RubyObject[] args, Ruby ruby) { try { Object value = c.newInstance(); RubyJavaObject javaObject = new RubyJavaObject(ruby, (RubyModule)recv, value); javaObject.callInit(args); return javaObject; } catch (Exception excptn) { } return ruby.getNil(); } }); return newRubyClass; } catch (ClassNotFoundException cnfExcptn) { throw new RubyNameException("cannot found Java class: " + javaName); } catch (SecurityException sExcptn) { } return ruby.getNil(); }
public static RubyObject m_load_class(Ruby ruby, RubyModule rubyClass, RubyString className, RubyObject[] args) { String javaName = className.getString(); String rubyName = javaName.substring(javaName.lastIndexOf('.') + 1); if (args.length > 0) { rubyName = ((RubyString)args[0]).getString(); } try { final Class c = Class.forName(javaName); final RubyClass newRubyClass = ruby.defineClass(rubyName, (RubyClass)ruby.getRubyClass("JavaObject")); Method[] methods = c.getMethods(); for (int i = 0; i < methods.length; i++) { String methodName = methods[i].getName(); if (methods[i].getDeclaringClass() != Object.class) { if (Modifier.isStatic(methods[i].getModifiers())) { if (singletonMethodMap.get(methods[i].getName()) == null) { singletonMethodMap.put(methods[i].getName(), new LinkedList()); } ((List)singletonMethodMap.get(methods[i].getName())).add(methods[i]); } else { if (methodMap.get(methods[i].getName()) == null) { methodMap.put(methods[i].getName(), new LinkedList()); } ((List)methodMap.get(methods[i].getName())).add(methods[i]); } } } newRubyClass.defineSingletonMethod("new", new RubyCallbackMethod() { public RubyObject execute(RubyObject recv, RubyObject[] args, Ruby ruby) { try { Object value = c.newInstance(); RubyJavaObject javaObject = new RubyJavaObject(ruby, (RubyModule)recv, value); javaObject.callInit(args); return javaObject; } catch (Exception excptn) { } return ruby.getNil(); } }); return newRubyClass; } catch (ClassNotFoundException cnfExcptn) { throw new RubyNameException("cannot found Java class: " + javaName); } catch (SecurityException sExcptn) { } return ruby.getNil(); }
3,238,716
public static RubyObject m_load_class(Ruby ruby, RubyModule rubyClass, RubyString className, RubyObject[] args) { String javaName = className.getString(); String rubyName = javaName.substring(javaName.lastIndexOf('.') + 1); if (args.length > 0) { rubyName = ((RubyString)args[0]).getString(); } try { final Class c = Class.forName(javaName); final RubyClass newRubyClass = ruby.defineClass(rubyName, (RubyClass)ruby.getRubyClass("JavaObject")); Method[] methods = c.getMethods(); for (int i = 0; i < methods.length; i++) { String methodName = methods[i].getName(); if (methods[i].getDeclaringClass() != Object.class) { newRubyClass.defineMethod(methodName, new JavaReflectionMethod(methods[i])); } } newRubyClass.defineSingletonMethod("new", new RubyCallbackMethod() { public RubyObject execute(RubyObject recv, RubyObject[] args, Ruby ruby) { try { Object value = c.newInstance(); RubyJavaObject javaObject = new RubyJavaObject(ruby, (RubyModule)recv, value); javaObject.callInit(args); return javaObject; } catch (Exception excptn) { } return ruby.getNil(); } }); return newRubyClass; } catch (ClassNotFoundException cnfExcptn) { throw new RubyNameException("cannot found Java class: " + javaName); } catch (SecurityException sExcptn) { } return ruby.getNil(); }
public static RubyObject m_load_class(Ruby ruby, RubyModule rubyClass, RubyString className, RubyObject[] args) { String javaName = className.getString(); String rubyName = javaName.substring(javaName.lastIndexOf('.') + 1); if (args.length > 0) { rubyName = ((RubyString)args[0]).getString(); } try { final Class c = Class.forName(javaName); final RubyClass newRubyClass = ruby.defineClass(rubyName, (RubyClass)ruby.getRubyClass("JavaObject")); Method[] methods = c.getMethods(); for (int i = 0; i < methods.length; i++) { String methodName = methods[i].getName(); if (methods[i].getDeclaringClass() != Object.class) { newRubyClass.defineMethod(methodName, new JavaReflectionMethod(methods[i])); } } newRubyClass.defineSingletonMethod("new", new RubyCallbackMethod() { public RubyObject execute(RubyObject recv, RubyObject[] args, Ruby ruby) { try { Object value = c.newInstance(); RubyJavaObject javaObject = new RubyJavaObject(ruby, (RubyModule)recv, value); javaObject.callInit(args); return javaObject; } catch (Exception excptn) { } return ruby.getNil(); } }); return newRubyClass; } catch (ClassNotFoundException cnfExcptn) { throw new RubyNameException("cannot found Java class: " + javaName); } catch (SecurityException sExcptn) { } return ruby.getNil(); }
3,238,717
private static TreeImageDisplay transformCategoryGroup(CategoryGroupData data) { if (data == null) throw new IllegalArgumentException("Cannot be null"); TreeImageSet group = new TreeImageSet(data); Set categories = data.getCategories(); Iterator i = categories.iterator(); while (i.hasNext()) group.addChildDisplay(transformCategory((CategoryData) i.next())); group.setNumberItems(categories.size()); return group; }
private static TreeImageDisplay transformCategoryGroup(CategoryGroupData data) { if (data == null) throw new IllegalArgumentException("Cannot be null"); TreeImageSet group = new TreeImageSet(data); Set categories = data.getCategories(); Iterator i = categories.iterator(); while (i.hasNext()) group.addChildDisplay(transformCategory((CategoryData) i.next())); group.setNumberItems(categories.size()); return group; }
3,238,718
private static TreeImageDisplay transformProject(ProjectData data) { if (data == null) throw new IllegalArgumentException("Cannot be null"); TreeImageSet project = new TreeImageSet(data); Set datasets = data.getDatasets(); Iterator i = datasets.iterator(); while (i.hasNext()) project.addChildDisplay(transformDataset((DatasetData) i.next())); project.setNumberItems(datasets.size()); return project; }
private static TreeImageDisplay transformProject(ProjectData data) { if (data == null) throw new IllegalArgumentException("Cannot be null"); TreeImageSet project = new TreeImageSet(data); Set datasets = data.getDatasets(); Iterator i = datasets.iterator(); while (i.hasNext()) project.addChildDisplay(transformDataset((DatasetData) i.next())); project.setNumberItems(datasets.size()); return project; }
3,238,719
public int getChannelFamily(int w);
public int getChannelFamily(int w);
3,238,720
public int getModel();
public int getModel();
3,238,721
public void setModel(int model);
public void setModel(int model);
3,238,722
public void setQuantizationMap(int w, int family, double coefficient, boolean noiseReduction);
public void setQuantizationMap(int w, Family family, double coefficient, boolean noiseReduction);
3,238,723
private static void defineGlobal(IRuby runtime, String name, boolean value) { runtime.getGlobalVariables().defineReadonly(name, new ValueAccessor(value ? runtime.getTrue() : runtime.getNil())); }
private void defineGlobal(IRuby runtime, String name, boolean value) { runtime.getGlobalVariables().defineReadonly(name, new ValueAccessor(value ? runtime.getTrue() : runtime.getNil())); }
3,238,724
private static void defineGlobalVERBOSE(final IRuby runtime) { // $VERBOSE can be true, false, or nil. Any non-false-nil value will get stored as true runtime.getGlobalVariables().define("$VERBOSE", new IAccessor() { public IRubyObject getValue() { return runtime.getVerbose(); } public IRubyObject setValue(IRubyObject newValue) { if (newValue.isNil()) { runtime.setVerbose(newValue); } else { runtime.setVerbose(runtime.newBoolean(newValue != runtime.getFalse())); } return newValue; } }); }
private void defineGlobalVERBOSE(final IRuby runtime) { // $VERBOSE can be true, false, or nil. Any non-false-nil value will get stored as true runtime.getGlobalVariables().define("$VERBOSE", new IAccessor() { public IRubyObject getValue() { return runtime.getVerbose(); } public IRubyObject setValue(IRubyObject newValue) { if (newValue.isNil()) { runtime.setVerbose(newValue); } else { runtime.setVerbose(runtime.newBoolean(newValue != runtime.getFalse())); } return newValue; } }); }
3,238,725
private static Node getParsedScript(IRuby runtime, Reader reader, String filename) { Node result = runtime.parse(reader, filename); if (commandline.isAssumePrinting()) { result = new ParserSupport().appendPrintToBlock(result); } if (commandline.isAssumeLoop()) { result = new ParserSupport().appendWhileLoopToBlock(result, commandline.isProcessLineEnds(), commandline.isSplit()); } return result; }
private Node getParsedScript(IRuby runtime, Reader reader, String filename) { Node result = runtime.parse(reader, filename); if (commandline.isAssumePrinting()) { result = new ParserSupport().appendPrintToBlock(result); } if (commandline.isAssumeLoop()) { result = new ParserSupport().appendWhileLoopToBlock(result, commandline.isProcessLineEnds(), commandline.isSplit()); } return result; }
3,238,726
private static void initializeRuntime(final IRuby runtime, String filename) { IRubyObject argumentArray = runtime.newArray(JavaUtil.convertJavaArrayToRuby(runtime, commandline.getScriptArguments())); runtime.setVerbose(runtime.newBoolean(commandline.isVerbose())); defineGlobalVERBOSE(runtime); runtime.getObject().setConstant("$VERBOSE", commandline.isVerbose() ? runtime.getTrue() : runtime.getNil()); runtime.defineGlobalConstant("ARGV", argumentArray); defineGlobal(runtime, "$-p", commandline.isAssumePrinting()); defineGlobal(runtime, "$-n", commandline.isAssumeLoop()); defineGlobal(runtime, "$-a", commandline.isSplit()); defineGlobal(runtime, "$-l", commandline.isProcessLineEnds()); runtime.getGlobalVariables().defineReadonly("$*", new ValueAccessor(argumentArray)); // TODO this is a fake cause we have no real process number in Java runtime.getGlobalVariables().defineReadonly("$$", new ValueAccessor(runtime.newFixnum(runtime.hashCode()))); runtime.defineVariable(new RubyGlobal.StringGlobalVariable(runtime, "$0", runtime.newString(filename))); runtime.getLoadService().init(commandline.loadPaths()); Iterator iter = commandline.requiredLibraries().iterator(); while (iter.hasNext()) { String scriptName = (String) iter.next(); RubyKernel.require(runtime.getTopSelf(), runtime.newString(scriptName)); } }
private void initializeRuntime(final IRuby runtime, String filename) { IRubyObject argumentArray = runtime.newArray(JavaUtil.convertJavaArrayToRuby(runtime, commandline.getScriptArguments())); runtime.setVerbose(runtime.newBoolean(commandline.isVerbose())); defineGlobalVERBOSE(runtime); runtime.getObject().setConstant("$VERBOSE", commandline.isVerbose() ? runtime.getTrue() : runtime.getNil()); runtime.defineGlobalConstant("ARGV", argumentArray); defineGlobal(runtime, "$-p", commandline.isAssumePrinting()); defineGlobal(runtime, "$-n", commandline.isAssumeLoop()); defineGlobal(runtime, "$-a", commandline.isSplit()); defineGlobal(runtime, "$-l", commandline.isProcessLineEnds()); runtime.getGlobalVariables().defineReadonly("$*", new ValueAccessor(argumentArray)); // TODO this is a fake cause we have no real process number in Java runtime.getGlobalVariables().defineReadonly("$$", new ValueAccessor(runtime.newFixnum(runtime.hashCode()))); runtime.defineVariable(new RubyGlobal.StringGlobalVariable(runtime, "$0", runtime.newString(filename))); runtime.getLoadService().init(commandline.loadPaths()); Iterator iter = commandline.requiredLibraries().iterator(); while (iter.hasNext()) { String scriptName = (String) iter.next(); RubyKernel.require(runtime.getTopSelf(), runtime.newString(scriptName)); } }
3,238,727
public static void main(String[] args) { commandline = new CommandlineParser(args, System.out); if (commandline.isShowVersion()) { showVersion(); } if (! commandline.shouldRunInterpreter()) { return; } long now = -1; if (commandline.isBenchmarking()) { now = System.currentTimeMillis(); } int status = runInterpreter(commandline.getScriptSource(), commandline.displayedFileName()); if (commandline.isBenchmarking()) { System.out.println("Runtime: " + (System.currentTimeMillis() - now) + " ms"); } // Only do an explicit exit if the interpreter has had an error. We // do not want to exit on non-errors since the interpreter may have // started background threads (ala samples/swing2.rb) if (status != 0) { System.exit(status); } }
public static void main(String[] args) { commandline = new CommandlineParser(args, System.out); if (commandline.isShowVersion()) { showVersion(); } if (! commandline.shouldRunInterpreter()) { return; } long now = -1; if (commandline.isBenchmarking()) { now = System.currentTimeMillis(); } int status = runInterpreter(commandline.getScriptSource(), commandline.displayedFileName()); if (commandline.isBenchmarking()) { System.out.println("Runtime: " + (System.currentTimeMillis() - now) + " ms"); } // Only do an explicit exit if the interpreter has had an error. We // do not want to exit on non-errors since the interpreter may have // started background threads (ala samples/swing2.rb) if (status != 0) { System.exit(status); } }
3,238,728
public static void printUsage(PrintStream printStream) { if (!hasPrintedUsage) { printStream.println("Usage: jruby [switches] [--] [rubyfile.rb] [arguments]"); printStream.println(" -e 'command' one line of script. Several -e's allowed. Omit [programfile]"); printStream.println(" -b benchmark mode, times the script execution"); printStream.println(" -Idirectory specify $LOAD_PATH directory (may be used more than once)"); printStream.println(" -- optional -- before rubyfile.rb for compatibility with ruby"); hasPrintedUsage = true; } }
public void printUsage() { if (!hasPrintedUsage) { printStream.println("Usage: jruby [switches] [--] [rubyfile.rb] [arguments]"); printStream.println(" -e 'command' one line of script. Several -e's allowed. Omit [programfile]"); printStream.println(" -b benchmark mode, times the script execution"); printStream.println(" -Idirectory specify $LOAD_PATH directory (may be used more than once)"); printStream.println(" -- optional -- before rubyfile.rb for compatibility with ruby"); hasPrintedUsage = true; } }
3,238,729
public static void printUsage(PrintStream printStream) { if (!hasPrintedUsage) { printStream.println("Usage: jruby [switches] [--] [rubyfile.rb] [arguments]"); printStream.println(" -e 'command' one line of script. Several -e's allowed. Omit [programfile]"); printStream.println(" -b benchmark mode, times the script execution"); printStream.println(" -Idirectory specify $LOAD_PATH directory (may be used more than once)"); printStream.println(" -- optional -- before rubyfile.rb for compatibility with ruby"); hasPrintedUsage = true; } }
public static void printUsage(PrintStream printStream) { if (!hasPrintedUsage) { printStream.println("Usage: jruby [switches] [--] [rubyfile.rb] [arguments]"); printStream.println(" -e 'command' one line of script. Several -e's allowed. Omit [programfile]"); printStream.println(" -b benchmark mode, times the script execution"); printStream.println(" -Idirectory specify $LOAD_PATH directory (may be used more than once)"); printStream.println(" -- optional -- before rubyfile.rb for compatibility with ruby"); hasPrintedUsage = true; } }
3,238,730
private static int runInterpreter(Reader reader, String filename) { IRuby runtime = Ruby.getDefaultInstance(); try { runInterpreter(runtime, reader, filename); return 0; } catch (JumpException je) { if (je.getJumpType() == JumpException.JumpType.RaiseJump) { RubyException raisedException = ((RaiseException)je).getException(); if (raisedException.isKindOf(runtime.getClass("SystemExit"))) { RubyFixnum status = (RubyFixnum)raisedException.getInstanceVariable("status"); if (status != null) { return RubyNumeric.fix2int(status); } else { return 0; } } else { runtime.printError(raisedException); return 1; } } else if (je.getJumpType() == JumpException.JumpType.ThrowJump) { runtime.printError((RubyException)je.getTertiaryData()); return 1; } else { throw je; } } }
private static int runInterpreter(Reader reader, String filename) { IRuby runtime = Ruby.getDefaultInstance(); try { runInterpreter(runtime, reader, filename); return 0; } catch (JumpException je) { if (je.getJumpType() == JumpException.JumpType.RaiseJump) { RubyException raisedException = ((RaiseException)je).getException(); if (raisedException.isKindOf(runtime.getClass("SystemExit"))) { RubyFixnum status = (RubyFixnum)raisedException.getInstanceVariable("status"); if (status != null) { return RubyNumeric.fix2int(status); } else { return 0; } } else { runtime.printError(raisedException); return 1; } } else if (je.getJumpType() == JumpException.JumpType.ThrowJump) { runtime.printError((RubyException)je.getTertiaryData()); return 1; } else { throw je; } } }
3,238,731
private static void showVersion() { System.out.print("ruby "); System.out.print(Constants.RUBY_VERSION); System.out.print(" ("); System.out.print(Constants.COMPILE_DATE); System.out.print(") ["); System.out.print("java"); System.out.println("]"); }
private static void showVersion() { System.out.print("ruby "); System.out.print(Constants.RUBY_VERSION); System.out.print(" ("); System.out.print(Constants.COMPILE_DATE); System.out.print(") ["); System.out.print("java"); System.out.println("]"); }
3,238,732
public IRubyObject invoke(RubyString self, IRubyObject[] args) { return self.getRuntime().newFixnum(self.getValue().hashCode()); }
public IRubyObject invoke(RubyString self, IRubyObject[] args) { return self.getRuntime().newFixnum(self.toString().hashCode()); }
3,238,733
public IRubyObject invoke(RubyString self, IRubyObject[] args) { IRubyObject other = args[0]; if (other == self) { return self.getRuntime().getTrue(); } else if (!(other instanceof RubyString)) { return self.getRuntime().getNil(); } /* use Java implementation if both different String instances */ return self.getRuntime().newBoolean( self.getValue().equals(((RubyString) other).getValue())); }
public IRubyObject invoke(RubyString self, IRubyObject[] args) { IRubyObject other = args[0]; if (other == self) { return self.getRuntime().getTrue(); } else if (!(other instanceof RubyString)) { return self.getRuntime().getFalse(); } /* use Java implementation if both different String instances */ return self.getRuntime().newBoolean( self.getValue().equals(((RubyString) other).getValue())); }
3,238,734
public IRubyObject invoke(RubyString self, IRubyObject[] args) { IRubyObject other = args[0]; if (other == self) { return self.getRuntime().getTrue(); } else if (!(other instanceof RubyString)) { return self.getRuntime().getNil(); } /* use Java implementation if both different String instances */ return self.getRuntime().newBoolean( self.getValue().equals(((RubyString) other).getValue())); }
public IRubyObject invoke(RubyString self, IRubyObject[] args) { IRubyObject other = args[0]; if (other == self) { return self.getRuntime().getTrue(); } else if (!(other instanceof RubyString)) { return self.getRuntime().getNil(); } /* use Java implementation if both different String instances */ return self.getRuntime().newBoolean( self.toString().equals(((RubyString) other).toString())); }
3,238,735
public IRubyObject invoke(RubyString self, IRubyObject[] args) { IRubyObject other = args[0]; RubyString str = RubyString.stringValue(other); return (RubyString) self.newString(self.getValue() + str.getValue()).infectBy(str); }
public IRubyObject invoke(RubyString self, IRubyObject[] args) { IRubyObject other = args[0]; RubyString str = RubyString.stringValue(other); return (RubyString) self.newString(self.toString() + str.toString()).infectBy(str); }
3,238,736
public IRubyObject invoke(RubyString self, IRubyObject[] args) { IRubyObject arg = args[0]; if (arg instanceof RubyArray) { Object[] args2 = new Object[((RubyArray) arg).getLength()]; for (int i = 0; i < args2.length; i++) { args2[i] = JavaUtil.convertRubyToJava(((RubyArray) arg).entry(i)); } return self.getRuntime().newString(new PrintfFormat(Locale.US, self.getValue()).sprintf(args2)); } return self.getRuntime().newString(new PrintfFormat(Locale.US, self.getValue()).sprintf(JavaUtil.convertRubyToJava(arg))); }
public IRubyObject invoke(RubyString self, IRubyObject[] args) { IRubyObject arg = args[0]; if (arg instanceof RubyArray) { Object[] args2 = new Object[((RubyArray) arg).getLength()]; for (int i = 0; i < args2.length; i++) { args2[i] = JavaUtil.convertRubyToJava(((RubyArray) arg).entry(i)); } return self.getRuntime().newString(new PrintfFormat(Locale.US, self.toString()).sprintf(args2)); } return self.getRuntime().newString(new PrintfFormat(Locale.US, self.getValue()).sprintf(JavaUtil.convertRubyToJava(arg))); }
3,238,737
public IRubyObject invoke(RubyString self, IRubyObject[] args) { IRubyObject arg = args[0]; if (arg instanceof RubyArray) { Object[] args2 = new Object[((RubyArray) arg).getLength()]; for (int i = 0; i < args2.length; i++) { args2[i] = JavaUtil.convertRubyToJava(((RubyArray) arg).entry(i)); } return self.getRuntime().newString(new PrintfFormat(Locale.US, self.getValue()).sprintf(args2)); } return self.getRuntime().newString(new PrintfFormat(Locale.US, self.getValue()).sprintf(JavaUtil.convertRubyToJava(arg))); }
public IRubyObject invoke(RubyString self, IRubyObject[] args) { IRubyObject arg = args[0]; if (arg instanceof RubyArray) { Object[] args2 = new Object[((RubyArray) arg).getLength()]; for (int i = 0; i < args2.length; i++) { args2[i] = JavaUtil.convertRubyToJava(((RubyArray) arg).entry(i)); } return self.getRuntime().newString(new PrintfFormat(Locale.US, self.getValue()).sprintf(args2)); } return self.getRuntime().newString(new PrintfFormat(Locale.US, self.toString()).sprintf(JavaUtil.convertRubyToJava(arg))); }
3,238,738
protected void initializeClass() { includeModule(getRuntime().getModule("Comparable")); includeModule(getRuntime().getModule("Enumerable")); addMethod("<=>", op_cmp); addMethod("==", equal); addMethod("===", veryEqual); addMethod("+", op_plus); addMethod("*", op_mul); addMethod("%", format); addMethod("hash", hash); addMethod("to_s", to_s); defineMethod("[]", Arity.optional(), "aref"); defineMethod("[]=", Arity.optional(), "aset"); defineMethod("=~", Arity.singleArgument(), "match"); defineMethod("~", Arity.noArguments(), "match2"); defineMethod("capitalize", Arity.noArguments()); defineMethod("capitalize!", Arity.noArguments(), "capitalize_bang"); defineMethod("casecmp", Arity.singleArgument()); defineMethod("center", Arity.singleArgument()); defineMethod("chop", Arity.noArguments()); defineMethod("chop!", Arity.noArguments(), "chop_bang"); defineMethod("chomp", Arity.optional()); defineMethod("chomp!", Arity.optional(), "chomp_bang"); defineMethod("clone", Arity.noArguments(), "rbClone"); defineMethod("concat", Arity.singleArgument()); defineMethod("count", Arity.optional()); defineMethod("delete", Arity.optional()); defineMethod("delete!", Arity.optional(), "delete_bang"); defineMethod("downcase", Arity.noArguments()); defineMethod("downcase!", Arity.noArguments(), "downcase_bang"); defineMethod("dump", Arity.noArguments()); defineMethod("dup", Arity.noArguments()); defineMethod("each_line", Arity.optional()); defineMethod("each_byte", Arity.noArguments()); defineMethod("empty?", Arity.noArguments(), "empty"); defineMethod("gsub", Arity.optional()); defineMethod("gsub!", Arity.optional(), "gsub_bang"); defineMethod("hex", Arity.noArguments()); defineMethod("include?", Arity.singleArgument(), "include"); defineMethod("index", Arity.optional()); defineMethod("initialize", Arity.optional(), "initialize"); defineMethod("initialize_copy", Arity.singleArgument(), "replace"); defineMethod("inspect", Arity.noArguments()); defineMethod("length", Arity.noArguments()); defineMethod("ljust", Arity.singleArgument()); defineMethod("lstrip", Arity.noArguments()); defineMethod("lstrip!", Arity.noArguments(), "lstrip_bang"); defineMethod("match", Arity.singleArgument(), "match3"); defineMethod("oct", Arity.noArguments()); defineMethod("replace", Arity.singleArgument()); defineMethod("reverse", Arity.noArguments()); defineMethod("reverse!", Arity.noArguments(), "reverse_bang"); defineMethod("rindex", Arity.optional()); defineMethod("rjust", Arity.singleArgument()); defineMethod("rstrip", Arity.noArguments()); defineMethod("rstrip!", Arity.noArguments(), "rstrip_bang"); defineMethod("scan", Arity.singleArgument()); defineMethod("slice!", Arity.optional(), "slice_bang"); defineMethod("split", Arity.optional()); defineMethod("strip", Arity.noArguments()); defineMethod("strip!", Arity.noArguments(), "strip_bang"); defineMethod("succ", Arity.noArguments()); defineMethod("succ!", Arity.noArguments(), "succ_bang"); defineMethod("squeeze", Arity.optional()); defineMethod("squeeze!", Arity.optional(), "squeeze_bang"); defineMethod("sub", Arity.optional()); defineMethod("sub!", Arity.optional(), "sub_bang"); defineMethod("sum", Arity.optional()); defineMethod("swapcase", Arity.noArguments()); defineMethod("swapcase!", Arity.noArguments(), "swapcase_bang"); defineMethod("to_f", Arity.noArguments()); defineMethod("to_i", Arity.noArguments()); defineMethod("to_str", Arity.noArguments()); defineMethod("to_sym", Arity.noArguments()); defineMethod("tr", Arity.twoArguments()); defineMethod("tr!", Arity.twoArguments(), "tr_bang"); defineMethod("tr_s", Arity.twoArguments()); defineMethod("tr_s!", Arity.twoArguments(), "tr_s_bang"); defineMethod("unpack", Arity.singleArgument()); defineMethod("upcase", Arity.noArguments()); defineMethod("upcase!", Arity.noArguments(), "upcase_bang"); defineMethod("upto", Arity.singleArgument()); defineAlias("<<", "concat"); defineAlias("each", "each_line"); defineAlias("eql?", "=="); defineAlias("intern", "to_sym"); defineAlias("next", "succ"); defineAlias("next!", "succ!"); defineAlias("size", "length"); defineAlias("slice", "[]"); }
protected void initializeClass() { includeModule(getRuntime().getModule("Comparable")); includeModule(getRuntime().getModule("Enumerable")); addMethod("<=>", op_cmp); addMethod("==", equal); addMethod("===", veryEqual); addMethod("+", op_plus); addMethod("*", op_mul); addMethod("%", format); addMethod("hash", hash); addMethod("to_s", to_s); defineMethod("[]", Arity.optional(), "aref"); defineMethod("[]=", Arity.optional(), "aset"); defineMethod("=~", Arity.singleArgument(), "match"); defineMethod("~", Arity.noArguments(), "match2"); defineMethod("capitalize", Arity.noArguments()); defineMethod("capitalize!", Arity.noArguments(), "capitalize_bang"); defineMethod("casecmp", Arity.singleArgument()); defineMethod("center", Arity.singleArgument()); defineMethod("chop", Arity.noArguments()); defineMethod("chop!", Arity.noArguments(), "chop_bang"); defineMethod("chomp", Arity.optional()); defineMethod("chomp!", Arity.optional(), "chomp_bang"); defineMethod("clone", Arity.noArguments(), "rbClone"); defineMethod("concat", Arity.singleArgument()); defineMethod("count", Arity.optional()); defineMethod("delete", Arity.optional()); defineMethod("delete!", Arity.optional(), "delete_bang"); defineMethod("downcase", Arity.noArguments()); defineMethod("downcase!", Arity.noArguments(), "downcase_bang"); defineMethod("dump", Arity.noArguments()); defineMethod("dup", Arity.noArguments()); defineMethod("each_line", Arity.optional()); defineMethod("each_byte", Arity.noArguments()); defineMethod("empty?", Arity.noArguments(), "empty"); defineMethod("gsub", Arity.optional()); defineMethod("gsub!", Arity.optional(), "gsub_bang"); defineMethod("hex", Arity.noArguments()); defineMethod("include?", Arity.singleArgument(), "include"); defineMethod("index", Arity.optional()); defineMethod("initialize", Arity.optional(), "initialize"); defineMethod("initialize_copy", Arity.singleArgument(), "replace"); defineMethod("inspect", Arity.noArguments()); defineMethod("length", Arity.noArguments()); defineMethod("ljust", Arity.singleArgument()); defineMethod("lstrip", Arity.noArguments()); defineMethod("lstrip!", Arity.noArguments(), "lstrip_bang"); defineMethod("match", Arity.singleArgument(), "match3"); defineMethod("oct", Arity.noArguments()); defineMethod("replace", Arity.singleArgument()); defineMethod("reverse", Arity.noArguments()); defineMethod("reverse!", Arity.noArguments(), "reverse_bang"); defineMethod("rindex", Arity.optional()); defineMethod("rjust", Arity.singleArgument()); defineMethod("rstrip", Arity.noArguments()); defineMethod("rstrip!", Arity.noArguments(), "rstrip_bang"); defineMethod("scan", Arity.singleArgument()); defineMethod("slice!", Arity.optional(), "slice_bang"); defineMethod("split", Arity.optional()); defineMethod("strip", Arity.noArguments()); defineMethod("strip!", Arity.noArguments(), "strip_bang"); defineMethod("succ", Arity.noArguments()); defineMethod("succ!", Arity.noArguments(), "succ_bang"); defineMethod("squeeze", Arity.optional()); defineMethod("squeeze!", Arity.optional(), "squeeze_bang"); defineMethod("sub", Arity.optional()); defineMethod("sub!", Arity.optional(), "sub_bang"); defineMethod("sum", Arity.optional()); defineMethod("swapcase", Arity.noArguments()); defineMethod("swapcase!", Arity.noArguments(), "swapcase_bang"); defineMethod("to_f", Arity.noArguments()); defineMethod("to_i", Arity.noArguments()); defineMethod("to_str", Arity.noArguments()); defineMethod("to_sym", Arity.noArguments()); defineMethod("tr", Arity.twoArguments()); defineMethod("tr!", Arity.twoArguments(), "tr_bang"); defineMethod("tr_s", Arity.twoArguments()); defineMethod("tr_s!", Arity.twoArguments(), "tr_s_bang"); defineMethod("unpack", Arity.singleArgument()); defineMethod("upcase", Arity.noArguments()); defineMethod("upcase!", Arity.noArguments(), "upcase_bang"); defineMethod("upto", Arity.singleArgument()); defineAlias("<<", "concat"); defineAlias("each", "each_line"); defineAlias("eql?", "=="); defineAlias("intern", "to_sym"); defineAlias("next", "succ"); defineAlias("next!", "succ!"); defineAlias("size", "length"); defineAlias("slice", "[]"); }
3,238,739
public IRubyObject method_missing(IRubyObject[] args) { if (args.length == 0) { throw getRuntime().newArgumentError("no id given"); } String name = args[0].asSymbol(); String description = callMethod("inspect").toString(); boolean noClass = description.charAt(0) == '#'; LastCallStatus lastCallStatus = getRuntime().getLastCallStatus(); String format = lastCallStatus.errorMessageFormat(name); String msg = new PrintfFormat(format).sprintf(new Object[] { name, description, noClass ? "" : ":", noClass ? "" : getType().getName()}); if (lastCallStatus.isVariable()) { throw getRuntime().newNameError(msg); } throw getRuntime().newNoMethodError(msg); }
public IRubyObject method_missing(IRubyObject[] args) { if (args.length == 0) { throw getRuntime().newArgumentError("no id given"); } String name = args[0].asSymbol(); String description = callMethod("inspect").toString(); boolean noClass = description.length() > 0 && description.charAt(0) == '#'; LastCallStatus lastCallStatus = getRuntime().getLastCallStatus(); String format = lastCallStatus.errorMessageFormat(name); String msg = new PrintfFormat(format).sprintf(new Object[] { name, description, noClass ? "" : ":", noClass ? "" : getType().getName()}); if (lastCallStatus.isVariable()) { throw getRuntime().newNameError(msg); } throw getRuntime().newNoMethodError(msg); }
3,238,740
public boolean onPreUpdate(PreUpdateEvent event) { Object entity = event.getEntity(); if ( entity instanceof IObject ) { int[] dirty = event.getPersister().findDirty( event.getState(), event.getOldState(), event.getEntity(), event.getSource()); if (dirty == null||dirty.length==0) { // return true; // veto. } else { // otherwise change update event (last modification) IObject obj = (IObject) entity; obj.getDetails().setUpdateEvent( secSys.currentEvent() ); } } return false; }
public boolean onPreUpdate(PreUpdateEvent event) { Object entity = event.getEntity(); if ( entity instanceof IObject ) { int[] dirty = event.getPersister().findDirty( event.getState(), event.getOldState(), event.getEntity(), event.getSource()); if (dirty == null||dirty.length==0) { // return true; // veto. } else { // otherwise change update event (last modification) IObject obj = (IObject) entity; obj.getDetails().setUpdateEvent( secSys.currentEvent() ); } } return false; }
3,238,742
public int getArity() { return 0; }
public int getArity() { return -1; }
3,238,743
public int getArity() { return 0; }
public int getArity() { return -1; }
3,238,744
public int getArity() { return 0; }
public int getArity() { return -1; }
3,238,745
public RubyClass newSubClass(String name, RubyModule parent) { return new BignumMetaClass(name, this, parent); }
public RubyClass newSubClass(String name, RubyModule parent) { return new BignumMetaClass(name, this, parent); }
3,238,746
public static RubyObject stderr(Ruby ruby, RubyClass rubyClass) { RubyIO io = new RubyIO(ruby, rubyClass); io.outStream = ruby.getRuntime().getErrorStream(); io.writeable = true; return io; }
public static RubyObject stderr(Ruby ruby, RubyClass rubyClass, OutputStream errStream) { RubyIO io = new RubyIO(ruby, rubyClass); io.outStream = ruby.getRuntime().getErrorStream(); io.writeable = true; return io; }
3,238,747
public static RubyObject stderr(Ruby ruby, RubyClass rubyClass) { RubyIO io = new RubyIO(ruby, rubyClass); io.outStream = ruby.getRuntime().getErrorStream(); io.writeable = true; return io; }
public static RubyObject stderr(Ruby ruby, RubyClass rubyClass) { RubyIO io = new RubyIO(ruby, rubyClass); io.outStream = errStream; io.writeable = true; return io; }
3,238,748
public static RubyObject stdin(Ruby ruby, RubyClass rubyClass) { RubyIO io = new RubyIO(ruby, rubyClass); io.inStream = new RubyInputStream(ruby.getRuntime().getInputStream()); io.readable = true; return io; }
public static RubyObject stdin(Ruby ruby, RubyClass rubyClass, InputStream inStream) { RubyIO io = new RubyIO(ruby, rubyClass); io.inStream = new RubyInputStream(ruby.getRuntime().getInputStream()); io.readable = true; return io; }
3,238,749
public static RubyObject stdin(Ruby ruby, RubyClass rubyClass) { RubyIO io = new RubyIO(ruby, rubyClass); io.inStream = new RubyInputStream(ruby.getRuntime().getInputStream()); io.readable = true; return io; }
public static RubyObject stdin(Ruby ruby, RubyClass rubyClass) { RubyIO io = new RubyIO(ruby, rubyClass); io.inStream = new RubyInputStream(inStream); io.readable = true; return io; }
3,238,750
public static RubyObject stdout(Ruby ruby, RubyClass rubyClass) { RubyIO io = new RubyIO(ruby, rubyClass); io.outStream = ruby.getRuntime().getOutputStream(); io.writeable = true; return io; }
public static RubyObject stdout(Ruby ruby, RubyClass rubyClass, OutputStream outStream) { RubyIO io = new RubyIO(ruby, rubyClass); io.outStream = ruby.getRuntime().getOutputStream(); io.writeable = true; return io; }
3,238,751
public static RubyObject stdout(Ruby ruby, RubyClass rubyClass) { RubyIO io = new RubyIO(ruby, rubyClass); io.outStream = ruby.getRuntime().getOutputStream(); io.writeable = true; return io; }
public static RubyObject stdout(Ruby ruby, RubyClass rubyClass) { RubyIO io = new RubyIO(ruby, rubyClass); io.outStream = outStream; io.writeable = true; return io; }
3,238,752
private int generateID(DBRow row) throws Exception { Integer id = (Integer) idGenerationMap.get(row.getClass()); if (id == null) { DBManager dbm = DBManager.getInstance(); PreparedStatement ps = dbm.getPreparedStatement(MAX_ID_QUERY); //ps.setString(1, row.getIDColumnName()); //ps.setString(2, row.getTableName()); ResultSet rs = ps.executeQuery(); rs.next(); id = new Integer(rs.getInt(1)); rs.close(); } id = new Integer(id.intValue()+1); idGenerationMap.put(row.getClass(), id); return id.intValue(); }
private int generateID(DBRow row) throws Exception { Integer id = (Integer) idGenerationMap.get(row.getClass()); if (id == null) { DBManager dbm = DBManager.getInstance(); PreparedStatement ps = dbm.getPreparedStatement(MAX_ID_QUERY); //ps.setString(1, row.getIDColumnName()); //ps.setString(2, row.getTableName()); ResultSet rs = ps.executeQuery(); rs.next(); id = new Integer(rs.getInt(1)); rs.close(); } id = new Integer(id.intValue()+1); idGenerationMap.put(row.getClass(), id); return id.intValue(); }
3,238,755
public static Criteria buildBasicCriteria(String g, int id) { Criteria c = new Criteria(); fillBasic(c, g, id); return c; }
public static Criteria buildBasicCriteria(String g, int id) { Criteria c = new Criteria(); c.addWantedField("Valid"); String column = (String) STSMapper.granularities.get(g); if (column != null) c.addFilter(column, new Integer(id)); return c; }
3,238,756