Closed ghost closed 3 years ago
@t0md3an
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)
@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;
}
@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:
compiler_init()
compiler->entry_point = "entry";
compiler->traits |= COMPILER_COLON_COLON | COMPILER_TYPE_COLON;
or
2.4/my_flavor.adept
and put
pragma enable_experimental_colon_colon_syntax
pragma enable_experimental_colon_before_type_syntax
in it, and just import it in your main file.
import my_flavor
import basics
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.
@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:If not, it won't compile (if it will be default syntax)
P.S. I think this happens because you added
:
to theparse_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
:
):This not works: