Skip to content

Commit

Permalink
Research activities. About to begin breaking the current implementati…
Browse files Browse the repository at this point in the history
…on. Tagging this version.

Finished tracing through the the Ruby C init so I have a full grasp of start to interpret.
About to begin new implementation which has a Ruby VM in AS3 instead of using the AS3 VM to store
the Ruby variables, classes, etc. Will be much more like HotRuby, but pre-compiled into AS3 instead
of interpreted directly from Ruby VM bytecode.
  • Loading branch information
jonathanbranam committed Oct 16, 2008
1 parent 7e17977 commit 25daa0f
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 10 deletions.
7 changes: 2 additions & 5 deletions flash/.actionScriptProperties
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<actionScriptProperties mainApplicationPath="RedSun.as" version="3">
<actionScriptProperties mainApplicationPath="RubyVMMain.as" version="3">
<compiler additionalCompilerArguments="-as3=false -es=true" copyDependentFiles="true" enableModuleDebug="true" generateAccessible="false" htmlExpressInstall="true" htmlGenerate="true" htmlHistoryManagement="true" htmlPlayerVersion="9.0.28" htmlPlayerVersionCheck="true" outputFolderPath="bin-debug" sourceFolderPath="src" strict="false" useApolloConfig="false" verifyDigests="true" warn="true">
<compilerSourcePath/>
<libraryPath defaultLinkType="1">
Expand All @@ -22,10 +22,7 @@
<sourceAttachmentPath/>
</compiler>
<applications>
<application path="FullRuby.as"/>
<application path="RFMain.as"/>
<application path="EmptySwf.as"/>
<application path="MethodDecompile.as"/>
<application path="RubyVMMain.as"/>
</applications>
<modules/>
<buildCSSFiles/>
Expand Down
21 changes: 21 additions & 0 deletions flash/src/RubyVMMain.as
@@ -0,0 +1,21 @@
package
{
import flash.display.Sprite;

import ruby.internals.RubyCore;

public class RubyVMMain extends Sprite
{
public function RubyVMMain()
{
super();
RubyCore.init();
basic_rb();
}

protected function basic_rb():void
{
}

}
}
5 changes: 5 additions & 0 deletions research/compile.c
Expand Up @@ -5,6 +5,9 @@ it emits.

/*
Initial compilation triggered from rt_startup.c when process_options() calls
rb_iseq_new() and passes in the filename and parse tree.
Compilation appears to be triggered from:
eval_string_with_cref() defined in
vm_eval.c:669. This calls rb_iseq_compile() from iseq.c:472 which calls
Expand All @@ -19,6 +22,8 @@ and produces the bytecode necessary for later interpretation. The bytecode
is produced as a linked list (LINK_ANCHOR?) and put into iseq(?). There are
various #defines that append bytecode instructions to the linked list such
as ADD_LABEL, ADD_INSN, ADD_INSN1, etc.
Execution is handled by vm.inc which is generated from insns.def.
*/

// compile.c:2659
Expand Down
99 changes: 99 additions & 0 deletions research/rt_startup.c
Expand Up @@ -164,6 +164,105 @@ VALUE process_options(VALUE arg) {
return iseq;
}

// iseq.c:303
VALUE
rb_iseq_new(NODE *node, VALUE name, VALUE filename,
VALUE parent, VALUE type)
{
return rb_iseq_new_with_opt(node, name, filename, parent, type,
&COMPILE_OPTION_DEFAULT);
}

// iseq.c:328
VALUE
rb_iseq_new_with_opt(NODE *node, VALUE name, VALUE filename,
VALUE parent, VALUE type,
const rb_compile_option_t *option)
{
return rb_iseq_new_with_bopt_and_opt(node, name, filename, parent, type,
Qfalse, option);
}

