webruby 0.2.5 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/lib/webruby.rb +0 -4
  3. data/lib/webruby/app.rb +4 -0
  4. data/lib/webruby/rake/files.rake +2 -1
  5. data/lib/webruby/rake/mruby.rake +1 -1
  6. data/modules/emscripten/AUTHORS +1 -0
  7. data/modules/emscripten/ChangeLog +34 -1
  8. data/modules/emscripten/cmake/Platform/Emscripten.cmake +30 -9
  9. data/modules/emscripten/emcc +61 -28
  10. data/modules/emscripten/emrun +15 -11
  11. data/modules/emscripten/emscripten.py +3 -0
  12. data/modules/emscripten/src/closure-externs.js +110 -0
  13. data/modules/emscripten/src/intertyper.js +1 -1
  14. data/modules/emscripten/src/jsifier.js +7 -21
  15. data/modules/emscripten/src/library.js +2 -1
  16. data/modules/emscripten/src/library_browser.js +16 -5
  17. data/modules/emscripten/src/library_fs.js +3 -1
  18. data/modules/emscripten/src/library_gl.js +691 -591
  19. data/modules/emscripten/src/library_glut.js +2 -0
  20. data/modules/emscripten/src/library_sdl.js +29 -5
  21. data/modules/emscripten/src/library_uuid.js +140 -0
  22. data/modules/emscripten/src/modules.js +1 -1
  23. data/modules/emscripten/src/parseTools.js +29 -19
  24. data/modules/emscripten/src/postamble.js +3 -4
  25. data/modules/emscripten/src/preamble.js +17 -1
  26. data/modules/emscripten/src/relooper/Relooper.cpp +8 -8
  27. data/modules/emscripten/src/relooper/Relooper.h +5 -5
  28. data/modules/emscripten/src/relooper/test.txt +2 -2
  29. data/modules/emscripten/src/runtime.js +1 -1
  30. data/modules/emscripten/src/settings.js +3 -0
  31. data/modules/emscripten/src/struct_info.json +12 -0
  32. data/modules/emscripten/system/include/uuid/uuid.h +35 -0
  33. data/modules/emscripten/tools/js-optimizer.js +191 -142
  34. data/modules/emscripten/tools/js_optimizer.py +3 -29
  35. data/modules/emscripten/tools/shared.py +43 -6
  36. data/modules/mruby/include/mruby/value.h +3 -2
  37. data/modules/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c +5 -9
  38. data/modules/mruby/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c +3 -5
  39. data/modules/mruby/mrbgems/mruby-hash-ext/src/hash-ext.c +0 -3
  40. data/modules/mruby/mrbgems/mruby-numeric-ext/src/numeric_ext.c +0 -1
  41. data/modules/mruby/mrbgems/mruby-random/src/mt19937ar.c +0 -1
  42. data/modules/mruby/mrbgems/mruby-range-ext/src/range.c +2 -6
  43. data/modules/mruby/mrbgems/mruby-sprintf/src/sprintf.c +0 -4
  44. data/modules/mruby/mrbgems/mruby-string-ext/mrblib/string.rb +22 -0
  45. data/modules/mruby/mrbgems/mruby-string-ext/src/string.c +2 -2
  46. data/modules/mruby/mrbgems/mruby-string-ext/test/string.rb +21 -2
  47. data/modules/mruby/mrbgems/mruby-string-utf8/mrbgem.rake +4 -0
  48. data/modules/mruby/mrbgems/mruby-string-utf8/src/string.c +297 -0
  49. data/modules/mruby/mrbgems/mruby-string-utf8/test/string.rb +27 -0
  50. data/modules/mruby/mrbgems/mruby-struct/src/struct.c +0 -1
  51. data/modules/mruby/mrblib/init_mrblib.c +0 -3
  52. data/modules/mruby/src/array.c +22 -8
  53. data/modules/mruby/src/backtrace.c +12 -9
  54. data/modules/mruby/src/class.c +3 -3
  55. data/modules/mruby/src/codegen.c +17 -5
  56. data/modules/mruby/src/dump.c +5 -6
  57. data/modules/mruby/src/error.c +0 -2
  58. data/modules/mruby/src/etc.c +0 -2
  59. data/modules/mruby/src/gc.c +4 -8
  60. data/modules/mruby/src/load.c +1 -6
  61. data/modules/mruby/src/numeric.c +0 -6
  62. data/modules/mruby/src/object.c +3 -5
  63. data/modules/mruby/src/parse.y +37 -38
  64. data/modules/mruby/src/proc.c +8 -1
  65. data/modules/mruby/src/range.c +3 -7
  66. data/modules/mruby/src/state.c +0 -1
  67. data/modules/mruby/src/string.c +2 -17
  68. data/modules/mruby/src/symbol.c +0 -1
  69. data/modules/mruby/src/variable.c +3 -22
  70. data/modules/mruby/src/vm.c +9 -8
  71. data/modules/mruby/tasks/mrbgem_spec.rake +13 -5
  72. data/modules/mruby/tasks/mrbgems_test.rake +3 -3
  73. data/modules/mruby/tasks/mruby_build_commands.rake +2 -2
  74. data/modules/mruby/tasks/mruby_build_gem.rake +3 -3
  75. data/modules/mruby/test/init_mrbtest.c +0 -3
  76. data/modules/mruby/test/t/array.rb +12 -1
  77. data/modules/mruby/test/t/class.rb +67 -0
  78. data/modules/mruby/test/t/exception.rb +12 -0
  79. data/modules/mruby/test/t/kernel.rb +75 -1
  80. data/modules/mruby/test/t/syntax.rb +115 -0
  81. data/scripts/gen_require.rb +12 -1
  82. metadata +8 -2
