Giter Site home page Giter Site logo

mruby's Introduction

The mruby programming language

mruby

GitHub Super-Linter

What is mruby

mruby is the lightweight implementation of the Ruby language complying to (part of) the ISO standard with more recent features provided by Ruby 3.x. Also, its syntax is Ruby 3.x compatible except for pattern matching.

You can link and embed mruby within your application. The "mruby" interpreter program and the interactive "mirb" shell are provided as examples. You can also compile Ruby programs into compiled byte code using the "mrbc" compiler. All these tools are located in the "bin" directory. "mrbc" can also generate compiled byte code in a C source file. See the "mrbtest" program under the "test" directory for an example.

This achievement was sponsored by the Regional Innovation Creation R&D Programs of the Ministry of Economy, Trade and Industry of Japan.

How to get mruby

To get mruby, you can download the stable version 3.3.0 from the official mruby GitHub repository or clone the trunk of the mruby source tree with the "git clone" command. You can also install and compile mruby using ruby-install, ruby-build or rvm.

The latest development version of mruby can be downloaded via the following URL: https://github.com/mruby/mruby/zipball/master

The trunk of the mruby source tree can be checked out with the following command:

$ git clone https://github.com/mruby/mruby.git

mruby homepage

The URL of the mruby homepage is: https://mruby.org.

Mailing list

We don't have a mailing list, but you can use GitHub issues.

How to compile, test, and install (mruby and gems)

For the simplest case, type

rake all test

See the compile.md file for the detail.

Building documentation

There are two sets of documentation in mruby: the mruby API (generated by YARD) and C API (Doxygen and Graphviz)

To build both of them, simply go

rake doc

You can also view them in your browser

rake view_api
rake view_capi

How to customize mruby (mrbgems)

mruby contains a package manager called "mrbgems" that you can use to create extensions in C and/or Ruby. For a guide on how to use mrbgems, consult the mrbgems.md file, and for example code, refer to the examples/mrbgems/ folder.

License

mruby is released under the MIT License.

Note for License

mruby has chosen a MIT License due to its permissive license allowing developers to target various environments such as embedded systems. However, the license requires the display of the copyright notice and license information in manuals for instance. Doing so for big projects can be complicated or troublesome. This is why mruby has decided to display "mruby developers" as the copyright name to make it simple conventionally. In the future, mruby might ask you to distribute your new code (that you will commit,) under the MIT License as a member of "mruby developers" but contributors will keep their copyright. (We did not intend for contributors to transfer or waive their copyrights, actual copyright holder name (contributors) will be listed in the AUTHORS file.)

Please ask us if you want to distribute your code under another license.

How to Contribute

To contribute to mruby, please refer to the contribution guidelines and send a pull request to the mruby GitHub repository. By contributing, you grant non-exclusive rights to your code under the MIT License.

mruby's People

Contributors

akiray03 avatar bovi avatar carsonmcdonald avatar christopheraue avatar cremno avatar crimsonwoods avatar cubicdaiya avatar dabroz avatar dearblue avatar dependabot[bot] avatar flaneur2020 avatar jbampton avatar kou avatar ksss avatar masamitsu-murase avatar masuidrive avatar mattn avatar matz avatar mimaki avatar monaka avatar pbosetti avatar picohz avatar roryo avatar sagmor avatar shuujii avatar skandhas avatar suzukaze avatar take-cheeze avatar tsahara avatar yui-knk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mruby's Issues

make test fails under Apple LLVM Gcc

In 3bbd82c, under Apple LLVM Gcc the target make test fails because of segfault of the command

../bin/mrbc -Bmrbtest_irep -omrbtest.ctmp mrbtest.rbtmp

Config is as follows:

$ gcc -v
Using built-in specs.
Target: i686-apple-darwin11
Configured with: /private/var/tmp/llvmgcc42/llvmgcc42-2336.9~22/src/configure --disable-checking --enable-werror --prefix=/Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2 --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-prefix=llvm- --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin11 --enable-llvm=/private/var/tmp/llvmgcc42/llvmgcc42-2336.9~22/dst-llvmCore/Developer/usr/local --program-prefix=i686-apple-darwin11- --host=x86_64-apple-darwin11 --target=i686-apple-darwin11 --with-gxx-include-dir=/usr/include/c++/4.2.1
Thread model: posix
gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.9.00)

On Debian GCC 4.4.5 it works fine.

Hash#inspect segfaults when inspecting self-referential Hashes

h = Hash.new
h[1] = h
puts h.inspect

Expected Result: {1=>{...}}

Actual Result: Segfault

Backtrace:

