Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/mruby/mruby into XCode
Browse files Browse the repository at this point in the history
  • Loading branch information
pbosetti committed May 29, 2012
2 parents 391f8dc + 1e5d15d commit d735178
Show file tree
Hide file tree
Showing 61 changed files with 848 additions and 202 deletions.
45 changes: 42 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# makefile discription.
# basic build file for mruby

# compiler, linker (gcc)
CC = gcc
LL = gcc
# compiler, linker (gcc), archiver, parser generator
export CC = gcc
export LL = gcc
export AR = ar
export YACC = bison

DEBUG_MODE = 1
ifeq ($(DEBUG_MODE),1)
CFLAGS = -g -O3
Expand All @@ -17,6 +20,16 @@ else
MAKE_FLAGS = --no-print-directory CC='$(CC)' LL='$(LL)' ALL_CFLAGS='$(ALL_CFLAGS)'
endif

##############################
# internal variables

export MSG_BEGIN = @for line in
export MSG_END = ; do echo "$$line"; done

export CP := cp
export RM_F := rm -f
export CAT := cat

##############################
# generic build targets, rules

Expand All @@ -39,3 +52,29 @@ clean :
@$(MAKE) clean -C tools/mruby $(MAKE_FLAGS)
@$(MAKE) clean -C tools/mirb $(MAKE_FLAGS)
@$(MAKE) clean -C test $(MAKE_FLAGS)

# display help for build configuration and interesting targets
.PHONY : showconfig
showconfig :
$(MSG_BEGIN) \
"" \
" CC = $(CC)" \
" LL = $(LL)" \
" MAKE = $(MAKE)" \
"" \
" CFLAGS = $(CFLAGS)" \
" ALL_CFLAGS = $(ALL_CFLAGS)" \
$(MSG_END)

.PHONY : help
help :
$(MSG_BEGIN) \
"" \
" Basic mruby Makefile" \
"" \
"targets:" \
" all (default): build all targets, install (locally) in-repo" \
" clean: clean all built and in-repo installed artifacts" \
" showconfig: show build config summary" \
" test: run all mruby tests" \
$(MSG_END)
4 changes: 1 addition & 3 deletions mrblib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,10 @@ else()
endif()


add_library(mrblib_object OBJECT mrblib.c)

# generate final static libmruby archive library
add_library(libmruby_static STATIC
mrblib.c
$<TARGET_OBJECTS:mruby_object>
$<TARGET_OBJECTS:mrblib_object>
)
set_target_properties(libmruby_static PROPERTIES OUTPUT_NAME mruby)

Expand Down
17 changes: 8 additions & 9 deletions mrblib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@ MRBS := $(MRB1)
LIBR0 := ../lib/libmruby_core.a
LIBR := ../lib/libmruby.a

# C compiler (gcc)
CC = gcc
LL = gcc
AR = ar
# libraries, includes
INCLUDES = -I../src -I../include

DEBUG_MODE = 1
ifeq ($(DEBUG_MODE),1)
CFLAGS = -g
else
CFLAGS = -O3
endif
INCLUDES = -I../src -I../include
ALL_CFLAGS = -Wall -Werror-implicit-function-declaration $(CFLAGS)
ifeq ($(OS),Windows_NT)
MAKE_FLAGS = CC=$(CC) LL=$(LL) ALL_CFLAGS="$(ALL_CFLAGS)"
Expand All @@ -40,6 +38,7 @@ else
MRBC = ../bin/mrbc
endif


##############################
# generic build targets, rules

Expand All @@ -48,7 +47,7 @@ all : $(LIBR)

# update libmruby.a
$(LIBR) : $(MLIB) $(LIBR0)
cp $(LIBR0) $(LIBR)
$(CP) $(LIBR0) $(LIBR)
$(AR) r $(LIBR) $(MLIB)

# Compile mrblib source
Expand All @@ -57,17 +56,17 @@ $(MLIB) : $(CLIB)

# Compile C source from merged mruby source
$(CLIB) : $(RLIB) $(MRBC)
$(MRBC) -Bmrblib_irep -o$(DLIB) $(RLIB); cat init_$(TARGET).c $(DLIB) > $@
$(MRBC) -Bmrblib_irep -o$(DLIB) $(RLIB); $(CAT) init_$(TARGET).c $(DLIB) > $@

$(MRBC) : ../src/opcode.h ../src/codegen.c ../src/parse.y
$(MAKE) -C ../tools/mrbc $(MAKE_FLAGS)

# merge mruby sources
$(RLIB) : $(MRBS)
cat $? > $@
$(CAT) $(MRBS) > $@

