80 lines
1.6 KiB
C
80 lines
1.6 KiB
C
|
|
#include <stddef.h>
|
|
|
|
#include <debug.h>
|
|
|
|
#include <stringtree/new.h>
|
|
#include <stringtree/println.h>
|
|
#include <stringtree/free.h>
|
|
|
|
#include <environment/new.h>
|
|
#include <environment/declare.h>
|
|
#include <environment/free.h>
|
|
|
|
#include <value/prettyprint.h>
|
|
#include <value/lazy/unlazy.h>
|
|
#include <value/free.h>
|
|
|
|
#include <expression/evaluate.h>
|
|
|
|
#include "struct.h"
|
|
#include "execute.h"
|
|
|
|
void assignment_statement_execute(
|
|
struct statement* super,
|
|
struct environment** environment,
|
|
struct booleans* booleans,
|
|
struct color_factory* cfactory,
|
|
struct wcostream* ostream,
|
|
bool print_value,
|
|
bool print_with_color)
|
|
{
|
|
ENTER;
|
|
|
|
struct assignment_statement* this = (void*) super;
|
|
|
|
struct value* value = expression_evaluate(
|
|
/* assignment: */ this->expression,
|
|
/* environment: */ *environment,
|
|
/* booleans: */ booleans);
|
|
|
|
struct value* vvalue = lazy_value_unlazy(value, booleans);
|
|
|
|
struct environment* new = new_environment(*environment);
|
|
|
|
environment_declare(new, this->variable_name, vvalue);
|
|
|
|
free_environment(*environment);
|
|
|
|
*environment = new;
|
|
|
|
if (print_value)
|
|
{
|
|
struct stringtree* tree = value_prettyprint(
|
|
/* outgoing chosen color: */ NULL,
|
|
/* value: */ vvalue,
|
|
/* color factory: */ cfactory,
|
|
/* print with color? */ print_with_color);
|
|
|
|
stringtree_println(tree, ostream);
|
|
|
|
free_stringtree(tree);
|
|
}
|
|
|
|
free_value(vvalue);
|
|
|
|
free_value(value);
|
|
|
|
EXIT;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|