Program terminated with signal 11, Segmentation fault.
#0  0x000000000044d3bb in kh_get_n2s (h=0x240b878, key=0x4c9a30 "TypeError")
    at ../../src/symbol.c:27
27  KHASH_MAP_INIT_STR(n2s, mrb_sym);
(gdb) bt
#0  0x000000000044d3bb in kh_get_n2s (h=0x240b878, key=0x4c9a30 "TypeError")
    at ../../src/symbol.c:27
#1  0x000000000044d74a in mrb_intern (mrb=0x23b9010, name=0x4c9a30 "TypeError")
    at ../../src/symbol.c:40
#2  0x000000000047b92a in mrb_class_obj_get (mrb=0x23b9010, name=0x4c9a30 "TypeError")
    at ../../src/variable.c:456
#3  0x000000000043e386 in mrb_obj_alloc (mrb=0x23b9010, ttype=MRB_TT_STRING, 
    cls=0x23c9578) at ../../src/gc.c:268
#4  0x0000000000421f56 in mrb_str_new (mrb=0x23b9010, 
    p=0x7fff71a2edf0 "arena overflow error", len=20) at ../../src/string.c:624
#5  0x00000000004162d8 in mrb_exc_new (mrb=0x23b9010, c=0x23c4e78, 
    ptr=0x7fff71a2edf0 "arena overflow error", len=20) at ../../src/error.c:35
#6  0x0000000000416cc4 in mrb_raise (mrb=0x23b9010, c=0x23c4e78, 
    fmt=0x4c9a3a "arena overflow error") at ../../src/error.c:209
#7  0x000000000043e3a2 in mrb_obj_alloc (mrb=0x23b9010, ttype=MRB_TT_STRING, 
    cls=0x23c9578) at ../../src/gc.c:268
#8  0x0000000000421f56 in mrb_str_new (mrb=0x23b9010, 
    p=0x7fff71a2f140 "arena overflow error", len=20) at ../../src/string.c:624
#9  0x00000000004162d8 in mrb_exc_new (mrb=0x23b9010, c=0x23c4e78, 
    ptr=0x7fff71a2f140 "arena overflow error", len=20) at ../../src/error.c:35
#10 0x0000000000416cc4 in mrb_raise (mrb=0x23b9010, c=0x23c4e78, 
    fmt=0x4c9a3a "arena overflow error") at ../../src/error.c:209
#11 0x000000000043e3a2 in mrb_obj_alloc (mrb=0x23b9010, ttype=MRB_TT_STRING, 
    cls=0x23c9578) at ../../src/gc.c:268
#12 0x0000000000421f56 in mrb_str_new (mrb=0x23b9010, 
    p=0x7fff71a2f490 "arena overflow error", len=20) at ../../src/string.c:624
#13 0x00000000004162d8 in mrb_exc_new (mrb=0x23b9010, c=0x23c4e78, 

Supress "warning: comparison is always true due to limited range of data type"

Refs #75.

There are so many "warning: comparison is always true due to limited range of data type" in mruby.h

