This commit builds on the emit-c feature by permitting C typed values to
be used anywhere in Carp code.
For example, if one wants to use the literal C macro `EDOM`:
```clojure
(register EDOM C "EDOM")
(Int.+ 1 EDOM)
=> 34
```
when compiled, this will produce the call:
```c
Int__PLUS(1, EDOM)
```
So it provides a quite flexible means of using C macros directly. It is,
of course, also radically unsafe. Anyone registering and using values of
the C type better be cautious.
One can get pretty crazy with this feature:
```clojure
(register comment-it C "// commented out;")
(Int.+ 1 comment-it)
=> int _11 = Int__PLUS_(1, // commented out;)
int* _12 = &_11; // ref
String _13 = IntRef_str(_12);
```
This commit fixes issue #1302, whereby types defined in modules were not
recognized as valid member types by our validation routines.
We simply need to account for types defined in modules in the global
env, threading the global env along through validation (previously we
only passed the top-level type env, which contains no modules).
A call to sequence in our handling of polymorphics would result in
discarding legitimate interface implementation results in rare cases.
Calling rights instead fixes the issue. We also need to take the union
of the results to ensure we account for cases such as polymorphically
realized interfaces (e.g. the `prn` function for a (Maybe String), other
wise, we don't resolve to concrete polymorphics for types that have
ad hoc polymorphic members.
Fixes#1307
* feat: Add additional ignore macros
This commit adds two new ignore macros, ignore*, which wraps an
arbitrary number of forms in calls to `ignore` and ignore-do, which
wraps an arbitrary number of forms in ignore, then bundles the whole in
a do call, effectively executing each form only for side effects and
ignoring all results.
* docs: Update ignore* docs
Link to `ignore` doc
Co-authored-by: Veit Heller <veit@veitheller.de>
* fix: Call ignore* in ignore-do
ignore-all was an old name that no longer exists!
* test: Add test for ignore-do
Co-authored-by: Veit Heller <veit@veitheller.de>
* refactor: refactor concretize module
This commit primarily refactors the concretize module, breaking out the
local definitions for visit functions into top level functions that are
hopefully easier to change. I've also modified some monadic code in the
interest of terseness.
This commit adds some additional patterns for XObj forms as well.
* refactor: Only export called functions in Concretize
Adds an export list to Concretize so that the module encapsulates those
functions that are only used internally within the module.
* refactor: better names in concretize functions
Clarify the names of variables in visitor type functions.
* refactor: ensure findType returns a type
Adds an additional check to findType that ensures the retrieved binder
is in fact a type and not another object. This is necessary for certain
contexts like type concretization since modules may also be designated
by symbols that refer to types.
* fix: ensure nested polymorphic types are emitted
This commit fixes an issue whereby nested polymorphic types would not be
emitted by the compiler, even though their member functions were
emitted.
In order to support this, we need to update a couple of functions to
take the global environment (to find nested types, which live in
modules) in addition to the top level type environment. Additionally, we
had to update scoring to account for nested names.
fixes#1293
* test: add tests for nested polymorphic types
Adds regression tests to ensure nested polymorphic types are concretized
and emitted correctly.
* refactor: refactor concretize module
This commit primarily refactors the concretize module, breaking out the
local definitions for visit functions into top level functions that are
hopefully easier to change. I've also modified some monadic code in the
interest of terseness.
This commit adds some additional patterns for XObj forms as well.
* refactor: Only export called functions in Concretize
Adds an export list to Concretize so that the module encapsulates those
functions that are only used internally within the module.
* refactor: better names in concretize functions
Clarify the names of variables in visitor type functions.
Previously, there was an edge case whereby types that depended on other
types that were not scored yet and functions that in turn depended on
these types could be assigned the same score. When this happened, we'd
sometimes incorrectly emit functions before the struct types they
depended on.
Since functions are always at the bottom of a type hierarchy (they
always depend on their members), there's a simple fix: we just add 1 to
ensure functions are emitted after type declarations in all possible
cases.
* 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>