* feat: add machine-info primitive draft
* feat: rename machine-info to structured-info
* fix: use the right primitive name in structured-info error
* refactor: remove unnecessary code
* refactor: Tiny cleanup before we begin
* refactor: Moved module finding to its own local function
* feat: save-docs-internal is now a binary command
* feat: This seems to work
* fix: Cleaned up the code, save-docs now emit one module per file listed
* feat!: implemented Pattern.match which returns start and end indizes of the first match
* fix: Pattern.match now returns correct end index
* feat: moved Pattern.match-str and Pattern.find from C to Carp code
* chore: fix build after merges
* chore: fix build after merges
* feat: moved Pattern.find-all from C to Carp code
* feat: Pattern.global-match-str no longer relies on Pattern.global-match
* docs: updated for Pattern.global-match
* fix: moved str/prn functions into sub module
* fix: removed unused functions from carp_pattern.h (using cflow)
* feat!: renamed (Pattern.global-match) to (Pattern.match-all-groups)
* fix: unit test
* fix: some functions renamed to match Carp style
Co-authored-by: guberatsie <gunnar.bernhardt@siemens.com>
* feat: generalized (and) and (or) to handle any number of parameters
* feat!: removed (and*) and (or*) macros
* chore: worked around compiler issue for unit test
* fix: unit test in ./test/macro.carp
Co-authored-by: guberatsie <gunnar.bernhardt@siemens.com>
* refactor: Mid-refactor save point.
* feat: Code compiles
* refactor: Remove unused imports
* refactor: Move functions out of massive `manageMemory` block
* refactor: Move out even more functions from `manageMemory`
* refactor: Made most patterns match on "head form" of each s-expression
e.g. (if a b c) matches on 'if', 'a', 'b' and 'c'
* refactor: Use the pattern synonyms in Memory
* refactor: Remove a little cruft
* refactor: whenOK function
* refactor: Use 'whenRight' functions to avoid directly matching on Either
* docs: Comment the 'getConcretizedPath' function
* refactor: Move functionFinding-functions into Polymorphism module
* feat!: implemented String.ascii-to-lower and String.ascii-to-upper
* fix: corrected docstrings
* fix: added unit test for ascii-to-lower and ascii-to-upper
* fix: moved tolower- and toupper from String to Byte module
Co-authored-by: guberatsie <gunnar.bernhardt@siemens.com>
* fix: render submodules in html docs
* fix: also render deeply nested modules
* feat: no prefixes in nested submodule doc rendering
* fix: fix text alignment of module index for sdl
* feat: make submodules expandable
The previous pattern matching changes introduced a subtle error in the
evaluator's handling of function applications, we used the same Resolver
for both lists and symbols, where previously we hadn't. Restoring the
old resolution selection and adding a new clause to capture forms like
((defn f [] 2)) restores the correct functioning in the repl.
Importantly, forms such as ((defn foo [x] x) 3), should only be resolved
when the defn form is the result of expanding a symbol.
Eventually, resolving defns to anonymous functions might simplify this
case.
Fixes#1237
* docs: implemented python script to convert local documentation from .md files to .html files
* docs: filled index.md; reviewed all references in .md files
* docs: updated Embedded.md and resized carp_on_arduboy.jpg to sensible width
* docs: copy sub folders (./docs/core and ./docs/sdl) to ./docs-html/ and refer docu to it
* docs: phrased requirements more clearly
* docs: generate docs for Standard libraries before converting .md docs to .html
* docs: change index to markdown lists
* docs: index.md worked around limitation in md converter
* docs: removed modules count from Libraries.md
Co-authored-by: guberatsie <gunnar.bernhardt@siemens.com>
* chore: Abuse deftemplate to get rid of Address
* chore: Avoid semicolon at end of define
* fix: address should be useable as an argument to a HOF
* chore: adapt examples to new address signature
* fix: Remove Address from typeOf
* fix: Remove more uses of Address
* fix: Remove more mentions of address in the Haskell code
* fix: Remove test that ensure you can't take the address of non-symbols
* refactor: Moved `address` to Pointer.carp
* refactor: Move address into Pointer module
Co-authored-by: Jorge Acereda <jacereda@gmail.com>
* chore: Re-format Haskell code
* fix: Unify aupdate and aupdate! with other update functions
* fix: Re-add comment
* fix: Also make StaticArray.aupdate! adhere to the normal update signature
* fix: Failing test
* test: Test for error when recursing using wrong nr of args
* test: Wrong type when recursing
* test: Defining function with def
* test: Using special symbol as binder
* test: Dynamic closures can refer to itself
* test: Avoid unification failure
* fix: Address feedback
This fix is a close cousin of the one that allowed let bindings to
shadow global commands. We now allow function arguments to shadow
commands as well by using a local lookup preference for argument names,
making functions such as:
```
(defndynamic foo [car]
(Symbol.prefix car 'foo)
```
work as anticipated. I've also removed unused code from `apply`.
Fixes#1057
* fix: don't expand inner module macros on first pass; privacy
This commit changes the behavior of expansions to avoid expanding module
expressions until we're actually processing the module in question.
Previously, the following form would be entirely expanded at the time of evaluating A:
```clojure
(defmodule A <- current environment
(some-macro) <- expand
(defmodule B
(some-macro f) <- expand, current env is A, *NOT* B.
so if this expands to
(private f)
(defn f ....)
the f of the expansion is added to *A*, and we have a duplicate
ghost binder.
)
(defn foo [] B.f) <- expand, B.f does not exist yet, any meta on the
binding will be ignored, permitting privacy errors since expansion
ignores undefined bindings, instead, we'll look this up at eval time,
and not check privacy as doing so would cause problems for legitimate
cases.
)
```
This meant that if the macro happened to have side-effects, e.g. calling
`meta-set!` we'd produce side-effects in the wrong environment, A,
resulting in duplicate bindings, missing bindings at evaluation time,
and other problems.
Now, we instead process the form as follows:
```clojure
(defmodule A <- current environment
(some-macro) <- expand
(defmodule B
(some-macro f) <- wait
)
(defn foo [] B.f)
)
;; step 2
(defmodule A
(foo-bar ) <- previously expanded macro
(defmodule B <- current environment
(some-macro f) <- expand
)
....
)
```
In general, this prevents the generation of a bunch of unintentional and
incorrectly added bindings when calling `meta-set!` from various macros.
Additionally, privacy constraints are now carried across nested modules:
```
(defmodule A
(defmodule B
(private f)
(defn f [] 0)
)
(defn g [] (B.f)) ;; Privacy error!
)
```
This change also fixed an issue whereby recursive functions with `sig`
annotations could trick the compiler. Again, this had to do with the
unintentionally added bindings stemming from expansion of nested module
expressions via meta-set.
Fixes#1213, Fixes#467
* fix: ensure we check privacy against the path of found binders
* fix: don't shadow local bindings with dynamics
This commit adds a new lookup preference to the evaluator, LookupLocal,
and uses it to lookup bindings in the scope of let forms. This fixes an
issue whereby our original bias toward dynamic bindings would prevent
users from shadowing dynamic bindings with local bindings of the same
name. Before the following code returned `command c`:
```
(defdynamic test-val (let [c (car (list 1 2 3))]
c))
```
It now returns `1`.
I also fixed a small issue with top-level (as in, without a
corresponding function environment) let forms (they'd cause a crash for
lack of an environment parent).
Fixes#659
* refactor: only prefer local lookups for shadows
The prior commit introduced a local lookup preference into the evaluator
in order allow for shadowing of global names in local scopes (like let
bindings). However, this introduced prohibitive performance costs,
especially for dynamic functions.
To mitigate this, we only perform local-biased lookups for a set of
known-shadows. Since we know the names of local bindings at form
evaluation time, we can restrict our local lookup bias to these paths
only. This greatly reduces the performance penalties initially incurred
by the change.
I've also refactored some of the lookup code for clarity.
* fix: support recursive let bindings
Previously, the bodies of anonymous functions bound to a let name did
not have access to their names, making recursion such as:
```
(let [f (fn [x] (if (= x 1) x (f (dec x))))] (f 10))
```
impossible. We now equip evaluation of let bindings with an additional
recursion environment making this possible. The example above will now
resolve to `1`.
Fixes#1133