Skip to content

Instantly share code, notes, and snippets.

@chad
Created September 1, 2010 00:02
Show Gist options
  • Save chad/560003 to your computer and use it in GitHub Desktop.
Save chad/560003 to your computer and use it in GitHub Desktop.
typedef struct {
VALUE *pc; /* cfp[0] */
VALUE *sp; /* cfp[1] */
VALUE *bp; /* cfp[2] */
rb_iseq_t *iseq; /* cfp[3] */
VALUE flag; /* cfp[4] */
VALUE self; /* cfp[5] / block[0] */
VALUE klass; /* cfp[6] / block[1] */
VALUE *lfp; /* cfp[7] / block[2] */
VALUE *dfp; /* cfp[8] / block[3] */
rb_iseq_t *block_iseq; /* cfp[9] / block[4] */
VALUE proc; /* cfp[10] / block[5] */
const rb_method_entry_t *me;/* cfp[11] */
} rb_control_frame_t;
@evanphx
Copy link

evanphx commented Sep 1, 2010

pc = position in bytecode of current instruction (maybe next instruction?)
sp = top of the operand stack
bp = bottom of the operand stack
iseq = instruction sequence currently being executed
flags = ... flags?
self = self
klass = probably the module that the method was found on (used for super)
lfp = locals frame pointer (i think), points to the start of where the local variables are stored
dfp = ?
block_iseq = pretty sure this is unused, there was just a patch to remove it
proc = unsure, perhaps the proc if the current frame is for a block
me = unsure, the method being executed?

@chad
Copy link
Author

chad commented Sep 1, 2010

dfp = block locals frame pointer?

@chad
Copy link
Author

chad commented Sep 1, 2010

/**
@c variable
@e get block local variable(which is pointed by idx and level).
level means nest level of block, and specify how above this variable.
@j level, idx Ç≈éwíËÇ≥ÇÍÇΩÉuÉçÉbÉNÉçÅ[ÉJÉãïœêîÇÃílÇÉXÉ^ÉbÉNÇ…íuÇ≠ÅB
level ÇÕÉuÉçÉbÉNÇÃÉlÉXÉgÉåÉxÉãÇ≈ÅAâΩíiè„Ç©Çé¶Ç∑ÅB
*/
DEFINE_INSN
getdynamic
(dindex_t idx, rb_num_t level)
()
(VALUE val)
{
rb_num_t i;
VALUE *dfp2 = GET_DFP();
for (i = 0; i < level; i++) {
dfp2 = GET_PREV_DFP(dfp2);
}
val = *(dfp2 - idx);
}

@mame
Copy link

mame commented Sep 1, 2010

If I recall correctly...

flags = ... flags?

Bad name. Currently it represents frame type: VM_FRAME_MAGIC_*.

dfp = ?

dynamic frame pointer (= block locals frame pointer, as chad said)

def foo(a)
  b = 1
  # lfp = dfp, which has a and b
  foo do |c|
    d = 1
    # lfp has a and b
    # dfp has c and d
  end
end

block_iseq = pretty sure this is unused, there was just a patch to remove it

proc = unsure, perhaps the proc if the current frame is for a block

Both fields are actually used, via cast to type rb_block_t; The comment "cfp[8] / block[3]" means so.
They represents current given block.
block_iseq is accessed as rb_block_t.iseq, and represents iseq of given block.
proc is accessed as rb_block_t.proc, and represents a Proc object created for the block, if any.

me = unsure, the method being executed?

If the current frame is method, this field has the method info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment