xo-interpreter: handle litersl strings. Broken memory model.
This commit is contained in:
parent
6e9349f70c
commit
cf846b2f8d
16 changed files with 234 additions and 32 deletions
|
|
@ -173,7 +173,7 @@ namespace xo {
|
|||
*/
|
||||
progress_xs::start(var.promote(), p_psm);
|
||||
|
||||
#ifdef NOT_YET
|
||||
#ifdef NOT_YET
|
||||
p_stack->push_exprstate(exprstate(exprstatetype::expr_progress,
|
||||
Variable::make(name, type)));
|
||||
#endif
|
||||
|
|
@ -227,6 +227,21 @@ namespace xo {
|
|||
p_psm);
|
||||
}
|
||||
|
||||
void
|
||||
expect_expr_xs::on_string_token(const token_type & tk,
|
||||
parserstatemachine * p_psm)
|
||||
{
|
||||
scope log(XO_DEBUG(p_psm->debug_flag()));
|
||||
|
||||
/* e.g.
|
||||
* def msg = "hello, world";
|
||||
* \----tk----/
|
||||
*/
|
||||
progress_xs::start
|
||||
(Constant<std::string>::make(tk.text()),
|
||||
p_psm);
|
||||
}
|
||||
|
||||
void
|
||||
expect_expr_xs::on_expr(bp<Expression> expr,
|
||||
parserstatemachine * p_psm)
|
||||
|
|
|
|||
|
|
@ -45,6 +45,8 @@ namespace xo {
|
|||
|
||||
if (tk.text() == "bool")
|
||||
td = Reflect::require<bool>();
|
||||
else if (tk.text() == "str")
|
||||
td = Reflect::require<std::string>();
|
||||
else if (tk.text() == "f64")
|
||||
td = Reflect::require<double>();
|
||||
else if(tk.text() == "f32")
|
||||
|
|
|
|||
|
|
@ -181,7 +181,7 @@ namespace xo {
|
|||
|
||||
scope log(XO_DEBUG(p_psm->debug_flag()));
|
||||
|
||||
constexpr const char * c_self_name = "exprseq_xs::on_i64_token";
|
||||
constexpr const char * c_self_name = "exprseq_xs::on_f64_token";
|
||||
|
||||
if (xseqtype_ == exprseqtype::toplevel_interactive)
|
||||
{
|
||||
|
|
@ -199,6 +199,44 @@ namespace xo {
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
exprseq_xs::on_string_token(const token_type & tk,
|
||||
parserstatemachine * p_psm)
|
||||
{
|
||||
using xo::scm::Constant;
|
||||
|
||||
scope log(XO_DEBUG(p_psm->debug_flag()));
|
||||
|
||||
constexpr const char * c_self_name = "exprseq_xs::on_string_token";
|
||||
|
||||
if (xseqtype_ == exprseqtype::toplevel_interactive)
|
||||
{
|
||||
// remark:
|
||||
// 1. Constant is an expression. At present (nov 2025) these are
|
||||
// reference-counted (+ leak in xo-interpreter).
|
||||
// 2. Could fix leak by adding a finalization feature to GC.
|
||||
// Do intend to eventually support finalization,
|
||||
// but not to use it here.
|
||||
// 3. Instead mean to change allocation strategy for Expression
|
||||
// to use GC instead.
|
||||
// 4. As intermediate step try migrating Expression hierarchy
|
||||
// to support arena allocation.
|
||||
// See xo/alloc/ArenaAllocT.hpp + assoc'd unit test
|
||||
//
|
||||
progress_xs::start(Constant<std::string>::make(tk.text()), p_psm);
|
||||
} else {
|
||||
/* policy: don't allow literals as toplevel expressions
|
||||
* unless interactive session.
|
||||
*/
|
||||
const char * exp = get_expect_str();
|
||||
|
||||
this->illegal_input_on_token(c_self_name,
|
||||
tk,
|
||||
exp,
|
||||
p_psm);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
exprseq_xs::on_typedescr(TypeDescr /*td*/,
|
||||
parserstatemachine * /*p_psm*/)
|
||||
|
|
|
|||
|
|
@ -336,7 +336,7 @@ namespace xo {
|
|||
{
|
||||
scope log(XO_DEBUG(p_psm->debug_flag()));
|
||||
|
||||
constexpr const char * c_self_name = "exprstate::on_bool";
|
||||
constexpr const char * c_self_name = "exprstate::on_bool_token";
|
||||
const char * exp = get_expect_str();
|
||||
|
||||
this->illegal_input_on_token(c_self_name, tk, exp, p_psm);
|
||||
|
|
@ -348,7 +348,7 @@ namespace xo {
|
|||
{
|
||||
scope log(XO_DEBUG(p_psm->debug_flag()));
|
||||
|
||||
constexpr const char * c_self_name = "exprstate::on_i64";
|
||||
constexpr const char * c_self_name = "exprstate::on_i64_token";
|
||||
const char * exp = get_expect_str();
|
||||
|
||||
this->illegal_input_on_token(c_self_name, tk, exp, p_psm);
|
||||
|
|
@ -360,7 +360,19 @@ namespace xo {
|
|||
{
|
||||
scope log(XO_DEBUG(p_psm->debug_flag()));
|
||||
|
||||
constexpr const char * c_self_name = "exprstate::on_f64";
|
||||
constexpr const char * c_self_name = "exprstate::on_f64_token";
|
||||
const char * exp = get_expect_str();
|
||||
|
||||
this->illegal_input_on_token(c_self_name, tk, exp, p_psm);
|
||||
}
|
||||
|
||||
void
|
||||
exprstate::on_string_token(const token_type & tk,
|
||||
parserstatemachine * p_psm)
|
||||
{
|
||||
scope log(XO_DEBUG(p_psm->debug_flag()));
|
||||
|
||||
constexpr const char * c_self_name = "exprstate::on_string_token";
|
||||
const char * exp = get_expect_str();
|
||||
|
||||
this->illegal_input_on_token(c_self_name, tk, exp, p_psm);
|
||||
|
|
@ -399,7 +411,7 @@ namespace xo {
|
|||
return;
|
||||
|
||||
case tokentype::tk_string:
|
||||
assert(false);
|
||||
this->on_string_token(tk, p_psm);
|
||||
return;
|
||||
|
||||
case tokentype::tk_symbol:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue