Skip to content

Commit

Permalink
Merge branch 'devel' into cbuilder-for-stmts
Browse files Browse the repository at this point in the history
  • Loading branch information
Araq authored Nov 3, 2024
2 parents 307ce61 + f5d80ed commit 903015b
Show file tree
Hide file tree
Showing 20 changed files with 563 additions and 582 deletions.
76 changes: 0 additions & 76 deletions .github/workflows/ci_gcc14.yml

This file was deleted.

17 changes: 10 additions & 7 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
strategy:
matrix:
Linux_amd64:
vmImage: 'ubuntu-20.04'
vmImage: 'ubuntu-24.04'
CPU: amd64
# regularly breaks, refs bug #17325
# Linux_i386:
Expand Down Expand Up @@ -80,10 +80,12 @@ jobs:
- bash: |
set -e
. ci/funs.sh
echo_run sudo apt-fast update -qq
echo_run sudo add-apt-repository universe
echo_run sudo apt-get update -qq
DEBIAN_FRONTEND='noninteractive' \
echo_run sudo apt-fast install --no-install-recommends -yq \
libcurl4-openssl-dev libgc-dev libsdl1.2-dev libsfml-dev valgrind libc6-dbg
echo_run sudo apt-get install --no-install-recommends -yq \
gcc-14 g++-14 libpcre3 liblapack-dev libpcre3 liblapack-dev libcurl4-openssl-dev libgc-dev libsdl1.2-dev libsfml-dev valgrind libc6-dbg
echo_run sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 60 --slave /usr/bin/g++ g++ /usr/bin/g++-14
displayName: 'Install dependencies (amd64 Linux)'
condition: and(succeeded(), eq(variables['skipci'], 'false'), eq(variables['Agent.OS'], 'Linux'), eq(variables['CPU'], 'amd64'))
Expand All @@ -100,15 +102,16 @@ jobs:
Pin-Priority: 1001
EOF
# echo_run sudo apt-fast update -qq
echo_run sudo apt-fast update -qq || echo "failed, see bug #17343"
# echo_run sudo apt-get update -qq
echo_run sudo apt-get update -qq || echo "failed, see bug #17343"
# `:i386` (e.g. in `libffi-dev:i386`) is needed otherwise you may get:
# `could not load: libffi.so` during dynamic loading.
DEBIAN_FRONTEND='noninteractive' \
echo_run sudo apt-fast install --no-install-recommends --allow-downgrades -yq \
echo_run sudo apt-get install --no-install-recommends --allow-downgrades -yq \
g++-multilib gcc-multilib libcurl4-openssl-dev:i386 libgc-dev:i386 \
libsdl1.2-dev:i386 libsfml-dev:i386 libglib2.0-dev:i386 libffi-dev:i386
cat << EOF > bin/gcc
#!/bin/bash
Expand Down
68 changes: 40 additions & 28 deletions compiler/cbuilderbase.nim
Original file line number Diff line number Diff line change
@@ -1,44 +1,56 @@
import ropes, int128

type
Snippet = string
Builder = string
Snippet* = string
Builder* = object
buf*: string

template newBuilder*(s: string): Builder =
Builder(buf: s)

proc extract*(builder: Builder): Snippet =
builder.buf

proc add*(builder: var Builder, s: string) =
builder.buf.add(s)

template newBuilder(s: string): Builder =
s
proc add*(builder: var Builder, s: char) =
builder.buf.add(s)

proc addIntValue(builder: var Builder, val: int) =
builder.addInt(val)
proc addIntValue*(builder: var Builder, val: int) =
builder.buf.addInt(val)

proc addIntValue(builder: var Builder, val: int64) =
builder.addInt(val)
proc addIntValue*(builder: var Builder, val: int64) =
builder.buf.addInt(val)

proc addIntValue(builder: var Builder, val: uint64) =
builder.addInt(val)
proc addIntValue*(builder: var Builder, val: uint64) =
builder.buf.addInt(val)

proc addIntValue(builder: var Builder, val: Int128) =
builder.addInt128(val)
proc addIntValue*(builder: var Builder, val: Int128) =
builder.buf.addInt128(val)

template cIntValue(val: int): Snippet = $val
template cIntValue(val: int64): Snippet = $val
template cIntValue(val: uint64): Snippet = $val
template cIntValue(val: Int128): Snippet = $val
template cIntValue*(val: int): Snippet = $val
template cIntValue*(val: int64): Snippet = $val
template cIntValue*(val: uint64): Snippet = $val
template cIntValue*(val: Int128): Snippet = $val

import std/formatfloat

proc addFloatValue(builder: var Builder, val: float) =
builder.addFloat(val)
proc addFloatValue*(builder: var Builder, val: float) =
builder.buf.addFloat(val)

template cFloatValue(val: float): Snippet = $val
template cFloatValue*(val: float): Snippet = $val

proc int64Literal(i: BiggestInt; result: var Builder) =
proc addInt64Literal*(result: var Builder; i: BiggestInt) =
if i > low(int64):
result.add "IL64($1)" % [rope(i)]
else:
result.add "(IL64(-9223372036854775807) - IL64(1))"