@@ -0,0 +1,27 @@
1
+ ##
2
+ # String(utf8) Test
3
+
4
+ assert('String#[]') do
5
+ assert_equal "ち", "こんにちわ世界"[3]
6
+ assert_equal nil, "こんにちわ世界"[20]
7
+ assert_equal "世", "こんにちわ世界"[-2]
8
+ assert_equal "世界", "こんにちわ世界"[-2..-1]
9
+ assert_equal "んに", "こんにちわ世界"[1,2]
10
+ assert_equal "世", "こんにちわ世界"["世"]
11
+ end
12
+
13
+ assert('String#reverse', '15.2.10.5.29') do
14
+ a = 'こんにちわ世界!'
15
+ a.reverse
16
+
17
+ assert_equal 'こんにちわ世界!', a
18
+ assert_equal '!界世わちにんこ', 'こんにちわ世界!'.reverse
19
+ end
20
+
21
+ assert('String#reverse!', '15.2.10.5.30') do
22
+ a = 'こんにちわ世界!'
23
+ a.reverse!
24
+
25
+ assert_equal '!界世わちにんこ', a
26
+ assert_equal '!界世わちにんこ', 'こんにちわ世界!'.reverse!
27
+ end
@@ -10,7 +10,6 @@
10
10
  #include "mruby/array.h"
11
11
  #include "mruby/string.h"
12
12
  #include "mruby/class.h"
13
- #include "mruby/data.h"
14
13
  #include "mruby/variable.h"
15
14
 
16
15
  #define RSTRUCT_ARY(st) mrb_ary_ptr(st)
@@ -1,8 +1,5 @@
1
1
  #include "mruby.h"
2
2
  #include "mruby/irep.h"
3
- #include "mruby/dump.h"
4
- #include "mruby/string.h"
5
- #include "mruby/proc.h"
6
3
 
7
4
  extern const uint8_t mrblib_irep[];
8
5
 
@@ -4,12 +4,6 @@
4
4
  ** See Copyright Notice in mruby.h
5
5
  */
6
6
 
7
- #ifndef SIZE_MAX
8
- /* Some versions of VC++
9
- * has SIZE_MAX in stdint.h
10
- */
11
- # include <limits.h>
12
- #endif
13
7
  #include "mruby.h"
14
8
  #include "mruby/array.h"
15
9
  #include "mruby/class.h"
@@ -318,7 +312,7 @@ mrb_ary_cmp(mrb_state *mrb, mrb_value ary1)
318
312
  for (i=0; i<len; i++) {
319
313
  mrb_value v = ary_elt(ary2, i);
320
314
  r = mrb_funcall_argv(mrb, ary_elt(ary1, i), cmp, 1, &v);
321
- if (mrb_type(r) != MRB_TT_FIXNUM || mrb_fixnum(r) != 0) return r;
315
+ if (!mrb_fixnum_p(r) || mrb_fixnum(r) != 0) return r;
322
316
  }
323
317
  }
324
318
  len = a1->len - a2->len;
@@ -697,7 +691,7 @@ mrb_ary_aget(mrb_state *mrb, mrb_value self)
697
691
  return mrb_ary_ref(mrb, self, index);
698
692
 
699
693
  case 1:
700
- if (mrb_type(argv[0]) != MRB_TT_FIXNUM) {
694
+ if (!mrb_fixnum_p(argv[0])) {
701
695
  mrb_raise(mrb, E_TYPE_ERROR, "expected Fixnum");
702
696
  }
703
697
  if (index < 0) index += a->len;
@@ -854,6 +848,9 @@ mrb_ary_splat(mrb_state *mrb, mrb_value v)
854
848
  if (mrb_array_p(v)) {
855
849
  return v;
856
850
  }
851
+ if (mrb_respond_to(mrb, v, mrb_intern_lit(mrb, "to_a"))) {
852
+ return mrb_funcall(mrb, v, "to_a", 0);
853
+ }
857
854
  else {
858
855
  return mrb_ary_new_from_values(mrb, 1, &v);
859
856
  }
@@ -1113,6 +1110,22 @@ mrb_ary_eql(mrb_state *mrb, mrb_value ary1)
1113
1110
  return mrb_true_value();
1114
1111
  }
1115
1112
 
1113
+ static mrb_value
1114
+ mrb_ary_ceqq(mrb_state *mrb, mrb_value ary)
1115
+ {
1116
+ mrb_value v;
1117
+ mrb_int i, len;
1118
+ mrb_sym eqq = mrb_intern_lit(mrb, "===");
1119
+
1120
+ mrb_get_args(mrb, "o", &v);
1121
+ len = RARRAY_LEN(ary);
1122
+ for (i=0; i<len; i++) {
1123
+ mrb_value c = mrb_funcall_argv(mrb, ary_elt(ary, i), eqq, 1, &v);
1124
+ if (mrb_test(c)) return mrb_true_value();
1125
+ }
1126
+ return mrb_false_value();
1127
+ }
1128
+
1116
1129
  void
