[Swfdec-commits] 14 commits - vivified/code
Pekka Lampila
medar at kemper.freedesktop.org
Wed Apr 23 03:29:52 PDT 2008
vivified/code/.gitignore | 1
vivified/code/Makefile.am | 2
vivified/code/compiler.c | 24
vivified/code/vivi_code_asm_push.c | 2
vivified/code/vivi_code_assembler.c | 14
vivified/code/vivi_code_assembler.h | 1
vivified/code/vivi_code_assignment.c | 26
vivified/code/vivi_code_binary.c | 15
vivified/code/vivi_code_binary.h | 3
vivified/code/vivi_code_binary_default.c | 6
vivified/code/vivi_code_block.c | 8
vivified/code/vivi_code_break.c | 4
vivified/code/vivi_code_builtin_call.c | 11
vivified/code/vivi_code_builtin_call.h | 3
vivified/code/vivi_code_builtin_statement.c | 11
vivified/code/vivi_code_builtin_statement.h | 3
vivified/code/vivi_code_builtin_statement_default.c | 9
vivified/code/vivi_code_builtin_statement_default.h | 2
vivified/code/vivi_code_builtin_value_call.c | 13
vivified/code/vivi_code_builtin_value_call_default.c | 5
vivified/code/vivi_code_builtin_value_call_default.h | 2
vivified/code/vivi_code_builtin_value_statement.c | 13
vivified/code/vivi_code_builtin_value_statement_default.c | 5
vivified/code/vivi_code_builtin_value_statement_default.h | 2
vivified/code/vivi_code_comment.c | 6
vivified/code/vivi_code_compiler.c | 247 ---
vivified/code/vivi_code_compiler.h | 89 -
vivified/code/vivi_code_concat.c | 15
vivified/code/vivi_code_constant.c | 1
vivified/code/vivi_code_continue.c | 3
vivified/code/vivi_code_defaults.h | 72
vivified/code/vivi_code_function.c | 68
vivified/code/vivi_code_function.h | 5
vivified/code/vivi_code_function_call.c | 28
vivified/code/vivi_code_get.c | 18
vivified/code/vivi_code_get_timer.c | 3
vivified/code/vivi_code_get_url.c | 26
vivified/code/vivi_code_if.c | 41
vivified/code/vivi_code_init_array.c | 18
vivified/code/vivi_code_init_object.c | 21
vivified/code/vivi_code_label.c | 14
vivified/code/vivi_code_return.c | 12
vivified/code/vivi_code_statement.c | 7
vivified/code/vivi_code_statement.h | 2
vivified/code/vivi_code_substring.c | 20
vivified/code/vivi_code_throw.c | 13
vivified/code/vivi_code_token.c | 14
vivified/code/vivi_code_token.h | 7
vivified/code/vivi_code_unary.c | 13
vivified/code/vivi_code_value.c | 7
vivified/code/vivi_code_value.h | 2
vivified/code/vivi_code_value_statement.c | 13
vivified/code/vivi_compiler_empty_statement.c | 4
vivified/code/vivi_decompiler.c | 4
vivified/code/vivi_parser.c | 1146 +++++++-------
55 files changed, 998 insertions(+), 1126 deletions(-)
New commits:
commit a8d64681b5e87c6cc457970eb80fcf33145b0e09
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Wed Apr 23 13:28:28 2008 +0300
Make ViviCodeFunction support named functions
diff --git a/vivified/code/vivi_code_function.c b/vivified/code/vivi_code_function.c
index 432dbeb..6ceb51d 100644
--- a/vivified/code/vivi_code_function.c
+++ b/vivified/code/vivi_code_function.c
@@ -39,6 +39,9 @@ vivi_code_function_dispose (GObject *object)
ViviCodeFunction *function = VIVI_CODE_FUNCTION (object);
guint i;
+ if (function->name != NULL)
+ g_free (function->name);
+
if (function->body)
g_object_unref (function->body);
@@ -56,7 +59,12 @@ vivi_code_function_print (ViviCodeToken *token, ViviCodePrinter*printer)
ViviCodeFunction *function = VIVI_CODE_FUNCTION (token);
guint i;
- vivi_code_printer_print (printer, "function (");
+ vivi_code_printer_print (printer, "function ");
+ if (function->name != NULL) {
+ vivi_code_printer_print (printer, function->name);
+ vivi_code_printer_print (printer, " ");
+ }
+ vivi_code_printer_print (printer, "(");
for (i = 0; i < function->arguments->len; i++) {
if (i != 0)
vivi_code_printer_print (printer, ", ");
@@ -134,9 +142,25 @@ vivi_code_function_init (ViviCodeFunction *function)
}
ViviCodeValue *
-vivi_code_function_new (void)
+vivi_code_function_new (const char *name)
{
- return VIVI_CODE_VALUE (g_object_new (VIVI_TYPE_CODE_FUNCTION, NULL));
+ ViviCodeValue *function;
+
+ function = VIVI_CODE_VALUE (g_object_new (VIVI_TYPE_CODE_FUNCTION, NULL));
+
+ VIVI_CODE_FUNCTION (function)->name = g_strdup (name);
+
+ return function;
+}
+
+void
+vivi_code_function_set_name (ViviCodeFunction *function, const char *name)
+{
+ g_return_if_fail (VIVI_IS_CODE_FUNCTION (function));
+
+ if (function->name != NULL)
+ g_free (function->name);
+ function->name = g_strdup (name);
}
void
@@ -167,6 +191,7 @@ vivi_code_function_new_from_script (SwfdecScript *script)
g_return_val_if_fail (script != NULL, NULL);
function = g_object_new (VIVI_TYPE_CODE_FUNCTION, NULL);
+ // TODO: set name
function->body = vivi_decompile_script (script);
for (i = 0; i < script->n_arguments; i++) {
diff --git a/vivified/code/vivi_code_function.h b/vivified/code/vivi_code_function.h
index 221da93..9ce708e 100644
--- a/vivified/code/vivi_code_function.h
+++ b/vivified/code/vivi_code_function.h
@@ -40,6 +40,7 @@ struct _ViviCodeFunction
{
ViviCodeValue value;
+ char * name;
GPtrArray * arguments; // char *
ViviCodeStatement * body;
};
@@ -51,9 +52,11 @@ struct _ViviCodeFunctionClass
GType vivi_code_function_get_type (void);
-ViviCodeValue * vivi_code_function_new (void);
+ViviCodeValue * vivi_code_function_new (const char *name);
ViviCodeValue * vivi_code_function_new_from_script (SwfdecScript * script);
+void vivi_code_function_set_name (ViviCodeFunction * function,
+ const char * name);
void vivi_code_function_set_body (ViviCodeFunction * function,
ViviCodeStatement * body);
void vivi_code_function_add_argument (ViviCodeFunction * function,
diff --git a/vivified/code/vivi_parser.c b/vivified/code/vivi_parser.c
index dccb91e..c3e473b 100644
--- a/vivified/code/vivi_parser.c
+++ b/vivified/code/vivi_parser.c
@@ -1471,7 +1471,7 @@ static gboolean
peek_function_expression (ParseData *data);
static ViviCodeValue *
-parse_function_expression (ParseData *data, ViviCodeStatement **statement);
+parse_function_expression (ParseData *data);
static gboolean
peek_member_expression (ParseData *data)
@@ -1490,7 +1490,8 @@ parse_member_expression (ParseData *data, ViviCodeStatement **statement)
if (peek_primary_expression (data)) {
value = parse_primary_expression (data, statement);
} else if (peek_function_expression (data)) {
- value = parse_function_expression (data, statement);
+ value = parse_function_expression (data);
+ *statement = NULL;
} else {
vivi_parser_error_unexpected_or (data, ERROR_TOKEN_PRIMARY_EXPRESSION,
ERROR_TOKEN_FUNCTION_EXPRESSION, TOKEN_NONE);
@@ -2664,12 +2665,12 @@ peek_source_element (ParseData *data);
static ViviCodeStatement *
parse_source_element (ParseData *data);
-static void
-parse_function_definition (ParseData *data, ViviCodeValue **function,
- ViviCodeValue **identifier, gboolean identifier_required)
+static ViviCodeValue *
+parse_function_definition (ParseData *data, gboolean name_required)
{
- ViviCodeValue **arguments;
+ ViviCodeValue *function, **arguments;
ViviCodeStatement *body;
+ const char *name;
guint i;
arguments = NULL;
@@ -2677,21 +2678,21 @@ parse_function_definition (ParseData *data, ViviCodeValue **function,
parse_token (data, TOKEN_FUNCTION);
- if (identifier_required) {
- *identifier = parse_identifier (data);
+ if (name_required) {
+ name = g_strdup (parse_identifier_value (data));
parse_token (data, TOKEN_PARENTHESIS_LEFT);
} else {
if (!try_parse_token (data, TOKEN_PARENTHESIS_LEFT)) {
if (peek_identifier (data)) {
- *identifier = parse_identifier (data);
+ name = g_strdup (parse_identifier_value (data));
parse_token (data, TOKEN_PARENTHESIS_LEFT);
} else {
vivi_parser_error_unexpected_or (data, TOKEN_PARENTHESIS_LEFT,
ERROR_TOKEN_IDENTIFIER, TOKEN_NONE);
- *identifier = NULL;
+ name = NULL;
}
} else {
- *identifier = NULL;
+ name = NULL;
}
}
@@ -2708,19 +2709,21 @@ parse_function_definition (ParseData *data, ViviCodeValue **function,
parse_token (data, TOKEN_BRACE_RIGHT);
- *function = vivi_code_function_new ();
+ function = vivi_code_function_new (name);
if (body != NULL) {
- vivi_code_function_set_body (VIVI_CODE_FUNCTION (*function), body);
+ vivi_code_function_set_body (VIVI_CODE_FUNCTION (function), body);
g_object_unref (body);
}
if (arguments != NULL) {
for (i = 0; arguments[i] != NULL; i++) {
- vivi_code_function_add_argument (VIVI_CODE_FUNCTION (*function),
+ vivi_code_function_add_argument (VIVI_CODE_FUNCTION (function),
vivi_code_constant_get_variable_name (VIVI_CODE_CONSTANT (
VIVI_CODE_GET (arguments[i])->name)));
}
free_value_list (arguments);
}
+
+ return function;
}
static gboolean
@@ -2733,13 +2736,10 @@ static ViviCodeStatement *
parse_function_declaration (ParseData *data)
{
ViviCodeStatement *statement;
- ViviCodeValue *function, *identifier;
+ ViviCodeValue *function;
- parse_function_definition (data, &function, &identifier, TRUE);
-
- // FIXME
- statement = vivi_parser_assignment_new (identifier, function);
- g_object_unref (identifier);
+ function = parse_function_definition (data, TRUE);
+ statement = vivi_code_value_statement_new (function);
g_object_unref (function);
return statement;
@@ -2752,21 +2752,9 @@ peek_function_expression (ParseData *data)
}
static ViviCodeValue *
-parse_function_expression (ParseData *data, ViviCodeStatement **statement)
+parse_function_expression (ParseData *data)
{
- ViviCodeValue *function, *identifier;
-
- parse_function_definition (data, &function, &identifier, FALSE);
-
- // FIXME
- if (identifier != NULL) {
- *statement = vivi_parser_assignment_new (identifier, identifier);
- g_object_unref (identifier);
- } else {
- *statement = NULL;
- }
-
- return function;
+ return parse_function_definition (data, FALSE);
}
// top
commit 3142b0a7dc7e6d6517eaac8252cf6f6bdcf43f90
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Wed Apr 23 12:09:33 2008 +0300
Make functions that parse values and statements return the value directly
diff --git a/vivified/code/vivi_parser.c b/vivified/code/vivi_parser.c
index 6e763cf..dccb91e 100644
--- a/vivified/code/vivi_parser.c
+++ b/vivified/code/vivi_parser.c
@@ -116,7 +116,7 @@ typedef struct {
typedef gboolean (*PeekFunction) (ParseData *data);
typedef ViviCodeValue * (*ParseValueFunction) (ParseData *data);
-typedef void (*ParseValueStatementFunction) (ParseData *data, ViviCodeValue **value, ViviCodeStatement **statement);
+typedef ViviCodeValue * (*ParseValueStatementFunction) (ParseData *data, ViviCodeStatement **statement);
typedef ViviCodeStatement * (*ParseStatementFunction) (ParseData *data);
static void
@@ -875,9 +875,8 @@ parse_property_name (ParseData *data)
static gboolean
peek_assignment_expression (ParseData *data);
-static void
-parse_assignment_expression (ParseData *data, ViviCodeValue **value,
- ViviCodeStatement **statement);
+static ViviCodeValue *
+parse_assignment_expression (ParseData *data, ViviCodeStatement **statement);
static gboolean
peek_array_literal (ParseData *data)
@@ -885,36 +884,35 @@ peek_array_literal (ParseData *data)
return peek_token (data, TOKEN_BRACKET_LEFT);
}
-static void
-parse_array_literal (ParseData *data, ViviCodeValue **value,
- ViviCodeStatement **statement)
+static ViviCodeValue *
+parse_array_literal (ParseData *data, ViviCodeStatement **statement)
{
- ViviCodeValue *member;
+ ViviCodeValue *value, *member;
ViviCodeStatement *statement_new;
vivi_parser_start_code_token (data);
- *value = vivi_code_init_array_new ();
+ value = vivi_code_init_array_new ();
*statement = NULL;
parse_token (data, TOKEN_BRACKET_LEFT);
while (TRUE) {
if (try_parse_token (data, TOKEN_BRACKET_RIGHT)) {
- vivi_code_init_array_add_variable (VIVI_CODE_INIT_ARRAY (*value),
+ vivi_code_init_array_add_variable (VIVI_CODE_INIT_ARRAY (value),
vivi_code_undefined_new ());
break;
} else if (try_parse_token (data, TOKEN_COMMA)) {
- vivi_code_init_array_add_variable (VIVI_CODE_INIT_ARRAY (*value),
+ vivi_code_init_array_add_variable (VIVI_CODE_INIT_ARRAY (value),
vivi_code_undefined_new ());
}
else if (peek_assignment_expression (data))
{
- parse_assignment_expression (data, &member, &statement_new);
+ member = parse_assignment_expression (data, &statement_new);
*statement = vivi_parser_join_statements (*statement, statement_new);
- vivi_code_init_array_add_variable (VIVI_CODE_INIT_ARRAY (*value),
+ vivi_code_init_array_add_variable (VIVI_CODE_INIT_ARRAY (value),
member);
g_object_unref (member);
@@ -932,7 +930,9 @@ parse_array_literal (ParseData *data, ViviCodeValue **value,
}
}
- vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (*value));
+ vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (value));
+
+ return value;
}
static gboolean
@@ -941,13 +941,14 @@ peek_object_literal (ParseData *data)
return peek_token (data, TOKEN_BRACE_LEFT);
}
-static void
-parse_object_literal (ParseData *data, ViviCodeValue **value,
- ViviCodeStatement **statement)
+static ViviCodeValue *
+parse_object_literal (ParseData *data, ViviCodeStatement **statement)
{
+ ViviCodeValue *value;
+
vivi_parser_start_code_token (data);
- *value = vivi_code_init_object_new ();
+ value = vivi_code_init_object_new ();
*statement = NULL;
parse_token (data, TOKEN_BRACE_LEFT);
@@ -959,18 +960,20 @@ parse_object_literal (ParseData *data, ViviCodeValue **value,
property = parse_property_name (data);
parse_token (data, TOKEN_COLON);
- parse_assignment_expression (data, &initializer, &statement_new);
+ initializer = parse_assignment_expression (data, &statement_new);
*statement = vivi_parser_join_statements (*statement, statement_new);
- vivi_code_init_object_add_variable (VIVI_CODE_INIT_OBJECT (*value),
+ vivi_code_init_object_add_variable (VIVI_CODE_INIT_OBJECT (value),
property, initializer);
} while (try_parse_token (data, TOKEN_COMMA));
}
parse_token (data, TOKEN_BRACE_RIGHT);
- vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (*value));
+ vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (value));
+
+ return value;
}
// misc
@@ -992,7 +995,7 @@ parse_variable_declaration (ParseData *data)
identifier = parse_identifier (data);
if (try_parse_token (data, TOKEN_ASSIGN)) {
- parse_assignment_expression (data, &value, &statement_right);
+ value = parse_assignment_expression (data, &statement_right);
} else {
vivi_parser_start_code_token (data);
@@ -1024,14 +1027,14 @@ parse_get_url2 (ParseData *data, gboolean require_two, gboolean level,
parse_token (data, TOKEN_PARENTHESIS_LEFT);
- parse_assignment_expression (data, &url, &statement);
+ url = parse_assignment_expression (data, &statement);
if (require_two || peek_token (data, TOKEN_COMMA)) {
parse_token (data, TOKEN_COMMA);
// target
if (!level) {
- parse_assignment_expression (data, &target, &expression_statement);
+ target = parse_assignment_expression (data, &expression_statement);
statement =
vivi_parser_join_statements (statement, expression_statement);
} else {
@@ -1043,7 +1046,7 @@ parse_get_url2 (ParseData *data, gboolean require_two, gboolean level,
g_free (level_name);
} else {
// TODO
- parse_assignment_expression (data, &target, &expression_statement);
+ target = parse_assignment_expression (data, &expression_statement);
statement =
vivi_parser_join_statements (statement, expression_statement);
}
@@ -1122,63 +1125,64 @@ parse_load_variables_num (ParseData *data)
return parse_get_url2 (data, TRUE, TRUE, FALSE, TRUE);
}
-static void
-parse_concat (ParseData *data, ViviCodeValue **value,
- ViviCodeStatement **statement)
+static ViviCodeValue *
+parse_concat (ParseData *data, ViviCodeStatement **statement)
{
- ViviCodeValue *first, *second;
+ ViviCodeValue *value, *first, *second;
ViviCodeStatement *expression_statement;
parse_token (data, TOKEN_PARENTHESIS_LEFT);
- parse_assignment_expression (data, &first, statement);
+ first = parse_assignment_expression (data, statement);
parse_token (data, TOKEN_COMMA);
- parse_assignment_expression (data, &second, &expression_statement);
+ second = parse_assignment_expression (data, &expression_statement);
*statement = vivi_parser_join_statements (*statement, expression_statement);
parse_token (data, TOKEN_PARENTHESIS_RIGHT);
- *value = vivi_code_concat_new (first, second);
+ value = vivi_code_concat_new (first, second);
g_object_unref (first);
g_object_unref (second);
+
+ return value;
}
-static void
-parse_substring (ParseData *data, ViviCodeValue **value,
- ViviCodeStatement **statement)
+static ViviCodeValue *
+parse_substring (ParseData *data, ViviCodeStatement **statement)
{
- ViviCodeValue *string, *index_, *count;
+ ViviCodeValue *value, *string, *index_, *count;
ViviCodeStatement *expression_statement;
parse_token (data, TOKEN_PARENTHESIS_LEFT);
- parse_assignment_expression (data, &string, statement);
+ string = parse_assignment_expression (data, statement);
parse_token (data, TOKEN_COMMA);
- parse_assignment_expression (data, &index_, &expression_statement);
+ index_ = parse_assignment_expression (data, &expression_statement);
*statement = vivi_parser_join_statements (*statement, expression_statement);
parse_token (data, TOKEN_COMMA);
- parse_assignment_expression (data, &count, &expression_statement);
+ count = parse_assignment_expression (data, &expression_statement);
*statement = vivi_parser_join_statements (*statement, expression_statement);
parse_token (data, TOKEN_PARENTHESIS_RIGHT);
- *value = vivi_code_substring_new (string, index_, count);
+ value = vivi_code_substring_new (string, index_, count);
g_object_unref (string);
g_object_unref (index_);
g_object_unref (count);
+
+ return value;
}
-static void
-parse_target_path (ParseData *data, ViviCodeValue **value,
- ViviCodeStatement **statement)
+static ViviCodeValue *
+parse_target_path (ParseData *data, ViviCodeStatement **statement)
{
- ViviCodeValue *identifier;
+ ViviCodeValue *value, *identifier;
*statement = NULL;
@@ -1188,8 +1192,10 @@ parse_target_path (ParseData *data, ViviCodeValue **value,
parse_token (data, TOKEN_PARENTHESIS_RIGHT);
- *value = vivi_code_target_path_new (identifier);
+ value = vivi_code_target_path_new (identifier);
g_object_unref (identifier);
+
+ return value;
}
typedef ViviCodeStatement *(*NewStatementVoid) (void);
@@ -1273,13 +1279,12 @@ peek_builtin_call (ParseData *data)
return FALSE;
}
-static void
-parse_builtin_call (ParseData *data, ViviCodeValue **value,
- ViviCodeStatement **statement)
+static ViviCodeValue *
+parse_builtin_call (ParseData *data, ViviCodeStatement **statement)
{
guint i;
const char *identifier;
- ViviCodeValue *argument;
+ ViviCodeValue *value, *argument;
identifier = parse_identifier_value (data);
@@ -1292,25 +1297,25 @@ parse_builtin_call (ParseData *data, ViviCodeValue **value,
i = 0;
}
- if (builtin_calls[i].parse_custom != NULL) {
- builtin_calls[i].parse_custom (data, value, statement);
- return;
- }
-//
+ if (builtin_calls[i].parse_custom != NULL)
+ return builtin_calls[i].parse_custom (data, statement);
+
parse_token (data, TOKEN_PARENTHESIS_LEFT);
if (builtin_calls[i].constructor_value != NULL)
- parse_assignment_expression (data, &argument, statement);
+ argument = parse_assignment_expression (data, statement);
parse_token (data, TOKEN_PARENTHESIS_RIGHT);
if (builtin_calls[i].constructor_value != NULL) {
- *value = builtin_calls[i].constructor_value (argument);
+ value = builtin_calls[i].constructor_value (argument);
g_object_unref (argument);
} else {
g_assert (builtin_calls[i].constructor_void != NULL);
- *value = builtin_calls[i].constructor_void ();
+ value = builtin_calls[i].constructor_void ();
}
+
+ return value;
}
@@ -1361,7 +1366,7 @@ parse_builtin_statement (ParseData *data)
parse_token (data, TOKEN_PARENTHESIS_LEFT);
if (builtin_statements[i].constructor_value != NULL)
- parse_assignment_expression (data, &argument, &argument_statement);
+ argument = parse_assignment_expression (data, &argument_statement);
parse_token (data, TOKEN_PARENTHESIS_RIGHT);
@@ -1410,60 +1415,63 @@ peek_primary_expression (ParseData *data)
return FALSE;
}
-static void
-parse_expression (ParseData *data, ViviCodeValue **value,
- ViviCodeStatement **statement);
+static ViviCodeValue *
+parse_expression (ParseData *data, ViviCodeStatement **statement);
-static void
-parse_primary_expression (ParseData *data, ViviCodeValue **value,
- ViviCodeStatement **statement)
+static ViviCodeValue *
+parse_primary_expression (ParseData *data, ViviCodeStatement **statement)
{
+ ViviCodeValue *value;
guint i;
vivi_parser_start_code_token (data);
if (try_parse_token (data, TOKEN_THIS)) {
- *value = vivi_code_get_new_name ("this");
+ value = vivi_code_get_new_name ("this");
*statement = NULL;
- vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (*value));
- return;
+ vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (value));
+
+ return value;
}
if (try_parse_token (data, TOKEN_PARENTHESIS_LEFT)) {
- parse_expression (data, value, statement);
+ value = parse_expression (data, statement);
parse_token (data, TOKEN_PARENTHESIS_RIGHT);
- vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (*value));
- return;
+ vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (value));
+
+ return value;
}
for (i = 0; primary_expression_functions[i].peek != NULL; i++) {
if (primary_expression_functions[i].peek (data)) {
if (primary_expression_functions[i].parse_value != NULL) {
- *value = primary_expression_functions[i].parse_value (data);
+ value = primary_expression_functions[i].parse_value (data);
*statement = NULL;
} else {
- primary_expression_functions[i].parse_value_statement (data, value,
+ value = primary_expression_functions[i].parse_value_statement (data,
statement);
}
vivi_parser_end_code_token (data, NULL);
- return;
+
+ return value;
}
}
vivi_parser_error_unexpected (data, ERROR_TOKEN_PRIMARY_EXPRESSION);
- *value = vivi_code_undefined_new ();
+ value = vivi_code_undefined_new ();
*statement = NULL;
- vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (*value));
+ vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (value));
+
+ return value;
}
static gboolean
peek_function_expression (ParseData *data);
-static void
-parse_function_expression (ParseData *data, ViviCodeValue **value,
- ViviCodeStatement **statement);
+static ViviCodeValue *
+parse_function_expression (ParseData *data, ViviCodeStatement **statement);
static gboolean
peek_member_expression (ParseData *data)
@@ -1471,34 +1479,33 @@ peek_member_expression (ParseData *data)
return (peek_primary_expression (data) || peek_function_expression (data));
}
-static void
-parse_member_expression (ParseData *data, ViviCodeValue **value,
- ViviCodeStatement **statement)
+static ViviCodeValue *
+parse_member_expression (ParseData *data, ViviCodeStatement **statement)
{
- ViviCodeValue *member;
+ ViviCodeValue *value, *member;
ViviCodeStatement *statement_member;
vivi_parser_start_code_token (data);
if (peek_primary_expression (data)) {
- parse_primary_expression (data, value, statement);
+ value = parse_primary_expression (data, statement);
} else if (peek_function_expression (data)) {
- parse_function_expression (data, value, statement);
+ value = parse_function_expression (data, statement);
} else {
vivi_parser_error_unexpected_or (data, ERROR_TOKEN_PRIMARY_EXPRESSION,
ERROR_TOKEN_FUNCTION_EXPRESSION, TOKEN_NONE);
- *value = vivi_code_undefined_new ();
+ value = vivi_code_undefined_new ();
*statement = NULL;
vivi_parser_duplicate_code_token (data);
- vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (*value));
+ vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (value));
}
while (TRUE) {
ViviCodeValue *tmp;
if (try_parse_token (data, TOKEN_BRACKET_LEFT)) {
- parse_expression (data, &member, &statement_member);
+ member = parse_expression (data, &statement_member);
*statement = vivi_parser_join_statements (*statement, statement_member);
@@ -1507,16 +1514,16 @@ parse_member_expression (ParseData *data, ViviCodeValue **value,
member = parse_identifier (data);
} else {
vivi_parser_end_code_token (data, NULL);
- return;
+ return value;
}
- tmp = *value;
- *value = vivi_parser_get_new (tmp, member);
+ tmp = value;
+ value = vivi_parser_get_new (tmp, member);
g_object_unref (tmp);
g_object_unref (member);
vivi_parser_duplicate_code_token (data);
- vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (*value));
+ vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (value));
}
g_assert_not_reached ();
@@ -1529,11 +1536,11 @@ peek_left_hand_side_expression (ParseData *data)
}
-static void
-parse_left_hand_side_expression (ParseData *data, ViviCodeValue **value,
+static ViviCodeValue *
+parse_left_hand_side_expression (ParseData *data,
ViviCodeStatement **statement)
{
- ViviCodeValue *name;
+ ViviCodeValue *value, *name;
ViviCodeValue **arguments;
ViviCodeStatement *argument_statement;
guint i;
@@ -1541,25 +1548,26 @@ parse_left_hand_side_expression (ParseData *data, ViviCodeValue **value,
vivi_parser_start_code_token (data);
if (try_parse_token (data, TOKEN_NEW)) {
- parse_left_hand_side_expression (data, value, statement);
+ value = parse_left_hand_side_expression (data, statement);
- if (!VIVI_IS_CODE_FUNCTION_CALL (*value)) {
- ViviCodeValue *tmp = VIVI_CODE_VALUE (*value);
- *value = vivi_parser_function_call_new (tmp);
+ if (!VIVI_IS_CODE_FUNCTION_CALL (value)) {
+ ViviCodeValue *tmp = value;
+ value = vivi_parser_function_call_new (tmp);
g_object_unref (tmp);
}
- vivi_code_function_call_set_construct (VIVI_CODE_FUNCTION_CALL (*value),
+ vivi_code_function_call_set_construct (VIVI_CODE_FUNCTION_CALL (value),
TRUE);
- vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (*value));
- return;
+ vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (value));
+
+ return value;
}
if (peek_builtin_call (data)) {
- parse_builtin_call (data, value, statement);
+ value = parse_builtin_call (data, statement);
} else {
- parse_member_expression (data, value, statement);
+ value = parse_member_expression (data, statement);
}
while (try_parse_token (data, TOKEN_PARENTHESIS_LEFT)) {
@@ -1576,23 +1584,25 @@ parse_left_hand_side_expression (ParseData *data, ViviCodeValue **value,
arguments = NULL;
}
- name = *value;
- *value = vivi_parser_function_call_new (name);
+ name = value;
+ value = vivi_parser_function_call_new (name);
g_object_unref (name);
if (arguments != NULL) {
for (i = 0; arguments[i] != NULL; i++) {
- vivi_code_function_call_add_argument (VIVI_CODE_FUNCTION_CALL (*value),
+ vivi_code_function_call_add_argument (VIVI_CODE_FUNCTION_CALL (value),
arguments[i]);
}
free_value_list (arguments);
}
vivi_parser_duplicate_code_token (data);
- vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (*value));
+ vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (value));
}
vivi_parser_end_code_token (data, NULL);
+
+ return value;
}
static gboolean
@@ -1601,21 +1611,20 @@ peek_postfix_expression (ParseData *data)
return peek_left_hand_side_expression (data);
}
-static void
-parse_postfix_expression (ParseData *data, ViviCodeValue **value,
- ViviCodeStatement **statement)
+static ViviCodeValue *
+parse_postfix_expression (ParseData *data, ViviCodeStatement **statement)
{
ViviCodeStatement *assignment;
- ViviCodeValue *operation, *one, *temporary;
+ ViviCodeValue *value, *operation, *one, *temporary;
gboolean add;
vivi_parser_start_code_token (data);
- parse_left_hand_side_expression (data, value, statement);
+ value = parse_left_hand_side_expression (data, statement);
if (peek_line_terminator (data)) {
vivi_parser_end_code_token (data, NULL);
- return;
+ return value;
}
if (try_parse_token (data, TOKEN_INCREASE)) {
@@ -1624,23 +1633,23 @@ parse_postfix_expression (ParseData *data, ViviCodeValue **value,
add = FALSE;
} else {
vivi_parser_end_code_token (data, NULL);
- return;
+ return value;
}
// FIXME: Correct?
- if (!vivi_parser_value_is_left_hand_side (*value)) {
+ if (!vivi_parser_value_is_left_hand_side (value)) {
vivi_parser_error (data,
"Invalid left-hand side expression for INCREASE/DECREASE");
}
one = vivi_code_number_new (1);
- operation = (add ? vivi_code_add_new : vivi_code_subtract_new) (*value, one);
+ operation = (add ? vivi_code_add_new : vivi_code_subtract_new) (value, one);
g_object_unref (one);
vivi_parser_duplicate_code_token (data);
vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (operation));
- assignment = vivi_parser_assignment_new (*value, operation);
+ assignment = vivi_parser_assignment_new (value, operation);
g_object_unref (operation);
vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (assignment));
@@ -1648,10 +1657,12 @@ parse_postfix_expression (ParseData *data, ViviCodeValue **value,
temporary = vivi_compiler_get_temporary_new ();
*statement = vivi_parser_join_statements (*statement,
vivi_parser_join_statements (
- vivi_parser_assignment_new (temporary, *value), assignment));
+ vivi_parser_assignment_new (temporary, value), assignment));
+
+ g_object_unref (value);
+ value = temporary;
- g_object_unref (*value);
- *value = temporary;
+ return value;
}
static gboolean
@@ -1676,11 +1687,10 @@ peek_unary_expression (ParseData *data)
g_assert_not_reached ();
}
-static void
-parse_unary_expression (ParseData *data, ViviCodeValue **value,
- ViviCodeStatement **statement)
+static ViviCodeValue *
+parse_unary_expression (ParseData *data, ViviCodeStatement **statement)
{
- ViviCodeValue *tmp, *one;
+ ViviCodeValue *value, *tmp, *one;
vivi_parser_scanner_peek_next_token (data->scanner);
switch ((guint)data->scanner->next_token) {
@@ -1693,22 +1703,23 @@ parse_unary_expression (ParseData *data, ViviCodeValue **value,
vivi_parser_scanner_get_next_token (data->scanner);
- parse_unary_expression (data, value, statement);
+ value = parse_unary_expression (data, statement);
// FIXME: Correct?
- if (!vivi_parser_value_is_left_hand_side (*value)) {
+ if (!vivi_parser_value_is_left_hand_side (value)) {
vivi_parser_error (data,
"Invalid left-hand side expression for INCREASE/DECREASE");
}
one = vivi_code_number_new (1);
- tmp = (data->scanner->next_token == TOKEN_INCREASE ? vivi_code_add_new : vivi_code_subtract_new) (*value, one);
+ tmp = (data->scanner->next_token == TOKEN_INCREASE ?
+ vivi_code_add_new : vivi_code_subtract_new) (value, one);
g_object_unref (one);
vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (tmp));
*statement = vivi_parser_join_statements (*statement,
- vivi_parser_assignment_new (*value, tmp));
+ vivi_parser_assignment_new (value, tmp));
g_object_unref (tmp);
break;
/*case TOKEN_PLUS:
@@ -1719,18 +1730,20 @@ parse_unary_expression (ParseData *data, ViviCodeValue **value,
vivi_parser_scanner_get_next_token (data->scanner);
- parse_unary_expression (data, value, statement);
+ value = parse_unary_expression (data, statement);
- tmp = VIVI_CODE_VALUE (*value);
- *value = vivi_code_unary_new (tmp, '!');
+ tmp = VIVI_CODE_VALUE (value);
+ value = vivi_code_unary_new (tmp, '!');
g_object_unref (tmp);
vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (tmp));
break;
default:
- parse_postfix_expression (data, value, statement);
+ value = parse_postfix_expression (data, statement);
break;
}
+
+ return value;
}
typedef enum {
@@ -1739,12 +1752,12 @@ typedef enum {
PASS_LOGICAL_AND
} ParseOperatorPass;
-static void
-parse_operator_expression (ParseData *data, ViviCodeValue **value,
- ViviCodeStatement **statement, const ViviParserScannerToken *tokens,
- ParseOperatorPass pass, ParseValueStatementFunction next_parse_function)
+static ViviCodeValue *
+parse_operator_expression (ParseData *data, ViviCodeStatement **statement,
+ const ViviParserScannerToken *tokens, ParseOperatorPass pass,
+ ParseValueStatementFunction next_parse_function)
{
- ViviCodeValue *left, *right;
+ ViviCodeValue *value, *left, *right;
ViviCodeStatement *statement_right;
guint i, j;
static const struct {
@@ -1780,25 +1793,25 @@ parse_operator_expression (ParseData *data, ViviCodeValue **value,
vivi_parser_start_code_token (data);
- next_parse_function (data, value, statement);
+ value = next_parse_function (data, statement);
again:
for (i = 0; tokens[i] != TOKEN_NONE; i++) {
if (try_parse_token (data, tokens[i])) {
- next_parse_function (data, &right, &statement_right);
+ right = next_parse_function (data, &statement_right);
if (statement_right != NULL) {
ViviCodeStatement *tmp;
switch (pass) {
case PASS_LOGICAL_OR:
- tmp = vivi_code_if_new (vivi_code_unary_new (*value, '!'));
+ tmp = vivi_code_if_new (vivi_code_unary_new (value, '!'));
vivi_code_if_set_if (VIVI_CODE_IF (tmp), statement_right);
g_object_unref (statement_right);
statement_right = tmp;
break;
case PASS_LOGICAL_AND:
- tmp = vivi_code_if_new (*value);
+ tmp = vivi_code_if_new (value);
vivi_code_if_set_if (VIVI_CODE_IF (tmp), statement_right);
g_object_unref (statement_right);
statement_right = tmp;
@@ -1813,17 +1826,17 @@ again:
*statement = vivi_parser_join_statements (*statement, statement_right);
}
- left = VIVI_CODE_VALUE (*value);
+ left = VIVI_CODE_VALUE (value);
for (j = 0; j < G_N_ELEMENTS (table); j++) {
if (tokens[i] != table[j].token)
continue;
- *value = table[j].func (left, VIVI_CODE_VALUE (right));
+ value = table[j].func (left, VIVI_CODE_VALUE (right));
g_object_unref (left);
g_object_unref (right);
vivi_parser_duplicate_code_token (data);
- vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (*value));
+ vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (value));
goto again;
}
@@ -1832,6 +1845,8 @@ again:
}
vivi_parser_end_code_token (data, NULL);
+
+ return value;
}
static gboolean
@@ -1840,14 +1855,14 @@ peek_multiplicative_expression (ParseData *data)
return peek_unary_expression (data);
}
-static void
-parse_multiplicative_expression (ParseData *data, ViviCodeValue **value,
+static ViviCodeValue *
+parse_multiplicative_expression (ParseData *data,
ViviCodeStatement **statement)
{
static const ViviParserScannerToken tokens[] = { TOKEN_MULTIPLY,
TOKEN_DIVIDE, TOKEN_REMAINDER, TOKEN_NONE };
- parse_operator_expression (data, value, statement, tokens, PASS_ALWAYS,
+ return parse_operator_expression (data, statement, tokens, PASS_ALWAYS,
parse_unary_expression);
}
@@ -1857,14 +1872,13 @@ peek_additive_expression (ParseData *data)
return peek_multiplicative_expression (data);
}
-static void
-parse_additive_expression (ParseData *data, ViviCodeValue **value,
- ViviCodeStatement **statement)
+static ViviCodeValue *
+parse_additive_expression (ParseData *data, ViviCodeStatement **statement)
{
static const ViviParserScannerToken tokens[] = { TOKEN_PLUS, TOKEN_MINUS,
TOKEN_NONE };
- parse_operator_expression (data, value, statement, tokens, PASS_ALWAYS,
+ return parse_operator_expression (data, statement, tokens, PASS_ALWAYS,
parse_multiplicative_expression);
}
@@ -1874,14 +1888,13 @@ peek_shift_expression (ParseData *data)
return peek_additive_expression (data);
}
-static void
-parse_shift_expression (ParseData *data, ViviCodeValue **value,
- ViviCodeStatement **statement)
+static ViviCodeValue *
+parse_shift_expression (ParseData *data, ViviCodeStatement **statement)
{
static const ViviParserScannerToken tokens[] = { TOKEN_SHIFT_LEFT,
TOKEN_SHIFT_RIGHT, TOKEN_SHIFT_RIGHT_UNSIGNED, TOKEN_NONE };
- parse_operator_expression (data, value, statement, tokens, PASS_ALWAYS,
+ return parse_operator_expression (data, statement, tokens, PASS_ALWAYS,
parse_additive_expression);
}
@@ -1891,15 +1904,14 @@ peek_relational_expression (ParseData *data)
return peek_shift_expression (data);
}
-static void
-parse_relational_expression (ParseData *data, ViviCodeValue **value,
- ViviCodeStatement **statement)
+static ViviCodeValue *
+parse_relational_expression (ParseData *data, ViviCodeStatement **statement)
{
static const ViviParserScannerToken tokens[] = { TOKEN_LESS_THAN,
TOKEN_GREATER_THAN, /*TOKEN_LESS_THAN_OR_EQUAL,
TOKEN_EQUAL_OR_GREATER_THAN, TOKEN_INSTANCEOF, TOKEN_IN,*/ TOKEN_NONE };
- parse_operator_expression (data, value, statement, tokens, PASS_ALWAYS,
+ return parse_operator_expression (data, statement, tokens, PASS_ALWAYS,
parse_shift_expression);
}
@@ -1909,15 +1921,14 @@ peek_equality_expression (ParseData *data)
return peek_relational_expression (data);
}
-static void
-parse_equality_expression (ParseData *data, ViviCodeValue **value,
- ViviCodeStatement **statement)
+static ViviCodeValue *
+parse_equality_expression (ParseData *data, ViviCodeStatement **statement)
{
static const ViviParserScannerToken tokens[] = { TOKEN_EQUAL,
/*TOKEN_NOT_EQUAL,*/ TOKEN_STRICT_EQUAL, /*TOKEN_NOT_STRICT_EQUAL,*/
TOKEN_NONE };
- parse_operator_expression (data, value, statement, tokens, PASS_ALWAYS,
+ return parse_operator_expression (data, statement, tokens, PASS_ALWAYS,
parse_relational_expression);
}
@@ -1927,14 +1938,13 @@ peek_bitwise_and_expression (ParseData *data)
return peek_equality_expression (data);
}
-static void
-parse_bitwise_and_expression (ParseData *data, ViviCodeValue **value,
- ViviCodeStatement **statement)
+static ViviCodeValue *
+parse_bitwise_and_expression (ParseData *data, ViviCodeStatement **statement)
{
static const ViviParserScannerToken tokens[] = { TOKEN_BITWISE_AND,
TOKEN_NONE };
- parse_operator_expression (data, value, statement, tokens, PASS_ALWAYS,
+ return parse_operator_expression (data, statement, tokens, PASS_ALWAYS,
parse_equality_expression);
}
@@ -1944,14 +1954,13 @@ peek_bitwise_xor_expression (ParseData *data)
return peek_bitwise_and_expression (data);
}
-static void
-parse_bitwise_xor_expression (ParseData *data, ViviCodeValue **value,
- ViviCodeStatement **statement)
+static ViviCodeValue *
+parse_bitwise_xor_expression (ParseData *data, ViviCodeStatement **statement)
{
static const ViviParserScannerToken tokens[] = { TOKEN_BITWISE_XOR,
TOKEN_NONE };
- parse_operator_expression (data, value, statement, tokens, PASS_ALWAYS,
+ return parse_operator_expression (data, statement, tokens, PASS_ALWAYS,
parse_bitwise_and_expression);
}
@@ -1961,14 +1970,13 @@ peek_bitwise_or_expression (ParseData *data)
return peek_bitwise_xor_expression (data);
}
-static void
-parse_bitwise_or_expression (ParseData *data, ViviCodeValue **value,
- ViviCodeStatement **statement)
+static ViviCodeValue *
+parse_bitwise_or_expression (ParseData *data, ViviCodeStatement **statement)
{
static const ViviParserScannerToken tokens[] = { TOKEN_BITWISE_OR,
TOKEN_NONE };
- parse_operator_expression (data, value, statement, tokens, PASS_ALWAYS,
+ return parse_operator_expression (data, statement, tokens, PASS_ALWAYS,
parse_bitwise_xor_expression);
}
@@ -1978,14 +1986,13 @@ peek_logical_and_expression (ParseData *data)
return peek_bitwise_or_expression (data);
}
-static void
-parse_logical_and_expression (ParseData *data, ViviCodeValue **value,
- ViviCodeStatement **statement)
+static ViviCodeValue *
+parse_logical_and_expression (ParseData *data, ViviCodeStatement **statement)
{
static const ViviParserScannerToken tokens[] = { TOKEN_LOGICAL_AND,
TOKEN_NONE };
- parse_operator_expression (data, value, statement, tokens, PASS_LOGICAL_AND,
+ return parse_operator_expression (data, statement, tokens, PASS_LOGICAL_AND,
parse_bitwise_or_expression);
}
@@ -1995,14 +2002,13 @@ peek_logical_or_expression (ParseData *data)
return peek_logical_and_expression (data);
}
-static void
-parse_logical_or_expression (ParseData *data, ViviCodeValue **value,
- ViviCodeStatement **statement)
+static ViviCodeValue *
+parse_logical_or_expression (ParseData *data, ViviCodeStatement **statement)
{
static const ViviParserScannerToken tokens[] = { TOKEN_LOGICAL_OR,
TOKEN_NONE };
- parse_operator_expression (data, value, statement, tokens, PASS_LOGICAL_OR,
+ return parse_operator_expression (data, statement, tokens, PASS_LOGICAL_OR,
parse_logical_and_expression);
}
@@ -2012,13 +2018,12 @@ peek_conditional_expression (ParseData *data)
return peek_logical_or_expression (data);
}
-static void
-parse_conditional_expression (ParseData *data, ViviCodeValue **value,
- ViviCodeStatement **statement)
+static ViviCodeValue *
+parse_conditional_expression (ParseData *data, ViviCodeStatement **statement)
{
//ViviCodeStatement *if_statement, *else_statement;
- parse_logical_or_expression (data, value, statement);
+ return parse_logical_or_expression (data, statement);
#if 0
if (!parse_token (data, TOKEN_QUESTION_MARK)) {
@@ -2062,22 +2067,21 @@ peek_assignment_expression (ParseData *data)
return peek_conditional_expression (data);
}
-static void
-parse_assignment_expression (ParseData *data, ViviCodeValue **value,
- ViviCodeStatement **statement)
+static ViviCodeValue *
+parse_assignment_expression (ParseData *data, ViviCodeStatement **statement)
{
- ViviCodeValue *right;
+ ViviCodeValue *value, *right;
ViviCodeStatement *assignment, *statement_right;
ViviCodeValue * (* func) (ViviCodeValue *, ViviCodeValue *);
vivi_parser_start_code_token (data);
- parse_conditional_expression (data, value, statement);
+ value = parse_conditional_expression (data, statement);
// FIXME: Correct?
- if (!vivi_parser_value_is_left_hand_side (*value)) {
+ if (!vivi_parser_value_is_left_hand_side (value)) {
vivi_parser_end_code_token (data, NULL);
- return;
+ return value;
}
vivi_parser_scanner_peek_next_token (data->scanner);
@@ -2119,18 +2123,17 @@ parse_assignment_expression (ParseData *data, ViviCodeValue **value,
func = NULL;
break;
default:
- return;
+ return value;
}
-
+
vivi_parser_scanner_get_next_token (data->scanner);
- parse_assignment_expression (data, &right, &statement_right);
+ right = parse_assignment_expression (data, &statement_right);
if (func != NULL) {
- assignment = vivi_parser_assignment_new (*value,
- func (*value, right));
+ assignment = vivi_parser_assignment_new (value, func (value, right));
} else {
- assignment = vivi_parser_assignment_new (*value, right);
+ assignment = vivi_parser_assignment_new (value, right);
}
g_object_unref (right);
@@ -2138,6 +2141,8 @@ parse_assignment_expression (ParseData *data, ViviCodeValue **value,
*statement = vivi_parser_join_statements (*statement,
vivi_parser_join_statements (statement_right, assignment));
+
+ return value;
}
static gboolean
@@ -2146,21 +2151,23 @@ peek_expression (ParseData *data)
return peek_assignment_expression (data);
}
-static void
-parse_expression (ParseData *data, ViviCodeValue **value,
- ViviCodeStatement **statement)
+static ViviCodeValue *
+parse_expression (ParseData *data, ViviCodeStatement **statement)
{
+ ViviCodeValue *value;
ViviCodeStatement *statement_one;
- *value = NULL;
+ value = NULL;
*statement = NULL;
do {
- if (*value != NULL)
- g_object_unref (*value);
- parse_assignment_expression (data, value, &statement_one);
+ if (value != NULL)
+ g_object_unref (value);
+ value = parse_assignment_expression (data, &statement_one);
*statement = vivi_parser_join_statements (*statement, statement_one);
} while (try_parse_token (data, TOKEN_COMMA));
+
+ return value;
}
// statement
@@ -2234,7 +2241,7 @@ parse_throw_statement (ParseData *data)
ERROR_TOKEN_EXPRESSION);
}
- parse_expression (data, &value, &expression_statement);
+ value = parse_expression (data, &expression_statement);
statement = vivi_code_throw_new (value);
g_object_unref (value);
@@ -2265,7 +2272,7 @@ parse_return_statement (ParseData *data)
ViviCodeValue *value;
ViviCodeStatement *expression_statement;
- parse_expression (data, &value, &expression_statement);
+ value = parse_expression (data, &expression_statement);
vivi_code_return_set_value (VIVI_CODE_RETURN (statement), value);
g_object_unref (value);
@@ -2303,7 +2310,7 @@ parse_iteration_statement (ParseData *data)
loop_statement = parse_statement (data);
parse_token (data, TOKEN_WHILE);
parse_token (data, TOKEN_PARENTHESIS_LEFT);
- parse_expression (data, &condition, &condition_statement);
+ condition = parse_expression (data, &condition_statement);
parse_token (data, TOKEN_PARENTHESIS_RIGHT);
parse_automatic_semicolon (data);
@@ -2312,7 +2319,7 @@ parse_iteration_statement (ParseData *data)
else if (try_parse_token (data, TOKEN_WHILE))
{
parse_token (data, TOKEN_PARENTHESIS_LEFT);
- parse_expression (data, &condition, &condition_statement);
+ condition = parse_expression (data, &condition_statement);
parse_token (data, TOKEN_PARENTHESIS_RIGHT);
loop_statement = parse_statement (data);
@@ -2347,7 +2354,7 @@ parse_iteration_statement (ParseData *data)
pre_statement = NULL;
} else {
// FIXME: no in
- parse_expression (data, &pre_value, &pre_statement);
+ pre_value = parse_expression (data, &pre_statement);
}
}
@@ -2359,14 +2366,14 @@ parse_iteration_statement (ParseData *data)
condition = vivi_code_boolean_new (TRUE);
condition_statement = NULL;
} else {
- parse_expression (data, &condition, &condition_statement);
+ condition = parse_expression (data, &condition_statement);
parse_token (data, TOKEN_SEMICOLON);
}
if (peek_token (data, TOKEN_PARENTHESIS_RIGHT)) {
post_statement = NULL;
} else {
- parse_expression (data, &pre_value, &post_statement);
+ pre_value = parse_expression (data, &post_statement);
g_object_unref (pre_value);
}
} else if (pre_value != NULL && try_parse_token (data, TOKEN_IN)) {
@@ -2452,7 +2459,7 @@ parse_if_statement (ParseData *data)
parse_token (data, TOKEN_IF);
parse_token (data, TOKEN_PARENTHESIS_LEFT);
- parse_expression (data, &condition, &pre_statement);
+ condition = parse_expression (data, &pre_statement);
parse_token (data, TOKEN_PARENTHESIS_RIGHT);
if_statement = parse_statement (data);
@@ -2496,7 +2503,7 @@ parse_expression_statement (ParseData *data)
if (peek_token (data, TOKEN_BRACE_LEFT) || peek_token (data, TOKEN_FUNCTION))
vivi_parser_error_unexpected (data, ERROR_TOKEN_EXPRESSION_STATEMENT);
- parse_expression (data, &value, &statement);
+ value = parse_expression (data, &statement);
// check for label
if (statement == NULL && vivi_parser_value_is_identifier (value) &&
@@ -2744,9 +2751,8 @@ peek_function_expression (ParseData *data)
return peek_function_definition (data);
}
-static void
-parse_function_expression (ParseData *data, ViviCodeValue **value,
- ViviCodeStatement **statement)
+static ViviCodeValue *
+parse_function_expression (ParseData *data, ViviCodeStatement **statement)
{
ViviCodeValue *function, *identifier;
@@ -2754,9 +2760,13 @@ parse_function_expression (ParseData *data, ViviCodeValue **value,
// FIXME
if (identifier != NULL) {
- *statement = vivi_parser_assignment_new (identifier, *value);
+ *statement = vivi_parser_assignment_new (identifier, identifier);
g_object_unref (identifier);
+ } else {
+ *statement = NULL;
}
+
+ return function;
}
// top
@@ -2848,7 +2858,7 @@ parse_value_statement_list (ParseData *data, PeekFunction peek,
array = g_ptr_array_new ();
do {
- parse (data, &value, &statement_one);
+ value = parse (data, &statement_one);
g_ptr_array_add (array, value);
*statement = vivi_parser_join_statements (*statement, statement_one);
} while ((separator == TOKEN_NONE || try_parse_token (data, separator)) &&
commit a604848c35c38dd18d4b5f19458d187338896f26
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Wed Apr 23 11:38:16 2008 +0300
Remove debug output
diff --git a/vivified/code/vivi_parser.c b/vivified/code/vivi_parser.c
index cf4c3e6..6e763cf 100644
--- a/vivified/code/vivi_parser.c
+++ b/vivified/code/vivi_parser.c
@@ -544,8 +544,7 @@ vivi_parser_end_code_token (ParseData *data, ViviCodeToken *token)
g_free (data->positions->data);
data->positions = g_slist_delete_link (data->positions, data->positions);
- if (token != NULL)
- g_print (":: %i - %i\n", (int) start, (int) vivi_parser_get_position (data));
+ // TODO
}
static void
commit 2b65330063ab23f2f4bb84b548a91718808940bb
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Wed Apr 23 11:37:04 2008 +0300
Make functions that parse statements return it directly and not as parameter
diff --git a/vivified/code/vivi_parser.c b/vivified/code/vivi_parser.c
index 0a8e194..cf4c3e6 100644
--- a/vivified/code/vivi_parser.c
+++ b/vivified/code/vivi_parser.c
@@ -117,7 +117,7 @@ typedef struct {
typedef gboolean (*PeekFunction) (ParseData *data);
typedef ViviCodeValue * (*ParseValueFunction) (ParseData *data);
typedef void (*ParseValueStatementFunction) (ParseData *data, ViviCodeValue **value, ViviCodeStatement **statement);
-typedef void (*ParseStatementFunction) (ParseData *data, ViviCodeStatement **statement);
+typedef ViviCodeStatement * (*ParseStatementFunction) (ParseData *data);
static void
parse_statement_list (ParseData *data, PeekFunction peek,
@@ -982,8 +982,8 @@ peek_variable_declaration (ParseData *data)
return peek_identifier (data);
}
-static void
-parse_variable_declaration (ParseData *data, ViviCodeStatement **statement)
+static ViviCodeStatement *
+parse_variable_declaration (ParseData *data)
{
ViviCodeValue *identifier, *value;
ViviCodeStatement *assignment, *statement_right;
@@ -1010,23 +1010,22 @@ parse_variable_declaration (ParseData *data, ViviCodeStatement **statement)
vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (assignment));
- *statement = vivi_parser_join_statements (statement_right, assignment);
+ return vivi_parser_join_statements (statement_right, assignment);
}
// builtin functions
-static void
-parse_get_url2 (ParseData *data, ViviCodeStatement **statement,
- gboolean require_two, gboolean level, gboolean internal,
- gboolean variables)
+static ViviCodeStatement *
+parse_get_url2 (ParseData *data, gboolean require_two, gboolean level,
+ gboolean internal, gboolean variables)
{
ViviCodeValue *url, *target;
- ViviCodeStatement *expression_statement;
+ ViviCodeStatement *statement, *expression_statement;
SwfdecLoaderRequest method;
parse_token (data, TOKEN_PARENTHESIS_LEFT);
- parse_assignment_expression (data, &url, statement);
+ parse_assignment_expression (data, &url, &statement);
if (require_two || peek_token (data, TOKEN_COMMA)) {
parse_token (data, TOKEN_COMMA);
@@ -1034,8 +1033,8 @@ parse_get_url2 (ParseData *data, ViviCodeStatement **statement,
// target
if (!level) {
parse_assignment_expression (data, &target, &expression_statement);
- *statement =
- vivi_parser_join_statements (*statement, expression_statement);
+ statement =
+ vivi_parser_join_statements (statement, expression_statement);
} else {
// FIXME: integer only
if (peek_numeric (data)) {
@@ -1046,8 +1045,8 @@ parse_get_url2 (ParseData *data, ViviCodeStatement **statement,
} else {
// TODO
parse_assignment_expression (data, &target, &expression_statement);
- *statement =
- vivi_parser_join_statements (*statement, expression_statement);
+ statement =
+ vivi_parser_join_statements (statement, expression_statement);
}
}
@@ -1087,39 +1086,41 @@ parse_get_url2 (ParseData *data, ViviCodeStatement **statement,
parse_token (data, TOKEN_PARENTHESIS_RIGHT);
- *statement = vivi_code_get_url_new (target, url, method, internal, variables);
+ statement = vivi_code_get_url_new (target, url, method, internal, variables);
g_object_unref (target);
g_object_unref (url);
+
+ return statement;
}
-static void
-parse_get_url (ParseData *data, ViviCodeStatement **statement)
+static ViviCodeStatement *
+parse_get_url (ParseData *data)
{
- parse_get_url2 (data, statement, FALSE, FALSE, FALSE, FALSE);
+ return parse_get_url2 (data, FALSE, FALSE, FALSE, FALSE);
}
-static void
-parse_load_movie (ParseData *data, ViviCodeStatement **statement)
+static ViviCodeStatement *
+parse_load_movie (ParseData *data)
{
- parse_get_url2 (data, statement, TRUE, FALSE, TRUE, FALSE);
+ return parse_get_url2 (data, TRUE, FALSE, TRUE, FALSE);
}
-static void
-parse_load_movie_num (ParseData *data, ViviCodeStatement **statement)
+static ViviCodeStatement *
+parse_load_movie_num (ParseData *data)
{
- parse_get_url2 (data, statement, TRUE, TRUE, TRUE, FALSE);
+ return parse_get_url2 (data, TRUE, TRUE, TRUE, FALSE);
}
-static void
-parse_load_variables (ParseData *data, ViviCodeStatement **statement)
+static ViviCodeStatement *
+parse_load_variables (ParseData *data)
{
- parse_get_url2 (data, statement, TRUE, FALSE, FALSE, TRUE);
+ return parse_get_url2 (data, TRUE, FALSE, FALSE, TRUE);
}
-static void
-parse_load_variables_num (ParseData *data, ViviCodeStatement **statement)
+static ViviCodeStatement *
+parse_load_variables_num (ParseData *data)
{
- parse_get_url2 (data, statement, TRUE, TRUE, FALSE, TRUE);
+ return parse_get_url2 (data, TRUE, TRUE, FALSE, TRUE);
}
static void
@@ -1335,13 +1336,13 @@ peek_builtin_statement (ParseData *data)
return FALSE;
}
-static void
-parse_builtin_statement (ParseData *data, ViviCodeStatement **statement)
+static ViviCodeStatement *
+parse_builtin_statement (ParseData *data)
{
guint i;
const char *identifier;
ViviCodeValue *argument;
- ViviCodeStatement *argument_statement;
+ ViviCodeStatement *statement, *argument_statement;
identifier = parse_identifier_value (data);
@@ -1355,10 +1356,9 @@ parse_builtin_statement (ParseData *data, ViviCodeStatement **statement)
}
if (builtin_statements[i].parse_custom != NULL) {
- builtin_statements[i].parse_custom (data, statement);
- return;
+ return builtin_statements[i].parse_custom (data);
}
-//
+
parse_token (data, TOKEN_PARENTHESIS_LEFT);
if (builtin_statements[i].constructor_value != NULL)
@@ -1369,13 +1369,15 @@ parse_builtin_statement (ParseData *data, ViviCodeStatement **statement)
parse_automatic_semicolon (data);
if (builtin_statements[i].constructor_value != NULL) {
- *statement = builtin_statements[i].constructor_value (argument);
+ statement = builtin_statements[i].constructor_value (argument);
g_object_unref (argument);
- *statement = vivi_parser_join_statements (argument_statement, *statement);
+ statement = vivi_parser_join_statements (argument_statement, statement);
} else {
g_assert (builtin_statements[i].constructor_void != NULL);
- *statement = builtin_statements[i].constructor_void ();
+ statement = builtin_statements[i].constructor_void ();
}
+
+ return statement;
}
// expression
@@ -2164,26 +2166,30 @@ parse_expression (ParseData *data, ViviCodeValue **value,
// statement
-static void
+static ViviCodeStatement *
parse_continue_or_break_statement (ParseData *data,
- ViviCodeStatement **statement, ViviParserScannerToken token)
+ ViviParserScannerToken token)
{
+ ViviCodeStatement *statement;
+
vivi_parser_start_code_token (data);
parse_token (data, token);
if (!try_parse_restricted_semicolon (data)) {
- *statement = vivi_compiler_goto_name_new (parse_identifier_value (data));
+ statement = vivi_compiler_goto_name_new (parse_identifier_value (data));
- vivi_parser_add_goto (data, VIVI_COMPILER_GOTO_NAME (*statement));
+ vivi_parser_add_goto (data, VIVI_COMPILER_GOTO_NAME (statement));
parse_automatic_semicolon (data);
} else {
// FIXME
- *statement = vivi_code_break_new ();
+ statement = vivi_code_break_new ();
}
- vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (*statement));
+ vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (statement));
+
+ return statement;
}
static gboolean
@@ -2192,10 +2198,10 @@ peek_continue_statement (ParseData *data)
return peek_token (data, TOKEN_CONTINUE);
}
-static void
-parse_continue_statement (ParseData *data, ViviCodeStatement **statement)
+static ViviCodeStatement *
+parse_continue_statement (ParseData *data)
{
- return parse_continue_or_break_statement (data, statement, TOKEN_CONTINUE);
+ return parse_continue_or_break_statement (data, TOKEN_CONTINUE);
}
static gboolean
@@ -2204,10 +2210,10 @@ peek_break_statement (ParseData *data)
return peek_token (data, TOKEN_BREAK);
}
-static void
-parse_break_statement (ParseData *data, ViviCodeStatement **statement)
+static ViviCodeStatement *
+parse_break_statement (ParseData *data)
{
- parse_continue_or_break_statement (data, statement, TOKEN_BREAK);
+ return parse_continue_or_break_statement (data, TOKEN_BREAK);
}
static gboolean
@@ -2216,11 +2222,11 @@ peek_throw_statement (ParseData *data)
return peek_token (data, TOKEN_THROW);
}
-static void
-parse_throw_statement (ParseData *data, ViviCodeStatement **statement)
+static ViviCodeStatement *
+parse_throw_statement (ParseData *data)
{
ViviCodeValue *value;
- ViviCodeStatement *expression_statement;
+ ViviCodeStatement *statement, *expression_statement;
parse_token (data, TOKEN_THROW);
@@ -2231,12 +2237,14 @@ parse_throw_statement (ParseData *data, ViviCodeStatement **statement)
parse_expression (data, &value, &expression_statement);
- *statement = vivi_code_throw_new (value);
+ statement = vivi_code_throw_new (value);
g_object_unref (value);
- *statement = vivi_parser_join_statements (expression_statement, *statement);
+ statement = vivi_parser_join_statements (expression_statement, statement);
parse_automatic_semicolon (data);
+
+ return statement;
}
static gboolean
@@ -2245,10 +2253,12 @@ peek_return_statement (ParseData *data)
return peek_token (data, TOKEN_RETURN);
}
-static void
-parse_return_statement (ParseData *data, ViviCodeStatement **statement)
+static ViviCodeStatement *
+parse_return_statement (ParseData *data)
{
- *statement = vivi_code_return_new ();
+ ViviCodeStatement *statement;
+
+ statement = vivi_code_return_new ();
parse_token (data, TOKEN_RETURN);
@@ -2258,21 +2268,22 @@ parse_return_statement (ParseData *data, ViviCodeStatement **statement)
parse_expression (data, &value, &expression_statement);
- vivi_code_return_set_value (VIVI_CODE_RETURN (*statement), value);
+ vivi_code_return_set_value (VIVI_CODE_RETURN (statement), value);
g_object_unref (value);
- *statement =
- vivi_parser_join_statements (expression_statement, *statement);
+ statement = vivi_parser_join_statements (expression_statement, statement);
parse_automatic_semicolon (data);
}
+
+ return statement;
}
static gboolean
peek_statement (ParseData *data);
-static void
-parse_statement (ParseData *data, ViviCodeStatement **statement);
+static ViviCodeStatement *
+parse_statement (ParseData *data);
static gboolean
peek_iteration_statement (ParseData *data)
@@ -2281,15 +2292,16 @@ peek_iteration_statement (ParseData *data)
peek_token (data, TOKEN_FOR));
}
-static void
-parse_iteration_statement (ParseData *data, ViviCodeStatement **statement)
+static ViviCodeStatement *
+parse_iteration_statement (ParseData *data)
{
ViviCodeValue *condition;
+ ViviCodeStatement *statement;
ViviCodeStatement *pre_statement, *condition_statement, *loop_statement;
if (try_parse_token (data, TOKEN_DO))
{
- parse_statement (data, &loop_statement);
+ loop_statement = parse_statement (data);
parse_token (data, TOKEN_WHILE);
parse_token (data, TOKEN_PARENTHESIS_LEFT);
parse_expression (data, &condition, &condition_statement);
@@ -2303,7 +2315,7 @@ parse_iteration_statement (ParseData *data, ViviCodeStatement **statement)
parse_token (data, TOKEN_PARENTHESIS_LEFT);
parse_expression (data, &condition, &condition_statement);
parse_token (data, TOKEN_PARENTHESIS_RIGHT);
- parse_statement (data, &loop_statement);
+ loop_statement = parse_statement (data);
pre_statement = NULL;
}
@@ -2393,7 +2405,7 @@ parse_iteration_statement (ParseData *data, ViviCodeStatement **statement)
}
parse_token (data, TOKEN_PARENTHESIS_RIGHT);
- parse_statement (data, &loop_statement);
+ loop_statement = parse_statement (data);
loop_statement =
vivi_parser_join_statements (loop_statement, post_statement);
@@ -2416,13 +2428,15 @@ parse_iteration_statement (ParseData *data, ViviCodeStatement **statement)
g_object_unref (condition_statement);
}
- *statement = vivi_code_loop_new ();
- vivi_code_loop_set_condition (VIVI_CODE_LOOP (*statement), condition);
+ statement = vivi_code_loop_new ();
+ vivi_code_loop_set_condition (VIVI_CODE_LOOP (statement), condition);
g_object_unref (condition);
- vivi_code_loop_set_statement (VIVI_CODE_LOOP (*statement), loop_statement);
+ vivi_code_loop_set_statement (VIVI_CODE_LOOP (statement), loop_statement);
g_object_unref (loop_statement);
- *statement = vivi_parser_join_statements (pre_statement, *statement);
+ statement = vivi_parser_join_statements (pre_statement, statement);
+
+ return statement;
}
static gboolean
@@ -2431,36 +2445,38 @@ peek_if_statement (ParseData *data)
return peek_token (data, TOKEN_IF);
}
-static void
-parse_if_statement (ParseData *data, ViviCodeStatement **statement)
+static ViviCodeStatement *
+parse_if_statement (ParseData *data)
{
ViviCodeValue *condition;
- ViviCodeStatement *pre_statement, *if_statement, *else_statement;
+ ViviCodeStatement *statement, *pre_statement, *if_statement, *else_statement;
parse_token (data, TOKEN_IF);
parse_token (data, TOKEN_PARENTHESIS_LEFT);
parse_expression (data, &condition, &pre_statement);
parse_token (data, TOKEN_PARENTHESIS_RIGHT);
- parse_statement (data, &if_statement);
+ if_statement = parse_statement (data);
if (try_parse_token (data, TOKEN_ELSE)) {
- parse_statement (data, &else_statement);
+ else_statement = parse_statement (data);
} else {
else_statement = NULL;
}
- *statement = vivi_code_if_new (condition);
+ statement = vivi_code_if_new (condition);
g_object_unref (condition);
- vivi_code_if_set_if (VIVI_CODE_IF (*statement), if_statement);
+ vivi_code_if_set_if (VIVI_CODE_IF (statement), if_statement);
g_object_unref (if_statement);
if (else_statement != NULL) {
- vivi_code_if_set_else (VIVI_CODE_IF (*statement), else_statement);
+ vivi_code_if_set_else (VIVI_CODE_IF (statement), else_statement);
g_object_unref (else_statement);
}
- *statement = vivi_parser_join_statements (pre_statement, *statement);
+ statement = vivi_parser_join_statements (pre_statement, statement);
+
+ return statement;
}
static gboolean
@@ -2472,39 +2488,38 @@ peek_expression_statement (ParseData *data)
return peek_expression (data);
}
-static void
-parse_expression_statement (ParseData *data, ViviCodeStatement **statement)
+static ViviCodeStatement *
+parse_expression_statement (ParseData *data)
{
ViviCodeValue *value;
- ViviCodeStatement *last;
+ ViviCodeStatement *statement, *last;
if (peek_token (data, TOKEN_BRACE_LEFT) || peek_token (data, TOKEN_FUNCTION))
vivi_parser_error_unexpected (data, ERROR_TOKEN_EXPRESSION_STATEMENT);
- parse_expression (data, &value, statement);
+ parse_expression (data, &value, &statement);
// check for label
- if (*statement == NULL && vivi_parser_value_is_identifier (value) &&
+ if (statement == NULL && vivi_parser_value_is_identifier (value) &&
try_parse_token (data, TOKEN_COLON))
{
- *statement = vivi_code_label_new (vivi_code_constant_get_variable_name (
+ statement = vivi_code_label_new (vivi_code_constant_get_variable_name (
VIVI_CODE_CONSTANT (VIVI_CODE_GET (value)->name)));
- if (!vivi_parser_add_label (data, VIVI_CODE_LABEL (*statement)))
+ if (!vivi_parser_add_label (data, VIVI_CODE_LABEL (statement)))
vivi_parser_error (data, "Same label name used twice");
- return;
}
parse_automatic_semicolon (data);
// add a value statement, if the last statement is not an assignment with the
// same value
- if (VIVI_IS_CODE_BLOCK (*statement)) {
- ViviCodeBlock *block = VIVI_CODE_BLOCK (*statement);
+ if (VIVI_IS_CODE_BLOCK (statement)) {
+ ViviCodeBlock *block = VIVI_CODE_BLOCK (statement);
last = vivi_code_block_get_statement (block,
vivi_code_block_get_n_statements (block) - 1);
} else {
- last = *statement;
+ last = statement;
}
if (VIVI_IS_CODE_ASSIGNMENT (last) && VIVI_IS_CODE_GET (value)) {
@@ -2512,13 +2527,15 @@ parse_expression_statement (ParseData *data, ViviCodeStatement **statement)
if (assignment->from == NULL && assignment->name == VIVI_CODE_GET (value)->name) {
g_object_unref (value);
- return;
+ return statement;
}
}
- *statement = vivi_parser_join_statements (*statement,
+ statement = vivi_parser_join_statements (statement,
vivi_code_value_statement_new (value));
g_object_unref (value);
+
+ return statement;
}
static gboolean
@@ -2527,12 +2544,12 @@ peek_empty_statement (ParseData *data)
return peek_token (data, TOKEN_SEMICOLON);
}
-static void
-parse_empty_statement (ParseData *data, ViviCodeStatement **statement)
+static ViviCodeStatement *
+parse_empty_statement (ParseData *data)
{
parse_token (data, TOKEN_SEMICOLON);
- *statement = vivi_compiler_empty_statement_new ();
+ return vivi_compiler_empty_statement_new ();
}
static gboolean
@@ -2541,18 +2558,22 @@ peek_block (ParseData *data)
return peek_token (data, TOKEN_BRACE_LEFT);
}
-static void
-parse_block (ParseData *data, ViviCodeStatement **statement)
+static ViviCodeStatement *
+parse_block (ParseData *data)
{
+ ViviCodeStatement *statement;
+
parse_token (data, TOKEN_BRACE_LEFT);
if (!try_parse_token (data, TOKEN_BRACE_RIGHT)) {
- parse_statement_list (data, peek_statement, parse_statement, statement,
+ parse_statement_list (data, peek_statement, parse_statement, &statement,
TOKEN_NONE);
parse_token (data, TOKEN_BRACE_RIGHT);
} else {
- *statement = vivi_code_block_new ();;
+ statement = vivi_code_block_new ();;
}
+
+ return statement;
}
static gboolean
@@ -2561,13 +2582,17 @@ peek_variable_statement (ParseData *data)
return peek_token (data, TOKEN_VAR);
}
-static void
-parse_variable_statement (ParseData *data, ViviCodeStatement **statement)
+static ViviCodeStatement *
+parse_variable_statement (ParseData *data)
{
+ ViviCodeStatement *statement;
+
parse_token (data, TOKEN_VAR);
parse_statement_list (data, peek_variable_declaration,
- parse_variable_declaration, statement, TOKEN_COMMA);
+ parse_variable_declaration, &statement, TOKEN_COMMA);
parse_automatic_semicolon (data);
+
+ return statement;
}
static const struct {
@@ -2604,20 +2629,19 @@ peek_statement (ParseData *data)
return FALSE;
}
-static void
-parse_statement (ParseData *data, ViviCodeStatement **statement)
+static ViviCodeStatement *
+parse_statement (ParseData *data)
{
guint i;
for (i = 0; statement_functions[i].peek != NULL; i++) {
if (statement_functions[i].peek (data)) {
- statement_functions[i].parse (data, statement);
- return;
+ return statement_functions[i].parse (data);
}
}
vivi_parser_error_unexpected (data, ERROR_TOKEN_STATEMENT);
- *statement = vivi_compiler_empty_statement_new ();
+ return vivi_compiler_empty_statement_new ();
}
// function
@@ -2631,8 +2655,8 @@ peek_function_definition (ParseData *data)
static gboolean
peek_source_element (ParseData *data);
-static void
-parse_source_element (ParseData *data, ViviCodeStatement **statement);
+static ViviCodeStatement *
+parse_source_element (ParseData *data);
static void
parse_function_definition (ParseData *data, ViviCodeValue **function,
@@ -2699,17 +2723,20 @@ peek_function_declaration (ParseData *data)
return peek_function_definition (data);
}
-static void
-parse_function_declaration (ParseData *data, ViviCodeStatement **statement)
+static ViviCodeStatement *
+parse_function_declaration (ParseData *data)
{
+ ViviCodeStatement *statement;
ViviCodeValue *function, *identifier;
parse_function_definition (data, &function, &identifier, TRUE);
// FIXME
- *statement = vivi_parser_assignment_new (identifier, function);
+ statement = vivi_parser_assignment_new (identifier, function);
g_object_unref (identifier);
g_object_unref (function);
+
+ return statement;
}
static gboolean
@@ -2741,17 +2768,17 @@ peek_source_element (ParseData *data)
return (peek_function_declaration (data) || peek_statement (data));
}
-static void
-parse_source_element (ParseData *data, ViviCodeStatement **statement)
+static ViviCodeStatement *
+parse_source_element (ParseData *data)
{
if (peek_function_declaration (data)) {
- parse_function_declaration (data, statement);
+ return parse_function_declaration (data);
} else if (peek_statement (data)) {
- parse_statement (data, statement);
+ return parse_statement (data);
} else {
vivi_parser_error_unexpected_or (data, ERROR_TOKEN_FUNCTION_DECLARATION,
ERROR_TOKEN_STATEMENT, TOKEN_NONE);
- *statement = vivi_compiler_empty_statement_new ();
+ return vivi_compiler_empty_statement_new ();
}
}
@@ -2761,18 +2788,22 @@ peek_program (ParseData *data)
return peek_source_element (data);
}
-static void
-parse_program (ParseData *data, ViviCodeStatement **statement)
+static ViviCodeStatement *
+parse_program (ParseData *data)
{
+ ViviCodeStatement *statement;
+
g_assert (data->level == NULL);
vivi_parser_start_level (data);
parse_statement_list (data, peek_source_element, parse_source_element,
- statement, TOKEN_NONE);
+ &statement, TOKEN_NONE);
parse_token (data, TOKEN_EOF);
vivi_parser_end_level (data);
g_assert (data->level == NULL);
+
+ return statement;
}
// parsing
@@ -2791,7 +2822,7 @@ parse_statement_list (ParseData *data, PeekFunction peek,
*block = vivi_code_block_new ();
do {
- parse (data, &statement);
+ statement = parse (data);
vivi_code_block_add_statement (VIVI_CODE_BLOCK (*block), statement);
g_object_unref (statement);
} while ((separator == TOKEN_NONE || try_parse_token (data, separator)) &&
@@ -2846,7 +2877,7 @@ vivi_parse_file (FILE *file, const char *input_name)
data.level = NULL;
data.error_count = 0;
- parse_program (&data, &statement);
+ statement = parse_program (&data);
if (data.error_count != 0) {
g_object_unref (statement);
statement = NULL;
commit ecf3cd72268794ad76e1249680071bbced1bece0
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Wed Apr 23 09:59:34 2008 +0300
Add vivi-rewrite to the ignore list
diff --git a/vivified/code/.gitignore b/vivified/code/.gitignore
index 83ce7a9..576ea9b 100644
--- a/vivified/code/.gitignore
+++ b/vivified/code/.gitignore
@@ -15,3 +15,4 @@ vivi_parser_scanner_lex.c
vivi-decompile
vivi-compile
+vivi-rewrite
commit f48dbd9595095645708e75a76f9d8146ab8bd822
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Wed Apr 23 09:58:48 2008 +0300
Fix couple of small bugs shown by compiler warnings
diff --git a/vivified/code/vivi_code_asm_push.c b/vivified/code/vivi_code_asm_push.c
index 153dde4..e9530eb 100644
--- a/vivified/code/vivi_code_asm_push.c
+++ b/vivified/code/vivi_code_asm_push.c
@@ -87,7 +87,7 @@ vivi_code_asm_push_print (ViviCodeToken *token, ViviCodePrinter*printer)
break;
case VIVI_CODE_CONSTANT_FLOAT:
s = g_strdup_printf ("%.ff", swfdec_bits_get_float (&bits));
- vivi_code_printer_print (printer, s2);
+ vivi_code_printer_print (printer, s);
g_free (s);
break;
case VIVI_CODE_CONSTANT_NULL:
diff --git a/vivified/code/vivi_decompiler.c b/vivified/code/vivi_decompiler.c
index 023fceb..98757d3 100644
--- a/vivified/code/vivi_decompiler.c
+++ b/vivified/code/vivi_decompiler.c
@@ -193,9 +193,11 @@ vivi_decompile_push (ViviDecompilerBlock *block, ViviDecompilerState *state,
}
default:
vivi_decompiler_block_add_error (block, state, "Push: type %u unknown, skipping", type);
+ val = NULL;
break;
}
- vivi_decompiler_state_push (state, val);
+ if (val != NULL)
+ vivi_decompiler_state_push (state, val);
}
return TRUE;
commit 361cf06a2c82636da1d38ea662a2c849ea5c17d7
Merge: f7511dd... 8637298...
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Wed Apr 23 09:58:38 2008 +0300
Merge branch 'master' of ssh://medar@git.freedesktop.org/git/swfdec/swfdec
Conflicts:
vivified/code/vivi_code_asm_code.c
vivified/code/vivi_code_label.c
diff --cc vivified/code/vivi_code_assembler.c
index afc39fe,582886b..02a0d91
--- a/vivified/code/vivi_code_assembler.c
+++ b/vivified/code/vivi_code_assembler.c
@@@ -26,8 -26,10 +26,9 @@@
#include "vivi_code_assembler.h"
#include "vivi_code_comment.h"
+ #include "vivi_code_emitter.h"
#include "vivi_code_label.h"
#include "vivi_code_printer.h"
-#include "vivi_code_compiler.h"
G_DEFINE_TYPE (ViviCodeAssembler, vivi_code_assembler, VIVI_TYPE_CODE_STATEMENT)
diff --cc vivified/code/vivi_code_comment.c
index 5985154,2d2ee91..681d900
--- a/vivified/code/vivi_code_comment.c
+++ b/vivified/code/vivi_code_comment.c
@@@ -23,9 -23,15 +23,15 @@@
#include "vivi_code_comment.h"
#include "vivi_code_asm.h"
-#include "vivi_code_compiler.h"
+#include "vivi_code_assembler.h"
#include "vivi_code_printer.h"
+ static gboolean
+ vivi_code_comment_emit (ViviCodeAsm *code, ViviCodeEmitter *emitter, GError **error)
+ {
+ return TRUE;
+ }
+
static void
vivi_code_comment_asm_init (ViviCodeAsmInterface *iface)
{
diff --cc vivified/code/vivi_code_label.c
index dc1ba9e,caf8174..db3604d
--- a/vivified/code/vivi_code_label.c
+++ b/vivified/code/vivi_code_label.c
@@@ -23,9 -23,20 +23,20 @@@
#include "vivi_code_label.h"
#include "vivi_code_asm.h"
-#include "vivi_code_compiler.h"
+#include "vivi_code_assembler.h"
+ #include "vivi_code_emitter.h"
#include "vivi_code_printer.h"
+ static gboolean
+ vivi_code_label_emit (ViviCodeAsm *code, ViviCodeEmitter *emitter, GError **error)
+ {
+ ViviCodeLabel *label = VIVI_CODE_LABEL (code);
+
+ vivi_code_emitter_add_label (emitter, label);
+
+ return TRUE;
+ }
+
static void
vivi_code_label_asm_init (ViviCodeAsmInterface *iface)
{
commit f7511ddf2c824b93a2698333c2dbbc788720237b
Merge: 06d1c53... a28db0e...
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Sun Apr 20 17:36:10 2008 +0300
Merge branch 'master' of ssh://medar@git.freedesktop.org/git/swfdec/swfdec
commit 06d1c53678ec77262f99048462bb5b50b542463c
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Fri Apr 18 16:35:24 2008 +0300
Parser: Make value parsing functions return the value and not use a parameter
Also added parse_*_value functions for literals and identifier, to give the
actual value not wrapped in ViviCodeValueSomething
diff --git a/vivified/code/vivi_parser.c b/vivified/code/vivi_parser.c
index 4532f79..0a8e194 100644
--- a/vivified/code/vivi_parser.c
+++ b/vivified/code/vivi_parser.c
@@ -22,6 +22,7 @@
#endif
#include <string.h>
+#include <math.h>
#include "vivi_parser.h"
@@ -114,7 +115,7 @@ typedef struct {
} ParseData;
typedef gboolean (*PeekFunction) (ParseData *data);
-typedef void (*ParseValueFunction) (ParseData *data, ViviCodeValue **value);
+typedef ViviCodeValue * (*ParseValueFunction) (ParseData *data);
typedef void (*ParseValueStatementFunction) (ParseData *data, ViviCodeValue **value, ViviCodeStatement **statement);
typedef void (*ParseStatementFunction) (ParseData *data, ViviCodeStatement **statement);
@@ -127,10 +128,6 @@ parse_value_statement_list (ParseData *data, PeekFunction peek,
ParseValueStatementFunction parse, ViviCodeValue ***list,
ViviCodeStatement **statement, guint separator);
-static void
-parse_value_list (ParseData *data, PeekFunction peek, ParseValueFunction parse,
- ViviCodeValue ***list, guint separator);
-
// helpers
static const char *
@@ -577,113 +574,184 @@ vivi_parser_error_handler (const char *text, gpointer user_data)
/* ActionScript specific */
static gboolean
-peek_undefined_literal (ParseData *data)
+peek_undefined (ParseData *data)
{
return peek_token (data, TOKEN_UNDEFINED);
}
-static void
-parse_undefined_literal (ParseData *data, ViviCodeValue **value)
+static ViviCodeValue *
+parse_undefined (ParseData *data)
{
+ ViviCodeValue *value;
+
vivi_parser_start_code_token (data);
parse_token (data, TOKEN_UNDEFINED);
- *value = vivi_code_undefined_new ();
+ value = vivi_code_undefined_new ();
- vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (*value));
+ vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (value));
+
+ return value;
}
static gboolean
-peek_null_literal (ParseData *data)
+peek_null (ParseData *data)
{
return peek_token (data, TOKEN_NULL);
}
-static void
-parse_null_literal (ParseData *data, ViviCodeValue **value)
+static ViviCodeValue *
+parse_null (ParseData *data)
{
+ ViviCodeValue *value;
+
vivi_parser_start_code_token (data);
parse_token (data, TOKEN_NULL);
- *value = vivi_code_null_new ();
+ value = vivi_code_null_new ();
- vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (*value));
+ vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (value));
+
+ return value;
+}
+
+G_GNUC_UNUSED static gboolean
+peek_boolean_value (ParseData *data)
+{
+ if (data->scanner->next_value.type == VALUE_TYPE_BOOLEAN) {
+ return data->scanner->next_value.v_boolean;
+ } else {
+ return FALSE;
+ }
}
static gboolean
-peek_boolean_literal (ParseData *data)
+parse_boolean_value (ParseData *data)
+{
+ parse_token (data, TOKEN_BOOLEAN);
+
+ if (data->scanner->value.type == VALUE_TYPE_BOOLEAN) {
+ return data->scanner->value.v_boolean;
+ } else {
+ return FALSE;
+ }
+}
+
+static gboolean
+peek_boolean (ParseData *data)
{
return peek_token (data, TOKEN_BOOLEAN);
}
-static void
-parse_boolean_literal (ParseData *data, ViviCodeValue **value)
+static ViviCodeValue *
+parse_boolean (ParseData *data)
{
+ ViviCodeValue *value;
+
vivi_parser_start_code_token (data);
- if (!try_parse_token (data, TOKEN_BOOLEAN)) {
- vivi_parser_error_unexpected (data, TOKEN_BOOLEAN);
- *value = vivi_code_boolean_new (0);
+ value = vivi_code_boolean_new (parse_boolean_value (data));
+
+ vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (value));
+
+ return value;
+}
+
+G_GNUC_UNUSED static double
+peek_numeric_value (ParseData *data)
+{
+ if (data->scanner->next_value.type == VALUE_TYPE_NUMBER) {
+ return data->scanner->next_value.v_number;
} else {
- *value = vivi_code_boolean_new (data->scanner->value.v_boolean);
+ return NAN;
}
+}
- vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (*value));
+static double
+parse_numeric_value (ParseData *data)
+{
+ parse_token (data, TOKEN_NUMBER);
+
+ if (data->scanner->value.type == VALUE_TYPE_NUMBER) {
+ return data->scanner->value.v_number;
+ } else {
+ return NAN;
+ }
}
static gboolean
-peek_numeric_literal (ParseData *data)
+peek_numeric (ParseData *data)
{
return peek_token (data, TOKEN_NUMBER);
}
-static void
-parse_numeric_literal (ParseData *data, ViviCodeValue **value)
+static ViviCodeValue *
+parse_numeric (ParseData *data)
{
+ ViviCodeValue *value;
+
vivi_parser_start_code_token (data);
- if (!try_parse_token (data, TOKEN_NUMBER)) {
- vivi_parser_error_unexpected (data, TOKEN_NUMBER);
- *value = vivi_code_number_new (0);
+ value = vivi_code_number_new (parse_numeric_value (data));
+
+ vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (value));
+
+ return value;
+}
+
+G_GNUC_UNUSED static const char *
+peek_string_value (ParseData *data)
+{
+ if (data->scanner->next_value.type == VALUE_TYPE_STRING) {
+ return data->scanner->next_value.v_string;
} else {
- *value = vivi_code_number_new (data->scanner->value.v_number);
+ return "undefined";
}
+}
- vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (*value));
+static const char *
+parse_string_value (ParseData *data)
+{
+ parse_token (data, TOKEN_STRING);
+
+ if (data->scanner->value.type == VALUE_TYPE_STRING) {
+ return data->scanner->value.v_string;
+ } else {
+ return "undefined";
+ }
}
static gboolean
-peek_string_literal (ParseData *data)
+peek_string (ParseData *data)
{
return peek_token (data, TOKEN_STRING);
}
-static void
-parse_string_literal (ParseData *data, ViviCodeValue **value)
+static ViviCodeValue *
+parse_string (ParseData *data)
{
+ ViviCodeValue *value;
+
vivi_parser_start_code_token (data);
- if (!try_parse_token (data, TOKEN_STRING)) {
- vivi_parser_error_unexpected (data, TOKEN_STRING);
- *value = vivi_code_string_new ("undefined");
- } else {
- *value = vivi_code_string_new (data->scanner->value.v_string);
- }
+ value = vivi_code_string_new (parse_string_value (data));
- vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (*value));
+ vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (value));
+
+ return value;
}
static const struct {
PeekFunction peek;
ParseValueFunction parse;
} literal_functions[] = {
- { peek_undefined_literal, parse_undefined_literal },
- { peek_null_literal, parse_null_literal },
- { peek_boolean_literal, parse_boolean_literal },
- { peek_numeric_literal, parse_numeric_literal },
- { peek_string_literal, parse_string_literal },
+ { peek_undefined, parse_undefined },
+ { peek_null, parse_null },
+ { peek_boolean, parse_boolean },
+ { peek_numeric, parse_numeric },
+ { peek_string, parse_string },
{ NULL, NULL }
};
@@ -700,22 +768,46 @@ peek_literal (ParseData *data)
return FALSE;
}
-static void
-parse_literal (ParseData *data, ViviCodeValue **value)
+static ViviCodeValue *
+parse_literal (ParseData *data)
{
+ ViviCodeValue *value;
guint i;
for (i = 0; literal_functions[i].peek != NULL; i++) {
if (literal_functions[i].peek (data)) {
- literal_functions[i].parse (data, value);
- return;
+ return literal_functions[i].parse (data);
}
}
vivi_parser_error_unexpected (data, ERROR_TOKEN_LITERAL);
vivi_parser_start_code_token (data);
- *value = vivi_code_undefined_new ();
- vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (*value));
+ value = vivi_code_undefined_new ();
+ vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (value));
+
+ return value;
+}
+
+static const char *
+peek_identifier_value (ParseData *data)
+{
+ if (data->scanner->next_value.type == VALUE_TYPE_IDENTIFIER) {
+ return data->scanner->next_value.v_identifier;
+ } else {
+ return "undefined";
+ }
+}
+
+static const char *
+parse_identifier_value (ParseData *data)
+{
+ parse_token (data, TOKEN_IDENTIFIER);
+
+ if (data->scanner->value.type == VALUE_TYPE_IDENTIFIER) {
+ return data->scanner->value.v_identifier;
+ } else {
+ return "undefined";
+ }
}
static gboolean
@@ -724,19 +816,18 @@ peek_identifier (ParseData *data)
return peek_token (data, TOKEN_IDENTIFIER);
}
-static void
-parse_identifier (ParseData *data, ViviCodeValue **value)
+static ViviCodeValue *
+parse_identifier (ParseData *data)
{
+ ViviCodeValue *value;
+
vivi_parser_start_code_token (data);
- if (!try_parse_token (data, TOKEN_IDENTIFIER)) {
- vivi_parser_error_unexpected (data, TOKEN_IDENTIFIER);
- *value = vivi_code_get_new_name ("undefined");
- } else {
- *value = vivi_code_get_new_name (data->scanner->value.v_identifier);
- }
+ value = vivi_code_get_new_name (parse_identifier_value (data));
- vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (*value));
+ vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (value));
+
+ return value;
}
static const struct {
@@ -744,8 +835,8 @@ static const struct {
ParseValueFunction parse;
} property_name_functions[] = {
{ peek_identifier, parse_identifier },
- { peek_string_literal, parse_string_literal },
- { peek_numeric_literal, parse_numeric_literal },
+ { peek_string, parse_string },
+ { peek_numeric, parse_numeric },
{ NULL, NULL }
};
@@ -762,22 +853,24 @@ peek_property_name (ParseData *data)
return FALSE;
}
-static void
-parse_property_name (ParseData *data, ViviCodeValue **value)
+static ViviCodeValue *
+parse_property_name (ParseData *data)
{
+ ViviCodeValue *value;
guint i;
for (i = 0; property_name_functions[i].peek != NULL; i++) {
if (property_name_functions[i].peek (data)) {
- property_name_functions[i].parse (data, value);
- return;
+ return property_name_functions[i].parse (data);
}
}
vivi_parser_error_unexpected (data, ERROR_TOKEN_PROPERTY_NAME);
vivi_parser_start_code_token (data);
- *value = vivi_code_undefined_new ();
- vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (*value));
+ value = vivi_code_string_new ("undefined");
+ vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (value));
+
+ return value;
}
static gboolean
@@ -865,7 +958,7 @@ parse_object_literal (ParseData *data, ViviCodeValue **value,
ViviCodeValue *property, *initializer;
ViviCodeStatement *statement_new;
- parse_property_name (data, &property);
+ property = parse_property_name (data);
parse_token (data, TOKEN_COLON);
parse_assignment_expression (data, &initializer, &statement_new);
@@ -897,7 +990,7 @@ parse_variable_declaration (ParseData *data, ViviCodeStatement **statement)
vivi_parser_start_code_token (data);
- parse_identifier (data, &identifier);
+ identifier = parse_identifier (data);
if (try_parse_token (data, TOKEN_ASSIGN)) {
parse_assignment_expression (data, &value, &statement_right);
@@ -912,6 +1005,8 @@ parse_variable_declaration (ParseData *data, ViviCodeStatement **statement)
assignment = vivi_parser_assignment_new (identifier, value);
vivi_code_assignment_set_local (VIVI_CODE_ASSIGNMENT (assignment), TRUE);
+ g_object_unref (identifier);
+ g_object_unref (value);
vivi_parser_end_code_token (data, VIVI_CODE_TOKEN (assignment));
@@ -943,12 +1038,9 @@ parse_get_url2 (ParseData *data, ViviCodeStatement **statement,
vivi_parser_join_statements (*statement, expression_statement);
} else {
// FIXME: integer only
- if (peek_numeric_literal (data)) {
- char *level_name;
- parse_numeric_literal (data, &target);
- level_name = g_strdup_printf ("_level%i",
- (int)vivi_code_number_get_value (VIVI_CODE_NUMBER (target)));
- g_object_unref (target);
+ if (peek_numeric (data)) {
+ char *level_name =
+ g_strdup_printf ("_level%i", (int)parse_numeric_value (data));
target = vivi_code_string_new (level_name);
g_free (level_name);
} else {
@@ -963,30 +1055,23 @@ parse_get_url2 (ParseData *data, ViviCodeStatement **statement,
if (peek_token (data, TOKEN_COMMA)) {
parse_token (data, TOKEN_COMMA);
- if (peek_identifier (data) || peek_string_literal (data)) {
- ViviCodeValue *identifier;
+ if (peek_identifier (data) || peek_string (data)) {
const char *method_string;
if (peek_identifier (data)) {
- parse_identifier (data, &identifier);
- method_string = vivi_code_constant_get_variable_name (
- VIVI_CODE_CONSTANT (VIVI_CODE_GET (identifier)->name));
+ method_string = parse_identifier_value (data);
} else {
- parse_string_literal (data, &identifier);
- method_string = vivi_code_constant_get_variable_name (
- VIVI_CODE_CONSTANT (identifier));
+ method_string = parse_string_value (data);
}
- // FIXME
if (g_ascii_strcasecmp (method_string, "GET") == 0) {
method = SWFDEC_LOADER_REQUEST_GET;
} else if (g_ascii_strcasecmp (method_string, "POST") == 0) {
method = SWFDEC_LOADER_REQUEST_POST;
} else {
method = SWFDEC_LOADER_REQUEST_DEFAULT;
- // only for identifiers?
+ // FIXME: only for identifiers?
vivi_parser_error (data, "Invalid URL method: %s\n", method_string);
}
- g_object_unref (identifier);
} else {
vivi_parser_error_unexpected_or (data, TOKEN_IDENTIFIER, TOKEN_STRING,
TOKEN_NONE);
@@ -1099,7 +1184,7 @@ parse_target_path (ParseData *data, ViviCodeValue **value,
parse_token (data, TOKEN_PARENTHESIS_LEFT);
- parse_identifier (data, &identifier);
+ identifier = parse_identifier (data);
parse_token (data, TOKEN_PARENTHESIS_RIGHT);
@@ -1196,10 +1281,7 @@ parse_builtin_call (ParseData *data, ViviCodeValue **value,
const char *identifier;
ViviCodeValue *argument;
- parse_identifier (data, &argument);
- identifier = vivi_code_constant_get_variable_name (VIVI_CODE_CONSTANT (
- VIVI_CODE_GET (argument)->name));
- g_object_unref (argument);
+ identifier = parse_identifier_value (data);
for (i = 0; i < G_N_ELEMENTS (builtin_calls); i++) {
if (g_ascii_strcasecmp (identifier, builtin_calls[i].name) == 0)
@@ -1241,7 +1323,7 @@ peek_builtin_statement (ParseData *data)
if (!peek_token (data, TOKEN_IDENTIFIER))
return FALSE;
- identifier = data->scanner->next_value.v_identifier;
+ identifier = peek_identifier_value (data);
// TODO: Check that ( follows?
@@ -1261,10 +1343,7 @@ parse_builtin_statement (ParseData *data, ViviCodeStatement **statement)
ViviCodeValue *argument;
ViviCodeStatement *argument_statement;
- parse_identifier (data, &argument);
- identifier = vivi_code_constant_get_variable_name (VIVI_CODE_CONSTANT (
- VIVI_CODE_GET (argument)->name));
- g_object_unref (argument);
+ identifier = parse_identifier_value (data);
for (i = 0; i < G_N_ELEMENTS (builtin_statements); i++) {
if (g_ascii_strcasecmp (identifier, builtin_statements[i].name) == 0)
@@ -1361,7 +1440,7 @@ parse_primary_expression (ParseData *data, ViviCodeValue **value,
for (i = 0; primary_expression_functions[i].peek != NULL; i++) {
if (primary_expression_functions[i].peek (data)) {
if (primary_expression_functions[i].parse_value != NULL) {
- primary_expression_functions[i].parse_value (data, value);
+ *value = primary_expression_functions[i].parse_value (data);
*statement = NULL;
} else {
primary_expression_functions[i].parse_value_statement (data, value,
@@ -1424,7 +1503,7 @@ parse_member_expression (ParseData *data, ViviCodeValue **value,
parse_token (data, TOKEN_BRACKET_RIGHT);
} else if (try_parse_token (data, TOKEN_DOT)) {
- parse_identifier (data, &member);
+ member = parse_identifier (data);
} else {
vivi_parser_end_code_token (data, NULL);
return;
@@ -2094,15 +2173,7 @@ parse_continue_or_break_statement (ParseData *data,
parse_token (data, token);
if (!try_parse_restricted_semicolon (data)) {
- ViviCodeValue *identifier;
-
- parse_identifier (data, &identifier);
-
- // FIXME
- *statement = vivi_compiler_goto_name_new (
- vivi_code_constant_get_variable_name (
- VIVI_CODE_CONSTANT (VIVI_CODE_GET (identifier)->name)));
- g_object_unref (identifier);
+ *statement = vivi_compiler_goto_name_new (parse_identifier_value (data));
vivi_parser_add_goto (data, VIVI_COMPILER_GOTO_NAME (*statement));
@@ -2577,12 +2648,12 @@ parse_function_definition (ParseData *data, ViviCodeValue **function,
parse_token (data, TOKEN_FUNCTION);
if (identifier_required) {
- parse_identifier (data, identifier);
+ *identifier = parse_identifier (data);
parse_token (data, TOKEN_PARENTHESIS_LEFT);
} else {
if (!try_parse_token (data, TOKEN_PARENTHESIS_LEFT)) {
if (peek_identifier (data)) {
- parse_identifier (data, identifier);
+ *identifier = parse_identifier (data);
parse_token (data, TOKEN_PARENTHESIS_LEFT);
} else {
vivi_parser_error_unexpected_or (data, TOKEN_PARENTHESIS_LEFT,
@@ -2595,8 +2666,6 @@ parse_function_definition (ParseData *data, ViviCodeValue **function,
}
if (!try_parse_token (data, TOKEN_PARENTHESIS_RIGHT)) {
- parse_value_list (data, peek_identifier, parse_identifier, &arguments,
- TOKEN_COMMA);
parse_token (data, TOKEN_PARENTHESIS_RIGHT);
}
@@ -2760,31 +2829,6 @@ parse_value_statement_list (ParseData *data, PeekFunction peek,
*list = (ViviCodeValue **)g_ptr_array_free (array, FALSE);
}
-static void
-parse_value_list (ParseData *data, PeekFunction peek, ParseValueFunction parse,
- ViviCodeValue ***list, guint separator)
-{
- GPtrArray *array;
- ViviCodeValue *value;
-
- g_assert (data != NULL);
- g_assert (peek != NULL);
- g_assert (parse != NULL);
- g_assert (list != NULL);
-
- array = g_ptr_array_new ();
-
- do {
- parse (data, &value);
- g_ptr_array_add (array, value);
- } while ((separator == TOKEN_NONE || try_parse_token (data, separator)) &&
- peek (data));
-
- g_ptr_array_add (array, NULL);
-
- *list = (ViviCodeValue **)g_ptr_array_free (array, FALSE);
-}
-
// public
ViviCodeStatement *
commit a6bfd1211ca63d8eee63f455584f0ffca0611533
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Fri Apr 18 14:30:43 2008 +0300
Don't forget to unref stuff in compile vfuncs...
diff --git a/vivified/code/vivi_code_assignment.c b/vivified/code/vivi_code_assignment.c
index 0dadecc..0163c16 100644
--- a/vivified/code/vivi_code_assignment.c
+++ b/vivified/code/vivi_code_assignment.c
@@ -119,6 +119,7 @@ vivi_code_assignment_compile (ViviCodeToken *token,
code = vivi_code_asm_set_variable_new ();
}
vivi_code_assembler_add_code (assembler, code);
+ g_object_unref (code);
}
static void
diff --git a/vivified/code/vivi_code_binary.c b/vivified/code/vivi_code_binary.c
index 5fab2b3..b7b68af 100644
--- a/vivified/code/vivi_code_binary.c
+++ b/vivified/code/vivi_code_binary.c
@@ -61,12 +61,15 @@ vivi_code_binary_compile (ViviCodeToken *token, ViviCodeAssembler *assembler)
{
ViviCodeBinary *binary = VIVI_CODE_BINARY (token);
ViviCodeBinaryClass *klass = VIVI_CODE_BINARY_GET_CLASS (binary);
+ ViviCodeAsm *code;
vivi_code_value_compile (binary->left, assembler);
vivi_code_value_compile (binary->right, assembler);
g_assert (klass->asm_constructor != 0);
- vivi_code_assembler_add_code (assembler, klass->asm_constructor ());
+ code = klass->asm_constructor ();
+ vivi_code_assembler_add_code (assembler, code);
+ g_object_unref (code);
}
static gboolean
diff --git a/vivified/code/vivi_code_builtin_call.c b/vivified/code/vivi_code_builtin_call.c
index ba9d7ae..bf299b7 100644
--- a/vivified/code/vivi_code_builtin_call.c
+++ b/vivified/code/vivi_code_builtin_call.c
@@ -43,9 +43,12 @@ vivi_code_builtin_call_compile (ViviCodeToken *token,
ViviCodeAssembler *assembler)
{
ViviCodeBuiltinCallClass *klass = VIVI_CODE_BUILTIN_CALL_GET_CLASS (token);
+ ViviCodeAsm *code;
g_assert (klass->asm_constructor != NULL);
- vivi_code_assembler_add_code (assembler, klass->asm_constructor ());
+ code = klass->asm_constructor ();
+ vivi_code_assembler_add_code (assembler, code);
+ g_object_unref (code);
}
static void
diff --git a/vivified/code/vivi_code_builtin_statement.c b/vivified/code/vivi_code_builtin_statement.c
index 9f89d72..8d9ca87 100644
--- a/vivified/code/vivi_code_builtin_statement.c
+++ b/vivified/code/vivi_code_builtin_statement.c
@@ -46,9 +46,12 @@ vivi_code_builtin_statement_compile (ViviCodeToken *token,
{
ViviCodeBuiltinStatementClass *klass =
VIVI_CODE_BUILTIN_STATEMENT_GET_CLASS (token);
+ ViviCodeAsm *code;
g_assert (klass->asm_constructor != NULL);
- vivi_code_assembler_add_code (assembler, klass->asm_constructor ());
+ code = klass->asm_constructor ();
+ vivi_code_assembler_add_code (assembler, code);
+ g_object_unref (code);
}
static void
diff --git a/vivified/code/vivi_code_builtin_value_call.c b/vivified/code/vivi_code_builtin_value_call.c
index 0829eb2..3a6bd14 100644
--- a/vivified/code/vivi_code_builtin_value_call.c
+++ b/vivified/code/vivi_code_builtin_value_call.c
@@ -62,12 +62,15 @@ vivi_code_builtin_value_call_compile (ViviCodeToken *token,
{
ViviCodeBuiltinCallClass *klass = VIVI_CODE_BUILTIN_CALL_GET_CLASS (token);
ViviCodeBuiltinValueCall *call = VIVI_CODE_BUILTIN_VALUE_CALL (token);
+ ViviCodeAsm *code;
g_assert (call->value != NULL);
vivi_code_value_compile (call->value, assembler);
g_assert (klass->asm_constructor != NULL);
- vivi_code_assembler_add_code (assembler, klass->asm_constructor ());
+ code = klass->asm_constructor ();
+ vivi_code_assembler_add_code (assembler, code);
+ g_object_unref (code);
}
static void
diff --git a/vivified/code/vivi_code_builtin_value_statement.c b/vivified/code/vivi_code_builtin_value_statement.c
index 25d5fc2..fb9978a 100644
--- a/vivified/code/vivi_code_builtin_value_statement.c
+++ b/vivified/code/vivi_code_builtin_value_statement.c
@@ -67,12 +67,15 @@ vivi_code_builtin_value_statement_compile (ViviCodeToken *token,
VIVI_CODE_BUILTIN_STATEMENT_GET_CLASS (token);
ViviCodeBuiltinValueStatement *stmt =
VIVI_CODE_BUILTIN_VALUE_STATEMENT (token);
+ ViviCodeAsm *code;
g_assert (stmt->value != NULL);
vivi_code_value_compile (stmt->value, assembler);
g_assert (klass->asm_constructor != NULL);
- vivi_code_assembler_add_code (assembler, klass->asm_constructor ());
+ code = klass->asm_constructor ();
+ vivi_code_assembler_add_code (assembler, code);
+ g_object_unref (code);
}
static void
diff --git a/vivified/code/vivi_code_concat.c b/vivified/code/vivi_code_concat.c
index f237484..7095222 100644
--- a/vivified/code/vivi_code_concat.c
+++ b/vivified/code/vivi_code_concat.c
@@ -58,11 +58,14 @@ static void
vivi_code_concat_compile (ViviCodeToken *token, ViviCodeAssembler *assembler)
{
ViviCodeConcat *concat = VIVI_CODE_CONCAT (token);
+ ViviCodeAsm *code;
vivi_code_value_compile (concat->first, assembler);
vivi_code_value_compile (concat->second, assembler);
- vivi_code_assembler_add_code (assembler, vivi_code_asm_string_add_new ());
+ code = vivi_code_asm_string_add_new ();
+ vivi_code_assembler_add_code (assembler, code);
+ g_object_unref (code);
}
static void
diff --git a/vivified/code/vivi_code_function.c b/vivified/code/vivi_code_function.c
index 9c89781..432dbeb 100644
--- a/vivified/code/vivi_code_function.c
+++ b/vivified/code/vivi_code_function.c
@@ -85,18 +85,20 @@ vivi_code_function_compile (ViviCodeToken *token, ViviCodeAssembler *assembler)
label_end = vivi_code_label_new_internal ("function_end");
- function = vivi_code_asm_define_function2_new (NULL, 0, 0, label_end)
+ define_function = vivi_code_asm_define_function2_new (NULL, 0, 0, label_end)
for (i = 0; i < function->arguments->len; i++) {
vivi_code_asm_define_function2_add_argument (
g_ptr_array_index (function->arguments, i), 0);
}
- vivi_code_assembler_add_code (assembler, function);
+ vivi_code_assembler_add_code (assembler, define_function);
+ g_object_unref (define_function);
if (function->body != NULL)
vivi_code_statement_compile (function->body, assembler);
vivi_code_assembler_add_code (assembler, label_end);
+ g_object_unref (label_end);
#endif
}
diff --git a/vivified/code/vivi_code_function_call.c b/vivified/code/vivi_code_function_call.c
index ce56b62..ab131a9 100644
--- a/vivified/code/vivi_code_function_call.c
+++ b/vivified/code/vivi_code_function_call.c
@@ -158,6 +158,7 @@ vivi_code_function_call_compile (ViviCodeToken *token,
}
vivi_code_assembler_add_code (assembler, code);
+ g_object_unref (code);
}
static gboolean
diff --git a/vivified/code/vivi_code_get.c b/vivified/code/vivi_code_get.c
index 5c99d73..9fd0ec8 100644
--- a/vivified/code/vivi_code_get.c
+++ b/vivified/code/vivi_code_get.c
@@ -91,6 +91,7 @@ vivi_code_get_compile (ViviCodeToken *token, ViviCodeAssembler *assembler)
}
vivi_code_assembler_add_code (assembler, code);
+ g_object_unref (code);
}
static gboolean
diff --git a/vivified/code/vivi_code_get_url.c b/vivified/code/vivi_code_get_url.c
index 8ee51e1..76eb2c1 100644
--- a/vivified/code/vivi_code_get_url.c
+++ b/vivified/code/vivi_code_get_url.c
@@ -72,7 +72,10 @@ vivi_code_get_url_compile (ViviCodeToken *token, ViviCodeAssembler *assembler)
vivi_code_value_compile (url->url, assembler);
vivi_code_value_compile (url->target, assembler);
- vivi_code_asm_get_url2_new (url->method, url->internal, url->variables);
+ code =
+ vivi_code_asm_get_url2_new (url->method, url->internal, url->variables);
+ vivi_code_assembler_add_code (assembler, code);
+ g_object_unref (code);
#endif
}
diff --git a/vivified/code/vivi_code_label.c b/vivified/code/vivi_code_label.c
index bed61c7..dc1ba9e 100644
--- a/vivified/code/vivi_code_label.c
+++ b/vivified/code/vivi_code_label.c
@@ -65,6 +65,7 @@ vivi_code_label_compile (ViviCodeToken *token, ViviCodeAssembler *assembler)
VIVI_CODE_ASM (vivi_code_label_new_internal_from_label (label));
vivi_code_assembler_add_code (assembler, code);
+ g_object_unref (code);
#endif
}
commit b392a8de5152cdc842d3496727e43344be0dfbd4
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Fri Apr 18 10:11:04 2008 +0300
Continue changing the compile vfuncs
diff --git a/vivified/code/compiler.c b/vivified/code/compiler.c
index e3a32a9..fd75ee8 100644
--- a/vivified/code/compiler.c
+++ b/vivified/code/compiler.c
@@ -25,21 +25,21 @@
#include "vivi_parser.h"
#include "vivi_code_text_printer.h"
-#include "vivi_code_compiler.h"
+#include "vivi_code_assembler.h"
int
main (int argc, char *argv[])
{
SwfdecPlayer *player;
- char *target_name;
- FILE *source, *target;
- ViviCodeStatement *statement;
- //ViviCodePrinter *printer;
- ViviCodeCompiler *compiler;
+ //char *target_name;
+ FILE *source;//, *target;
+ ViviCodeStatement *statement, *assembler;
+ ViviCodePrinter *printer;
+ /*ViviCodeCompiler *compiler;
SwfdecBots *bots;
SwfdecBuffer *buffer;
unsigned char *length_ptr;
- SwfdecRect rect = { 0, 0, 2000, 3000 };
+ SwfdecRect rect = { 0, 0, 2000, 3000 };*/
player = swfdec_player_new (NULL);
@@ -69,6 +69,14 @@ main (int argc, char *argv[])
g_object_unref (printer);*/
+ assembler = vivi_code_assembler_new ();
+ vivi_code_statement_compile (statement, VIVI_CODE_ASSEMBLER (assembler));
+ printer = vivi_code_text_printer_new ();
+ vivi_code_printer_print_token (printer, VIVI_CODE_TOKEN (assembler));
+ g_object_unref (printer);
+ g_object_unref (assembler);
+
+#if 0
bots = swfdec_bots_open ();
@@ -135,7 +143,9 @@ main (int argc, char *argv[])
fclose (target);
swfdec_buffer_unref (buffer);
+#endif
+ g_object_unref (statement);
g_object_unref (player);
return (statement == NULL ? -1 : 0);
diff --git a/vivified/code/vivi_code_assignment.c b/vivified/code/vivi_code_assignment.c
index 3024ac4..0dadecc 100644
--- a/vivified/code/vivi_code_assignment.c
+++ b/vivified/code/vivi_code_assignment.c
@@ -22,7 +22,6 @@
#endif
#include "vivi_code_assignment.h"
-#include "vivi_code_compiler.h"
#include "vivi_code_get.h"
#include "vivi_code_printer.h"
#include "vivi_code_string.h"
diff --git a/vivified/code/vivi_code_binary_default.c b/vivified/code/vivi_code_binary_default.c
index 9cecff3..9955e06 100644
--- a/vivified/code/vivi_code_binary_default.c
+++ b/vivified/code/vivi_code_binary_default.c
@@ -27,7 +27,7 @@
#include "vivi_code_asm_code_default.h"
-#define DEFAULT_BINARY(CapsName, underscore_name, operatorname, precedence) \
+#define DEFAULT_BINARY(CapsName, underscore_name, operatorname, bytecode, precedence) \
\
G_DEFINE_TYPE (ViviCode ## CapsName, vivi_code_ ## underscore_name, VIVI_TYPE_CODE_BINARY) \
\
diff --git a/vivified/code/vivi_code_binary_default.h b/vivified/code/vivi_code_binary_default.h
index 7a36dee..18a4926 100644
--- a/vivified/code/vivi_code_binary_default.h
+++ b/vivified/code/vivi_code_binary_default.h
@@ -24,7 +24,7 @@
G_BEGIN_DECLS
-#define DEFAULT_BINARY(CapsName, underscore_name, operator_name, precedence) \
+#define DEFAULT_BINARY(CapsName, underscore_name, operator_name, bytecode, precedence) \
\
typedef ViviCodeBinary ViviCode ## CapsName; \
typedef ViviCodeBinaryClass ViviCode ## CapsName ## Class; \
diff --git a/vivified/code/vivi_code_constant.c b/vivified/code/vivi_code_constant.c
index f7e2211..54f3d52 100644
--- a/vivified/code/vivi_code_constant.c
+++ b/vivified/code/vivi_code_constant.c
@@ -27,7 +27,6 @@
#include "vivi_code_constant.h"
#include "vivi_code_printer.h"
-#include "vivi_code_compiler.h"
G_DEFINE_ABSTRACT_TYPE (ViviCodeConstant, vivi_code_constant, VIVI_TYPE_CODE_VALUE)
diff --git a/vivified/code/vivi_code_continue.c b/vivified/code/vivi_code_continue.c
index cb6ab77..b00a766 100644
--- a/vivified/code/vivi_code_continue.c
+++ b/vivified/code/vivi_code_continue.c
@@ -23,7 +23,6 @@
#include "vivi_code_continue.h"
#include "vivi_code_printer.h"
-#include "vivi_code_compiler.h"
G_DEFINE_TYPE (ViviCodeContinue, vivi_code_continue, VIVI_TYPE_CODE_STATEMENT)
@@ -35,7 +34,7 @@ vivi_code_continue_print (ViviCodeToken *token, ViviCodePrinter *printer)
}
static void
-vivi_code_continue_compile (ViviCodeToken *token, ViviCodeCompiler *compiler)
+vivi_code_continue_compile (ViviCodeToken *token, ViviCodeAssembler *assembler)
{
g_printerr ("Implement continue\n");
}
diff --git a/vivified/code/vivi_code_defaults.h b/vivified/code/vivi_code_defaults.h
index 4b929d6..6486c3f 100644
--- a/vivified/code/vivi_code_defaults.h
+++ b/vivified/code/vivi_code_defaults.h
@@ -19,32 +19,32 @@
*/
#ifndef DEFAULT_BINARY
-#define DEFAULT_BINARY(CapsName, underscore_name, operator_name, precedence)
+#define DEFAULT_BINARY(CapsName, underscore_name, operator_name, bytecode, precedence)
#endif
-DEFAULT_BINARY (Add, add, "add", VIVI_PRECEDENCE_ADD)
-/*DEFAULT_BINARY (Subtract, subtract, "-", VIVI_PRECEDENCE_ADD)
-DEFAULT_BINARY (Multiply, multiply, "*", VIVI_PRECEDENCE_MULTIPLY)
-DEFAULT_BINARY (Divide, divide, "/", VIVI_PRECEDENCE_MULTIPLY)
-DEFAULT_BINARY (Modulo, modulo, "%", VIVI_PRECEDENCE_MULTIPLY)
-DEFAULT_BINARY (Equals, equals, "==", VIVI_PRECEDENCE_EQUALITY)
-DEFAULT_BINARY (Less, less, "<", VIVI_PRECEDENCE_RELATIONAL)
-DEFAULT_BINARY (LogicalAnd, logical_and, "and", VIVI_PRECEDENCE_AND)
-DEFAULT_BINARY (LogicalOr, logical_or, "or", VIVI_PRECEDENCE_OR)
-DEFAULT_BINARY (StringEquals, string_equals, "eq", VIVI_PRECEDENCE_EQUALITY)
-DEFAULT_BINARY (StringLess, string_less, "lt", VIVI_PRECEDENCE_RELATIONAL)
-DEFAULT_BINARY (Add2, add2, "+", VIVI_PRECEDENCE_ADD)
-DEFAULT_BINARY (Less2, less2, "<", VIVI_PRECEDENCE_RELATIONAL)
-DEFAULT_BINARY (Equals2, equals2, "==", VIVI_PRECEDENCE_EQUALITY)
-DEFAULT_BINARY (BitwiseAnd, bitwise_and, "&", VIVI_PRECEDENCE_BINARY_AND)
-DEFAULT_BINARY (BitwiseOr, bitwise_or, "|", VIVI_PRECEDENCE_BINARY_OR)
-DEFAULT_BINARY (BitwiseXor, bitwise_xor, "^", VIVI_PRECEDENCE_BINARY_XOR)
-DEFAULT_BINARY (LeftShift, left_shift, "<<", VIVI_PRECEDENCE_SHIFT)
-DEFAULT_BINARY (RightShift, right_shift, ">>", VIVI_PRECEDENCE_SHIFT)
-DEFAULT_BINARY (UnsignedRightShift,unsigned_right_shift,">>>",VIVI_PRECEDENCE_SHIFT)
-DEFAULT_BINARY (StrictEquals, strict_equals, "===", VIVI_PRECEDENCE_EQUALITY)
-DEFAULT_BINARY (Greater, greater, ">", VIVI_PRECEDENCE_RELATIONAL)
-DEFAULT_BINARY (StringGreater, string_greater, "gt", VIVI_PRECEDENCE_RELATIONAL)*/
+DEFAULT_BINARY (Add, add, "add", SWFDEC_AS_ACTION_ADD, VIVI_PRECEDENCE_ADD)
+DEFAULT_BINARY (Subtract, subtract, "-", SWFDEC_AS_ACTION_SUBTRACT, VIVI_PRECEDENCE_ADD)
+DEFAULT_BINARY (Multiply, multiply, "*", SWFDEC_AS_ACTION_MULTIPLY, VIVI_PRECEDENCE_MULTIPLY)
+DEFAULT_BINARY (Divide, divide, "/", SWFDEC_AS_ACTION_DIVIDE, VIVI_PRECEDENCE_MULTIPLY)
+DEFAULT_BINARY (Modulo, modulo, "%", SWFDEC_AS_ACTION_MODULO, VIVI_PRECEDENCE_MULTIPLY)
+DEFAULT_BINARY (Equals, equals, "==", SWFDEC_AS_ACTION_EQUALS, VIVI_PRECEDENCE_EQUALITY)
+DEFAULT_BINARY (Less, less, "<", SWFDEC_AS_ACTION_LESS, VIVI_PRECEDENCE_RELATIONAL)
+//DEFAULT_BINARY (LogicalAnd, logical_and, "and", SWFDEC_AS_ACTION_AND, VIVI_PRECEDENCE_AND)
+//DEFAULT_BINARY (LogicalOr, logical_or, "or", SWFDEC_AS_ACTION_OR, VIVI_PRECEDENCE_OR)
+DEFAULT_BINARY (StringEquals, string_equals, "eq", SWFDEC_AS_ACTION_STRING_EQUALS, VIVI_PRECEDENCE_EQUALITY)
+DEFAULT_BINARY (StringLess, string_less, "lt", SWFDEC_AS_ACTION_STRING_LESS, VIVI_PRECEDENCE_RELATIONAL)
+DEFAULT_BINARY (Add2, add2, "+", SWFDEC_AS_ACTION_ADD2, VIVI_PRECEDENCE_ADD)
+DEFAULT_BINARY (Less2, less2, "<", SWFDEC_AS_ACTION_LESS2, VIVI_PRECEDENCE_RELATIONAL)
+DEFAULT_BINARY (Equals2, equals2, "==", SWFDEC_AS_ACTION_EQUALS2, VIVI_PRECEDENCE_EQUALITY)
+//DEFAULT_BINARY (BitwiseAnd, bitwise_and, "&", SWFDEC_AS_ACTION_BIT_AND, VIVI_PRECEDENCE_BINARY_AND)
+//DEFAULT_BINARY (BitwiseOr, bitwise_or, "|", SWFDEC_AS_ACTION_BIT_OR, VIVI_PRECEDENCE_BINARY_OR)
+//DEFAULT_BINARY (BitwiseXor, bitwise_xor, "^", SWFDEC_AS_ACTION_BIT_XOR, VIVI_PRECEDENCE_BINARY_XOR)
+//DEFAULT_BINARY (LeftShift, left_shift, "<<", SWFDEC_AS_ACTION_BIT_LSHIFT, VIVI_PRECEDENCE_SHIFT)
+//DEFAULT_BINARY (RightShift, right_shift, ">>", SWFDEC_AS_ACTION_BIT_RSHIFT, VIVI_PRECEDENCE_SHIFT)
+//DEFAULT_BINARY (UnsignedRightShift,unsigned_right_shift,">>>",SWFDEC_AS_ACTION_BIT_URSHIFT,VIVI_PRECEDENCE_SHIFT)
+DEFAULT_BINARY (StrictEquals, strict_equals, "===", SWFDEC_AS_ACTION_STRICT_EQUALS, VIVI_PRECEDENCE_EQUALITY)
+DEFAULT_BINARY (Greater, greater, ">", SWFDEC_AS_ACTION_GREATER, VIVI_PRECEDENCE_RELATIONAL)
+DEFAULT_BINARY (StringGreater, string_greater, "gt", SWFDEC_AS_ACTION_STRING_GREATER,VIVI_PRECEDENCE_RELATIONAL)
/* other special ones:
DEFAULT_BINARY (And, and, "&&", ???, VIVI_PRECEDENCE_AND)
DEFAULT_BINARY (Or, or, "||", ???, VIVI_PRECEDENCE_AND)
diff --git a/vivified/code/vivi_code_function.c b/vivified/code/vivi_code_function.c
index 82ae90c..9c89781 100644
--- a/vivified/code/vivi_code_function.c
+++ b/vivified/code/vivi_code_function.c
@@ -25,8 +25,9 @@
#include "vivi_code_function.h"
#include "vivi_code_constant.h"
+#include "vivi_code_label.h"
#include "vivi_code_printer.h"
-#include "vivi_code_compiler.h"
+#include "vivi_code_assembler.h"
#include "vivi_decompiler.h"
@@ -73,34 +74,30 @@ vivi_code_function_print (ViviCodeToken *token, ViviCodePrinter*printer)
}
static void
-vivi_code_function_compile (ViviCodeToken *token, ViviCodeCompiler *compiler)
+vivi_code_function_compile (ViviCodeToken *token, ViviCodeAssembler *assembler)
{
+ g_printerr ("Implement function");
+#if 0
ViviCodeFunction *function = VIVI_CODE_FUNCTION (token);
+ ViviCodeLabel *label_end;
+ ViviCodeAsmDefineFunction2 *function;
guint i;
- vivi_code_compiler_begin_action (compiler, SWFDEC_AS_ACTION_DEFINE_FUNCTION2);
+ label_end = vivi_code_label_new_internal ("function_end");
- vivi_code_compiler_write_string (compiler, "");
- vivi_code_compiler_write_u16 (compiler, function->arguments->len);
- vivi_code_compiler_write_u8 (compiler, 0); // reg
- vivi_code_compiler_write_u16 (compiler, 0); // flags
-
- // arguments
+ function = vivi_code_asm_define_function2_new (NULL, 0, 0, label_end)
for (i = 0; i < function->arguments->len; i++) {
- vivi_code_compiler_write_u8 (compiler, 0); // register
- vivi_code_compiler_write_string (compiler,
- g_ptr_array_index (function->arguments, i )); // name
+ vivi_code_asm_define_function2_add_argument (
+ g_ptr_array_index (function->arguments, i), 0);
}
- if (function->body != NULL) {
- vivi_code_compiler_compile_token (compiler,
- VIVI_CODE_TOKEN (function->body));
- }
+ vivi_code_assembler_add_code (assembler, function);
- vivi_code_compiler_write_u16 (compiler,
- vivi_code_compiler_tail_size (compiler)); // body length
+ if (function->body != NULL)
+ vivi_code_statement_compile (function->body, assembler);
- vivi_code_compiler_end_action (compiler);
+ vivi_code_assembler_add_code (assembler, label_end);
+#endif
}
static gboolean
diff --git a/vivified/code/vivi_code_function_call.c b/vivified/code/vivi_code_function_call.c
index 14dc4d6..ce56b62 100644
--- a/vivified/code/vivi_code_function_call.c
+++ b/vivified/code/vivi_code_function_call.c
@@ -21,8 +21,9 @@
#include "config.h"
#endif
+#include "vivi_code_assembler.h"
+#include "vivi_code_asm_code_default.h"
#include "vivi_code_function_call.h"
-#include "vivi_code_compiler.h"
#include "vivi_code_number.h"
#include "vivi_code_printer.h"
@@ -122,41 +123,41 @@ vivi_code_function_call_print (ViviCodeToken *token, ViviCodePrinter*printer)
static void
vivi_code_function_call_compile (ViviCodeToken *token,
- ViviCodeCompiler *compiler)
+ ViviCodeAssembler *assembler)
{
ViviCodeFunctionCall *call = VIVI_CODE_FUNCTION_CALL (token);
- SwfdecAsAction action;
ViviCodeValue *count;
+ ViviCodeAsm *code;
guint i;
for (i = 0; i < call->arguments->len; i++) {
- vivi_code_compiler_compile_value (compiler,
- g_ptr_array_index (call->arguments, i));
+ vivi_code_value_compile (g_ptr_array_index (call->arguments, i),
+ assembler);
}
count = vivi_code_number_new (call->arguments->len);
- vivi_code_compiler_compile_value (compiler, count);
+ vivi_code_value_compile (count, assembler);
g_object_unref (count);
- vivi_code_compiler_compile_value (compiler, call->name);
+ vivi_code_value_compile (call->name, assembler);
if (call->value)
- vivi_code_compiler_compile_value (compiler, call->value);
+ vivi_code_value_compile (call->value, assembler);
if (call->construct) {
if (call->value) {
- action = SWFDEC_AS_ACTION_NEW_METHOD;
+ code = vivi_code_asm_new_method_new ();
} else {
- action = SWFDEC_AS_ACTION_NEW_OBJECT;
+ code = vivi_code_asm_new_object_new ();
}
} else {
if (call->value) {
- action = SWFDEC_AS_ACTION_CALL_METHOD;
+ code = vivi_code_asm_call_method_new ();
} else {
- action = SWFDEC_AS_ACTION_CALL_FUNCTION;
+ code = vivi_code_asm_call_function_new ();
}
}
- vivi_code_compiler_write_empty_action (compiler, action);
+ vivi_code_assembler_add_code (assembler, code);
}
static gboolean
diff --git a/vivified/code/vivi_code_get.c b/vivified/code/vivi_code_get.c
index dced1f1..5c99d73 100644
--- a/vivified/code/vivi_code_get.c
+++ b/vivified/code/vivi_code_get.c
@@ -21,8 +21,9 @@
#include "config.h"
#endif
+#include "vivi_code_asm_code_default.h"
+#include "vivi_code_assembler.h"
#include "vivi_code_get.h"
-#include "vivi_code_compiler.h"
#include "vivi_code_printer.h"
#include "vivi_code_string.h"
@@ -74,22 +75,22 @@ vivi_code_get_print (ViviCodeToken *token, ViviCodePrinter*printer)
}
static void
-vivi_code_get_compile (ViviCodeToken *token, ViviCodeCompiler *compiler)
+vivi_code_get_compile (ViviCodeToken *token, ViviCodeAssembler *assembler)
{
ViviCodeGet *get = VIVI_CODE_GET (token);
- SwfdecAsAction action;
+ ViviCodeAsm *code;
- vivi_code_compiler_compile_value (compiler, get->name);
+ vivi_code_value_compile (get->name, assembler);
if (get->from)
- vivi_code_compiler_compile_value (compiler, get->from);
+ vivi_code_value_compile (get->from, assembler);
if (get->from) {
- action = SWFDEC_AS_ACTION_GET_MEMBER;
+ code = vivi_code_asm_get_member_new ();
} else {
- action = SWFDEC_AS_ACTION_GET_VARIABLE;
+ code = vivi_code_asm_get_variable_new ();
}
- vivi_code_compiler_write_empty_action (compiler, action);
+ vivi_code_assembler_add_code (assembler, code);
}
static gboolean
diff --git a/vivified/code/vivi_code_get_timer.c b/vivified/code/vivi_code_get_timer.c
index b712feb..c1c6dc7 100644
--- a/vivified/code/vivi_code_get_timer.c
+++ b/vivified/code/vivi_code_get_timer.c
@@ -23,6 +23,7 @@
#endif
#include "vivi_code_get_timer.h"
+#include "vivi_code_asm_code_default.h"
G_DEFINE_TYPE (ViviCodeGetTimer, vivi_code_get_timer, VIVI_TYPE_CODE_BUILTIN_CALL)
@@ -33,7 +34,7 @@ vivi_code_get_timer_class_init (ViviCodeGetTimerClass *klass)
VIVI_CODE_BUILTIN_CALL_CLASS (klass);
builtin_class->function_name = "getTimer";
- builtin_class->bytecode = SWFDEC_AS_ACTION_GET_TIME;
+ builtin_class->asm_constructor = vivi_code_asm_get_time_new;
}
static void
diff --git a/vivified/code/vivi_code_get_url.c b/vivified/code/vivi_code_get_url.c
index 33a74f3..8ee51e1 100644
--- a/vivified/code/vivi_code_get_url.c
+++ b/vivified/code/vivi_code_get_url.c
@@ -23,7 +23,7 @@
#include "vivi_code_get_url.h"
#include "vivi_code_printer.h"
-#include "vivi_code_compiler.h"
+#include "vivi_code_assembler.h"
G_DEFINE_TYPE (ViviCodeGetUrl, vivi_code_get_url, VIVI_TYPE_CODE_STATEMENT)
@@ -62,25 +62,18 @@ vivi_code_get_url_print (ViviCodeToken *token, ViviCodePrinter *printer)
}
static void
-vivi_code_get_url_compile (ViviCodeToken *token, ViviCodeCompiler *compiler)
+vivi_code_get_url_compile (ViviCodeToken *token, ViviCodeAssembler *assembler)
{
+ g_printerr ("Implement getURL2");
+#if 0
ViviCodeGetUrl *url = VIVI_CODE_GET_URL (token);
guint bits;
- vivi_code_compiler_compile_value (compiler, url->url);
- vivi_code_compiler_compile_value (compiler, url->target);
+ vivi_code_value_compile (url->url, assembler);
+ vivi_code_value_compile (url->target, assembler);
- vivi_code_compiler_begin_action (compiler, SWFDEC_AS_ACTION_GET_URL2);
-
- bits = url->method;
- if (url->internal)
- bits |= 64;
- if (url->variables)
- bits |= 128;
-
- vivi_code_compiler_write_u8 (compiler, bits);
-
- vivi_code_compiler_end_action (compiler);
+ vivi_code_asm_get_url2_new (url->method, url->internal, url->variables);
+#endif
}
static void
diff --git a/vivified/code/vivi_code_if.c b/vivified/code/vivi_code_if.c
index 112f883..a1aa62b 100644
--- a/vivified/code/vivi_code_if.c
+++ b/vivified/code/vivi_code_if.c
@@ -24,7 +24,8 @@
#include "vivi_code_if.h"
#include "vivi_code_unary.h"
#include "vivi_code_printer.h"
-#include "vivi_code_compiler.h"
+#include "vivi_code_label.h"
+#include "vivi_code_assembler.h"
G_DEFINE_TYPE (ViviCodeIf, vivi_code_if, VIVI_TYPE_CODE_STATEMENT)
@@ -126,29 +127,37 @@ vivi_code_if_print (ViviCodeToken *token, ViviCodePrinter *printer)
}
static void
-vivi_code_if_compile (ViviCodeToken *token, ViviCodeCompiler *compiler)
+vivi_code_if_compile (ViviCodeToken *token, ViviCodeAssembler *assembler)
{
+ g_printerr ("Implement if\n");
+#if 0
ViviCodeIf *stmt = VIVI_CODE_IF (token);
- ViviCodeAsmLabel *label_if, *label_else;
+ ViviCodeLabel *label_if, *label_else;
+ ViviCodeAsm *code;
- vivi_code_compiler_compile_value (compiler, stmt->condition);
+ vivi_code_value_compile (stmt->condition, assembler);
- label_if = vivi_code_asm_label_new ();
- vivi_code_compiler_add (compiler, vivi_code_asm_if_new (label_if));
+ label_if = vivi_code_label_new_internal ("if");
+ code = vivi_code_asm_if_new (label_if)
+ vivi_code_assembler_add_code (assembler, code);
+ g_object_unref (code);
if (stmt->else_statement)
- vivi_code_compiler_compile_statement (compiler, stmt->else_statement);
+ vivi_code_statement_compile (stmt->else_statement, assembler);
- label_else = vivi_code_asm_label_new ();
- vivi_code_compiler_add (compiler, vivi_code_asm_jump_new (label_else));
- g_object_unref (label_else);
+ label_end = vivi_code_label_new_internal ("end");
+ code = vivi_code_asm_jump_new (label_end);
+ vivi_code_assembler_add_code (assembler, code);
+ g_object_unref (code);
- vivi_code_compiler_add (compiler, label_if);
+ vivi_code_assembler_add_code (assembler, label_if);
g_object_unref (label_if);
- vivi_code_compiler_compile_statement (compiler, stmt->if_statement);
+ vivi_code_assembler_compile_statement (assembler, stmt->if_statement);
- vivi_code_compiler_add (compiler, label_else);
+ vivi_code_assembler_add_code (assembler, label_end);
+ g_object_unref (label_end);
+#endif
}
static void
diff --git a/vivified/code/vivi_code_init_array.c b/vivified/code/vivi_code_init_array.c
index e61522f..fbb74fb 100644
--- a/vivified/code/vivi_code_init_array.c
+++ b/vivified/code/vivi_code_init_array.c
@@ -22,8 +22,9 @@
#include "config.h"
#endif
+#include "vivi_code_asm_code_default.h"
+#include "vivi_code_assembler.h"
#include "vivi_code_init_array.h"
-#include "vivi_code_compiler.h"
#include "vivi_code_number.h"
#include "vivi_code_printer.h"
#include "vivi_code_undefined.h"
@@ -79,22 +80,25 @@ vivi_code_init_array_print (ViviCodeToken *token, ViviCodePrinter *printer)
}
static void
-vivi_code_init_array_compile (ViviCodeToken *token, ViviCodeCompiler *compiler)
+vivi_code_init_array_compile (ViviCodeToken *token,
+ ViviCodeAssembler *assembler)
{
ViviCodeInitArray *array = VIVI_CODE_INIT_ARRAY (token);
ViviCodeValue *count;
+ ViviCodeAsm *code;
guint i;
for (i = 0; i < array->variables->len; i++) {
- vivi_code_compiler_compile_value (compiler,
- VIVI_CODE_VALUE (g_ptr_array_index (array->variables, i)));
+ vivi_code_value_compile (VIVI_CODE_VALUE (g_ptr_array_index (
+ array->variables, i)), assembler);
}
count = vivi_code_number_new (array->variables->len);
- vivi_code_compiler_compile_value (compiler, count);
+ vivi_code_value_compile (count, assembler);
g_object_unref (count);
- vivi_code_compiler_write_empty_action (compiler,
- SWFDEC_AS_ACTION_INIT_ARRAY);
+ code = vivi_code_asm_init_array_new ();
+ vivi_code_assembler_add_code (assembler, code);
+ g_object_unref (code);
}
static gboolean
diff --git a/vivified/code/vivi_code_init_object.c b/vivified/code/vivi_code_init_object.c
index 90c1da3..d632aec 100644
--- a/vivified/code/vivi_code_init_object.c
+++ b/vivified/code/vivi_code_init_object.c
@@ -23,7 +23,9 @@
#include "vivi_code_init_object.h"
#include "vivi_code_printer.h"
-#include "vivi_code_compiler.h"
+#include "vivi_code_number.h"
+#include "vivi_code_assembler.h"
+#include "vivi_code_asm_code_default.h"
G_DEFINE_TYPE (ViviCodeInitObject, vivi_code_init_object, VIVI_TYPE_CODE_VALUE)
@@ -78,21 +80,26 @@ vivi_code_init_object_print (ViviCodeToken *token, ViviCodePrinter*printer)
static void
vivi_code_init_object_compile (ViviCodeToken *token,
- ViviCodeCompiler *compiler)
+ ViviCodeAssembler *assembler)
{
ViviCodeInitObject *object = VIVI_CODE_INIT_OBJECT (token);
+ ViviCodeValue *count;
+ ViviCodeAsm *code;
guint i;
for (i = 0; i < object->variables->len; i++) {
VariableEntry *entry = &g_array_index (object->variables, VariableEntry, i);
- vivi_code_compiler_compile_value (compiler, entry->value);
- vivi_code_compiler_compile_value (compiler, entry->name);
+ vivi_code_value_compile (entry->value, assembler);
+ vivi_code_value_compile (entry->name, assembler);
}
- vivi_code_compiler_write_u8 (compiler, object->variables->len);
+ count = vivi_code_number_new (object->variables->len);
+ vivi_code_value_compile (count, assembler);
+ g_object_unref (count);
- vivi_code_compiler_write_empty_action (compiler,
- SWFDEC_AS_ACTION_INIT_OBJECT);
+ code = vivi_code_asm_init_object_new ();
+ vivi_code_assembler_add_code (assembler, code);
+ g_object_unref (code);
}
static gboolean
diff --git a/vivified/code/vivi_code_label.c b/vivified/code/vivi_code_label.c
index 7588554..bed61c7 100644
--- a/vivified/code/vivi_code_label.c
+++ b/vivified/code/vivi_code_label.c
@@ -23,7 +23,7 @@
#include "vivi_code_label.h"
#include "vivi_code_asm.h"
-#include "vivi_code_compiler.h"
+#include "vivi_code_assembler.h"
#include "vivi_code_printer.h"
static void
@@ -56,9 +56,16 @@ vivi_code_label_print (ViviCodeToken *token, ViviCodePrinter *printer)
}
static void
-vivi_code_label_compile (ViviCodeToken *token, ViviCodeCompiler *compiler)
+vivi_code_label_compile (ViviCodeToken *token, ViviCodeAssembler *assembler)
{
- // TODO: save the position
+ g_printerr ("Implement label\n");
+#if 0
+ ViviCodeLabel *label = VIVI_CODE_LABEL (token);
+ ViviCodeAsm *code =
+ VIVI_CODE_ASM (vivi_code_label_new_internal_from_label (label));
+
+ vivi_code_assembler_add_code (assembler, code);
+#endif
}
static gboolean
diff --git a/vivified/code/vivi_code_return.c b/vivified/code/vivi_code_return.c
index 629c569..e031805 100644
--- a/vivified/code/vivi_code_return.c
+++ b/vivified/code/vivi_code_return.c
@@ -23,7 +23,8 @@
#include "vivi_code_return.h"
#include "vivi_code_printer.h"
-#include "vivi_code_compiler.h"
+#include "vivi_code_assembler.h"
+#include "vivi_code_asm_code_default.h"
G_DEFINE_TYPE (ViviCodeReturn, vivi_code_return, VIVI_TYPE_CODE_STATEMENT)
@@ -55,13 +56,16 @@ vivi_code_return_print (ViviCodeToken *token, ViviCodePrinter *printer)
}
static void
-vivi_code_return_compile (ViviCodeToken *token, ViviCodeCompiler *compiler)
+vivi_code_return_compile (ViviCodeToken *token, ViviCodeAssembler *assembler)
{
ViviCodeReturn *ret = VIVI_CODE_RETURN (token);
+ ViviCodeAsm *code;
- vivi_code_compiler_compile_value (compiler, ret->value);
+ vivi_code_value_compile (ret->value, assembler);
- vivi_code_compiler_write_empty_action (compiler, SWFDEC_AS_ACTION_RETURN);
+ code = vivi_code_asm_return_new ();
+ vivi_code_assembler_add_code (assembler, code);
+ g_object_unref (code);
}
static void
diff --git a/vivified/code/vivi_code_substring.c b/vivified/code/vivi_code_substring.c
index 6144542..21c7e48 100644
--- a/vivified/code/vivi_code_substring.c
+++ b/vivified/code/vivi_code_substring.c
@@ -23,7 +23,7 @@
#include "vivi_code_substring.h"
#include "vivi_code_printer.h"
-#include "vivi_code_compiler.h"
+#include "vivi_code_assembler.h"
G_DEFINE_TYPE (ViviCodeSubstring, vivi_code_substring, VIVI_TYPE_CODE_VALUE)
@@ -58,16 +58,22 @@ vivi_code_substring_print (ViviCodeToken *token, ViviCodePrinter *printer)
}
static void
-vivi_code_substring_compile (ViviCodeToken *token, ViviCodeCompiler *compiler)
+vivi_code_substring_compile (ViviCodeToken *token,
+ ViviCodeAssembler *assembler)
{
+ g_printerr ("Implement substring\n");
+#if 0
ViviCodeSubstring *substring = VIVI_CODE_SUBSTRING (token);
+ ViviCodeAsm *code;
- vivi_code_compiler_compile_value (compiler, substring->string);
- vivi_code_compiler_compile_value (compiler, substring->index_);
- vivi_code_compiler_compile_value (compiler, substring->count);
+ vivi_code_value_compile (substring->string, assembler);
+ vivi_code_value_compile (substring->index_, assembler);
+ vivi_code_value_compile (substring->count, assembler);
- vivi_code_compiler_write_empty_action (compiler,
- SWFDEC_AS_ACTION_STRING_EXTRACT);
+ code = vivi_code_asm_string_extract_new ();
+ vivi_code_assembler_add_code (assembler, code);
+ g_object_unref (code);
+#endif
}
static void
diff --git a/vivified/code/vivi_code_throw.c b/vivified/code/vivi_code_throw.c
index e805039..8b369b8 100644
--- a/vivified/code/vivi_code_throw.c
+++ b/vivified/code/vivi_code_throw.c
@@ -23,7 +23,9 @@
#include "vivi_code_throw.h"
#include "vivi_code_printer.h"
-#include "vivi_code_compiler.h"
+#include "vivi_code_assembler.h"
+#include "vivi_code_asm.h"
+#include "vivi_code_asm_code_default.h"
G_DEFINE_TYPE (ViviCodeThrow, vivi_code_throw, VIVI_TYPE_CODE_STATEMENT)
@@ -55,15 +57,18 @@ vivi_code_throw_print (ViviCodeToken *token, ViviCodePrinter *printer)
}
static void
-vivi_code_throw_compile (ViviCodeToken *token, ViviCodeCompiler *compiler)
+vivi_code_throw_compile (ViviCodeToken *token, ViviCodeAssembler *assembler)
{
ViviCodeThrow *throw_ = VIVI_CODE_THROW (token);
+ ViviCodeAsm *code;
g_return_if_fail (throw_->value != NULL);
- vivi_code_compiler_compile_value (compiler, throw_->value);
+ vivi_code_value_compile (throw_->value, assembler);
- vivi_code_compiler_write_empty_action (compiler, SWFDEC_AS_ACTION_THROW);
+ code = vivi_code_asm_throw_new ();
+ vivi_code_assembler_add_code (assembler, code);
+ g_object_unref (code);
}
static void
diff --git a/vivified/code/vivi_code_token.c b/vivified/code/vivi_code_token.c
index cafa850..53fce9a 100644
--- a/vivified/code/vivi_code_token.c
+++ b/vivified/code/vivi_code_token.c
@@ -22,6 +22,7 @@
#endif
#include "vivi_code_token.h"
+#include "vivi_code_assembler.h"
G_DEFINE_ABSTRACT_TYPE (ViviCodeToken, vivi_code_token, G_TYPE_OBJECT)
diff --git a/vivified/code/vivi_code_unary.c b/vivified/code/vivi_code_unary.c
index eb49c45..9885219 100644
--- a/vivified/code/vivi_code_unary.c
+++ b/vivified/code/vivi_code_unary.c
@@ -23,7 +23,9 @@
#include "vivi_code_unary.h"
#include "vivi_code_printer.h"
-#include "vivi_code_compiler.h"
+#include "vivi_code_assembler.h"
+#include "vivi_code_asm.h"
+#include "vivi_code_asm_code_default.h"
G_DEFINE_TYPE (ViviCodeUnary, vivi_code_unary, VIVI_TYPE_CODE_VALUE)
@@ -68,15 +70,18 @@ vivi_code_unary_print (ViviCodeToken *token, ViviCodePrinter*printer)
}
static void
-vivi_code_unary_compile (ViviCodeToken *token, ViviCodeCompiler *compiler)
+vivi_code_unary_compile (ViviCodeToken *token, ViviCodeAssembler *assembler)
{
ViviCodeUnary *unary = VIVI_CODE_UNARY (token);
+ ViviCodeAsm *code;
g_return_if_fail (unary->operation != '!');
- vivi_code_compiler_compile_value (compiler, unary->value);
+ vivi_code_value_compile (unary->value, assembler);
- vivi_code_compiler_write_empty_action (compiler, SWFDEC_AS_ACTION_NOT);
+ code = vivi_code_asm_not_new ();
+ vivi_code_assembler_add_code (assembler, code);
+ g_object_unref (code);
}
static gboolean
diff --git a/vivified/code/vivi_code_value_statement.c b/vivified/code/vivi_code_value_statement.c
index 97677cb..8efc9d3 100644
--- a/vivified/code/vivi_code_value_statement.c
+++ b/vivified/code/vivi_code_value_statement.c
@@ -23,7 +23,9 @@
#include "vivi_code_value_statement.h"
#include "vivi_code_printer.h"
-#include "vivi_code_compiler.h"
+#include "vivi_code_assembler.h"
+#include "vivi_code_asm.h"
+#include "vivi_code_asm_code_default.h"
G_DEFINE_TYPE (ViviCodeValueStatement, vivi_code_value_statement, VIVI_TYPE_CODE_STATEMENT)
@@ -49,13 +51,16 @@ vivi_code_value_statement_print (ViviCodeToken *token, ViviCodePrinter *printer)
static void
vivi_code_value_statement_compile (ViviCodeToken *token,
- ViviCodeCompiler *compiler)
+ ViviCodeAssembler *assembler)
{
ViviCodeValueStatement *stmt = VIVI_CODE_VALUE_STATEMENT (token);
+ ViviCodeAsm *code;
- vivi_code_compiler_compile_value (compiler, stmt->value);
+ vivi_code_value_compile (stmt->value, assembler);
- vivi_code_compiler_write_empty_action (compiler, SWFDEC_AS_ACTION_POP);
+ code = vivi_code_asm_pop_new ();
+ vivi_code_assembler_add_code (assembler, code);
+ g_object_unref (code);
}
static void
diff --git a/vivified/code/vivi_compiler_empty_statement.c b/vivified/code/vivi_compiler_empty_statement.c
index 5924234..de1bb50 100644
--- a/vivified/code/vivi_compiler_empty_statement.c
+++ b/vivified/code/vivi_compiler_empty_statement.c
@@ -24,7 +24,7 @@
#include "vivi_compiler_empty_statement.h"
#include "vivi_code_printer.h"
-#include "vivi_code_compiler.h"
+#include "vivi_code_assembler.h"
G_DEFINE_TYPE (ViviCompilerEmptyStatement, vivi_compiler_empty_statement, VIVI_TYPE_CODE_STATEMENT)
@@ -44,7 +44,7 @@ vivi_compiler_empty_statement_print (ViviCodeToken *token,
static void
vivi_compiler_empty_statement_compile (ViviCodeToken *token,
- ViviCodeCompiler *compile)
+ ViviCodeAssembler *assembler)
{
/* nothing */
}
diff --git a/vivified/code/vivi_parser.c b/vivified/code/vivi_parser.c
index 35619a2..4532f79 100644
--- a/vivified/code/vivi_parser.c
+++ b/vivified/code/vivi_parser.c
@@ -1131,12 +1131,12 @@ static const BuiltinStatement builtin_statements[] = {
{ "nextFrame", vivi_code_next_frame_new, NULL, NULL },
{ "play", vivi_code_play_new, NULL, NULL },
{ "prevFrame", vivi_code_previous_frame_new, NULL, NULL },
- { "removeMovieClip", NULL, vivi_code_remove_movie_clip_new, NULL },
+ { "removeMovieClip", NULL, vivi_code_remove_sprite_new, NULL },
//{ "setProperty", NULL, NULL, parse_set_property },
- { "setTarget", NULL, vivi_code_set_target_new, NULL },
+ { "setTarget", NULL, vivi_code_set_target2_new, NULL },
//{ "startDrag", NULL, NULL, parse_start_drag },
{ "stop", vivi_code_stop_new, NULL, NULL },
- { "stopDrag", vivi_code_stop_drag_new, NULL, NULL },
+ { "stopDrag", vivi_code_end_drag_new, NULL, NULL },
{ "stopSounds", vivi_code_stop_sounds_new, NULL, NULL },
{ "toggleQuality", vivi_code_toggle_quality_new, NULL, NULL },
{ "trace", NULL, vivi_code_trace_new, NULL }
@@ -1153,14 +1153,14 @@ typedef struct {
} BuiltinCall;
static const BuiltinCall builtin_calls[] = {
- { "chr", NULL, vivi_code_chr_new, NULL },
+ { "chr", NULL, vivi_code_ascii_to_char_new, NULL },
{ "concat", NULL, NULL, parse_concat },
- { "eval", NULL, vivi_code_eval_new, NULL },
+ { "eval", NULL, vivi_code_get_variable_new, NULL },
//{ "getProperty", NULL, NULL, parse_get_property },
{ "getTimer", vivi_code_get_timer_new, NULL, NULL },
- { "int", NULL, vivi_code_int_new, NULL },
- { "length", NULL, vivi_code_length_new, NULL },
- { "ord", NULL, vivi_code_ord_new, NULL },
+ { "int", NULL, vivi_code_to_integer_new, NULL },
+ { "length", NULL, vivi_code_string_length_new, NULL },
+ { "ord", NULL, vivi_code_char_to_ascii_new, NULL },
{ "random", NULL, vivi_code_random_new, NULL },
{ "substring", NULL, NULL, parse_substring },
{ "targetPath", NULL, NULL, parse_target_path },
@@ -1685,12 +1685,12 @@ parse_operator_expression (ParseData *data, ViviCodeValue **value,
{ TOKEN_PLUS, vivi_code_add2_new },
{ TOKEN_LESS_THAN, vivi_code_less2_new },
{ TOKEN_EQUAL, vivi_code_equals2_new },
- { TOKEN_BITWISE_AND, vivi_code_bitwise_and_new },
- { TOKEN_BITWISE_OR, vivi_code_bitwise_or_new },
- { TOKEN_BITWISE_XOR, vivi_code_bitwise_xor_new },
- { TOKEN_SHIFT_LEFT, vivi_code_left_shift_new },
- { TOKEN_SHIFT_RIGHT, vivi_code_right_shift_new },
- { TOKEN_SHIFT_RIGHT_UNSIGNED, vivi_code_unsigned_right_shift_new },
+// { TOKEN_BITWISE_AND, vivi_code_bitwise_and_new },
+// { TOKEN_BITWISE_OR, vivi_code_bitwise_or_new },
+// { TOKEN_BITWISE_XOR, vivi_code_bitwise_xor_new },
+// { TOKEN_SHIFT_LEFT, vivi_code_left_shift_new },
+// { TOKEN_SHIFT_RIGHT, vivi_code_right_shift_new },
+// { TOKEN_SHIFT_RIGHT_UNSIGNED, vivi_code_unsigned_right_shift_new },
{ TOKEN_STRICT_EQUAL, vivi_code_strict_equals_new },
{ TOKEN_GREATER_THAN, vivi_code_greater_new },
// { TOKEN_, vivi_code_string_greater_new },
@@ -2017,24 +2017,24 @@ parse_assignment_expression (ParseData *data, ViviCodeValue **value,
case TOKEN_ASSIGN_MINUS:
func = vivi_code_subtract_new;
break;
- case TOKEN_ASSIGN_SHIFT_LEFT:
- func = vivi_code_left_shift_new;
- break;
- case TOKEN_ASSIGN_SHIFT_RIGHT:
- func = vivi_code_right_shift_new;
- break;
- case TOKEN_ASSIGN_SHIFT_RIGHT_ZERO:
- func = vivi_code_unsigned_right_shift_new;
- break;
- case TOKEN_ASSIGN_BITWISE_AND:
- func = vivi_code_bitwise_and_new;
- break;
- case TOKEN_ASSIGN_BITWISE_OR:
- func = vivi_code_bitwise_or_new;
- break;
- case TOKEN_ASSIGN_BITWISE_XOR:
- func = vivi_code_bitwise_and_new;
- break;
+ //case TOKEN_ASSIGN_SHIFT_LEFT:
+ // func = vivi_code_left_shift_new;
+ // break;
+ //case TOKEN_ASSIGN_SHIFT_RIGHT:
+ // func = vivi_code_right_shift_new;
+ // break;
+ //case TOKEN_ASSIGN_SHIFT_RIGHT_ZERO:
+ // func = vivi_code_unsigned_right_shift_new;
+ // break;
+ //case TOKEN_ASSIGN_BITWISE_AND:
+ // func = vivi_code_bitwise_and_new;
+ // break;
+ //case TOKEN_ASSIGN_BITWISE_OR:
+ // func = vivi_code_bitwise_or_new;
+ // break;
+ //case TOKEN_ASSIGN_BITWISE_XOR:
+ // func = vivi_code_bitwise_xor_new;
+ // break;
case TOKEN_ASSIGN:
func = NULL;
break;
commit 9503e5265ba79c4946cb1d9dd1eda5a684e642bc
Merge: f5e4b09... 3aca0af...
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Fri Apr 18 09:12:55 2008 +0300
Merge branch 'master' of ssh://medar@git.freedesktop.org/git/swfdec/swfdec
Conflicts:
vivified/code/vivi_code_assignment.c
diff --cc vivified/code/vivi_code_assignment.c
index c7cddc4,e16367b..3024ac4
--- a/vivified/code/vivi_code_assignment.c
+++ b/vivified/code/vivi_code_assignment.c
@@@ -22,11 -22,11 +22,13 @@@
#endif
#include "vivi_code_assignment.h"
- #include "vivi_code_constant.h"
+ #include "vivi_code_compiler.h"
#include "vivi_code_get.h"
#include "vivi_code_printer.h"
+ #include "vivi_code_string.h"
+ #include "vivi_code_undefined.h"
+#include "vivi_code_assembler.h"
+#include "vivi_code_asm_code_default.h"
G_DEFINE_TYPE (ViviCodeAssignment, vivi_code_assignment, VIVI_TYPE_CODE_STATEMENT)
commit f5e4b0911068dd79896ba1f0db9bdc63a4b76373
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Fri Apr 18 09:11:41 2008 +0300
Make/start the change to new compile vfunc in various ViviCode classes
diff --git a/vivified/code/vivi_code_assignment.c b/vivified/code/vivi_code_assignment.c
index 1045031..c7cddc4 100644
--- a/vivified/code/vivi_code_assignment.c
+++ b/vivified/code/vivi_code_assignment.c
@@ -25,7 +25,8 @@
#include "vivi_code_constant.h"
#include "vivi_code_get.h"
#include "vivi_code_printer.h"
-#include "vivi_code_compiler.h"
+#include "vivi_code_assembler.h"
+#include "vivi_code_asm_code_default.h"
G_DEFINE_TYPE (ViviCodeAssignment, vivi_code_assignment, VIVI_TYPE_CODE_STATEMENT)
@@ -92,33 +93,33 @@ finalize:
}
static void
-vivi_code_assignment_compile (ViviCodeToken *token, ViviCodeCompiler *compiler)
+vivi_code_assignment_compile (ViviCodeToken *token,
+ ViviCodeAssembler *assembler)
{
ViviCodeAssignment *assignment = VIVI_CODE_ASSIGNMENT (token);
- SwfdecAsAction action;
+ ViviCodeAsm *code;
- vivi_code_compiler_compile_value (compiler, assignment->name);
+ vivi_code_value_compile (assignment->name, assembler);
if (assignment->from && !assignment->local)
- vivi_code_compiler_compile_value (compiler, assignment->from);
+ vivi_code_value_compile (assignment->from, assembler);
if (assignment->local && assignment->from) {
ViviCodeValue *get =
vivi_code_get_new (assignment->from, assignment->value);
- vivi_code_compiler_compile_value (compiler, get);
+ vivi_code_value_compile (get, assembler);
g_object_unref (get);
} else {
- vivi_code_compiler_compile_value (compiler, assignment->value);
+ vivi_code_value_compile (assignment->value, assembler);
}
-
if (assignment->local) {
- action = SWFDEC_AS_ACTION_DEFINE_LOCAL;
+ code = vivi_code_asm_define_local_new ();
} else if (assignment->from) {
- action = SWFDEC_AS_ACTION_SET_MEMBER;
+ code = vivi_code_asm_set_member_new ();
} else {
- action = SWFDEC_AS_ACTION_SET_VARIABLE;
+ code = vivi_code_asm_set_variable_new ();
}
- vivi_code_compiler_write_empty_action (compiler, action);
+ vivi_code_assembler_add_code (assembler, code);
}
static void
diff --git a/vivified/code/vivi_code_binary.c b/vivified/code/vivi_code_binary.c
index 2995c0e..5fab2b3 100644
--- a/vivified/code/vivi_code_binary.c
+++ b/vivified/code/vivi_code_binary.c
@@ -25,7 +25,7 @@
#include "vivi_code_binary.h"
#include "vivi_code_printer.h"
-#include "vivi_code_compiler.h"
+#include "vivi_code_assembler.h"
G_DEFINE_TYPE (ViviCodeBinary, vivi_code_binary, VIVI_TYPE_CODE_VALUE)
@@ -57,16 +57,16 @@ vivi_code_binary_print (ViviCodeToken *token, ViviCodePrinter*printer)
}
static void
-vivi_code_binary_compile (ViviCodeToken *token, ViviCodeCompiler *compiler)
+vivi_code_binary_compile (ViviCodeToken *token, ViviCodeAssembler *assembler)
{
ViviCodeBinary *binary = VIVI_CODE_BINARY (token);
ViviCodeBinaryClass *klass = VIVI_CODE_BINARY_GET_CLASS (binary);
- vivi_code_compiler_compile_value (compiler, binary->left);
- vivi_code_compiler_compile_value (compiler, binary->right);
+ vivi_code_value_compile (binary->left, assembler);
+ vivi_code_value_compile (binary->right, assembler);
- g_assert (klass->bytecode != 0);
- vivi_code_compiler_write_empty_action (compiler, klass->bytecode);
+ g_assert (klass->asm_constructor != 0);
+ vivi_code_assembler_add_code (assembler, klass->asm_constructor ());
}
static gboolean
diff --git a/vivified/code/vivi_code_binary.h b/vivified/code/vivi_code_binary.h
index b11cd03..ff21614 100644
--- a/vivified/code/vivi_code_binary.h
+++ b/vivified/code/vivi_code_binary.h
@@ -22,6 +22,7 @@
#include <swfdec/swfdec_as_interpret.h>
#include <vivified/code/vivi_code_value.h>
+#include <vivified/code/vivi_code_asm.h>
G_BEGIN_DECLS
@@ -51,7 +52,7 @@ struct _ViviCodeBinaryClass
/*< private >*/
/* use vivi_code_default.h */
const char * operator_name;
- SwfdecAsAction bytecode;
+ ViviCodeAsm * (*asm_constructor) (void);
};
GType vivi_code_binary_get_type (void);
diff --git a/vivified/code/vivi_code_binary_default.c b/vivified/code/vivi_code_binary_default.c
index dbb3ba4..9cecff3 100644
--- a/vivified/code/vivi_code_binary_default.c
+++ b/vivified/code/vivi_code_binary_default.c
@@ -24,8 +24,10 @@
#include <swfdec/swfdec_as_interpret.h>
#include "vivi_code_binary_default.h"
+#include "vivi_code_asm_code_default.h"
-#define DEFAULT_BINARY(CapsName, underscore_name, operatorname, bc, precedence) \
+
+#define DEFAULT_BINARY(CapsName, underscore_name, operatorname, precedence) \
\
G_DEFINE_TYPE (ViviCode ## CapsName, vivi_code_ ## underscore_name, VIVI_TYPE_CODE_BINARY) \
\
@@ -35,7 +37,7 @@ vivi_code_ ## underscore_name ## _class_init (ViviCodeBinaryClass *klass) \
ViviCodeBinaryClass *binary_class = VIVI_CODE_BINARY_CLASS (klass); \
\
binary_class->operator_name = operatorname; \
- binary_class->bytecode = bc; \
+ binary_class->asm_constructor = vivi_code_asm_ ## underscore_name ## _new; \
} \
\
static void \
diff --git a/vivified/code/vivi_code_binary_default.h b/vivified/code/vivi_code_binary_default.h
index 18a4926..7a36dee 100644
--- a/vivified/code/vivi_code_binary_default.h
+++ b/vivified/code/vivi_code_binary_default.h
@@ -24,7 +24,7 @@
G_BEGIN_DECLS
-#define DEFAULT_BINARY(CapsName, underscore_name, operator_name, bytecode, precedence) \
+#define DEFAULT_BINARY(CapsName, underscore_name, operator_name, precedence) \
\
typedef ViviCodeBinary ViviCode ## CapsName; \
typedef ViviCodeBinaryClass ViviCode ## CapsName ## Class; \
diff --git a/vivified/code/vivi_code_block.c b/vivified/code/vivi_code_block.c
index 06c415a..b9a760d 100644
--- a/vivified/code/vivi_code_block.c
+++ b/vivified/code/vivi_code_block.c
@@ -28,7 +28,7 @@
#include "vivi_code_comment.h"
#include "vivi_code_label.h"
#include "vivi_code_printer.h"
-#include "vivi_code_compiler.h"
+#include "vivi_code_assembler.h"
G_DEFINE_TYPE (ViviCodeBlock, vivi_code_block, VIVI_TYPE_CODE_STATEMENT)
@@ -90,14 +90,14 @@ vivi_code_block_print (ViviCodeToken *token, ViviCodePrinter *printer)
}
static void
-vivi_code_block_compile (ViviCodeToken *token, ViviCodeCompiler *compiler)
+vivi_code_block_compile (ViviCodeToken *token, ViviCodeAssembler *assembler)
{
ViviCodeBlock *block = VIVI_CODE_BLOCK (token);
guint i;
for (i = 0; i < block->statements->len; i++) {
- vivi_code_compiler_compile_token (compiler,
- VIVI_CODE_TOKEN (g_ptr_array_index (block->statements, i)));
+ vivi_code_statement_compile (VIVI_CODE_STATEMENT (g_ptr_array_index (
+ block->statements, i)), assembler);
}
}
diff --git a/vivified/code/vivi_code_break.c b/vivified/code/vivi_code_break.c
index 9286fa5..ded28d1 100644
--- a/vivified/code/vivi_code_break.c
+++ b/vivified/code/vivi_code_break.c
@@ -23,7 +23,7 @@
#include "vivi_code_break.h"
#include "vivi_code_printer.h"
-#include "vivi_code_compiler.h"
+#include "vivi_code_assembler.h"
G_DEFINE_TYPE (ViviCodeBreak, vivi_code_break, VIVI_TYPE_CODE_STATEMENT)
@@ -35,7 +35,7 @@ vivi_code_break_print (ViviCodeToken *token, ViviCodePrinter *printer)
}
static void
-vivi_code_break_compile (ViviCodeToken *token, ViviCodeCompiler *compiler)
+vivi_code_break_compile (ViviCodeToken *token, ViviCodeAssembler *assembler)
{
g_printerr ("Implement break\n");
}
diff --git a/vivified/code/vivi_code_builtin_call.c b/vivified/code/vivi_code_builtin_call.c
index cc81bb2..ba9d7ae 100644
--- a/vivified/code/vivi_code_builtin_call.c
+++ b/vivified/code/vivi_code_builtin_call.c
@@ -23,7 +23,7 @@
#include "vivi_code_builtin_call.h"
#include "vivi_code_printer.h"
-#include "vivi_code_compiler.h"
+#include "vivi_code_assembler.h"
G_DEFINE_ABSTRACT_TYPE (ViviCodeBuiltinCall, vivi_code_builtin_call, VIVI_TYPE_CODE_VALUE)
@@ -40,12 +40,12 @@ vivi_code_builtin_call_print (ViviCodeToken *token, ViviCodePrinter *printer)
static void
vivi_code_builtin_call_compile (ViviCodeToken *token,
- ViviCodeCompiler *compiler)
+ ViviCodeAssembler *assembler)
{
ViviCodeBuiltinCallClass *klass = VIVI_CODE_BUILTIN_CALL_GET_CLASS (token);
- g_assert (klass->bytecode != SWFDEC_AS_ACTION_END);
- vivi_code_compiler_write_empty_action (compiler, klass->bytecode);
+ g_assert (klass->asm_constructor != NULL);
+ vivi_code_assembler_add_code (assembler, klass->asm_constructor ());
}
static void
diff --git a/vivified/code/vivi_code_builtin_call.h b/vivified/code/vivi_code_builtin_call.h
index c174a91..54400e7 100644
--- a/vivified/code/vivi_code_builtin_call.h
+++ b/vivified/code/vivi_code_builtin_call.h
@@ -23,6 +23,7 @@
#include <swfdec/swfdec_as_interpret.h>
#include <vivified/code/vivi_code_value.h>
+#include <vivified/code/vivi_code_asm.h>
G_BEGIN_DECLS
@@ -47,7 +48,7 @@ struct _ViviCodeBuiltinCallClass
ViviCodeValueClass value_class;
const char * function_name;
- SwfdecAsAction bytecode;
+ ViviCodeAsm * (*asm_constructor) (void);
};
GType vivi_code_builtin_call_get_type (void);
diff --git a/vivified/code/vivi_code_builtin_statement.c b/vivified/code/vivi_code_builtin_statement.c
index 0abea7c..9f89d72 100644
--- a/vivified/code/vivi_code_builtin_statement.c
+++ b/vivified/code/vivi_code_builtin_statement.c
@@ -23,7 +23,7 @@
#include "vivi_code_builtin_statement.h"
#include "vivi_code_printer.h"
-#include "vivi_code_compiler.h"
+#include "vivi_code_assembler.h"
G_DEFINE_ABSTRACT_TYPE (ViviCodeBuiltinStatement, vivi_code_builtin_statement, VIVI_TYPE_CODE_STATEMENT)
@@ -42,13 +42,13 @@ vivi_code_builtin_statement_print (ViviCodeToken *token,
static void
vivi_code_builtin_statement_compile (ViviCodeToken *token,
- ViviCodeCompiler *compiler)
+ ViviCodeAssembler *assembler)
{
ViviCodeBuiltinStatementClass *klass =
VIVI_CODE_BUILTIN_STATEMENT_GET_CLASS (token);
- g_assert (klass->bytecode != SWFDEC_AS_ACTION_END);
- vivi_code_compiler_write_empty_action (compiler, klass->bytecode);
+ g_assert (klass->asm_constructor != NULL);
+ vivi_code_assembler_add_code (assembler, klass->asm_constructor ());
}
static void
diff --git a/vivified/code/vivi_code_builtin_statement.h b/vivified/code/vivi_code_builtin_statement.h
index 2a26b5b..a596ee4 100644
--- a/vivified/code/vivi_code_builtin_statement.h
+++ b/vivified/code/vivi_code_builtin_statement.h
@@ -23,6 +23,7 @@
#include <swfdec/swfdec_as_interpret.h>
#include <vivified/code/vivi_code_statement.h>
+#include <vivified/code/vivi_code_asm.h>
G_BEGIN_DECLS
@@ -47,7 +48,7 @@ struct _ViviCodeBuiltinStatementClass
ViviCodeStatementClass statement_class;
const char * function_name;
- SwfdecAsAction bytecode;
+ ViviCodeAsm * (*asm_constructor) (void);
};
GType vivi_code_builtin_statement_get_type (void);
diff --git a/vivified/code/vivi_code_builtin_statement_default.c b/vivified/code/vivi_code_builtin_statement_default.c
index c464f02..4a6b917 100644
--- a/vivified/code/vivi_code_builtin_statement_default.c
+++ b/vivified/code/vivi_code_builtin_statement_default.c
@@ -23,18 +23,19 @@
#endif
#include "vivi_code_builtin_statement_default.h"
+#include "vivi_code_asm_code_default.h"
-#define DEFAULT_BUILTIN_STATEMENT(CapsName, underscore_name, name, bc) \
+#define DEFAULT_BUILTIN_STATEMENT(CapsName, underscore_name, name) \
\
G_DEFINE_TYPE (ViviCode ## CapsName, vivi_code_ ## underscore_name, VIVI_TYPE_CODE_BUILTIN_STATEMENT) \
\
static void \
vivi_code_ ## underscore_name ## _class_init (ViviCodeBuiltinStatementClass *klass) \
{ \
- ViviCodeBuiltinStatementClass *builtin_statement_class = VIVI_CODE_BUILTIN_STATEMENT_CLASS (klass); \
+ ViviCodeBuiltinStatementClass *builtin_class = VIVI_CODE_BUILTIN_STATEMENT_CLASS (klass); \
\
- builtin_statement_class->function_name = name; \
- builtin_statement_class->bytecode = bc; \
+ builtin_class->function_name = name; \
+ builtin_class->asm_constructor = vivi_code_asm_ ## underscore_name ## _new; \
} \
\
static void \
diff --git a/vivified/code/vivi_code_builtin_statement_default.h b/vivified/code/vivi_code_builtin_statement_default.h
index 78c1611..bfb0001 100644
--- a/vivified/code/vivi_code_builtin_statement_default.h
+++ b/vivified/code/vivi_code_builtin_statement_default.h
@@ -25,7 +25,7 @@
G_BEGIN_DECLS
-#define DEFAULT_BUILTIN_STATEMENT(CapsName, underscore_name, function_name, bytecode) \
+#define DEFAULT_BUILTIN_STATEMENT(CapsName, underscore_name, function_name) \
\
typedef ViviCodeBuiltinStatement ViviCode ## CapsName; \
typedef ViviCodeBuiltinStatementClass ViviCode ## CapsName ## Class; \
diff --git a/vivified/code/vivi_code_builtin_value_call.c b/vivified/code/vivi_code_builtin_value_call.c
index e3f6f9a..0829eb2 100644
--- a/vivified/code/vivi_code_builtin_value_call.c
+++ b/vivified/code/vivi_code_builtin_value_call.c
@@ -23,7 +23,7 @@
#include "vivi_code_builtin_value_call.h"
#include "vivi_code_printer.h"
-#include "vivi_code_compiler.h"
+#include "vivi_code_assembler.h"
G_DEFINE_ABSTRACT_TYPE (ViviCodeBuiltinValueCall, vivi_code_builtin_value_call, VIVI_TYPE_CODE_BUILTIN_CALL)
@@ -58,16 +58,16 @@ vivi_code_builtin_value_call_print (ViviCodeToken *token,
static void
vivi_code_builtin_value_call_compile (ViviCodeToken *token,
- ViviCodeCompiler *compiler)
+ ViviCodeAssembler *assembler)
{
ViviCodeBuiltinCallClass *klass = VIVI_CODE_BUILTIN_CALL_GET_CLASS (token);
ViviCodeBuiltinValueCall *call = VIVI_CODE_BUILTIN_VALUE_CALL (token);
g_assert (call->value != NULL);
- vivi_code_compiler_compile_value (compiler, call->value);
+ vivi_code_value_compile (call->value, assembler);
- g_assert (klass->bytecode != SWFDEC_AS_ACTION_END);
- vivi_code_compiler_write_empty_action (compiler, klass->bytecode);
+ g_assert (klass->asm_constructor != NULL);
+ vivi_code_assembler_add_code (assembler, klass->asm_constructor ());
}
static void
diff --git a/vivified/code/vivi_code_builtin_value_call_default.c b/vivified/code/vivi_code_builtin_value_call_default.c
index 7be6d08..7f230cc 100644
--- a/vivified/code/vivi_code_builtin_value_call_default.c
+++ b/vivified/code/vivi_code_builtin_value_call_default.c
@@ -23,8 +23,9 @@
#endif
#include "vivi_code_builtin_value_call_default.h"
+#include "vivi_code_asm_code_default.h"
-#define DEFAULT_BUILTIN_VALUE_CALL(CapsName, underscore_name, name, bc) \
+#define DEFAULT_BUILTIN_VALUE_CALL(CapsName, underscore_name, name) \
\
G_DEFINE_TYPE (ViviCode ## CapsName, vivi_code_ ## underscore_name, VIVI_TYPE_CODE_BUILTIN_VALUE_CALL) \
\
@@ -34,7 +35,7 @@ vivi_code_ ## underscore_name ## _class_init (ViviCodeBuiltinValueCallClass *kla
ViviCodeBuiltinCallClass *builtin_class = VIVI_CODE_BUILTIN_CALL_CLASS (klass); \
\
builtin_class->function_name = name; \
- builtin_class->bytecode = bc; \
+ builtin_class->asm_constructor = vivi_code_asm_ ## underscore_name ## _new; \
} \
\
static void \
diff --git a/vivified/code/vivi_code_builtin_value_call_default.h b/vivified/code/vivi_code_builtin_value_call_default.h
index 80bd624..c0b56ad 100644
--- a/vivified/code/vivi_code_builtin_value_call_default.h
+++ b/vivified/code/vivi_code_builtin_value_call_default.h
@@ -26,7 +26,7 @@
G_BEGIN_DECLS
-#define DEFAULT_BUILTIN_VALUE_CALL(CapsName, underscore_name, function_name, bytecode) \
+#define DEFAULT_BUILTIN_VALUE_CALL(CapsName, underscore_name, function_name) \
\
typedef ViviCodeBuiltinValueCall ViviCode ## CapsName; \
typedef ViviCodeBuiltinValueCallClass ViviCode ## CapsName ## Class; \
diff --git a/vivified/code/vivi_code_builtin_value_statement.c b/vivified/code/vivi_code_builtin_value_statement.c
index c4f85a5..25d5fc2 100644
--- a/vivified/code/vivi_code_builtin_value_statement.c
+++ b/vivified/code/vivi_code_builtin_value_statement.c
@@ -23,7 +23,7 @@
#include "vivi_code_builtin_value_statement.h"
#include "vivi_code_printer.h"
-#include "vivi_code_compiler.h"
+#include "vivi_code_assembler.h"
G_DEFINE_ABSTRACT_TYPE (ViviCodeBuiltinValueStatement, vivi_code_builtin_value_statement, VIVI_TYPE_CODE_BUILTIN_STATEMENT)
@@ -61,7 +61,7 @@ vivi_code_builtin_value_statement_print (ViviCodeToken *token,
static void
vivi_code_builtin_value_statement_compile (ViviCodeToken *token,
- ViviCodeCompiler *compiler)
+ ViviCodeAssembler *assembler)
{
ViviCodeBuiltinStatementClass *klass =
VIVI_CODE_BUILTIN_STATEMENT_GET_CLASS (token);
@@ -69,10 +69,10 @@ vivi_code_builtin_value_statement_compile (ViviCodeToken *token,
VIVI_CODE_BUILTIN_VALUE_STATEMENT (token);
g_assert (stmt->value != NULL);
- vivi_code_compiler_compile_value (compiler, stmt->value);
+ vivi_code_value_compile (stmt->value, assembler);
- g_assert (klass->bytecode != SWFDEC_AS_ACTION_END);
- vivi_code_compiler_write_empty_action (compiler, klass->bytecode);
+ g_assert (klass->asm_constructor != NULL);
+ vivi_code_assembler_add_code (assembler, klass->asm_constructor ());
}
static void
diff --git a/vivified/code/vivi_code_builtin_value_statement_default.c b/vivified/code/vivi_code_builtin_value_statement_default.c
index 9d9ab80..d9d7f97 100644
--- a/vivified/code/vivi_code_builtin_value_statement_default.c
+++ b/vivified/code/vivi_code_builtin_value_statement_default.c
@@ -23,8 +23,9 @@
#endif
#include "vivi_code_builtin_value_statement_default.h"
+#include "vivi_code_asm_code_default.h"
-#define DEFAULT_BUILTIN_VALUE_STATEMENT(CapsName, underscore_name, name, bc) \
+#define DEFAULT_BUILTIN_VALUE_STATEMENT(CapsName, underscore_name, name) \
\
G_DEFINE_TYPE (ViviCode ## CapsName, vivi_code_ ## underscore_name, VIVI_TYPE_CODE_BUILTIN_VALUE_STATEMENT) \
\
@@ -34,7 +35,7 @@ vivi_code_ ## underscore_name ## _class_init (ViviCodeBuiltinValueStatementClass
ViviCodeBuiltinStatementClass *builtin_statement_class = VIVI_CODE_BUILTIN_STATEMENT_CLASS (klass); \
\
builtin_statement_class->function_name = name; \
- builtin_statement_class->bytecode = bc; \
+ builtin_statement_class->asm_constructor = vivi_code_asm_ ## underscore_name ## _new; \
} \
\
static void \
diff --git a/vivified/code/vivi_code_builtin_value_statement_default.h b/vivified/code/vivi_code_builtin_value_statement_default.h
index 1fb4856..809ffc6 100644
--- a/vivified/code/vivi_code_builtin_value_statement_default.h
+++ b/vivified/code/vivi_code_builtin_value_statement_default.h
@@ -26,7 +26,7 @@
G_BEGIN_DECLS
-#define DEFAULT_BUILTIN_VALUE_STATEMENT(CapsName, underscore_name, function_name, bytecode) \
+#define DEFAULT_BUILTIN_VALUE_STATEMENT(CapsName, underscore_name, function_name) \
\
typedef ViviCodeBuiltinValueStatement ViviCode ## CapsName; \
typedef ViviCodeBuiltinValueStatementClass ViviCode ## CapsName ## Class; \
diff --git a/vivified/code/vivi_code_comment.c b/vivified/code/vivi_code_comment.c
index 65fe694..188df42 100644
--- a/vivified/code/vivi_code_comment.c
+++ b/vivified/code/vivi_code_comment.c
@@ -23,7 +23,7 @@
#include "vivi_code_comment.h"
#include "vivi_code_asm.h"
-#include "vivi_code_compiler.h"
+#include "vivi_code_assembler.h"
#include "vivi_code_printer.h"
static void
@@ -56,9 +56,9 @@ vivi_code_comment_print (ViviCodeToken *token, ViviCodePrinter *printer)
}
static void
-vivi_code_comment_compile (ViviCodeToken *token, ViviCodeCompiler *compile)
+vivi_code_comment_compile (ViviCodeToken *token, ViviCodeAssembler *assembler)
{
- /* nothing */
+ g_printerr ("Implement comment");
}
static void
diff --git a/vivified/code/vivi_code_concat.c b/vivified/code/vivi_code_concat.c
index 4f29155..f237484 100644
--- a/vivified/code/vivi_code_concat.c
+++ b/vivified/code/vivi_code_concat.c
@@ -23,7 +23,8 @@
#include "vivi_code_concat.h"
#include "vivi_code_printer.h"
-#include "vivi_code_compiler.h"
+#include "vivi_code_assembler.h"
+#include "vivi_code_asm_code_default.h"
G_DEFINE_TYPE (ViviCodeConcat, vivi_code_concat, VIVI_TYPE_CODE_VALUE)
@@ -54,15 +55,14 @@ vivi_code_concat_print (ViviCodeToken *token, ViviCodePrinter *printer)
}
static void
-vivi_code_concat_compile (ViviCodeToken *token, ViviCodeCompiler *compiler)
+vivi_code_concat_compile (ViviCodeToken *token, ViviCodeAssembler *assembler)
{
ViviCodeConcat *concat = VIVI_CODE_CONCAT (token);
- vivi_code_compiler_compile_value (compiler, concat->first);
- vivi_code_compiler_compile_value (compiler, concat->second);
+ vivi_code_value_compile (concat->first, assembler);
+ vivi_code_value_compile (concat->second, assembler);
- vivi_code_compiler_write_empty_action (compiler,
- SWFDEC_AS_ACTION_STRING_ADD);
+ vivi_code_assembler_add_code (assembler, vivi_code_asm_string_add_new ());
}
static void
diff --git a/vivified/code/vivi_code_defaults.h b/vivified/code/vivi_code_defaults.h
index 62c62d8..4b929d6 100644
--- a/vivified/code/vivi_code_defaults.h
+++ b/vivified/code/vivi_code_defaults.h
@@ -19,32 +19,32 @@
*/
#ifndef DEFAULT_BINARY
-#define DEFAULT_BINARY(CapsName, underscore_name, operator_name, bytecode, precedence)
+#define DEFAULT_BINARY(CapsName, underscore_name, operator_name, precedence)
#endif
-DEFAULT_BINARY (Add, add, "add", SWFDEC_AS_ACTION_ADD, VIVI_PRECEDENCE_ADD)
-DEFAULT_BINARY (Subtract, subtract, "-", SWFDEC_AS_ACTION_SUBTRACT, VIVI_PRECEDENCE_ADD)
-DEFAULT_BINARY (Multiply, multiply, "*", SWFDEC_AS_ACTION_MULTIPLY, VIVI_PRECEDENCE_MULTIPLY)
-DEFAULT_BINARY (Divide, divide, "/", SWFDEC_AS_ACTION_DIVIDE, VIVI_PRECEDENCE_MULTIPLY)
-DEFAULT_BINARY (Modulo, modulo, "%", SWFDEC_AS_ACTION_MODULO, VIVI_PRECEDENCE_MULTIPLY)
-DEFAULT_BINARY (Equals, equals, "==", SWFDEC_AS_ACTION_EQUALS, VIVI_PRECEDENCE_EQUALITY)
-DEFAULT_BINARY (Less, less, "<", SWFDEC_AS_ACTION_LESS, VIVI_PRECEDENCE_RELATIONAL)
-DEFAULT_BINARY (LogicalAnd, logical_and, "and", SWFDEC_AS_ACTION_AND, VIVI_PRECEDENCE_AND)
-DEFAULT_BINARY (LogicalOr, logical_or, "or", SWFDEC_AS_ACTION_OR, VIVI_PRECEDENCE_OR)
-DEFAULT_BINARY (StringEquals, string_equals, "eq", SWFDEC_AS_ACTION_STRING_EQUALS, VIVI_PRECEDENCE_EQUALITY)
-DEFAULT_BINARY (StringLess, string_less, "lt", SWFDEC_AS_ACTION_STRING_LESS, VIVI_PRECEDENCE_RELATIONAL)
-DEFAULT_BINARY (Add2, add2, "+", SWFDEC_AS_ACTION_ADD2, VIVI_PRECEDENCE_ADD)
-DEFAULT_BINARY (Less2, less2, "<", SWFDEC_AS_ACTION_LESS2, VIVI_PRECEDENCE_RELATIONAL)
-DEFAULT_BINARY (Equals2, equals2, "==", SWFDEC_AS_ACTION_EQUALS2, VIVI_PRECEDENCE_EQUALITY)
-DEFAULT_BINARY (BitwiseAnd, bitwise_and, "&", SWFDEC_AS_ACTION_BIT_AND, VIVI_PRECEDENCE_BINARY_AND)
-DEFAULT_BINARY (BitwiseOr, bitwise_or, "|", SWFDEC_AS_ACTION_BIT_OR, VIVI_PRECEDENCE_BINARY_OR)
-DEFAULT_BINARY (BitwiseXor, bitwise_xor, "^", SWFDEC_AS_ACTION_BIT_XOR, VIVI_PRECEDENCE_BINARY_XOR)
-DEFAULT_BINARY (LeftShift, left_shift, "<<", SWFDEC_AS_ACTION_BIT_LSHIFT, VIVI_PRECEDENCE_SHIFT)
-DEFAULT_BINARY (RightShift, right_shift, ">>", SWFDEC_AS_ACTION_BIT_RSHIFT, VIVI_PRECEDENCE_SHIFT)
-DEFAULT_BINARY (UnsignedRightShift,unsigned_right_shift,">>>",SWFDEC_AS_ACTION_BIT_URSHIFT,VIVI_PRECEDENCE_SHIFT)
-DEFAULT_BINARY (StrictEquals, strict_equals, "===", SWFDEC_AS_ACTION_STRICT_EQUALS, VIVI_PRECEDENCE_EQUALITY)
-DEFAULT_BINARY (Greater, greater, ">", SWFDEC_AS_ACTION_GREATER, VIVI_PRECEDENCE_RELATIONAL)
-DEFAULT_BINARY (StringGreater, string_greater, "gt", SWFDEC_AS_ACTION_STRING_GREATER,VIVI_PRECEDENCE_RELATIONAL)
+DEFAULT_BINARY (Add, add, "add", VIVI_PRECEDENCE_ADD)
+/*DEFAULT_BINARY (Subtract, subtract, "-", VIVI_PRECEDENCE_ADD)
+DEFAULT_BINARY (Multiply, multiply, "*", VIVI_PRECEDENCE_MULTIPLY)
+DEFAULT_BINARY (Divide, divide, "/", VIVI_PRECEDENCE_MULTIPLY)
+DEFAULT_BINARY (Modulo, modulo, "%", VIVI_PRECEDENCE_MULTIPLY)
+DEFAULT_BINARY (Equals, equals, "==", VIVI_PRECEDENCE_EQUALITY)
+DEFAULT_BINARY (Less, less, "<", VIVI_PRECEDENCE_RELATIONAL)
+DEFAULT_BINARY (LogicalAnd, logical_and, "and", VIVI_PRECEDENCE_AND)
+DEFAULT_BINARY (LogicalOr, logical_or, "or", VIVI_PRECEDENCE_OR)
+DEFAULT_BINARY (StringEquals, string_equals, "eq", VIVI_PRECEDENCE_EQUALITY)
+DEFAULT_BINARY (StringLess, string_less, "lt", VIVI_PRECEDENCE_RELATIONAL)
+DEFAULT_BINARY (Add2, add2, "+", VIVI_PRECEDENCE_ADD)
+DEFAULT_BINARY (Less2, less2, "<", VIVI_PRECEDENCE_RELATIONAL)
+DEFAULT_BINARY (Equals2, equals2, "==", VIVI_PRECEDENCE_EQUALITY)
+DEFAULT_BINARY (BitwiseAnd, bitwise_and, "&", VIVI_PRECEDENCE_BINARY_AND)
+DEFAULT_BINARY (BitwiseOr, bitwise_or, "|", VIVI_PRECEDENCE_BINARY_OR)
+DEFAULT_BINARY (BitwiseXor, bitwise_xor, "^", VIVI_PRECEDENCE_BINARY_XOR)
+DEFAULT_BINARY (LeftShift, left_shift, "<<", VIVI_PRECEDENCE_SHIFT)
+DEFAULT_BINARY (RightShift, right_shift, ">>", VIVI_PRECEDENCE_SHIFT)
+DEFAULT_BINARY (UnsignedRightShift,unsigned_right_shift,">>>",VIVI_PRECEDENCE_SHIFT)
+DEFAULT_BINARY (StrictEquals, strict_equals, "===", VIVI_PRECEDENCE_EQUALITY)
+DEFAULT_BINARY (Greater, greater, ">", VIVI_PRECEDENCE_RELATIONAL)
+DEFAULT_BINARY (StringGreater, string_greater, "gt", VIVI_PRECEDENCE_RELATIONAL)*/
/* other special ones:
DEFAULT_BINARY (And, and, "&&", ???, VIVI_PRECEDENCE_AND)
DEFAULT_BINARY (Or, or, "||", ???, VIVI_PRECEDENCE_AND)
@@ -53,44 +53,44 @@ DEFAULT_BINARY (Or, or, "||", ???, VIVI_PRECEDENCE_AND)
#undef DEFAULT_BINARY
#ifndef DEFAULT_BUILTIN_STATEMENT
-#define DEFAULT_BUILTIN_STATEMENT(CapsName, underscore_name, function_name, bytecode)
+#define DEFAULT_BUILTIN_STATEMENT(CapsName, underscore_name, function_name)
#endif
-DEFAULT_BUILTIN_STATEMENT (NextFrame, next_frame, "nextFrame", SWFDEC_AS_ACTION_NEXT_FRAME)
-DEFAULT_BUILTIN_STATEMENT (Play, play, "play", SWFDEC_AS_ACTION_PLAY)
-DEFAULT_BUILTIN_STATEMENT (PreviousFrame, previous_frame, "prevFrame", SWFDEC_AS_ACTION_PREVIOUS_FRAME)
-DEFAULT_BUILTIN_STATEMENT (Stop, stop, "stop", SWFDEC_AS_ACTION_STOP)
-DEFAULT_BUILTIN_STATEMENT (StopDrag, stop_drag, "stopDrag", SWFDEC_AS_ACTION_END_DRAG)
-DEFAULT_BUILTIN_STATEMENT (StopSounds, stop_sounds, "stopSounds", SWFDEC_AS_ACTION_STOP_SOUNDS)
-DEFAULT_BUILTIN_STATEMENT (ToggleQuality, toggle_quality, "toggleQuality", SWFDEC_AS_ACTION_TOGGLE_QUALITY)
+DEFAULT_BUILTIN_STATEMENT (NextFrame, next_frame, "nextFrame")
+DEFAULT_BUILTIN_STATEMENT (Play, play, "play")
+DEFAULT_BUILTIN_STATEMENT (PreviousFrame, previous_frame, "prevFrame")
+DEFAULT_BUILTIN_STATEMENT (Stop, stop, "stop")
+DEFAULT_BUILTIN_STATEMENT (EndDrag, end_drag, "stopDrag")
+DEFAULT_BUILTIN_STATEMENT (StopSounds, stop_sounds, "stopSounds")
+DEFAULT_BUILTIN_STATEMENT (ToggleQuality, toggle_quality, "toggleQuality")
#undef DEFAULT_BUILTIN_STATEMENT
#ifndef DEFAULT_BUILTIN_VALUE_STATEMENT
-#define DEFAULT_BUILTIN_VALUE_STATEMENT(CapsName, underscore_name, function_name, bytecode)
+#define DEFAULT_BUILTIN_VALUE_STATEMENT(CapsName, underscore_name, function_name)
#endif
-//DEFAULT_BUILTIN_VALUE_STATEMENT (CallFrame, call_frame, "callFrame", SWFDEC_AS_ACTION_CALL)
-//DEFAULT_BUILTIN_VALUE_STATEMENT (GotoAndPlay, goto_and_play, "gotoAndPlay", ???)
-//DEFAULT_BUILTIN_VALUE_STATEMENT (GotoAndStop, goto_and_stop, "gotoAndStop", ???)
-DEFAULT_BUILTIN_VALUE_STATEMENT (RemoveMovieClip, remove_movie_clip, "removeMovieClip", SWFDEC_AS_ACTION_REMOVE_SPRITE)
-DEFAULT_BUILTIN_VALUE_STATEMENT (SetTarget, set_target, "setTarget", SWFDEC_AS_ACTION_SET_TARGET2)
-DEFAULT_BUILTIN_VALUE_STATEMENT (Trace, trace, "trace", SWFDEC_AS_ACTION_TRACE)
+//DEFAULT_BUILTIN_VALUE_STATEMENT (CallFrame, call_frame, "callFrame", SWFDEC_AS_ACTION_CALL)
+//DEFAULT_BUILTIN_VALUE_STATEMENT (GotoAndPlay, goto_and_play, "gotoAndPlay", ???)
+//DEFAULT_BUILTIN_VALUE_STATEMENT (GotoAndStop, goto_and_stop, "gotoAndStop", ???)
+DEFAULT_BUILTIN_VALUE_STATEMENT (RemoveSprite, remove_sprite, "removeMovieClip")
+DEFAULT_BUILTIN_VALUE_STATEMENT (SetTarget2, set_target2, "setTarget")
+DEFAULT_BUILTIN_VALUE_STATEMENT (Trace, trace, "trace")
#undef DEFAULT_BUILTIN_VALUE_STATEMENT
#ifndef DEFAULT_BUILTIN_VALUE_CALL
-#define DEFAULT_BUILTIN_VALUE_CALL(CapsName, underscore_name, function_name, bytecode)
+#define DEFAULT_BUILTIN_VALUE_CALL(CapsName, underscore_name, function_name)
#endif
-DEFAULT_BUILTIN_VALUE_CALL (Chr, chr, "chr", SWFDEC_AS_ACTION_ASCII_TO_CHAR)
-DEFAULT_BUILTIN_VALUE_CALL (Eval, eval, "eval", SWFDEC_AS_ACTION_GET_VARIABLE)
-DEFAULT_BUILTIN_VALUE_CALL (Int, int, "int", SWFDEC_AS_ACTION_TO_INTEGER)
-DEFAULT_BUILTIN_VALUE_CALL (Length, length, "length", SWFDEC_AS_ACTION_STRING_LENGTH)
-DEFAULT_BUILTIN_VALUE_CALL (Ord, ord, "ord", SWFDEC_AS_ACTION_CHAR_TO_ASCII)
-DEFAULT_BUILTIN_VALUE_CALL (Random, random, "random", SWFDEC_AS_ACTION_RANDOM)
-DEFAULT_BUILTIN_VALUE_CALL (TargetPath, target_path, "targetPath", SWFDEC_AS_ACTION_TARGET_PATH)
-DEFAULT_BUILTIN_VALUE_CALL (TypeOf, type_of, "typeOf", SWFDEC_AS_ACTION_TYPE_OF)
+DEFAULT_BUILTIN_VALUE_CALL (AsciiToChar, ascii_to_char, "chr")
+DEFAULT_BUILTIN_VALUE_CALL (GetVariable, get_variable, "eval")
+DEFAULT_BUILTIN_VALUE_CALL (ToInteger, to_integer, "int")
+DEFAULT_BUILTIN_VALUE_CALL (StringLength, string_length, "length")
+DEFAULT_BUILTIN_VALUE_CALL (CharToAscii, char_to_ascii, "ord")
+DEFAULT_BUILTIN_VALUE_CALL (Random, random, "random")
+DEFAULT_BUILTIN_VALUE_CALL (TargetPath, target_path, "targetPath")
+DEFAULT_BUILTIN_VALUE_CALL (TypeOf, type_of, "typeOf")
#undef DEFAULT_BUILTIN_VALUE_CALL
diff --git a/vivified/code/vivi_code_if.c b/vivified/code/vivi_code_if.c
index 4bc5471..112f883 100644
--- a/vivified/code/vivi_code_if.c
+++ b/vivified/code/vivi_code_if.c
@@ -129,28 +129,26 @@ static void
vivi_code_if_compile (ViviCodeToken *token, ViviCodeCompiler *compiler)
{
ViviCodeIf *stmt = VIVI_CODE_IF (token);
+ ViviCodeAsmLabel *label_if, *label_else;
vivi_code_compiler_compile_value (compiler, stmt->condition);
- vivi_code_compiler_begin_action (compiler, SWFDEC_AS_ACTION_IF);
+ label_if = vivi_code_asm_label_new ();
+ vivi_code_compiler_add (compiler, vivi_code_asm_if_new (label_if));
- if (stmt->else_statement) {
- vivi_code_compiler_compile_token (compiler,
- VIVI_CODE_TOKEN (stmt->else_statement));
- }
+ if (stmt->else_statement)
+ vivi_code_compiler_compile_statement (compiler, stmt->else_statement);
- vivi_code_compiler_write_s16 (compiler,
- vivi_code_compiler_tail_size (compiler) + 5); // else_statement + jump
- vivi_code_compiler_end_action (compiler);
+ label_else = vivi_code_asm_label_new ();
+ vivi_code_compiler_add (compiler, vivi_code_asm_jump_new (label_else));
+ g_object_unref (label_else);
- vivi_code_compiler_begin_action (compiler, SWFDEC_AS_ACTION_JUMP);
+ vivi_code_compiler_add (compiler, label_if);
+ g_object_unref (label_if);
- vivi_code_compiler_compile_token (compiler,
- VIVI_CODE_TOKEN (stmt->if_statement));
+ vivi_code_compiler_compile_statement (compiler, stmt->if_statement);
- vivi_code_compiler_write_s16 (compiler,
- vivi_code_compiler_tail_size (compiler)); // if_statement
- vivi_code_compiler_end_action (compiler);
+ vivi_code_compiler_add (compiler, label_else);
}
static void
commit 7995ab696c3079ae89de00a3fe315a39c6a85340
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Fri Apr 18 09:11:13 2008 +0300
Remove the ViviCodeCompiler class and make compile vfunc convert to assembler
diff --git a/vivified/code/Makefile.am b/vivified/code/Makefile.am
index d0ae8a5..319c1d4 100644
--- a/vivified/code/Makefile.am
+++ b/vivified/code/Makefile.am
@@ -34,7 +34,6 @@ libvivified_compiler_la_SOURCES = \
vivi_code_builtin_value_statement.c \
vivi_code_builtin_value_statement_default.c \
vivi_code_comment.c \
- vivi_code_compiler.c \
vivi_code_concat.c \
vivi_code_constant.c \
vivi_code_continue.c \
@@ -90,7 +89,6 @@ noinst_HEADERS = \
vivi_code_builtin_value_statement.h \
vivi_code_builtin_value_statement_default.h \
vivi_code_comment.h \
- vivi_code_compiler.h \
vivi_code_concat.h \
vivi_code_constant.h \
vivi_code_continue.h \
diff --git a/vivified/code/vivi_code_asm_code.c b/vivified/code/vivi_code_asm_code.c
index 7f060b3..9c6971c 100644
--- a/vivified/code/vivi_code_asm_code.c
+++ b/vivified/code/vivi_code_asm_code.c
@@ -25,7 +25,6 @@
#include "vivi_code_asm_code.h"
#include "vivi_code_asm.h"
-#include "vivi_code_compiler.h"
#include "vivi_code_printer.h"
static void
@@ -37,21 +36,8 @@ G_DEFINE_TYPE_WITH_CODE (ViviCodeAsmCode, vivi_code_asm_code, VIVI_TYPE_CODE_ASM
G_IMPLEMENT_INTERFACE (VIVI_TYPE_CODE_ASM, vivi_code_asm_code_asm_init))
static void
-vivi_code_asm_code_compile (ViviCodeToken *token, ViviCodeCompiler *compiler)
-{
- ViviCodeAsmCode *code = VIVI_CODE_ASM_CODE (token);
- SwfdecAsAction action = vivi_code_asm_code_get_action (code);
-
- g_assert (action < 0x80);
- vivi_code_compiler_write_empty_action (compiler, action);
-}
-
-static void
vivi_code_asm_code_class_init (ViviCodeAsmCodeClass *klass)
{
- ViviCodeTokenClass *token_class = VIVI_CODE_TOKEN_CLASS (klass);
-
- token_class->compile = vivi_code_asm_code_compile;
}
static void
diff --git a/vivified/code/vivi_code_assembler.c b/vivified/code/vivi_code_assembler.c
index d1fecd5..d7509f6 100644
--- a/vivified/code/vivi_code_assembler.c
+++ b/vivified/code/vivi_code_assembler.c
@@ -28,7 +28,6 @@
#include "vivi_code_comment.h"
#include "vivi_code_label.h"
#include "vivi_code_printer.h"
-#include "vivi_code_compiler.h"
G_DEFINE_TYPE (ViviCodeAssembler, vivi_code_assembler, VIVI_TYPE_CODE_STATEMENT)
@@ -70,18 +69,6 @@ vivi_code_assembler_print (ViviCodeToken *token, ViviCodePrinter *printer)
}
static void
-vivi_code_assembler_compile (ViviCodeToken *token, ViviCodeCompiler *compiler)
-{
- ViviCodeAssembler *assembler = VIVI_CODE_ASSEMBLER (token);
- guint i;
-
- for (i = 0; i < assembler->codes->len; i++) {
- vivi_code_compiler_compile_token (compiler,
- VIVI_CODE_TOKEN (g_ptr_array_index (assembler->codes, i)));
- }
-}
-
-static void
vivi_code_assembler_class_init (ViviCodeAssemblerClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
@@ -91,7 +78,6 @@ vivi_code_assembler_class_init (ViviCodeAssemblerClass *klass)
object_class->dispose = vivi_code_assembler_dispose;
token_class->print = vivi_code_assembler_print;
- token_class->compile = vivi_code_assembler_compile;
code_class->optimize = vivi_code_assembler_optimize;
}
diff --git a/vivified/code/vivi_code_assembler.h b/vivified/code/vivi_code_assembler.h
index 2fcd1f3..baaeb9b 100644
--- a/vivified/code/vivi_code_assembler.h
+++ b/vivified/code/vivi_code_assembler.h
@@ -26,7 +26,6 @@
G_BEGIN_DECLS
-typedef struct _ViviCodeAssembler ViviCodeAssembler;
typedef struct _ViviCodeAssemblerClass ViviCodeAssemblerClass;
#define VIVI_TYPE_CODE_ASSEMBLER (vivi_code_assembler_get_type())
diff --git a/vivified/code/vivi_code_compiler.c b/vivified/code/vivi_code_compiler.c
deleted file mode 100644
index e913e79..0000000
--- a/vivified/code/vivi_code_compiler.c
+++ /dev/null
@@ -1,247 +0,0 @@
-/* Vivified
- * Copyright (C) 2008 Pekka Lampila <pekka.lampila at iki.fi>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "vivi_code_compiler.h"
-
-G_DEFINE_TYPE (ViviCodeCompiler, vivi_code_compiler, G_TYPE_OBJECT)
-
-static void
-vivi_code_compiler_dispose (GObject *object)
-{
- ViviCodeCompiler *compiler = VIVI_CODE_COMPILER (object);
- GSList *iter;
-
- for (iter = compiler->actions; iter != NULL; iter = iter->next) {
- if (((ViviCodeCompilerAction *)iter->data)->data != NULL) {
- swfdec_buffer_unref (
- swfdec_bots_close (((ViviCodeCompilerAction *)iter->data)->data));
- }
- }
-
- g_slist_free (compiler->actions);
-
- G_OBJECT_CLASS (vivi_code_compiler_parent_class)->dispose (object);
-}
-
-static void
-vivi_code_compiler_class_init (ViviCodeCompilerClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->dispose = vivi_code_compiler_dispose;
-}
-
-static void
-vivi_code_compiler_init (ViviCodeCompiler *compiler)
-{
-}
-
-ViviCodeCompiler *
-vivi_code_compiler_new (void)
-{
- return g_object_new (VIVI_TYPE_CODE_COMPILER, NULL);
-}
-
-void
-vivi_code_compiler_compile_token (ViviCodeCompiler *compiler,
- ViviCodeToken *token)
-{
- ViviCodeTokenClass *klass;
- ViviCodeCompilerAction *action;
- GSList *current;
-
- g_return_if_fail (VIVI_IS_CODE_COMPILER (compiler));
- g_return_if_fail (VIVI_IS_CODE_TOKEN (token));
-
- current = compiler->current;
- action = compiler->action;
-
- klass = VIVI_CODE_TOKEN_GET_CLASS (token);
- g_return_if_fail (klass->compile);
- klass->compile (token, compiler);
-
- g_assert (compiler->current == current);
- g_assert (compiler->action == action);
-}
-
-void
-vivi_code_compiler_compile_value (ViviCodeCompiler *compiler,
- ViviCodeValue *value)
-{
- vivi_code_compiler_compile_token (compiler, VIVI_CODE_TOKEN (value));
-}
-
-static gsize
-vivi_code_compiler_action_get_size (ViviCodeCompilerAction *action)
-{
- g_return_val_if_fail (action != NULL, 0);
-
- if (action->id & 0x80) {
- return 3 +
- (action->data != NULL ? swfdec_bots_get_bytes (action->data) : 0);
- } else {
- g_assert (action->data == NULL ||
- swfdec_bots_get_bytes (action->data) == 0);
- return 1;
- }
-}
-
-static void
-vivi_code_compiler_action_write_data (ViviCodeCompilerAction *action,
- SwfdecBots *data)
-{
- g_return_if_fail (action != NULL);
- g_return_if_fail (data != NULL);
-
- swfdec_bots_put_u8 (data, action->id);
- if (action->id & 0x80) {
- if (action->data == NULL) {
- swfdec_bots_put_u16 (data, 0);
- } else {
- swfdec_bots_put_u16 (data, swfdec_bots_get_bytes (action->data));
- swfdec_bots_put_bots (data, action->data);
- }
- } else {
- g_assert (action->data == NULL ||
- swfdec_bots_get_bytes (action->data) == 0);
- }
-}
-
-SwfdecBuffer *
-vivi_code_compiler_get_data (ViviCodeCompiler *compiler)
-{
- SwfdecBots *data;
- GSList *iter;
-
- g_return_val_if_fail (VIVI_IS_CODE_COMPILER (compiler), NULL);
- g_return_val_if_fail (compiler->current == NULL, NULL);
-
- data = swfdec_bots_open ();
- compiler->actions = g_slist_reverse (compiler->actions);
- for (iter = compiler->actions; iter != NULL; iter = iter->next) {
- vivi_code_compiler_action_write_data (iter->data, data);
- }
- compiler->actions = g_slist_reverse (compiler->actions);
- return swfdec_bots_close (data);
-}
-
-gsize
-vivi_code_compiler_tail_size (ViviCodeCompiler *compiler)
-{
- GSList *iter;
- gsize size;
-
- g_return_val_if_fail (VIVI_IS_CODE_COMPILER (compiler), 0);
-
- size = 0;
- for (iter = compiler->actions; iter != compiler->current; iter = iter->next)
- {
- size += vivi_code_compiler_action_get_size (iter->data);
- }
- return size;
-}
-
-void
-vivi_code_compiler_begin_action (ViviCodeCompiler *compiler,
- SwfdecAsAction action)
-{
- g_return_if_fail (VIVI_IS_CODE_COMPILER (compiler));
-
- compiler->action = g_new0 (ViviCodeCompilerAction, 1);
- compiler->action->id = action;
- compiler->action->data = swfdec_bots_open ();
- compiler->action->parent = compiler->current;
-
- compiler->actions = g_slist_prepend (compiler->actions, compiler->action);
- compiler->current = compiler->actions;
-}
-
-void
-vivi_code_compiler_end_action (ViviCodeCompiler *compiler)
-{
- g_return_if_fail (VIVI_IS_CODE_COMPILER (compiler));
- g_return_if_fail (compiler->current != NULL);
-
- compiler->current = compiler->action->parent;
- if (compiler->current != NULL) {
- compiler->action = compiler->current->data;
- } else {
- compiler->action = NULL;
- }
-}
-
-void
-vivi_code_compiler_write_empty_action (ViviCodeCompiler *compiler,
- SwfdecAsAction id)
-{
- ViviCodeCompilerAction *action;
-
- action = g_new0 (ViviCodeCompilerAction, 1);
- action->id = id;
- action->data = NULL;
- action->parent = NULL;
-
- compiler->actions = g_slist_prepend (compiler->actions, action);
-}
-
-void vivi_code_compiler_write_u8 (ViviCodeCompiler *compiler, guint value)
-{
- g_return_if_fail (VIVI_IS_CODE_COMPILER (compiler));
- g_return_if_fail (compiler->action != NULL);
-
- swfdec_bots_put_u8 (compiler->action->data, value);
-}
-
-void vivi_code_compiler_write_u16 (ViviCodeCompiler *compiler, guint value)
-{
- g_return_if_fail (VIVI_IS_CODE_COMPILER (compiler));
- g_return_if_fail (compiler->action != NULL);
-
- swfdec_bots_put_u16 (compiler->action->data, value);
-}
-
-void vivi_code_compiler_write_s16 (ViviCodeCompiler *compiler, guint value)
-{
- g_return_if_fail (VIVI_IS_CODE_COMPILER (compiler));
- g_return_if_fail (compiler->action != NULL);
-
- swfdec_bots_put_s16 (compiler->action->data, value);
-}
-
-void
-vivi_code_compiler_write_double (ViviCodeCompiler *compiler, double value)
-{
- g_return_if_fail (VIVI_IS_CODE_COMPILER (compiler));
- g_return_if_fail (compiler->action != NULL);
-
- swfdec_bots_put_double (compiler->action->data, value);
-}
-
-void
-vivi_code_compiler_write_string (ViviCodeCompiler *compiler, const char *value)
-{
- g_return_if_fail (VIVI_IS_CODE_COMPILER (compiler));
- g_return_if_fail (compiler->action != NULL);
-
- swfdec_bots_put_string (compiler->action->data, value);
-}
diff --git a/vivified/code/vivi_code_compiler.h b/vivified/code/vivi_code_compiler.h
deleted file mode 100644
index afaddad..0000000
--- a/vivified/code/vivi_code_compiler.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/* Vivified
- * Copyright (C) 2008 Benjamin Otte <otte at gnome.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA
- */
-
-#ifndef _VIVI_CODE_COMPILER_H_
-#define _VIVI_CODE_COMPILER_H_
-
-#include <swfdec/swfdec.h>
-#include <swfdec/swfdec_as_interpret.h>
-#include <swfdec/swfdec_bots.h>
-
-#include <vivified/code/vivi_code_token.h>
-#include <vivified/code/vivi_code_value.h>
-
-G_BEGIN_DECLS
-
-
-typedef struct _ViviCodeCompilerClass ViviCodeCompilerClass;
-
-#define VIVI_TYPE_CODE_COMPILER (vivi_code_compiler_get_type())
-#define VIVI_IS_CODE_COMPILER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VIVI_TYPE_CODE_COMPILER))
-#define VIVI_IS_CODE_COMPILER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VIVI_TYPE_CODE_COMPILER))
-#define VIVI_CODE_COMPILER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VIVI_TYPE_CODE_COMPILER, ViviCodeCompiler))
-#define VIVI_CODE_COMPILER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VIVI_TYPE_CODE_COMPILER, ViviCodeCompilerClass))
-#define VIVI_CODE_COMPILER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VIVI_TYPE_CODE_COMPILER, ViviCodeCompilerClass))
-
-typedef struct {
- SwfdecAsAction id;
- SwfdecBots * data;
- GSList * parent;
-} ViviCodeCompilerAction;
-
-struct _ViviCodeCompiler
-{
- GObject object;
-
- GSList * actions;
- GSList * current;
- ViviCodeCompilerAction * action;
-};
-
-struct _ViviCodeCompilerClass
-{
- GObjectClass object_class;
-};
-
-GType vivi_code_compiler_get_type (void);
-
-ViviCodeCompiler *vivi_code_compiler_new (void);
-
-SwfdecBuffer * vivi_code_compiler_get_data (ViviCodeCompiler * compiler);
-
-void vivi_code_compiler_compile_token (ViviCodeCompiler * compiler,
- ViviCodeToken * token);
-void vivi_code_compiler_compile_value (ViviCodeCompiler * compiler,
- ViviCodeValue * value);
-
-gsize vivi_code_compiler_tail_size (ViviCodeCompiler * compiler);
-
-void vivi_code_compiler_begin_action (ViviCodeCompiler * compiler,
- SwfdecAsAction action);
-void vivi_code_compiler_end_action (ViviCodeCompiler * compiler);
-void vivi_code_compiler_write_empty_action (ViviCodeCompiler * compiler,
- SwfdecAsAction action);
-
-void vivi_code_compiler_write_u8 (ViviCodeCompiler * compiler, guint value);
-void vivi_code_compiler_write_u16 (ViviCodeCompiler * compiler, guint value);
-void vivi_code_compiler_write_s16 (ViviCodeCompiler * compiler, guint value);
-void vivi_code_compiler_write_double (ViviCodeCompiler * compiler, double value);
-void vivi_code_compiler_write_string (ViviCodeCompiler * compiler, const char *value);
-
-
-G_END_DECLS
-#endif
diff --git a/vivified/code/vivi_code_statement.c b/vivified/code/vivi_code_statement.c
index e8700ad..7c20622 100644
--- a/vivified/code/vivi_code_statement.c
+++ b/vivified/code/vivi_code_statement.c
@@ -77,3 +77,10 @@ vivi_code_statement_needs_braces (ViviCodeStatement *stmt)
}
}
+void vivi_code_statement_compile (ViviCodeStatement *statement,
+ ViviCodeAssembler *assembler)
+{
+ g_return_if_fail (VIVI_IS_CODE_STATEMENT (statement));
+
+ vivi_code_token_compile (VIVI_CODE_TOKEN (statement), assembler);
+}
diff --git a/vivified/code/vivi_code_statement.h b/vivified/code/vivi_code_statement.h
index 60326a8..84d0f93 100644
--- a/vivified/code/vivi_code_statement.h
+++ b/vivified/code/vivi_code_statement.h
@@ -50,6 +50,8 @@ struct _ViviCodeStatementClass
GType vivi_code_statement_get_type (void);
+void vivi_code_statement_compile (ViviCodeStatement * statement,
+ ViviCodeAssembler * assembler);
ViviCodeStatement * vivi_code_statement_optimize (ViviCodeStatement * stmt);
gboolean vivi_code_statement_needs_braces(ViviCodeStatement * stmt);
diff --git a/vivified/code/vivi_code_token.c b/vivified/code/vivi_code_token.c
index e722aa8..cafa850 100644
--- a/vivified/code/vivi_code_token.c
+++ b/vivified/code/vivi_code_token.c
@@ -46,3 +46,16 @@ vivi_code_token_init (ViviCodeToken *token)
{
}
+
+void
+vivi_code_token_compile (ViviCodeToken *token, ViviCodeAssembler *assembler)
+{
+ ViviCodeTokenClass *klass;
+
+ g_return_if_fail (VIVI_IS_CODE_TOKEN (token));
+ g_return_if_fail (VIVI_IS_CODE_ASSEMBLER (assembler));
+
+ klass = VIVI_CODE_TOKEN_GET_CLASS (token);
+ g_return_if_fail (klass->compile);
+ klass->compile (token, assembler);
+}
diff --git a/vivified/code/vivi_code_token.h b/vivified/code/vivi_code_token.h
index f23054a..2ef0d61 100644
--- a/vivified/code/vivi_code_token.h
+++ b/vivified/code/vivi_code_token.h
@@ -26,7 +26,7 @@ G_BEGIN_DECLS
typedef struct _ViviCodePrinter ViviCodePrinter;
-typedef struct _ViviCodeCompiler ViviCodeCompiler;
+typedef struct _ViviCodeAssembler ViviCodeAssembler;
typedef struct _ViviCodeToken ViviCodeToken;
typedef struct _ViviCodeTokenClass ViviCodeTokenClass;
@@ -50,11 +50,14 @@ struct _ViviCodeTokenClass
void (* print) (ViviCodeToken * token,
ViviCodePrinter * printer);
void (* compile) (ViviCodeToken * token,
- ViviCodeCompiler * compiler);
+ ViviCodeAssembler * assembler);
};
GType vivi_code_token_get_type (void);
+void vivi_code_token_compile (ViviCodeToken * token,
+ ViviCodeAssembler * assembler);
+
G_END_DECLS
#endif
diff --git a/vivified/code/vivi_code_value.c b/vivified/code/vivi_code_value.c
index 722eb66..9fb8ce9 100644
--- a/vivified/code/vivi_code_value.c
+++ b/vivified/code/vivi_code_value.c
@@ -101,3 +101,10 @@ vivi_code_value_is_equal (ViviCodeValue *a, ViviCodeValue *b)
return a == b;
}
+void vivi_code_value_compile (ViviCodeValue *value,
+ ViviCodeAssembler *assembler)
+{
+ g_return_if_fail (VIVI_IS_CODE_VALUE (value));
+
+ vivi_code_token_compile (VIVI_CODE_TOKEN (value), assembler);
+}
diff --git a/vivified/code/vivi_code_value.h b/vivified/code/vivi_code_value.h
index ae66a9c..dc7e2cd 100644
--- a/vivified/code/vivi_code_value.h
+++ b/vivified/code/vivi_code_value.h
@@ -88,6 +88,8 @@ ViviPrecedence vivi_code_value_get_precedence (ViviCodeValue * value);
ViviCodeValue * vivi_code_value_optimize (ViviCodeValue * value,
SwfdecAsValueType hint);
+void vivi_code_value_compile (ViviCodeValue * value,
+ ViviCodeAssembler * assembler);
G_END_DECLS
#endif
More information about the Swfdec-commits
mailing list