# clean up
.PHONY : clean
clean :
@echo "make: removing targets, objects and depend files of `pwd`"
-rm -f $(MRBC) $(MLIB) $(CLIB) $(RLIB) $(DLIB) $(DEPLIB) $(LIBR)
-$(RM_F) $(MRBC) $(MLIB) $(CLIB) $(RLIB) $(DLIB) $(DEPLIB) $(LIBR)
52 changes: 44 additions & 8 deletions mrblib/compar.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
##
# Comparable
#
# ISO 15.3.3
module Comparable
# 15.3.3.2.1

##
# Return true if +self+ is less
# than +other+. Otherwise return
# false.
#
# ISO 15.3.3.2.1
def < other
cmp = self <=> other
if cmp.nil?
Expand All @@ -11,7 +21,12 @@ def < other
end
end

# 15.3.3.2.2
##
# Return true if +self+ is less
# than or equal to +other+.
# Otherwise return false.
#
# ISO 15.3.3.2.2
def <= other
cmp = self <=> other
if cmp.nil?
Expand All @@ -23,7 +38,12 @@ def <= other
end
end

# 15.3.3.2.3
##
# Return true if +self+ is equal
# to +other+. Otherwise return
# false.
#
# ISO 15.3.3.2.3
def == other
cmp = self <=> other
if cmp == 0
Expand All @@ -33,7 +53,12 @@ def == other
end
end

# 15.3.3.2.4
##
# Return true if +self+ is greater
# than +other+. Otherwise return
# false.
#
# ISO 15.3.3.2.4
def > other
cmp = self <=> other
if cmp.nil?
Expand All @@ -45,9 +70,14 @@ def > other
end
end

# 15.3.3.2.5
##
# Return true if +self+ is greater
# than or equal to +other+.
# Otherwise return false.
#
# ISO 15.3.3.2.5
def >= other
cmp = self <=> other
cmp = self <=> other
if cmp.nil?
false
elsif cmp >= 0
Expand All @@ -57,8 +87,14 @@ def >= other
end
end

# 15.3.3.2.6
def between?(min,max)
##
# Return true if +self+ is greater
# than or equal to +min+ and
# less than or equal to +max+.
# Otherwise return false.
#
# ISO 15.3.3.2.6
def between?(min, max)
if self < min or self > max
false
else
Expand Down
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ file(GLOB MRUBY_SRC_C "*.c")
list(APPEND MRUBY_SRC_C "${CMAKE_CURRENT_BINARY_DIR}/parse.c")

add_library(mruby_object OBJECT ${MRUBY_SRC_C} ${BISON_mruby_OUTPUTS})
add_library(mruby_static STATIC EXCLUDE_FROM_ALL $<TARGET_OBJECTS:mruby_object>)

# vim: ts=2 sts=2 sw=2 et
13 changes: 4 additions & 9 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ OBJS := $(OBJ1) $(OBJ2) $(OBJ3)
# libraries, includes
INCLUDES = -I$(BASEDIR) -I$(BASEDIR)/../include

# compiler, linker (gcc)
CC = gcc
LL = gcc
AR = ar
YACC = bison

DEBUG_MODE = 1
ifeq ($(DEBUG_MODE),1)
CFLAGS = -g -O3
Expand All @@ -33,6 +27,7 @@ CFLAGS = -O3
endif
ALL_CFLAGS = -Wall -Werror-implicit-function-declaration $(CFLAGS)


##############################
# generic build targets, rules

Expand Down Expand Up @@ -64,6 +59,6 @@ $(LDEF) : $(KWD)
.PHONY : clean #cleandep
clean :
@echo "make: removing targets, objects and depend files of `pwd`"
-rm -f $(TARGET) $(OBJS) $(OBJY) $(YC)
-rm -f $(OBJS:.o=.d) $(OBJY:.o=.d)
-rm -f $(patsubst %.c,%.o,$(EXCEPT1)) $(patsubst %.c,%.d,$(EXCEPT1))
-$(RM_F) $(TARGET) $(OBJS) $(OBJY) $(YC)
-$(RM_F) $(OBJS:.o=.d) $(OBJY:.o=.d)
-$(RM_F) $(patsubst %.c,%.o,$(EXCEPT1)) $(patsubst %.c,%.d,$(EXCEPT1))
18 changes: 3 additions & 15 deletions src/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -917,22 +917,10 @@ mrb_ary_join(mrb_state *mrb, mrb_value ary, mrb_value sep)
static mrb_value
mrb_ary_join_m(mrb_state *mrb, mrb_value ary)
{
mrb_value *argv;
int argc;

mrb_get_args(mrb, "*", &argv, &argc);
switch(argc) {
case 0:
return mrb_ary_join(mrb, ary, mrb_nil_value());

case 1:
return mrb_ary_join(mrb, ary, argv[0]);

default:
mrb_raise(mrb, E_ARGUMENT_ERROR, "wrong number of arguments");
}
mrb_value sep = mrb_nil_value();

return mrb_nil_value(); /* dummy */
mrb_get_args(mrb, "|o", &sep);
return mrb_ary_join(mrb, ary, sep);
}

