Giter Site home page Giter Site logo

mrubyc's People

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

mrubyc's Issues

Which branch should I pull request on?

I find the branch mrubyc3.1 is under active development, but I can't test it using mrubyc-test on account of some bugs which I can't fix for now. I'm not using docker, instead I just install mrubyc-test gem directly .

However, I can test the master branch well, and I've already implemented some lacking pieces of the code. Can I pull request on the master branch?

warning

i get 3 warning:

cc -Wall -Wpointer-arith -g -DMRBC_DEBUG -c -o c_string.o c_string.c
c_string.c:75:13: warning: unused function 'c_string_idx_get'
[-Wunused-function]
static void c_string_idx_get(mrb_vm *vm, mrb_value *v)
^
1 warning generated.
cc -Wall -Wpointer-arith -g -DMRBC_DEBUG -c -o c_symbol.o c_symbol.c
c_symbol.c:13:18: warning: implicit declaration of function 'mrbc_string_dup' is
invalid in C99 [-Wimplicit-function-declaration]
v->value.str = mrbc_string_dup(vm, sym);
^
c_symbol.c:13:16: warning: incompatible integer to pointer conversion assigning
to 'char *' from 'int' [-Wint-conversion]
v->value.str = mrbc_string_dup(vm, sym);
^ ~~~~~~~~~~~~~~~~~~~~~~~~
2 warnings generated.

MRB_TT_NIL

Is MRB_TT_NIL necessary?

Although nil is different from false, that is same behavior in conditional expression.

libmrubyc.a(c_math.o) has no symbols

condition

OS Mac OS Sierra 10.12.6
cc --version Apple LLVM version 9.0.0 (clang-900.0.39.2) Target: x86_64-apple-darwin16.7.0
mrubyc-master Latest commit ae1d945
Date: Mon Aug 3 10:01:00 2018 +0900

compile

mrubyc-master


$ make
cd mrblib ; make all
make[1]: Nothing to be done for `all'.
cd src ; make all
/Library/Developer/CommandLineTools/usr/bin/make libmrubyc.a
cc -Wall -Wpointer-arith -g -DMRBC_DEBUG     -c -o alloc.o alloc.c
cc -Wall -Wpointer-arith -g -DMRBC_DEBUG     -c -o class.o class.c
cc -Wall -Wpointer-arith -g -DMRBC_DEBUG     -c -o console.o console.c
cc -Wall -Wpointer-arith -g -DMRBC_DEBUG     -c -o global.o global.c
cc -Wall -Wpointer-arith -g -DMRBC_DEBUG     -c -o keyvalue.o keyvalue.c
cc -Wall -Wpointer-arith -g -DMRBC_DEBUG     -c -o load.o load.c
cc -Wall -Wpointer-arith -g -DMRBC_DEBUG     -c -o rrt0.o rrt0.c
cc -Wall -Wpointer-arith -g -DMRBC_DEBUG     -c -o static.o static.c
cc -Wall -Wpointer-arith -g -DMRBC_DEBUG     -c -o symbol.o symbol.c
cc -Wall -Wpointer-arith -g -DMRBC_DEBUG     -c -o value.o value.c
cc -Wall -Wpointer-arith -g -DMRBC_DEBUG     -c -o vm.o vm.c
cc -Wall -Wpointer-arith -g -DMRBC_DEBUG     -c -o hal/hal.o hal/hal.c
cc -Wall -Wpointer-arith -g -DMRBC_DEBUG     -c -o c_array.o c_array.c
cc -Wall -Wpointer-arith -g -DMRBC_DEBUG     -c -o c_hash.o c_hash.c
cc -Wall -Wpointer-arith -g -DMRBC_DEBUG     -c -o c_numeric.o c_numeric.c
cc -Wall -Wpointer-arith -g -DMRBC_DEBUG     -c -o c_math.o c_math.c
cc -Wall -Wpointer-arith -g -DMRBC_DEBUG     -c -o c_range.o c_range.c
cc -Wall -Wpointer-arith -g -DMRBC_DEBUG     -c -o c_string.o c_string.c
cc -Wall -Wpointer-arith -g -DMRBC_DEBUG     -c -o mrblib.o mrblib.c
ar rv libmrubyc.a alloc.o class.o console.o global.o keyvalue.o load.o rrt0.o static.o symbol.o value.o vm.o hal/hal.o c_array.o c_hash.o c_numeric.o c_math.o c_range.o c_string.o mrblib.o
ar: creating archive libmrubyc.a
a - alloc.o
a - class.o
a - console.o
a - global.o
a - keyvalue.o
a - load.o
a - rrt0.o
a - static.o
a - symbol.o
a - value.o
a - vm.o
a - hal/hal.o
a - c_array.o
a - c_hash.o
a - c_numeric.o
a - c_math.o
a - c_range.o
a - c_string.o
a - c_symbol.o
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: libmrubyc.a(c_math.o) has no symbols
cd ext ; make all
/Library/Developer/CommandLineTools/usr/bin/make libmrubyc_ext.a 
cc -Wall -Wpointer-arith -g -DMRBC_DEBUG -I../src    -c -o c_ext.o c_ext.c
ar rv libmrubyc_ext.a c_ext.o
ar: creating archive libmrubyc_ext.a
a - c_ext.o
cd sample_c ; make all
cc -g -I ../src -I ../ext -Wall -Wpointer-arith -L ../src -o mrubyc main.c ../src/libmrubyc.a ../ext/libmrubyc_ext.a
cc -g -I ../src -I ../ext -Wall -Wpointer-arith -L ../src -o mrubyc_sample main_sample.c ../src/libmrubyc.a ../ext/libmrubyc_ext.a
cc -g -I ../src -I ../ext -Wall -Wpointer-arith -L ../src -o mrubyc_concurrent main_concurrent.c ../src/libmrubyc.a ../ext/libmrubyc_ext.a
cc -g -I ../src -I ../ext -Wall -Wpointer-arith -L ../src -o mrubyc_myclass main_myclass.c ../src/libmrubyc.a ../ext/libmrubyc_ext.a

execute

$ cd sample_ruby
$ /Users/administrator/Downloads/mruby-1.3.0/bin/mrbc mrubyc basic_sample01.rb 
$ ../sample_c/mrubyc basic_sample01.mrb 
30
-10
30

comment

Can I ignore the warning?

There are no description to use mrbc at doc.

!!

a = !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!a
(mirb):5: too complex expression

Keyword redo in block works strangely

Environment

  • mruby/c
    • tag: release2.1
  • mrbc
    • 2.1.1
  • Ubuntu 20.04 on WSL2 (Windows 10)

Code

[0,1].each do |i|
  redo if i == 0
  puts i
end

Expected

  • Prints nothing
  • Doesn't exit (loops infinitely)

Actual

  • Prints below and exits as if it's normally finished

1

(Line 1 is empty line that happens like puts nil)

Case 2

a = 0
[0,1].each do |i|
  redo if a == 0
  puts i
end

This code loops infinitely as we expect.
So, it seems accessing local variable i which is configured as a block parameter goes something wrong.

Symbol method name not consistent with others

A class's instance method name should be c_classname_methodname, for example c_string_insert

But in Symbol class, it's not consistent, for example: c_to_s should be c_symbol_to_s

"No method" error happens when instance variable is set in initialize method

Precondition

  • OS Windows10/cygwin64
  • mruby 1.3.0
  • mruby/c
    commit 7549788 (HEAD -> master, origin/master, origin/HEAD)
    Author: Hirohito Higashi <uzuki.local>
    Date: Wed May 30 17:27:00 2018 +0900

Procedure to reproduce

to run the following byte-compiled script test.rb by mrbc.

class Test
        def initialize
                puts "initilize"
                @val="test"
        end
        def method1
                puts "method1"
                puts @val
        end

end

t=Test.new
t.method1

Expected result

 $ ./mrubyc.exe test.mrb
initilize 
method1
test

Observed result

 $ ./mrubyc.exe test.mrb
initilize 
No method. vtype=23 method='method1'

Comment

Is that expected behavior? I also saw the same error on ubuntu14.04 32bit.
I'm trying to find cause for my study...

benchmark and memory ussage

Is possible to write some scripts to count:
benchmark
$ time ./mrubyc_sample
real 0m0.001s
user 0m0.000s
sys 0m0.001s
(but not only once time)

and memory usage:
$memory_usage ./mrubyc_sample
min, max

I don't know how writing this

`#define MAX_SYMBOLS_COUNT` - Is this value arbitrary?

In src/vm_config.h the macro variable MAX_SYMBOLS_COUNT has a value of 255.

I haven't found anything in the code to provide a concrete reason why it's that number.
Is it just what was set? or does the runtime need it to be no higher than a uint8_t value?
I'm just running into that as an error (Overflow MAX_SYMBOLS_COUNT) and I want to know if making it higher will affect anything.

Please write documentation

Please write me small documentation.
For example one function, one ruby opcodes
but with information how get arguments, how return numbers or symbols
small information for developers.

BTW is possible to create web page width information how many opcodes ist and how many need to write

some sample update

diff --git a/sample_ruby/basic_sample01.rb b/sample_ruby/basic_sample01.rb
index 207ddcc..d0fce3a 100644
--- a/sample_ruby/basic_sample01.rb
+++ b/sample_ruby/basic_sample01.rb
@@ -11,3 +11,9 @@ b = b / 2
c = a + b
puts c

+a = 3
+b = 2 ** a
+puts b
+
+c = b * 2 - a - 2
+puts c
diff --git a/sample_ruby/basic_sample05.rb b/sample_ruby/basic_sample05.rb
index eeba72e..9d5b85e 100644
--- a/sample_ruby/basic_sample05.rb
+++ b/sample_ruby/basic_sample05.rb
@@ -4,3 +4,4 @@ for i in 1..10 do
puts i
end

+(11..19).each {|e| puts e}


for example

# loop
4.times do |a| puts a end
(4..8).each {|e| puts e}
for i in 9..12 do
  puts i
end

string_sample03.rb

String

a = "Super "
puts a * 3

puts "This is " + self.to_s + " program"

a << "mrubyc"
puts a

puts "abcdef" <=> "abcde"
puts "abcd".bytesize
puts "żółw".bytesize


.size == .bytesize ? mrubyc not using utf8?

Illegal return position when returning from block

The return position is incorrect when returning from a block.

Revision: 4a22ffe

Sample code

class Hoge
  def initialize
    @bufsize = 256
    @bufidx = 0
    @idx = 0
    @buffer = " " * @bufsize
  end

  def _read # stub
    c = "test\n"[@idx]
    @idx += 1
    c
  end

  def get_line(rs="\n")
    puts "get_line start."
    while @bufidx < @bufsize
      c = _read
      break if c == nil  # no data
      if c == rs
        line = @buffer[0, @bufidx]
        @bufidx = 0
        puts "get_line end. line=#{line}"
        return line
      end
      @buffer[@bufidx] = c
      @bufidx += 1
    end
    puts "get_line end. line=nil"
    nil
  end

  def hoge
    puts "hoge start."
    while line = get_line
      puts "hoge: #{line}"
    end
    puts "hoge end."
  end
end

puts ">>>"
Hoge.new.hoge
puts "<<<"

Actual

>>>
hoge start.
get_line start.
get_line end. line=test
<<<

Expect

>>>
hoge start.
get_line start.
get_line end. line=test
hoge: test
get_line start.
get_line end. line=nil
hoge end.
<<<

Cannot call self method from Array#each block

I am testing on Wio 3G

NG Sample.

class MyClass

  def my_loop(array)
    array.each do |v|
      tara(v)  # self.tara is same result
    end
  end

  def tara(val)
    val
  end

end

my = MyClass.new
my.my_loop([1, 2, 3])

=> No Method Error

OK Sample

class MyClass

  def my_loop(array)
    myself = self

    array.each do |v|
      myself.tara(v)
    end
  end

  def tara(val)
    val
  end

end

my = MyClass.new
my.my_loop([1,2,3])

=> OK

suport windows ??????

I compile on windows MINGW64 , but fail

windows do not have SIGALRM ???

$ make all
cd mrblib ; make all
make[1]: Entering directory '/home/jling/mrubyc/mrubyc-release3.1/mrblib'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/home/jling/mrubyc/mrubyc-release3.1/mrblib'
cd src ; make all
make[1]: Entering directory '/home/jling/mrubyc/mrubyc-release3.1/src'
cc -DMRBC_USE_HAL_POSIX -Wall -Wpointer-arith -g -c -o hal_posix/hal.o hal_posix/hal.c
In file included from hal_posix/hal.c:23:
hal_posix/hal.h: In function 'hal_flush':
hal_posix/hal.h:95:10: warning: implicit declaration of function 'fsync' [-Wimplicit-function-declaration]
95 | return fsync(1);
| ^~~~~
hal_posix/hal.c: At top level:
hal_posix/hal.c:32:8: error: unknown type name 'sigset_t'
32 | static sigset_t sigset_, sigset2_;
| ^~~~~~~~
hal_posix/hal.c: In function 'hal_init':
hal_posix/hal.c:63:3: warning: implicit declaration of function 'sigemptyset' [-Wimplicit-function-declaration]
63 | sigemptyset(&sigset_);
| ^~~~~~~~~~~
hal_posix/hal.c:64:3: warning: implicit declaration of function 'sigaddset' [-Wimplicit-function-declaration]
64 | sigaddset(&sigset_, SIGALRM);
| ^~~~~~~~~
hal_posix/hal.c:64:23: error: 'SIGALRM' undeclared (first use in this function); did you mean 'SIGABRT'?
64 | sigaddset(&sigset_, SIGALRM);
| ^~~~~~~
| SIGABRT
hal_posix/hal.c:64:23: note: each undeclared identifier is reported only once for each function it appears in
hal_posix/hal.c:67:20: error: storage size of 'sa' isn't known
67 | struct sigaction sa;
| ^~
hal_posix/hal.c:69:19: error: 'SA_RESTART' undeclared (first use in this function)
69 | sa.sa_flags = SA_RESTART;
| ^~~~~~~~~~
hal_posix/hal.c:71:3: warning: implicit declaration of function 'sigaction' [-Wimplicit-function-declaration]
71 | sigaction(SIGALRM, &sa, 0);
| ^~~~~~~~~
hal_posix/hal.c:74:20: error: storage size of 'tval' isn't known
74 | struct itimerval tval;
| ^~~~
hal_posix/hal.c:81:3: warning: implicit declaration of function 'setitimer' [-Wimplicit-function-declaration]
81 | setitimer(ITIMER_REAL, &tval, 0);
| ^~~~~~~~~
hal_posix/hal.c:81:13: error: 'ITIMER_REAL' undeclared (first use in this function)
81 | setitimer(ITIMER_REAL, &tval, 0);
| ^~~~~~~~~~~
hal_posix/hal.c:74:20: warning: unused variable 'tval' [-Wunused-variable]
74 | struct itimerval tval;
| ^~~~
hal_posix/hal.c:67:20: warning: unused variable 'sa' [-Wunused-variable]
67 | struct sigaction sa;
| ^~
hal_posix/hal.c: In function 'hal_enable_irq':
hal_posix/hal.c:92:3: warning: implicit declaration of function 'sigprocmask' [-Wimplicit-function-declaration]
92 | sigprocmask(SIG_SETMASK, &sigset2_, 0);
| ^~~~~~~~~~~
hal_posix/hal.c:92:15: error: 'SIG_SETMASK' undeclared (first use in this function)
92 | sigprocmask(SIG_SETMASK, &sigset2_, 0);
| ^~~~~~~~~~~
hal_posix/hal.c: In function 'hal_disable_irq':
hal_posix/hal.c:103:15: error: 'SIG_BLOCK' undeclared (first use in this function); did you mean 'SIG_ACK'?
103 | sigprocmask(SIG_BLOCK, &sigset_, &sigset2_);
| ^~~~~~~~~
| SIG_ACK
make[1]: *** [: hal_posix/hal.o] Error 1
make[1]: Leaving directory '/home/jling/mrubyc/mrubyc-release3.1/src'
make: *** [Makefile:23: mrubyc_lib] Error 2

