Skip to content

Commit

Permalink
Megacommit
Browse files Browse the repository at this point in the history
  • Loading branch information
jaytaph committed Feb 8, 2014
1 parent cb832d2 commit 9c3bf9d
Show file tree
Hide file tree
Showing 72 changed files with 1,478 additions and 754 deletions.
18 changes: 9 additions & 9 deletions configure.ac
Expand Up @@ -79,15 +79,15 @@ AM_CONDITIONAL(ENABLE_COVERAGE, test "x$enable_coverage" = "xyes")



dnl # check for icu-config
dnl AC_PATH_PROG(icu_config, icu-config, no)
dnl if test "$icu_config" = "no"; then
dnl AC_MSG_ERROR([Cannot find icu-config. ICU library is needed.])
dnl fi
dnl ICU_CPPFLAGS=`$icu_config --cppflags`
dnl ICU_LIBS=`$icu_config --ldflags`
dnl AC_SUBST([ICU_CPPFLAGS])
dnl AC_SUBST([ICU_LIBS])
# check for icu-config
AC_PATH_PROG(icu_config, icu-config, no)
if test "$icu_config" = "no"; then
AC_MSG_ERROR([Cannot find icu-config. ICU library is needed.])
fi
ICU_CFLAGS=`$icu_config --cflags`
ICU_LIBS=`$icu_config --ldflags`
AC_SUBST([ICU_CFLAGS])
AC_SUBST([ICU_LIBS])


# Checks for libraries.
Expand Down
16 changes: 10 additions & 6 deletions hello.sf
Expand Up @@ -4,28 +4,32 @@ import io;
// Call the print method from our (imported) io class with a single argument
io.print("Hello world!\n");


/*

class bar {
public method foo(b) {
return 1;
return 1;
}
}

class foo {
public property a = 2;

public method bar(numerical b) {
self.foo(b);
self.foo(b);
return self.a * b;
}

public method foo(b) {
tmp = bar();
tmp.foo(b);

tmp = bar();
tmp.foo(b);
}
}

io.print("Oh hai again!\n");
f = foo();
b = f.bar(5);
io.print("The number is ",b," and ", f.bar(7),".\n");
io.print("The number is ",b," and ", f.bar(7),".\n");

*/
17 changes: 16 additions & 1 deletion sfl/saffire.sf
Expand Up @@ -13,7 +13,7 @@ class saffire {
}

