}
decode :: (stream: ^io.Stream, allocator := context.allocator) -> ^Value {
-
+
}
\ No newline at end of file
json_string := "{ \"test\": \"Hello, World!\", \"array\": [1,2,3,4,5], }";
main :: (args: [] cstr) {
- decoded_json := json.decode_string(json_string);
+ arena := alloc.arena.make(context.allocator, 4096);
+ defer alloc.arena.free(^arena);
+
+ decoded_json := json.decode_string(json_string, alloc.arena.make_allocator(^arena));
defer json.free(decoded_json);
test_str := decoded_json |> json.get("test")
Object;
}
- KeyValue :: struct {
- key : str;
- value : ^Value;
- }
-
type : Type;
allocator : Allocator;
use value : struct #union {
bool_ : bool;
int_ : i64;
float_ : f64;
- str_ : str;
+ str_ : str; // This is allocated out of the allocator above.
@CompilerBug @Cleanup // I don't want these to be pointers in the long run. In theory, they should be
// able to be normal values, but there is a compiler bug that prevents the size and alignment of Value
// being known.
+ //
+ // Thinking about it a little more, I think having these be pointers will be better from a performance
+ // point of view, because the overhead of copying the return/parameter values would be significant.
array_ : [..] ^Value;
- object_ : [..] KeyValue;
+ object_ : [..] struct {
+ key : str; // This is allocated out of the allocator on the Value.
+ value : ^Value;
+ };
};
}
}
free :: (v: ^Value) do switch v.type {
+ case .String {
+ raw_free(v.allocator, v.str_.data);
+ }
+
case .Array {
for elem: v.array_ {
free(elem);
case .Object {
for ^entry: v.object_ {
+ raw_free(v.allocator, entry.key.data);
free(entry.value);
}
array.free(^v.object_);
mem_alignment = type_alignment_of((*member)->type);
if (mem_alignment <= 0) {
+ if ((*member)->type->kind == Type_Kind_Struct) {
+ AstStructType* member_node = (AstStructType *) (*member)->type->ast_type;
+ if (member_node->stcache_is_valid) {
+ s_node->stcache_is_valid = 0;
+ return NULL;
+ }
+ }
+
onyx_report_error((*member)->token->pos, "Invalid member type: %s", type_get_name((*member)->type));
return NULL;
}