nitlanguage
/
nit.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
9c53a2c
)
compiler: introduce and use char_instance, float_instance and null_instance
author
Jean Privat
<jean@pryen.org>
Sat, 21 Mar 2015 05:21:03 +0000
(12:21 +0700)
committer
Jean Privat
<jean@pryen.org>
Sat, 21 Mar 2015 14:27:48 +0000
(21:27 +0700)
Signed-off-by: Jean Privat <jean@pryen.org>
src/compiler/abstract_compiler.nit
patch
|
blob
|
history
diff --git
a/src/compiler/abstract_compiler.nit
b/src/compiler/abstract_compiler.nit
index
40ac105
..
4dc34c8
100644
(file)
--- a/
src/compiler/abstract_compiler.nit
+++ b/
src/compiler/abstract_compiler.nit
@@
-1426,6
+1426,24
@@
abstract class AbstractCompilerVisitor
return res
end
return res
end
+ # Generate a char value
+ fun char_instance(value: Char): RuntimeVariable
+ do
+ var t = mmodule.char_type
+ var res = new RuntimeVariable("'{value.to_s.escape_to_c}'", t, t)
+ return res
+ end
+
+ # Generate a float value
+ #
+ # FIXME pass a Float, not a string
+ fun float_instance(value: String): RuntimeVariable
+ do
+ var t = mmodule.float_type
+ var res = new RuntimeVariable("{value}", t, t)
+ return res
+ end
+
# Generate an integer value
fun bool_instance(value: Bool): RuntimeVariable
do
# Generate an integer value
fun bool_instance(value: Bool): RuntimeVariable
do
@@
-1434,6
+1452,14
@@
abstract class AbstractCompilerVisitor
return res
end
return res
end
+ # Generate the `null` value
+ fun null_instance: RuntimeVariable
+ do
+ var t = compiler.mainmodule.model.null_type
+ var res = new RuntimeVariable("((val*)NULL)", t, t)
+ return res
+ end
+
# Generate a string value
fun string_instance(string: String): RuntimeVariable
do
# Generate a string value
fun string_instance(string: String): RuntimeVariable
do
@@
-2696,11
+2722,11
@@
redef class AIntExpr
end
redef class AFloatExpr
end
redef class AFloatExpr
- redef fun expr(v) do return v.new_expr("{self.n_float.text}", self.mtype.as(not null)) # FIXME use value, not n_float
+ redef fun expr(v) do return v.float_instance("{self.n_float.text}") # FIXME use value, not n_float
end
redef class ACharExpr
end
redef class ACharExpr
- redef fun expr(v) do return v.new_expr("'{self.value.to_s.escape_to_c}'", self.mtype.as(not null))
+ redef fun expr(v) do return v.char_instance(self.value.as(not null))
end
redef class AArrayExpr
end
redef class AArrayExpr
@@
-2773,7
+2799,7
@@
redef class AFalseExpr
end
redef class ANullExpr
end
redef class ANullExpr
- redef fun expr(v) do return v.new_expr("NULL", self.mtype.as(not null))
+ redef fun expr(v) do return v.null_instance
end
redef class AIsaExpr
end
redef class AIsaExpr