/**
* Returnst the git SHA commit that is used for compiling this version
* Returns the git SHA commit that is used for compiling this version
*/
static public method git_revision() {
return ::_sfl::saffire::saffire.git_revision();
Expand All @@ -27,6 +27,21 @@ class saffire {
return e.getCode();
}

/**
*
*/
static public method getLocale() {
return ::_sfl::saffire::saffire.get_locale();
}

/**
*
*/
static public method setLocale(string locale) {
return ::_sfl::saffire::saffire.set_locale(locale);
}


/**
* Returns the current server API, could be "fastcgi", "cli", "repl" or "unknown"
*/
Expand Down
8 changes: 4 additions & 4 deletions src/Makefile.am
Expand Up @@ -117,7 +117,9 @@ libgeneral_a_SOURCES = components/general/hashtable.c \
components/general/mutex.c \
components/general/printf/arg_printf.c \
components/general/ini.c \
components/general/base64.c
components/general/base64.c \
components/general/string.c \
components/general/unicode.c


########################################################################
Expand Down Expand Up @@ -232,8 +234,6 @@ libgc_a_SOURCES = components/gc/gc.c

# There are double archives here, this is because of resolving of objects.
SAFFIRE_LIBS = \
libobjects.a \
libgeneral.a \
libobjects.a \
libgeneral.a \
libcompiler.a \
Expand All @@ -247,7 +247,7 @@ SAFFIRE_LIBS = \

bin_PROGRAMS = saffire

saffire_LDADD = $(SAFFIRE_LIBS) $(SAFFIRE_LIBS) $(edit_LIBS) ${libxml2_LIBS} -lpthread
saffire_LDADD = $(SAFFIRE_LIBS) $(SAFFIRE_LIBS) $(edit_LIBS) ${libxml2_LIBS} ${ICU_LIBS} -lpthread

saffire_SOURCES = main/saffire.c \
main/commands/config.c main/commands/fastcgi.c main/commands/lint.c \
Expand Down
16 changes: 8 additions & 8 deletions src/components/compiler/ast_nodes.c
Expand Up @@ -119,7 +119,7 @@ t_ast_element *ast_node_string(int lineno, char *value) {

p->lineno = lineno;
p->type = typeAstString;
p->string.value = smm_strdup(value);
p->string.value = string_strdup0(value);

return p;
}
Expand All @@ -129,7 +129,7 @@ t_ast_element *ast_node_regex(int lineno, char *value) {

p->lineno = lineno;
p->type = typeAstRegex;
p->regex.value = smm_strdup(value);
p->regex.value = string_strdup0(value);

return p;
}
Expand All @@ -140,7 +140,7 @@ t_ast_element *ast_node_id_to_string(t_ast_element *src) {

p->lineno = src->lineno;
p->type = typeAstString;
p->string.value = smm_strdup(src->identifier.name);
p->string.value = string_strdup0(src->identifier.name);

return p;
}
Expand All @@ -153,7 +153,7 @@ t_ast_element *ast_node_string_dup(int lineno, t_ast_element *src) {

p->lineno = lineno;
p->type = typeAstString;
p->string.value = smm_strdup(src->string.value);
p->string.value = string_strdup0(src->string.value);

return p;
}
Expand Down Expand Up @@ -189,7 +189,7 @@ t_ast_element *ast_node_identifier(int lineno, char *var_name) {

p->lineno = lineno;
p->type = typeAstIdentifier;
p->identifier.name = smm_strdup(var_name);
p->identifier.name = string_strdup0(var_name);
return p;
}

Expand Down Expand Up @@ -420,7 +420,7 @@ t_ast_element *ast_node_class(int lineno, t_class *class, t_ast_element *body) {
p->lineno = lineno;
p->type = typeAstClass;
p->class.modifiers = class->modifiers;
p->class.name = smm_strdup(class->name);
p->class.name = string_strdup0(class->name);

p->class.extends = class->extends;
p->class.implements = class->implements;
Expand All @@ -439,7 +439,7 @@ t_ast_element *ast_node_interface(int lineno, int modifiers, char *name, t_ast_e
p->lineno = lineno;
p->type = typeAstInterface;
p->interface.modifiers = modifiers;
p->interface.name = smm_strdup(name);
p->interface.name = string_strdup0(name);
p->interface.implements = implements;
p->interface.body = body;

Expand All @@ -454,7 +454,7 @@ t_ast_element *ast_node_attribute(int lineno, char *name, char attrib_type, char

p->lineno = lineno;
p->type = typeAstAttribute;
p->attribute.name = smm_strdup(name);
p->attribute.name = string_strdup0(name);
p->attribute.attrib_type = attrib_type;
p->attribute.visibility = visibility;
p->attribute.access = access;
Expand Down
2 changes: 1 addition & 1 deletion src/components/compiler/ast_to_asm.c
Expand Up @@ -135,7 +135,7 @@ static void __ast_walker(t_ast_element *leaf, t_hash_table *output, t_dll *frame

// We know the scope now. We still need to use "self"
smm_free(node->identifier.name);
node->identifier.name = smm_strdup("self");
node->identifier.name = string_strdup0("self");
}

stack_push(state->context, (void *)st_ctx_load);
Expand Down
2 changes: 1 addition & 1 deletion src/components/compiler/bytecode/io.c
Expand Up @@ -74,7 +74,7 @@ t_bytecode *bytecode_load(const char *filename, int verify_signature) {
if (verify_signature == 0 &&
(header.flags & BYTECODE_FLAG_SIGNED) == BYTECODE_FLAG_SIGNED &&
header.signature_offset != 0) {
output("A signature is present, but verification is disabled");
output_char("A signature is present, but verification is disabled");
}

// We need to check signature, and there is one present
Expand Down
23 changes: 12 additions & 11 deletions src/components/compiler/bytecode/marshal.c
Expand Up @@ -74,25 +74,26 @@ static void _add_constant(t_bytecode *bc, t_bytecode_constant *c) {
/**
* Add a new string constant to the bytecode structure
*/
static void _new_constant_string(t_bytecode *bc, char *s) {
static void _new_constant_string(t_bytecode *bc, t_string *s) {
// Setup constant
t_bytecode_constant *c = (t_bytecode_constant *)smm_malloc(sizeof(t_bytecode_constant));
c->type = BYTECODE_CONST_STRING;
c->len = strlen(s);
c->data.s = smm_strdup(s);
c->len = s->len;
c->data.s = s->val;


_add_constant(bc, c);
}

/**
* Add a new regex constant to the bytecode structure
*/
static void _new_constant_regex(t_bytecode *bc, char *s) {
static void _new_constant_regex(t_bytecode *bc, t_string *r) {
// Setup constant
t_bytecode_constant *c = (t_bytecode_constant *)smm_malloc(sizeof(t_bytecode_constant));
c->type = BYTECODE_CONST_REGEX;
c->len = strlen(s);
c->data.s = smm_strdup(s);
c->len = r->len;
c->data.r = r->val;

_add_constant(bc, c);
}
Expand Down Expand Up @@ -133,7 +134,7 @@ static void _new_name(t_bytecode *bc, char *var) {
// Setup identifier
t_bytecode_identifier *c = smm_malloc(sizeof(t_bytecode_identifier));
c->len = strlen(var);
c->s = smm_strdup(var);
c->s = string_strdup0(var);

// Add identifier
bc->identifiers = smm_realloc(bc->identifiers, sizeof(t_bytecode_identifier *) * (bc->identifiers_len + 1));
Expand Down Expand Up @@ -213,15 +214,15 @@ t_bytecode *bytecode_unmarshal(char *bincode) {
s = smm_malloc(len+1);
_read_buffer(bincode, &pos, len, s);
s[len] = '\0';
_new_constant_string(bytecode, s);
_new_constant_string(bytecode, char_to_string(s, len));
smm_free(s);
break;
case BYTECODE_CONST_REGEX :
// Constant rexeg do not have a trailing \0 on disk.
s = smm_malloc(len+1);
_read_buffer(bincode, &pos, len, s);
s[len] = '\0';
_new_constant_regex(bytecode, s);
_new_constant_regex(bytecode, char_to_string(s, len));
smm_free(s);
break;
case BYTECODE_CONST_NUMERICAL :
Expand Down Expand Up @@ -373,10 +374,10 @@ t_bytecode *convert_frames_to_bytecode(t_hash_table *frames, char *name, int sta
_new_constant_code(bc, convert_frames_to_bytecode(frames, c->data.s, 1));
break;
case const_string :
_new_constant_string(bc, c->data.s);
_new_constant_string(bc, char0_to_string(c->data.s));
break;
case const_regex :
_new_constant_regex(bc, c->data.s);
_new_constant_regex(bc, char0_to_string(c->data.s));
break;
case const_long :
_new_constant_long(bc, c->data.l);
Expand Down
14 changes: 7 additions & 7 deletions src/components/compiler/output/asm.c
Expand Up @@ -129,7 +129,7 @@ static int _convert_constant_string(t_asm_frame *frame, char *s) {
// Add to DLL
t_asm_constant *c = smm_malloc(sizeof(t_asm_constant));
c->type = const_string;
c->data.s = smm_strdup(s);
c->data.s = string_strdup0(s);
dll_append(frame->constants, c);

return frame->constants->size - 1;
Expand All @@ -148,7 +148,7 @@ static int _convert_constant_regex(t_asm_frame *frame, char *r) {
// Add to DLL
t_asm_constant *c = smm_malloc(sizeof(t_asm_constant));
c->type = const_regex;
c->data.s = smm_strdup(r);
c->data.s = string_strdup0(r);
dll_append(frame->constants, c);

return frame->constants->size - 1;
Expand All @@ -167,7 +167,7 @@ static int _convert_constant_code(t_asm_frame *frame, char *s) {
// Add to DLL
t_asm_constant *c = smm_malloc(sizeof(t_asm_constant));
c->type = const_code;
c->data.s = smm_strdup(s);
c->data.s = string_strdup0(s);
dll_append(frame->constants, c);

return frame->constants->size - 1;
Expand Down Expand Up @@ -337,7 +337,7 @@ static t_asm_frame *assemble_frame(t_dll *source_frame, int mainframe) {
bp = smm_malloc(sizeof(struct _backpatch));
bp->opcode_offset = opcode_off;
bp->operand_offset = frame->code_len;
bp->label = smm_strdup(line->opr[i]->data.s);
bp->label = string_strdup0(line->opr[i]->data.s);
dll_append(frame->backpatch_offsets, bp);

opr = 0xFFFF; // Add dummy bytes keep the offsets happy
Expand Down Expand Up @@ -459,7 +459,7 @@ void assembler_free(t_hash_table *asm_code) {
t_asm_opr *asm_create_opr(int type, char *s, int l) {
t_asm_opr *opr = smm_malloc(sizeof(t_asm_opr));
opr->type = type;
opr->data.s = s ? smm_strdup(s) : NULL;
opr->data.s = s ? string_strdup0(s) : NULL;
opr->data.l = l;
return opr;
}
Expand Down Expand Up @@ -492,7 +492,7 @@ t_asm_line *asm_create_codeline(int lineno, int opcode, int opr_cnt, ...) {
t_asm_line *asm_create_labelline(char *label) {
t_asm_line *line = smm_malloc(sizeof(t_asm_line));
line->type = ASM_LINE_TYPE_LABEL;
line->s = smm_strdup(label);
line->s = string_strdup0(label);
return line;
}

Expand Down Expand Up @@ -520,7 +520,7 @@ t_bytecode *assembler(t_hash_table *asm_code, const char *filename) {
}

t_bytecode *bc = convert_frames_to_bytecode(assembled_frames, "main", 1);
bc->source_filename = filename ? smm_strdup(filename) : NULL;
bc->source_filename = filename ? string_strdup0(filename) : NULL;


// Cleanup our frames
Expand Down
8 changes: 4 additions & 4 deletions src/components/compiler/saffire.l
Expand Up @@ -161,7 +161,7 @@ ml_comment "/*"([^\*]|\*[^/])*"*/"
/* Only match regex when we are in the regex state */
<st_regex>\/[^\/\\]*(?:\\.[^\/\\]*)*\/[a-z]* {
do_yylloc;
yylval->sVal = smm_strdup(yytext);
yylval->sVal = string_strdup0(yytext);
return T_REGEX;
}

Expand Down Expand Up @@ -257,15 +257,15 @@ ml_comment "/*"([^\*]|\*[^/])*"*/"
<st_string_dbl>\" {
do_yylloc;
/* Closing double string quote */
yylval->sVal = smm_strdup(strbuf ? strbuf : "");
yylval->sVal = string_strdup0(strbuf ? strbuf : "");
smm_free(strbuf);
saffire_pop_state();
return T_STRING;
}
<st_string_sgl>\' {
do_yylloc;
/* Closing Single string quote */
yylval->sVal = smm_strdup(strbuf ? strbuf : "");
yylval->sVal = string_strdup0(strbuf ? strbuf : "");
smm_free(strbuf);
saffire_pop_state();
return T_STRING;
Expand Down Expand Up @@ -350,7 +350,7 @@ ml_comment "/*"([^\*]|\*[^/])*"*/"
{identifier} {
do_yylloc;
saffire_push_state(st_div);
yylval->sVal = smm_strdup(yytext);
yylval->sVal = string_strdup0(yytext);
return T_IDENTIFIER;
}
Expand Down

0 comments on commit 9c3bf9d

Please sign in to comment.