From: Jean Privat Date: Wed, 10 Feb 2010 15:45:31 +0000 (-0500) Subject: icode: add I*Value classes X-Git-Tag: v0.4~36 X-Git-Url: http://nitlanguage.org?ds=sidebyside icode: add I*Value classes Signed-off-by: Jean Privat --- diff --git a/src/analysis/icode_dump.nit b/src/analysis/icode_dump.nit index 7c60d59..4a618d3 100644 --- a/src/analysis/icode_dump.nit +++ b/src/analysis/icode_dump.nit @@ -379,6 +379,41 @@ redef class INative end end +redef class IIntValue + redef fun dump_intern(icd) + do + return "INTVALUE {value}" + end +end + +redef class IBoolValue + redef fun dump_intern(icd) + do + return "BOOLVALUE {value}" + end +end + +redef class IStringValue + redef fun dump_intern(icd) + do + return "STRINGVALUE {value}" + end +end + +redef class ICharValue + redef fun dump_intern(icd) + do + return "CHARVALUE {value}" + end +end + +redef class IFloatValue + redef fun dump_intern(icd) + do + return "FLOATVALUE {value}" + end +end + redef class IMove redef fun dump_intern(icd) do diff --git a/src/analysis/remove_out_of_init_get_test.nit b/src/analysis/remove_out_of_init_get_test.nit index 31df643..2dc1c8c 100644 --- a/src/analysis/remove_out_of_init_get_test.nit +++ b/src/analysis/remove_out_of_init_get_test.nit @@ -78,8 +78,7 @@ special ICodeVisitor if ic isa IAttrIsset then var result = ic.result assert result != null - var e = new INative("TAG_Bool(true)", null) - e.is_pure = true + var e = new IBoolValue(true) e.result = result current_icode.insert_before(e) current_icode.delete diff --git a/src/compiling/compiling_icode.nit b/src/compiling/compiling_icode.nit index 17a70d2..264bd5e 100644 --- a/src/compiling/compiling_icode.nit +++ b/src/compiling/compiling_icode.nit @@ -696,6 +696,53 @@ redef class INative end end +redef class IIntValue + redef fun compile_to_c(v) + do + v.add_location(location) + var w = new_result(v) + w.add("TAG_Int(").add(value.to_s).add(")") + end +end + +redef class IBoolValue + redef fun compile_to_c(v) + do + v.add_location(location) + var w = new_result(v) + w.add("TAG_Bool(") + if value then w.add("true") else w.add("false") + w.add(")") + end +end + +redef class ICharValue + redef fun compile_to_c(v) + do + v.add_location(location) + var w = new_result(v) + w.add("TAG_Char(").add(value).add(")") + end +end + +redef class IFloatValue + redef fun compile_to_c(v) + do + v.add_location(location) + var w = new_result(v) + w.add("BOX_Float(").add(value).add(")") + end +end + +redef class IStringValue + redef fun compile_to_c(v) + do + v.add_location(location) + var w = new_result(v) + w.add("BOX_NativeString(\"").add(value).add("\")") + end +end + redef class IAbort redef fun compile_to_c(v) do diff --git a/src/icode/icode_base.nit b/src/icode/icode_base.nit index b3da5a9..3db7132 100644 --- a/src/icode/icode_base.nit +++ b/src/icode/icode_base.nit @@ -340,6 +340,61 @@ special ICodeN redef readable writable var _is_pure: Bool = false end +# A literal Int value +class IIntValue +special ICode0 + # The value + readable var _value: String + + init(v: String) do _value = v + + redef fun is_pure do return true +end + +# A literal Bool value +class IBoolValue +special ICode0 + # The value + readable var _value: Bool + + init(v: Bool) do _value = v + + redef fun is_pure do return true +end + +# A literal NativeString value +class IStringValue +special ICode0 + # The value + readable var _value: String + + init(v: String) do _value = v + + redef fun is_pure do return true +end + +# A literal Float value +class IFloatValue +special ICode0 + # The value + readable var _value: String + + init(v: String) do _value = v + + redef fun is_pure do return true +end + +# A literal Char value +class ICharValue +special ICode0 + # The value + readable var _value: String + + init(v: String) do _value = v + + redef fun is_pure do return true +end + # A register assigment # expr is the assigned value # result is the register assigned diff --git a/src/icode/icode_builder.nit b/src/icode/icode_builder.nit index 118d325..d6691d3 100644 --- a/src/icode/icode_builder.nit +++ b/src/icode/icode_builder.nit @@ -181,16 +181,14 @@ class ICodeBuilder # Return a literal "true" value fun lit_true_reg: IRegister do - var e = new INative("TAG_Bool(true)", null) - e.is_pure = true + var e = new IBoolValue(true) return expr(e, module.type_bool) end # Return a literal "false" value fun lit_false_reg: IRegister do - var e = new INative("TAG_Bool(false)", null) - e.is_pure = true + var e = new IBoolValue(false) return expr(e, module.type_bool) end diff --git a/src/icode/icode_tools.nit b/src/icode/icode_tools.nit index 1201f00..2ee7b8b 100644 --- a/src/icode/icode_tools.nit +++ b/src/icode/icode_tools.nit @@ -390,6 +390,41 @@ redef class INative end end +redef class IIntValue + redef fun inner_dup_with(d) + do + return new IIntValue(value) + end +end + +redef class IBoolValue + redef fun inner_dup_with(d) + do + return new IBoolValue(value) + end +end + +redef class IStringValue + redef fun inner_dup_with(d) + do + return new IStringValue(value) + end +end + +redef class IFloatValue + redef fun inner_dup_with(d) + do + return new IFloatValue(value) + end +end + +redef class ICharValue + redef fun inner_dup_with(d) + do + return new ICharValue(value) + end +end + redef class IMove redef fun inner_dup_with(d) do diff --git a/src/syntax/icode_generation.nit b/src/syntax/icode_generation.nit index d021373..0d60974 100644 --- a/src/syntax/icode_generation.nit +++ b/src/syntax/icode_generation.nit @@ -39,7 +39,7 @@ special ICodeBuilder fun add_new_array(stype: MMType, length: Int): IRegister do var prop = visitor.get_method(stype, once "with_capacity".to_symbol) - var ni = expr(new INative("TAG_Int({length})", null), visitor.type_int) + var ni = expr(new IIntValue(length.to_s), visitor.type_int) return expr(new INew(stype, prop, [ni]), stype) end @@ -1008,21 +1008,21 @@ end redef class AIntExpr redef fun generate_icode(v) do - return v.expr(new INative("TAG_Int({n_number.text})", null), stype) + return v.expr(new IIntValue(n_number.text), stype) end end redef class AFloatExpr redef fun generate_icode(v) do - return v.expr(new INative("BOX_Float({n_float.text})", null), stype) + return v.expr(new IFloatValue(n_float.text), stype) end end redef class ACharExpr redef fun generate_icode(v) do - return v.expr(new INative("TAG_Char({n_char.text})", null), stype) + return v.expr(new ICharValue(n_char.text), stype) end end @@ -1034,8 +1034,8 @@ redef class AStringFormExpr var ionce = new IOnce var reg = v.expr(ionce, stype) v.seq = ionce.body - var ns = v.expr(new INative("BOX_NativeString(\"{_cstring.as(not null)}\")", null), v.visitor.type_nativestring) - var ni = v.expr(new INative("TAG_Int({_cstring_length.as(not null)})", null), v.visitor.type_int) + var ns = v.expr(new IStringValue(_cstring.as(not null)), v.visitor.type_nativestring) + var ni = v.expr(new IIntValue(_cstring_length.to_s), v.visitor.type_int) var prop = v.visitor.get_method(stype, once "with_native".to_symbol) var e = v.expr(new INew(stype, prop, [ns, ni]), stype) v.add_assignment(reg, e)