1117
1130
  mrb_init_array(mrb_state *mrb)
1118
1131
  {
@@ -1155,4 +1168,5 @@ mrb_init_array(mrb_state *mrb)
1155
1168
  mrb_define_method(mrb, a, "==", mrb_ary_equal, MRB_ARGS_REQ(1)); /* 15.2.12.5.33 (x) */
1156
1169
  mrb_define_method(mrb, a, "eql?", mrb_ary_eql, MRB_ARGS_REQ(1)); /* 15.2.12.5.34 (x) */
1157
1170
  mrb_define_method(mrb, a, "<=>", mrb_ary_cmp, MRB_ARGS_REQ(1)); /* 15.2.12.5.36 (x) */
1171
+ mrb_define_method(mrb, a, "__case_eqq", mrb_ary_ceqq, MRB_ARGS_REQ(1)); /* internal */
1158
1172
  }
@@ -4,6 +4,7 @@
4
4
  ** See Copyright Notice in mruby.h
5
5
  */
6
6
 
7
+ #include <stdarg.h>
7
8
  #include "mruby.h"
8
9
  #include "mruby/variable.h"
9
10
  #include "mruby/proc.h"
@@ -11,7 +12,6 @@
11
12
  #include "mruby/string.h"
12
13
  #include "mruby/class.h"
13
14
  #include "mruby/debug.h"
14
- #include <stdarg.h>
15
15
 
16
16
  typedef void (*output_stream_func)(mrb_state*, void*, int, const char*, ...);
17
17
 
