Permalink
Browse files

Merge pull request #186 from jaytaph/codeblocks

Codeblocks
  • Loading branch information...
2 parents a5471a4 + 65642a6 commit 0915b616ed776e021ae96dddac95cbb1b1d10622 @jaytaph jaytaph committed Mar 6, 2014
Showing with 2,752 additions and 1,748 deletions.
  1. +1 −1 .travis.yml
  2. +9 −9 configure.ac
  3. +10 −6 hello.sf
  4. +16 −1 sfl/saffire.sf
  5. +6 −5 src/Makefile.am
  6. +8 −8 src/components/compiler/ast_nodes.c
  7. +6 −6 src/components/compiler/ast_to_asm.c
  8. +1 −1 src/components/compiler/bytecode/io.c
  9. +13 −17 src/components/compiler/bytecode/marshal.c
  10. +7 −7 src/components/compiler/output/asm.c
  11. +4 −4 src/components/compiler/saffire.l
  12. +23 −17 src/components/debugger/dbgp/commands.c
  13. +7 −7 src/components/debugger/dbgp/dbgp.c
  14. +11 −7 src/components/fastcgi/fastcgi_srv.c
  15. +1 −1 src/components/gc/gc.c
  16. +1 −1 src/components/general/config.c
  17. +1 −1 src/components/general/gpg.c
  18. +35 −25 src/components/general/hash/chained.c
  19. +19 −18 src/components/general/hashtable.c
  20. +11 −11 src/components/general/ini.c
  21. +83 −41 src/components/general/output.c
  22. +6 −6 src/components/general/parse_options.c
  23. +69 −84 src/components/general/printf/arg_printf.c
  24. +1 −8 src/components/general/smm.c
  25. +40 −3 src/components/general/smm/asprintf.c
  26. +147 −0 src/components/general/string.c
  27. +206 −0 src/components/general/unicode.c
  28. +10 −9 src/components/modules/io.c
  29. +2 −2 src/components/modules/module_api.c
  30. +32 −4 src/components/modules/saffire.c
  31. +1 −1 src/components/modules/sapi/fastcgi.c
  32. +9 −6 src/components/objects/attrib.c
  33. +5 −6 src/components/objects/base.c
  34. +5 −4 src/components/objects/boolean.c
  35. +4 −3 src/components/objects/callable.c
  36. +9 −7 src/components/objects/exception.c
  37. +16 −14 src/components/objects/hash.c
  38. +2 −1 src/components/objects/list.c
  39. +3 −1 src/components/objects/null.c
  40. +9 −1 src/components/objects/numerical.c
  41. +46 −42 src/components/objects/object.c
  42. +31 −5 src/components/objects/regex.c
  43. +219 −194 src/components/objects/string.c
  44. +3 −2 src/components/objects/tuple.c
  45. +5 −2 src/components/objects/userland.c
  46. +6 −3 src/components/repl/repl.c
  47. +13 −14 src/components/vm/block.c
  48. +164 −0 src/components/vm/codeframe.c
  49. +68 −24 src/components/vm/context.c
  50. +0 −597 src/components/vm/frame.c
  51. +85 −124 src/components/vm/import.c
  52. +469 −0 src/components/vm/stackframe.c
  53. +25 −4 src/components/vm/thread.c
  54. +252 −179 src/components/vm/vm.c
  55. +2 −0 src/components/vm/vm_opcodes.dat
  56. +2 −2 src/include/compiler/bytecode.h
  57. +2 −2 src/include/compiler/saffire_parser.h
  58. +23 −2 src/include/debug.h
  59. +4 −4 src/include/debugger/dbgp/dbgp.h
  60. +2 −2 src/include/general/hashtable.h
  61. +21 −9 src/include/general/output.h
  62. +2 −1 src/include/general/printf.h
  63. +6 −3 src/include/general/smm.h
  64. +62 −0 src/include/general/string.h
  65. +72 −0 src/include/general/unicode.h
  66. +7 −2 src/include/objects/callable.h
  67. +2 −2 src/include/objects/exception.h
  68. +4 −4 src/include/objects/object.h
  69. +22 −7 src/include/objects/string.h
  70. +1 −2 src/include/objects/userland.h
  71. +5 −26 src/include/vm/block.h
  72. +40 −0 src/include/vm/codeframe.h
  73. +5 −15 src/include/vm/context.h
  74. +6 −5 src/include/vm/import.h
  75. +77 −0 src/include/vm/stackframe.h
  76. +10 −5 src/include/vm/thread.h
  77. +3 −5 src/include/vm/vm.h
  78. +59 −59 src/include/vm/{frame.h → vmtypes.h}
  79. +3 −2 src/main/commands/bytecode.c
  80. +8 −8 src/main/commands/config.c
  81. +13 −7 src/main/commands/exec.c
  82. +3 −3 src/main/commands/help.c
  83. +10 −10 src/main/commands/lint.c
  84. +2 −2 src/main/commands/version.c
  85. +12 −12 src/main/saffire.c
  86. +1 −1 support/generators/generate_exceptions.php
  87. +5 −0 support/readdump/bytecode/Constant/String.php
  88. +1 −1 unittests/core/Makefile.am
  89. +20 −0 unittests/tests/syntax/regex-001.sfu
  90. +0 −1 unittests/tests/syntax/subscriptions-001.sfu
