package json
use package core
-decode_string :: (data: str, allocator := context.allocator) -> Value {
+decode_string :: (data: str, allocator := context.allocator) -> ^Value {
stream := io.string_stream_make(data);
return decode(^stream, allocator);
}
-decode :: (stream: ^io.Stream, allocator := context.allocator) -> Value {
-
+decode :: (stream: ^io.Stream, allocator := context.allocator) -> ^Value {
+
}
\ No newline at end of file
package json
#load "./encoder"
-#load "./decoder"
\ No newline at end of file
+#load "./decoder"
+#load "./types"
\ No newline at end of file
package json
+use package core
-use package core.map { Map }
+null_value : Value
Value :: struct {
Type :: enum {
- Null;
+ Null :: 0x00;
Bool;
Integer;
Float;
Object;
}
- type : Type;
- value : struct #union {
+ KeyValue :: struct {
+ key : str;
+ value : ^Value;
+ }
+
+ type : Type;
+ allocator : Allocator;
+ use value : struct #union {
bool_ : bool;
int_ : i64;
float_ : f64;
str_ : str;
- array_ : [..] Value;
- object_ : Map(str, Value);
+
+ @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.
+ array_ : [..] ^Value;
+ object_ : [..] KeyValue;
+ };
+}
+
+is_null :: (v: ^Value) -> bool {
+ if v == null do return true;
+ return v == ^null_value || v.type == .Null;
+}
+
+to_str :: (v: ^Value) -> str do return null_str;
+
+get :: (v: ^Value, key: str) -> ^Value {
+ if v.type != .Object do return ^null_value;
+
+ for ^entry: v.object_ {
+ if entry.key == key do return entry.value;
+ }
+ return ^null_value;
+}
+
+free :: (v: ^Value) do switch v.type {
+ case .Array {
+ for elem: v.array_ {
+ free(elem);
+ }
+ array.free(^v.array_);
+ }
+
+ case .Object {
+ for ^entry: v.object_ {
+ free(entry.value);
+ }
+ array.free(^v.object_);
}
-}
\ No newline at end of file
+}
s_type->Struct.unique_id = next_unique_id++;
s_type->Struct.mem_count = bh_arr_length(s_node->members);
+ s_type->Struct.memarr = NULL;
+ bh_table_init(global_heap_allocator, s_type->Struct.members, s_type->Struct.mem_count + 1);
+ bh_arr_new(global_heap_allocator, s_type->Struct.memarr, s_type->Struct.mem_count);
+
} else {
s_type = s_node->stcache;
}
- s_type->Struct.memarr = NULL;
s_type->Struct.poly_sln = NULL;
- bh_table_init(global_heap_allocator, s_type->Struct.members, s_type->Struct.mem_count + 1);
- bh_arr_new(global_heap_allocator, s_type->Struct.memarr, s_type->Struct.mem_count);
+ bh_arr_clear(s_type->Struct.memarr);
+ bh_table_clear(s_type->Struct.members);
s_node->stcache_is_valid = 1;