Skip to content

Commit

Permalink
stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiayang committed Dec 1, 2020
1 parent 12de5ae commit 6425002
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 34 deletions.
6 changes: 3 additions & 3 deletions build/tests/basic.flx
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ public fn doBasicTest()
var c: any = 30
println("c.typeid = %, c.refcount = %", c.id, c.refcount)

enum E
enum E: u32
{
case ONE
case TWO
case ONE = 100
case TWO = 200
}

var e = E::TWO
Expand Down
5 changes: 5 additions & 0 deletions build/tmp2/b.flx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
// Copyright (c) 2020, zhiayang
// Licensed under the Apache License Version 2.0.

<<<<<<< Updated upstream
public import c as _

public fn bazzle() -> int => 30
=======
public let INIT_TIMER: u32 = 0x00000001
public let INIT_AUDIO: u32 = 0x00000010
>>>>>>> Stashed changes
3 changes: 3 additions & 0 deletions build/tmp2/c.flx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright (c) 2020, zhiayang
// Licensed under the Apache License Version 2.0.

<<<<<<< Updated upstream
export c

ffi fn printf(fmt: &i8, ...) -> int
Expand All @@ -10,3 +11,5 @@ public fn foozle(x: int)
{
printf("hello, world! (%d)\n", x)
}
=======
>>>>>>> Stashed changes
69 changes: 39 additions & 30 deletions notes.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,56 @@
## notes

each scope already exists as a StateTree, so, whenever a public definition is encountered, it is added to the
`exports` list of its tree.
## to fix

when importing another module:
1. if the module is imported `as _`, add the module's StateTree to the current (toplevel) scope's `imports` list
2. if the module is imported `as foo::bar`, add the module's StateTree to the `imports` list of `foo::bar` (creating if needed)
1. `public static` doesn't work, but `static public` works.

3. do a (complete) tree traversal "in-step" with the current scope, to check for duplicate (incompatbile) definitions.
- big oof, but if we want the current module "paradigm" to work, this has to be done.
2. underlining breaks for multi-line spans; just don't underline in that case.

(done) when resolving a definition:
1. follow the same resolution order (deepest-to-widest)
2. after checking each level, additionally check the list of imports.
3. of course, we should not traverse "down" into the imported tree -- only look at its top-level defs
- we need to be going up, not down!
4. for each imported tree, we should only check definitions that are in its `exports` list
3. types don't appear before functions for some reason, for typechecking. (ie. order becomes important)

to refactor using:
we should simply treat it as a scope-level import, ie. for `using foo::bar as qux`, we just create a new scope
`qux`, then attach `foo::bar` to `qux` by appending to its `imports` list. here, we should check that `qux` does
not already exist.
(this is different for imports, where two imported modules are able merge their exported namespaces. for `using`,
i'm not too sure that's a good idea, but it's easy enough to change if needed)
4. enum values are not working correctly (seems to be right-shifted by 8?)
(the values are not assigned)

for `using foo::bar as _`, we do the same thing as `import as _`, and just attach the tree of `foo::bar` to
the imports list of the current scope.
5. defer appears to be broken:
```
var i = 0
while true {
defer i += 1
// doesn't change
}
```

6. "unsynchronised use of global init function!!!" -- need to figure out a way to serialise access to the global init function

## to fix
7. polymorphic stuff breaks when manually instantiating

1. `public static` doesn't work, but `static public` works.
8. compiler crash:
```
import libc as _
2. underlining breaks for multi-line spans; just don't underline in that case.
struct Cat<T> {
fn greet() {
printf("i love manga uwu\n")
}
}
@entry fn main() {
let c: Cat!<Integer> = Cat()
## to refactor
c.greet();
}
```

2. a lot of places probably still have the concept of `scope == std::vector<std::string>`.
- after the first scope refactor, i think these instances will be reduced
- undoubtedly there will be more. for instance, Identifier holds the scope as exactly that.
(but, is there actually a need for it to be anything else? it really is just an identifier, after all)
9. ambiguous call to initialiser of class

10. assignment to runtime variable in #run block

11. numbers basically don't cast properly at all



## to refactor

3. all uses of defer() need to be audited. there are instances where an exception is thrown during typechecking
as a result of unwrapping a `TCResult` that contains an error; as the stack unwinds, it may encounter a
Expand All @@ -68,5 +77,5 @@ the imports list of the current scope.

## to investigate

1. we rely on a lot of places to set `realScope` (and `enclosingScope`) correctly when typechecking structs etc. there should
1. we rely on a lot of places to set `enclosingScope` correctly when typechecking structs etc. there should
be a better way to do this, probably automatically or something like that. basically anything except error-prone manual setting.
2 changes: 2 additions & 0 deletions source/frontend/parser/function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ namespace parser
bool startedOptional = false;
while(st.front() != TT::RParen)
{
st.skipWS();

if(iscvar || isfvar)
error(st, "variadic parameter list must be the last function parameter");

Expand Down
6 changes: 5 additions & 1 deletion source/frontend/parser/type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,11 @@ namespace parser
if(st.frontAfterWS() == TT::Equal)
{
if(memberType == 0)
error(st.loc(), "enumeration member type must be specified when assigning explicit values to cases");
{
SimpleError::make(st.loc(), "enumeration member type must be specified when assigning explicit values to cases")
->append(SimpleError::make(MsgType::Note, idloc, "add the type here"))
->postAndQuit();
}

// ok, parse a value
st.eat();
Expand Down

0 comments on commit 6425002

Please sign in to comment.