Module: Kapusta::Compiler
- Defined in:
- lib/kapusta/compiler.rb,
lib/kapusta/compiler/emitter.rb,
lib/kapusta/compiler/normalizer.rb,
lib/kapusta/compiler/macro_expander.rb,
lib/kapusta/compiler/emitter/interop.rb,
lib/kapusta/compiler/emitter/support.rb,
lib/kapusta/compiler/emitter/bindings.rb,
lib/kapusta/compiler/emitter/patterns.rb,
lib/kapusta/compiler/emitter/collections.rb,
lib/kapusta/compiler/emitter/expressions.rb,
lib/kapusta/compiler/emitter/control_flow.rb
Defined Under Namespace
Modules: EmitterModules
Classes: Emitter, Error, MacroExpander, Normalizer
Constant Summary
collapse
- SPECIAL_FORMS =
%w[
fn lambda λ let local var global set if when unless case match
while for each do values
-> ->> -?> -?>> doto
icollect collect fcollect accumulate faccumulate
hashfn
. ?. :
..
length
require
module class
try catch finally
raise
ivar cvar gvar
ruby
tset pcall xpcall
and or not
= not= < <= > >=
+ - * / %
print
macro macros import-macros
quasi-sym quasi-list quasi-list-tail quasi-vec quasi-vec-tail quasi-hash quasi-gensym
].freeze
Class Method Summary
collapse
Class Method Details
.compile(source, path: '(kapusta)') ⇒ Object
35
36
37
38
39
40
41
|
# File 'lib/kapusta/compiler.rb', line 35
def self.compile(source, path: '(kapusta)')
forms = Reader.read_all(source)
expanded = MacroExpander.new(path:).expand_all(forms)
compile_forms(expanded, path:)
rescue Kapusta::Error => e
raise e.with_defaults(path:)
end
|
.run(source, path: '(kapusta)') ⇒ Object
50
51
52
53
|
# File 'lib/kapusta/compiler.rb', line 50
def self.run(source, path: '(kapusta)')
ruby = compile(source, path:)
TOPLEVEL_BINDING.eval(ruby, path, 1)
end
|
.run_file(path) ⇒ Object
55
56
57
|
# File 'lib/kapusta/compiler.rb', line 55
def self.run_file(path)
run(File.read(path), path:)
end
|