Example #1
0
// Reads the state of the stack piece lid into the given frame; doesn't modify
// the piece in any way though.
static void read_stack_piece_lid(value_t piece, frame_t *frame) {
  CHECK_TRUE("stack piece not closed", is_stack_piece_closed(piece));
  frame->stack_piece = piece;
  value_t *stack_start = frame_get_stack_piece_bottom(frame);
  frame->frame_pointer = stack_start + get_integer_value(get_stack_piece_lid_frame_pointer(piece));
  frame_walk_down_stack(frame);
}
Example #2
0
static value_t integer_transient_identity_hash(value_t self,
    hash_stream_t *stream) {
  CHECK_DOMAIN(vdInteger, self);
  hash_stream_write_tags(stream, vdInteger, __ofUnknown__);
  hash_stream_write_int64(stream, get_integer_value(self));
  return success();
}
Example #3
0
value_t assembler_flush(assembler_t *assm) {
  // Copy the bytecode into a blob object.
  blob_t code_blob;
  short_buffer_flush(&assm->code, &code_blob);
  TRY_DEF(bytecode, new_heap_blob_with_data(assm->runtime, &code_blob));
  // Invert the constant pool map into an array.
  value_t value_pool_map = assm->value_pool;
  size_t value_pool_size = get_id_hash_map_size(value_pool_map);
  TRY_DEF(value_pool, new_heap_array(assm->runtime, value_pool_size));
  id_hash_map_iter_t iter;
  id_hash_map_iter_init(&iter, value_pool_map);
  size_t entries_seen = 0;
  while (id_hash_map_iter_advance(&iter)) {
    value_t key;
    value_t value;
    id_hash_map_iter_get_current(&iter, &key, &value);
    size_t index = get_integer_value(value);
    // Check that the entry hasn't been set already.
    CHECK_PHYLUM(tpNull, get_array_at(value_pool, index));
    set_array_at(value_pool, index, key);
    entries_seen++;
  }
  CHECK_EQ("wrong number of entries", entries_seen, value_pool_size);
  return new_heap_code_block(assm->runtime, bytecode, value_pool,
      assm->high_water_mark);
}
Example #4
0
value_t plankton_set_unbound_module_fragment_contents(value_t object, runtime_t *runtime,
    value_t contents) {
  UNPACK_PLANKTON_MAP(contents, stage, imports, elements);
  set_unbound_module_fragment_stage(object, new_stage_offset(get_integer_value(stage_value)));
  set_unbound_module_fragment_imports(object, imports_value);
  set_unbound_module_fragment_elements(object, elements_value);
  return success();
}
Example #5
0
value_t plankton_set_operation_contents(value_t object, runtime_t *runtime,
    value_t contents) {
  BEGIN_UNPACK_PLANKTON(contents);
  UNPACK_PLANKTON_FIELD(snInDomain(vdInteger), type);
  UNPACK_PLANKTON_FIELD(snNoCheck, value);
  set_operation_type(object, get_integer_value(type_value));
  set_operation_value(object, value_value);
  return ensure_frozen(runtime, object);
}
Example #6
0
// Restores the previous state of the interpreter from the given derived
// object's escape state.
static void restore_escape_state(frame_t *frame, value_t stack,
                                 value_t destination) {
    value_t target_piece = get_derived_object_host(destination);
    if (!is_same_value(target_piece, frame->stack_piece)) {
        set_stack_top_piece(stack, target_piece);
        open_stack_piece(target_piece, frame);
    }
    value_t *stack_start = frame_get_stack_piece_bottom(frame);
    value_t stack_pointer = get_escape_state_stack_pointer(destination);
    frame->stack_pointer = stack_start + get_integer_value(stack_pointer);
    value_t frame_pointer = get_escape_state_frame_pointer(destination);
    frame->frame_pointer = stack_start + get_integer_value(frame_pointer);
    value_t limit_pointer = get_escape_state_limit_pointer(destination);
    frame->limit_pointer = stack_start + get_integer_value(limit_pointer);
    frame->flags = get_escape_state_flags(destination);
    value_t pc = get_escape_state_pc(destination);
    frame->pc = get_integer_value(pc);
}
Example #7
0
// Map ints to values.
static value_t int_to_value(value_t value, runtime_t *runtime, void *ptr) {
  test_resolver_data_t *data = (test_resolver_data_t*) ptr;
  switch (get_integer_value(value)) {
    case 0:
      return data->i0;
    case 1:
      return data->i1;
    default:
      UNREACHABLE("int to value");
      return new_integer(0);
  }
}
Example #8
0
// Performs a lookup for a single symbol scope.
static value_t map_scope_lookup(map_scope_o *self, value_t symbol,
    binding_info_t *info_out) {
  value_t value = get_id_hash_map_at(self->map, symbol);
  if (in_condition_cause(ccNotFound, value)) {
    return scope_lookup(self->outer, symbol, info_out);
  } else {
    if (info_out != NULL) {
      binding_info_codec_t codec;
      codec.encoded = get_integer_value(value);
      *info_out = codec.decoded;
    }
    return success();
  }
}
Example #9
0
// Run function of whole program
static void run(const char *config_filename) {
	double max_z, min_z;
	source_object *object;
	double complex *optical_field;

	// Initialize FFTW threads
	fftw_init_threads();

	// Load config to memory
	load_config(config_filename);

	// Initialize logger
	initialize_logger(get_integer_value(CONF_LOGGER_DEBUG_MODE));

	// Load source object
	load_source_object(&object, get_string_value(CONF_OBJECT_POINTS_FILE));

	// Initialize final optical field
	initialize_optical_field(&optical_field);

	// Extract z position extremes of source object
	extract_object_proportions(object, &min_z, &max_z, OBJECT_DEPTH);

	// Modified WRP method itself
	perform_wrp_method(object, optical_field, min_z, max_z);

	// Numerical reconstruction on hologram
	perform_numerical_reconstruction(optical_field, min_z);

	// Memory clear
	log_info("Deleting all structures from memory\n");
	free(optical_field);
	delete_source_object(object);
	delete_lookup_table();
	delete_config();
}
Example #10
0
bool try_push_new_frame(frame_t *frame, size_t frame_capacity, uint32_t flags,
    bool is_lid) {
  value_t stack_piece = frame->stack_piece;
  CHECK_FALSE("pushing closed stack piece", is_stack_piece_closed(stack_piece));
  // First record the current state of the old top frame so we can store it in
  // the header of the new frame.
  frame_t old_frame = *frame;
  // Determine how much room is left in the stack piece.
  value_t *stack_piece_start = get_stack_piece_storage(stack_piece);
  size_t capacity = get_integer_value(get_stack_piece_capacity(stack_piece));
  value_t *stack_piece_limit = stack_piece_start + capacity;
  // There must always be room on a stack piece for the lid frame because it
  // must always be possible to close a stack if a condition occurs, which we
  // assume it can at any time. So we hold back a frame header's worth of stack
  // except when allocating the lid.
  if (!is_lid)
    stack_piece_limit -= kFrameHeaderSize;
  value_t *new_frame_pointer = old_frame.stack_pointer + kFrameHeaderSize;
  value_t *new_frame_limit = new_frame_pointer + frame_capacity;
  if (new_frame_limit > stack_piece_limit)
    return false;
  // Store the new frame's info in the frame struct.
  frame->stack_pointer = frame->frame_pointer = new_frame_pointer;
  frame->limit_pointer = new_frame_limit;
  frame->flags = new_flag_set(flags);
  frame->pc = 0;
  // Record the relevant information about the previous frame in the new frame's
  // header.
  frame_set_previous_frame_pointer(frame, old_frame.frame_pointer - stack_piece_start);
  frame_set_previous_limit_pointer(frame, old_frame.limit_pointer - stack_piece_start);
  frame_set_previous_flags(frame, old_frame.flags);
  frame_set_previous_pc(frame, old_frame.pc);
  frame_set_code_block(frame, nothing());
  frame_set_argument_map(frame, nothing());
  return true;
}
Example #11
0
static void integer_print_on(value_t value, print_on_context_t *context) {
  CHECK_DOMAIN(vdInteger, value);
  const char *fmt = (context->flags & pfHex) ? "%llx" : "%lli";
  string_buffer_printf(context->buf, fmt, get_integer_value(value));
}
Example #12
0
static value_t integer_ordering_compare(value_t a, value_t b) {
  return compare_signed_integers(get_integer_value(a), get_integer_value(b));
}
Example #13
0
int64_t get_call_tags_offset_at(value_t self, int64_t index) {
  CHECK_FAMILY(ofCallTags, self);
  value_t entries = get_call_tags_entries(self);
  return get_integer_value(get_pair_array_second_at(entries, index));
}
Example #14
0
void get_stack_piece_layout(value_t value, heap_object_layout_t *layout) {
  size_t capacity = get_integer_value(get_stack_piece_capacity(value));
  size_t size = calc_stack_piece_size(capacity);
  heap_object_layout_set(layout, size, kHeapObjectHeaderSize);
}
Example #15
0
value_t *frame_get_stack_piece_top(frame_t *frame) {
  value_t *storage = get_stack_piece_storage(frame->stack_piece);
  return storage + get_integer_value(get_stack_piece_capacity(frame->stack_piece));
}