This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// We don't actually execute the command given in prog, as we don't want | |
// to have to split it up into its individual components. Instead, we execute | |
// all of its components as an argument to /bin/sh -c. | |
char *spawnedArgs[] = {(char*)_PATH_BSHELL, "-c", (char*)RSTRING_PTR(prog), NULL}; | |
posix_spawn_file_actions_t actions; | |
if ((pipe(read_pipe) < 0) || (pipe(write_pipe) < 0)) { | |
posix_spawn_file_actions_destroy(&actions); | |
rb_sys_fail("pipe() failed."); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
VALUE | |
io_from_spawning_new_process(VALUE prog, VALUE mode) | |
{ | |
// Allocate space for a new IO struct. | |
VALUE io = io_alloc(rb_cIO, 0); | |
rb_io_t *io_struct = ExtractIOStruct(io); | |
io_struct->readStream = NULL; | |
io_struct->writeStream = NULL; | |
posix_spawn_file_actions_t actions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static VALUE | |
str_new(VALUE klass, const char *ptr, long len) | |
{ | |
VALUE str; | |
if (len < 0) { | |
rb_raise(rb_eArgError, "negative string size (or size too big)"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static long | |
rb_io_stream_read_internal(CFReadStreamRef readStream, UInt8 *buffer, long len) | |
{ | |
long data_read = 0; | |
while (data_read < len) { | |
printf("About to read. bytes available? %d\n", CFReadStreamHasBytesAvailable(readStream)); | |
int code = CFReadStreamRead(readStream, &buffer[data_read], len - data_read); | |
printf("Read completed. Read %d bytes\n", code); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: io.c | |
=================================================================== | |
--- io.c (revision 1622) | |
+++ io.c (working copy) | |
@@ -498,9 +498,8 @@ | |
{ | |
off_t result; | |
- CFNumberRef pos = CFReadStreamCopyProperty(stream, | |
- kCFStreamPropertyFileCurrentOffset); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local:~/Repositories/MacRuby VM_DUMP_IR=1 ./miniruby -e "def f(x,y); x/y; end;" | |
IR dump ---------------------------------------------- | |
; ModuleID = 'Roxor' | |
@redefined = internal global i1 false ; <i1*> [#uses=1] | |
define i64 @0(i64 %self, i8* %sel) { | |
MainBlock: | |
tail call void @rb_vm_prepare_method(i64 140735081247880, i8* inttoptr (i64 4310314656 to i8*), i8* inttoptr (i64 4370479232 to i8*), i8* inttoptr (i64 8590190784 to i8*)) | |
ret i64 4 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- typedefs for clarity | |
type Stack = String | |
type Stream = String | |
-- an ADT that describes the possible states of a PDA. `Fail` is used to | |
-- indicate that we're in a trap state and should return | |
data Result = Accept | Reject | Fail deriving (Show, Eq) | |
-- the PDA has a stream, a stack, the initial state (which is reused to | |
-- save the result of the last computation), and a function that takes | |
-- a member of the stream, the stack, and returns the new stack and whether | |
-- or not the PDA is currently in an accept or reject state |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- typedefs for clarity | |
type Stack = String | |
type Stream = String | |
-- an ADT that describes the possible states of a PDA. `Fail` is used to | |
-- indicate that we're in a trap state and should return | |
data Result = Accept | Reject | Epsilon | Fail deriving (Show, Eq) | |
-- the PDA has a stream, a stack, the initial state (which is reused to | |
-- save the result of the last computation), and a function that takes | |
-- a member of the stream, the stack, and returns the new stack and whether | |
-- or not the PDA is currently in an accept or reject state |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ObjectSpace | |
def each_instance_of(klass) | |
each_object do |obj| | |
yield(obj) if obj.instance_of? klass | |
end | |
end | |
def each_kind_of(klass) | |
each_object do |obj| | |
yield(obj) if obj.kind_of? klass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grammar MExpressions | |
rule boolean | |
"#" [tf] | |
end | |
rule integer | |
decimal_integer / hex_integer / octal_integer / binary_integer | |
end |