proc uint64Literal(i: uint64; result: var Builder) =
proc addUint64Literal*(result: var Builder; i: uint64) =
result.add rope($i & "ULL")

proc intLiteral(i: BiggestInt; result: var Builder) =
proc addIntLiteral*(result: var Builder; i: BiggestInt) =
if i > low(int32) and i <= high(int32):
result.addIntValue(i)
elif i == low(int32):
Expand All @@ -49,19 +61,19 @@ proc intLiteral(i: BiggestInt; result: var Builder) =
else:
result.add "(IL64(-9223372036854775807) - IL64(1))"

proc intLiteral(i: Int128; result: var Builder) =
intLiteral(toInt64(i), result)
proc addIntLiteral*(result: var Builder; i: Int128) =
addIntLiteral(result, toInt64(i))

proc cInt64Literal(i: BiggestInt): Snippet =
proc cInt64Literal*(i: BiggestInt): Snippet =
if i > low(int64):
result = "IL64($1)" % [rope(i)]
else:
result = "(IL64(-9223372036854775807) - IL64(1))"

proc cUint64Literal(i: uint64): Snippet =
proc cUint64Literal*(i: uint64): Snippet =
result = $i & "ULL"

proc cIntLiteral(i: BiggestInt): Snippet =
proc cIntLiteral*(i: BiggestInt): Snippet =
if i > low(int32) and i <= high(int32):
result = rope(i)
elif i == low(int32):
Expand All @@ -72,5 +84,5 @@ proc cIntLiteral(i: BiggestInt): Snippet =
else:
result = "(IL64(-9223372036854775807) - IL64(1))"

proc cIntLiteral(i: Int128): Snippet =
proc cIntLiteral*(i: Int128): Snippet =
result = cIntLiteral(toInt64(i))
20 changes: 16 additions & 4 deletions compiler/cbuilderdecls.nim
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ template addVarWithType(builder: var Builder, kind: VarKind = Local, name: strin
builder.add(name)
builder.add(";\n")

template addVarWithInitializer(builder: var Builder, kind: VarKind = Local, name: string,
typ: Snippet, initializerBody: typed) =
## adds a variable declaration to the builder, with
## `initializerBody` building the initializer. initializer must be provided
builder.addVarHeader(kind)
builder.add(typ)
builder.add(" ")
builder.add(name)
builder.add(" = ")
initializerBody
builder.add(";\n")

template addVarWithTypeAndInitializer(builder: var Builder, kind: VarKind = Local, name: string,
typeBody, initializerBody: typed) =
## adds a variable declaration to the builder, with `typeBody` building the type, and
Expand Down Expand Up @@ -252,12 +264,12 @@ proc startSimpleStruct(obj: var Builder; m: BModule; name: string; baseType: Sni
obj.add(baseType)
obj.add(" ")
obj.add("{\n")
result.preFieldsLen = obj.len
result.preFieldsLen = obj.buf.len
if result.baseKind == bcSupField:
obj.addField(name = "Sup", typ = baseType)

proc finishSimpleStruct(obj: var Builder; m: BModule; info: StructBuilderInfo) =
if info.baseKind == bcNone and info.preFieldsLen == obj.len:
if info.baseKind == bcNone and info.preFieldsLen == obj.buf.len:
# no fields were added, add dummy field
obj.addField(name = "dummy", typ = "char")
if info.named:
Expand Down Expand Up @@ -308,7 +320,7 @@ proc startStruct(obj: var Builder; m: BModule; t: PType; name: string; baseType:
obj.add(baseType)
obj.add(" ")
obj.add("{\n")
result.preFieldsLen = obj.len
result.preFieldsLen = obj.buf.len
case result.baseKind
of bcNone:
# rest of the options add a field or don't need it due to inheritance,
Expand All @@ -328,7 +340,7 @@ proc startStruct(obj: var Builder; m: BModule; t: PType; name: string; baseType:
obj.addField(name = "Sup", typ = baseType)

proc finishStruct(obj: var Builder; m: BModule; t: PType; info: StructBuilderInfo) =
if info.baseKind == bcNone and info.preFieldsLen == obj.len and
if info.baseKind == bcNone and info.preFieldsLen == obj.buf.len and
t.itemId notin m.g.graph.memberProcsPerType:
# no fields were added, add dummy field
obj.addField(name = "dummy", typ = "char")
Expand Down
3 changes: 1 addition & 2 deletions compiler/ccgcalls.nim
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,7 @@ proc genOpenArraySlice(p: BProc; q: PNode; formalType, destType: PType; prepareF
result = ("($3*)(($1)+($2))" % [rdLoc(a), rdLoc(b), dest],
lengthExpr)
else:
var lit = newRopeAppender()
intLiteral(first, lit)
let lit = cIntLiteral(first)
result = ("($4*)($1)+(($2)-($3))" %
[rdLoc(a), rdLoc(b), lit, dest],
lengthExpr)
Expand Down
Loading

0 comments on commit 903015b

Please sign in to comment.