Skip to content

Commit

Permalink
Merge branch 'master' into refactor/crystal-system-thread
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil committed Oct 31, 2023
2 parents 40a5aef + c97c20e commit 25b4ca1
Show file tree
Hide file tree
Showing 43 changed files with 1,828 additions and 280 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/wasm32.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
rm wasm32-wasi-libs.tar.gz
- name: Build spec/wasm32_std_spec.cr
run: bin/crystal build spec/wasm32_std_spec.cr -o wasm32_std_spec.wasm --target wasm32-wasi -Duse_pcre
run: bin/crystal build spec/wasm32_std_spec.cr -o wasm32_std_spec.wasm --target wasm32-wasi -Duse_pcre -Dwithout_openssl
env:
CRYSTAL_LIBRARY_PATH: ${{ github.workspace }}/wasm32-wasi-libs

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ jobs:
run: |
mkdir llvm-build
cd llvm-build
cmake ..\llvm-src -Thost=x64 -DLLVM_TARGETS_TO_BUILD="X86;AArch64" -DLLVM_USE_CRT_RELEASE=MT -DBUILD_SHARED_LIBS=OFF -DCMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH=OFF -DLLVM_INCLUDE_BENCHMARKS=OFF -DLLVM_INCLUDE_TESTS=OFF -DLLVM_ENABLE_ZSTD=OFF
cmake ..\llvm-src -Thost=x64 -DLLVM_TARGETS_TO_BUILD="X86;AArch64" -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded -DBUILD_SHARED_LIBS=OFF -DCMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH=OFF -DLLVM_INCLUDE_BENCHMARKS=OFF -DLLVM_INCLUDE_TESTS=OFF -DLLVM_ENABLE_ZSTD=OFF
cmake --build . --config Release
cmake "-DCMAKE_INSTALL_PREFIX=$(pwd)\..\llvm" -P cmake_install.cmake
Expand Down
2 changes: 1 addition & 1 deletion Makefile.win
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ $(O)\crystal.exe: $(DEPS) $(SOURCES) $(O)\crystal.res
@$(call MKDIR,"$(O)")
$(call export_vars)
$(call export_build_vars)
.\bin\crystal build $(FLAGS) -o "$(O)\crystal-next.exe" src\compiler\crystal.cr -D without_openssl -D without_zlib -D without_playground $(if $(USE_PCRE1),-D use_pcre,-D use_pcre2) --link-flags=/PDBALTPATH:crystal.pdb "--link-flags=$(realpath $(O)\crystal.res)"
.\bin\crystal build $(FLAGS) -o "$(O)\crystal-next.exe" src\compiler\crystal.cr -D without_openssl -D without_zlib $(if $(USE_PCRE1),-D use_pcre,-D use_pcre2) --link-flags=/PDBALTPATH:crystal.pdb "--link-flags=$(realpath $(O)\crystal.res)"
$(call MV,"$(O)\crystal-next.exe","$@")
$(call MV,"$(O)\crystal-next.pdb","$(O)\crystal.pdb")

Expand Down
5 changes: 4 additions & 1 deletion scripts/generate_grapheme_break_specs.cr
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ File.open(path, "w") do |file|

format, _, comment = line.partition('#')

# TODO: implement grapheme boundary rule GB9c in UAX29
pending = comment.includes?("[9.3]")

graphemes = [] of String | Char
string = String.build do |io|
grapheme = String::Builder.new
Expand All @@ -61,7 +64,7 @@ File.open(path, "w") do |file|
graphemes << string_or_char(grapheme.to_s)
end

file.puts " it_iterates_graphemes #{string.dump}, [#{graphemes.join(", ", &.dump)}] # #{comment}"
file.puts " #{%(pending "GB9c" { ) if pending} it_iterates_graphemes #{string.dump}, [#{graphemes.join(", ", &.dump)}] #{" }" if pending} # #{comment}"
end
file.puts "end"
end
Expand Down
3 changes: 3 additions & 0 deletions spec/compiler/crystal_path/crystal_path_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ describe Crystal::CrystalPath do
assert_finds "../test_folder", relative_to: "test_files/test_folder/file_three.cr", results: [
"test_files/test_folder/test_folder.cr",
]
assert_finds "foo.cr", results: [
"foo.cr/foo.cr",
]

# For `require "foo"`:
# 1. foo.cr (to find something in the standard library)
Expand Down
Empty file.
35 changes: 35 additions & 0 deletions spec/compiler/macro/macro_methods_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,13 @@ module Crystal
end
end

describe "char methods" do
it "executes ord" do
assert_macro %({{'a'.ord}}), %(97)
assert_macro %({{'龍'.ord}}), %(40845)
end
end

describe "string methods" do
it "executes string == string" do
assert_macro %({{"foo" == "foo"}}), %(true)
Expand Down Expand Up @@ -2503,6 +2510,34 @@ module Crystal
end
end

describe "macro if methods" do
it "executes cond" do
assert_macro %({{x.cond}}), "true", {x: MacroIf.new(BoolLiteral.new(true), NilLiteral.new)}
end

it "executes then" do
assert_macro %({{x.then}}), "\"test\"", {x: MacroIf.new(BoolLiteral.new(true), StringLiteral.new("test"), StringLiteral.new("foo"))}
end

it "executes else" do
assert_macro %({{x.else}}), "\"foo\"", {x: MacroIf.new(BoolLiteral.new(true), StringLiteral.new("test"), StringLiteral.new("foo"))}
end
end

