File tree 3 files changed +69
-1
lines changed
3 files changed +69
-1
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ MCS_BUILD = mcs -debug- -optimize+ -out:$@ $^
27
27
MLTON_BUILD = mlton -output $@ $^
28
28
NIM_CLANG_BUILD = nim c -o:$@ --cc:clang $(NIM_FLAGS ) $^
29
29
NIM_GCC_BUILD = nim c -o:$@ --cc:gcc $(NIM_FLAGS ) $^
30
+ ODIN_BUILD = odin build $^ -file -out:$@ -o:speed -no-bounds-check
30
31
RUSTC_BUILD = rustc $(RUSTC_FLAGS ) -C opt-level=3 -C lto -C codegen-units=1 -C panic=abort -C strip=symbols -o $@ $^
31
32
RUST_CLIPPY = clippy-driver -o $@ .clippy $^
32
33
SWIFTC_BUILD = swiftc -parse-as-library -O -lto=llvm-full -cross-module-optimization $(LIBNOTIFY_FLAGS ) -import-objc-header ../common/libnotify/libnotify.h -o $@ $^
Original file line number Diff line number Diff line change @@ -64,7 +64,8 @@ executables := \
64
64
json-core/target/Release/net8.0/json-core \
65
65
target/json_zig \
66
66
target/json_yajl_gcc \
67
- target/json_yajl_clang
67
+ target/json_yajl_clang \
68
+ target/json_odin
68
69
69
70
# TODO: Enable Julia test after https://github.com/quinnj/JSON3.jl/issues/276 fixed
70
71
artifacts := $(executables ) \
@@ -331,6 +332,9 @@ target/json_yajl_gcc: test_yajl.c | target libnotify
331
332
target/json_yajl_clang : test_yajl.c | target libnotify
332
333
$(CLANG_BUILD ) -lyajl
333
334
335
+ target/json_odin : test.odin
336
+ $(ODIN_BUILD )
337
+
334
338
# Run
335
339
336
340
.PHONY : run
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import " core:encoding/json"
4
+ import " core:fmt"
5
+ import " core:net"
6
+ import " core:os"
7
+ import " core:os/os2"
8
+
9
+ Coordinate :: struct {
10
+ x, y, z: f64 ,
11
+ }
12
+
13
+ TestStruct :: struct {
14
+ coordinates: []Coordinate,
15
+ }
16
+
17
+ notify :: proc (msg: string ) {
18
+ sock, _ := net.dial_tcp (" 127.0.0.1:9001" )
19
+ defer net.close (sock)
20
+ net.send (sock, transmute ([]byte )msg)
21
+ }
22
+
23
+ calc :: proc (s: string ) -> Coordinate {
24
+ j: TestStruct
25
+ if err := json.unmarshal_string (s, &j); err != nil {
26
+ panic (fmt.tprintf (" %v" , err))
27
+ }
28
+
29
+ coord := Coordinate{}
30
+ for c in j.coordinates {
31
+ coord.x += c.x
32
+ coord.y += c.y
33
+ coord.z += c.z
34
+ }
35
+
36
+ return coord
37
+ }
38
+
39
+ main :: proc () {
40
+ context .allocator = context .temp_allocator
41
+ defer free_all (context .temp_allocator)
42
+
43
+ right := Coordinate{2.0 , 0.5 , 0.25 }
44
+ for v in ([]string {
45
+ ` {"coordinates":[{"x":2.0,"y":0.5,"z":0.25}]}` ,
46
+ ` {"coordinates":[{"y":0.5,"x":2.0,"z":0.25}]}` ,
47
+ }) {
48
+ left := calc (v)
49
+ assert (left == right)
50
+ }
51
+
52
+ s, ok := os.read_entire_file_from_filename (" /tmp/1.json" )
53
+ if !ok {
54
+ panic (" Failed to read 1.json" )
55
+ }
56
+ defer delete (s)
57
+
58
+ notify (fmt.tprintf (" Odin\t %d" , os2.get_pid ()))
59
+ results := calc (string (s))
60
+ notify (" stop" )
61
+
62
+ fmt.println (results)
63
+ }
You can’t perform that action at this time.
0 commit comments