<script>
-var str = "hello world";
-var p = /L/gi;
-document.write(str.match(p));
+var s0 = "123";
+var s1 = "124";
+
+document.write(s0 == s1);
+document.write("<br>");
+
+if (s0 == s1)
+ document.write(true);
+else
+ document.write(false);
</script>
CFILES += ../js/core/scf_type_cast_u64.c
CFILES += ../js/core/scf_type_cast_float.c
CFILES += ../js/core/scf_type_cast_double.c
+CFILES += ../js/core/scf_type_cast_bool.c
CFILES += ../js/core/scf_operator_handler_3ac.c
SCF_VAR_U8,
SCF_VAR_VOID,
SCF_VAR_VAR,
- SCF_VAR_BIT,
+ SCF_VAR_BOOL,
SCF_VAR_U2,
SCF_VAR_U3,
SCF_VAR_U4,
SCF_LEX_WORD_KEY_INT64, // int64_t
SCF_LEX_WORD_KEY_UINT8, // uint8_t
- SCF_LEX_WORD_KEY_BIT, // bit
- SCF_LEX_WORD_KEY_BIT2, // bit2_t
- SCF_LEX_WORD_KEY_BIT3, // bit3_t
- SCF_LEX_WORD_KEY_BIT4, // bit4_t
+ SCF_LEX_WORD_KEY_BOOL, // bool
SCF_LEX_WORD_KEY_UINT16, // uint16_t
SCF_LEX_WORD_KEY_UINT32, // uint32_t
SCF_LEX_WORD_KEY_UINT64, // uint64_t
// const literal value
SCF_LEX_WORD_CONST_CHAR,
+ SCF_LEX_WORD_CONST_BOOL,
SCF_LEX_WORD_CONST_INT,
SCF_LEX_WORD_CONST_U32,
if (!f->node.define_flag)
continue;
- if (strcmp(f->node.w->text->data, "__toString"))
+ if (strcmp(f->node.w->text->data, "__js_main"))
continue;
printf("\n");
static int type_update[] =
{
+ SCF_VAR_BOOL,
SCF_VAR_I8,
SCF_VAR_CHAR,
- SCF_VAR_BIT,
SCF_VAR_U8,
SCF_VAR_I16,
static scf_type_cast_t base_type_casts[] =
{
{"char", -1, SCF_VAR_CHAR, scf_cast_to_u8},
- {"bit", -1, SCF_VAR_BIT, scf_cast_to_u8},
+ {"bool", -1, SCF_VAR_BOOL, scf_cast_to_bool},
{"u8", -1, SCF_VAR_U8, scf_cast_to_u8},
{"u16", -1, SCF_VAR_U16, scf_cast_to_u16},
{"u32", -1, SCF_VAR_U32, scf_cast_to_u32},
int scf_cast_to_u32(scf_ast_t* ast, scf_variable_t** pret, scf_variable_t* src);
int scf_cast_to_u64(scf_ast_t* ast, scf_variable_t** pret, scf_variable_t* src);
+int scf_cast_to_bool(scf_ast_t* ast, scf_variable_t** pret, scf_variable_t* src);
+
int scf_cast_to_float(scf_ast_t* ast, scf_variable_t** pret, scf_variable_t* src);
int scf_cast_to_double(scf_ast_t* ast, scf_variable_t** pret, scf_variable_t* src);
--- /dev/null
+#include"scf_type_cast.h"
+
+int scf_cast_to_bool(scf_ast_t* ast, scf_variable_t** pret, scf_variable_t* src)
+{
+ if (!pret || !src)
+ return -EINVAL;
+
+ scf_type_t* t = scf_block_find_type_type(ast->current_block, SCF_VAR_BOOL);
+
+ scf_variable_t* r = SCF_VAR_ALLOC_BY_TYPE(src->w, t, src->const_flag, 0, NULL);
+
+ switch (src->type) {
+ case SCF_VAR_FLOAT:
+ r->data.u32 = !!(uint32_t)src->data.f;
+ break;
+
+ case SCF_VAR_DOUBLE:
+ r->data.u32 = !!(uint32_t)src->data.d;
+ break;
+
+ case SCF_VAR_CHAR:
+ case SCF_VAR_I8:
+ case SCF_VAR_U8:
+ case SCF_VAR_I16:
+ case SCF_VAR_U16:
+ case SCF_VAR_I32:
+ case SCF_VAR_U32:
+ case SCF_VAR_I64:
+ case SCF_VAR_U64:
+ r->data.u32 = !!src->data.u32;
+ break;
+
+ default:
+ if (src->nb_pointers > 0)
+ r->data.u32 = !!src->data.u32;
+ else {
+ scf_variable_free(r);
+ return -EINVAL;
+ }
+ break;
+ };
+
+ *pret = r;
+ return 0;
+}
return 0;
}
+ int __init(Object* this, bool b)
+ {
+ this->i64 = b;
+ this->type = JS_Boolean;
+ printf("this: %p, this->i64: %ld, b: %d\n\n", this, this->i64, b);
+ return 0;
+ }
+
int __init(Object* this, const char* s)
{
int len = strlen(s);
return res;
}
+ Object* Boolean(Object* this, bool b)
+ {
+ Object* res = new Object();
+ if (!res)
+ return NULL;
+
+ res->i64 = b;
+ res->type = JS_Boolean;
+ return res;
+ }
+
Object* Boolean(Object* this, Object* that)
{
Object* res = new Object();
abc_html_write(this, s);
}
+ void write(Object* this, bool b)
+ {
+ if (b)
+ abc_html_write(this, "true");
+ else
+ abc_html_write(this, "false");
+ }
+
void write(Object* this, int64_t i)
{
abc_html_write_i(this, i);
Object* operator+(Object* this, Object* that)
{
- Object* res = new Object(this->d + that->d);
+ Object* res = new Object();
+ if (res) {
+ if (JS_Number == this->type && JS_Number == that->type) {
+ res->d = this->d + that->d;
+ res->type = JS_Number;
+ } else {
+ int len0 = this->__toStringLen();
+ int len1 = that->__toStringLen();
+
+ res->str = scf__auto_malloc(len0 + len1 + 1);
+ if (res->str) {
+ int n0 = this->__toString(res->str);
+
+ that->__toString(res->str + n0);
+ res->type = JS_String;
+ }
+ }
+ }
+ return res;
+ }
+
+ Object* operator-(Object* this, Object* that)
+ {
+ if (JS_Number != this->type || JS_Number != that->type)
+ return NULL;
+
+ Object* res = new Object(this->d - that->d);
return res;
}
+ bool operator==(Object* this, Object* that)
+ {
+ if (JS_Number == this->type && JS_Number == that->type)
+ return this->d == that->d;
+
+ if (JS_Boolean == this->type && JS_Boolean == that->type)
+ return this->i64 == that->i64;
+
+ if (JS_String == this->type && JS_String == that->type)
+ return !strcmp(this->str, that->str);
+
+ return 0;
+ }
+
void __release(Object* this)
{
if (this->members) {
{"int", SCF_LEX_WORD_KEY_INT},
{"float", SCF_LEX_WORD_KEY_FLOAT},
{"double", SCF_LEX_WORD_KEY_DOUBLE},
- {"bit", SCF_LEX_WORD_KEY_BIT},
- {"bit2_t", SCF_LEX_WORD_KEY_BIT2},
- {"bit3_t", SCF_LEX_WORD_KEY_BIT3},
- {"bit4_t", SCF_LEX_WORD_KEY_BIT4},
+ {"bool", SCF_LEX_WORD_KEY_BOOL},
{"int8_t", SCF_LEX_WORD_KEY_INT8},
{"int1_t", SCF_LEX_WORD_KEY_INT1},
if (w)
w->data.u64 = 0;
+ } else if (!strcmp(s->data, "true")) {
+
+ w = scf_lex_word_alloc(lex->file, lex->nb_lines, lex->pos, SCF_LEX_WORD_CONST_BOOL);
+ if (w)
+ w->data.u64 = 1;
+
+ } else if (!strcmp(s->data, "false")) {
+
+ w = scf_lex_word_alloc(lex->file, lex->nb_lines, lex->pos, SCF_LEX_WORD_CONST_BOOL);
+ if (w)
+ w->data.u64 = 0;
+
} else if (!strcmp(s->data, "__LINE__")) {
w = scf_lex_word_alloc(lex->file, lex->nb_lines, lex->pos, SCF_LEX_WORD_CONST_U64);
type = SCF_VAR_U64;
break;
+ case SCF_LEX_WORD_CONST_BOOL:
+ type = SCF_VAR_BOOL;
+ break;
default:
scf_loge("unknown number type\n");
return SCF_DFA_ERROR;
{SCF_VAR_VOID, "void", 1},
{SCF_VAR_VAR, "var", 1},
+ {SCF_VAR_BOOL, "bool", 1},
{SCF_VAR_INT, "int", 4},
{SCF_VAR_FLOAT, "float", 4},
for (j = 0; j < file->nb_nodes; ) {
e = file->nodes[j];
- if (SCF_OP_EXPR != e->type) {
- j++;
- continue;
- }
+ switch (e->type) {
+ case SCF_OP_EXPR:
+ case SCF_OP_IF:
+ ret = scf_node_add_child((scf_node_t*)f, e);
+ if (ret < 0)
+ return ret;
- ret = scf_node_add_child((scf_node_t*)f, e);
- if (ret < 0)
- return ret;
- scf_node_del_child(file, e);
+ scf_node_del_child(file, e);
+ break;
+ default:
+ j++;
+ break;
+ };
}
}
CFILES += ../js/core/scf_type_cast_u64.c
CFILES += ../js/core/scf_type_cast_float.c
CFILES += ../js/core/scf_type_cast_double.c
+CFILES += ../js/core/scf_type_cast_bool.c
CFILES += ../js/core/scf_operator_handler_3ac.c