I'm not sure the strict C language specification.
But enum is converted to signed int in case there are at least one negative values.
(I tested on gcc-4.2 (OSX). It seems ARM's genuine compiler also works same.)

So this code will stop warnings.

enum mrb_vtype {
  DUMMY = -1, /* Supress warnings. Slightly tricky */
  MRB_TT_FALSE = 0,   /*   0 */
  MRB_TT_FREE,        /*   1 */

Or this code also will stop as same as above.

#define IMMEDIATE_P(x) (mrb_type(x) <= MRB_TT_FLOAT) /* Don't compare with MRB_TT_FALSE as it is always true. */

There are some plans to fix it. So I just only suggest without patches.

Inappropriate assumption about the pointer address.

This is minor case, but we care of this story.
In the embedded system what can use the memory space which begins from the address 0 as a usual data area exists.
It makes bugs sometimes.

See this code.

void *ptr = ptr_to_data_or_data_type;
intptr_t data_type = (intptr_t)ptr_to_data_or_data_type;
switch (data_type) {
case 0:
    do_something_0(ptr);
    break;
case 1:
    do_something_1(ptr);
    break;
}

This code can run normally, if 'ptr' is far from address 0 enough.
However, this assumption is out of place in a specific embedded system.

In src/parser.y: void parser_dump(...)

dump_prefix(offset);
n = (int)(intptr_t)tree->car;
tree = tree->cdr;
switch (n) {

This code has same problem.

64 bit

Is mruby supposed to compile on 64? I noticed that in mrbconf.h there is an uncondional define

define SIZEOF_VOIDP 4

Can I change these defines to the correct values for my 64bit system or this will this break anything?

Underlying bug in mrb_get_args()

mrb_get_args() in class.c

    case 's':
      {
        char **ps;
        size_t *pl;
        struct RString *s;

        if (argc > i) {
          s = mrb_str_ptr(*sp);
          ps = va_arg(ap, char**);
          *ps = s->buf;
          pl = va_arg(ap, size_t*);
          *pl = s->len;
        }
        else {
          *ps = "";
          *pl = 0;

This code will be crashed in case argc <= i. It should be fixed or removed.
I think it's possible to remove it as there is no path calling this case clause in the current version.

`p global_variables` segfaults on Linux x86-64

The following code causes a Segfault on Fedora Linux x86-64, gcc 4.6.3 20120306:

p global_variables

Backtrace:

#0  0x000000000047b57b in mrb_f_global_variables (mrb=0x7cf010, self=...)
    at ../../src/variable.c:350
350   for (i=0;i< kh_end(h);i++) {
(gdb) bt
#0  0x000000000047b57b in mrb_f_global_variables (mrb=0x7cf010, self=...)
    at ../../src/variable.c:350
#1  0x00000000004508e4 in mrb_run (mrb=0x7cf010, proc=0x7d8c78, self=...)
    at ../../src/vm.c:669
#2  0x0000000000401d32 in main (argc=2, argv=0x7fff6d496558)
    at ../../src/../tools/mruby/mruby.c:160

Question on mrb_get_args behavior

I'm currently using

static mrb_value MR_JsonParse (mrb_state* mrb, mrb_value self) {
char* s;
size_t l;
int res;

res = mrb_get_args(mrb, "s", &s, &l);
printf("---> %d\n", res);
printf("===> %d %s\n", (int) l, s == NULL ? "NULL" : s);

return mrb_float_value(0);
}

void TRI_InitMRUtils (mrb_state* mrb) {
struct RClass *rcl;

rcl = mrb->kernel_module;

rcl = mrb_define_class(mrb, "ArangoJson", mrb->object_class);

mrb_define_class_method(mrb, rcl, "parse", MR_JsonParse, ARGS_REQ(1));
}

I have the following questions:

(1) what is the purpose of ARGS_REQ(1)? Is it ignored? Calling

ArangoJson.parse "a" "b"

does not raise an exception.

(2) Is mrb_get_args the correct way to access the arguments

ArangoJson.parse "a"

works, but

ArangoJson.parse 1

crashs mruby.

(3) What is the meaning of the result value?

Thanks for sharing any insight,
Frank

use gmtime_s/localtime_s on windows

In src/time.c it says:

#ifdef _WIN32
/* unfortunately Win32 platform do not provide gmtime_r/localtime_r */
#define NO_GMTIME_R
#endif 

Actually, windows does provide gmtime_s and localtime_s which provide the same functionality, but their arguments are in the opposite order and they return an errno_t. So instead, you can do

#ifdef _WIN32
#define gmtime_r(tp, tm)    ((gmtime_s((tm), (tp)) == 0) ? (tp) : NULL)
#define localtime_r(tp, tm)    ((localtime_s((tm), (tp)) == 0) ? (tp) : NULL)
#endif /* _WIN32 */

...and you should be all set. See: http://msdn.microsoft.com/en-us/library/a442x3ye(v=vs.80).aspx for details

The method "methods" cause mruby interpreter to crash.

The method "methods" cause mruby interpreter to crash.
example:

puts Object.methods  # crash~

I think have two ways to fix this issue,but I'm not so sure.
1.kernel.c

static void
method_entry_loop(mrb_state *mrb, struct RClass* klass, mrb_value ary)
{
  int i;

  khash_t(mt) *h = klass->mt;

 if(!h) return;   /* if mt is 0, return    */

  for (i=0;i<kh_end(h);i++) {
    if (kh_exist(h, i)) {
      mrb_ary_push(mrb, ary, mrb_symbol_value(kh_key(h,i)));
    }
  }
}

or

2.class.c

static void
make_metaclass(mrb_state *mrb, struct RClass *c)
{
  struct RClass *sc;

  if (c->c->tt == MRB_TT_SCLASS) {
    return;
  }
  sc = mrb_obj_alloc(mrb, MRB_TT_SCLASS, mrb->class_class);
  sc->mt = kh_init(mt, mrb);   /* initialize method table */
  if (!c->super) {
    sc->super = mrb->class_class;
  }
  else {
    sc->super = c->super->c;
  }
  c->c = sc;
  mrb_field_write_barrier(mrb, (struct RBasic*)c, (struct RBasic*)sc);
  mrb_field_write_barrier(mrb, (struct RBasic*)sc, (struct RBasic*)sc->super);
}

encoidng.h missing when including mruby/string.h

When I use mruby/string.h on my program. encoding.h does not find.

mruby/include/mruby/string.h:11:10: fatal error: 'encoding.h' file not found
#include "encoding.h"

Currently, encoding.h is in mruby/src directory. probably, It would be placed in include/ruby directory i think.
(also some header files.)

Thanks

mruby equivalent of rb_define_module_function

Current implementation of Math module relies on the mrb_define_class_method() function. Since all the math functions are thus defined as class methods of the Math module, the only way of using them is

Math.sin(angle)

and, in particular, you cannot do things as:

class Foo
    include Math
    def one(a)
        sin(a)**2 * cos(a)**2
    end
end

Nevertheless, the mrb_define_method does not work, and there is no equivalent to the CRuby's rb_define_module_function().

Anyone knows how to solve this?

build error by segmentation fault

$ cat /etc/slackware-version
Slackware 13.37.0

$ uname -a
Linux c760 3.1.10 #1 PREEMPT Thu Feb 16 01:18:19 JST 2012 armv5tel XScale-PXA255 rev 6 (v5l) SHARP Husky GNU/Linux

$ tar xvzf mruby-mruby-e26bf08.tar.gz
$ cd mruby-mruby-e26bf08
$ make

snip

gcc -o ../../bin/mrbc ../../src/../tools/mrbc/mrbc.o ../../src/transcode.o ../../src/state.o ../../src/string.o ../../src/ascii.o ../../src/unicode.o ../../src/cdump.o ../../src/
crc.o ../../src/struct.o ../../src/codegen.o ../../src/sprintf.o ../../src/init.o ../../src/kernel.o ../../src/us_ascii.o ../../src/gc.o ../../src/vm.o ../../src/regparse.o ../..
/src/class.o ../../src/etc.o ../../src/dump.o ../../src/re.o ../../src/regcomp.o ../../src/version.o ../../src/encoding.o ../../src/error.o ../../src/hash.o ../../src/regenc.o ..
/../src/object.o ../../src/utf_8.o ../../src/compar.o ../../src/proc.o ../../src/regexec.o ../../src/variable.o ../../src/range.o ../../src/pool.o ../../src/enum.o ../../src/nume
ric.o ../../src/array.o ../../src/regerror.o ../../src/print.o ../../src/symbol.o ../../src/st.o ../../src/y.tab.o -lm
make: built targets of /home/m-ito/tmp/mruby-mruby-e26bf08/tools/mrbc
cat struct.rb error.rb string.rb hash.rb compar.rb range.rb enum.rb numeric.rb kernel.rb array.rb print.rb > mrblib.rbtmp
../bin/mrbc -Bmrblib_irep -omrblib.ctmp mrblib.rbtmp; cat init_mrblib.c mrblib.ctmp > mrblib.c
/bin/sh: line 1: 14047 Segmentation fault ../bin/mrbc -Bmrblib_irep -omrblib.ctmp mrblib.rbtmp

snip

make: built targets of /home/m-ito/tmp/mruby-mruby-e26bf08/mrblib
gcc -o ../../bin/mruby ../../src/../tools/mruby/mruby.o ../../src/transcode.o ../../src/unicode.o ../../src/crc.o ../../src/struct.o ../../src/us_ascii.o ../../src/proc.o ../../s
rc/pool.o ../../src/regenc.o ../../src/load.o ../../src/ascii.o ../../src/version.o ../../src/hash.o ../../src/utf_8.o ../../src/codegen.o ../../src/range.o ../../src/enum.o ../.
./src/regerror.o ../../src/symbol.o ../../src/object.o ../../src/state.o ../../src/vm.o ../../src/print.o ../../src/sprintf.o ../../src/init.o ../../src/numeric.o ../../src/error
.o ../../src/regparse.o ../../src/init_ext.o ../../src/class.o ../../src/etc.o ../../src/string.o ../../src/regcomp.o ../../src/kernel.o ../../src/encoding.o ../../src/compar.o .
./../src/regexec.o ../../src/variable.o ../../src/re.o ../../src/array.o ../../src/gc.o ../../src/st.o ../../src/y.tab.o ../../src/../mrblib/mrblib.o -lm
../../src/../mrblib/mrblib.o: In function mrb_init_mrblib': /home/m-ito/tmp/mruby-mruby-e26bf08/mrblib/mrblib.c:16: undefined reference tomrblib_irep'
collect2: ld returned 1 exit status
make[1]: *** [../../bin/mruby] Error 1
make: *** [src/init_ext.o] Error 2

$ cd mrblib/
$ ../bin/mrbc -Bmrblib_irep -omrblib.ctmp mrblib.rbtmp
Segmentation fault

$ gdb ../bin/mrbc
GNU gdb (GDB) 7.2
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "arm-slackware-linux-gnueabi".
For bug reporting instructions, please see:
http://www.gnu.org/software/gdb/bugs/...
Reading symbols from /home/m-ito/tmp/mruby-mruby-e26bf08/bin/mrbc...done.
(gdb) run -Bmrblib_irep -omrblib.ctmp mrblib.rbtmp
Starting program: /home/m-ito/tmp/mruby-mruby-e26bf08/bin/mrbc -Bmrblib_irep -omrblib.ctmp mrblib.rbtmp

Program received signal SIGSEGV, Segmentation fault.
0x000ab7ec in parser_yylex (p=0x11c8f0) at ../../src/parse.y:4451
4451 if (!identchar(c)) {
(gdb) list
4446 case '_':
4447 token_column = newtok(p);
4448 break;
4449
4450 default:
4451 if (!identchar(c)) {
4452 yyerror_i(p, "Invalid char `\x%02X' in expression", c);
4453 goto retry;
4454 }
4455
(gdb) p c
$1 = 2686976
(gdb) quit
A debugging session is active.

    Inferior 1 [process 14086] will be killed.

Quit anyway? (y or n) y

What can I do ?

[WinSDK] Numeric#** C99 impl breaks build

With WinSDK 7.1 with cl 16.00.30319.01 I get the following failure because numeric.c:num_pow uses C99 isfinite which the msvc math.h header doesn't provide.


...
mruby_static.lib(numeric.c.obj) : error LNK2019: unresolved external symbol _isfinite referenced in function _num_pow
mrbc.exe : fatal error LNK1120: 1 unresolved externals
LINK Pass 1 failed. with 2
NMAKE : fatal error U1077: 'C:\Apps\cmake\bin\cmake.exe' : return code '0xffffffff'
Stop.

If isfinite and other C99-isms are needed, the mingw and mingw-w64 math.h provides public domain impls. For example, line 281+ from the mingw-w64 math.h impl

more header files should get 'extern "C"' guards

Some of the header files have C++ guards already:

include/mruby/data.h:extern "C" {
src/encoding.h:extern "C" {
src/oniguruma.h:extern "C" {
src/regex.h:extern "C" {
src/st.h:extern "C" {

However most of the header files (mruby.h, mruby/proc.h, etc) are missing them, making it inconvenient to use from C++ code

introduce fiber support

well, thread is not important for mruby, but I do think fiber is a very interesting feature.

SIZEOF_ST_INDEX_T undeclared

Just a heads up: I compiled last night, everything worked fine. Build is broken this morning though:

../../src/st.c: In function ‘st_hash’:
../../src/st.c:1053: error: ‘SIZEOF_ST_INDEX_T’ undeclared (first use in this function)
../../src/st.c:1053: error: (Each undeclared identifier is reported only once
../../src/st.c:1053: error: for each function it appears in.)

Partial merge maybe?

latest OS/X, Xcode

Is mrb_define_variable missing or replaced by something else?

The header file still contains a "mrb_define_variable". But it seems to be missing from variable.c file. Is there an replacement?

fceller@huerth:~/mruby> fgrep mrb_define_variable src/variable.h
void mrb_define_variable(mrb_state *mrb, const char *name, mrb_value *var);

Time class is missing

p Time.now => #<NameError: uninitialized constant Time>

One class at a time, I know, I know. But aiming at embedded and realtime applications, the Time class is rather important...

Size is too large

Mruby is still quite large even when stripping .eh_frame and debug sections ~ 1mb for ritevm as well as mruby and mrb

modest proposal for enhanced multi-platform support

It's likely that platform specific implementation details will become scattered throughout the codebase making it less maintainable and less understandable.

I propose a change to the current include structure to better modularize platform specifics where possible. Specifically, update mruby.h with the following


...
#ifndef MRUBY_H
#define MRUBY_H

#include 
#include "mrbconf.h"

#if defined(__unix__) || defined(__POSIX__) || defined(__APPLE__)
# /* TODO: include "mrb-internal/mrb-unix.h" */
#else
# include "mrb-internal/mrb-win.h"
#endif

and start by consolidating all the applicable windows impl oddities into the include/mrb-internal/mrb-win.h file. The goal is to minimize platform specific #ifdef's in the *.c files and allow for future platform specific include files, eg. mrb-internal/mrb-arm.h.

An example of how this looks in real-world code:

Behavior of mrb_parse_string

Is it a desired behavior that mrb_parse_string does directly print a syntax error to stderr? I would like to get the lexical state of a parsed string without printing anything. So I thought of calling mrb_parse_string and then take the parser_state->lstate structure. Is there a better function available for doing this which I didn't found yet?

incorrect gmtime_r/localtime_r macros?

In time.c, shouldn't the following macros return (tm), a struct tm *, rather than (tp), a time_t *


#define gmtime_r(tp, tm)    ((gmtime_s((tm), (tp)) == 0) ? (tp) : NULL)
#define localtime_r(tp, tm)    ((localtime_s((tm), (tp)) == 0) ? (tp) : NULL)

given their usage by struct tm *aid in mrb_time_update_datetime?


struct mrb_time*
mrb_time_update_datetime(struct mrb_time *self)
{
  struct tm *aid;

  if(self->timezone == MRB_TIMEZONE_UTC) { 
    aid = gmtime_r(&self->sec, &self->datetime);
  }
  else {
    aid = localtime_r(&self->sec, &self->datetime);
  }
  if(!aid) return NULL;
#ifdef NO_GMTIME_R
  self->datetime = *aid; // copy data
#endif

  return self;  
}

build failed when #undef INCLUDE_ENCODING

I tried to build without INCLUDE_ENCODING and INCLUDE_REGEXP, like below:

diff --git a/include/mrbconf.h b/include/mrbconf.h
index b21388f..af7d880 100644
--- a/include/mrbconf.h
+++ b/include/mrbconf.h
@@ -22,10 +22,10 @@ typedef intptr_t mrb_sym;
 #define readint(p,base) strtol((p),NULL,(base))
 
 #undef  INCLUDE_ENCODING   /* not use encoding classes (ascii only) */
-#define INCLUDE_ENCODING   /* use UTF-8 encoding classes */
+/* #define INCLUDE_ENCODING */  /* use UTF-8 encoding classes */
 
 #undef  INCLUDE_REGEXP     /* not use regular expression classes */
-#define INCLUDE_REGEXP     /* use regular expression classes */
+/* #define INCLUDE_REGEXP */    /* use regular expression classes */
 
 #ifdef  INCLUDE_REGEXP
 # define INCLUDE_ENCODING  /* Regexp depends Encoding */

then I got an error and stoped.

$ make
gcc -Wall -Werror-implicit-function-declaration -g -O3 -MMD -I. -I./../include -c array.c -o array.o
In file included from array.c:7:
./../include/mruby.h: In function ‘mrb_special_const_p’:
./../include/mruby.h:101: warning: comparison is always true due to limited range of data type
gcc -Wall -Werror-implicit-function-declaration -g -O3 -MMD -I. -I./../include -c ascii.c -o ascii.o
(snip)
make: built targets of /Users/maki/git/mruby/src
make -C ../tools/mrbc CC='gcc' LL='gcc' ALL_CFLAGS='-Wall -Werror-implicit-function-declaration -g -O3'
gcc -Wall -Werror-implicit-function-declaration -g -O3 -MMD -I../../src -I../../src/../include -c ../../src/../tools/mrbc/mrbc.c -o ../../src/../tools/mrbc/mrbc.o
In file included from ../../src/../tools/mrbc/mrbc.c:1:
../../src/../include/mruby.h: In function ‘mrb_special_const_p’:
../../src/../include/mruby.h:101: warning: comparison is always true due to limited range of data type
gcc -o ../../bin/mrbc ../../src/../tools/mrbc/mrbc.o ../../lib/libmruby.a -lm
Undefined symbols:
  "_mrb_str_buf_append", referenced from:
      _mrb_str_append in libmruby.a(string.o)
ld: symbol(s) not found
collect2: ld returned 1 exit status
make[2]: *** [../../bin/mrbc] Error 1
make[1]: *** [../bin/mrbc] Error 2
make: *** [all] Error 2

MANDEL block in init.c

There is a #ifdef MANDEL block in init.c that defines pow, sqrt, and putc methods under the kernel. I could not find any reference to the MANDEL preproc in the source, so I wonder what is its purpose (there is a #define MANDEL immediately before).

I still don't have access to the ISO standard, but I wonder if we could:

  1. remove the whole MANDEL section,
  2. move the sqrt function under the Math module,
  3. move the pow function in numeric.c and call it ** as in ruby standard (is there an ISO code for it?)
  4. move the putc function in kernel.c (again: ISO code?)

Read-Eval-Print Loop

Is it possible to implement a read-eval-print loop?

I'va basically tried

while (read line) {
...compile...
mrb_value result = mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_nil_value());

if (mrb->exc) {
  mrb_funcall(mrb, mrb_nil_value(), "p", 1, mrb_obj_value(mrb->exc));
}
else {
  mrb_funcall(mrb, mrb_nil_value(), "p", 1, result);
}

}

But given the input "1" mrb_run does return nothing.

Is it possible to extract the value of the block?

BTW: typing "yield 1" or "return 1" results in a crash:

avocmrb> return 1

Program received signal SIGSEGV, Segmentation fault.
0x000000000097a864 in mrb_run (mrb=0x103ac60, proc=0x0, self=...) at ../../src/vm.c:1008
1008 irep = proc->body.irep;
(gdb) where
#0 0x000000000097a864 in mrb_run (mrb=0x103ac60, proc=0x0, self=...)

at ../../src/vm.c:1008

#1 0x0000000000488dde in triagens::avocado::AvocadoServer::executeRubyShell (

Many compile warnings

Compiling mruby with gcc creates a plethora of build warnings - will attach output from gcc and clang when I have access to a machine

some files aren't removed with make clean

When I do make clean, some files are not removed.

mrblib/mrblib.d
src/cdump.d
src/cdump.o
src/dump.d
src/dump.o
tools/mrbc/mrbc.d
tools/mrbc/mrbc.o

Notice that *.d and *.o files is in .gitignore, so we cannot find them with git status.

mruby may be crashed by uninitialized pointers.

I got some warnings by using -strict option.

class.c: In function 'mrb_get_args':
class.c:416: warning: 'pl' may be used uninitialized in this function
class.c:415: warning: 'ps' may be used uninitialized in this function

I just reviewed and doesn't run. But I feel these warnings are reasonable.
The hash of my class.c is f4cf8ea.

Math functions C99

I can't compile math.c in MSVC.

Some math functions are not supported in MSVC,
asinh, acosh, atanh, cbrt, erf, erfc, signbit, tgamma

Are those functions are needed?

Bug with Hash tables with symbols as keys

Hi, I was playing with adding native methods to a module, and ran into a problem, with rb_hash_get() when using symbols as keys. For example here is some ruby code:

Foo::bar({ :a => 1, :b => 2 })
puts '*********'
Foo::bar({ :yyy => 10, :a => 1, :xxx => 10, :b => 2 })

And here is the body of the bar c function:

static mrb_value bar(mrb_state* mrb, mrb_value obj)
{
    mrb_value hash;
    mrb_get_args(mrb, "o", &hash);
    mrb_value a_val = mrb_hash_get(mrb, hash, a_sym);
    dump(a_val);
    mrb_value b_val = mrb_hash_get(mrb, hash, b_sym);
    dump(b_val);
    return mrb_nil_value();
}

When I run this program I get inconsistant results with the two hashes:

fixnum 1
nil
*********
fixnum 1
fixnum 2

Am I doing something incorrect with interning the symbol keys?

a_sym = mrb_symbol_value(mrb_intern(mrb, "a"));
b_sym = mrb_symbol_value(mrb_intern(mrb, "b"));

The full source is here:

https://github.com/hyperlogic/mruby-test/blob/master/main.cpp

How about a Math module?

Is it OK if I start working on it, including the initialization in init.c?
Is there someone already doing it?

Crash while inspect hashs.

h = {}
(1...120).each {|x| h[x] = x }
p h

Windows XP SP3. MinGW32

gcc (GCC) 4.6.2
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
bison (GNU Bison) 2.4.1
Written by Robert Corbett and Richard Stallman.

Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[参考訳 -- 法的効力は英文が適用されます]
これはフリーソフトウェアです -- 複製についての条件はソースを見ましょう。
一切の保証はありません -- 商業性や目的適合性についての保証すらありません。

class Test; end

Defining a class gives an error message:

fceller@huerth:/tmp/mruby> ./bin/mruby test.rb

<TypeError: wrong argument type nil (expected Class)>

fceller@huerth:/tmp/mruby> cat test.rb
class Test
end

make fails on Centos/gcc 4.1.2 for undefined methods

I was able to compile mruby on my OSX machine (10.5.x with gcc 4.2.1) but when compiling on Centos (5.8) with gcc 4.1.2 I get an undefined error in src/numeric.c for the "round" method.

The "round" method is undefined unless I compile with c99 support (-std=c99) but when adding that option I get an undefined error in src/encoding.c for the "strdup" method.

The "strdup" method is NOT c99 but it is implemented when using instead -std=gnu99 (c99 + gnu extensions). With this option I can build mruby with no errors.

add <string.h> to mrbc.c to suppress mingw-w64 warnings

Building with mingw-w64 on Windows (or cross compiling from Ubuntu) I get the following warnings that don't occur with mingw32.

It's likely a simple header difference and adding <string.h> to tools/mrbc/mrbc.c makes the warnings disappear.


...
[ 90%] Building C object tools/mrbc/CMakeFiles/mrbc.dir/mrbc.c.obj
c:/Users/Jon/Documents/RubyDev/mruby-git/tools/mrbc/mrbc.c: In function 'get_outfilename':
c:/Users/Jon/Documents/RubyDev/mruby-git/tools/mrbc/mrbc.c:55:27: warning: incompatible implicit declaration of built-in function 'strlen' [enabled by default]
c:/Users/Jon/Documents/RubyDev/mruby-git/tools/mrbc/mrbc.c:56:3: warning: incompatible implicit declaration of built-in function 'strcpy' [enabled by default]
c:/Users/Jon/Documents/RubyDev/mruby-git/tools/mrbc/mrbc.c:58:14: warning: incompatible implicit declaration of built-in function 'strrchr' [enabled by default]
c:/Users/Jon/Documents/RubyDev/mruby-git/tools/mrbc/mrbc.c: In function 'parse_args':
c:/Users/Jon/Documents/RubyDev/mruby-git/tools/mrbc/mrbc.c:78:11: warning: incompatible implicit declaration of built-in function 'strlen' [enabled by default]

Integer overflow

code

def fact n; (n > 1) ? n*fact(n-1) : 1; end
30.times{|i| puts "#{i}! = #{fact i}"}

produces

0! = 1
1! = 1
2! = 2
3! = 6
4! = 24
5! = 120
6! = 720
7! = 5040
8! = 40320
9! = 362880
10! = 3628800
11! = 39916800
12! = 479001600
13! = 1932053504
14! = 1278945280
15! = 2004310016
16! = 2004189184
17! = -288522240
18! = -898433024
19! = 109641728
20! = -2102132736
21! = -1195114496
22! = -522715136
23! = 862453760
24! = -775946240
25! = 2076180480
26! = -1853882368
27! = 1484783616
28! = -1375731712
29! = -1241513984

Missing src/mdata.h

Attempted building mruby (2b9ed5a) on Fedora Linux x86-64 with gcc 4.6.3:

../../src/error.c: At top level:
../../src/error.c:403:1: warning: ‘mrb_exc_c_exception’ defined but not used [-Wunused-function]
../../src/error.c:413:1: warning: ‘mrb_exc_exception’ defined but not used [-Wunused-function]
make[2]: *** No rule to make target `../../src/mdata.h', needed by `../../src/dump.o'.  Stop.
make[1]: *** [../bin/mrbc] Error 2
make: *** [src/mrblib/mrblib.o] Error 2

Doesn't work mrb_parse_string/mrb_parse_file on iOS

Doesn't work mrb_parse_string/mrb_parse_file on iOS Simulator.
How I get more debugging information?

Compile information

xcrun -sdk iphoneos llvm-gcc-4.2 -arch i386 -isysroot "/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/" $@

Code

mrb_state *mrb = mrb_open();
struct mrb_parser_state *p = mrb_parse_string(mrb, "puts 123");

if (!p || !p->tree || p->nerr) {
    puts("Error");
    printf("p=%p\n", p);
    printf("tree=%p\n", p->tree);
    printf("nerr=%d", p->nerr);
    return -1;
}

Result

Error
p=0x7296c10
tree=0x0
nerr=0

"p 1" parse error on ARM

The code raise alignement error on ARM cpu.

mrb_parse_string(mrb, "p 1");
* thread #1: tid = 0x1c03, 0x000c62d8 MobiRuby`parser_yylex [inlined] cons_gen + 104 at parse.y:95, stop reason = EXC_BAD_ACCESS (code=EXC_ARM_DA_ALIGN, address=0x3f415fa)
    frame #0: 0x000c62d8 MobiRuby`parser_yylex [inlined] cons_gen + 104 at parse.y:95
    frame #1: 0x000c6270 MobiRuby`parser_yylex [inlined] parser_strdup at y.tab.c:118
    frame #2: 0x000c6270 MobiRuby`parser_yylex [inlined] tok at y.tab.c:663
    frame #3: 0x000c6270 MobiRuby`parser_yylex + 13872 at y.tab.c:4069
    frame #4: 0x000b59d6 MobiRuby`yyparse [inlined] yylex + 14 at parse.y:4610
    frame #5: 0x000b59c8 MobiRuby`yyparse + 988 at y.tab.c:4993
    frame #6: 0x000c7d1e MobiRuby`start_parser + 70 at parse.y:4626

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.