Skip to content

Commit 2610b7d

Browse files
authored
Parse Basilisp code into an intermediate AST (#325)
* Use explicit AST * Constant values * Use constant map for const node type dispatch * Def form * Many more things * Host calls * Emit specialized :host-call and :host-field nodes in :host-interop handler * Fix MyPy errors * Symbol table * Function parsing * Generate code from the parsed Lisp AST * Compiling constants! * Simple interop * Statementize unused exprs * If expressions * Rudimentary def and var symbol generators * Non-quoted collections * Fix type checks * Explicitly typed nodes using attrs * Convert Generator to using Node types * Clean up * Ordering matters * Handle top_level kwarg for nodes * Node visitor * Cleanup * List literals * Invoke handler * Throw AST * Generic host interop * Try AST * set! special form * Clean up code generation for set! * Add TODO * Cleanup * Remove usage of functional.seq * Remove functional.seq from runtime * Remove functional.seq * Loop parsing * Let bindings and locals * Use attrs for POJO * Loops * Cleanup * Recursively parse macros * Mostly new CompilerException, except a lil recur handler * Recur for loop * Catch errors during macroexpansion and report them as such * Slight doc changes * Simplify SymbolTable classes * Cleanup * Import special form * Single arity functions; also, using the symbol table * Fix some mutable defaults 😬 * Assert recur in function method appears in tail * Fix formatting that got borked * Generate multi-arity function * Function arities * Formatting * Remove incorrect comment * Fix interop ref * Clean up * Getting closer! * Fix the typing * Load names correctly * Stop printing AST * Generate proper code for (var sym) calls * Combine Generator & Parser contexts for public interface * Handle interop props * Correct interop form * Formatting * Allow unqualified references to builtins * Prevent recurs in loop* binding inits * Fix interop call * Fix another interop test * Don't choke on regex literals * Format code goodly * Throw a proper exception for '.' chars in symbol names * Correctly bind the catch exception name * Fix unquote test * Import names & name resolution * Use generated, munged names for recursive function calls * Fix more tests * Insert variadic arity into dispatch map * Formatting * Special case empty lists * Check fixed arities for variadic arguments are not lower than any other fixed arities * Compiler meta * Tiny fixes tiny fixes * Catch exception in Python compilation * Add super basic optimizer to remove no-op expression statements * Missing runtime thing * Fixing tests 💪 * Catch Python compilation exceptions * Most tests are working now * Rename compyler to compiler cuz its getting real * Fix MyPy errors * Remove unused code * Address a host of linting errors * Clarify symbol resolution * Address linting errors * Include line/column info in Python AST * Clean up def meta * Allow recur in nested function defs * Hopefully correctly attach location information * Also formatting * Satisfy linter & mypy * Generate special code for defn style defs * Clean up Coverage files and ignore .envrc * Make tests not fail plz * Make the linter less mad at me * Try building on PyPy * Once more with gusto * Plz * Spell better * Fix missing locations on node environments * Freeze! * Make PyPy builds stop erroring out * Set runtime TypeError for nth to TRACE since it's typically not a bug * Fix compiler tests (for CPython at least) * Fix linting error * Stop sourcing macroexpansion exc * Remove unused trace function * Fix linting and other exception sourcing * Fix some things * Supplement a bunch of tests * Spice up some tests * Interop tests * Fix lint and type errors * Disable Coverage checks for no-op lines * Ooops * Clean up pointless coverage misses * More tests * moar tests * Recur tests * More tests * No cover * Coverage * Omit __version__.py (maybe?) * Maybe? * Fine * Set! tests * More tests 4 coverage * More symbol resolution tests * Remove unused interop code * Remove duplicative bootstrapping code from CLI * Remove unused HostInterop form * Remove unnecessary try/except from _clean_meta in Generator * Verify imports resolve from within do block * Coverage magic * Speed up everything by apparently a lot * Formatting * Remove unused parser tests * Remove dead code in the optimizer * Docstrings * Clean up optimizer code
1 parent c939446 commit 2610b7d

File tree

15 files changed

+6279
-3496
lines changed

15 files changed

+6279
-3496
lines changed

src/basilisp/core/__init__.lpy

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,7 +1131,7 @@
11311131
(defmacro apply-method
11321132
"Apply arguments to a method call. Equivalent to (apply (.-method o) args)."
11331133
[o method & args]
1134-
`(apply (.- ~o ~method) ~@args))
1134+
`(apply (. ~o ~(symbol (str "-" method))) ~@args))
11351135

11361136
(defmacro comment
11371137
"Ignore all the forms passed, returning nil."
@@ -1218,7 +1218,7 @@
12181218
val (second bindings)]
12191219
`(try
12201220
(do
1221-
(. (var ~vvar) ~'push-bindings ~val)
1221+
(. (var ~vvar) (~'push-bindings ~val))
12221222
~@(if (nthnext bindings 2)
12231223
[(concat
12241224
(list 'binding (vec (nthrest bindings 2)))
@@ -1755,7 +1755,7 @@
17551755
{:value v}))))
17561756
(recur (rest requires))))]
17571757
(do-require args)
1758-
(set! '*ns* current-ns)
1758+
(set! *ns* current-ns)
17591759
nil))
17601760

17611761
(defmacro ns
@@ -1881,7 +1881,7 @@
18811881
(defmacro defmethod
18821882
"Add a new method to the multi-function which responds to dispatch-val."
18831883
[multifn dispatch-val & fn-tail]
1884-
`(. ~multifn ~'add-method ~dispatch-val (fn ~@fn-tail)))
1884+
`(. ~multifn (~'add-method ~dispatch-val (fn ~@fn-tail))))
18851885

18861886
(defn methods
18871887
"Return a map of dispatch values to methods for the given multi function."
@@ -2215,10 +2215,9 @@
22152215
(defmacro ^:no-warn-on-redef let
22162216
"Let bindings with destructuring support."
22172217
[bindings & body]
2218-
(let [bindings (->> (partition 2 bindings)
2219-
(mapcat destructure))]
2220-
`(let* [~@bindings]
2221-
~@body)))
2218+
`(let* [~@(->> (partition 2 bindings)
2219+
(mapcat destructure))]
2220+
~@body))
22222221

22232222
(defn ^:private loop-with-destructuring
22242223
"Take a loop definition (an binding vector and 0 or more body

src/basilisp/importer.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,10 @@ def _exec_cached_module(
194194
fullname, path_stats["mtime"], path_stats["size"], cache_data
195195
)
196196
compiler.compile_bytecode(
197-
cached_code, compiler.CompilerContext(filename=filename), module
197+
cached_code,
198+
compiler.GeneratorContext(filename=filename),
199+
compiler.PythonASTOptimizer(),
200+
module,
198201
)
199202

200203
def _exec_module(

0 commit comments

Comments
 (0)