String#ord has a minor bug.

String#ord has a minor bug.

p "\x00".ord

CRuby

0

mruby/c

Exception(vm_id=1): empty string (ArgumentError)

attr_accessor causes Segmantation fault in multi-tasking

sample code

in main.c

...
#include "my_model.c" /* bytecode of my_model.rb */
#include "my_main.c"  /* bytecode of my_main.rb  */
...
int main(void) {
  ...
  mrbc_create_task( my_model, 0 );
  mrbc_create_task( my_main, 0 );
  mrbc_run();
  ...
}

my_model.rb

class MyModel
  # attr_reader causes the same issue
  attr_accessor :my_ivar
end

my_main.rb

MyModel.new #=> Segmentation fault (on POSIX)

unexpected result

this code causes Segmentation fault

in short,

initializing a class that has attr_accessor or/and attr_reader and is defined in other task causes Segmantation fault.

note

initializing a class that is defined in the same task works

class MyClass
  attr_accessor :my_ivar
end
MyClass.new # work well

Several constant visibility issues

  • can't recognize inside class constant
  • can't recognize subclass constant
  • nested class wrong visibility

It's hard to add test with mrubyc-test framework, so I list tests and results here.

# inside class constant case
class X
  FOO = 3
  puts FOO
end
==== CRuby Standard Behaviour ====
3
==== mruby 3.1.0 Behaviour  ======
3
==== mruby 2.1.1 Behaviour  ======
3
==== mruby/c 2.1.1 upstream  =====
NameError: uninitialized constant FOO

==== mruby/c 2.1.1 fixed (pull request behavior) =====
3

# subclass constant case
class A
  FOO = 1
end

class B < A
  puts FOO
end
==== CRuby Standard Behaviour ====
1
==== mruby 3.1.0 Behaviour  ======
1
==== mruby 2.1.1 Behaviour  ======
1
==== mruby/c 2.1.1 upstream  =====
NameError: uninitialized constant FOO
(empty)
==== mruby/c 2.1.1 fixed (pull request behavior) =====
1

# nested class wrong visibility case

FOO = 1

class A
  FOO = 2
  class B
    FOO = 3
    class C
      puts FOO
    end
  end
end
==== CRuby Standard Behaviour ====
3
==== mruby 3.1.0 Behaviour  ======
3
==== mruby 2.1.1 Behaviour  ======
3
==== mruby/c 2.1.1 upstream  =====
1
==== mruby/c 2.1.1 fixed (pull request behavior) =====
3

method receiver problem in block

sample code

class MyClass
  def say
    puts 'hello'
  end
  def say_in_block
    2.times do
      say
    end
  end
end

my_obj = MyClass.new
my_obj.say
my_obj.say_in_block

expected

hello
hello
hello

actual

hello
No method. Class:Proc Method:say
No method. Class:Proc Method:say

this problem seems to appear from this commit
f864d19

make gc_support branch

I try to implement gc feature for mruby/c.
The basic point is,

  • manage objects by reference counter
  • use dynamic memory allocation instead of static array

License compatibility with mruby

I'm using mruby/c currently in a small proof of concept project and I really appreciate the reduced set of functionality. Yet I have some stuff I would like to take over from mruby but I notice that mruby/c is under BSD in opposite to the mruby's MIT. So merging code from mruby into mruby/c and publish it again is for me (as an uneducated legal person) unclear if there might be problems and consequences.

