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

First implementation of imports in Candice. #2

Merged
merged 10 commits into from
Jan 31, 2022
Merged

Conversation

gabivlj
Copy link
Owner

@gabivlj gabivlj commented Jan 31, 2022

What is this about

This is a basic implementation of import and """"generics"""" on Candice.

Changes

  • Now functions, structs, even identifiers, have a unique name, the basic formulae is: $(originalName) + "-" + parserInstanceId. This means that we can have multiple declarations of the same function name in multiple files without worrying of overlaps. Mentioned functionality does not work with extern functions, if you redeclare an extern function it will probably fail, even with multiple files.
  • We can pass type parameters to files, this means we can implement generic data structures.

Examples

// toImport.cd
type T


struct Something {
    integer T
}


func outsideFunction(s *Something) {
    s.integer = s.integer + @cast(T, 1);
}

func something() Something {
    @println("hello world!");
    s := @Something {integer:@cast(T, 0)}
    outsideFunction(&s)
    return s
}
// toExecute.cd
import someModule, i64, "./toImport.cd";
import someModulei32, i32, "./toImport.cd";

func something() someModule.Something {
    return @someModule.Something { integer: @cast(i64, 3) };
}

func main() {
    somethingVariable : someModule.Something = someModule.something();
    somethingVariableI32 : someModulei32.Something = someModulei32.something();    
    localSomethingFunction : someModule.Something = something()
    @println(somethingVariableI32.integer + @cast(i32, somethingVariable.integer) + @cast(i32, localSomethingFunction.integer));    
}

To execute this file use: ./compiler toExecute.cd

@gabivlj gabivlj merged commit 13b19d2 into main Jan 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant