Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Struct #14

Merged
merged 143 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
143 commits
Select commit Hold shift + click to select a range
4c3ddf6
wip, parse struct declarations
JeffIrwin Jun 8, 2024
3245ec3
rename member to name
JeffIrwin Jun 8, 2024
7ce31d7
wip, save struct signature
JeffIrwin Jun 8, 2024
5ddb8f0
parse struct instantiator and break tests due to syntactic ambiguity
JeffIrwin Jun 8, 2024
15a4e67
fix tests; add struct dict types and insert/search
JeffIrwin Jun 8, 2024
883e7bb
parse dot member access expressions
JeffIrwin Jun 9, 2024
6e68a4e
insert each struct's members into a dict; workaround cursed memory bug
JeffIrwin Jun 9, 2024
edd4d96
lookup struct members. works with ifx but not gfort
JeffIrwin Jun 9, 2024
a1d1107
make docker test less sensitive to debug logging
JeffIrwin Jun 9, 2024
a1890d9
evaluate struct instantiators
JeffIrwin Jun 10, 2024
4bba2bc
mvp structs; wonky asl
JeffIrwin Jun 10, 2024
6a32f3f
fix structs initialized by expressions
JeffIrwin Jun 10, 2024
c921452
comments
JeffIrwin Jun 10, 2024
0d883d1
remove unnecessary temp var
JeffIrwin Jun 10, 2024
e4bbbfd
wip, debug gfort, change fns to subroutines
JeffIrwin Jun 11, 2024
bd19bce
add premature tests; catch non-struct dot expr
JeffIrwin Jun 11, 2024
ea4078d
fix gfort (holy fucking bingle)
JeffIrwin Jun 11, 2024
eb16ba9
add a couple more struct tests
JeffIrwin Jun 11, 2024
404b02a
fix ifx bug; comments
JeffIrwin Jun 11, 2024
1a1aff6
fix unset existance return value
JeffIrwin Jun 12, 2024
79c39ab
remove intel classic ifort 2021.1
JeffIrwin Jun 12, 2024
c94098c
cleanup (mostly debug logging)
JeffIrwin Jun 21, 2024
cf6c521
copy constructors can't be removed
JeffIrwin Jun 22, 2024
6a70e32
add str conversion for printing structs
JeffIrwin Aug 24, 2024
1c2df1a
lhs dot expressions
JeffIrwin Aug 24, 2024
c1c260f
fix type checking to allow `x = t1.m`
JeffIrwin Aug 24, 2024
dcbf20f
reduce debug logging
JeffIrwin Aug 24, 2024
bff9a37
fix more complex dot sub expressions
JeffIrwin Aug 24, 2024
010c76a
add a few more short struct tests
JeffIrwin Aug 24, 2024
2a19f9e
fix member index bug and add more tests
JeffIrwin Aug 24, 2024
f945f4a
return early to avoid segfault
JeffIrwin Aug 24, 2024
1b070f3
decorate printed structs with their class name
JeffIrwin Aug 24, 2024
444c7b1
fix bugs for dot exprs in fn args and bin exprs
JeffIrwin Aug 25, 2024
7e938b0
add aoc example using structs
JeffIrwin Aug 25, 2024
d09c633
cleanup
JeffIrwin Aug 25, 2024
7eceb55
add tests to cover the bugs from 444c7b1
JeffIrwin Aug 25, 2024
be5f089
allow structs as fn arguments
JeffIrwin Aug 25, 2024
b9fba82
throw error for re-declared fns
JeffIrwin Aug 25, 2024
b80604b
comment on perf
JeffIrwin Aug 25, 2024
8f9cfc1
Revert "make res intent(inout), not sure if i'll keep it"
JeffIrwin Aug 25, 2024
17545b8
comments
JeffIrwin Aug 25, 2024
567f122
fix bugs for type checking and returning dot exprs in fns
JeffIrwin Aug 25, 2024
ee56276
reformat inline struct tests with line breaks
JeffIrwin Aug 25, 2024
8ac771f
add a bunch of struct fn tests
JeffIrwin Aug 25, 2024
70860ba
most of those tests only worked cause i'm not checking sub-types in s…
JeffIrwin Aug 25, 2024
b10d63f
add struct version of aoc 2023/02 as a test
JeffIrwin Aug 25, 2024
0fe7304
refactor and simplify dot expr type handling
JeffIrwin Aug 27, 2024
ef3f17f
here's a bunch of shit but i probably only need the loop in value_copy()
JeffIrwin Aug 27, 2024
9ad4ac9
Revert "here's a bunch of shit but i probably only need the loop in v…
JeffIrwin Aug 27, 2024
d9ea910
fuck yeah
JeffIrwin Aug 27, 2024
3b1fc0c
add tests for dot exprs in struct instantiators
JeffIrwin Aug 27, 2024
26a8daa
one more test
JeffIrwin Aug 27, 2024
5b6a071
fix bug for nested structs; add tests
JeffIrwin Aug 28, 2024
9da834e
cleanup
JeffIrwin Aug 28, 2024
4bdc25f
more cleanup and comments
JeffIrwin Aug 28, 2024
ca19794
add tests for structs of arrays
JeffIrwin Aug 28, 2024
0368df2
implement nested rhs dot exprs
JeffIrwin Aug 29, 2024
96ad59e
broke intel by forgetting 'recursive'
JeffIrwin Aug 29, 2024
1b89415
fix 3rd-order nested rhs dot exprs
JeffIrwin Aug 30, 2024
91e3438
add tests for 3rd-order nested rhs dot exprs
JeffIrwin Aug 30, 2024
6bb2505
refactor
JeffIrwin Aug 30, 2024
08cac79
use recursion instead of iteration for rhs dot expr eval
JeffIrwin Aug 30, 2024
b29c42f
cleanup, rename
JeffIrwin Aug 30, 2024
2c43af0
cleanup 1st order lhs dot expr assignment
JeffIrwin Aug 30, 2024
fcb0310
omfg. lhs nested dot exprs aren't so bad
JeffIrwin Aug 31, 2024
01855e6
add tests for lhs nested dot exprs
JeffIrwin Aug 31, 2024
7ea35b7
rhs dot expr subscripts
JeffIrwin Aug 31, 2024
9122de0
add tests. refactor
JeffIrwin Aug 31, 2024
177515d
add higher order struct array tests
JeffIrwin Aug 31, 2024
5192056
add dot string subscripts, planning to revert
JeffIrwin Aug 31, 2024
08b529c
Revert "add dot string subscripts, planning to revert"
JeffIrwin Aug 31, 2024
c2fa40c
wip, arrays of structs
JeffIrwin Aug 31, 2024
9898e6c
add str conversion for arrays of structs
JeffIrwin Aug 31, 2024
18bb085
pass types for arrays of structs and subscripting
JeffIrwin Sep 1, 2024
55bbade
cleanup logging
JeffIrwin Sep 1, 2024
37c05d9
add tests; refactor
JeffIrwin Sep 1, 2024
33352cb
add dotted subscript exprs like `a[0].b`
JeffIrwin Sep 1, 2024
aae1568
explicit arrays of structs
JeffIrwin Sep 1, 2024
653acc3
cleanup struct str conversion
JeffIrwin Sep 1, 2024
f1a5302
unify get_val() and get_array_value_t(). move tests
JeffIrwin Sep 1, 2024
0124182
rename get_array_value_t -> get_array_val, also setter
JeffIrwin Sep 1, 2024
2b333d3
chained dot exprs for arrays of structs
JeffIrwin Sep 1, 2024
2fdf4ad
chained dot sub exprs like `a[0].b[0]`
JeffIrwin Sep 1, 2024
904fa03
comments, cleanup
JeffIrwin Sep 1, 2024
28f7e8c
refactor conditional nesting
JeffIrwin Sep 1, 2024
0225f85
update setter for lhs. add a couple tests
JeffIrwin Sep 1, 2024
5de982f
add more tests
JeffIrwin Sep 1, 2024
647d024
fix bug for nested array of structs of array
JeffIrwin Sep 1, 2024
3cf7599
fix setter like last commit
JeffIrwin Sep 1, 2024
c7bf69d
add order-5 tests with various arrays interleaved
JeffIrwin Sep 2, 2024
264af3f
add a struct diagnostic. so it begins
JeffIrwin Sep 2, 2024
1c95f71
add more struct type checking diagnostics
JeffIrwin Sep 2, 2024
a174113
more diags
JeffIrwin Sep 2, 2024
a212433
add diags for unset and reset members
JeffIrwin Sep 2, 2024
7eebcb2
check struct and array subtypes for struct instances
JeffIrwin Sep 2, 2024
0154d01
dry up fn arg type checking
JeffIrwin Sep 2, 2024
d716025
check struct type; fix tests :pray:
JeffIrwin Sep 2, 2024
c9c9d34
check assignment and fn arg array of struct types
JeffIrwin Sep 4, 2024
e1606c1
cleanup
JeffIrwin Sep 4, 2024
46eb09f
ban struct/array slicing
JeffIrwin Sep 4, 2024
51832e4
cleanup
JeffIrwin Sep 5, 2024
be44080
Merge remote-tracking branch 'origin/main' into struct
JeffIrwin Sep 5, 2024
c6bd6ab
stuff
JeffIrwin Sep 6, 2024
9422b06
update version to 0.0.48
JeffIrwin Sep 6, 2024
4c43b68
Revert "update version to 0.0.48"
JeffIrwin Sep 6, 2024
b825a54
Merge remote-tracking branch 'origin/main' into struct
JeffIrwin Sep 6, 2024
d9c3707
Merge remote-tracking branch 'origin/main' into struct
JeffIrwin Sep 7, 2024
6e9e102
add build date to version output
JeffIrwin Sep 7, 2024
2630ced
fix array of structs bug and wicked state bug
JeffIrwin Sep 7, 2024
1175799
add test for array of structs bug from 2630ced9
JeffIrwin Sep 7, 2024
e35d545
add another pre-emptive one-time subscript eval
JeffIrwin Sep 7, 2024
7cc6692
prefer out-args for intel perf; catch errors
JeffIrwin Sep 7, 2024
475bcea
run lipo on mac bin to get info
JeffIrwin Sep 7, 2024
72f6359
check fn return structure sub type
JeffIrwin Sep 7, 2024
9acb712
Merge remote-tracking branch 'origin/main' into struct
JeffIrwin Sep 7, 2024
c6a0145
cleanup
JeffIrwin Sep 8, 2024
14e9b88
fix type bug for fns returning structs *lights cigarette*
JeffIrwin Sep 8, 2024
7769ea3
add test for bug from 14e9b88a
JeffIrwin Sep 8, 2024
b949090
add diagnostic for dots on things that aren't structs
JeffIrwin Sep 8, 2024
7b17eb0
Merge remote-tracking branch 'origin/main' into struct
JeffIrwin Sep 8, 2024
606b768
add tests for fns returning arrays of structs
JeffIrwin Sep 8, 2024
5fe5439
add diagnostic for bad member names in dot exprs
JeffIrwin Sep 8, 2024
012f140
add test for fn of high-order struct; stop cascades
JeffIrwin Sep 8, 2024
4bd6746
remove unnecessary syntax node vector from parse_struct_instance()
JeffIrwin Sep 8, 2024
2722730
comments
JeffIrwin Sep 8, 2024
ba14778
remove most of member_t. this feels risky
JeffIrwin Sep 8, 2024
f1e5c72
a type is a value! refactor fn param type handling
JeffIrwin Sep 8, 2024
c4811d0
get rid of whole member_t class
JeffIrwin Sep 8, 2024
b45cad0
remove copy
JeffIrwin Sep 8, 2024
8adea92
return rich type meta-data from parse_type()
JeffIrwin Sep 8, 2024
2e03f26
cleanup
JeffIrwin Sep 8, 2024
29b2797
rename
JeffIrwin Sep 8, 2024
15b9002
get rid of whole param_t class *lights another cigarette*
JeffIrwin Sep 8, 2024
f1dbf36
cleanup. structs are just about ready
JeffIrwin Sep 8, 2024
c3edb11
fix dot expr str indexing
JeffIrwin Sep 8, 2024
e5688fb
cleanup
JeffIrwin Sep 8, 2024
1474a34
more cleanup
JeffIrwin Sep 8, 2024
3221641
final cleanup?
JeffIrwin Sep 9, 2024
081e70a
comments
JeffIrwin Sep 10, 2024
044f674
Merge remote-tracking branch 'origin/main' into struct
JeffIrwin Sep 10, 2024
c847e7f
so there was something that i missed in that giant whitespace merge
JeffIrwin Sep 10, 2024
2a34f7b
fix uninitialized `kind`
JeffIrwin Sep 10, 2024
4cd3a72
revert test changes from 2a34f7b5. add 'recursive' because gfort comp…
JeffIrwin Sep 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,7 @@
##{"compiler": "intel", "version": "2022.2"}, # ifx 2022.2 doesn't have `do while ()` :(

{"compiler": "intel-classic", "version": "2021.10"},
{"compiler": "intel-classic", "version": "2021.1"},

##{"compiler": "nvidia-hpc", "version": "23.11"} # setup fails
#{"compiler": "intel-classic", "version": "2021.1"}, # complains about coarrays???
]
}
},
Expand Down Expand Up @@ -405,7 +403,7 @@
mv /opt/homebrew/bin /opt/homebrew/bin-BACKUP || true \n
mv /opt/homebrew/opt /opt/homebrew/opt-BACKUP || true \n
mv /opt/homebrew/Cellar /opt/homebrew/Cellar-BACKUP || true \n
ls /opt/homebrew/ \n
#ls /opt/homebrew/ \n

curl -LO \"https://github.com/JeffIrwin/syntran/releases/latest/download/syntran-macos.zip\" \n
unzip syntran-macos*.zip \n
Expand Down
28 changes: 14 additions & 14 deletions Dockerfile.ubuntu
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ RUN apt-get update -y
RUN apt-get install -y vim

## syntran crashes almost immediately with gfortran 13
ARG GFORT_VERS="12"
#ARG GFORT_VERS="13"
#ARG GFORT_VERS="12"
ARG GFORT_VERS="13"

#RUN apt-get install -y gfortran
RUN apt-get install -y gfortran-${GFORT_VERS}
Expand All @@ -33,15 +33,15 @@ RUN fpm --version

RUN yes | fpm clean
RUN fpm build --compiler gfortran-${GFORT_VERS}
RUN fpm test test --compiler gfortran-${GFORT_VERS}
#RUN fpm test long --compiler gfortran-${GFORT_VERS}

#ARG PROFILE release
ARG PROFILE debug

#RUN fpm build --compiler gfortran-${GFORT_VERS} --profile "$PROFILE" --link-flag "-static-libgcc -static-libgfortran -static-libquadmath"

RUN fpm build --compiler gfortran-${GFORT_VERS} --profile "$PROFILE" --link-flag "-static-libgcc -static-libgfortran -Wl,-Bstatic -lquadmath -Wl,-Bdynamic"

RUN find ./build -wholename "*app/syntran" | xargs ls -ltrh

#RUN fpm test test --compiler gfortran-${GFORT_VERS}
##RUN fpm test long --compiler gfortran-${GFORT_VERS}
#
##ARG PROFILE release
#ARG PROFILE debug
#
##RUN fpm build --compiler gfortran-${GFORT_VERS} --profile "$PROFILE" --link-flag "-static-libgcc -static-libgfortran -static-libquadmath"
#
#RUN fpm build --compiler gfortran-${GFORT_VERS} --profile "$PROFILE" --link-flag "-static-libgcc -static-libgfortran -Wl,-Bstatic -lquadmath -Wl,-Bdynamic"
#
#RUN find ./build -wholename "*app/syntran" | xargs ls -ltrh
#
33 changes: 3 additions & 30 deletions samples/array-fns.syntran
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@