Is there a specific reason why the BSD license was chosen instead of MIT? If no would it be possible to streamline the license to the mruby one? I saw that at the moment the contributor list seems to be still reasonable small that all contributors could find a common ground, so if there is no strict reason to stay with BSD it would be still a good time to switch.

DISCLAIMER: I'm involved in the mruby project but I do not want to give the impression that I want to strongly push mruby's decision for MIT to this project just for the sake of MIT. I personally do not really care about license issues but I wonder if both projects could benefit from an unified license.

mrb_load_string()

Is the planned function of mrb_load_string() ? (and sometimes mrb_load_file(mrb, f); )

Or the only way is to be external compilation.

opcode

Hello,
I'm not sure. Is it all opcodes ?


opcode

;1;OP_NOP;0x00;
;1;OP_MOVE;0x01;
;1;OP_LOADL;0x02;
;1;OP_LOADI;0x03;
;0;OP_LOADSYM;
;1;OP_LOADNIL;0x05;
;1;OP_LOADSELF;0x06;
;1;OP_LOADT;0x07;
;1;OP_LOADF;0x08;
;1;OP_GETGLOBAL;0x09;
;1;OP_SETGLOBAL;0x0a;
;0;OP_GETSPECIAL;
;0;OP_SETSPECIAL;
;0;OP_GETIV;
;0;OP_SETIV;
;0;OP_GETCV;
;0;OP_SETCV;
;0;OP_GETMCNST;
;0;OP_SETMCNST;
;0;OP_GETUPVAR;
;0;OP_SETUPVAR;
;1;OP_GETCONST;0x11;
;1;OP_SETCONST;0x12;
;1;OP_JMP;0x17;
;1;OP_JMPIF;0x18;
;1;OP_JMPNOT;0x19;
;0;OP_ONERR;
;0;OP_RESCUE;
;0;OP_POPERR;
;0;OP_RAISE;
;0;OP_EPUSH;
;0;OP_EPOP;
;1;OP_SEND;0x20;
;0;OP_SENDB;
;0;OP_FSEND;
;0;OP_CALL;
;0;OP_SUPER;
;0;OP_ARGARY;
;1;OP_ENTER;0x26;
;0;OP_KARG;
;0;OP_KDICT;
;1;OP_RETURN;0x29;
;0;OP_TAILCALL;
;0;OP_BLKPUSH;
;1;OP_ADD;0x2c;
;1;OP_ADDI;0x2d;
;1;OP_SUB;0x2e;
;1;OP_SUBI;0x2f;
;0;OP_MUL;
;0;OP_DIV;
;1;OP_EQ;0x32;
;1;OP_LT;0x33;
;1;OP_LE;0x34;
;1;OP_GT;0x35;
;1;OP_GE;0x36;
;1;OP_ARRAY;0x37;
;0;OP_ARYCAT;
;0;OP_ARYPUSH;
;0;OP_AREF;
;0;OP_ASET;
;0;OP_APOST;
;0;OP_STRING;
;0;OP_STRCAT;
;0;OP_HASH;
;1;OP_LAMBDA;0x40;
;0;OP_RANGE;
;0;OP_OCLASS;
;1;OP_CLASS;0x43;
;0;OP_MODULE;
;0;OP_EXEC;
;1;OP_METHOD;0x46;
;0;OP_SCLASS;
;1;OP_TCLASS;0x48;
;0;OP_DEBUG;
;1;OP_STOP;0x4a;
;0;OP_ERR;
;0;OP_RSVD1;
;0;OP_RSVD2;
;0;OP_RSVD3;
;0;OP_RSVD4;
;0;OP_RSVD5;


array and hash

I read source code.
Is possible to using one Array functions to all arrays in mruby?
in class.c is find_method etc. Is possible to using one array mini lib to whole project?
in wich places are using array and hash ?

Access null pointer and core dumped when call proc object

Environment

  • mruby/c (from lastest master branch)

Detail

I met core dumped when execute these mruby code.

100.times{|i| Arduino.analog_write(4, i * 100) }

Output

Exception (28):
epc1=0x402071c7 epc2=0x00000000 epc3=0x00000000 excvaddr=0x0000000c depc=0x00000000

ctx: cont
sp: 3fff97e0 end: 3fff9e00 offset: 01a0

>>>stack>>>
3fff9980:  3fff45d4 00000000 3fff463c 402071c2
3fff9990:  feefeffe feefeffe feefeffe feefeffe
3fff99a0:  72293328 20736765 7830203d 66666633
3fff99b0:  63303634 6d76202c 63703e2d 6572695f
3fff99c0:  203d2070 66000a30 38356666 000a3831
...
...

I set to output debug info, and watch serial console, and got these info.
I tracked RiteVM code, and I found a point which proc->irep is NULL when op_stop called.

I doubt these points.

  • Is it correct that vm->current_regs no changed at op_abort called?
  • It seems to not propery to restore regs from callstack in op_return.