// iseq.c:311
static VALUE
rb_iseq_new_with_bopt_and_opt(NODE *node, VALUE name, VALUE filename,
VALUE parent, VALUE type, VALUE bopt,
const rb_compile_option_t *option)
{
rb_iseq_t *iseq;
VALUE self = iseq_alloc(rb_cISeq);

GetISeqPtr(self, iseq);
iseq->self = self;

prepare_iseq_build(iseq, name, filename, parent, type, bopt, option);
iseq_compile(self, node); // SEE compile.c
cleanup_iseq_build(iseq);
return self;
}

// iseq.c:152
static VALUE
prepare_iseq_build(rb_iseq_t *iseq,
VALUE name, VALUE filename,
VALUE parent, VALUE type, VALUE block_opt,
const rb_compile_option_t *option)
{
OBJ_FREEZE(name);
OBJ_FREEZE(filename);

iseq->name = name;
iseq->filename = filename;
iseq->defined_method_id = 0;
iseq->mark_ary = rb_ary_new();
RBASIC(iseq->mark_ary)->klass = 0;

iseq->type = type;
iseq->arg_rest = -1;
iseq->arg_block = -1;
iseq->klass = 0;

/*
* iseq->special_block_builder = GC_GUARDED_PTR_REF(block_opt);
* iseq->cached_special_block_builder = 0;
* iseq->cached_special_block = 0;
*/

iseq->compile_data = ALLOC(struct iseq_compile_data);
MEMZERO(iseq->compile_data, struct iseq_compile_data, 1);
iseq->compile_data->mark_ary = rb_ary_new();
RBASIC(iseq->compile_data->mark_ary)->klass = 0;

iseq->compile_data->storage_head = iseq->compile_data->storage_current =
(struct iseq_compile_data_storage *)
ALLOC_N(char, INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE +
sizeof(struct iseq_compile_data_storage));

iseq->compile_data->catch_table_ary = rb_ary_new();
iseq->compile_data->storage_head->pos = 0;
iseq->compile_data->storage_head->next = 0;
iseq->compile_data->storage_head->size =
INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE;
iseq->compile_data->storage_head->buff =
(char *)(&iseq->compile_data->storage_head->buff + 1);
iseq->compile_data->option = option;

set_relation(iseq, parent);

iseq->coverage = Qfalse;
if (!GET_THREAD()->parse_in_eval) {
extern VALUE rb_get_coverages(void);
VALUE coverages = rb_get_coverages();
if (RTEST(coverages)) {
iseq->coverage = rb_hash_lookup(coverages, filename);
if (NIL_P(iseq->coverage)) iseq->coverage = Qfalse;
}
}

return Qtrue;
}


//eval.c:233
void ruby_run_node(VALUE n) {
Init_stack(n);
Expand Down
10 changes: 5 additions & 5 deletions research/rt_structs.c
Expand Up @@ -4,14 +4,14 @@ Important Ruby structs

//vm_core.h:343
typedef struct {
VALUE *pc; /* cfp[0] */
VALUE *sp; /* cfp[1] */
VALUE *bp; /* cfp[2] */
VALUE *pc; /* cfp[0] */ /* Program counter? */
VALUE *sp; /* cfp[1] */ /* Stack pointer? */
VALUE *bp; /* cfp[2] */ /* Base pointer? */
rb_iseq_t *iseq; /* cfp[3] */
VALUE flag; /* cfp[4] */
VALUE self; /* cfp[5] / block[0] */
VALUE *lfp; /* cfp[6] / block[1] */
VALUE *dfp; /* cfp[7] / block[2] */
VALUE *lfp; /* cfp[6] / block[1] */ /* Local Frame Ptr */
VALUE *dfp; /* cfp[7] / block[2] */ /* Dynamic Frame Ptr*/
rb_iseq_t *block_iseq; /* cfp[8] / block[3] */
VALUE proc; /* cfp[9] / block[4] */
ID method_id; /* cfp[10] saved in special case */
Expand Down

0 comments on commit 25daa0f

Please sign in to comment.