- Crystal has evented IO by default. Added
spawn
andChannel
. - Correctly support the X86_64 and X86 ABIs. Now bindings to C APIs that pass and return structs works perfectly fine.
- Added
crystal init
to quickly create a skeleton library or application (thanks @waterlink) - Added
--emit
flag to the compiler. Now you can easily see the generated LLVM IR, LLVM bitcode, assembly and object files. - Added
--no-color
flag to supress color output, useful for editor tools. - Added macro vars:
%var
and%var{x, y}
create uniqely named variables inside macros. - Added typed splats.
- Added
Iterator
and many methods that return iterators, likeArray#each
,Hash#each
,Int#times
,Int#step
,String#each_char
, etc. - Added
sprintf
and improvedString#%
to support floats and float formatting. - Added more variants of
String#gsub
. - Added
Pointer#clear
and use it to clear anArray
's values when doingpop
and other shrinking methods. - Added
BigInt#to_s(base)
,BigInt::cast
and bit operators (thanks @Exilor) - Allow invoking methods on a union class as long as all types in the union have it.
- Allow specifying a def's return type. The compiler checks the return type only for that def for now (not for subclasses overrding the method). The return type appears in the documentation.
- Allow constants and computed constants for a StaticArray length.
- Allow class vars in enums.
- Allow private and protected defs in enums.
- Allow reopening a
lib
and adding more@[Link]
attributes to it, even allowing duplicated attributes. - Allow getting a function pointer to a lib fun without specifying its types (i.e.
->LibC.getenv
) - Allow specifying
ditto
for a doc comment to reuse the previous comment. - Changed the semantic of
%
: previously it meantremainder
, not it meansmodulo
, similar to Ruby and Python. AddedInt#remainder
. #to_s
and#inspect
now work for a union class.- Spec: added global
before_each
andafter_each
hooks, which will simplify the use of mocking libraries like timecop.cr and webmock.cr. Range(T)
is nowRange(B, E)
again (much more flexible).- Improved Regex performance.
- Better XML support.
- Support LLVM 3.6.
- Exception class is now shown on unhandled exceptions
- The following types are now disallowed in generics (for now): Object, Value, Reference, Number, Int and Float.
- Lots of bug fixes, enhancements and optimizations.
- The
class
method now works in all cases. You can now compare classes with==
and ask theirhash
value. - Block variables can now shadow local variables.
Range(B, E)
is nowRange(T)
.- Added
Number::[]
. Now you can doInt64[1, 2, 3]
instead of[1_i64, 2_i64, 3_u64]
. - Better detection of nilable instance variables, and better error messages too.
- Added
Crypto::Blowfish
(thanks @akaufmann) - Added
Matrix
(thanks @Exilor) - Added
CallConvention
attribute forfun
s. - Macros: added
constants
so you can inspect a type's constants at compile time. - Macros: added
methods
, which lists a type's methods (without including supertypes). - Macros: added
has_attribute?
for enum types, so you can check if an enum has the Flags attribute on it. - Many more small additions and bug fixes.
- Same as 0.5.10
- Note: This release makes core, breaking changes to the language, and doesn't work out of the box with its accompanying standard library. Use 0.6.0 instead.
- Improved error messages related to nilable instance variables.
- The magic variables
$~
and$?
are now method-local and concurrent-safe. Tuple
is now correctly considered a structPointer
is now correctly considered a struct- Renamed
Function
toProc
Random
is now a module, with static methods that default to theRandom::MT19937
class.- Added
Random::ISAAC
engine (thanks @ysbaddaden!) - Added
String#size
(thanks @zamith!) - Added
limit
to allString#split
variants (thanks @jhass!) - Raising inside a Thread is now rescued and re-raised on join (thanks @jhass!)
- Added
path
option to Projectfile forcrystal deps
(thanks @naps62!) - Many fixes towards making Crystal work on linux 32 bits.
- Huge refactors, additions and improvements for sockets: Socket, IPSocket, TCPSocket, TCPServer, UDPSocket, UNIXSocket, UNIXServer (thanks @ysbaddaden!)
- Allow regex with empty spaces in various places.
- Added
HTML.escape(String)
(thanks @naps62!) - Added support for
%w[...]
,%w{...}
,%w<...>
as alternatives to%w(...)
. Same goes for%i(...)
(thanks @zamith!) - Added
Enumerable#min_of
,Enumerable#max_of
andEnumerable#minmax_of
,Enumerable#to_h
,Dir.chdir
andNumber#fdiv
(thanks @jhass!) - Added
String#match
,String#[]
,String#[]?
andMatchData#[]?
related to regexes (thanks @jhass!) - Allow
T::Bar
when T is a generic type argument. - Added
subclasses
andall_subclasses
in macros. - Now you can invoke
to_s
andinspect
on C structs and unions, making debugging C bindings much easier! - Added
#to_f
and#to_i
toTime
andTimeSpan
(thanks @epitron!) - Added
IO.select
(thanks @jhass!) - Now you can use
ifdef
inside C structs and unions. - Added
include
inside C structs, to include other struct fields (useful for composition and avoiding an explicit indirection). - Added
Char#in_set?
,String#count
,String#delete
andString#squeeze
(thanks @jhass!) - Added
-D flag
option to the compiler to set compile-time flags to use inifdef
. - More support for forward declarations inside C libs.
- Rewritten some
Function
primitives in Crystal itself, and added methods for obtaining the pointer and closure data, as well as for recreating a function from these. - Added a
Logger
class (thanks @ysbaddaden!) - Lots of bugs fixed.
- Added
Random
andRandom::MT19937
(Mersenne Twister) classes (thanks @rhysd). - Docs: removed automatic linking. To link to classes and methods surround with backticks.
- Fixed #328:
!=
bug.
- Fixed:
doc
command had some hardcoded paths and didn't work - Added:
private def
at the top-level of a file is only available inside that file
- Added a
crystal doc
command to automatically generate documentation for a project using Markdown syntax. The style is still ugly but it's quite functional. Now we only need to start documenting things :-) - Removed the old
@:
attribute syntax. - Fixed #311: Issues with invoking lib functions in other ways (thanks @scidom).
- Fixed #314: NoReturn information is not lazy.
- Fixed #317: Fixes in UTF-8 encoding/decoding (thanks @yous).
- Fixed #319: Unexpected EOF (thanks @Exilor).
{{yield}}
inside macros now preserve the yielded node location, leading to much better error messages.- Added
Float#nan?
,Float#infinite?
andFloat#finite?
. - Many other bug fixes and improvements.
- Removed
src
and crystal compilerlibs
directory from CRYSTAL_PATH. - Several bug fixes.
- (breaking change)
require "foo"
always looks up inCRYSTAL_PATH
.require "./foo"
looks up relative to the requiring file. - (breaking change) Renamed
Json
toJSON
,Xml
toXML
andYaml
toYAML
to follow a convention. - (breaking change) To use HTTP types do, for example,
require "http/client"
instead of the oldrequire "net/http"
. - Added
alias_method
macro (thanks @Exilor and @jtomschroeder). - Added some
Complex
number methods and many math methods, refactors and specs (thanks @scidom). - Inheriting generic classes is now possible.
- Creating arrays of generic types (i.e.:
[] of Thread
) is now possible. - Allow using an alias in a block type (i.e.:
alias F = Int32 ->
,&block : F
). json_mapping
macro supports a simpler syntax:json_mapping({key1: Type1, key2: Type2})
.- Spec: added
be_a(type)
matcher. - Spec: added
be > ...
and similar matchers for>=
,<
and<=
. - Added
File::file?
andFile::directory?
. - CSV parser can parse from String or IO.
- When invoking the compiler like this:
crystal foo.cr -o foo
thebuild
command is assumed instead ofrun
. - Added short symbol notation for methods that are operators (i.e.
:+
,:*
,:[]
, etc.). - Added
TimeSpan#ago
,TimeSpan#from_now
,MonthSpan#ago
andMonthSpan#from_now
.
- Spec: when a
should
orshould_not
fail, the filename and line number, including the source's line, is included in the error message. - Spec: added
-l
switch to be able to run a spec defined in a line. - Added
crystal spec file:line
- Properties (property, setter, getter) can now be restricted to a type with the syntax
property name :: Type
. - Enums can be used outside
lib
. They inheritEnum
, can have methods and can be marked with @[Flags]. - Removed the distinction between
lib
enums and regular enums. - Fixed: it was incorrectly possible to define
class
,def
, etc. inside a call block. - The syntax for specifying the base type of an enum,
enum Name < BaseType
has been deprecated. Useenum Name : BaseType
. - Added
Array#<=>
and make it comparable to other arrays.
- New command line interface to the compiler (
crystal build ...
,crystal run ...
,crystal spec
, etc.). The default is to compiler and run a program. crystal eval
without arguments reads from standard input.- Added preliminar
crystal deps
command. __FILE__
,__DIR__
and__LINE__
, when used as def default arguments, resolve to the caller location (similar to D and Swift)- Allow
as
to determine a type even if the casted value doesn't have a type yet. - Added
is_a?
in macros. The check is against an AST node name. For examplenode.is_a?(HashLiteral)
. - Added
emit_null
property tojson_mapping
. - Added
converter
property tojson_mapping
. - Added
pp
in macros. - Added
to_pretty_json
. - Added really basic
CSV.parse
. - Added
Regex.escape
. - Added
String#scan
. - Added
-e
switch to spec, to run specs that match a pattern. - Added
--fail-fast
swtich to spec. - Added
HTTPClient#basic_auth
. - Added
DeclareVar
,Def
andArg
macro methods. - Added
Time
andTimeSpan
structs.TimeWithZone
will come later. - Added
Array#fill
(thanks @Exilor). - Added
Array#uniq
. - Optimized
File.read_lines
. - Allow any expression inside
{% ... %}
so that you can intepret code without outputting the result. - Allow
\
at the end of a line. - Allow using
if
andunless
inside macro expressions. - Allow marking a
fun/def
as@[Raises]
(useful when a function can potentially raise from a callback). - Allow procs are now considered
@[Raises]
. OAuth2::Client
supports getting an access token via authorization code or refresh token.- Consecutive string literals are automatically concatenated by the parser as long as there is a
\
with a newline between them. - Many bug fixes.
- Added json_mapping macro.
- Added Signal module.
- Added Tempfile class.
- Enhanced HTTP::Client.
- Added OAuth::Consumer.
- Added OAuth2::Client.
- Added OpenSSL::HMAC.
- Added SecureRandom.
- New syntax for array/hash-like classes. For example:
Set {1, 2, 3}
andHTTP::Headers {"content-type": "text/plain"}
. These just create the type and use<<
or[]=
. - Optimized Json parsing performance.
- Added a CSV builder.
- XML reader can parse from an IO.
- Added
Dir::glob
andDir::Entries
(thanks @jhass) - Allow
ensure
as an expression suffix. - Fixed #219: Proc type is not inferred when passing to library fun and the return type doesn't match.
- Fixed #224: Class#new doesn't pass a block.
- Fixed #225: ICE when comparing void to something.
- Fixed #227: Nested captured block looses scope and crashes compiler.
- Fixed #228: Macro expansion doesn't retain symbol escaping as needed.
- Fixed #229: Can't change block context if defined within module context.
- Fixed #230: Type interference breaks equality operator.
- Fixed #233: Incorrect
no block given
message with new. - Other bug fixes.
- String overhaul, and optimizations
- Define backtick (`) for command execution.
- Allow string literals as keys in hash literals:
{"foo": "bar"} # :: Hash(String, String)
- Allow
ifdef
as a suffix. - Integer division by zero raises a
DivisionByZero
exception. - Link attributes are now only processed if a lib function is used.
- Removed the
type Name : Type
syntax (usetype Name = Type
instead). - Removed the
lib Lib("libname"); end
syntax. Use@[Link]
attribute instead. - Fixed some
require
issues. - String representation includes length.
- Upgraded to LLVM 3.5.
- Fixed #193: allow initializing an enum value with another's one.
- The
record
macro is now variadic, so instead ofrecord Vec3, [x, y, z]
writerecord Vec3, x, y, z
. - The
def_equals
,def_hash
anddef_equals_and_hash
macros are now variadic. - The
property
,getter
andsetter
macros are now variadic. - All String methods are now UTF-8 aware.
String#length
returns the number of characters, whileString#bytesize
return the number of bytes (previouslylength
returned the number of bytes andbytesize
didn't exist).String#[](index)
now returns aChar
instead of anUInt8
, where index is counted in characters. There's alsoString#byte_at(index)
.- Removed the
\x
escape sequence in char and string literals. Use\u
instead. initialize
methods are now protected.- Added
IO#gets_to_end
. - Added backticks (
...
) and%x(...)
for command execution. - Added
%r(...)
for regular expression literals. - Allow interpolations in regular expresion literals.
- Compiling with
--release
sets arelease
flag that you can test withifdef
. - Allow passing splats to C functions
- A C type can now be declared like
type Name = Type
(type Name : Type
will be deprecated). - Now a C struct/union type can be created with named arguments.
- New attributes syntax:
@[Attr(...)
] instead of@:Attr
. The old syntax will be deprecated in a future release. - New link syntax for C libs:
@[Link("name")]
(usesname
aspkg-config name
if available or-lname
instead),@[Link(ldflags: "...")]
to pass raw flags to the linker,@[Link("name", static: true)]
to try to find a static library first, and@[Link(framework: "AppKit")]
(for Mac OSX). - Added an
exec
method to execute shell commands. Added thesystem
andbacktick
similar to Ruby ones. - Added
be_truthy
andbe_falsey
spec matchers. AddedArray#zip
without a block. (thanks @mjgpy3) - Added
getter?
andproperty?
macros to create methods that end with?
. - Added a
CGI
module. - The compiler now only depends on
cc
for compiling (removed dependency tollc
,opt
,llvm-dis
andclang
). - Added
IO#tty?
. - Some bug fixes.
- Reverted a commit that introduced random crashes.
- Fixed #187: mixing
yield
andblock.call
crashes the compiler. - Added
\u
unicode escape sequences inside strings and chars (similar to Ruby).\x
will be deprecated as it can generate strings with invalid UTF-8 byte sequences. - Added
String#chars
. - Fixed: splats weren't working in
initialize
. - Added the
private
andprotected
visibility modifiers, with the same semantics as Ruby. The difference is that you must place them before adef
or a macro call. - Some bug fixes.
- Fixed #185:
-e
flag stopped working. - Added a
@length
compile-time variable available inside tuples that allows to do loop unrolling. - Some bug fixes.
- Support splats in macros.
- Support splats in defs and calls.
- Added named arguments.
- Renamed the
make_named_tuple
macro torecord
. - Added
def_equals
,def_hash
anddef_equals_and_hash
macros to generate them from a list of fields. - Added
Slice(T)
, which is a struct having a pointer and a length. Use this in IO for a safe API. - Some
StaticArray
fixes and enhancements.
- (breaking change) Removed the special
->
operator for pointers of structs/unions: instead offoo->bar
usefoo.value.bar
; instead offoo->bar = 1
usefoo.value.bar = 1
. - Added
colorize
file that provides methods to easily output bash colors. - Now you can use modules as generic type arguments (for example, do
x = [] of IO
). - Added SSL sockets. Now HTTP::Server implements HTTPS.
- Macros have access to constants and types.
- Allow iterating a range in macros with
for
. - Use cpu cycle counter to initialize random.
method_missing
now works in generic types.- Fixed #154: bug, constants are initialized before global variables.
- Fixed #168: incorrect type inference of instance variables if not assigned in superclass.
- Fixed #169:
responds_to?
wasn't working with generic types. - Fixed #171: ensure blocks are not executed if the rescue block returns from a def.
- Fixed #175: invalid code generated when using with/yield with structs.
- Fixed some parser issues and other small issues.
- Allow forward struct/union declarations in libs.
- Added
String#replace(Regex, String)
- Added a
Box(T)
class, useful for boxing value types to pass them to C asVoid*
.
- Fixed #165: restrictions with generic types didn't work for hierarchy types.
- Allow using a single underscore in restrictions, useful for matching against an n-tuple or an n-function where you don't care about the types (e.g.:
def foo(x : {_, _})
. - Added a
generate_hash
macro that generates ahash
methods based on some AST nodes. - Added very basic
previous_def
: similar tosuper
, but uses the previous definition of a method. Useful to decorate existing methods (similar toalias_method_chain
). For now the method's type restrictions must match for a previous definition to be found. - Made the compiler a bit faster
- Added
env
in macros, to fetch an environment value. Returns a StringLiteral if found or NilLiteral if not. - Make
return 1, 2
be the same asreturn {1, 2}
. Same goes withbreak
andnext
. - Added
Pointer#as_enumerable(size : Int)
to create anEnumerable
from a Pointer with an associated size, with zero overhead. Some methods removed fromPointer
:each
,map
,to_a
,index
. - Added
StaticArray::new
,StaticArray::new(value)
,StaticArray::new(&block)
,StaticArray#shuffle!
andStaticArray#map!
. - Faster
Char#to_s(io : IO)
- Allow implicit conversion to C types by defining a
to_unsafe
method. This removed the hardcoded rule for converting aString
toUInt8*
and also allows passing anArray(T)
to an argument expectingPointer(T)
. - Fixed
.is_a?(Class)
not working (#162) - Attributes are now associated to AST nodes in the semantic pass, not during parsing. This allows macros to generate attributes that will be attached to subsequent expressions.
- (breaking change) Make ENV#[] raise on missing key, and added ENV#[]?
- (breaking change) Macro defs are now written like
macro def name(args) : ReturnType
instead ofdef name(args) : ReturnType
, which was a bit confusing.
- Integer literals without a suffix are inferred to be Int32, Int64 or UInt64 depending on their value.
- Check that integer literals fit into their types.
- Put back
Int#to_s(radix : Int)
(was renamed toto_s_in_base
in the previous release) by also specifying a restriction inInt#to_s(io : IO)
. - Added
expect_raises
macros in specs
- (breaking change) Replaced
@name
inside macros with@class_name
. - (breaking change) Instance variables inside macros now don't have the
@
symbols in their names.
- Added
Array#each_index
- Optimized
String#*
for the case when the string has length one. - Use
GC.malloc_atomic
for String and String::Buffer (as they don't contain internal pointers.) - Added a
PointerAppender
struct to easily append to aPointer
while counting at the same time (thanks @kostya for the idea). - Added a
Base64
module (thanks @kostya) - Allow default arguments in macros
- Allow invoking
new
on a function type. For example:alias F = Int32 -> Int32; f = F.new { |x| x + 1 }; f.call(2) #=> 3
. - Allow ommiting function argument types when invoking C functions that accept functions as arguments.
- Renamed
@name
to@class_name
inside macros.@name
will be deprecated in the next version. - Added IO#read_fully
- Macro hooks:
inherited
,included
andextended
method_missing
macro- Added
{{ raise ... }}
inside macros to issue a compile error. - Started JSON serialization and deserialization
- Now
at_exit
handlers are run when you invokeexit
- Methods can be marked as abstract
- New convention for
to_s
andinspect
: you must override them receiving an IO object - StringBuilder and StringBuffer have been replaced by StringIO
-
Removed icr (a REPL): it is abandoned for the moment because it was done in a hacky, non-reliable way
-
Added very basic
String#underscore
andString#camelcase
. -
The parser generates string literals out of strings with interpolated string literals. For example,
"#{__DIR__}/foo"
is interpolated at compile time and generates a string literal with the full path, since__DIR__
is just a (special) string literal. -
(breaking change) Now macro nodes are always pasted as is. If you want to generate an id use
{{var.id}}
.Previously, a code like this:
macro foo(name) def {{name}}; end end foo :hello foo "hello" foo hello
generated this:
def hello; end def hello; end def hello; end
With this change, it generates this:
def :hello; end def "hello"; end def hello; end
Now, to get an identifier out of a symbol literal, string literal or a name, use id:
macro foo(name) def {{name.id}}; end end
Although it's longer to type, the implicit "id" call was sometimes confusing. Explicit is better than implicit.
Invoking
id
on any other kind of node has no effect on the pasted result. -
Allow escaping curly braces inside macros with
\{
. This allows defining macros that, when expanded, can contain other macro expressions. -
Added a special comment-like pragma to change the lexer's filename, line number and colum number.
# foo.cr a = 1 #<loc:"bar.cr",12,24>b = 2 c = 3
In the previous example,
b = 2
(and the rest of the file) is considered as being parsed from filebar.cr
at line 12, column 24. -
Added a special
run
call inside macros. This compiles and executes another Crystal program and pastes its output into the current program.As an example, consider this program:
# foo.cr {{ run("my_program", 1, 2, 3) }}
Compiling
foo.cr
will, at compile-time, compilemy_program.cr
and execute it with arguments1 2 3
. The output of that execution is pasted intofoo.cr
at that location. -
Added ECR (Embedded Crystal) support. This is implemented using the special
run
macro call.A small example:
# template.ecr Hello <%= @msg %>
# foo.cr require "ecr/macros" class HelloView def initialize(@msg) end # This generates a to_s method with the contents of template.ecr ecr_file "template.ecr" end view = HelloView.new "world!" view.to_s #=> "Hello world!"
The nice thing about this is that, using the
#<loc...>
pragma for specifying the lexer's location, if you have a syntax/semantic error in the template the error points to the template :-)
- First official release