@@ -62,9 +62,8 @@ mrb_output_backtrace(mrb_state *mrb, struct RObject *exc, output_stream_func fun
62
62
  mrb_callinfo *ci;
63
63
  mrb_int ciidx;
64
64
  const char *filename, *method, *sep;
65
- int i, line;
65
+ int i, lineno, tracehead = 1;
66
66
 
67
- func(mrb, stream, 1, "trace:\n");
68
67
  ciidx = mrb_fixnum(mrb_obj_iv_get(mrb, exc, mrb_intern_lit(mrb, "ciidx")));
69
68
  if (ciidx >= mrb->c->ciend - mrb->c->cibase)
70
69
  ciidx = 10; /* ciidx is broken... */
@@ -72,7 +71,7 @@ mrb_output_backtrace(mrb_state *mrb, struct RObject *exc, output_stream_func fun
72
71
  for (i = ciidx; i >= 0; i--) {
73
72
  ci = &mrb->c->cibase[i];
74
73
  filename = NULL;
75
- line = -1;
74
+ lineno = -1;
76
75
 
77
76
  if (MRB_PROC_CFUNC_P(ci->proc)) {
78
77
  continue;
@@ -91,9 +90,9 @@ mrb_output_backtrace(mrb_state *mrb, struct RObject *exc, output_stream_func fun
91
90
  pc = (mrb_code*)mrb_cptr(mrb_obj_iv_get(mrb, exc, mrb_intern_lit(mrb, "lastpc")));
92
91
  }
93
92
  filename = mrb_debug_get_filename(irep, pc - irep->iseq);
94
- line = mrb_debug_get_line(irep, pc - irep->iseq);
93
+ lineno = mrb_debug_get_line(irep, pc - irep->iseq);
95
94
  }
96
- if (line == -1) continue;
95
+ if (lineno == -1) continue;
97
96
  if (ci->target_class == ci->proc->target_class)
98
97
  sep = ".";
99
98
  else
@@ -103,24 +102,28 @@ mrb_output_backtrace(mrb_state *mrb, struct RObject *exc, output_stream_func fun
103
102
  filename = "(unknown)";
104
103
  }
105
104
 
105
+ if (tracehead) {
106
+ func(mrb, stream, 1, "trace:\n");
107
+ tracehead = 0;
108
+ }
106
109
  method = mrb_sym2name(mrb, ci->mid);
107
110
  if (method) {
108
111
  const char *cn = mrb_class_name(mrb, ci->proc->target_class);
109
112
 
110
113
  if (cn) {
111
114
  func(mrb, stream, 1, "\t[%d] ", i);
112
- func(mrb, stream, 0, "%s:%d:in %s%s%s", filename, line, cn, sep, method);
115
+ func(mrb, stream, 0, "%s:%d:in %s%s%s", filename, lineno, cn, sep, method);
113
116
  func(mrb, stream, 1, "\n");
114
117
  }
115
118
  else {
116
119
  func(mrb, stream, 1, "\t[%d] ", i);
117
- func(mrb, stream, 0, "%s:%d:in %s", filename, line, method);
120
+ func(mrb, stream, 0, "%s:%d:in %s", filename, lineno, method);
118
121
  func(mrb, stream, 1, "\n");
119
122
  }
120
123
  }
121
124
  else {
122
125
  func(mrb, stream, 1, "\t[%d] ", i);
123
- func(mrb, stream, 0, "%s:%d", filename, line);
126
+ func(mrb, stream, 0, "%s:%d", filename, lineno);
124
127
  func(mrb, stream, 1, "\n");
125
128
  }
126
129
  }
@@ -4,9 +4,9 @@
4
4
  ** See Copyright Notice in mruby.h
5
5
  */
6
6
 
7
- #include "mruby.h"
8
- #include <stdarg.h>
9
7
  #include <ctype.h>
8
+ #include <stdarg.h>
9
+ #include "mruby.h"
10
10
  #include "mruby/array.h"
11
11
  #include "mruby/class.h"
12
12
  #include "mruby/numeric.h"
@@ -522,7 +522,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
522
522
  s = mrb_str_ptr(ss);
523
523
  len = (mrb_int)strlen(s->ptr);
524
524
  if (len < s->len) {
525
- mrb_raise(mrb, E_ARGUMENT_ERROR, "String contains NUL");
525
+ mrb_raise(mrb, E_ARGUMENT_ERROR, "string contains null byte");
526
526
  }
527
527
  else if (len > s->len) {
528
528
  mrb_str_modify(mrb, s);
@@ -421,7 +421,7 @@ new_lit(codegen_scope *s, mrb_value val)
421
421
  case MRB_TT_FIXNUM:
422
422
  for (i=0; i<s->irep->plen; i++) {
423
423
  pv = &s->irep->pool[i];
424
- if (mrb_type(*pv) != MRB_TT_FIXNUM) continue;
424
+ if (!mrb_fixnum_p(*pv)) continue;
425
425
  if (mrb_fixnum(*pv) == mrb_fixnum(val)) return i;
426
426
  }
427
427
  break;
@@ -661,7 +661,7 @@ scope_body(codegen_scope *s, node *tree, int val)
661
661
  {
662
662
  codegen_scope *scope = scope_new(s->mrb, s, tree->car);
663
663
 
664
- codegen(scope, tree->cdr, val);
664
+ codegen(scope, tree->cdr, VAL);
665
665
  if (!s->iseq) {
666
666
  genop(scope, MKOP_A(OP_STOP, 0));
667
667
  }
@@ -1386,7 +1386,12 @@ codegen(codegen_scope *s, node *tree, int val)
1386
1386
  if (head) {
1387
1387
  genop(s, MKOP_AB(OP_MOVE, cursp(), head));
1388
1388
  pop();
1389
- genop(s, MKOP_ABC(OP_SEND, cursp(), new_msym(s, mrb_intern_lit(s->mrb, "===")), 1));
1389
+ if ((intptr_t)n->car->car == NODE_SPLAT) {
1390
+ genop(s, MKOP_ABC(OP_SEND, cursp(), new_msym(s, mrb_intern_lit(s->mrb, "__case_eqq")), 1));
1391
+ }
1392
+ else {
1393
+ genop(s, MKOP_ABC(OP_SEND, cursp(), new_msym(s, mrb_intern_lit(s->mrb, "===")), 1));
1394
+ }
1390
1395
  }
1391
1396
  else {
1392
1397
  pop();
@@ -1510,7 +1515,14 @@ codegen(codegen_scope *s, node *tree, int val)
1510
1515
  break;
1511
1516
 
1512
1517
  case NODE_SPLAT:
1513
- codegen(s, tree, VAL);
1518
+ {
1519
+ int idx = new_msym(s, mrb_intern_lit(s->mrb, "to_a"));
1520
+
1521
+ codegen(s, tree, VAL);
1522
+ pop();
1523
+ genop(s, MKOP_ABC(OP_SEND, cursp(), idx, 0));
1524
+ push();
1525
+ }
1514
1526
  break;
1515
1527
 
1516
1528
  case NODE_ASGN:
@@ -2895,7 +2907,7 @@ codedump_recur(mrb_state *mrb, mrb_irep *irep)
2895
2907
  void
2896
2908
  codedump_all(mrb_state *mrb, struct RProc *proc)
2897
2909
  {
2898
- return codedump_recur(mrb, proc->body.irep);
2910
+ codedump_recur(mrb, proc->body.irep);
2899
2911
  }
2900
2912
 
2901
2913
  struct RProc*
@@ -4,10 +4,9 @@
4
4
  ** See Copyright Notice in mruby.h
5
5
  */
6
6
 
7
+ #include <ctype.h>
7
8
  #include <string.h>
8
9
  #include "mruby/dump.h"
9
- #include <ctype.h>
10
-
11
10
  #include "mruby/string.h"
12
11
  #include "mruby/irep.h"
13
12
  #include "mruby/numeric.h"
@@ -595,6 +594,9 @@ write_filename_table(mrb_state *mrb, mrb_irep *irep, uint8_t **cp, mrb_sym **fp,
595
594
 
596
595
  size += sizeof(uint16_t) + fn_len;
597
596
  }
597
+ for (file_i=0; file_i<irep->rlen; file_i++) {
598
+ size += write_filename_table(mrb, irep->reps[file_i], &cur, fp, lp);
599
+ }
598
600
  *cp = cur;
599
601
  return size;
600
602
  }
@@ -606,7 +608,7 @@ write_section_debug(mrb_state *mrb, mrb_irep *irep, uint8_t *cur)
606
608
  const uint8_t *bin = cur;
607
609
  struct rite_section_debug_header *header;
608
610
  mrb_sym *filenames;
609
- size_t filenames_len = 0, i;
611
+ size_t filenames_len = 0;
610
612
  uint8_t *filenames_len_out;
611
613
  uint32_t dlen;
612
614
 
@@ -624,9 +626,6 @@ write_section_debug(mrb_state *mrb, mrb_irep *irep, uint8_t *cur)
624
626
  cur += sizeof(uint16_t);
625
627
  section_size += sizeof(uint16_t);
626
628
  section_size += write_filename_table(mrb, irep, &cur, &filenames, &filenames_len);
627
- for (i=0; i<irep->rlen; i++) {
628
- section_size += write_filename_table(mrb, irep->reps[i], &cur, &filenames, &filenames_len);
629
- }
630
629
  uint16_to_bin(filenames_len, filenames_len_out);
631
630
 
632
631
  // debug records
@@ -7,10 +7,8 @@
7
7
  #include <errno.h>
8
8
  #include <stdarg.h>
9
9
  #include <stdlib.h>
10
- #include <string.h>
11
10
  #include "mruby.h"
12
11
  #include "mruby/array.h"
13
- #include "mruby/class.h"
14
12
  #include "mruby/irep.h"
15
13
  #include "mruby/proc.h"
16
14
  #include "mruby/string.h"
@@ -6,8 +6,6 @@
6
6
 
7
7
  #include "mruby.h"
8
8
  #include "mruby/string.h"
9
- #include "error.h"
10
- #include "mruby/numeric.h"
11
9
  #include "mruby/data.h"
12
10
  #include "mruby/class.h"
13
11
 
@@ -4,12 +4,6 @@
4
4
  ** See Copyright Notice in mruby.h
5
5
  */
6
6
 
7
- #ifndef SIZE_MAX
8
- /* Some versions of VC++
9
- * has SIZE_MAX in stdint.h
10
- */
11
- # include <limits.h>
12
- #endif
13
7
  #include <string.h>
14
8
  #include <stdlib.h>
15
9
  #include "mruby.h"
@@ -370,17 +364,19 @@ mrb_free_heap(mrb_state *mrb)
370
364
  static void
371
365
  gc_protect(mrb_state *mrb, struct RBasic *p)
372
366
  {
373
- if (mrb->arena_idx >= MRB_GC_ARENA_SIZE) {
374
367
  #ifdef MRB_GC_FIXED_ARENA
368
+ if (mrb->arena_idx >= MRB_GC_ARENA_SIZE) {
375
369
  /* arena overflow error */
376
370
  mrb->arena_idx = MRB_GC_ARENA_SIZE - 4; /* force room in arena */
377
371
  mrb_raise(mrb, E_RUNTIME_ERROR, "arena overflow error");
372
+ }
378
373
  #else
374
+ if (mrb->arena_idx >= mrb->arena_capa) {
379
375
  /* extend arena */
380
376
  mrb->arena_capa *= 1.5;
381
377
  mrb->arena = (struct RBasic**)mrb_realloc(mrb, mrb->arena, sizeof(struct RBasic*)*mrb->arena_capa);
382
- #endif
383
378
  }
379
+ #endif
384
380
  mrb->arena[mrb->arena_idx++] = p;
385
381
  }
386
382
 
@@ -4,12 +4,7 @@
4
4
  ** See Copyright Notice in mruby.h
5
5
  */
6
6
 
7
- #ifndef SIZE_MAX
8
- /* Some versions of VC++
9
- * has SIZE_MAX in stdint.h
10
- */
11
- # include <limits.h>
12
- #endif
7
+ #include <limits.h>
13
8
  #include <stdlib.h>
14
9
  #include <string.h>
15
10
  #include "mruby/dump.h"
@@ -5,12 +5,6 @@
5
5
  */
6
6
 
7
7
  #include <float.h>
8
- #if defined(__FreeBSD__) && __FreeBSD__ < 4
9
- # include <floatingpoint.h>
10
- #endif
11
- #ifdef HAVE_IEEEFP_H
12
- # include <ieeefp.h>
13
- #endif
14
8
  #include <limits.h>
15
9
  #include <math.h>
16
10
  #include <stdlib.h>
@@ -5,11 +5,9 @@
5
5
  */
6
6
 
7
7
  #include "mruby.h"
8
- #include "mruby/array.h"
9
8
  #include "mruby/class.h"
10
9
  #include "mruby/numeric.h"
11
10
  #include "mruby/string.h"
12
- #include "error.h"
13
11
 
14
12
  mrb_bool
15
13
  mrb_obj_eq(mrb_state *mrb, mrb_value v1, mrb_value v2)
@@ -326,9 +324,9 @@ mrb_check_to_integer(mrb_state *mrb, mrb_value val, const char *method)
326
324
  {
327
325
  mrb_value v;
328
326
 
329
- if (mrb_type(val) == MRB_TT_FIXNUM) return val;
327
+ if (mrb_fixnum_p(val)) return val;
330
328
  v = convert_type(mrb, val, "Integer", method, FALSE);
331
- if (mrb_nil_p(v) || mrb_type(v) != MRB_TT_FIXNUM) {
329
+ if (mrb_nil_p(v) || !mrb_fixnum_p(v)) {
332
330
  return mrb_nil_value();
333
331
  }
334
332
  return v;
@@ -404,7 +402,7 @@ mrb_check_type(mrb_state *mrb, mrb_value x, enum mrb_vtype t)
404
402
  if (mrb_nil_p(x)) {
405
403
  etype = "nil";
406
404
  }
407
- else if (mrb_type(x) == MRB_TT_FIXNUM) {
405
+ else if (mrb_fixnum_p(x)) {
408
406
  etype = "Fixnum";
409
407
  }
410
408
  else if (mrb_type(x) == MRB_TT_SYMBOL) {
@@ -3335,13 +3335,9 @@ nextc(parser_state *p)
3335
3335
  eof:
3336
3336
  if (!p->cxt) return -1;
3337
3337
  else {
3338
- mrbc_context *cxt = p->cxt;
3339
-
3340
- if (cxt->partial_hook(p) < 0) return -1;
3341
- c = '\n';
3342
- p->lineno = 1;
3343
- p->cxt = cxt;
3344
- return c;
3338
+ if (p->cxt->partial_hook(p) < 0)
3339
+ return -1;
3340
+ return -2;
3345
3341
  }
3346
3342
  }
3347
3343
 
@@ -3560,7 +3556,7 @@ read_escape(parser_state *p)
3560
3556
  buf[0] = c;
3561
3557
  for (i=1; i<3; i++) {
3562
3558
  buf[i] = nextc(p);
3563
- if (buf[i] == -1) goto eof;
3559
+ if (buf[i] < 0) goto eof;
3564
3560
  if (buf[i] < '0' || '7' < buf[i]) {
3565
3561
  pushback(p, buf[i]);
3566
3562
  break;
@@ -3577,7 +3573,7 @@ read_escape(parser_state *p)
3577
3573
 
3578
3574
  for (i=0; i<2; i++) {
3579
3575
  buf[i] = nextc(p);
3580
- if (buf[i] == -1) goto eof;
3576
+ if (buf[i] < 0) goto eof;
3581
3577
  if (!ISXDIGIT(buf[i])) {
3582
3578
  pushback(p, buf[i]);
3583
3579
  break;
@@ -3606,7 +3602,7 @@ read_escape(parser_state *p)
3606
3602
  if ((c = nextc(p)) == '\\') {
3607
3603
  return read_escape(p) | 0x80;
3608
3604
  }
3609
- else if (c == -1) goto eof;
3605
+ else if (c < 0) goto eof;
3610
3606
  else {
3611
3607
  return ((c & 0xff) | 0x80);
3612
3608
  }
@@ -3623,11 +3619,12 @@ read_escape(parser_state *p)
3623
3619
  }
3624
3620
  else if (c == '?')
3625
3621
  return 0177;
3626
- else if (c == -1) goto eof;
3622
+ else if (c < 0) goto eof;
3627
3623
  return c & 0x9f;
3628
3624
 
3629
3625
  eof:
3630
3626
  case -1:
3627
+ case -2:
3631
3628
  yyerror(p, "Invalid escape character syntax");
3632
3629
  return '\0';
3633
3630
 
@@ -3649,7 +3646,7 @@ parse_string(parser_state *p)
3649
3646
 
3650
3647
  newtok(p);
3651
3648
  while ((c = nextc(p)) != end || nest_level != 0) {
3652
- if (hinf && (c == '\n' || c == -1)) {
3649
+ if (hinf && (c == '\n' || c < 0)) {
3653
3650
  int line_head;
3654
3651
  tokadd(p, '\n');
3655
3652
  tokfix(p);
@@ -3671,7 +3668,7 @@ parse_string(parser_state *p)
3671
3668
  return tHEREDOC_END;
3672
3669
  }
3673
3670
  }
3674
- if (c == -1) {
3671
+ if (c < 0) {
3675
3672
  char buf[256];
3676
3673
  snprintf(buf, sizeof(buf), "can't find heredoc delimiter \"%s\" anywhere before EOF", hinf->term);
3677
3674
  yyerror(p, buf);
@@ -3680,7 +3677,7 @@ parse_string(parser_state *p)
3680
3677
  yylval.nd = new_str(p, tok(p), toklen(p));
3681
3678
  return tHD_STRING_MID;
3682
3679
  }
3683
- if (c == -1) {
3680
+ if (c < 0) {
3684
3681
  yyerror(p, "unterminated string meets end of file");
3685
3682
  return 0;
3686
3683
  }
@@ -3706,7 +3703,7 @@ parse_string(parser_state *p)
3706
3703
  else {
3707
3704
  if (type & STR_FUNC_REGEXP) {
3708
3705
  tokadd(p, '\\');
3709
- if (c != -1)
3706
+ if (c >= 0)
3710
3707
  tokadd(p, c);
3711
3708
  } else {
3712
3709
  pushback(p, c);
@@ -3796,7 +3793,7 @@ parse_string(parser_state *p)
3796
3793
  char *dup;
3797
3794
 
3798
3795
  newtok(p);
3799
- while (c = nextc(p), c != -1 && ISALPHA(c)) {
3796
+ while (c = nextc(p), c >= 0 && ISALPHA(c)) {
3800
3797
  switch (c) {
3801
3798
  case 'i': f |= 1; break;
3802
3799
  case 'x': f |= 2; break;
@@ -3855,19 +3852,19 @@ heredoc_identifier(parser_state *p)
3855
3852
  if (c == '\'')
3856
3853
  quote = TRUE;
3857
3854
  newtok(p);
3858
- while ((c = nextc(p)) != -1 && c != term) {
3855
+ while ((c = nextc(p)) >= 0 && c != term) {
3859
3856
  if (c == '\n') {
3860
3857
  c = -1;
3861
3858
  break;
3862
3859
  }
3863
3860
  tokadd(p, c);
3864
3861
  }
3865
- if (c == -1) {
3862
+ if (c < 0) {
3866
3863
  yyerror(p, "unterminated here document identifier");
3867
3864
  return 0;
3868
3865
  }
3869
3866
  } else {
3870
- if (c == -1) {
3867
+ if (c < 0) {
3871
3868
  return 0; /* missing here document identifier */
3872
3869
  }
3873
3870
  if (! identchar(c)) {
@@ -3878,7 +3875,7 @@ heredoc_identifier(parser_state *p)
3878
3875
  newtok(p);
3879
3876
  do {
3880
3877
  tokadd(p, c);
3881
- } while ((c = nextc(p)) != -1 && identchar(c));
3878
+ } while ((c = nextc(p)) >= 0 && identchar(c));
3882
3879
  pushback(p, c);
3883
3880
  }
3884
3881
  tokfix(p);
@@ -3948,6 +3945,7 @@ parser_yylex(parser_state *p)
3948
3945
  case '#': /* it's a comment */
3949
3946
  skip(p, '\n');
3950
3947
  /* fall through */
3948
+ case -2: /* end of partial script. */
3951
3949
  case '\n':
3952
3950
  maybe_heredoc:
3953
3951
  heredoc_treat_nextline(p);
@@ -3982,6 +3980,7 @@ parser_yylex(parser_state *p)
3982
3980
  goto retry;
3983
3981
  }
3984
3982
  case -1: /* EOF */
3983
+ case -2: /* end of partial script */
3985
3984
  goto normal_newline;
3986
3985
  default:
3987
3986
  pushback(p, c);
@@ -4165,7 +4164,7 @@ parser_yylex(parser_state *p)
4165
4164
  return '?';
4166
4165
  }
4167
4166
  c = nextc(p);
4168
- if (c == -1) {
4167
+ if (c < 0) {
4169
4168
  yyerror(p, "incomplete character syntax");
4170
4169
  return 0;
4171
4170
  }
@@ -4313,7 +4312,7 @@ parser_yylex(parser_state *p)
4313
4312
  if (IS_BEG() || (IS_SPCARG(c) && arg_ambiguous(p))) {
4314
4313
  p->lstate = EXPR_BEG;
4315
4314
  pushback(p, c);
4316
- if (c != -1 && ISDIGIT(c)) {
4315
+ if (c >= 0 && ISDIGIT(c)) {
4317
4316
  c = '+';
4318
4317
  goto start_num;
4319
4318
  }
@@ -4345,7 +4344,7 @@ parser_yylex(parser_state *p)
4345
4344
  if (IS_BEG() || (IS_SPCARG(c) && arg_ambiguous(p))) {
4346
4345
  p->lstate = EXPR_BEG;
4347
4346
  pushback(p, c);
4348
- if (c != -1 && ISDIGIT(c)) {
4347
+ if (c >= 0 && ISDIGIT(c)) {
4349
4348
  return tUMINUS_NUM;
4350
4349
  }
4351
4350
  return tUMINUS;
@@ -4364,7 +4363,7 @@ parser_yylex(parser_state *p)
4364
4363
  return tDOT2;
4365
4364
  }
4366
4365
  pushback(p, c);
4367
- if (c != -1 && ISDIGIT(c)) {
4366
+ if (c >= 0 && ISDIGIT(c)) {
4368
4367
  yyerror(p, "no .<digit> floating literal anymore; put 0 before dot");
4369
4368
  }
4370
4369
  p->lstate = EXPR_DOT;
@@ -4390,7 +4389,7 @@ parser_yylex(parser_state *p)
4390
4389
  if (c == 'x' || c == 'X') {
4391
4390
  /* hexadecimal */
4392
4391
  c = nextc(p);
4393
- if (c != -1 && ISXDIGIT(c)) {
4392
+ if (c >= 0 && ISXDIGIT(c)) {
4394
4393
  do {
4395
4394
  if (c == '_') {
4396
4395
  if (nondigit) break;
@@ -4400,7 +4399,7 @@ parser_yylex(parser_state *p)
4400
4399
  if (!ISXDIGIT(c)) break;
4401
4400
  nondigit = 0;
4402
4401
  tokadd(p, tolower(c));
4403
- } while ((c = nextc(p)) != -1);
4402
+ } while ((c = nextc(p)) >= 0);
4404
4403
  }
4405
4404
  pushback(p, c);
4406
4405
  tokfix(p);
@@ -4424,7 +4423,7 @@ parser_yylex(parser_state *p)
4424
4423
  if (c != '0' && c != '1') break;
4425
4424
  nondigit = 0;
4426
4425
  tokadd(p, c);
4427
- } while ((c = nextc(p)) != -1);
4426
+ } while ((c = nextc(p)) >= 0);
4428
4427
  }
4429
4428
  pushback(p, c);
4430
4429
  tokfix(p);
@@ -4438,7 +4437,7 @@ parser_yylex(parser_state *p)
4438
4437
  if (c == 'd' || c == 'D') {
4439
4438
  /* decimal */
4440
4439
  c = nextc(p);
4441
- if (c != -1 && ISDIGIT(c)) {
4440
+ if (c >= 0 && ISDIGIT(c)) {
4442
4441
  do {
4443
4442
  if (c == '_') {
4444
4443
  if (nondigit) break;
@@ -4448,7 +4447,7 @@ parser_yylex(parser_state *p)
4448
4447
  if (!ISDIGIT(c)) break;
4449
4448
  nondigit = 0;
4450
4449
  tokadd(p, c);
4451
- } while ((c = nextc(p)) != -1);
4450
+ } while ((c = nextc(p)) >= 0);
4452
4451
  }
4453
4452
  pushback(p, c);
4454
4453
  tokfix(p);
@@ -4466,7 +4465,7 @@ parser_yylex(parser_state *p)
4466
4465
  if (c == 'o' || c == 'O') {
4467
4466
  /* prefixed octal */
4468
4467
  c = nextc(p);
4469
- if (c == -1 || c == '_' || !ISDIGIT(c)) {
4468
+ if (c < 0 || c == '_' || !ISDIGIT(c)) {
4470
4469
  no_digits();
4471
4470
  }
4472
4471
  }
@@ -4483,7 +4482,7 @@ parser_yylex(parser_state *p)
4483
4482
  if (c > '7') goto invalid_octal;
4484
4483
  nondigit = 0;
4485
4484
  tokadd(p, c);
4486
- } while ((c = nextc(p)) != -1);
4485
+ } while ((c = nextc(p)) >= 0);
4487
4486
 
4488
4487
  if (toklen(p) > start) {
4489
4488
  pushback(p, c);
@@ -4526,7 +4525,7 @@ parser_yylex(parser_state *p)
4526
4525
  }
4527
4526
  else {
4528
4527
  int c0 = nextc(p);
4529
- if (c0 == -1 || !ISDIGIT(c0)) {
4528
+ if (c0 < 0 || !ISDIGIT(c0)) {
4530
4529
  pushback(p, c0);
4531
4530
  goto decode_num;
4532
4531
  }
@@ -4760,7 +4759,7 @@ parser_yylex(parser_state *p)
4760
4759
 
4761
4760
  c = nextc(p);
4762
4761
  quotation:
4763
- if (c == -1 || !ISALNUM(c)) {
4762
+ if (c < 0 || !ISALNUM(c)) {
4764
4763
  term = c;
4765
4764
  c = 'Q';
4766
4765
  }
@@ -4771,7 +4770,7 @@ parser_yylex(parser_state *p)
4771
4770
  return 0;
4772
4771
  }
4773
4772
  }
4774
- if (c == -1 || term == -1) {
4773
+ if (c < 0 || term < 0) {
4775
4774
  yyerror(p, "unterminated quoted string meets end of file");
4776
4775
  return 0;
4777
4776
  }
@@ -4844,14 +4843,14 @@ parser_yylex(parser_state *p)
4844
4843
  p->lstate = EXPR_END;
4845
4844
  token_column = newtok(p);
4846
4845
  c = nextc(p);
4847
- if (c == -1) {
4846
+ if (c < 0) {
4848
4847
  yyerror(p, "incomplete global variable syntax");
4849
4848
  return 0;
4850
4849
  }
4851
4850
  switch (c) {
4852
4851
  case '_': /* $_: last read line string */
4853
4852
  c = nextc(p);
4854
- if (c != -1 && identchar(c)) { /* if there is more after _ it is a variable */
4853
+ if (c >= 0 && identchar(c)) { /* if there is more after _ it is a variable */
4855
4854
  tokadd(p, '$');
4856
4855
  tokadd(p, c);
4857
4856
  break;
@@ -4909,7 +4908,7 @@ parser_yylex(parser_state *p)
4909
4908
  do {
4910
4909
  tokadd(p, c);
4911
4910
  c = nextc(p);
4912
- } while (c != -1 && isdigit(c));
4911
+ } while (c >= 0 && isdigit(c));
4913
4912
  pushback(p, c);
4914
4913
  if (last_state == EXPR_FNAME) goto gvar;
4915
4914
  tokfix(p);
@@ -4934,7 +4933,7 @@ parser_yylex(parser_state *p)
4934
4933
  tokadd(p, '@');
4935
4934
  c = nextc(p);
4936
4935
  }
4937
- if (c == -1) {
4936
+ if (c < 0) {
4938
4937
  if (p->bidx == 1) {
4939
4938
  yyerror(p, "incomplete instance variable syntax");
4940
4939
  }