pc_irep= 0x3fff57d8 pc_irep->code = 0x3fff0b90 pc= 0 current_regs= 0x3fff45ec code = 12595587 reg->proc->irep = 0 opcode = 0x3, A = 0, sBx = 64, Bx = 8063
pc_irep= 0x3fff57d8 pc_irep->code = 0x3fff0b90 pc= 1 current_regs= 0x3fff45ec code = 16777536 reg->proc->irep = 0 opcode = 0x40, A = 0, sBx = ffff8003, Bx = 2
proc->irep = 0x3fff5818 vm->pc_irep->reps[rb] = 0x3fff5818 ra = 2, rb = 0
pc_irep= 0x3fff57d8 pc_irep->code = 0x3fff0b90 pc= 2 current_regs= 0x3fff45ec code = 8388641 reg->proc->irep = 0 opcode = 0x21, A = 4, sBx = ffff8001, Bx = 0

pc_irep= 0x3fff9af0 pc_irep->code = 0x3fff9b0c pc= 0 current_regs= 0x3fff460c code = 35 reg->proc->irep = 0x3fff5818 opcode = 0x23, A = 21, sBx = ffff8001, Bx = 0
(3)regs = 0x3fff460c, vm->pc_irep = 0x3fff5818
pc_irep= 0x3fff5818 pc_irep->code = 0x3fff0bc0 pc= 0 current_regs= 0x3fff460c code = 33554470 reg->proc->irep = 0x3fff5818 opcode = 0x26, A = 0, sBx = ffff8001, Bx = 0
pc_irep= 0x3fff5818 pc_irep->code = 0x3fff0bc0 pc= 1 current_regs= 0x3fff460c code = 25165841 reg->proc->irep = 0x3fff5818 opcode = 0x11, A = 0, sBx = ffff8001, Bx = 0
pc_irep= 0x3fff5818 pc_irep->code = 0x3fff0bc0 pc= 2 current_regs= 0x3fff460c code = 37749123 reg->proc->irep = 0x3fff5818 opcode = 0x3, A = 0, sBx = 4, Bx =
8003
pc_irep= 0x3fff5818 pc_irep->code = 0x3fff0bc0 pc= 3 current_regs= 0x3fff460c code = 41959425 reg->proc->irep = 0x3fff5818 opcode = 0x1, A = 0, sBx = ffff8081, Bx = 80
pc_irep= 0x3fff5818 pc_irep->code = 0x3fff0bc0 pc= 4 current_regs= 0x3fff460c code = 54527107 reg->proc->irep = 0x3fff5818 opcode = 0x3, A = 0, sBx = a, Bx =
8009
pc_irep= 0x3fff5818 pc_irep->code = 0x3fff0bc0 pc= 5 current_regs= 0x3fff460c code = 41975984 reg->proc->irep = 0x3fff5818 opcode = 0x30, A = 4, sBx = ffff8102, Bx = 101
pc_irep= 0x3fff5818 pc_irep->code = 0x3fff0bc0 pc= 6 current_regs= 0x3fff460c code = 25182496 reg->proc->irep = 0x3fff5818 opcode = 0x20, A = 7, sBx = ffff8083, Bx = 82
pc_irep= 0x3fff5818 pc_irep->code = 0x3fff0bc0 pc= 7 current_regs= 0x3fff460c code = 25165865 reg->proc->irep = 0x3fff5818 opcode = 0x29, A = 3, sBx = ffff8001, Bx = 0
(4)vm->pc_irep = 0x3fff9af0
pc_irep= 0x3fff9af0 pc_irep->code = 0x3fff9b0c pc= 1 current_regs= 0x3fff460c code = 80 reg->proc->irep = 0 opcode = 0x50, A = 3, sBx = ffff8001, Bx = 0
pc_irep= 0x3fff9af0 pc_irep->code = 0x3fff9b0c pc= 0 current_regs= 0x3fff460c code = 35 reg->proc->irep = 0 opcode = 0x23, A = 3, sBx = ffff8001, Bx = 0
(3)regs = 0x3fff460c, vm->pc_irep = 0 # <---------access NULL pointer
pc_irep= 0
Exception (28):
epc1=0x402071c7 epc2=0x00000000 epc3=0x00000000 excvaddr=0x0000000c depc=0x00000000

ctx: cont
sp: 3fff97e0 end: 3fff9e00 offset: 01a0

>>>stack>>>
3fff9980:  3fff45d4 00000000 3fff463c 402071c2
3fff9990:  feefeffe feefeffe feefeffe feefeffe
3fff99a0:  72293328 20736765 7830203d 66666633
3fff99b0:  63303634 6d76202c 63703e2d 6572695f
3fff99c0:  203d2070 66000a30 38356666 000a3831
3fff99d0:  feefeffe feefeffe feefeffe feefeffe
3fff99e0:  feefeffe feefeffe feefeffe feefeffe
3fff99f0:  feefeffe feefeffe feefeffe feefeffe
3fff9a00:  00000005 00000000 00000020 40100eb6
3fff9a10:  3ffeaec5 401042bb 3ffee888 feefeffe
3fff9a20:  695f6370 3d706572 00203020 41202c33
3fff9a30:  33203d20 4273202c 203d2078 66666666
3fff9a40:  31303038 7842202c 30203d20 00000a20
3fff9a50:  ffffff00 3fff9b12 3fff9a80 00000100
3fff9a60:  7fffffff 3ffeb764 3ffeb764 3fff9ad0
3fff9a70:  40213538 3fff9b70 3fff9b12 4020f948
3fff9a80:  00000001 00886bcd 00002200 4000050c
3fff9a90:  3ffe8308 00000000 00000010 3ffeaaf7
3fff9aa0:  00000003 00000000 3fff5424 00000000
3fff9ab0:  3fff4bd4 00000023 00000000 ffff8001
3fff9ac0:  00000000 00000000 00000023 3fff460c
3fff9ad0:  00000000 ffffffff ffffffff 00000064
3fff9ae0:  00000001 3fff45fc 3fff45d4 402037cc
3fff9af0:  00000000 00020000 3fff0000 3fff9b0c
3fff9b00:  00000000 00000000 00000000 23000000
3fff9b10:  50000000 feef7878 feefeffe feefeffe
3fff9b20:  3fff461c feefeffe 00000000 00000004
3fff9b30:  00000004 00000000 00000064 01000000
3fff9b40:  00000000 3fff45fc 3fff45d4 40206f55
3fff9b50:  0000001c 3ffe8308 3fff9be0 00010000
3fff9b60:  3fff45d4 00000000 3fff45fc 40210194
3fff9b70:  3fff9cde 00000000 7fffffd1 ffff0208
3fff9b80:  3fff9cb0 7fffffff 3fff9c1f 4020f948
3fff9b90:  00000004 402213db 3ffef29c feefeffe
3fff9ba0:  3ffe8308 00000003 0000000a 3ffeaae6
3fff9bb0:  3fff9c23 0000002d 3fff9cdd 4020e480
3fff9bc0:  3ffeac3a 3ffeac3a 3fff585c 00010000
3fff9bd0:  3fff45d4 00000000 3fff8d08 4020d285
3fff9be0:  00000004 00000000 00000064 00000000
3fff9bf0:  00000010 3fff0baa 3fff45fc 4020d35c
3fff9c00:  ffff8001 00000000 3fff5844 00010000
3fff9c10:  3fff45d4 00000000 3fff45fc 4020752c
3fff9c20:  40103922 40224d3c 3ffef29c 00000012
3fff9c30:  636f7270 72693e2d 3d207065 33783020
3fff9c40:  35666666 20383138 3e2d6d76 695f6370
3fff9c50:  2d706572 7065723e 62725b73 203d205d
3fff9c60:  66337830 38356666 72203831 203d2061
3fff9c70:  72202c32 203d2062 3f000a30 402010b6
3fff9c80:  3fffc278 40101f80 3fff5810 40201416
3fff9c90:  3fff9ca0 0000003f 3ffe97b8 3fff9cd0
3fff9ca0:  3fff57d8 3fff45d4 00000000 40201559
3fff9cb0:  6f63706f 3d206564 32783020 41202c31
3fff9cc0:  34203d20 4273202c 203d2078 66666666
3fff9cd0:  31303038 7842202c 30203d20 40000a20
3fff9ce0:  00000000 3fff45d4 00000000 3fff9d10
3fff9cf0:  3fff57d8 3fff45d4 00000000 3fff9d10
3fff9d00:  3fff57d8 3fff45d4 00000000 40206521
3fff9d10:  4023c69a 3fff9d50 3fff5804 4023c6b1
3fff9d20:  3fffb09c 0028bf8d 3ffea881 4020e480
3fff9d30:  40104b0a 3fff0158 0028bf8d 0000008f
3fff9d40:  3fff4bd4 00000021 00000001 ffff8001
3fff9d50:  00000000 00000010 00800021 3fff45ec
3fff9d60:  3fff0c24 000000c4 4020d9d4 000000c4
3fff9d70:  3fff0b58 3fff8d08 3fff0b54 4020a3a7
3fff9d80:  3fff0b5c 000000c4 00000000 4020a4a9
3fff9d90:  3fffa91c 0000000f 00000000 c40001ff
3fff9da0:  00000000 3fffb0cc 0000000a 3fff8dcc
3fff9db0:  3fffdad0 00000000 3fff8dc5 4020a53e
3fff9dc0:  40106d68 00000000 000003e8 4020a32c
3fff9dd0:  00000000 3fffb0cc 00000001 4020d9f5
3fff9de0:  3fffdad0 00000000 3fff8dc5 4020da20
3fff9df0:  feefeffe feefeffe 3fff8de0 40100700
<<<stack<<<

Please tell me if there is someone good idea.
Thanks.

How creating sample_c/sample1.c file?

