Skip to content

Commit

Permalink
Changed some typeinference rule for dangerous (#56)
Browse files Browse the repository at this point in the history
* Changed some typeinference rule for dangerous + missing stringDelim function

* Disabled the flaky formatting action
  • Loading branch information
JKRT committed Jan 5, 2022
1 parent 25b4909 commit 1770d6a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 36 deletions.
13 changes: 1 addition & 12 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -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.
34 changes: 16 additions & 18 deletions src/dangerous.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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

Expand Down
12 changes: 6 additions & 6 deletions src/metaRuntime.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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. =#
Expand All @@ -753,7 +754,6 @@ end
end
end


SOURCEINFO(fileName::String, isReadOnly::Bool, lineNumberStart::ModelicaInteger,
columnNumberSTart::ModelicaInteger, lineNumberEnd::ModelicaInteger,
columnNumberEnd::ModelicaInteger) =
Expand Down

0 comments on commit 1770d6a

Please sign in to comment.