Skip to content

Commit

Permalink
Use CallGraph.Function instead of function prefix to identify functions
Browse files Browse the repository at this point in the history
  • Loading branch information
cardillan committed Jan 28, 2024
1 parent c7176e3 commit 36efd1e
Show file tree
Hide file tree
Showing 80 changed files with 581 additions and 250 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

All notable changes to this project will be documented in this file.

## Unreleased

### Fixed

* Fixed wrong optimization of side effects in the `when` expressions
([#119](https://github.com/cardillan/mindcode/issues/119)).

### Miscellaneous

* Changed AstContext to store `CallGraph.Function` instances instead of a function prefix (`String`) to identify
functions. All other classes that handle functions now operate on functions themselves instead of the prefixes.
Avoids function lookups from local prefixes and increases type safety.

## 2024-01-22

### Added
Expand Down
33 changes: 18 additions & 15 deletions ROADMAP.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,13 @@ This documents servers as a scratch pad to track ideas and possible enhancements
* Allow empty bodies of ifs, loops, functions etc.
* Allow properties to be invoked on expressions. The nature of the call will be determined by the property name.
* Use mimex to obtain all metadata needed to recognize all valid properties.
* Unknown properties will be called via `sensor`.
* Unknown properties will be delegated to the `sensor` instruction.
* Allow empty optional arguments in function calls. At this moment, optional arguments can only be omitted at the
end of the argument list.
* Block comments to allow commenting/uncommenting blocks of code when battling a syntax error (better syntax
error reporting would be much more preferable, but quite hard to implement).
* Only allow dashes in REF identifiers (the `@` Mindustry constants), and only in the middle of the identifier. Then
add support for `++` and `--` operators.
* Ruby-like parallel assignments, e.g. `a, b, c = 1, 2, 3` or even `a, b = b, a`.
* Varargs inline functions (??)
* Function needs to be explicitly declared inline
* `inline def foo(a, b, c, x...) ... end`
* The vararg can be processed using list iteration loop, or maybe passed to another vararg function:
`def foo(arg...) for a in arg print(a) end end def bar(arg...) foo(arg) end`
* Block comments `/* this is a block comment that can span several lines */`.
* Only allow dashes in REF identifiers (e.g. `@battery-large`) and property names (e.g. `vault.blast-compound`), and
only in the middle of the identifier. Then add support for `++` and `--` operators. `a-b` will become an
expression equivalent to `a - b`.

## New and extended keywords

Expand All @@ -100,7 +94,7 @@ This documents servers as a scratch pad to track ideas and possible enhancements
* `array`
* Used in `allocate array`
* Reserved for future use in declaring in-memory arrays
* `declare`, `var` (?)
* `declare`, `var`: reserved for possible future use in declaring typed variables.
* `enum`
* Possible syntax:
* `enum name(id1, id2, id3)`
Expand All @@ -127,6 +121,15 @@ This documents servers as a scratch pad to track ideas and possible enhancements
isn't a variable.
* Used in when branch of case expression to set resulting value of the branch and exit the case expression.

# Additional syntax enhancements

* Ruby-like parallel assignments, e.g. `a, b, c = 1, 2, 3` or even `a, b = b, a`.
* Varargs inline functions (??)
* Function needs to be explicitly declared inline
* `inline def foo(a, b, c, x...) ... end`
* The vararg can be processed using list iteration loop, or maybe passed to another vararg function:
`def foo(arg...) for a in arg print(a) end end def bar(arg...) foo(arg) end`

## #use compiler directive/statement

```
Expand All @@ -147,6 +150,9 @@ Typed variables, parameters and function return values.
* This would allow better optimization and some special features, such as function pointers.
* Typed variables would have to be declared and could exist alongside untyped ones.
* Compiler directive could be created to require all variables to be declared and typed.
* Problems:
* Types of some expressions might not be possible to determine statically, e.g. the type of `block.sensor(property)`
value depends on the property being sensed.

## Records/structures

Expand Down Expand Up @@ -314,9 +320,6 @@ Two basic approaches
* Could help keeping track of global variables and memory blocks.
* Could be used to create more versions of a function, possibly inlining some of them, based on (dis)similarities
of variable states between visits (probably quite complex.)
* Expression distribution:
* `foo(value ? a : b)` could be turned into `if value foo(a) else foo(b) end`
* Is useful when at least one value produced by the ternary expression is a constant.
* Code path splitting
* If a variable is known to take on several distinct values and is part of several control statements or complex
expressions, create a jump table targeting specialized code for some or all of the values the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package info.teksol.mindcode.ast;

import info.teksol.mindcode.compiler.instructions.AstContextType;
import info.teksol.mindcode.compiler.generator.AstContextType;
import org.antlr.v4.runtime.Token;

import java.util.Objects;
Expand Down
4 changes: 2 additions & 2 deletions mindcode/src/main/java/info/teksol/mindcode/ast/AstNode.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package info.teksol.mindcode.ast;

import info.teksol.mindcode.compiler.instructions.AstContextType;
import info.teksol.mindcode.compiler.instructions.AstSubcontextType;
import info.teksol.mindcode.compiler.generator.AstContextType;
import info.teksol.mindcode.compiler.generator.AstSubcontextType;
import org.antlr.v4.runtime.Token;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package info.teksol.mindcode.ast;

import info.teksol.mindcode.compiler.instructions.AstContextType;
import info.teksol.mindcode.compiler.instructions.AstSubcontextType;
import info.teksol.mindcode.compiler.generator.AstContextType;
import info.teksol.mindcode.compiler.generator.AstSubcontextType;
import org.antlr.v4.runtime.Token;

import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package info.teksol.mindcode.ast;

import info.teksol.mindcode.compiler.instructions.AstContextType;
import info.teksol.mindcode.compiler.generator.AstContextType;
import org.antlr.v4.runtime.Token;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package info.teksol.mindcode.ast;

import info.teksol.mindcode.compiler.instructions.AstContextType;
import info.teksol.mindcode.compiler.generator.AstContextType;
import org.antlr.v4.runtime.Token;

import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package info.teksol.mindcode.ast;

import info.teksol.mindcode.compiler.instructions.AstContextType;
import info.teksol.mindcode.compiler.generator.AstContextType;
import org.antlr.v4.runtime.Token;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package info.teksol.mindcode.ast;

import info.teksol.mindcode.compiler.instructions.AstContextType;
import info.teksol.mindcode.compiler.generator.AstContextType;
import org.antlr.v4.runtime.Token;

import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package info.teksol.mindcode.ast;

import info.teksol.mindcode.compiler.instructions.AstContextType;
import info.teksol.mindcode.compiler.generator.AstContextType;
import org.antlr.v4.runtime.Token;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package info.teksol.mindcode.ast;

import info.teksol.mindcode.compiler.instructions.AstContextType;
import info.teksol.mindcode.compiler.generator.AstContextType;
import org.antlr.v4.runtime.Token;

import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package info.teksol.mindcode.ast;

import info.teksol.mindcode.compiler.instructions.AstContextType;
import info.teksol.mindcode.compiler.generator.AstContextType;
import org.antlr.v4.runtime.Token;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package info.teksol.mindcode.ast;

import info.teksol.mindcode.compiler.instructions.AstContextType;
import info.teksol.mindcode.compiler.generator.AstContextType;
import org.antlr.v4.runtime.Token;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package info.teksol.mindcode.ast;

import info.teksol.mindcode.compiler.instructions.AstContextType;
import info.teksol.mindcode.compiler.instructions.AstSubcontextType;
import info.teksol.mindcode.compiler.generator.AstContextType;
import info.teksol.mindcode.compiler.generator.AstSubcontextType;
import org.antlr.v4.runtime.Token;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package info.teksol.mindcode.ast;


import info.teksol.mindcode.compiler.instructions.AstContextType;
import info.teksol.mindcode.compiler.generator.AstContextType;
import org.antlr.v4.runtime.Token;

import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package info.teksol.mindcode.ast;


import info.teksol.mindcode.compiler.instructions.AstContextType;
import info.teksol.mindcode.compiler.generator.AstContextType;
import org.antlr.v4.runtime.Token;

import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package info.teksol.mindcode.ast;

import info.teksol.mindcode.compiler.instructions.AstContextType;
import info.teksol.mindcode.compiler.generator.AstContextType;
import org.antlr.v4.runtime.Token;

import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package info.teksol.mindcode.ast;

import info.teksol.mindcode.compiler.instructions.AstContextType;
import info.teksol.mindcode.compiler.generator.AstContextType;
import org.antlr.v4.runtime.Token;

import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package info.teksol.mindcode.ast;

import info.teksol.mindcode.compiler.instructions.AstContextType;
import info.teksol.mindcode.compiler.generator.AstContextType;
import org.antlr.v4.runtime.Token;

import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package info.teksol.mindcode.ast;

import info.teksol.mindcode.compiler.instructions.AstContextType;
import info.teksol.mindcode.compiler.generator.AstContextType;
import org.antlr.v4.runtime.Token;

import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package info.teksol.mindcode.ast;

import info.teksol.mindcode.compiler.instructions.AstContextType;
import info.teksol.mindcode.compiler.generator.AstContextType;
import info.teksol.mindcode.logic.LogicVariable;
import org.antlr.v4.runtime.Token;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package info.teksol.mindcode.ast;

import info.teksol.mindcode.compiler.instructions.AstContextType;
import info.teksol.mindcode.compiler.generator.AstContextType;
import org.antlr.v4.runtime.Token;

import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package info.teksol.mindcode.ast;

import info.teksol.mindcode.compiler.instructions.AstContextType;
import info.teksol.mindcode.compiler.generator.AstContextType;
import org.antlr.v4.runtime.Token;

import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package info.teksol.mindcode.compiler;

import info.teksol.mindcode.compiler.instructions.AstContext;
import info.teksol.mindcode.compiler.instructions.AstSubcontextType;
import info.teksol.mindcode.compiler.generator.AstContext;
import info.teksol.mindcode.compiler.generator.AstSubcontextType;
import info.teksol.mindcode.compiler.instructions.InstructionProcessor;
import info.teksol.mindcode.compiler.instructions.LogicInstruction;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import info.teksol.mindcode.MindcodeInternalError;
import info.teksol.mindcode.compiler.CompilerMessage;
import info.teksol.mindcode.compiler.MindcodeMessage;
import info.teksol.mindcode.compiler.instructions.AstContext;
import info.teksol.mindcode.compiler.generator.AstContext;
import info.teksol.mindcode.compiler.instructions.InstructionProcessor;
import info.teksol.mindcode.compiler.instructions.LogicInstruction;
import info.teksol.mindcode.logic.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package info.teksol.mindcode.compiler.functions;

import info.teksol.mindcode.compiler.CompilerMessage;
import info.teksol.mindcode.compiler.instructions.AstContext;
import info.teksol.mindcode.compiler.generator.AstContext;
import info.teksol.mindcode.compiler.instructions.InstructionProcessor;

import java.util.function.Consumer;
Expand Down
Loading

0 comments on commit 36efd1e

Please sign in to comment.