$ ./mrbc -v
mruby 1.2.0 (2015-11-17)
$mrbc -Bary -osample01.c ../sample_ruby/basic_sample01.rb
i change header to "const uint8_t ary[]"
$make
$./mrubyc_sample
Error: Illegal bytecode.


meybe in mrubyc/sample_c/Makefile add line
MRUBY_COMPILER = ../../mruby/build/host/bin/mrbc

sample1.c : ../sample_ruby/basic_sample01.rb
MRUBY_COMPILER -Bary [....]

working example on esp

Is possible to create any working example for esp (32 or 6628)
For example i have screen ESP32

  • how writing my own text
  • how creating web server (meybe temp sensor)

normal example, i get device , compiling program, flashing device = working device ;)

support_mruby2 branch

I've add a new branch 'support_mruby2', which is work in progress.
Soon I'll update codes.

We'd like to improve mruby/c for supporting mruby2 in this branch.

Calling mrbc_release when returning C method

I noticed that C extension library was being created.

In the method of the C extension class library, the SET_XXX_VALUE macro is used to specify the return value.

The reference counter is supported after version 1.1, and it is necessary to release self (--ref_count) stored in v[0] before setting the return value.

static void c_hoge(mrb_vm *vm, mrb_value v[], int argc)
{
   mrbc_release(v);    /* I do not want to call this */
   SET_INT_RETURN(0);
}

It is hard for the library developer to call this mrbc_release() call, and if you forget to call, the self's reference counter will continue to increase and become a fatal situation.

I think that calling mrbc_release() should be included in the SET_XXX_RETURN macro.

Please consider it.

NilClass#to_i should be 0

sample code

nil.to_i

expected

0

actual

No method. Class:NilClass Method:to_i

there is a work around though...

class NilClass
  def to_i
    0
  end
end

Cannot return from block

return not works in block.

sample code

def func
  v = nil
  while true
    return 'OK'
    v = 'NG'
    break
  end
  return v
end

puts func

expected

OK

actual

NG

module keyword/support

Is module a feature that would be welcome in the vm? I noticed that it is marked op_unsupported and am curious if this is because it's not wanted because of the design goals of the project (small size, small memory consumption)?

logo

m 💎 c^2

E=m * c^2 but change multiply to symbol ruby
the name of repository /mrubyc2
What You think about this?

void * have no size, meybe change to unsigned char* or other sized pointer?

vm.c: In function ‘find_irep_symbol’:
vm.c:38:5: error: pointer of type ‘void _’ used in arithmetic [-Wpointer-arith]
p += 4;
^
vm.c:41:7: error: pointer of type ‘void *’ used in arithmetic [-Wpointer-arith]
p += 2+s+1; // size(2 bytes) + symbol len + '\0'
^
vm.c:41:5: error: pointer of type ‘void *’ used in arithmetic [-Wpointer-arith]
p += 2+s+1; // size(2 bytes) + symbol len + '\0'
^
vm.c:44:11: error: pointer of type ‘void *’ used in arithmetic [-Wpointer-arith]
return p+2; // skip size(2 bytes)
^
vm.c: In function ‘vm_run_step’:
vm.c:1078:45: error: pointer of type ‘void *’ used in arithmetic [-Wpointer-arith]
uint8_t *p = (uint8_t *)(vm->pc_irep->code+vm->pc_4);

Dynamic memory allocation

I want to start a discussion here about usage of dynamic memory allocation.

According to static.c currently we are allocating ~30Kb statically using config variables provided in vm_config.h.

I suggest to change static memory allocation to dynamic memory allocation so we will use less RAM.
This will require to implement _sbrk function on every platform to use malloc.h functions. The simplest sample (I've created it for TI Tiva-C board) goes below:

extern unsigned long _heap_bottom;
extern unsigned long _heap_top;
char *heap_end = (caddr_t)&_heap_bottom;

caddr_t _sbrk(unsigned int inc) {
  static char *prev_heap_end;
  if (heap_end == 0) {
    heap_end = (caddr_t)&_heap_bottom;
  }
  prev_heap_end = heap_end;
  if (heap_end + inc > (caddr_t)&_heap_top) {
    return (caddr_t)0;
  }
  heap_end += inc;
  return (caddr_t)prev_heap_end;
}

_heap_bottom and _heap_top are segments from ld script for this board (you can take a look on it here).

This will also require to implement simple GC to free memory if it's needed. Anyhow, now memory consumption is on it's max level.

What do you think?

doc 'How compile'

  • in /sample_c is more than thre exacutables and any not named mrubyc

  • no file basic_*.mrb in any directory

Support for nested class

Because of the lack of Module, we can use nested class to do some "similar" things.

For example:

class WifiToolkit
  class ConnectionMaker
  end
end

print WifiToolkit::ConnectionMaker # Should recgonize it

Change MRB_TT_XX values

To distinguish between primitive type and non primitive type, change MRB_TT_XXX values.
This change cause no influences to other codes, this change aims to support new features.

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.