static mrb_value
Expand Down
2 changes: 1 addition & 1 deletion src/class.c
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
break;
}
}
if (!*format && argc > i) {
if (!c && argc > i) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "wrong number of arguments");
}
va_end(ap);
Expand Down
17 changes: 10 additions & 7 deletions src/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ typedef struct scope {

int nlocals;
int nregs;
int ai;

int idx;
} codegen_scope;
Expand Down Expand Up @@ -1234,25 +1235,25 @@ codegen(codegen_scope *s, node *tree, int val)
int idx = new_msym(s, sym);

if (name[0] == '+' && strlen(name) == 1) {
genop(s, MKOP_ABC(OP_ADD, cursp(), idx, 2));
genop(s, MKOP_ABC(OP_ADD, cursp(), idx, 1));
}
else if (name[0] == '-' && strlen(name) == 1) {
genop(s, MKOP_ABC(OP_SUB, cursp(), idx, 2));
genop(s, MKOP_ABC(OP_SUB, cursp(), idx, 1));
}
else if (name[0] == '<' && strlen(name) == 1) {
genop(s, MKOP_ABC(OP_LT, cursp(), idx, 2));
genop(s, MKOP_ABC(OP_LT, cursp(), idx, 1));
}
else if (name[0] == '<' && strlen(name) == 2 && name[1] == '=') {
genop(s, MKOP_ABC(OP_LE, cursp(), idx, 2));
genop(s, MKOP_ABC(OP_LE, cursp(), idx, 1));
}
else if (name[0] == '>' && strlen(name) == 1) {
genop(s, MKOP_ABC(OP_GT, cursp(), idx, 2));
genop(s, MKOP_ABC(OP_GT, cursp(), idx, 1));
}
else if (name[0] == '>' && strlen(name) == 2 && name[1] == '=') {
genop(s, MKOP_ABC(OP_GE, cursp(), idx, 2));
genop(s, MKOP_ABC(OP_GE, cursp(), idx, 1));
}
else {
genop(s, MKOP_ABC(OP_SEND, cursp(), idx, 2));
genop(s, MKOP_ABC(OP_SEND, cursp(), idx, 1));
}
}
gen_assignment(s, tree->car, cursp(), val);
Expand Down Expand Up @@ -1849,6 +1850,7 @@ scope_new(mrb_state *mrb, codegen_scope *prev, node *lv)
p->lv = lv;
p->sp += node_len(lv)+2;
p->nlocals = p->sp;
p->ai = mrb->arena_idx;

p->idx = mrb->irep_len++;

Expand Down Expand Up @@ -1882,6 +1884,7 @@ scope_finish(codegen_scope *s, int idx)
irep->nlocals = s->nlocals;
irep->nregs = s->nregs;

s->mrb->arena_idx = s->ai;
mrb_pool_close(s->mpool);
}

Expand Down
2 changes: 1 addition & 1 deletion src/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ mrb_init_exception(mrb_state *mrb)
#ifdef INCLUDE_ENCODING
mrb_define_class(mrb, "EncodingError", mrb->eStandardError_class);
#endif
mrb_define_class(mrb, "ZeroDivisionError", mrb->eStandardError_class); /* 15.2.30 */
// mrb_define_class(mrb, "ZeroDivisionError", mrb->eStandardError_class); /* 15.2.30 */

mrb_define_class(mrb, "FloatDomainError", eRangeError);
mrb_define_class(mrb, "KeyError", eIndexError);
Expand Down
9 changes: 5 additions & 4 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,13 @@ mrb_obj_alloc(mrb_state *mrb, enum mrb_vtype ttype, struct RClass *cls)
}

mrb->live++;
mrb->arena[mrb->arena_idx++] = p;
memset(p, 0, sizeof(RVALUE));
if (mrb->arena_idx >= MRB_ARENA_SIZE) {
if (mrb->arena_idx > MRB_ARENA_SIZE) {
/* arena overflow error */
mrb_raise(mrb, E_TYPE_ERROR, "arena overflow error");
mrb->arena_idx = MRB_ARENA_SIZE - 2; /* force room in arena */
mrb_raise(mrb, mrb->eRuntimeError_class, "arena overflow error");
}
mrb->arena[mrb->arena_idx++] = p;
memset(p, 0, sizeof(RVALUE));
p->tt = ttype;
p->c = cls;
paint_partial_white(mrb, p);
Expand Down

0 comments on commit d735178

Please sign in to comment.