New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
crystal i #10910
Closed
Closed
crystal i #10910
Changes from 250 commits
Commits
Show all changes
524 commits
Select commit
Hold shift + click to select a range
25e7baa
Bool for NilableReferenceUnionType
asterite f499df4
More cast
asterite fd60bcb
More intrinsics
asterite ec28e33
More float32/float64 primitives
asterite 68fe983
atomicrmw
asterite b503484
More LibM
asterite fbd564d
Better pry next
asterite 7220d0f
Fix pry finish
asterite f367407
Define interpreter primitives directly in Crystal :tada:
asterite 30729b4
Stricter cast checks to avoid surprises
asterite e63c47f
No need to override Crystal::Scheduler.reschedule
asterite db21117
external_var_set
asterite eb35bf7
Captured blocks
asterite 25217e5
C callbacks almost working!
asterite 603950a
C callbacks! Kind of...
asterite 6763631
Don't lose GC reference to closure context
asterite 5383f58
A bit more casts
asterite cb53caf
Symbol autocasting
asterite 7c2760c
Fix missing "self" in pry
asterite 9c17908
Allow accessing block argument in pry
asterite 6558cfa
More casts and to bool
asterite a905a78
Pry: pad line numbers if needed
asterite d8a8e37
Use relative filenames in pry if possible
asterite 27ada4d
Link interpreters for pry
asterite b19557a
General Cast
asterite deb548a
Upcast between tuple types
asterite dbf57f5
Extract unpack tuple
asterite 0db02ae
More casts
asterite 356f90b
More casts
asterite f571db5
More cast
asterite 35ef748
Fix multidispatch for virtual types
asterite f08fb34
A bit more cast
asterite e2b269f
Correct way to do consts
asterite 0f0061a
More constants
asterite 623a8a9
Those nasty structs that are passed as pointers...
asterite be53264
A bit more struct pointer
asterite c23d65b
Do `@wants_struct_pointer` for Pointer#value
asterite 5baf25a
Do class vars well
asterite e1f5532
Refactor and interoduce compile_pointerof_class_var
asterite da1ad38
More correct call arguments, upcasting, autocasting
asterite 2f0a99e
Cast yield expression to block var type, not block arg type
asterite d956564
Fix C callbacks argument order
asterite c705c5c
A bit more raise if wants struct pointer
asterite 10a39e0
Fix pointer in union to bool
asterite 404de3e
Make Intrinsics.debugtrap a macro
asterite c225542
Let `leave` have a location so that pry stops in it
asterite 5611bca
Migration local variable types in the repl!
asterite a4f733e
Fix tuple indexer struct pointer
asterite 1f6c8f7
ARGV!
asterite 96eb855
Simplify semantic in repl
asterite cfa2a8f
Interpret prelude too
asterite 8dc1d33
Run full semantic on everything on repl!
asterite 37f72a7
Add readline
asterite f3e3edd
Highlight "raise" and "loop"
asterite 28fda5f
pointerof read instance var
asterite 0fbf915
wants_struct_pointer for ReadInstanceVar
asterite 12b2f62
spawn!
asterite c39d78d
No need to allocate an extra stack in interpreted mode
asterite e183c35
Sync pry between all known interpreters
asterite cfa7abe
Interpret read instance var with struct type
asterite 50b0e65
ReadInstanceVar with wants_struct_pointer
asterite cffcb8c
Inline methods that just return an instance var
asterite 64cf261
Fill out space with zeros (Time.local broke)
asterite bbe90dd
Missing normalize, and adding newline after readline
asterite cf8218d
Merge remote-tracking branch 'origin/master' into repl
asterite 1f13913
Use Readline for pry
asterite 25856b0
Include more info when llvm_typer fails
asterite b0cc148
Use correct owner for super
asterite 0ae3da5
Fix and simplify local variables migration
asterite 960c44c
Fix a couple of UInt64 instructions
asterite d4971b5
Merge branch 'master' into repl
asterite 6b698f0
Bugfix: accept call args of inlined method that reads instance var
asterite bdcb64b
Skip file if in interpreted mode
asterite d43eeaa
I don't know why this doesn't compile in aarch
asterite 960137f
Document repl/c.cr
asterite 9f6afb5
Don't define pause intrinsic if it doesn't exist
asterite 60b5253
Comment message about remainig opcodes
asterite d382fc9
Correct definitions of memcpy, memmove and memset for multiple platforms
asterite d1e13dd
Document a bit repl/cast.cr
asterite e188d69
Remove some unneeded comparison instructions
asterite 8aa4481
Fix pause
asterite 02477e6
Hardcode align parameter to zero
asterite 4ae06ad
Simplify and document repl/class_vars.cr
asterite 2469222
Simplify and document repl/constants.cr
asterite 302bedc
Move FFI inside the Crystal namespace
asterite 29b5173
Move Readline under the Crystal namespace
asterite 5a02939
No need to pass MainVisitor to interpret
asterite 0bfc440
Update src/compiler/crystal/semantic/semantic_visitor.cr
asterite de6ba1c
Some more comments
asterite 2a3d380
Merge branch 'repl' of github.com:asterite/crystal-1 into repl
asterite 6a66cd7
More comments, specs, and removal of dead code
asterite a4252be
Don't use `interpter(...)` overload for repl inspect
asterite dd2b12c
Simplify the interpreter by not making it do semantic analysis
asterite cdeaf8d
Move FFI closure context logic out of interpreter and into context
asterite 2c431f5
More docs and comments
asterite f641b09
Move trace and decompile to compile-time checks
asterite 414e4d0
Remove unused commented code
asterite e804e23
Merge branch 'master' into repl
asterite 31b169a
Simplify interpreter specs
asterite 465b234
Add integration specs
asterite ab0cb44
Start interpreting closures
asterite 56a4e09
Access closure inside block
asterite 143ee8b
Closure context inside def
asterite 3259b5a
Allow closuring def arguments
asterite 57fff82
Closures inside procs
asterite b1c6b95
Add spec to make sure proc args can be closured
asterite 610f63c
Concurrency fixes to avoid unintended closured vars
asterite 8ac92f8
Interpret cmpxchg
asterite bb48cd4
Refactor reading and writing from closured vars
asterite 4e479f8
Extract closure context logic
asterite add5e53
Make closures work in FileNode
asterite 2ee16c0
Merge branch 'master' into repl
asterite c343509
Correctly carry FileModule information inside block
asterite abdb6ec
Don't change var context for FileNode
asterite cb69ef7
Add missing closure file
asterite 359ca58
Assign with wants_struct_pointer
asterite faba943
Closures inside constants
asterite 6619b63
Extract declare_local_vars
asterite 312d581
Closures inside class var initializers
asterite 64add15
An easy cast
asterite 4958563
Interpter lib calls other than LibC and those in the compiler's binary
asterite 2be4743
Cast in struct_or_union_set
asterite e1f9a0d
A couple more small casts
asterite 35cdb87
Closures inside blocks
asterite e08c999
Closure block args
asterite ef08a82
Parent closures inside proc literals
asterite 9a1fe19
Parent closure inside block
asterite b872923
Some docs for ClosureContext
asterite 0563f34
Merge branch 'master' into repl
asterite 816ad9c
Upcast exception handler body to node type
asterite 4b1e9de
Refactor to prepare for exceptions
asterite 0e396a8
Start interpreting exception handling
asterite 263491c
Make sure ensure is executed on raised exception in body or rescue
asterite ad3b4c1
Backtraces!
asterite b60b6c8
Carry call stack in pry
asterite e975fdd
Handle exceptions in spawn
asterite b472579
More intrinsics and libm
asterite 6bcc90b
Extern unions
asterite 8ec30af
A small cast
asterite e390736
Add YAML integration spec
asterite f2d5c11
Add JSON integration spec
asterite 194c8ce
class_crystal_instance_type_id
asterite c336097
Make XML work
asterite 7d9fef8
Make YAML::Serializable work
asterite f05ae1c
Handle a few more def return types
asterite 4aed133
Added a couple more integration specs because why not
asterite 9dd116f
Interpret `responds_to?`
asterite 24c51e8
Closure self (still missing instance vars)
asterite 2a88970
Pointerof closured local var
asterite dce47c3
Closure instance vars
asterite 5273980
Fix broken IsA
asterite af00f90
is_a? for nilable proc type
asterite ca6fa1a
self in some places
asterite 534eb86
Consider nil in upcast in if
asterite a0d9725
Call method on struct over a closured var
asterite 430994d
Named arguments are gone after the semantic pass
asterite eb9209a
Interpret magic constants (file = __FILE__ in method arg)
asterite 6dcc672
Interpret special vars ($?, $~)
asterite b80142a
Show exception handlers in disassembly
asterite 6a3ab45
Run at_exit handlers on interpreter exit
asterite 11d1c38
Introduce Interpreter.interpret to reduce some code duplication
asterite 4229135
Interpret Float32 division
asterite 82e41ec
A few more casts
asterite 5221cf7
Better disassembly for calls
asterite dacf202
Cleaner trace output
asterite e11bcc4
Pass self according to target def owner, not scope
asterite 66a0a9a
Interpret TypeNode
asterite 81bb6c4
Fix block break in nested block
asterite 17821f9
Set extern struct Proc field
asterite 61334a0
Use a stack pool instead of reusing a stack (fixes bug)
asterite 9bb3851
Reuse stacks in a few more places
asterite 95c68ce
Better disassmble for get_local and set_local
asterite fec9c26
Don't pass self FileModule
asterite ef7e32c
Upcast from MetaclassType to VirtualMetaclassType
asterite 1202e54
Fix incorrect closure detected
asterite ccfbd82
Simplify instructions
asterite 9b2a7f5
Fix pointer_diff reversed
asterite 49759d8
Implement arithemtic overflow
asterite b6b3918
Simplify conversion instructions
asterite c88e177
Interpret `with ... yield`
asterite 7dda64b
Special vars multidispatch
asterite 277e51f
Float div when int is involved
asterite 86a307c
Cach FFI::CallInterface to avoid it being lost by GC
asterite ee1ce66
A few more casts
asterite afcf612
Inline call that returns self
asterite df60f7b
Pass all arguments to `crystal i` runner
asterite 85d3a8f
Greatly simplify how to obtain a pointer to any AST node exp
asterite a41cde3
Clean up
asterite 30a9236
Fix and was doing or
asterite 99fee82
Interpret `.class` for virtual types
asterite 2835d07
Cast nil to Void*
asterite 5df902e
Some string literals fixes
asterite d2de86a
Undefine vars when existing block
asterite f99d67a
Fix cast nilable type to mixed union
asterite ab71240
Fix leading/trailing zeros count
asterite f00b4c9
Fix Float32 op Float64
asterite c7ec6df
Handle fdiv
asterite 050ddb8
Splats in yield
asterite 5650488
Block with splat
asterite 1b71d37
Compiler: fix is_a? for virtual metaclass types
asterite c528cf8
Some fixes for metaclasses and virtual metaclasses
asterite 4112923
Implement fdiv for different float types
asterite 86f7a65
FFI bool
asterite 50b636b
Use string pool for all strings
asterite 3c149cb
Move crystal_raise_overflow cached call to Context
asterite e9bf336
Raise when `as(...)` fails
asterite 4066dac
Correctly pass static array to C function
asterite 9918018
Don't mix local vars with closured vars
asterite a45ae36
Remove unused `backup` method
asterite 46a7143
Syntax highlight repl values
asterite 81c3158
Remove additions to the compiler that aren't really necessary for the…
asterite 1d235d9
Remove extra `always_falsey?`
asterite a1aceb6
Remove primitive handling that's not needed anymore
asterite 008423c
Undo things that aren't needed for the repl
asterite 1638679
Filter reference union type
asterite 571eee3
Merge remote-tracking branch 'origin/master' into repl
asterite 0b2e348
Merge branch 'master' into repl
asterite aaabfb4
Don't use LLVMId for type id
asterite 79e1801
to_bool for float
asterite 2dacdaa
Fix exception handling indexes
asterite a493d4d
Inline `ensure` when `return` is done
asterite fd5bf66
Fix stack pool implementation
asterite 0578825
to_bool for enum types
asterite e923091
Rename compile_pointerof_struct_to_be_passed_as_self to
asterite a75405c
Remove debug comments
asterite 150d2d2
Merge branch 'master' into repl
asterite 52ccbd4
Don't store last exception in interpreter
asterite 1eebf27
Let `return` inside block execute ensure
asterite 9b0547a
Execute ensure when breaking from block
asterite 01ce648
Optimize returning value
asterite 2235b26
Handle closured block arg
asterite 098921e
Sometimes there's nothing to clear before entering a block
asterite 24fd05e
to_bool for reference union type
asterite f94e6b4
Merge branch 'master' into repl
asterite 3181ebe
Cast to filtered type, not type in `as(...)`
asterite 55d09a6
Tuple metaclass indexer
asterite 060cc79
Don't change ip on overflow
asterite 7af6c4b
Fix `.class` for virtual types
asterite cf62f6f
Allow viewing the stack, and shorten pry commands
asterite 8e3556b
Better local vars dump
asterite b696dfe
Merge branch 'master' into repl
asterite 9154f21
Correctly pass self as pointer in multidispatch
asterite 1180c1d
Pass self pointer of closured instance var
asterite f0a6a90
Ingore visibility checks in repl multidispatch
asterite 373f656
Check block body NoReturn
asterite dc971dd
Use correct scope for inlined instance var
asterite 8ad91a1
Correctly pass arguments with nil type to C functions
asterite 0253c75
Don't pass STDOUT to `inspect_with_backtrace`
asterite 81deb85
Interpret `out _`
asterite 5d9b915
Make it work for linux (thanks @straight-shoota !)
asterite File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Implementation of the `crystal repl` command | ||
|
||
class Crystal::Command | ||
private def repl | ||
decompile = false | ||
trace = false | ||
stats = false | ||
|
||
OptionParser.parse(options) do |opts| | ||
opts.banner = "Usage: crystal repl [options] [files]\n\nOptions:" | ||
|
||
opts.on("-d", "--decompile", "Show decompilation") do | ||
decompile = true | ||
end | ||
|
||
opts.on("-s", "--status", "Show time taken to execute") do | ||
stats = true | ||
end | ||
|
||
opts.on("-t", "--trace", "Trace execution") do | ||
trace = true | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are all experimental! Also I think the options there should match the options of the usual crystal compiled, being able to pass |
||
|
||
opts.on("-h", "--help", "Show this message") do | ||
puts opts | ||
exit | ||
end | ||
end | ||
|
||
repl = Repl.new( | ||
decompile: decompile, | ||
decompile_defs: false, | ||
trace: trace, | ||
stats: stats, | ||
) | ||
|
||
if options.empty? | ||
repl.run | ||
else | ||
filename = options.shift | ||
unless File.file?(filename) | ||
error "File '#{filename}' doesn't exist" | ||
end | ||
|
||
repl.run_file(filename, options) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
require "../types" | ||
require "./value" | ||
require "./repl" | ||
|
||
module Crystal | ||
class Type | ||
def ffi_type | ||
raise "BUG: missing ffi_type for #{self} (#{self.class})" | ||
end | ||
end | ||
|
||
class IntegerType | ||
def ffi_type | ||
case kind | ||
when :i8 then FFI::Type.sint8 | ||
when :u8 then FFI::Type.uint8 | ||
when :i16 then FFI::Type.sint16 | ||
when :u16 then FFI::Type.uint16 | ||
when :i32 then FFI::Type.sint32 | ||
when :u32 then FFI::Type.uint32 | ||
when :i64 then FFI::Type.sint64 | ||
when :u64 then FFI::Type.uint64 | ||
when :f32 then FFI::Type.float | ||
when :f64 then FFI::Type.double | ||
else | ||
raise "BUG: missing ffi_type for #{self} (#{self.class})" | ||
end | ||
end | ||
end | ||
|
||
class FloatType | ||
def ffi_type | ||
case kind | ||
when :f32 then FFI::Type.float | ||
when :f64 then FFI::Type.double | ||
else | ||
raise "BUG: missing ffi_type for #{self} (#{self.class})" | ||
end | ||
end | ||
end | ||
|
||
class EnumType | ||
def ffi_type | ||
base_type.ffi_type | ||
end | ||
end | ||
|
||
class PointerInstanceType | ||
def ffi_type | ||
FFI::Type.pointer | ||
end | ||
end | ||
|
||
class ProcInstanceType | ||
def ffi_type | ||
FFI::Type.pointer | ||
end | ||
|
||
def ffi_call_interface | ||
FFI::CallInterface.new( | ||
abi: FFI::ABI::DEFAULT, | ||
args: arg_types.map(&.ffi_type), | ||
return_type: return_type.ffi_type, | ||
) | ||
end | ||
end | ||
|
||
class NilType | ||
def ffi_type | ||
# Nil is used to pass a null pointer | ||
FFI::Type.pointer | ||
end | ||
end | ||
|
||
class NoReturnType | ||
def ffi_type | ||
FFI::Type.void | ||
end | ||
end | ||
|
||
class TypeDefType | ||
def ffi_type | ||
typedef.ffi_type | ||
end | ||
end | ||
|
||
class NonGenericClassType | ||
def ffi_type | ||
FFI::Type.struct(all_instance_vars.map do |name, var| | ||
var.type.ffi_type | ||
end) | ||
end | ||
end | ||
|
||
class StaticArrayInstanceType | ||
def ffi_type | ||
element_ffi_type = element_type.ffi_type | ||
FFI::Type.struct( | ||
Array.new(size.as(NumberLiteral).value.to_i, element_ffi_type) | ||
) | ||
end | ||
end | ||
end | ||
|
||
struct Crystal::Repl::Value | ||
def ffi_value(pointer : Pointer(Void)) : Nil | ||
pointer.as(Void**).value = @pointer | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idea: don't use this LLVMId type at all for the repl. Instead, store the types and ids in
Repl::Context
.