AdeptLanguage / Adept

The Adept Programming Language
GNU General Public License v3.0
121 stars 9 forks source link

Big problem with new experimental syntax (`:` problems, polymorphs can't be declared). #34

Closed ghost closed 3 years ago

ghost commented 3 years ago

@IsaacShelton I have changed this syntax to be used as default and I detected that you made : work not only for declaring variables. I mean that if make : default, then you should use : every time you type data type:

num : int = 0
printf(num as : int) // must be num as int

If not, it won't compile (if it will be default syntax)

P.S. I think this happens because you added : to the parse_type() and now every time you want to write type you should write : before it.

Also after this syntax, I can't correctly write this string (I do not know where I should put :):

struct <$T> PolymorphicStructName (field1 $T, field2 <$T> AnotherType)

This not works:

<$T> PolymorphicStructName :: struct(field1 : $T, field2 : <$T> AnotherType)
IsaacShelton commented 3 years ago

@t0md3an

  1. The first example works fine for me,

pragma enable_experimental_colon_before_type_syntax import basics

func main { num : int = 0 print(num as : int) print(num as int) }

0 0

If you changed the source code of Adept to make it the default, you don't want to remove the conditional check in `parse_type`.

Instead, go to `compiler_init` in `DRVR/compiler.c` and add `compiler->traits |= COMPILER_TYPE_COLON;` at the end of the function.

2. Polymorphic types can still be declared, they just use this slightly different syntax:

PolymorphicStructName :: struct <$T> (field1 : $T, field2 : <$T> AnotherType)

ghost commented 3 years ago

@IsaacShelton I changed the else block to print error if something wrong and now:

main.adept:1:44: Expected type
  1| poly :: struct <$T> (field1 : $T, field2 : <$T> int)
                                                ^

I have changed this:

if(ctx->compiler->traits & COMPILER_TYPE_COLON && id == TOKEN_COLON){
    // Skip over colon for experimental ": int" syntax
    start = ++(*i);
    id = tokens[start].id;
}

to this:

if(ctx->compiler->traits & COMPILER_TYPE_COLON && id == TOKEN_COLON){
    // Skip over colon for experimental ": int" syntax
    start = ++(*i);
    id = tokens[start].id;
} else {
    compiler_panicf(ctx->compiler, ctx->tokenlist->sources[*ctx->i - 1], "Expected type");
    return FAILURE;
}
IsaacShelton commented 3 years ago

@t0md3an If you are trying to make it so : is required, but not for things like as, it would require restructuring large portions of the code base. I'm busy working on vanilla Adept, so for more-complicated issues like this that don't pertain to mainline, I'm not going to be able to help you, because I've got other things that are higher priority.

If you want to make your own custom flavor of Adept, I would recommend either:

main(argc: int, argv: *ubyte) : int :: func { / ... */ }



If you do it this way, I can guarantee support and bug fixes for it. Otherwise, there may be bugs in your flavor of Adept that don't exist in vanilla, and I won't be able to help with those.

If you absolutely insist on modifying large portions of the compiler, just be prepared for bugs/issues. Again, I have other things that are higher priority, so I won't be able to help you debug your flavor of Adept if you decide to go down this route.