- uses: actions/checkout@v2
- name: make build.sh executable
run: chmod +x build.sh
+ - name: make build directory
+ run: mkdir -p build
- name: build onyx
run: ./build.sh
- name: run tests
+++ /dev/null
-{ "configurations": {
- "cpptools-run": {
- "adapter": "vscode-cpptools",
- "configuration": {
- "type": "cppdbg",
- "request": "launch",
- "program": "/home/brendan/dev/c/onyx/bin/onyx-debug",
- "args": ["-VVV", "-I", "/home/brendan/dev/c/onyx", "-o", "site/analyzer.wasm", "-r", "js", "--no-colors", "src/build.onyx", "--doc", "doc/source_reference" ],
- "stopAtEntry": true,
- "cwd": "/home/brendan/dev/onyx/wasm_analyzer",
- "environment": [],
- "externalConsole": false,
- "MIMode": "gdb",
- "setupCommands": [
- {
- "description": "Enable pretty-printing for gdb",
- "text": "-enable-pretty-printing",
- "ignoreFailures": true
- }
- ]
- }
- }
- }
-}
return get(^b, idx);
}
+#operator ^[] macro (b: Bucket_Array($T), idx: i32) -> ^T {
+ get_ptr :: get_ptr
+ return get_ptr(^b, idx);
+}
+
get :: (use b: ^Bucket_Array($T), idx: i32) -> T {
bucket_index := idx / elements_per_bucket;
elem_index := idx % elements_per_bucket;
}
}
+iterator :: (b: ^Bucket_Array($T)) -> Iterator(T) {
+ Context :: struct (T: type_expr) {
+ ba : ^Bucket_Array(T);
+ bucket_idx : i32;
+ elem_idx : i32;
+ }
+
+ c := new(#type Context(T));
+ c.ba = b;
+ c.bucket_idx = 0;
+ c.elem_idx = 0;
+
+ next :: (use c: ^Context($T)) -> (T, bool) {
+ use package core.intrinsics.onyx
+
+ bucket := ^ba.buckets[bucket_idx];
+ while elem_idx == bucket.count {
+ bucket_idx += 1;
+ if bucket_idx == ba.buckets.count do return __zero_value(T), false;
+
+ bucket = ^ba.buckets[bucket_idx];
+ elem_idx = 0;
+ }
+
+ defer elem_idx += 1;
+ return bucket.data[elem_idx], true;
+ }
+
+ close :: (x: rawptr) => cfree(x);
+
+ return .{
+ data = c,
+ next = #solidify next { T=T },
+ close = close,
+ };
+}
+
#private
alloc_bucket :: (use b: ^Bucket_Array($T)) -> Bucket_Array.Bucket(T) {
data := raw_alloc(allocator, sizeof T * elements_per_bucket);
}
#private_file
-allocate_elem :: (list: ^List($T)) -> ^ListElem(T) {
- return new(#type ListElem(T), allocator=list.allocator);
-}
+allocate_elem :: macro (list: ^List($T)) => new(#type ListElem(T), allocator=list.allocator);
["[", "]"],
["(", ")"],
["\"", "\""]
- ]
+ ],
+ "wordPattern": "(-?\\d*\\.\\d\\w*)|([^\\`\\~\\!\\@\\#\\%\\^\\&\\*\\(\\)\\-\\=\\+\\[\\{\\]\\}\\\\\\|\\;\\:\\'\\\"\\,\\.\\<\\>\\/\\?\\s]+)"
}
\ No newline at end of file
</dict>
<dict>
<key>match</key>
- <string>\b(str|cstr)\b</string>
+ <string>\b(str|cstr|type_expr|any)\b</string>
<key>name</key>
<string>storage.type.onyx</string>
</dict>
</dict>
<dict>
<key>match</key>
- <string>(\b[[:alpha:]_]+[[:alnum:]_]*\b)\s*[!]?\s*[\(]</string>
+ <string>(\b[[:alpha:]_]+[[:alnum:]_]*\b)\s*[:]\s*[:]\s*[\(]</string>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
- <string>support.function.onyx</string>
+ <string>entity.name.function.onyx</string>
</dict>
</dict>
</dict>
package bmfont
use package core
-
+#private_file json :: package json
load_bmfont :: (fnt_data: [] u8) -> BMFont {
- bmf: BMFont;
- memory.set(^bmf, 0, sizeof BMFont);
-
- map.init(^bmf.pages);
- map.init(^bmf.glyphs);
+ bmf := create_bmfont();
parse_bmfont(fnt_data, ^bmf);
return bmf;
}
+load_bmfont_from_json :: (fnt_data: [] u8) -> BMFont {
+ bmf := create_bmfont();
+
+ j := json.decode(fnt_data);
+ defer json.free(j);
+
+ extract_bmfont_from_json(^bmf, j.root);
+}
+
+#private_file
+create_bmfont :: () -> BMFont {
+ bmf: BMFont;
+ memory.set(^bmf, 0, sizeof BMFont);
+
+ map.init(^bmf.pages);
+ map.init(^bmf.glyphs);
+
+ return bmf;
+}
+
#private_file
parse_bmfont :: (fnt_data: [] u8, font: ^BMFont) {
R :: package core.string.reader
elseif key == "blueChnl" do common.blue_channel = ~~ conv.str_to_i64(value);
}
}
+
+#private_file
+extract_bmfont_from_json :: (font: ^BMFont, root: ^json.Value) {
+ font_info := root["info"];
+ font.info.face_name = font_info["face"]->as_str();
+ font.info.size = ~~font_info["size"]->as_int();
+ font.info.bold = font_info["bold"]->as_int() != 0;
+ font.info.italic = font_info["italic"]->as_int() != 0;
+ font.info.unicode = font_info["unicode"]->as_int() != 0;
+ font.info.stretchH = ~~font_info["stretchH"]->as_int();
+ font.info.smooth = font_info["smooth"]->as_int() != 0;
+ font.info.supersampling = ~~font_info["aa"]->as_int();
+
+ font_padding := font_info["padding"];
+ font.info.padding.top = ~~font_padding[0]->as_int();
+ font.info.padding.right = ~~font_padding[1]->as_int();
+ font.info.padding.bottom = ~~font_padding[2]->as_int();
+ font.info.padding.left = ~~font_padding[3]->as_int();
+
+ font_spacing := font_info["spacing"];
+ font.info.spacing.horizontal = ~~font_spacing[0]->as_int();
+ font.info.spacing.vertical = ~~font_spacing[1]->as_int();
+
+ font_common := root["common"];
+ font.common.line_height = ~~font_common["lineHeight"]->as_int();
+ font.common.baseline = ~~font_common["base"]->as_int();
+ font.common.scale_width = ~~font_common["scaleW"]->as_int();
+ font.common.scale_height = ~~font_common["scaleH"]->as_int();
+ font.common.page_count = ~~font_common["pages"]->as_int();
+ font.common.packed = font_common["packed"]->as_int() != 0;
+ font.common.alpha_channel = ~~font_common["alphaChnl"]->as_int();
+ font.common.red_channel = ~~font_common["redChnl"]->as_int();
+ font.common.green_channel = ~~font_common["greenChnl"]->as_int();
+ font.common.blue_channel = ~~font_common["blueChnl"]->as_int();
+
+ i := 0;
+ for page: root["pages"]->as_array() {
+ defer i += 1;
+
+ font.pages[i] = page->as_str();
+ }
+
+ for ch: root["chars"]->as_array() {
+ id := cast(i32) ch["id"]->as_int();
+ font.glyphs[id] = .{
+ id = id,
+
+ x = ~~ch["x"]->as_int(),
+ y = ~~ch["y"]->as_int(),
+ w = ~~ch["width"]->as_int(),
+ h = ~~ch["height"]->as_int(),
+
+ xoffset = ~~ch["xoffset"]->as_int(),
+ yoffset = ~~ch["yoffset"]->as_int(),
+ xadvance = ~~ch["xadvance"]->as_int(),
+
+ page = ~~ch["page"]->as_int(),
+ channel = ~~ch["chnl"]->as_int(),
+ };
+ }
+}
gl.uniform1i(active_shader.texture_uniform, math.max(texture_id, 0));
}
- use_ortho_projection :: (use ir: ^Immediate_Renderer, left: f32, right: f32, top: f32, bottom: f32) {
+ use_ortho_projection :: (use ir: ^Immediate_Renderer, left, right, top, bottom: f32) {
projection_matrix := f32.[
2 / (right - left), 0, 0, 0,
0, 2 / (top - bottom), 0, 0,
gl.useProgram(active_shader.program);
}
- push_scissor :: (use ir: ^Immediate_Renderer, x: f32, y: f32, w: f32, h: f32) {
+ push_scissor :: (use ir: ^Immediate_Renderer, x, y, w, h: f32) {
if vertex_count > 0 do ir->flush();
if !gl.isEnabled(gl.SCISSOR_TEST) {
}
}
- set_window_size :: (use ir: ^Immediate_Renderer, width: i32, height: i32) {
+ set_window_size :: (use ir: ^Immediate_Renderer, width, height: i32) {
window_width = width;
window_height = height;
[1] -> 21
[2] -> 22
[3] -> 23
+0
+1
+2
+3
+4
+5
+6
+7
+8
+9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+21
+22
+23
Sum is 276
sum += *it;
});
+ for it: bucket_array.iterator(^ba) {
+ printf("{}\n", it);
+ }
+
printf("Sum is {}\n", sum);
}
\ No newline at end of file