From 1770d6aed6bf6c10d06597a061f1d0f87a93c4ed Mon Sep 17 00:00:00 2001 From: John Tinnerholm Date: Wed, 5 Jan 2022 15:10:52 +0100 Subject: [PATCH 1/4] Changed some typeinference rule for dangerous (#56) * Changed some typeinference rule for dangerous + missing stringDelim function * Disabled the flaky formatting action --- .github/workflows/main.yml | 13 +------------ src/dangerous.jl | 34 ++++++++++++++++------------------ src/metaRuntime.jl | 12 ++++++------ 3 files changed, 23 insertions(+), 36 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 17578a5..64da180 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,12 +1 @@ -name: Format - -on: [push, pull_request] -#sdsdsd -jobs: - format: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@master - - uses: julia-actions/julia-format@master - with: - args: -i 2 -v . +# Actions to be added here. diff --git a/src/dangerous.jl b/src/dangerous.jl index 3778ded..abb673f 100644 --- a/src/dangerous.jl +++ b/src/dangerous.jl @@ -9,17 +9,13 @@ import ExportAll using ..MetaModelica """ O(1) """ -function arrayGetNoBoundsChecking(arr::Array{A}, index::ModelicaInteger)::A where {A<:Any} - if index < 0 - println("arrayGetNoBoundsChecking: index < 0!") - end +function arrayGetNoBoundsChecking(arr::Array, index::ModelicaInteger) @inbounds arr[index] end """ O(1) """ -function arrayUpdateNoBoundsChecking(arr::Array{A}, index::ModelicaInteger, - newValue::A)::Array{A} where {A<:Any} - local newArray::Array{A} = arr +function arrayUpdateNoBoundsChecking(arr::Array{T}, index::ModelicaInteger, newValue::T) where {T} + local newArray = arr if index < 0 println("arrayUpdateNoBoundsChecking: index < 0!") end @@ -32,8 +28,8 @@ access an uninitialized elements may cause segmentation faults if you're lucky, and pretty much anything else if you're not. Do not use unless you will immediately fill the whole array with data. The dummy variable is used to fix the type of the array. """ -function arrayCreateNoInit(size::ModelicaInteger, dummy::A)::Array{A} where {A<:Any} - local arr::Array{A} = fill(dummy, size) +function arrayCreateNoInit(size::ModelicaInteger, dummy::T) where {T} + local arr = fill(dummy, size) arr end @@ -47,24 +43,26 @@ function stringGetNoBoundsChecking(str::String, index::ModelicaInteger)::Modelic end """ Not possible unless we write a C list impl for Julia """ -function listReverseInPlace(inList::List{T})::List{T} where {T<:Any} +function listReverseInPlace(inList::List{T}) where {T} MetaModelica.listReverse(inList) end """ O(1). A destructive operation changing the \"first\" part of a cons-cell. """ -function listSetFirst(inConsCell::List{A}, inNewContent::A) where {A<:Any} #= A non-empty list =# - #= Defined in the runtime =# +function listSetFirst(inConsCell::Cons{A}, inNewContent::A) where {A} #= A non-empty list =# + @assign inConsCell.head = inNewConent end -""" O(1). A destructive operation changing the rest part of a cons-cell """ -#= NOTE: Make sure you do NOT create cycles as infinite lists are not handled well in the compiler. =# -function listSetRest(inConsCell::List{A}, inNewRest::List{A}) where {A<:Any} #= A non-empty list =# - #= Defined in the runtime =# +""" +O(1). A destructive operation changing the rest part of a cons-cell +NOTE: Make sure you do NOT create cycles as infinite lists are not handled well in the compiler. +""" +function listSetRest(inConsCell::Cons{T}, inNewRest::List{T}) where {T} #= A non-empty list =# + @assign inConsCell.tail = inNewRest end """ O(n) """ -function listArrayLiteral(lst::List{A})::Array{A} where {A<:Any} - local arr::Array{A} = listArray(lst) +function listArrayLiteral(lst::List{T}) where {T} + local arr = listArray(lst) arr end diff --git a/src/metaRuntime.jl b/src/metaRuntime.jl index 95b37e8..1054977 100644 --- a/src/metaRuntime.jl +++ b/src/metaRuntime.jl @@ -392,6 +392,8 @@ function stringDelimitList(strs::List{Any}, delimiter::String)::String str end +stringDelimitList(lst::Nil, delim::String) = "{}" + """ O(1) """ function stringLength(str::String)::ModelicaInteger length(str) @@ -502,7 +504,7 @@ function arrayEmpty(arr::Array{A})::Bool where {A} end """ O(1) """ -function arrayGet(arr::Array{A}, index::ModelicaInteger)::A where {A} +function arrayGet(arr::Array{A}, index::ModelicaInteger) where {A} if index < 0 println("arrayGet: index < 0!") fail() @@ -511,12 +513,12 @@ function arrayGet(arr::Array{A}, index::ModelicaInteger)::A where {A} end """ O(size) """ -function arrayCreate(size::ModelicaInteger, initialValue::A)::Array{A} where {A} +function arrayCreate(size::ModelicaInteger, initialValue::A) where {A} fill(initialValue, size) end """ O(N) """ -function arrayList(arr::Array{T})::List{T} where {T} +function arrayList(arr::Array{T}) where {T} local lst::List{T} = nil for i = length(arr):-1:1 lst = Cons{T}(arr[i], lst) @@ -525,7 +527,7 @@ function arrayList(arr::Array{T})::List{T} where {T} end """ O(n) """ -function listArray(lst::Cons{T})::Array{T} where {T} +function listArray(lst::Cons{T}) where {T} local arr::Vector{T} = T[] for i in lst push!(arr, i) @@ -737,7 +739,6 @@ end function isPresent(ident::T)::Bool where {T} local b::Bool b = true - b end #= The Info attribute provides location information for elements and classes. =# @@ -753,7 +754,6 @@ end end end - SOURCEINFO(fileName::String, isReadOnly::Bool, lineNumberStart::ModelicaInteger, columnNumberSTart::ModelicaInteger, lineNumberEnd::ModelicaInteger, columnNumberEnd::ModelicaInteger) = From 2e5927201927e418c68d6c1c926b0d545b7f8037 Mon Sep 17 00:00:00 2001 From: John Tinnerholm Date: Thu, 6 Jan 2022 16:33:38 +0100 Subject: [PATCH 2/4] Improved error messages during the lowering of match/matchcontinue (#57) --- src/matchcontinue.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/matchcontinue.jl b/src/matchcontinue.jl index 6305f90..15e301b 100644 --- a/src/matchcontinue.jl +++ b/src/matchcontinue.jl @@ -178,11 +178,12 @@ function handle_destruct(value::Symbol, pattern, bound::Set{Symbol}, asserts::Ve #= NONE is a function. However, we treat it a bit special=# if $(esc(T)) !== NONE && typeof($(esc(T))) <: Function func = $(esc(T)) - throw(LoadError("Attempted to match on a function", @__LINE__, + file = @__FILE__ + throw(LoadError("Attempted to match on a function at $(file)", @__LINE__, AssertionError("Incorrect match usage attempted to match on: $func"))) end if !(isstructtype(typeof($(esc(T)))) || issabstracttype(typeof($(esc(T))))) - throw(LoadError("Attempted to match on a pattern that is not a struct", + throw(LoadError("Attempted to match on a pattern that is not a struct at $(file)", @__LINE__, AssertionError("Incorrect match usage. Attempted to match on a pattern that is not a struct"))) end From c4d5783da664cc997890aa9f4c4080b3b04eb191 Mon Sep 17 00:00:00 2001 From: John Tinnerholm Date: Tue, 11 Jan 2022 13:32:45 +0100 Subject: [PATCH 3/4] Removed old to string method (#58) * Removed toString method that was invalidating code * Update version due to API change --- Project.toml | 2 +- src/metaRuntime.jl | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/Project.toml b/Project.toml index 3e7e167..7d4284f 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "MetaModelica" uuid = "9d7f2a79-07b5-5542-8b19-c0100dda6b06" authors = ["Martin Sjölund ", "John Tinnerholm "] -version = "0.0.2" +version = "0.0.3" [deps] DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" diff --git a/src/metaRuntime.jl b/src/metaRuntime.jl index 1054977..191ca2c 100644 --- a/src/metaRuntime.jl +++ b/src/metaRuntime.jl @@ -795,7 +795,3 @@ end function StringFunction(r::Float64)::String realString(r) end - -function String(a)::String - string(a) -end From 8afe308315c1cde60023457d4de84989c4bc7f61 Mon Sep 17 00:00:00 2001 From: John Tinnerholm Date: Tue, 11 Jan 2022 20:55:43 +0100 Subject: [PATCH 4/4] Readded the string function (#59) This was removed in #58 however, there seem to be issues with it being removed --- src/metaRuntime.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/metaRuntime.jl b/src/metaRuntime.jl index 191ca2c..359e780 100644 --- a/src/metaRuntime.jl +++ b/src/metaRuntime.jl @@ -795,3 +795,7 @@ end function StringFunction(r::Float64)::String realString(r) end + +function String(arg)::String + return string(arg) +end