View
@@ -6,7 +6,7 @@ before_script:
- sudo ln -s `pwd`/sfl /usr/share/saffire/modules/sfl
before_install:
- sudo apt-get update -qq
- - sudo apt-get install -qq libpcre3-dev libfcgi-dev libedit-dev libbz2-dev libxml2-dev
+ - sudo apt-get install -qq libpcre3-dev libfcgi-dev libedit-dev libbz2-dev libxml2-dev libicu-dev
- sudo apt-get install -qq php5-cli php-pear
- sudo apt-get install -qq libcunit1-dev
- printf "\n" | sudo pecl install yaml
View
@@ -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.
View
@@ -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");
+
+*/
View
@@ -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();
@@ -28,6 +28,21 @@ class saffire {
}
/**
+ *
+ */
+ 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"
*/
static public method sapi() {
View
@@ -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
########################################################################
@@ -211,7 +213,8 @@ CLEANFILES += components/vm/_generated_vm_opcodes.c \
noinst_LIBRARIES += libvm.a
libvm_a_SOURCES = components/vm/vm.c \
components/vm/block.c \
- components/vm/frame.c \
+ components/vm/stackframe.c \
+ components/vm/codeframe.c \
components/vm/context.c \
components/vm/thread.c \
components/vm/import.c \
@@ -234,8 +237,6 @@ libgc_a_SOURCES = components/gc/gc.c
SAFFIRE_LIBS = \
libobjects.a \
libgeneral.a \
- libobjects.a \
- libgeneral.a \
libcompiler.a \
libfastcgi.a \
librepl.a \
@@ -247,7 +248,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 \
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
@@ -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;
@@ -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;
@@ -37,7 +37,7 @@
#include "general/dll.h"
#include "debug.h"
#include "vm/vm_opcodes.h"
-#include "vm/frame.h"
+#include "vm/stackframe.h"
#include "objects/attrib.h"
#define MAX_LABEL_LEN 100
@@ -56,7 +56,7 @@ enum call_state { st_call_pop, st_call_stay };
* Structure that holds info for current block in the frame (while, if, foreach etc)
*/
typedef struct _state_frame {
- int type; // BLOCK_TYPE_* as defined in vm/frame.h
+ int type; // BLOCK_TYPE_* as defined in vm/stackframe.h
char label[MAX_LABEL_LEN];
t_hash_table *labels; // Defined labels inside this block (so we can tests for duplicates)
} t_state_frame;
@@ -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);
@@ -385,7 +385,7 @@ static void __ast_walker(t_ast_element *leaf, t_hash_table *output, t_dll *frame
// Store class into identifier
opr1 = asm_create_opr(ASM_LINE_TYPE_OP_ID, leaf->class.name, 0);
- dll_append(frame, asm_create_codeline(leaf->lineno, VM_STORE_ID, 1, opr1));
+ dll_append(frame, asm_create_codeline(leaf->lineno, VM_STORE_FRAME_ID, 1, opr1));
break;
@@ -424,7 +424,7 @@ static void __ast_walker(t_ast_element *leaf, t_hash_table *output, t_dll *frame
// Store class into identifier
opr1 = asm_create_opr(ASM_LINE_TYPE_OP_ID, leaf->interface.name, 0);
- dll_append(frame, asm_create_codeline(leaf->lineno, VM_STORE_ID, 1, opr1));
+ dll_append(frame, asm_create_codeline(leaf->lineno, VM_STORE_FRAME_ID, 1, opr1));
break;
case typeAstAttribute :
@@ -562,7 +562,7 @@ static void __ast_walker(t_ast_element *leaf, t_hash_table *output, t_dll *frame
node = leaf->opr.ops[1];
opr1 = asm_create_opr(ASM_LINE_TYPE_OP_ID, node->string.value, 0);
- dll_append(frame, asm_create_codeline(leaf->lineno, VM_STORE_ID, 1, opr1));
+ dll_append(frame, asm_create_codeline(leaf->lineno, VM_STORE_FRAME_ID, 1, opr1));
break;
case T_CALL_ARGUMENT_LIST :
@@ -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
@@ -44,8 +44,6 @@
static void _free_constant(t_bytecode_constant *c) {
switch (c->type) {
case BYTECODE_CONST_STRING :
- smm_free(c->data.s);
- break;
case BYTECODE_CONST_REGEX :
smm_free(c->data.s);
break;
@@ -74,25 +72,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.s = r->val;
_add_constant(bc, c);
}
@@ -133,7 +132,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));
@@ -213,15 +212,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.
+ // Constant regex 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 :
@@ -283,9 +282,6 @@ int bytecode_marshal(t_bytecode *bytecode, int *bincode_off, char **bincode) {
_write_buffer(bincode, bincode_off, child_bincode_len, child_bincode);
break;
case BYTECODE_CONST_STRING :
- _write_buffer(bincode, bincode_off, sizeof(int), &bytecode->constants[i]->len);
- _write_buffer(bincode, bincode_off, bytecode->constants[i]->len, bytecode->constants[i]->data.s);
- break;
case BYTECODE_CONST_REGEX :
_write_buffer(bincode, bincode_off, sizeof(int), &bytecode->constants[i]->len);
_write_buffer(bincode, bincode_off, bytecode->constants[i]->len, bytecode->constants[i]->data.s);
@@ -373,10 +369,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);
Oops, something went wrong.

0 comments on commit 0915b61

Please sign in to comment.