Fix field resolution not resolving constant value properly
This commit is contained in:
@@ -8,4 +8,4 @@ if not exist build\bld.exe (
|
|||||||
)
|
)
|
||||||
|
|
||||||
rem ubuntu run ./build.sh
|
rem ubuntu run ./build.sh
|
||||||
build\bld.exe --quick
|
build\bld.exe --tests text_editor
|
||||||
|
|||||||
@@ -28,6 +28,10 @@ main :: proc(): int {
|
|||||||
font_spacing: float = 1;
|
font_spacing: float = 1;
|
||||||
font: Font = LoadFontEx("C:/Windows/Fonts/consola.ttf", :int(font_size), nil, 0);
|
font: Font = LoadFontEx("C:/Windows/Fonts/consola.ttf", :int(font_size), nil, 0);
|
||||||
|
|
||||||
|
glyph_info: GlyphInfo = GetGlyphInfo(font, 'A');
|
||||||
|
size := MeasureTextEx(font, "A", font_size, font_spacing);
|
||||||
|
TE.Monosize = {:float(glyph_info.image.width), size.y};
|
||||||
|
|
||||||
SANDBOX_TEXT_EDITOR :: 1;
|
SANDBOX_TEXT_EDITOR :: 1;
|
||||||
SANDBOX_PROTOTYPE :: 2;
|
SANDBOX_PROTOTYPE :: 2;
|
||||||
sandbox_chosen := SANDBOX_PROTOTYPE;
|
sandbox_chosen := SANDBOX_PROTOTYPE;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ Perm: MA_Arena;
|
|||||||
Transcripts: TranscriptStack;
|
Transcripts: TranscriptStack;
|
||||||
|
|
||||||
SearchBar: TE.Buffer;
|
SearchBar: TE.Buffer;
|
||||||
|
FilenamesBuffer: TE.Buffer;
|
||||||
ResultsBuffer: TE.Buffer;
|
ResultsBuffer: TE.Buffer;
|
||||||
|
|
||||||
UpdatePrototype :: proc(rect: Rect2P, font: Font, font_size: float, font_spacing: float) {
|
UpdatePrototype :: proc(rect: Rect2P, font: Font, font_size: float, font_spacing: float) {
|
||||||
@@ -10,8 +11,6 @@ UpdatePrototype :: proc(rect: Rect2P, font: Font, font_size: float, font_spacing
|
|||||||
Inited = true;
|
Inited = true;
|
||||||
for iter := OS_IterateFiles(&Perm, S8("C:/video")); OS_IsValid(iter); OS_Advance(&iter) {
|
for iter := OS_IterateFiles(&Perm, S8("C:/video")); OS_IsValid(iter); OS_Advance(&iter) {
|
||||||
if S8_EndsWith(iter.absolute_path, S8(".srt"), true) {
|
if S8_EndsWith(iter.absolute_path, S8(".srt"), true) {
|
||||||
printf("%.*s\n", :int(iter.absolute_path.len), iter.absolute_path.str);
|
|
||||||
|
|
||||||
file_content := OS_ReadFile(&Perm, iter.absolute_path);
|
file_content := OS_ReadFile(&Perm, iter.absolute_path);
|
||||||
PushTranscript(&Transcripts, {
|
PushTranscript(&Transcripts, {
|
||||||
absolute_path = STR(iter.absolute_path),
|
absolute_path = STR(iter.absolute_path),
|
||||||
@@ -19,27 +18,21 @@ UpdatePrototype :: proc(rect: Rect2P, font: Font, font_size: float, font_spacing
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for i := 0; i < Transcripts.len; i += 1 {
|
||||||
|
TE.ReplaceText(&FilenamesBuffer, {FilenamesBuffer.len, FilenamesBuffer.len}, Transcripts.data[i].absolute_path);
|
||||||
|
TE.ReplaceText(&FilenamesBuffer, {FilenamesBuffer.len, FilenamesBuffer.len}, "\n");
|
||||||
|
}
|
||||||
|
TE.ReplaceText(&ResultsBuffer, {ResultsBuffer.len, ResultsBuffer.len}, Transcripts.data[0].file_content);
|
||||||
|
TE.ReplaceText(&SearchBar, {SearchBar.len, SearchBar.len}, "");
|
||||||
|
|
||||||
TE.AddWindow({buffer = &SearchBar});
|
TE.AddWindow({buffer = &SearchBar});
|
||||||
TE.AddWindow({buffer = &ResultsBuffer});
|
TE.AddWindow({buffer = &ResultsBuffer, flags = TE.WindowFlags_DrawScrollbar});
|
||||||
TE.FocusedWindow = &TE.WindowStack[0];
|
TE.FocusedWindow = &TE.WindowStack[0];
|
||||||
TE.FocusedWindow = nil;
|
TE.FocusedWindow = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
for key := GetCharPressed(); key; key = GetCharPressed() {
|
|
||||||
selection_range := :TE.Range{0,0};
|
|
||||||
|
|
||||||
result: UTF8_Result = UTF32ToUTF8(:u32(key));
|
|
||||||
if result.error == 0 {
|
|
||||||
TE.ReplaceText(&SearchBar, selection_range, {:*char(&result.out_str[0]), result.len});
|
|
||||||
} else {
|
|
||||||
TE.ReplaceText(&SearchBar, selection_range, "?");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Te.ComputeWindowRects(rect);
|
// Te.ComputeWindowRects(rect);
|
||||||
TE.WindowStack[0].rect = CutLeft(&rect, 0.5 * GetRectX(rect));
|
TE.WindowStack[0].rect = CutTop(&rect, font_size * 2);
|
||||||
TE.WindowStack[1].rect = CutLeft(&rect, 1.0 * GetRectX(rect));
|
TE.WindowStack[1].rect = CutLeft(&rect, 1.0 * GetRectX(rect));
|
||||||
|
|
||||||
TE.UpdateAndDrawWindows(font, font_size);
|
TE.UpdateAndDrawWindows(font, font_size);
|
||||||
|
|||||||
@@ -14,11 +14,6 @@ WindowStackCount: int;
|
|||||||
UpdateTextEditor :: proc(rect: Rect2P, font: Font, font_size: float, font_spacing: float) {
|
UpdateTextEditor :: proc(rect: Rect2P, font: Font, font_size: float, font_spacing: float) {
|
||||||
if !Inited {
|
if !Inited {
|
||||||
Inited = true;
|
Inited = true;
|
||||||
|
|
||||||
glyph_info: GlyphInfo = GetGlyphInfo(font, 'A');
|
|
||||||
size := MeasureTextEx(font, "A", font_size, font_spacing);
|
|
||||||
Monosize = {:float(glyph_info.image.width), size.y};
|
|
||||||
|
|
||||||
file_content := LoadFileText("C:/Work/language/examples/text_editor/entry_point/entry_point.lc");
|
file_content := LoadFileText("C:/Work/language/examples/text_editor/entry_point/entry_point.lc");
|
||||||
AddText(&TeBuffer, {file_content, :int(strlen(file_content))});
|
AddText(&TeBuffer, {file_content, :int(strlen(file_content))});
|
||||||
UnloadFileText(file_content);
|
UnloadFileText(file_content);
|
||||||
@@ -31,8 +26,13 @@ UpdateTextEditor :: proc(rect: Rect2P, font: Font, font_size: float, font_spacin
|
|||||||
UpdateAndDrawWindows(font, font_size);
|
UpdateAndDrawWindows(font, font_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WindowFlags :: typedef u64;
|
||||||
|
WindowFlags_DrawScrollbar :: 1;
|
||||||
|
|
||||||
Window :: struct {
|
Window :: struct {
|
||||||
|
flags: WindowFlags;
|
||||||
buffer: *Buffer;
|
buffer: *Buffer;
|
||||||
|
|
||||||
cursor: Selection;
|
cursor: Selection;
|
||||||
scroll: Vector2;
|
scroll: Vector2;
|
||||||
mouse_scrolling: bool;
|
mouse_scrolling: bool;
|
||||||
@@ -324,8 +324,7 @@ UpdateAndDrawWindow :: proc(w: *Window, font: Font, font_size: float) {
|
|||||||
if (w.scroll.x < 0) w.scroll.x = 0;
|
if (w.scroll.x < 0) w.scroll.x = 0;
|
||||||
if (w.scroll.y < 0) w.scroll.y = 0;
|
if (w.scroll.y < 0) w.scroll.y = 0;
|
||||||
|
|
||||||
adjusted_kind_of_end := buffer_end_wpos.y - GetRectY(text_window_rect) * 0.8;
|
if (w.scroll.y > buffer_end_wpos.y) w.scroll.y = buffer_end_wpos.y;
|
||||||
if (w.scroll.y > adjusted_kind_of_end) w.scroll.y = adjusted_kind_of_end;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Mouse
|
// Mouse
|
||||||
|
|||||||
@@ -6855,16 +6855,15 @@ LC_FUNCTION LC_Operand LC_ResolveExprEx(LC_AST *n) {
|
|||||||
} break;
|
} break;
|
||||||
|
|
||||||
case LC_ASTKind_ExprField: {
|
case LC_ASTKind_ExprField: {
|
||||||
bool first_part_executed = false;
|
bool resolved_import = false;
|
||||||
|
|
||||||
LC_Operand op = {0};
|
LC_Operand op = {0};
|
||||||
if (n->efield.left->kind == LC_ASTKind_ExprIdent) {
|
if (n->efield.left->kind == LC_ASTKind_ExprIdent) {
|
||||||
LC_AST *nf = n->efield.left;
|
LC_AST *nf = n->efield.left;
|
||||||
LC_Operand LC_PROP_ERROR(op_name, nf, LC_ResolveName(nf, nf->eident.name));
|
LC_Operand LC_PROP_ERROR(op_name, nf, LC_ResolveName(nf, nf->eident.name));
|
||||||
|
|
||||||
// LC_Match (Package.) and fold (Package.Other) into just (Other)
|
|
||||||
if (op_name.decl->kind == LC_DeclKind_Import) {
|
if (op_name.decl->kind == LC_DeclKind_Import) {
|
||||||
first_part_executed = true;
|
resolved_import = true;
|
||||||
nf->eident.resolved_decl = op_name.decl;
|
nf->eident.resolved_decl = op_name.decl;
|
||||||
nf->type = L->tvoid;
|
nf->type = L->tvoid;
|
||||||
|
|
||||||
@@ -6872,7 +6871,7 @@ LC_FUNCTION LC_Operand LC_ResolveExprEx(LC_AST *n) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!first_part_executed) {
|
if (!resolved_import) {
|
||||||
LC_ASTKind left_kind = n->efield.left->kind;
|
LC_ASTKind left_kind = n->efield.left->kind;
|
||||||
LC_PROP_ERROR(op, n, LC_ResolveExpr(n->efield.left));
|
LC_PROP_ERROR(op, n, LC_ResolveExpr(n->efield.left));
|
||||||
|
|
||||||
@@ -6881,10 +6880,18 @@ LC_FUNCTION LC_Operand LC_ResolveExprEx(LC_AST *n) {
|
|||||||
LC_IF(!LC_IsAggType(type), n->efield.left, "invalid operation, expected aggregate type, '%s' is not an aggregate", LC_GenLCType(type));
|
LC_IF(!LC_IsAggType(type), n->efield.left, "invalid operation, expected aggregate type, '%s' is not an aggregate", LC_GenLCType(type));
|
||||||
LC_PROP_ERROR(op, n, LC_ResolveNameInScope(n, type->decl));
|
LC_PROP_ERROR(op, n, LC_ResolveNameInScope(n, type->decl));
|
||||||
LC_ASSERT(n, op.decl->kind == LC_DeclKind_Var);
|
LC_ASSERT(n, op.decl->kind == LC_DeclKind_Var);
|
||||||
result.flags |= LC_OPF_Const;
|
result.flags |= LC_OPF_LValue | LC_OPF_Const;
|
||||||
|
result.val = op.decl->val;
|
||||||
|
} else {
|
||||||
|
result.val = op.decl->val;
|
||||||
|
// @copy_paste from ExprIdent
|
||||||
|
if (op.decl->kind == LC_DeclKind_Const) {
|
||||||
|
result.flags |= LC_OPF_UTConst | LC_OPF_Const;
|
||||||
|
SetConstVal(n, result.val);
|
||||||
|
} else {
|
||||||
|
result.flags |= LC_OPF_LValue | LC_OPF_Const;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
result.flags |= LC_OPF_LValue;
|
|
||||||
result.val = op.decl->val;
|
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case LC_ASTKind_ExprCall: {
|
case LC_ASTKind_ExprCall: {
|
||||||
|
|||||||
@@ -690,16 +690,15 @@ LC_FUNCTION LC_Operand LC_ResolveExprEx(LC_AST *n) {
|
|||||||
} break;
|
} break;
|
||||||
|
|
||||||
case LC_ASTKind_ExprField: {
|
case LC_ASTKind_ExprField: {
|
||||||
bool first_part_executed = false;
|
bool resolved_import = false;
|
||||||
|
|
||||||
LC_Operand op = {0};
|
LC_Operand op = {0};
|
||||||
if (n->efield.left->kind == LC_ASTKind_ExprIdent) {
|
if (n->efield.left->kind == LC_ASTKind_ExprIdent) {
|
||||||
LC_AST *nf = n->efield.left;
|
LC_AST *nf = n->efield.left;
|
||||||
LC_Operand LC_PROP_ERROR(op_name, nf, LC_ResolveName(nf, nf->eident.name));
|
LC_Operand LC_PROP_ERROR(op_name, nf, LC_ResolveName(nf, nf->eident.name));
|
||||||
|
|
||||||
// LC_Match (Package.) and fold (Package.Other) into just (Other)
|
|
||||||
if (op_name.decl->kind == LC_DeclKind_Import) {
|
if (op_name.decl->kind == LC_DeclKind_Import) {
|
||||||
first_part_executed = true;
|
resolved_import = true;
|
||||||
nf->eident.resolved_decl = op_name.decl;
|
nf->eident.resolved_decl = op_name.decl;
|
||||||
nf->type = L->tvoid;
|
nf->type = L->tvoid;
|
||||||
|
|
||||||
@@ -707,7 +706,7 @@ LC_FUNCTION LC_Operand LC_ResolveExprEx(LC_AST *n) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!first_part_executed) {
|
if (!resolved_import) {
|
||||||
LC_ASTKind left_kind = n->efield.left->kind;
|
LC_ASTKind left_kind = n->efield.left->kind;
|
||||||
LC_PROP_ERROR(op, n, LC_ResolveExpr(n->efield.left));
|
LC_PROP_ERROR(op, n, LC_ResolveExpr(n->efield.left));
|
||||||
|
|
||||||
@@ -716,10 +715,18 @@ LC_FUNCTION LC_Operand LC_ResolveExprEx(LC_AST *n) {
|
|||||||
LC_IF(!LC_IsAggType(type), n->efield.left, "invalid operation, expected aggregate type, '%s' is not an aggregate", LC_GenLCType(type));
|
LC_IF(!LC_IsAggType(type), n->efield.left, "invalid operation, expected aggregate type, '%s' is not an aggregate", LC_GenLCType(type));
|
||||||
LC_PROP_ERROR(op, n, LC_ResolveNameInScope(n, type->decl));
|
LC_PROP_ERROR(op, n, LC_ResolveNameInScope(n, type->decl));
|
||||||
LC_ASSERT(n, op.decl->kind == LC_DeclKind_Var);
|
LC_ASSERT(n, op.decl->kind == LC_DeclKind_Var);
|
||||||
result.flags |= LC_OPF_Const;
|
result.flags |= LC_OPF_LValue | LC_OPF_Const;
|
||||||
|
result.val = op.decl->val;
|
||||||
|
} else {
|
||||||
|
result.val = op.decl->val;
|
||||||
|
// @copy_paste from ExprIdent
|
||||||
|
if (op.decl->kind == LC_DeclKind_Const) {
|
||||||
|
result.flags |= LC_OPF_UTConst | LC_OPF_Const;
|
||||||
|
SetConstVal(n, result.val);
|
||||||
|
} else {
|
||||||
|
result.flags |= LC_OPF_LValue | LC_OPF_Const;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
result.flags |= LC_OPF_LValue;
|
|
||||||
result.val = op.decl->val;
|
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case LC_ASTKind_ExprCall: {
|
case LC_ASTKind_ExprCall: {
|
||||||
|
|||||||
5
tests/const_not_folding/main/test_unused.lc
Normal file
5
tests/const_not_folding/main/test_unused.lc
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import b "second";
|
||||||
|
|
||||||
|
main :: proc(): int {
|
||||||
|
return b.A;
|
||||||
|
}
|
||||||
1
tests/const_not_folding/second/second.lc
Normal file
1
tests/const_not_folding/second/second.lc
Normal file
@@ -0,0 +1 @@
|
|||||||
|
A :: 0;
|
||||||
11
tests/defer.txt
Normal file
11
tests/defer.txt
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
a: char;
|
||||||
|
|
||||||
|
main :: proc(): int {
|
||||||
|
for i := 0; i < 4; i += 1 {
|
||||||
|
if i == 2 { break; }
|
||||||
|
|
||||||
|
string := &a;
|
||||||
|
defer *string = 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user