let chain = true;
//chain = false;

fn mul_mat_vec(mat: [f32; :,:], vec: [f32; :]): [f32; :]
{
// Matrix-vector multiplication. Return mat * vec
Expand Down Expand Up @@ -72,14 +69,7 @@ println(mul_mat_vec(rotx, vec));

// Apply 180 degree x rotation

if chain
println(mul_mat_vec(mul_mat(rotx, rotx), vec));
else
{
let rotxx = mul_mat(rotx, rotx);
println(mul_mat_vec(rotxx, vec));
}

println(mul_mat_vec(mul_mat(rotx, rotx), vec));
println(mul_mat_vec(mul_mat(rotx, rotx), vec));

// [1.0, -2.0, -3.0]
Expand All @@ -89,31 +79,14 @@ println(mul_mat_vec(mul_mat(rotx, rotx), vec));
// to applying a 180 degree z rotation
println("calling 1");

// TODO: this is broken. It should work as a chain of fn calls (without temp
//// var rotxx) but there's a syntran bug, maybe re deep copy of value_t
////
if chain
println(mul_mat_vec(mul_mat(mul_mat(mul_mat(rotx, rotx), roty), roty), vec));
else
{
let rotxx = mul_mat(rotx, rotx);
let rotxxy = mul_mat(rotxx, roty);
println(mul_mat_vec(mul_mat(rotxxy, roty), vec));
}
println(mul_mat_vec(mul_mat(mul_mat(mul_mat(rotx, rotx), roty), roty), vec));

println("done 1");
// [-1.0, -2.0, 3.0]

println("calling 2");

if chain
println(mul_mat(mul_mat(mul_mat(rotx, rotx), roty), roty));
else
{
let rotxx = mul_mat(rotx, rotx);
let rotxxy = mul_mat(rotxx, roty);
println(mul_mat(rotxxy, roty));
}
println(mul_mat(mul_mat(mul_mat(rotx, rotx), roty), roty));

println("done 2");
// [
Expand Down
56 changes: 56 additions & 0 deletions samples/struct.syntran
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

struct Time
{
hh: i32,
mm: i32,
ss: f32, // trailing comma is optional
}

let t1 = Time{hh = 9, mm = 20, ss = 0.030,};
println("t1.hh = ", t1.hh);

let t2 = Time{hh = 13, mm = 37, ss = 0.069,};

fn print_time(t: Time)
{
// You can also do `println("t = ", t);` if you're ok with the default
// formatting
println("h = ", t.hh);
println("m = ", t.mm);
println("s = ", t.ss);
println();
return;
}

struct Date {
d: i32,
m: str,
y: i64
}

fn print_date(d: Date)
{
println("y = ", d.y);
println("m = ", d.m);
println("d = ", d.d);
println();
return;
}

let d1 = Date{y = i64(1900) + 12, m = "Apr", d = 14};
println("d1 =");
print_date(d1);

println("t1 =");
print_time(t1);

t2 = t1;
t2.hh = 11;
println("t2 = ", t2);

d1 = Date{y = i64(1900) + 45, m = "Ma" + "y", d = 5*4};
d1.m = "June";
println("d1 = ", d1);

return 0;

6 changes: 3 additions & 3 deletions src/compiler.F90
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ module syntran__compiler_m

#elif defined(__INTEL_COMPILER)

! Could be ifx or ifort
! Could be either ifx or ifort
character(len = *), parameter :: fort_compiler = "intel"
integer, parameter :: fort_vers(*) = [__INTEL_COMPILER]

#else

#error Neither __GFORTRAN__ nor __INTEL__ are defined. Please use a supported compiler and compile with pre-processing `-cpp` (gfortran) or `-fpp` (intel)

character(len = *), parameter :: fort_compiler = "unknown"
integer, parameter :: fort_vers(*) = []

#error Neither __GFORTRAN__ nor __INTEL__ are defined. Please use a supported compiler and compile with pre-processing `-cpp` (gfortran) or `-fpp` (intel)

#endif

! dev commit is replaced with the git hash by gen-header.sh
Expand Down
21 changes: 20 additions & 1 deletion src/consts.f90
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@ module syntran__consts_m
integer :: maxerr ! TODO: move this (not default) into a settings struct that gets passed around
integer, parameter :: maxerr_def = 4

! Must be larger than largest token enum below
! Must be larger than largest token enum below. TODO: add an init check for
! this
integer, parameter :: magic = 128

! Token and syntax node kinds enum. Is there a better way to do this that
! allows re-ordering enums? Currently it would break kind_name()
integer, parameter :: &
dot_expr = 98, &
struct_type = 97, &
struct_instance_expr = 96, &
struct_declaration = 95, &
struct_keyword = 94, &
dot_token = 93, &
return_statement = 92, &
return_keyword = 91, &
size_array = 90, &
Expand Down Expand Up @@ -213,6 +220,12 @@ function kind_token(kind)
"size_array ", & ! 90
"return ", & ! 91
"return statement ", & ! 92
". ", & ! 93
"struct ", & ! 94
"struct declaration ", & ! 95
"struct instance expr ", & ! 96
"struct type ", & ! 97
"dot expression ", & ! 98
"unknown " & ! inf
]

Expand Down Expand Up @@ -326,6 +339,12 @@ function kind_name(kind)
"size_array ", & ! 90
"return_keyword ", & ! 91
"return_statement ", & ! 92
"dot_token ", & ! 93
"struct_keyword ", & ! 94
"struct_declaration ", & ! 95
"struct_instance_expr", & ! 96
"struct_type ", & ! 97
"dot_expr ", & ! 98
"unknown " & ! inf (trailing comma hack)
]
! FIXME: update kind_tokens array too
Expand Down
Loading
Loading