Skip to content
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
wants to merge 524 commits into from
Closed
Show file tree
Hide file tree
Changes from 250 commits
Commits
Show all changes
524 commits
Select commit Hold shift + click to select a range
25e7baa
Bool for NilableReferenceUnionType
asterite Jun 13, 2021
f499df4
More cast
asterite Jun 13, 2021
fd60bcb
More intrinsics
asterite Jun 13, 2021
ec28e33
More float32/float64 primitives
asterite Jun 14, 2021
68fe983
atomicrmw
asterite Jun 14, 2021
b503484
More LibM
asterite Jun 14, 2021
fbd564d
Better pry next
asterite Jun 14, 2021
7220d0f
Fix pry finish
asterite Jun 14, 2021
f367407
Define interpreter primitives directly in Crystal :tada:
asterite Jun 14, 2021
30729b4
Stricter cast checks to avoid surprises
asterite Jun 15, 2021
e63c47f
No need to override Crystal::Scheduler.reschedule
asterite Jun 15, 2021
db21117
external_var_set
asterite Jun 15, 2021
eb35bf7
Captured blocks
asterite Jun 15, 2021
25217e5
C callbacks almost working!
asterite Jun 16, 2021
603950a
C callbacks! Kind of...
asterite Jun 16, 2021
6763631
Don't lose GC reference to closure context
asterite Jun 16, 2021
5383f58
A bit more casts
asterite Jun 16, 2021
cb53caf
Symbol autocasting
asterite Jun 16, 2021
7c2760c
Fix missing "self" in pry
asterite Jun 16, 2021
9c17908
Allow accessing block argument in pry
asterite Jun 16, 2021
6558cfa
More casts and to bool
asterite Jun 16, 2021
a905a78
Pry: pad line numbers if needed
asterite Jun 16, 2021
d8a8e37
Use relative filenames in pry if possible
asterite Jun 16, 2021
27ada4d
Link interpreters for pry
asterite Jun 16, 2021
b19557a
General Cast
asterite Jun 18, 2021
deb548a
Upcast between tuple types
asterite Jun 19, 2021
dbf57f5
Extract unpack tuple
asterite Jun 19, 2021
0db02ae
More casts
asterite Jun 19, 2021
356f90b
More casts
asterite Jun 19, 2021
f571db5
More cast
asterite Jun 19, 2021
35ef748
Fix multidispatch for virtual types
asterite Jun 19, 2021
f08fb34
A bit more cast
asterite Jun 20, 2021
e2b269f
Correct way to do consts
asterite Jun 20, 2021
0f0061a
More constants
asterite Jun 20, 2021
623a8a9
Those nasty structs that are passed as pointers...
asterite Jun 21, 2021
be53264
A bit more struct pointer
asterite Jun 21, 2021
c23d65b
Do `@wants_struct_pointer` for Pointer#value
asterite Jun 21, 2021
5baf25a
Do class vars well
asterite Jun 21, 2021
e1f5532
Refactor and interoduce compile_pointerof_class_var
asterite Jun 21, 2021
da1ad38
More correct call arguments, upcasting, autocasting
asterite Jun 21, 2021
2f0a99e
Cast yield expression to block var type, not block arg type
asterite Jun 22, 2021
d956564
Fix C callbacks argument order
asterite Jun 22, 2021
c705c5c
A bit more raise if wants struct pointer
asterite Jun 22, 2021
10a39e0
Fix pointer in union to bool
asterite Jun 22, 2021
404de3e
Make Intrinsics.debugtrap a macro
asterite Jun 23, 2021
c225542
Let `leave` have a location so that pry stops in it
asterite Jun 23, 2021
5611bca
Migration local variable types in the repl!
asterite Jun 23, 2021
a4f733e
Fix tuple indexer struct pointer
asterite Jun 23, 2021
1f6c8f7
ARGV!
asterite Jun 23, 2021
96eb855
Simplify semantic in repl
asterite Jun 24, 2021
cfa2a8f
Interpret prelude too
asterite Jun 24, 2021
8dc1d33
Run full semantic on everything on repl!
asterite Jun 24, 2021
37f72a7
Add readline
asterite Jun 24, 2021
f3e3edd
Highlight "raise" and "loop"
asterite Jun 26, 2021
28fda5f
pointerof read instance var
asterite Jun 27, 2021
0fbf915
wants_struct_pointer for ReadInstanceVar
asterite Jun 27, 2021
12b2f62
spawn!
asterite Jun 27, 2021
c39d78d
No need to allocate an extra stack in interpreted mode
asterite Jun 27, 2021
e183c35
Sync pry between all known interpreters
asterite Jun 27, 2021
cfa7abe
Interpret read instance var with struct type
asterite Jun 29, 2021
50b0e65
ReadInstanceVar with wants_struct_pointer
asterite Jun 29, 2021
cffcb8c
Inline methods that just return an instance var
asterite Jun 29, 2021
64cf261
Fill out space with zeros (Time.local broke)
asterite Jun 29, 2021
bbe90dd
Missing normalize, and adding newline after readline
asterite Jun 29, 2021
cf8218d
Merge remote-tracking branch 'origin/master' into repl
asterite Jun 30, 2021
1f13913
Use Readline for pry
asterite Jun 30, 2021
25856b0
Include more info when llvm_typer fails
asterite Jul 2, 2021
b0cc148
Use correct owner for super
asterite Jul 2, 2021
0ae3da5
Fix and simplify local variables migration
asterite Jul 2, 2021
960c44c
Fix a couple of UInt64 instructions
asterite Jul 3, 2021
d4971b5
Merge branch 'master' into repl
asterite Jul 8, 2021
6b698f0
Bugfix: accept call args of inlined method that reads instance var
asterite Jul 9, 2021
bdcb64b
Skip file if in interpreted mode
asterite Jul 9, 2021
d43eeaa
I don't know why this doesn't compile in aarch
asterite Jul 9, 2021
960137f
Document repl/c.cr
asterite Jul 9, 2021
9f6afb5
Don't define pause intrinsic if it doesn't exist
asterite Jul 9, 2021
60b5253
Comment message about remainig opcodes
asterite Jul 9, 2021
d382fc9
Correct definitions of memcpy, memmove and memset for multiple platforms
asterite Jul 9, 2021
d1e13dd
Document a bit repl/cast.cr
asterite Jul 9, 2021
e188d69
Remove some unneeded comparison instructions
asterite Jul 9, 2021
8aa4481
Fix pause
asterite Jul 9, 2021
02477e6
Hardcode align parameter to zero
asterite Jul 9, 2021
4ae06ad
Simplify and document repl/class_vars.cr
asterite Jul 9, 2021
2469222
Simplify and document repl/constants.cr
asterite Jul 9, 2021
302bedc
Move FFI inside the Crystal namespace
asterite Jul 9, 2021
29b5173
Move Readline under the Crystal namespace
asterite Jul 9, 2021
5a02939
No need to pass MainVisitor to interpret
asterite Jul 9, 2021
0bfc440
Update src/compiler/crystal/semantic/semantic_visitor.cr
asterite Jul 10, 2021
de6ba1c
Some more comments
asterite Jul 13, 2021
2a3d380
Merge branch 'repl' of github.com:asterite/crystal-1 into repl
asterite Jul 13, 2021
6a66cd7
More comments, specs, and removal of dead code
asterite Jul 13, 2021
a4252be
Don't use `interpter(...)` overload for repl inspect
asterite Jul 13, 2021
dd2b12c
Simplify the interpreter by not making it do semantic analysis
asterite Jul 13, 2021
cdeaf8d
Move FFI closure context logic out of interpreter and into context
asterite Jul 14, 2021
2c431f5
More docs and comments
asterite Jul 14, 2021
f641b09
Move trace and decompile to compile-time checks
asterite Jul 14, 2021
414e4d0
Remove unused commented code
asterite Jul 15, 2021
e804e23
Merge branch 'master' into repl
asterite Jul 24, 2021
31b169a
Simplify interpreter specs
asterite Jul 26, 2021
465b234
Add integration specs
asterite Jul 26, 2021
ab0cb44
Start interpreting closures
asterite Jul 27, 2021
56a4e09
Access closure inside block
asterite Jul 27, 2021
143ee8b
Closure context inside def
asterite Jul 27, 2021
3259b5a
Allow closuring def arguments
asterite Jul 28, 2021
57fff82
Closures inside procs
asterite Jul 28, 2021
b1c6b95
Add spec to make sure proc args can be closured
asterite Jul 28, 2021
610f63c
Concurrency fixes to avoid unintended closured vars
asterite Jul 28, 2021
8ac92f8
Interpret cmpxchg
asterite Jul 28, 2021
bb48cd4
Refactor reading and writing from closured vars
asterite Jul 28, 2021
4e479f8
Extract closure context logic
asterite Jul 28, 2021
add5e53
Make closures work in FileNode
asterite Jul 28, 2021
2ee16c0
Merge branch 'master' into repl
asterite Jul 28, 2021
c343509
Correctly carry FileModule information inside block
asterite Jul 29, 2021
abdb6ec
Don't change var context for FileNode
asterite Jul 29, 2021
cb69ef7
Add missing closure file
asterite Jul 29, 2021
359ca58
Assign with wants_struct_pointer
asterite Jul 29, 2021
faba943
Closures inside constants
asterite Jul 29, 2021
6619b63
Extract declare_local_vars
asterite Jul 29, 2021
312d581
Closures inside class var initializers
asterite Jul 29, 2021
64add15
An easy cast
asterite Jul 29, 2021
4958563
Interpter lib calls other than LibC and those in the compiler's binary
asterite Jul 30, 2021
2be4743
Cast in struct_or_union_set
asterite Jul 30, 2021
e1f9a0d
A couple more small casts
asterite Jul 30, 2021
35cdb87
Closures inside blocks
asterite Aug 2, 2021
e08c999
Closure block args
asterite Aug 2, 2021
ef08a82
Parent closures inside proc literals
asterite Aug 2, 2021
9a1fe19
Parent closure inside block
asterite Aug 2, 2021
b872923
Some docs for ClosureContext
asterite Aug 2, 2021
0563f34
Merge branch 'master' into repl
asterite Aug 2, 2021
816ad9c
Upcast exception handler body to node type
asterite Aug 3, 2021
4b1e9de
Refactor to prepare for exceptions
asterite Aug 3, 2021
0e396a8
Start interpreting exception handling
asterite Aug 4, 2021
263491c
Make sure ensure is executed on raised exception in body or rescue
asterite Aug 4, 2021
ad3b4c1
Backtraces!
asterite Aug 5, 2021
b60b6c8
Carry call stack in pry
asterite Aug 5, 2021
e975fdd
Handle exceptions in spawn
asterite Aug 5, 2021
b472579
More intrinsics and libm
asterite Aug 6, 2021
6bcc90b
Extern unions
asterite Aug 7, 2021
8ec30af
A small cast
asterite Aug 7, 2021
e390736
Add YAML integration spec
asterite Aug 7, 2021
f2d5c11
Add JSON integration spec
asterite Aug 7, 2021
194c8ce
class_crystal_instance_type_id
asterite Aug 8, 2021
c336097
Make XML work
asterite Aug 8, 2021
7d9fef8
Make YAML::Serializable work
asterite Aug 8, 2021
f05ae1c
Handle a few more def return types
asterite Aug 8, 2021
4aed133
Added a couple more integration specs because why not
asterite Aug 8, 2021
9dd116f
Interpret `responds_to?`
asterite Aug 9, 2021
24c51e8
Closure self (still missing instance vars)
asterite Aug 9, 2021
2a88970
Pointerof closured local var
asterite Aug 9, 2021
dce47c3
Closure instance vars
asterite Aug 9, 2021
5273980
Fix broken IsA
asterite Aug 9, 2021
af00f90
is_a? for nilable proc type
asterite Aug 9, 2021
ca6fa1a
self in some places
asterite Aug 11, 2021
534eb86
Consider nil in upcast in if
asterite Aug 11, 2021
a0d9725
Call method on struct over a closured var
asterite Aug 11, 2021
430994d
Named arguments are gone after the semantic pass
asterite Aug 12, 2021
eb9209a
Interpret magic constants (file = __FILE__ in method arg)
asterite Aug 12, 2021
6dcc672
Interpret special vars ($?, $~)
asterite Aug 13, 2021
b80142a
Show exception handlers in disassembly
asterite Aug 13, 2021
6a3ab45
Run at_exit handlers on interpreter exit
asterite Aug 13, 2021
11d1c38
Introduce Interpreter.interpret to reduce some code duplication
asterite Aug 13, 2021
4229135
Interpret Float32 division
asterite Aug 13, 2021
82e41ec
A few more casts
asterite Aug 13, 2021
5221cf7
Better disassembly for calls
asterite Aug 14, 2021
dacf202
Cleaner trace output
asterite Aug 14, 2021
e11bcc4
Pass self according to target def owner, not scope
asterite Aug 14, 2021
66a0a9a
Interpret TypeNode
asterite Aug 14, 2021
81bb6c4
Fix block break in nested block
asterite Aug 14, 2021
17821f9
Set extern struct Proc field
asterite Aug 15, 2021
61334a0
Use a stack pool instead of reusing a stack (fixes bug)
asterite Aug 16, 2021
9bb3851
Reuse stacks in a few more places
asterite Aug 16, 2021
95c68ce
Better disassmble for get_local and set_local
asterite Aug 16, 2021
fec9c26
Don't pass self FileModule
asterite Aug 16, 2021
ef7e32c
Upcast from MetaclassType to VirtualMetaclassType
asterite Aug 16, 2021
1202e54
Fix incorrect closure detected
asterite Aug 16, 2021
ccfbd82
Simplify instructions
asterite Aug 16, 2021
9b2a7f5
Fix pointer_diff reversed
asterite Aug 18, 2021
49759d8
Implement arithemtic overflow
asterite Aug 18, 2021
b6b3918
Simplify conversion instructions
asterite Aug 18, 2021
c88e177
Interpret `with ... yield`
asterite Aug 18, 2021
7dda64b
Special vars multidispatch
asterite Aug 18, 2021
277e51f
Float div when int is involved
asterite Aug 19, 2021
86a307c
Cach FFI::CallInterface to avoid it being lost by GC
asterite Aug 19, 2021
ee1ce66
A few more casts
asterite Aug 19, 2021
afcf612
Inline call that returns self
asterite Aug 20, 2021
df60f7b
Pass all arguments to `crystal i` runner
asterite Aug 20, 2021
85d3a8f
Greatly simplify how to obtain a pointer to any AST node exp
asterite Aug 21, 2021
a41cde3
Clean up
asterite Aug 21, 2021
30a9236
Fix and was doing or
asterite Aug 21, 2021
99fee82
Interpret `.class` for virtual types
asterite Aug 21, 2021
2835d07
Cast nil to Void*
asterite Aug 21, 2021
5df902e
Some string literals fixes
asterite Aug 22, 2021
d2de86a
Undefine vars when existing block
asterite Aug 22, 2021
f99d67a
Fix cast nilable type to mixed union
asterite Aug 22, 2021
ab71240
Fix leading/trailing zeros count
asterite Aug 22, 2021
f00b4c9
Fix Float32 op Float64
asterite Aug 22, 2021
c7ec6df
Handle fdiv
asterite Aug 22, 2021
050ddb8
Splats in yield
asterite Aug 22, 2021
5650488
Block with splat
asterite Aug 22, 2021
1b71d37
Compiler: fix is_a? for virtual metaclass types
asterite Aug 23, 2021
c528cf8
Some fixes for metaclasses and virtual metaclasses
asterite Aug 23, 2021
4112923
Implement fdiv for different float types
asterite Aug 23, 2021
86f7a65
FFI bool
asterite Aug 23, 2021
50b636b
Use string pool for all strings
asterite Aug 24, 2021
3c149cb
Move crystal_raise_overflow cached call to Context
asterite Aug 24, 2021
e9bf336
Raise when `as(...)` fails
asterite Aug 24, 2021
4066dac
Correctly pass static array to C function
asterite Aug 24, 2021
9918018
Don't mix local vars with closured vars
asterite Aug 26, 2021
a45ae36
Remove unused `backup` method
asterite Aug 26, 2021
46a7143
Syntax highlight repl values
asterite Aug 26, 2021
81c3158
Remove additions to the compiler that aren't really necessary for the…
asterite Aug 27, 2021
1d235d9
Remove extra `always_falsey?`
asterite Aug 27, 2021
a1aceb6
Remove primitive handling that's not needed anymore
asterite Aug 27, 2021
008423c
Undo things that aren't needed for the repl
asterite Aug 27, 2021
1638679
Filter reference union type
asterite Aug 27, 2021
571eee3
Merge remote-tracking branch 'origin/master' into repl
asterite Aug 27, 2021
0b2e348
Merge branch 'master' into repl
asterite Aug 27, 2021
aaabfb4
Don't use LLVMId for type id
asterite Aug 27, 2021
79e1801
to_bool for float
asterite Aug 27, 2021
2dacdaa
Fix exception handling indexes
asterite Aug 27, 2021
a493d4d
Inline `ensure` when `return` is done
asterite Aug 27, 2021
fd5bf66
Fix stack pool implementation
asterite Aug 28, 2021
0578825
to_bool for enum types
asterite Aug 28, 2021
e923091
Rename compile_pointerof_struct_to_be_passed_as_self to
asterite Aug 28, 2021
a75405c
Remove debug comments
asterite Aug 28, 2021
150d2d2
Merge branch 'master' into repl
asterite Aug 28, 2021
52ccbd4
Don't store last exception in interpreter
asterite Aug 28, 2021
1eebf27
Let `return` inside block execute ensure
asterite Aug 28, 2021
9b0547a
Execute ensure when breaking from block
asterite Aug 28, 2021
01ce648
Optimize returning value
asterite Aug 28, 2021
2235b26
Handle closured block arg
asterite Aug 28, 2021
098921e
Sometimes there's nothing to clear before entering a block
asterite Aug 29, 2021
24fd05e
to_bool for reference union type
asterite Aug 29, 2021
f94e6b4
Merge branch 'master' into repl
asterite Aug 29, 2021
3181ebe
Cast to filtered type, not type in `as(...)`
asterite Aug 29, 2021
55d09a6
Tuple metaclass indexer
asterite Aug 30, 2021
060cc79
Don't change ip on overflow
asterite Aug 30, 2021
7af6c4b
Fix `.class` for virtual types
asterite Aug 30, 2021
cf62f6f
Allow viewing the stack, and shorten pry commands
asterite Aug 30, 2021
8e3556b
Better local vars dump
asterite Aug 30, 2021
b696dfe
Merge branch 'master' into repl
asterite Aug 30, 2021
9154f21
Correctly pass self as pointer in multidispatch
asterite Aug 30, 2021
1180c1d
Pass self pointer of closured instance var
asterite Aug 30, 2021
f0a6a90
Ingore visibility checks in repl multidispatch
asterite Aug 31, 2021
373f656
Check block body NoReturn
asterite Aug 31, 2021
dc971dd
Use correct scope for inlined instance var
asterite Aug 31, 2021
8ad91a1
Correctly pass arguments with nil type to C functions
asterite Aug 31, 2021
0253c75
Don't pass STDOUT to `inspect_with_backtrace`
asterite Aug 31, 2021
81deb85
Interpret `out _`
asterite Sep 1, 2021
5d9b915
Make it work for linux (thanks @straight-shoota !)
asterite Sep 1, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3,569 changes: 3,569 additions & 0 deletions spec/compiler/repl/interpreter_spec.cr

Large diffs are not rendered by default.

12 changes: 0 additions & 12 deletions spec/compiler/semantic/primitives_spec.cr
Expand Up @@ -212,18 +212,6 @@ describe "Semantic: primitives" do
"expected Primitive argument to be a symbol literal"
end

it "errors if @[Primitive] method has body" do
assert_error %(
struct Int32
@[Primitive(:binary)]
def +(other : Int32) : Int32
1
end
end
),
"method marked as Primitive must have an empty body"
end

pending_win32 "types va_arg primitive" do
assert_type(%(
struct VaList
Expand Down
6 changes: 6 additions & 0 deletions src/compiler/crystal/codegen/llvm_id.cr
Expand Up @@ -30,12 +30,17 @@ module Crystal

def initialize(program)
@ids = {} of Type => {Int32, Int32}
@id_to_type = {} of Int32 => Type
Copy link
Member Author

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.

@id_to_metaclass = {} of Int32 => Int32
@next_id = 0
assign_id(program.object)
assign_id_to_metaclass(program.object)
end

def type_from_id(id : Int32)
@id_to_type[id]
end

def type_id(type : TypeDefType)
type_id(type.typedef)
end
Expand Down Expand Up @@ -156,6 +161,7 @@ module Crystal
end

private def put_id(type, min, max)
@id_to_type[max] = type
@ids[type] = {min, max}
end

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/codegen/llvm_typer.cr
Expand Up @@ -362,7 +362,7 @@ module Crystal
end

private def create_llvm_struct_type(type : Type, wants_size)
raise "BUG: called llvm_struct_type for #{type}"
raise "BUG: called llvm_struct_type for #{type} (#{type.class})"
end

def llvm_embedded_type(type, wants_size = false)
Expand Down
9 changes: 7 additions & 2 deletions src/compiler/crystal/command.cr
Expand Up @@ -21,7 +21,9 @@ class Crystal::Command
docs generate documentation
env print Crystal environment information
eval eval code from args or standard input
i/interactive starts interactive Crystal
play starts Crystal playground server
repl launch a repl
run (default) build and run program
spec build and run specs (in spec directory)
tool run a tool
Expand Down Expand Up @@ -64,7 +66,7 @@ class Crystal::Command
when !command
puts USAGE
exit
when "init".starts_with?(command)
when command == "init"
straight-shoota marked this conversation as resolved.
Show resolved Hide resolved
options.shift
init
when "build".starts_with?(command)
Expand Down Expand Up @@ -95,7 +97,10 @@ class Crystal::Command
options.shift
use_crystal_opts
eval
when "run".starts_with?(command)
when command == "i" || command == "interactive"
options.shift
repl
when command == "run"
options.shift
use_crystal_opts
run_command(single_file: false)
Expand Down
48 changes: 48 additions & 0 deletions src/compiler/crystal/command/repl.cr
@@ -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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are all experimental! Also status should be stats 😊

I think the options there should match the options of the usual crystal compiled, being able to pass --prelude, -D, etc.


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
109 changes: 109 additions & 0 deletions src/compiler/crystal/repl/c.cr
@@ -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