You are on page 1of 2

/*

https://github.com/ruby/ruby/blob/v1_8_6_111/
eval.c
*/
static VALUE /* Line 2924*/
rb_eval(self, n)
VALUE self;
NODE *n;
{
NODE * volatile contnode = 0;
NODE * volatile node = n;
int state;
volatile VALUE result = Qnil;
#define RETURN(v) \
do {
result = (v); \
goto finish; \
} while (0)
again:
if (!node) RETURN(Qnil);
ruby_current_node = node;
switch (nd_type(node)) {
case NODE_BLOCK:
/* ... */
case NODE_POSTEXE:
/* ... */
case NODE_BEGIN:
/*
.
.
.
*/
finish:
CHECK_INTS;
if (contnode) {
node = contnode;
contnode = 0;
goto again;
}
return result;
} /* Line 4144 */
/* 1200-line-long switch! */
/* A few simple examples: */
case NODE_SELF:
RETURN(self);
case NODE_NIL:
RETURN(Qnil);
case NODE_TRUE:
RETURN(Qtrue);
case NODE_FALSE:
RETURN(Qfalse);
/* A more interesting example: The if node */
case NODE_IF:
EXEC_EVENT_HOOK(RUBY_EVENT_LINE, node, self,
ruby_frame->last_func,
ruby_frame->last_class);
if (RTEST(rb_eval(self, node->nd_cond))) {
node = node->nd_body;
}
else {
node = node->nd_else;
}
goto again;
/* So execution is not that crazy, just go down the syntax tree, evaluating ever
y node (almost) recursively */

/* Then comes YARV (Yet Another Ruby VM): The virtual machine used by MRI (from
1.9 onwards) */

You might also like