describe "macro for methods" do
it "executes vars" do
assert_macro %({{x.vars}}), "[bar]", {x: MacroFor.new([Var.new("bar")], Var.new("foo"), Call.new(nil, "puts", [Var.new("bar")] of ASTNode))}
end

it "executes exp" do
assert_macro %({{x.exp}}), "foo", {x: MacroFor.new([Var.new("bar")], Var.new("foo"), Call.new(nil, "puts", [Var.new("bar")] of ASTNode))}
end

it "executes body" do
assert_macro %({{x.body}}), "puts(bar)", {x: MacroFor.new([Var.new("bar")], Var.new("foo"), Call.new(nil, "puts", [Var.new("bar")] of ASTNode))}
end
end

describe "unary expression methods" do
it "executes exp" do
assert_macro %({{x.exp}}), "some_call", {x: Not.new("some_call".call)}
Expand Down
12 changes: 11 additions & 1 deletion spec/std/big/big_float_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,17 @@ describe "BigFloat" do
describe "#**" do
it { ("1.34".to_big_f ** 2).should be_close("1.7956".to_big_f, 1e-12) }
it { ("-0.05".to_big_f ** 10).should be_close("0.00000000000009765625".to_big_f, 1e-12) }
it { (0.1234567890.to_big_f ** 3).should be_close("0.001881676371789154860897069".to_big_f, 1e-12) }
it { ("0.1234567890".to_big_f ** 3).should be_close("0.001881676371789154860897069".to_big_f, 1e-12) }

it { ("1.34".to_big_f ** 2.to_big_i).should be_close("1.7956".to_big_f, 1e-12) }
it { ("-0.05".to_big_f ** 10.to_big_i).should be_close("0.00000000000009765625".to_big_f, 1e-12) }
it { ("0.1234567890".to_big_f ** 3.to_big_i).should be_close("0.001881676371789154860897069".to_big_f, 1e-12) }

it { ("10".to_big_f ** (-5).to_big_i).should be_close("0.00001".to_big_f, 1e-12) }
it { ("0.1".to_big_f ** (-5).to_big_i).should be_close("100000".to_big_f, 1e-12) }
it { ("0".to_big_f ** 1.to_big_i).should eq(0.to_big_f) }
it { ("0".to_big_f ** 0.to_big_i).should eq(1.to_big_f) }
it { expect_raises(ArgumentError, "Cannot raise 0 to a negative power") { "0".to_big_f ** (-1).to_big_i } }
end

describe "#abs" do
Expand Down
39 changes: 39 additions & 0 deletions spec/std/box_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,49 @@ describe "Box" do
Box(String).unbox(box).should be(a)
end

it "boxing a nilable reference returns the same pointer" do
a = "foo".as(String?)
box = Box.box(a)
box.address.should eq(a.object_id)

b = Box(String?).unbox(box)
b.should be_a(String)
b.should be(a)
end

it "boxing a nilable value returns the same value" do
a = 1.as(Int32?)
box = Box.box(a)

b = Box(Int32?).unbox(box)
b.should be_a(Int32)
b.should eq(a)
end

it "boxes with explicit type" do
box = Box(Int32?).box(1)
b = Box(Int32?).unbox(box)
b.should be_a(Int32)
b.should eq(1)
end

it "boxing nil returns a null pointer" do
box = Box.box(nil)
box.address.should eq(0)

Box(Nil).unbox(box).should be_nil
end

it "boxing nil in a reference-like union returns a null pointer (#11839)" do
box = Box.box(nil.as(String?))
box.address.should eq(0)

Box(String?).unbox(box).should be_nil
end

it "boxing nil in a value-like union doesn't crash (#11839)" do
box = Box.box(nil.as(Int32?))

Box(Int32?).unbox(box).should be_nil
end
end
38 changes: 38 additions & 0 deletions spec/std/enumerable_spec.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "spec"
require "spec/helpers/iterate"

private class SpecEnumerable
include Enumerable(Int32)
Expand Down Expand Up @@ -393,6 +394,43 @@ describe "Enumerable" do
end
end

describe "each_step" do
it_iterates "yields every 2nd element", %w[a c e], %w[a b c d e f].each_step(2)
it_iterates "accepts an optional offset parameter", %w[b d f], %w[a b c d e f].each_step(2, offset: 1)
it_iterates "accepts an offset of 0", %w[a c e], %w[a b c d e f].each_step(2, offset: 0)
it_iterates "accepts an offset larger then the step size", %w[d f], %w[a b c d e f].each_step(2, offset: 3)

it_iterates "accepts a step larger then the enumerable size", %w[a], %w[a b c d e f].each_step(7)
it_iterates "accepts an offset larger then the enumerable size", %w[], %w[a b c d e f].each_step(1, offset: 7)

it "doesn't accept a negative step" do
expect_raises(ArgumentError) do
%w[a b c d e f].each_step(-2)
end
expect_raises(ArgumentError) do
%w[a b c d e f].each_step(-2) { }
end
end

it "doesn't accept a step of 0" do
expect_raises(ArgumentError) do
%w[a b c d e f].each_step(0)
end
expect_raises(ArgumentError) do
%w[a b c d e f].each_step(0) { }
end
end

it "doesn't accept a negative offset" do
expect_raises(ArgumentError) do
%w[a b c d e f].each_step(2, offset: -2)
end
expect_raises(ArgumentError) do
%w[a b c d e f].each_step(2, offset: -2) { }
end
end
end

describe "each_with_index" do
it "yields the element and the index" do
collection = [] of {String, Int32}
Expand Down
Loading

0 comments on commit 25b4ca1

Please sign in to comment.